blob: 9da0abd0fe845b55408eaf0e2c8c019f66020811 [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;
233 XGL_GPU_MEMORY m_depthStencilMem;
234 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700235 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600236
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600237
238 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600239
240 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
241 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800242 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600243 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800244 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600245 this->app_info.engineVersion = 1;
246 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
247
Cody Northrop350727b2014-10-06 15:42:00 -0600248 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
249 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700250 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600251
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600252 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600253 }
254
255 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600256 // Clean up resources before we reset
257 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600258 }
259};
260
Tony Barbour02472db2015-01-08 17:08:28 -0700261void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
262{
263 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700264 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700265 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
266 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Tony Barbour02472db2015-01-08 17:08:28 -0700269 pipelineobj->CreateXGLPipeline(descriptorSet);
270 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
271 descriptorSet->CreateXGLDescriptorSet();
272 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
273}
Tony Barbourf43b6982014-11-25 13:18:32 -0700274
Tony Barbourf43b6982014-11-25 13:18:32 -0700275void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700276 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
277{
278 int i;
279 glm::mat4 MVP;
280 int matrixSize = sizeof(MVP);
281 XGL_RESULT err;
282
283 for (i = 0; i < 8; i++) {
284 void *pData = constantBuffer->map();
285
286 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
287 MVP = Projection * View * Model;
288 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
289
290 constantBuffer->unmap();
291
292 // submit the command buffer to the universal queue
293 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
294
Tony Barbourdd4c9642015-01-09 12:55:14 -0700295 err = xglQueueWaitIdle( m_device->m_queue );
296 ASSERT_XGL_SUCCESS( err );
297
298 // Wait for work to finish before cleaning up.
299 xglDeviceWaitIdle(m_device->device());
300
301 assert(m_renderTargetCount == 1);
302 RecordImage(m_renderTargets[0]);
303 }
304}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600305
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600306void dumpMatrix(const char *note, glm::mat4 MVP)
307{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800308 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600309
310 printf("%s: \n", note);
311 for (i=0; i<4; i++) {
312 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
313 }
314 printf("\n");
315 fflush(stdout);
316}
317
318void dumpVec4(const char *note, glm::vec4 vector)
319{
320 printf("%s: \n", note);
321 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
322 printf("\n");
323 fflush(stdout);
324}
325
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600326void XglRenderTest::InitDepthStencil()
327{
328 XGL_RESULT err;
329 XGL_IMAGE_CREATE_INFO image;
330 XGL_MEMORY_ALLOC_INFO mem_alloc;
331 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
332 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700333 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600334
335 // Clean up default state created by framework
336 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
337
338 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
339 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
340
341 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
342 image.pNext = NULL;
343 image.imageType = XGL_IMAGE_2D;
344 image.format = m_depth_stencil_fmt;
345 image.extent.width = m_width;
346 image.extent.height = m_height;
347 image.extent.depth = 1;
348 image.mipLevels = 1;
349 image.arraySize = 1;
350 image.samples = 1;
351 image.tiling = XGL_OPTIMAL_TILING;
352 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
353 image.flags = 0;
354
355 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
356 mem_alloc.pNext = NULL;
357 mem_alloc.allocationSize = 0;
358 mem_alloc.alignment = 0;
359 mem_alloc.flags = 0;
360 mem_alloc.heapCount = 0;
361 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
362
363 /* create image */
364 err = xglCreateImage(device(), &image,
365 &m_depthStencilImage);
366 ASSERT_XGL_SUCCESS(err);
367
368 err = xglGetObjectInfo(m_depthStencilImage,
369 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
370 &mem_reqs_size, &mem_reqs);
371 ASSERT_XGL_SUCCESS(err);
372 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
373
Tony Barbourfa6cac72015-01-16 14:27:35 -0700374 XGL_UINT heapInfo[mem_reqs.heapCount];
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600375 mem_alloc.allocationSize = mem_reqs.size;
376 mem_alloc.alignment = mem_reqs.alignment;
377 mem_alloc.heapCount = mem_reqs.heapCount;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 mem_alloc.pHeaps = heapInfo;
379 memcpy(heapInfo, mem_reqs.pHeaps,
380 sizeof(mem_reqs.pHeaps) * mem_reqs.heapCount);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600381
382 /* allocate memory */
383 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
384 ASSERT_XGL_SUCCESS(err);
385
386 /* bind memory */
387 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
388 ASSERT_XGL_SUCCESS(err);
389
Tony Barbourfa6cac72015-01-16 14:27:35 -0700390 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
391 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
392
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600393 depthStencil.minDepth = 0.f;
394 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700395 depthStencil.stencilBackRef = 0;
396 depthStencil.stencilFrontRef = 0;
397 depthStencil.stencilReadMask = 0xff;
398 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600399
Tony Barbourfa6cac72015-01-16 14:27:35 -0700400 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600401 ASSERT_XGL_SUCCESS( err );
402
403 /* create image view */
404 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
405 view.pNext = NULL;
406 view.image = XGL_NULL_HANDLE;
407 view.mipLevel = 0;
408 view.baseArraySlice = 0;
409 view.arraySize = 1;
410 view.flags = 0;
411 view.image = m_depthStencilImage;
412 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
413 ASSERT_XGL_SUCCESS(err);
414
415 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000416 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600417}
418
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600419struct xgltriangle_vs_uniform {
420 // Must start with MVP
421 XGL_FLOAT mvp[4][4];
422 XGL_FLOAT position[3][4];
423 XGL_FLOAT color[3][4];
424};
425
Tony Barbourae442072015-01-12 13:27:11 -0700426void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600427{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700428#ifdef DEBUG_CALLBACK
429 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
430#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 // Create identity matrix
432 int i;
433 struct xgltriangle_vs_uniform data;
434
435 glm::mat4 Projection = glm::mat4(1.0f);
436 glm::mat4 View = glm::mat4(1.0f);
437 glm::mat4 Model = glm::mat4(1.0f);
438 glm::mat4 MVP = Projection * View * Model;
439 const int matrixSize = sizeof(MVP);
440 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
441 memcpy(&data.mvp, &MVP[0][0], matrixSize);
442
443 static const Vertex tri_data[] =
444 {
445 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
446 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
447 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
448 };
449
450 for (i=0; i<3; i++) {
451 data.position[i][0] = tri_data[i].posX;
452 data.position[i][1] = tri_data[i].posY;
453 data.position[i][2] = tri_data[i].posZ;
454 data.position[i][3] = tri_data[i].posW;
455 data.color[i][0] = tri_data[i].r;
456 data.color[i][1] = tri_data[i].g;
457 data.color[i][2] = tri_data[i].b;
458 data.color[i][3] = tri_data[i].a;
459 }
460
Tony Barbourf43b6982014-11-25 13:18:32 -0700461 ASSERT_NO_FATAL_FAILURE(InitState());
462 ASSERT_NO_FATAL_FAILURE(InitViewport());
463
464 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
465
466 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
467 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Chia-I Wu714df452015-01-01 07:55:04 +0800468 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
470 XglPipelineObj pipelineobj(m_device);
471 pipelineobj.AddShader(&vs);
472 pipelineobj.AddShader(&ps);
473
474 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +0800475 descriptorSet.AttachBufferView(&constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700476 m_memoryRefManager.AddMemoryRef(&constantBuffer);
477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
479 XglCommandBufferObj cmdBuffer(m_device);
480 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700481
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700482 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700483
484 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
485
486 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
487#ifdef DUMP_STATE_DOT
488 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
489 pDSDumpDot((char*)"triTest2.dot");
490#endif
491 // render triangle
492 cmdBuffer.Draw(0, 3, 0, 1);
493
494 // finalize recording of the command buffer
495 cmdBuffer.EndCommandBuffer();
496 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
497
498 for (int i = 0; i < m_renderTargetCount; i++)
499 RecordImage(m_renderTargets[i]);
500
501 if (rotate)
502 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
503
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700504#ifdef PRINT_OBJECTS
505 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
506 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
507 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
508 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
509 printf("DEBUG : Number of Objects : %lu\n", numObjects);
510 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
511 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
512 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
513 for (i=0; i < numObjects; i++) {
514 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);
515 }
516 free(pObjNodeArray);
517#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700518
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600519}
520
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600521TEST_F(XglRenderTest, XGLTriangle_FragColor)
522{
523 static const char *vertShaderText =
524 "#version 140\n"
525 "#extension GL_ARB_separate_shader_objects : enable\n"
526 "#extension GL_ARB_shading_language_420pack : enable\n"
527 "\n"
528 "layout(binding = 0) uniform buf {\n"
529 " mat4 MVP;\n"
530 " vec4 position[3];\n"
531 " vec4 color[3];\n"
532 "} ubuf;\n"
533 "\n"
534 "layout (location = 0) out vec4 outColor;\n"
535 "\n"
536 "void main() \n"
537 "{\n"
538 " outColor = ubuf.color[gl_VertexID];\n"
539 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
540 "}\n";
541
542 static const char *fragShaderText =
543 "#version 140\n"
544 "#extension GL_ARB_separate_shader_objects : enable\n"
545 "#extension GL_ARB_shading_language_420pack : enable\n"
546 "\n"
547 "layout (location = 0) in vec4 inColor;\n"
548 "\n"
549 "void main()\n"
550 "{\n"
551 " gl_FragColor = inColor;\n"
552 "}\n";
553
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600554 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700555 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600556}
557
558TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
559{
560 static const char *vertShaderText =
561 "#version 140\n"
562 "#extension GL_ARB_separate_shader_objects : enable\n"
563 "#extension GL_ARB_shading_language_420pack : enable\n"
564 "\n"
565 "layout(binding = 0) uniform buf {\n"
566 " mat4 MVP;\n"
567 " vec4 position[3];\n"
568 " vec4 color[3];\n"
569 "} ubuf;\n"
570 "\n"
571 "layout (location = 0) out vec4 outColor;\n"
572 "\n"
573 "void main() \n"
574 "{\n"
575 " outColor = ubuf.color[gl_VertexID];\n"
576 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
577 "}\n";
578
579 static const char *fragShaderText =
580 "#version 140\n"
581 "#extension GL_ARB_separate_shader_objects : enable\n"
582 "#extension GL_ARB_shading_language_420pack : enable\n"
583 "\n"
584 "layout (location = 0) in vec4 inColor;\n"
585 "layout (location = 0) out vec4 outColor;\n"
586 "\n"
587 "void main()\n"
588 "{\n"
589 " outColor = inColor;\n"
590 "}\n";
591
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600592 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 -0600593
Tony Barbourae442072015-01-12 13:27:11 -0700594 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600595}
596
Tony Barbourf43b6982014-11-25 13:18:32 -0700597TEST_F(XglRenderTest, BIL_XGLTriangle)
598{
599 bool saved_use_bil = XglTestFramework::m_use_bil;
600
601 static const char *vertShaderText =
602 "#version 140\n"
603 "#extension GL_ARB_separate_shader_objects : enable\n"
604 "#extension GL_ARB_shading_language_420pack : enable\n"
605 "\n"
606 "layout(binding = 0) uniform buf {\n"
607 " mat4 MVP;\n"
608 " vec4 position[3];\n"
609 " vec4 color[3];\n"
610 "} ubuf;\n"
611 "\n"
612 "layout (location = 0) out vec4 outColor;\n"
613 "\n"
614 "void main() \n"
615 "{\n"
616 " outColor = ubuf.color[gl_VertexID];\n"
617 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
618 "}\n";
619
620 static const char *fragShaderText =
621 "#version 140\n"
622 "#extension GL_ARB_separate_shader_objects : enable\n"
623 "#extension GL_ARB_shading_language_420pack : enable\n"
624 "\n"
625 "layout (location = 0) in vec4 inColor;\n"
626 "\n"
627 "void main()\n"
628 "{\n"
629 " gl_FragColor = inColor;\n"
630 "}\n";
631
632 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
633
634 XglTestFramework::m_use_bil = true;
635
Tony Barbourae442072015-01-12 13:27:11 -0700636 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700637
638 XglTestFramework::m_use_bil = saved_use_bil;
639}
640
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600641TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600642{
643 static const char *vertShaderText =
644 "#version 130\n"
645 "vec2 vertices[3];\n"
646 "void main() {\n"
647 " vertices[0] = vec2(-1.0, -1.0);\n"
648 " vertices[1] = vec2( 1.0, -1.0);\n"
649 " vertices[2] = vec2( 0.0, 1.0);\n"
650 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
651 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600652
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600653 static const char *fragShaderText =
654 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600655 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600656 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600657 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600658
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600659 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
660
Tony Barbourae442072015-01-12 13:27:11 -0700661 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600662}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600663
Tony Barbourf43b6982014-11-25 13:18:32 -0700664TEST_F(XglRenderTest, BIL_GreenTriangle)
665{
666 bool saved_use_bil = XglTestFramework::m_use_bil;
667
668 static const char *vertShaderText =
669 "#version 130\n"
670 "vec2 vertices[3];\n"
671 "void main() {\n"
672 " vertices[0] = vec2(-1.0, -1.0);\n"
673 " vertices[1] = vec2( 1.0, -1.0);\n"
674 " vertices[2] = vec2( 0.0, 1.0);\n"
675 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
676 "}\n";
677
678 static const char *fragShaderText =
679 "#version 130\n"
680 "void main() {\n"
681 " gl_FragColor = vec4(0,1,0,1);\n"
682 "}\n";
683
684 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
685
686 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700687 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700688 XglTestFramework::m_use_bil = saved_use_bil;
689}
690
691TEST_F(XglRenderTest, YellowTriangle)
692{
693 static const char *vertShaderText =
694 "#version 130\n"
695 "void main() {\n"
696 " vec2 vertices[3];"
697 " vertices[0] = vec2(-0.5, -0.5);\n"
698 " vertices[1] = vec2( 0.5, -0.5);\n"
699 " vertices[2] = vec2( 0.5, 0.5);\n"
700 " vec4 colors[3];\n"
701 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
702 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
703 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
704 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
705 "}\n";
706
707 static const char *fragShaderText =
708 "#version 130\n"
709 "void main() {\n"
710 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
711 "}\n";
712
Tony Barbourae442072015-01-12 13:27:11 -0700713 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700714}
715
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600716TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600717{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600718 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700719 "#version 130\n"
720 //XYZ1( -1, -1, -1 )
721 "in vec4 pos;\n"
722 //XYZ1( 0.f, 0.f, 0.f )
723 "in vec4 inColor;\n"
724 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600725 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600726 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600727 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600728 "}\n";
729
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600730
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600731 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700732 "#version 140\n"
733 "#extension GL_ARB_separate_shader_objects : enable\n"
734 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700735 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700736 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600737 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700738 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600739 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600740
Tony Barbourf43b6982014-11-25 13:18:32 -0700741
742
743 ASSERT_NO_FATAL_FAILURE(InitState());
744 ASSERT_NO_FATAL_FAILURE(InitViewport());
745
746 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000747 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700748
749 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
750 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
751
752 XglPipelineObj pipelineobj(m_device);
753 pipelineobj.AddShader(&vs);
754 pipelineobj.AddShader(&ps);
755
756 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +0800757 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700758
759 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
760 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
761 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
762 };
763
764 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
765 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
766 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
767 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
768 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
769 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
770 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
771 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
772 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
773
774 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
775 pipelineobj.AddVertexInputBindings(&vi_binding,1);
776 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
777
Tony Barboure4ed9942015-01-09 10:06:53 -0700778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
779 XglCommandBufferObj cmdBuffer(m_device);
780 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700781
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700782 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700783 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
784
Tony Barboure4ed9942015-01-09 10:06:53 -0700785 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
786
787 // render two triangles
788 cmdBuffer.Draw(0, 6, 0, 1);
789
790 // finalize recording of the command buffer
791 cmdBuffer.EndCommandBuffer();
792 cmdBuffer.QueueCommandBuffer(NULL, 0);
793
794 for (int i = 0; i < m_renderTargetCount; i++)
795 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600796}
797
Chia-I Wue09d1a72014-12-05 10:32:23 +0800798TEST_F(XglRenderTest, TriangleMRT)
799{
800 static const char *vertShaderText =
801 "#version 130\n"
802 "in vec4 pos;\n"
803 "void main() {\n"
804 " gl_Position = pos;\n"
805 "}\n";
806
807 static const char *fragShaderText =
808 "#version 130\n"
809 "void main() {\n"
810 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
811 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
812 "}\n";
813 const XGL_FLOAT vb_data[][2] = {
814 { -1.0f, -1.0f },
815 { 1.0f, -1.0f },
816 { -1.0f, 1.0f }
817 };
818
819 ASSERT_NO_FATAL_FAILURE(InitState());
820 ASSERT_NO_FATAL_FAILURE(InitViewport());
821
822 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000823 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800824
825 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
826 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
827
828 XglPipelineObj pipelineobj(m_device);
829 pipelineobj.AddShader(&vs);
830 pipelineobj.AddShader(&ps);
831
832 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
833 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
834 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
835 };
836
837 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
838 vi_attrib.binding = 0; // index into vertexBindingDescriptions
839 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
840 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
841 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
842
843 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
844 pipelineobj.AddVertexInputBindings(&vi_binding,1);
845 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
846
847 XglDescriptorSetObj descriptorSet(m_device);
848
849 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800851
852 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
853 att.blendEnable = XGL_FALSE;
854 att.format = m_render_target_fmt;
855 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700856 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857
Tony Barbour5ed79702015-01-07 14:31:52 -0700858 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700859
Tony Barbour5ed79702015-01-07 14:31:52 -0700860 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
861 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700862
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700863 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700864
Tony Barboure4ed9942015-01-09 10:06:53 -0700865 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
866
Tony Barbour5ed79702015-01-07 14:31:52 -0700867 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700868#ifdef DUMP_STATE_DOT
869 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
870 pDSDumpDot((char*)"triTest2.dot");
871#endif
872 // render triangle
873 cmdBuffer.Draw(0, 3, 0, 1);
874
875 // finalize recording of the command buffer
876 cmdBuffer.EndCommandBuffer();
877 cmdBuffer.QueueCommandBuffer(NULL, 0);
878
879 for (int i = 0; i < m_renderTargetCount; i++)
880 RecordImage(m_renderTargets[i]);
881
Chia-I Wue09d1a72014-12-05 10:32:23 +0800882}
883
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700884TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
885{
886 static const char *vertShaderText =
887 "#version 140\n"
888 "#extension GL_ARB_separate_shader_objects : enable\n"
889 "#extension GL_ARB_shading_language_420pack : enable\n"
890 "layout(location = 0) in vec4 pos;\n"
891 "layout(location = 1) in vec4 inColor;\n"
892 "layout(location = 0) out vec4 outColor;\n"
893 "void main() {\n"
894 " outColor = inColor;\n"
895 " gl_Position = pos;\n"
896 "}\n";
897
898
899 static const char *fragShaderText =
900 "#version 140\n"
901 "#extension GL_ARB_separate_shader_objects : enable\n"
902 "#extension GL_ARB_shading_language_420pack : enable\n"
903 "layout(location = 0) in vec4 color;\n"
904 "void main() {\n"
905 " gl_FragColor = color;\n"
906 "}\n";
907
908 const Vertex g_vbData[] =
909 {
910 // first tri
911 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
912 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
913 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
914
915 // second tri
916 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
917 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
918 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
919 };
920
921 const uint16_t g_idxData[6] = {
922 0, 1, 2,
923 3, 4, 5,
924 };
925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927 ASSERT_NO_FATAL_FAILURE(InitViewport());
928
929 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000930 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700931
932 XglIndexBufferObj indexBuffer(m_device);
933 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000934 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700935
936 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
937 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
938
939 XglPipelineObj pipelineobj(m_device);
940 pipelineobj.AddShader(&vs);
941 pipelineobj.AddShader(&ps);
942
943 XglDescriptorSetObj descriptorSet(m_device);
944
945 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
946 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
947 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
948 };
949
950 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
951 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
952 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
953 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
954 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
955 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
956 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
957 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
958 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
959
960 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
961 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700964 XglCommandBufferObj cmdBuffer(m_device);
965 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700966 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700967
968 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970#ifdef DUMP_STATE_DOT
971 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700972 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700973#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700974
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700975 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
976 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700977
978 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700979 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980
981 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700982 cmdBuffer.EndCommandBuffer();
983 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700985 for (int i = 0; i < m_renderTargetCount; i++)
986 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987
988}
989
GregF6bef1212014-12-02 15:41:44 -0700990TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
991{
992 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700993
GregF6bef1212014-12-02 15:41:44 -0700994 static const char *vertShaderText =
995 "#version 140\n"
996 "#extension GL_ARB_separate_shader_objects : enable\n"
997 "#extension GL_ARB_shading_language_420pack : enable\n"
998 "layout (location = 0) in vec4 pos;\n"
999 "layout (location = 0) out vec4 outColor;\n"
1000 "layout (location = 1) out vec4 outColor2;\n"
1001 "void main() {\n"
1002 " gl_Position = pos;\n"
1003 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1004 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1005 "}\n";
1006
1007 static const char *fragShaderText =
1008 //"#version 140\n"
1009 "#version 330\n"
1010 "#extension GL_ARB_separate_shader_objects : enable\n"
1011 "#extension GL_ARB_shading_language_420pack : enable\n"
1012 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1013 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1014 "layout (location = 0) in vec4 color;\n"
1015 "layout (location = 1) in vec4 color2;\n"
1016 "void main() {\n"
1017 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1018 " float dist_squared = dot(pos, pos);\n"
1019 " gl_FragColor = (dist_squared < 400.0)\n"
1020 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1021 " : color2;\n"
1022 "}\n";
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025 ASSERT_NO_FATAL_FAILURE(InitViewport());
1026
1027 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001028 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001029
1030 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1031 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1032
1033 XglPipelineObj pipelineobj(m_device);
1034 pipelineobj.AddShader(&vs);
1035 pipelineobj.AddShader(&ps);
1036
1037 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001038 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001039
1040 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1041 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1042 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1043 };
1044
1045 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1046 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1047 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1048 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1049 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1050 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1051 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1052 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1053 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1054
1055 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1056 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1057 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1058
Tony Barbourdd4c9642015-01-09 12:55:14 -07001059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1060 XglCommandBufferObj cmdBuffer(m_device);
1061 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1062
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001063 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001064
1065 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1066
1067 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1068#ifdef DUMP_STATE_DOT
1069 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1070 pDSDumpDot((char*)"triTest2.dot");
1071#endif
1072 // render triangle
1073 cmdBuffer.Draw(0, 6, 0, 1);
1074
1075 // finalize recording of the command buffer
1076 cmdBuffer.EndCommandBuffer();
1077 cmdBuffer.QueueCommandBuffer(NULL, 0);
1078
1079 for (int i = 0; i < m_renderTargetCount; i++)
1080 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001081
1082}
1083
1084TEST_F(XglRenderTest, RedCirclesonBlue)
1085{
1086 // This tests that we correctly handle unread fragment inputs
1087
1088 static const char *vertShaderText =
1089 "#version 140\n"
1090 "#extension GL_ARB_separate_shader_objects : enable\n"
1091 "#extension GL_ARB_shading_language_420pack : enable\n"
1092 "layout (location = 0) in vec4 pos;\n"
1093 "layout (location = 0) out vec4 outColor;\n"
1094 "layout (location = 1) out vec4 outColor2;\n"
1095 "void main() {\n"
1096 " gl_Position = pos;\n"
1097 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1098 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1099 "}\n";
1100
1101 static const char *fragShaderText =
1102 //"#version 140\n"
1103 "#version 330\n"
1104 "#extension GL_ARB_separate_shader_objects : enable\n"
1105 "#extension GL_ARB_shading_language_420pack : enable\n"
1106 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1107 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1108 "layout (location = 0) in vec4 color;\n"
1109 "layout (location = 1) in vec4 color2;\n"
1110 "void main() {\n"
1111 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1112 " float dist_squared = dot(pos, pos);\n"
1113 " gl_FragColor = (dist_squared < 400.0)\n"
1114 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1115 " : color2;\n"
1116 "}\n";
1117
1118 ASSERT_NO_FATAL_FAILURE(InitState());
1119 ASSERT_NO_FATAL_FAILURE(InitViewport());
1120
1121 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001122 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001123
1124 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1125 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1126
1127 XglPipelineObj pipelineobj(m_device);
1128 pipelineobj.AddShader(&vs);
1129 pipelineobj.AddShader(&ps);
1130
1131 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001132 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001133
1134 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1135 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1136 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1137 };
1138
1139 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1140 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1141 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1142 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1143 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1144 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1145 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1146 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1147 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1148
1149 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1150 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1151 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1152
Tony Barbourdd4c9642015-01-09 12:55:14 -07001153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1154 XglCommandBufferObj cmdBuffer(m_device);
1155 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1156
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001157 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001158
1159 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1160
1161 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1162#ifdef DUMP_STATE_DOT
1163 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1164 pDSDumpDot((char*)"triTest2.dot");
1165#endif
1166 // render triangle
1167 cmdBuffer.Draw(0, 6, 0, 1);
1168
1169 // finalize recording of the command buffer
1170 cmdBuffer.EndCommandBuffer();
1171 cmdBuffer.QueueCommandBuffer(NULL, 0);
1172
1173 for (int i = 0; i < m_renderTargetCount; i++)
1174 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001175
1176}
1177
1178TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1179{
1180 // This tests reading gl_ClipDistance from FS
1181
1182 static const char *vertShaderText =
1183 "#version 330\n"
1184 "#extension GL_ARB_separate_shader_objects : enable\n"
1185 "#extension GL_ARB_shading_language_420pack : enable\n"
1186 "out gl_PerVertex {\n"
1187 " vec4 gl_Position;\n"
1188 " float gl_ClipDistance[1];\n"
1189 "};\n"
1190 "layout (location = 0) in vec4 pos;\n"
1191 "layout (location = 0) out vec4 outColor;\n"
1192 "layout (location = 1) out vec4 outColor2;\n"
1193 "void main() {\n"
1194 " gl_Position = pos;\n"
1195 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1196 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1197 " float dists[3];\n"
1198 " dists[0] = 0.0;\n"
1199 " dists[1] = 1.0;\n"
1200 " dists[2] = 1.0;\n"
1201 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1202 "}\n";
1203
1204
1205 static const char *fragShaderText =
1206 //"#version 140\n"
1207 "#version 330\n"
1208 "#extension GL_ARB_separate_shader_objects : enable\n"
1209 "#extension GL_ARB_shading_language_420pack : enable\n"
1210 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1211 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1212 "layout (location = 0) in vec4 color;\n"
1213 "layout (location = 1) in vec4 color2;\n"
1214 "void main() {\n"
1215 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1216 " float dist_squared = dot(pos, pos);\n"
1217 " gl_FragColor = (dist_squared < 400.0)\n"
1218 " ? color * gl_ClipDistance[0]\n"
1219 " : color2;\n"
1220 "}\n";
1221
1222 ASSERT_NO_FATAL_FAILURE(InitState());
1223 ASSERT_NO_FATAL_FAILURE(InitViewport());
1224
1225 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001226 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001227
1228 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1229 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1230
1231 XglPipelineObj pipelineobj(m_device);
1232 pipelineobj.AddShader(&vs);
1233 pipelineobj.AddShader(&ps);
1234
1235 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001236 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001237
1238 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1239 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1240 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1241 };
1242
1243 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1244 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1245 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1246 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1247 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1248 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1249 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1250 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1251 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1252
1253 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1254 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1255 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1256
Tony Barbourdd4c9642015-01-09 12:55:14 -07001257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1258 XglCommandBufferObj cmdBuffer(m_device);
1259 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001260
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001261 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001262
1263 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1264
1265 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1266#ifdef DUMP_STATE_DOT
1267 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1268 pDSDumpDot((char*)"triTest2.dot");
1269#endif
1270 // render triangle
1271 cmdBuffer.Draw(0, 6, 0, 1);
1272
1273 // finalize recording of the command buffer
1274 cmdBuffer.EndCommandBuffer();
1275 cmdBuffer.QueueCommandBuffer(NULL, 0);
1276
1277 for (int i = 0; i < m_renderTargetCount; i++)
1278 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001279}
Tony Barbourf43b6982014-11-25 13:18:32 -07001280
GregF7a23c792014-12-02 17:19:34 -07001281TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1282{
1283 static const char *vertShaderText =
1284 "#version 140\n"
1285 "#extension GL_ARB_separate_shader_objects : enable\n"
1286 "#extension GL_ARB_shading_language_420pack : enable\n"
1287 "layout (location = 0) in vec4 pos;\n"
1288 "layout (location = 0) out vec4 outColor;\n"
1289 "layout (location = 1) out vec4 outColor2;\n"
1290 "void main() {\n"
1291 " gl_Position = pos;\n"
1292 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1293 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1294 "}\n";
1295
1296
1297 static const char *fragShaderText =
1298 //"#version 140\n"
1299 "#version 330\n"
1300 "#extension GL_ARB_separate_shader_objects : enable\n"
1301 "#extension GL_ARB_shading_language_420pack : enable\n"
1302 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1303 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1304 "layout (location = 0) in vec4 color;\n"
1305 "layout (location = 1) in vec4 color2;\n"
1306 "void main() {\n"
1307 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1308 " float dist_squared = dot(pos, pos);\n"
1309 " if (dist_squared < 100.0)\n"
1310 " discard;\n"
1311 " gl_FragColor = (dist_squared < 400.0)\n"
1312 " ? color\n"
1313 " : color2;\n"
1314 "}\n";
1315
1316 ASSERT_NO_FATAL_FAILURE(InitState());
1317 ASSERT_NO_FATAL_FAILURE(InitViewport());
1318
1319 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001320 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001321
1322 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1323 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1324
1325 XglPipelineObj pipelineobj(m_device);
1326 pipelineobj.AddShader(&vs);
1327 pipelineobj.AddShader(&ps);
1328
1329 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001330 descriptorSet.AttachBufferView(&meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001331
1332 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1333 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1334 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1335 };
1336
1337 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1338 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1339 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1340 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1341 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1342 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1343 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1344 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1345 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1346
1347 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1348 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1349 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1350
Tony Barbourdd4c9642015-01-09 12:55:14 -07001351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1352 XglCommandBufferObj cmdBuffer(m_device);
1353 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1354
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001355 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001356
1357 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1358
1359 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1360#ifdef DUMP_STATE_DOT
1361 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1362 pDSDumpDot((char*)"triTest2.dot");
1363#endif
1364 // render triangle
1365 cmdBuffer.Draw(0, 6, 0, 1);
1366
1367 // finalize recording of the command buffer
1368 cmdBuffer.EndCommandBuffer();
1369 cmdBuffer.QueueCommandBuffer(NULL, 0);
1370
1371 for (int i = 0; i < m_renderTargetCount; i++)
1372 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001373
1374}
1375
1376
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001377TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001378{
1379 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001380 "#version 140\n"
1381 "#extension GL_ARB_separate_shader_objects : enable\n"
1382 "#extension GL_ARB_shading_language_420pack : enable\n"
1383 "\n"
1384 "layout(binding = 0) uniform buf {\n"
1385 " mat4 MVP;\n"
1386 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001387 "void main() {\n"
1388 " vec2 vertices[3];"
1389 " vertices[0] = vec2(-0.5, -0.5);\n"
1390 " vertices[1] = vec2( 0.5, -0.5);\n"
1391 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001392 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001393 "}\n";
1394
1395 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001396 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001397 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001398 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001399 "}\n";
1400
Tony Barbourf43b6982014-11-25 13:18:32 -07001401 ASSERT_NO_FATAL_FAILURE(InitState());
1402 ASSERT_NO_FATAL_FAILURE(InitViewport());
1403
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001404 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001405 glm::mat4 Projection = glm::mat4(1.0f);
1406 glm::mat4 View = glm::mat4(1.0f);
1407 glm::mat4 Model = glm::mat4(1.0f);
1408 glm::mat4 MVP = Projection * View * Model;
1409 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1410
Tony Barbourf43b6982014-11-25 13:18:32 -07001411 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1412 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1413 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001414
Chia-I Wu714df452015-01-01 07:55:04 +08001415 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001416
1417 XglPipelineObj pipelineobj(m_device);
1418 pipelineobj.AddShader(&vs);
1419 pipelineobj.AddShader(&ps);
1420
1421 // Create descriptor set and attach the constant buffer to it
1422 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001423 descriptorSet.AttachBufferView(&MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001424
1425 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1426
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1428 XglCommandBufferObj cmdBuffer(m_device);
1429 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001430
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001431 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001432
1433 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1434
1435 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1436#ifdef DUMP_STATE_DOT
1437 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1438 pDSDumpDot((char*)"triTest2.dot");
1439#endif
1440 // render triangle
1441 cmdBuffer.Draw(0, 6, 0, 1);
1442
1443 // finalize recording of the command buffer
1444 cmdBuffer.EndCommandBuffer();
1445 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1446
1447 for (int i = 0; i < m_renderTargetCount; i++)
1448 RecordImage(m_renderTargets[i]);
1449
1450 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001451}
1452
Tony Barbourf43b6982014-11-25 13:18:32 -07001453TEST_F(XglRenderTest, MixTriangle)
1454{
1455 // This tests location applied to varyings. Notice that we have switched foo
1456 // and bar in the FS. The triangle should be blended with red, green and blue
1457 // corners.
1458 static const char *vertShaderText =
1459 "#version 140\n"
1460 "#extension GL_ARB_separate_shader_objects : enable\n"
1461 "#extension GL_ARB_shading_language_420pack : enable\n"
1462 "layout (location=0) out vec4 bar;\n"
1463 "layout (location=1) out vec4 foo;\n"
1464 "layout (location=2) out float scale;\n"
1465 "vec2 vertices[3];\n"
1466 "void main() {\n"
1467 " vertices[0] = vec2(-1.0, -1.0);\n"
1468 " vertices[1] = vec2( 1.0, -1.0);\n"
1469 " vertices[2] = vec2( 0.0, 1.0);\n"
1470 "vec4 colors[3];\n"
1471 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1472 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1473 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1474 " foo = colors[gl_VertexID % 3];\n"
1475 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1476 " scale = 1.0;\n"
1477 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1478 "}\n";
1479
1480 static const char *fragShaderText =
1481 "#version 140\n"
1482 "#extension GL_ARB_separate_shader_objects : enable\n"
1483 "#extension GL_ARB_shading_language_420pack : enable\n"
1484 "layout (location = 1) in vec4 bar;\n"
1485 "layout (location = 0) in vec4 foo;\n"
1486 "layout (location = 2) in float scale;\n"
1487 "void main() {\n"
1488 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1489 "}\n";
1490
1491 ASSERT_NO_FATAL_FAILURE(InitState());
1492 ASSERT_NO_FATAL_FAILURE(InitViewport());
1493
1494 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1495 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1496
1497 XglPipelineObj pipelineobj(m_device);
1498 pipelineobj.AddShader(&vs);
1499 pipelineobj.AddShader(&ps);
1500
1501 XglDescriptorSetObj descriptorSet(m_device);
1502
Tony Barbourdd4c9642015-01-09 12:55:14 -07001503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504 XglCommandBufferObj cmdBuffer(m_device);
1505 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1506
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001507 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001508
1509 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1510
1511#ifdef DUMP_STATE_DOT
1512 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1513 pDSDumpDot((char*)"triTest2.dot");
1514#endif
1515 // render triangle
1516 cmdBuffer.Draw(0, 3, 0, 1);
1517
1518 // finalize recording of the command buffer
1519 cmdBuffer.EndCommandBuffer();
1520 cmdBuffer.QueueCommandBuffer(NULL, 0);
1521
1522 for (int i = 0; i < m_renderTargetCount; i++)
1523 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001524}
1525
1526TEST_F(XglRenderTest, TriVertFetchAndVertID)
1527{
1528 // This tests that attributes work in the presence of gl_VertexID
1529
1530 static const char *vertShaderText =
1531 "#version 140\n"
1532 "#extension GL_ARB_separate_shader_objects : enable\n"
1533 "#extension GL_ARB_shading_language_420pack : enable\n"
1534 //XYZ1( -1, -1, -1 )
1535 "layout (location = 0) in vec4 pos;\n"
1536 //XYZ1( 0.f, 0.f, 0.f )
1537 "layout (location = 1) in vec4 inColor;\n"
1538 "layout (location = 0) out vec4 outColor;\n"
1539 "void main() {\n"
1540 " outColor = inColor;\n"
1541 " vec4 vertices[3];"
1542 " vertices[gl_VertexID % 3] = pos;\n"
1543 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1544 "}\n";
1545
1546
1547 static const char *fragShaderText =
1548 "#version 140\n"
1549 "#extension GL_ARB_separate_shader_objects : enable\n"
1550 "#extension GL_ARB_shading_language_420pack : enable\n"
1551 "layout (location = 0) in vec4 color;\n"
1552 "void main() {\n"
1553 " gl_FragColor = color;\n"
1554 "}\n";
1555
1556 ASSERT_NO_FATAL_FAILURE(InitState());
1557 ASSERT_NO_FATAL_FAILURE(InitViewport());
1558
1559 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001560 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001561
1562 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1563 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1564
1565 XglPipelineObj pipelineobj(m_device);
1566 pipelineobj.AddShader(&vs);
1567 pipelineobj.AddShader(&ps);
1568
1569 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001570 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001571
1572 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1573 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1574 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1575 };
1576
1577 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1578 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1579 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1580 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1581 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1582 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1583 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1584 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1585 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1586
1587 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1588 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1589 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1590
Tony Barbourdd4c9642015-01-09 12:55:14 -07001591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1592 XglCommandBufferObj cmdBuffer(m_device);
1593 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1594
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001595 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001596
1597 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1598
1599 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1600#ifdef DUMP_STATE_DOT
1601 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1602 pDSDumpDot((char*)"triTest2.dot");
1603#endif
1604 // render triangle
1605 cmdBuffer.Draw(0, 6, 0, 1);
1606
1607 // finalize recording of the command buffer
1608 cmdBuffer.EndCommandBuffer();
1609 cmdBuffer.QueueCommandBuffer(NULL, 0);
1610
1611 for (int i = 0; i < m_renderTargetCount; i++)
1612 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001613}
1614
1615TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1616{
1617 // This tests that attributes work in the presence of gl_VertexID
1618 // and a dead attribute in position 0. Draws a triangle with yellow,
1619 // red and green corners, starting at top and going clockwise.
1620
1621 static const char *vertShaderText =
1622 "#version 140\n"
1623 "#extension GL_ARB_separate_shader_objects : enable\n"
1624 "#extension GL_ARB_shading_language_420pack : enable\n"
1625 //XYZ1( -1, -1, -1 )
1626 "layout (location = 0) in vec4 pos;\n"
1627 //XYZ1( 0.f, 0.f, 0.f )
1628 "layout (location = 1) in vec4 inColor;\n"
1629 "layout (location = 0) out vec4 outColor;\n"
1630 "void main() {\n"
1631 " outColor = inColor;\n"
1632 " vec2 vertices[3];"
1633 " vertices[0] = vec2(-1.0, -1.0);\n"
1634 " vertices[1] = vec2( 1.0, -1.0);\n"
1635 " vertices[2] = vec2( 0.0, 1.0);\n"
1636 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1637 "}\n";
1638
1639
1640 static const char *fragShaderText =
1641 "#version 140\n"
1642 "#extension GL_ARB_separate_shader_objects : enable\n"
1643 "#extension GL_ARB_shading_language_420pack : enable\n"
1644 "layout (location = 0) in vec4 color;\n"
1645 "void main() {\n"
1646 " gl_FragColor = color;\n"
1647 "}\n";
1648
1649 ASSERT_NO_FATAL_FAILURE(InitState());
1650 ASSERT_NO_FATAL_FAILURE(InitViewport());
1651
1652 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001653 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001654
1655 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1656 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1657
1658 XglPipelineObj pipelineobj(m_device);
1659 pipelineobj.AddShader(&vs);
1660 pipelineobj.AddShader(&ps);
1661
1662 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001663 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001664
1665 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1666 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1667 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1668 };
1669
1670 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1671 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1672 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1673 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1674 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1675 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1676 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1677 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1678 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1679
1680 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1681 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1682 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1683
Tony Barbourdd4c9642015-01-09 12:55:14 -07001684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1685 XglCommandBufferObj cmdBuffer(m_device);
1686 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001687
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001688 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001689
1690 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1691
1692 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1693#ifdef DUMP_STATE_DOT
1694 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1695 pDSDumpDot((char*)"triTest2.dot");
1696#endif
1697 // render triangle
1698 cmdBuffer.Draw(0, 6, 0, 1);
1699
1700 // finalize recording of the command buffer
1701 cmdBuffer.EndCommandBuffer();
1702 cmdBuffer.QueueCommandBuffer(NULL, 0);
1703
1704 for (int i = 0; i < m_renderTargetCount; i++)
1705 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001706}
1707
1708TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001709{
1710 static const char *vertShaderText =
1711 "#version 140\n"
1712 "layout (std140) uniform bufferVals {\n"
1713 " mat4 mvp;\n"
1714 "} myBufferVals;\n"
1715 "in vec4 pos;\n"
1716 "in vec4 inColor;\n"
1717 "out vec4 outColor;\n"
1718 "void main() {\n"
1719 " outColor = inColor;\n"
1720 " gl_Position = myBufferVals.mvp * pos;\n"
1721 "}\n";
1722
1723 static const char *fragShaderText =
1724 "#version 130\n"
1725 "in vec4 color;\n"
1726 "void main() {\n"
1727 " gl_FragColor = color;\n"
1728 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001729 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001730
Tony Barbourf43b6982014-11-25 13:18:32 -07001731 glm::mat4 View = glm::lookAt(
1732 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1733 glm::vec3(0,0,0), // and looks at the origin
1734 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1735 );
1736
1737 glm::mat4 Model = glm::mat4(1.0f);
1738
1739 glm::mat4 MVP = Projection * View * Model;
1740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
1742 ASSERT_NO_FATAL_FAILURE(InitViewport());
1743 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1744
1745 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1746 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1747
1748 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1749
1750 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1751 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1752 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1753
Chia-I Wu714df452015-01-01 07:55:04 +08001754 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001755
1756 XglPipelineObj pipelineobj(m_device);
1757 pipelineobj.AddShader(&vs);
1758 pipelineobj.AddShader(&ps);
1759
Tony Barbourfa6cac72015-01-16 14:27:35 -07001760 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1761 ds_state.depthTestEnable = XGL_TRUE;
1762 ds_state.depthWriteEnable = XGL_TRUE;
1763 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1764 ds_state.depthBoundsEnable = XGL_FALSE;
1765 ds_state.stencilTestEnable = XGL_FALSE;
1766 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1767 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1768 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1769 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1770 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1771 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1772 ds_state.front = ds_state.back;
1773 pipelineobj.SetDepthStencil(&ds_state);
1774
Tony Barbourf43b6982014-11-25 13:18:32 -07001775 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001776 descriptorSet.AttachBufferView(&MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001777
1778 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1779 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1780
1781 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1782 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1783 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1784 };
1785
1786 // this is the current description of g_vbData
1787 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1788 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1789 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1790 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1791 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1792 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1793 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1794 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1795 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1796
1797 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1798 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1799 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1800
Tony Barboure4ed9942015-01-09 10:06:53 -07001801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1802 XglCommandBufferObj cmdBuffer(m_device);
1803 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001804
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001805 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001806 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001807
Tony Barboure4ed9942015-01-09 10:06:53 -07001808 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1809#ifdef DUMP_STATE_DOT
1810 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1811 pDSDumpDot((char*)"triTest2.dot");
1812#endif
1813 // render triangle
1814 cmdBuffer.Draw(0, 36, 0, 1);
1815
1816 // finalize recording of the command buffer
1817 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001818 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001819
1820 for (int i = 0; i < m_renderTargetCount; i++)
1821 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001822}
1823
Tony Barbourf43b6982014-11-25 13:18:32 -07001824TEST_F(XglRenderTest, VSTexture)
1825{
1826 // The expected result from this test is a green and red triangle;
1827 // one red vertex on the left, two green vertices on the right.
1828 static const char *vertShaderText =
1829 "#version 130\n"
1830 "out vec4 texColor;\n"
1831 "uniform sampler2D surface;\n"
1832 "void main() {\n"
1833 " vec2 vertices[3];"
1834 " vertices[0] = vec2(-0.5, -0.5);\n"
1835 " vertices[1] = vec2( 0.5, -0.5);\n"
1836 " vertices[2] = vec2( 0.5, 0.5);\n"
1837 " vec2 positions[3];"
1838 " positions[0] = vec2( 0.0, 0.0);\n"
1839 " positions[1] = vec2( 0.25, 0.1);\n"
1840 " positions[2] = vec2( 0.1, 0.25);\n"
1841 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1842 " texColor = textureLod(surface, samplePos, 0.0);\n"
1843 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1844 "}\n";
1845
1846 static const char *fragShaderText =
1847 "#version 130\n"
1848 "in vec4 texColor;\n"
1849 "void main() {\n"
1850 " gl_FragColor = texColor;\n"
1851 "}\n";
1852
1853 ASSERT_NO_FATAL_FAILURE(InitState());
1854 ASSERT_NO_FATAL_FAILURE(InitViewport());
1855
1856 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1857 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1858 XglSamplerObj sampler(m_device);
1859 XglTextureObj texture(m_device);
1860
Cody Northrop5fcacbc2014-12-09 19:08:54 -07001861 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001862 vs.BindShaderEntitySlotToSampler(0, &sampler);
1863
1864 XglPipelineObj pipelineobj(m_device);
1865 pipelineobj.AddShader(&vs);
1866 pipelineobj.AddShader(&ps);
1867
1868 XglDescriptorSetObj descriptorSet(m_device);
1869 descriptorSet.AttachImageView(&texture);
1870 descriptorSet.AttachSampler(&sampler);
1871
1872 m_memoryRefManager.AddMemoryRef(&texture);
1873
Tony Barbourdd4c9642015-01-09 12:55:14 -07001874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1875 XglCommandBufferObj cmdBuffer(m_device);
1876 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001877
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001878 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001879
1880 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1881
1882#ifdef DUMP_STATE_DOT
1883 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1884 pDSDumpDot((char*)"triTest2.dot");
1885#endif
1886 // render triangle
1887 cmdBuffer.Draw(0, 3, 0, 1);
1888
1889 // finalize recording of the command buffer
1890 cmdBuffer.EndCommandBuffer();
1891 cmdBuffer.QueueCommandBuffer(NULL, 0);
1892
1893 for (int i = 0; i < m_renderTargetCount; i++)
1894 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895}
1896TEST_F(XglRenderTest, TexturedTriangle)
1897{
1898 // The expected result from this test is a red and green checkered triangle
1899 static const char *vertShaderText =
1900 "#version 140\n"
1901 "#extension GL_ARB_separate_shader_objects : enable\n"
1902 "#extension GL_ARB_shading_language_420pack : enable\n"
1903 "layout (location = 0) out vec2 samplePos;\n"
1904 "void main() {\n"
1905 " vec2 vertices[3];"
1906 " vertices[0] = vec2(-0.5, -0.5);\n"
1907 " vertices[1] = vec2( 0.5, -0.5);\n"
1908 " vertices[2] = vec2( 0.5, 0.5);\n"
1909 " vec2 positions[3];"
1910 " positions[0] = vec2( 0.0, 0.0);\n"
1911 " positions[1] = vec2( 1.0, 0.0);\n"
1912 " positions[2] = vec2( 1.0, 1.0);\n"
1913 " samplePos = positions[gl_VertexID % 3];\n"
1914 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1915 "}\n";
1916
1917 static const char *fragShaderText =
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) in vec2 samplePos;\n"
1922 "layout (binding = 0) uniform sampler2D surface;\n"
1923 "layout (location=0) out vec4 outColor;\n"
1924 "void main() {\n"
1925 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1926 " outColor = texColor;\n"
1927 "}\n";
1928
1929 ASSERT_NO_FATAL_FAILURE(InitState());
1930 ASSERT_NO_FATAL_FAILURE(InitViewport());
1931
1932 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1933 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1934 XglSamplerObj sampler(m_device);
1935 XglTextureObj texture(m_device);
1936
Cody Northrop5fcacbc2014-12-09 19:08:54 -07001937 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001938 ps.BindShaderEntitySlotToSampler(0, &sampler);
1939
1940 XglPipelineObj pipelineobj(m_device);
1941 pipelineobj.AddShader(&vs);
1942 pipelineobj.AddShader(&ps);
1943
1944 XglDescriptorSetObj descriptorSet(m_device);
1945 descriptorSet.AttachImageView(&texture);
1946 descriptorSet.AttachSampler(&sampler);
1947
1948 m_memoryRefManager.AddMemoryRef(&texture);
1949
Tony Barbourdd4c9642015-01-09 12:55:14 -07001950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1951 XglCommandBufferObj cmdBuffer(m_device);
1952 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1953
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001954 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001955
1956 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1957
1958#ifdef DUMP_STATE_DOT
1959 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1960 pDSDumpDot((char*)"triTest2.dot");
1961#endif
1962 // render triangle
1963 cmdBuffer.Draw(0, 3, 0, 1);
1964
1965 // finalize recording of the command buffer
1966 cmdBuffer.EndCommandBuffer();
1967 cmdBuffer.QueueCommandBuffer(NULL, 0);
1968
1969 for (int i = 0; i < m_renderTargetCount; i++)
1970 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001971}
1972TEST_F(XglRenderTest, TexturedTriangleClip)
1973{
1974 // The expected result from this test is a red and green checkered triangle
1975 static const char *vertShaderText =
1976 "#version 330\n"
1977 "#extension GL_ARB_separate_shader_objects : enable\n"
1978 "#extension GL_ARB_shading_language_420pack : enable\n"
1979 "layout (location = 0) out vec2 samplePos;\n"
1980 "out gl_PerVertex {\n"
1981 " vec4 gl_Position;\n"
1982 " float gl_ClipDistance[1];\n"
1983 "};\n"
1984 "void main() {\n"
1985 " vec2 vertices[3];"
1986 " vertices[0] = vec2(-0.5, -0.5);\n"
1987 " vertices[1] = vec2( 0.5, -0.5);\n"
1988 " vertices[2] = vec2( 0.5, 0.5);\n"
1989 " vec2 positions[3];"
1990 " positions[0] = vec2( 0.0, 0.0);\n"
1991 " positions[1] = vec2( 1.0, 0.0);\n"
1992 " positions[2] = vec2( 1.0, 1.0);\n"
1993 " float dists[3];\n"
1994 " dists[0] = 1.0;\n"
1995 " dists[1] = 1.0;\n"
1996 " dists[2] = -1.0;\n"
1997 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1998 " samplePos = positions[gl_VertexID % 3];\n"
1999 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2000 "}\n";
2001
2002 static const char *fragShaderText =
2003 "#version 140\n"
2004 "#extension GL_ARB_separate_shader_objects : enable\n"
2005 "#extension GL_ARB_shading_language_420pack : enable\n"
2006 "layout (location = 0) in vec2 samplePos;\n"
2007 "layout (binding = 0) uniform sampler2D surface;\n"
2008 "layout (location=0) out vec4 outColor;\n"
2009 "void main() {\n"
2010 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2011 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2012 " outColor = texColor;\n"
2013 "}\n";
2014
2015
2016 ASSERT_NO_FATAL_FAILURE(InitState());
2017 ASSERT_NO_FATAL_FAILURE(InitViewport());
2018
2019 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2020 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2021 XglSamplerObj sampler(m_device);
2022 XglTextureObj texture(m_device);
2023
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002024 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002025 ps.BindShaderEntitySlotToSampler(0, &sampler);
2026
2027 XglPipelineObj pipelineobj(m_device);
2028 pipelineobj.AddShader(&vs);
2029 pipelineobj.AddShader(&ps);
2030
2031 XglDescriptorSetObj descriptorSet(m_device);
2032 descriptorSet.AttachImageView(&texture);
2033 descriptorSet.AttachSampler(&sampler);
2034
2035 m_memoryRefManager.AddMemoryRef(&texture);
2036
Tony Barbourdd4c9642015-01-09 12:55:14 -07002037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2038 XglCommandBufferObj cmdBuffer(m_device);
2039 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2040
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002041 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002042
2043 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2044
2045#ifdef DUMP_STATE_DOT
2046 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2047 pDSDumpDot((char*)"triTest2.dot");
2048#endif
2049 // render triangle
2050 cmdBuffer.Draw(0, 3, 0, 1);
2051
2052 // finalize recording of the command buffer
2053 cmdBuffer.EndCommandBuffer();
2054 cmdBuffer.QueueCommandBuffer(NULL, 0);
2055
2056 for (int i = 0; i < m_renderTargetCount; i++)
2057 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002058}
2059TEST_F(XglRenderTest, FSTriangle)
2060{
2061 // The expected result from this test is a red and green checkered triangle
2062 static const char *vertShaderText =
2063 "#version 140\n"
2064 "#extension GL_ARB_separate_shader_objects : enable\n"
2065 "#extension GL_ARB_shading_language_420pack : enable\n"
2066 "layout (location = 0) out vec2 samplePos;\n"
2067 "void main() {\n"
2068 " vec2 vertices[3];"
2069 " vertices[0] = vec2(-0.5, -0.5);\n"
2070 " vertices[1] = vec2( 0.5, -0.5);\n"
2071 " vertices[2] = vec2( 0.5, 0.5);\n"
2072 " vec2 positions[3];"
2073 " positions[0] = vec2( 0.0, 0.0);\n"
2074 " positions[1] = vec2( 1.0, 0.0);\n"
2075 " positions[2] = vec2( 1.0, 1.0);\n"
2076 " samplePos = positions[gl_VertexID % 3];\n"
2077 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2078 "}\n";
2079
2080 static const char *fragShaderText =
2081 "#version 140\n"
2082 "#extension GL_ARB_separate_shader_objects : enable\n"
2083 "#extension GL_ARB_shading_language_420pack : enable\n"
2084 "layout (location = 0) in vec2 samplePos;\n"
2085 "layout (binding = 0) uniform sampler2D surface;\n"
2086 "layout (location=0) out vec4 outColor;\n"
2087 "void main() {\n"
2088 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2089 " outColor = texColor;\n"
2090 "}\n";
2091
2092 ASSERT_NO_FATAL_FAILURE(InitState());
2093 ASSERT_NO_FATAL_FAILURE(InitViewport());
2094
2095 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2096 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2097 XglSamplerObj sampler(m_device);
2098 XglTextureObj texture(m_device);
2099
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002100 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002101 ps.BindShaderEntitySlotToSampler(0, &sampler);
2102
2103 XglPipelineObj pipelineobj(m_device);
2104 pipelineobj.AddShader(&vs);
2105 pipelineobj.AddShader(&ps);
2106
2107 XglDescriptorSetObj descriptorSet(m_device);
2108 descriptorSet.AttachImageView(&texture);
2109 descriptorSet.AttachSampler(&sampler);
2110
2111 m_memoryRefManager.AddMemoryRef(&texture);
2112
Tony Barbourdd4c9642015-01-09 12:55:14 -07002113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2114 XglCommandBufferObj cmdBuffer(m_device);
2115 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2116
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002117 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002118
2119 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2120
2121#ifdef DUMP_STATE_DOT
2122 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2123 pDSDumpDot((char*)"triTest2.dot");
2124#endif
2125 // render triangle
2126 cmdBuffer.Draw(0, 3, 0, 1);
2127
2128 // finalize recording of the command buffer
2129 cmdBuffer.EndCommandBuffer();
2130 cmdBuffer.QueueCommandBuffer(NULL, 0);
2131
2132 for (int i = 0; i < m_renderTargetCount; i++)
2133 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002134}
2135TEST_F(XglRenderTest, SamplerBindingsTriangle)
2136{
2137 // This test sets bindings on the samplers
2138 // For now we are asserting that sampler and texture pairs
2139 // march in lock step, and are set via GLSL binding. This can
2140 // and will probably change.
2141 // The sampler bindings should match the sampler and texture slot
2142 // number set up by the application.
2143 // This test will result in a blue triangle
2144 static const char *vertShaderText =
2145 "#version 140\n"
2146 "#extension GL_ARB_separate_shader_objects : enable\n"
2147 "#extension GL_ARB_shading_language_420pack : enable\n"
2148 "layout (location = 0) out vec4 samplePos;\n"
2149 "void main() {\n"
2150 " vec2 vertices[3];"
2151 " vertices[0] = vec2(-0.5, -0.5);\n"
2152 " vertices[1] = vec2( 0.5, -0.5);\n"
2153 " vertices[2] = vec2( 0.5, 0.5);\n"
2154 " vec2 positions[3];"
2155 " positions[0] = vec2( 0.0, 0.0);\n"
2156 " positions[1] = vec2( 1.0, 0.0);\n"
2157 " positions[2] = vec2( 1.0, 1.0);\n"
2158 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2159 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2160 "}\n";
2161
2162 static const char *fragShaderText =
2163 "#version 140\n"
2164 "#extension GL_ARB_separate_shader_objects : enable\n"
2165 "#extension GL_ARB_shading_language_420pack : enable\n"
2166 "layout (location = 0) in vec4 samplePos;\n"
2167 "layout (binding = 0) uniform sampler2D surface0;\n"
2168 "layout (binding = 1) uniform sampler2D surface1;\n"
2169 "layout (binding = 12) uniform sampler2D surface2;\n"
2170 "void main() {\n"
2171 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2172 "}\n";
2173
2174 ASSERT_NO_FATAL_FAILURE(InitState());
2175 ASSERT_NO_FATAL_FAILURE(InitViewport());
2176
2177 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2178 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2179
2180 XglSamplerObj sampler1(m_device);
2181 XglSamplerObj sampler2(m_device);
2182 XglSamplerObj sampler3(m_device);
2183
2184 XglTextureObj texture1(m_device); // Red
2185 texture1.ChangeColors(0xffff0000,0xffff0000);
2186 XglTextureObj texture2(m_device); // Green
2187 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2188 XglTextureObj texture3(m_device); // Blue
2189 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2190
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002191 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002192 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2193
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002194 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Tony Barbourf43b6982014-11-25 13:18:32 -07002195 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2196
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002197 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002198 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2199
2200 XglPipelineObj pipelineobj(m_device);
2201 pipelineobj.AddShader(&vs);
2202 pipelineobj.AddShader(&ps);
2203
2204 XglDescriptorSetObj descriptorSet(m_device);
2205 descriptorSet.AttachImageView(&texture1);
2206 descriptorSet.AttachSampler(&sampler1);
2207 descriptorSet.AttachImageView(&texture2);
2208 descriptorSet.AttachSampler(&sampler2);
2209 descriptorSet.AttachImageView(&texture3);
2210 descriptorSet.AttachSampler(&sampler3);
2211
2212 m_memoryRefManager.AddMemoryRef(&texture1);
2213 m_memoryRefManager.AddMemoryRef(&texture2);
2214 m_memoryRefManager.AddMemoryRef(&texture3);
2215
Tony Barbourdd4c9642015-01-09 12:55:14 -07002216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2217 XglCommandBufferObj cmdBuffer(m_device);
2218 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2219
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002220 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002221
2222 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2223
2224#ifdef DUMP_STATE_DOT
2225 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2226 pDSDumpDot((char*)"triTest2.dot");
2227#endif
2228 // render triangle
2229 cmdBuffer.Draw(0, 3, 0, 1);
2230
2231 // finalize recording of the command buffer
2232 cmdBuffer.EndCommandBuffer();
2233 cmdBuffer.QueueCommandBuffer(NULL, 0);
2234
2235 for (int i = 0; i < m_renderTargetCount; i++)
2236 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002237
2238}
2239
2240TEST_F(XglRenderTest, TriangleVSUniformBlock)
2241{
2242 // The expected result from this test is a blue triangle
2243
2244 static const char *vertShaderText =
2245 "#version 140\n"
2246 "#extension GL_ARB_separate_shader_objects : enable\n"
2247 "#extension GL_ARB_shading_language_420pack : enable\n"
2248 "layout (location = 0) out vec4 outColor;\n"
2249 "layout (std140, binding = 0) uniform bufferVals {\n"
2250 " vec4 red;\n"
2251 " vec4 green;\n"
2252 " vec4 blue;\n"
2253 " vec4 white;\n"
2254 "} myBufferVals;\n"
2255 "void main() {\n"
2256 " vec2 vertices[3];"
2257 " vertices[0] = vec2(-0.5, -0.5);\n"
2258 " vertices[1] = vec2( 0.5, -0.5);\n"
2259 " vertices[2] = vec2( 0.5, 0.5);\n"
2260 " outColor = myBufferVals.blue;\n"
2261 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2262 "}\n";
2263
2264 static const char *fragShaderText =
2265 "#version 140\n"
2266 "#extension GL_ARB_separate_shader_objects : enable\n"
2267 "#extension GL_ARB_shading_language_420pack : enable\n"
2268 "layout (location = 0) in vec4 inColor;\n"
2269 "void main() {\n"
2270 " gl_FragColor = inColor;\n"
2271 "}\n";
2272
2273 ASSERT_NO_FATAL_FAILURE(InitState());
2274 ASSERT_NO_FATAL_FAILURE(InitViewport());
2275
2276 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2277 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2278
2279 // Let's populate our buffer with the following:
2280 // vec4 red;
2281 // vec4 green;
2282 // vec4 blue;
2283 // vec4 white;
2284 const int valCount = 4 * 4;
2285 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2286 0.0, 1.0, 0.0, 1.0,
2287 0.0, 0.0, 1.0, 1.0,
2288 1.0, 1.0, 1.0, 1.0 };
2289
2290 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002291 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002292
2293 XglPipelineObj pipelineobj(m_device);
2294 pipelineobj.AddShader(&vs);
2295 pipelineobj.AddShader(&ps);
2296
2297 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002298 descriptorSet.AttachBufferView(&colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002299
Tony Barbourdd4c9642015-01-09 12:55:14 -07002300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2301 XglCommandBufferObj cmdBuffer(m_device);
2302 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2303
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002304 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002305
2306 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2307
2308#ifdef DUMP_STATE_DOT
2309 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2310 pDSDumpDot((char*)"triTest2.dot");
2311#endif
2312 // render triangle
2313 cmdBuffer.Draw(0, 3, 0, 1);
2314
2315 // finalize recording of the command buffer
2316 cmdBuffer.EndCommandBuffer();
2317 cmdBuffer.QueueCommandBuffer(NULL, 0);
2318
2319 for (int i = 0; i < m_renderTargetCount; i++)
2320 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002321
2322}
2323
2324TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2325{
2326 // This test allows the shader to select which buffer it is
2327 // pulling from using layout binding qualifier.
2328 // There are corresponding changes in the compiler stack that
2329 // will select the buffer using binding directly.
2330 // The binding number should match the slot number set up by
2331 // the application.
2332 // The expected result from this test is a purple triangle
2333
2334 static const char *vertShaderText =
2335 "#version 140\n"
2336 "#extension GL_ARB_separate_shader_objects : enable\n"
2337 "#extension GL_ARB_shading_language_420pack : enable\n"
2338 "void main() {\n"
2339 " vec2 vertices[3];"
2340 " vertices[0] = vec2(-0.5, -0.5);\n"
2341 " vertices[1] = vec2( 0.5, -0.5);\n"
2342 " vertices[2] = vec2( 0.5, 0.5);\n"
2343 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2344 "}\n";
2345
2346 static const char *fragShaderText =
2347 "#version 140\n"
2348 "#extension GL_ARB_separate_shader_objects : enable\n"
2349 "#extension GL_ARB_shading_language_420pack : enable\n"
2350 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2351 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2352 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2353 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2354 "void main() {\n"
2355 " gl_FragColor = myBlueVal.color;\n"
2356 " gl_FragColor += myRedVal.color;\n"
2357 "}\n";
2358
2359 ASSERT_NO_FATAL_FAILURE(InitState());
2360 ASSERT_NO_FATAL_FAILURE(InitViewport());
2361
2362 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2363 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2364
2365 // We're going to create a number of uniform buffers, and then allow
2366 // the shader to select which it wants to read from with a binding
2367
2368 // Let's populate the buffers with a single color each:
2369 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2370 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2371 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2372 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2373
2374 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2375 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2376 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2377 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2378
2379 const int redCount = sizeof(redVals) / sizeof(float);
2380 const int greenCount = sizeof(greenVals) / sizeof(float);
2381 const int blueCount = sizeof(blueVals) / sizeof(float);
2382 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2383
2384 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002385 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002386
2387 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002388 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002389
2390 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002391 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002392
2393 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002394 ps.BindShaderEntitySlotToBuffer(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002395
2396 XglPipelineObj pipelineobj(m_device);
2397 pipelineobj.AddShader(&vs);
2398 pipelineobj.AddShader(&ps);
2399
2400 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002401 descriptorSet.AttachBufferView(&redBuffer);
2402 descriptorSet.AttachBufferView(&greenBuffer);
2403 descriptorSet.AttachBufferView(&blueBuffer);
2404 descriptorSet.AttachBufferView(&whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002405
Tony Barbourdd4c9642015-01-09 12:55:14 -07002406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2407 XglCommandBufferObj cmdBuffer(m_device);
2408 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002409
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002410 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002411
2412 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2413
2414#ifdef DUMP_STATE_DOT
2415 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2416 pDSDumpDot((char*)"triTest2.dot");
2417#endif
2418 // render triangle
2419 cmdBuffer.Draw(0, 3, 0, 1);
2420
2421 // finalize recording of the command buffer
2422 cmdBuffer.EndCommandBuffer();
2423 cmdBuffer.QueueCommandBuffer(NULL, 0);
2424
2425 for (int i = 0; i < m_renderTargetCount; i++)
2426 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002427}
2428
2429TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2430{
2431 // This test is the same as TriangleFSUniformBlockBinding, but
2432 // it does not provide an instance name.
2433 // The expected result from this test is a purple triangle
2434
2435 static const char *vertShaderText =
2436 "#version 140\n"
2437 "#extension GL_ARB_separate_shader_objects : enable\n"
2438 "#extension GL_ARB_shading_language_420pack : enable\n"
2439 "void main() {\n"
2440 " vec2 vertices[3];"
2441 " vertices[0] = vec2(-0.5, -0.5);\n"
2442 " vertices[1] = vec2( 0.5, -0.5);\n"
2443 " vertices[2] = vec2( 0.5, 0.5);\n"
2444 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2445 "}\n";
2446
2447 static const char *fragShaderText =
2448 "#version 430\n"
2449 "#extension GL_ARB_separate_shader_objects : enable\n"
2450 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002451 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2452 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2453 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2454 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002455 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002456 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002457 " outColor = blue;\n"
2458 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002459 "}\n";
2460 ASSERT_NO_FATAL_FAILURE(InitState());
2461 ASSERT_NO_FATAL_FAILURE(InitViewport());
2462
2463 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2464 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2465
2466 // We're going to create a number of uniform buffers, and then allow
2467 // the shader to select which it wants to read from with a binding
2468
2469 // Let's populate the buffers with a single color each:
2470 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2471 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2472 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2473 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2474
2475 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2476 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2477 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2478 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2479
2480 const int redCount = sizeof(redVals) / sizeof(float);
2481 const int greenCount = sizeof(greenVals) / sizeof(float);
2482 const int blueCount = sizeof(blueVals) / sizeof(float);
2483 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2484
2485 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002486 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002487
2488 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002489 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002490
2491 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002492 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002493
2494 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002495 ps.BindShaderEntitySlotToBuffer(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002496
2497 XglPipelineObj pipelineobj(m_device);
2498 pipelineobj.AddShader(&vs);
2499 pipelineobj.AddShader(&ps);
2500
2501 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002502 descriptorSet.AttachBufferView(&redBuffer);
2503 descriptorSet.AttachBufferView(&greenBuffer);
2504 descriptorSet.AttachBufferView(&blueBuffer);
2505 descriptorSet.AttachBufferView(&whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002506
Tony Barbourdd4c9642015-01-09 12:55:14 -07002507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2508 XglCommandBufferObj cmdBuffer(m_device);
2509 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2510
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002511 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002512
2513 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2514
2515#ifdef DUMP_STATE_DOT
2516 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2517 pDSDumpDot((char*)"triTest2.dot");
2518#endif
2519 // render triangle
2520 cmdBuffer.Draw(0, 3, 0, 1);
2521
2522 // finalize recording of the command buffer
2523 cmdBuffer.EndCommandBuffer();
2524 cmdBuffer.QueueCommandBuffer(NULL, 0);
2525
2526 for (int i = 0; i < m_renderTargetCount; i++)
2527 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
2529}
2530
2531TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2532{
2533 static const char *vertShaderText =
2534 "#version 140\n"
2535 "#extension GL_ARB_separate_shader_objects : enable\n"
2536 "#extension GL_ARB_shading_language_420pack : enable\n"
2537 "layout (std140, binding=0) uniform bufferVals {\n"
2538 " mat4 mvp;\n"
2539 "} myBufferVals;\n"
2540 "layout (location=0) in vec4 pos;\n"
2541 "layout (location=0) out vec2 UV;\n"
2542 "void main() {\n"
2543 " vec2 positions[3];"
2544 " positions[0] = vec2( 0.0, 0.0);\n"
2545 " positions[1] = vec2( 0.25, 0.1);\n"
2546 " positions[2] = vec2( 0.1, 0.25);\n"
2547 " UV = positions[gl_VertexID % 3];\n"
2548 " gl_Position = myBufferVals.mvp * pos;\n"
2549 "}\n";
2550
2551 static const char *fragShaderText =
2552 "#version 140\n"
2553 "#extension GL_ARB_separate_shader_objects : enable\n"
2554 "#extension GL_ARB_shading_language_420pack : enable\n"
2555 "layout (binding=0) uniform sampler2D surface;\n"
2556 "layout (location=0) out vec4 outColor;\n"
2557 "layout (location=0) in vec2 UV;\n"
2558 "void main() {\n"
2559 " outColor= textureLod(surface, UV, 0.0);\n"
2560 "}\n";
2561 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2562
2563 glm::mat4 View = glm::lookAt(
2564 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2565 glm::vec3(0,0,0), // and looks at the origin
2566 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2567 );
2568
2569 glm::mat4 Model = glm::mat4(1.0f);
2570
2571 glm::mat4 MVP = Projection * View * Model;
2572
2573
2574 ASSERT_NO_FATAL_FAILURE(InitState());
2575 ASSERT_NO_FATAL_FAILURE(InitViewport());
2576 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2577
2578 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2579 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002580 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002581
2582 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2583
2584 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2585 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2586 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2587 XglSamplerObj sampler(m_device);
2588 XglTextureObj texture(m_device);
2589
Chia-I Wu714df452015-01-01 07:55:04 +08002590 // vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2591 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002592 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002593 ps.BindShaderEntitySlotToSampler(0, &sampler);
2594
2595 XglPipelineObj pipelineobj(m_device);
2596 pipelineobj.AddShader(&vs);
2597 pipelineobj.AddShader(&ps);
2598
2599 XglDescriptorSetObj descriptorSet(m_device);
2600
Chia-I Wu714df452015-01-01 07:55:04 +08002601 descriptorSet.AttachBufferView(&mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002602 descriptorSet.AttachImageView(&texture);
2603 descriptorSet.AttachSampler(&sampler);
2604
2605 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2606 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2607 m_memoryRefManager.AddMemoryRef(&texture);
2608
2609 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2610 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2611 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2612 };
2613
2614 // this is the current description of g_vbData
2615 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2616 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2617 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2618 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2619 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2620 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2621 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2622 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2623 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2624
2625 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2626 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2627 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2628
Tony Barbourfa6cac72015-01-16 14:27:35 -07002629 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2630 ds_state.depthTestEnable = XGL_TRUE;
2631 ds_state.depthWriteEnable = XGL_TRUE;
2632 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2633 ds_state.depthBoundsEnable = XGL_FALSE;
2634 ds_state.stencilTestEnable = XGL_FALSE;
2635 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2636 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2637 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2638 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2639 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2640 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2641 ds_state.front = ds_state.back;
2642 pipelineobj.SetDepthStencil(&ds_state);
2643
Tony Barbourdd4c9642015-01-09 12:55:14 -07002644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2645 XglCommandBufferObj cmdBuffer(m_device);
2646 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002647
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002648 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002649 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2650
2651 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2652#ifdef DUMP_STATE_DOT
2653 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2654 pDSDumpDot((char*)"triTest2.dot");
2655#endif
2656 // render triangle
2657 cmdBuffer.Draw(0, 36, 0, 1);
2658
2659 // finalize recording of the command buffer
2660 cmdBuffer.EndCommandBuffer();
2661 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2662
2663 for (int i = 0; i < m_renderTargetCount; i++)
2664 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002665
2666}
Cody Northropd1ce7842014-12-09 11:17:01 -07002667
2668TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2669{
2670 // This test mixes binding slots of textures and buffers, ensuring
2671 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002672 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002673 // you can modify it to move the desired result around.
2674
2675 static const char *vertShaderText =
2676 "#version 140\n"
2677 "#extension GL_ARB_separate_shader_objects : enable\n"
2678 "#extension GL_ARB_shading_language_420pack : enable\n"
2679 "void main() {\n"
2680 " vec2 vertices[3];"
2681 " vertices[0] = vec2(-0.5, -0.5);\n"
2682 " vertices[1] = vec2( 0.5, -0.5);\n"
2683 " vertices[2] = vec2( 0.5, 0.5);\n"
2684 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2685 "}\n";
2686
2687 static const char *fragShaderText =
2688 "#version 430\n"
2689 "#extension GL_ARB_separate_shader_objects : enable\n"
2690 "#extension GL_ARB_shading_language_420pack : enable\n"
2691 "layout (binding = 0) uniform sampler2D surface0;\n"
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002692 "layout (binding = 9) uniform sampler2D surface1;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002693 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropa0410942014-12-09 13:59:39 -07002694 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002695
Cody Northropa0410942014-12-09 13:59:39 -07002696
2697 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2698 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2699 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2700 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002701 "layout (location = 0) out vec4 outColor;\n"
2702 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002703 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002704 " outColor += white * vec4(0.00001);\n"
2705 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002706 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002707 "}\n";
2708 ASSERT_NO_FATAL_FAILURE(InitState());
2709 ASSERT_NO_FATAL_FAILURE(InitViewport());
2710
2711 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2712 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2713
Cody Northropd1ce7842014-12-09 11:17:01 -07002714 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2715 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2716 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2717 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2718
2719 const int redCount = sizeof(redVals) / sizeof(float);
2720 const int greenCount = sizeof(greenVals) / sizeof(float);
2721 const int blueCount = sizeof(blueVals) / sizeof(float);
2722 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2723
2724 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002725 ps.BindShaderEntitySlotToBuffer(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002726
2727 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002728 ps.BindShaderEntitySlotToBuffer(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002729
2730 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002731 ps.BindShaderEntitySlotToBuffer(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002732
2733 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002734 ps.BindShaderEntitySlotToBuffer(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002735
2736 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002737 XglTextureObj texture0(m_device); // Light Red
2738 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002739 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
Cody Northropd1ce7842014-12-09 11:17:01 -07002740 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2741 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002742 XglTextureObj texture2(m_device); // Light Blue
2743 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002744 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Cody Northropd1ce7842014-12-09 11:17:01 -07002745 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2746 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002747 XglTextureObj texture4(m_device); // Light Green
2748 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002749 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
Cody Northropd1ce7842014-12-09 11:17:01 -07002750 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002751
2752 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2753 // TODO: Get back here ASAP and understand why.
2754 XglSamplerObj sampler7(m_device);
2755 XglTextureObj texture7(m_device); // Red and Blue
2756 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002757 ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2758 ps.BindShaderEntitySlotToSampler(9, &sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002759
2760
2761 XglPipelineObj pipelineobj(m_device);
2762 pipelineobj.AddShader(&vs);
2763 pipelineobj.AddShader(&ps);
2764
2765 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002766 descriptorSet.AttachBufferView(&redBuffer);
2767 descriptorSet.AttachBufferView(&greenBuffer);
2768 descriptorSet.AttachBufferView(&blueBuffer);
2769 descriptorSet.AttachBufferView(&whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002770 descriptorSet.AttachImageView(&texture0);
2771 descriptorSet.AttachSampler(&sampler0);
2772 descriptorSet.AttachImageView(&texture2);
2773 descriptorSet.AttachSampler(&sampler2);
2774 descriptorSet.AttachImageView(&texture4);
2775 descriptorSet.AttachSampler(&sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002776 descriptorSet.AttachImageView(&texture7);
2777 descriptorSet.AttachSampler(&sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002778
2779 m_memoryRefManager.AddMemoryRef(&texture0);
2780 m_memoryRefManager.AddMemoryRef(&texture2);
2781 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002782 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002783
Tony Barbourdd4c9642015-01-09 12:55:14 -07002784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2785 XglCommandBufferObj cmdBuffer(m_device);
2786 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002787
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002788 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002789
2790 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2791
2792#ifdef DUMP_STATE_DOT
2793 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2794 pDSDumpDot((char*)"triTest2.dot");
2795#endif
2796 // render triangle
2797 cmdBuffer.Draw(0, 3, 0, 1);
2798
2799 // finalize recording of the command buffer
2800 cmdBuffer.EndCommandBuffer();
2801 cmdBuffer.QueueCommandBuffer(NULL, 0);
2802
2803 for (int i = 0; i < m_renderTargetCount; i++)
2804 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002805
2806}
2807
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002808TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2809{
2810 // This test matches binding slots of textures and buffers, requiring
2811 // the driver to give them distinct number spaces.
2812 // The expected result from this test is a red triangle, although
2813 // you can modify it to move the desired result around.
2814
2815 static const char *vertShaderText =
2816 "#version 140\n"
2817 "#extension GL_ARB_separate_shader_objects : enable\n"
2818 "#extension GL_ARB_shading_language_420pack : enable\n"
2819 "void main() {\n"
2820 " vec2 vertices[3];"
2821 " vertices[0] = vec2(-0.5, -0.5);\n"
2822 " vertices[1] = vec2( 0.5, -0.5);\n"
2823 " vertices[2] = vec2( 0.5, 0.5);\n"
2824 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2825 "}\n";
2826
2827 static const char *fragShaderText =
2828 "#version 430\n"
2829 "#extension GL_ARB_separate_shader_objects : enable\n"
2830 "#extension GL_ARB_shading_language_420pack : enable\n"
2831 "layout (binding = 0) uniform sampler2D surface0;\n"
2832 "layout (binding = 1) uniform sampler2D surface1;\n"
2833 "layout (binding = 2) uniform sampler2D surface2;\n"
2834 "layout (binding = 3) uniform sampler2D surface3;\n"
2835 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2836 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2837 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2838 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2839 "layout (location = 0) out vec4 outColor;\n"
2840 "void main() {\n"
2841 " outColor = red;// * vec4(0.00001);\n"
2842 " outColor += white * vec4(0.00001);\n"
2843 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2844 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2845 "}\n";
2846 ASSERT_NO_FATAL_FAILURE(InitState());
2847 ASSERT_NO_FATAL_FAILURE(InitViewport());
2848
2849 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2850 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2851
2852 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2853 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2854 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2855 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2856
2857 const int redCount = sizeof(redVals) / sizeof(float);
2858 const int greenCount = sizeof(greenVals) / sizeof(float);
2859 const int blueCount = sizeof(blueVals) / sizeof(float);
2860 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2861
2862 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002863 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002864
2865 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002866 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002867
2868 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002869 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002870
2871 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002872 ps.BindShaderEntitySlotToBuffer(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002873
2874 XglSamplerObj sampler0(m_device);
2875 XglTextureObj texture0(m_device); // Light Red
2876 texture0.ChangeColors(0xff800000,0xff800000);
2877 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
2878 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2879 XglSamplerObj sampler2(m_device);
2880 XglTextureObj texture2(m_device); // Light Blue
2881 texture2.ChangeColors(0xff000080,0xff000080);
2882 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
2883 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2884 XglSamplerObj sampler4(m_device);
2885 XglTextureObj texture4(m_device); // Light Green
2886 texture4.ChangeColors(0xff008000,0xff008000);
2887 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
2888 ps.BindShaderEntitySlotToSampler(2, &sampler4);
2889 XglSamplerObj sampler7(m_device);
2890 XglTextureObj texture7(m_device); // Red and Blue
2891 texture7.ChangeColors(0xffff00ff,0xffff00ff);
2892 ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2893 ps.BindShaderEntitySlotToSampler(3, &sampler7);
2894
2895
2896 XglPipelineObj pipelineobj(m_device);
2897 pipelineobj.AddShader(&vs);
2898 pipelineobj.AddShader(&ps);
2899
2900 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002901 descriptorSet.AttachBufferView(&redBuffer);
2902 descriptorSet.AttachBufferView(&greenBuffer);
2903 descriptorSet.AttachBufferView(&blueBuffer);
2904 descriptorSet.AttachBufferView(&whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002905 descriptorSet.AttachImageView(&texture0);
2906 descriptorSet.AttachSampler(&sampler0);
2907 descriptorSet.AttachImageView(&texture2);
2908 descriptorSet.AttachSampler(&sampler2);
2909 descriptorSet.AttachImageView(&texture4);
2910 descriptorSet.AttachSampler(&sampler4);
2911 descriptorSet.AttachImageView(&texture7);
2912 descriptorSet.AttachSampler(&sampler7);
2913
2914 m_memoryRefManager.AddMemoryRef(&texture0);
2915 m_memoryRefManager.AddMemoryRef(&texture2);
2916 m_memoryRefManager.AddMemoryRef(&texture4);
2917 m_memoryRefManager.AddMemoryRef(&texture7);
2918
Tony Barbourdd4c9642015-01-09 12:55:14 -07002919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2920 XglCommandBufferObj cmdBuffer(m_device);
2921 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002922
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002923 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002924
2925 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2926
2927#ifdef DUMP_STATE_DOT
2928 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2929 pDSDumpDot((char*)"triTest2.dot");
2930#endif
2931 // render triangle
2932 cmdBuffer.Draw(0, 3, 0, 1);
2933
2934 // finalize recording of the command buffer
2935 cmdBuffer.EndCommandBuffer();
2936 cmdBuffer.QueueCommandBuffer(NULL, 0);
2937
2938 for (int i = 0; i < m_renderTargetCount; i++)
2939 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002940
2941}
2942
Cody Northrop02690bd2014-12-17 15:26:33 -07002943TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2944{
2945 // This test populates a buffer with a variety of different data
2946 // types, then reads them out with a shader.
2947 // The expected result from this test is a green triangle
2948
2949 static const char *vertShaderText =
2950 "#version 140\n"
2951 "#extension GL_ARB_separate_shader_objects : enable\n"
2952 "#extension GL_ARB_shading_language_420pack : enable\n"
2953 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2954 " vec4 fRed;\n"
2955 " vec4 fGreen;\n"
2956 " layout(row_major) mat4 worldToProj;\n"
2957 " layout(row_major) mat4 projToWorld;\n"
2958 " layout(row_major) mat4 worldToView;\n"
2959 " layout(row_major) mat4 viewToProj;\n"
2960 " layout(row_major) mat4 worldToShadow[4];\n"
2961 " float fZero;\n"
2962 " float fOne;\n"
2963 " float fTwo;\n"
2964 " float fThree;\n"
2965 " vec3 fZeroZeroZero;\n"
2966 " float fFour;\n"
2967 " vec3 fZeroZeroOne;\n"
2968 " float fFive;\n"
2969 " vec3 fZeroOneZero;\n"
2970 " float fSix;\n"
2971 " float fSeven;\n"
2972 " float fEight;\n"
2973 " float fNine;\n"
2974 " vec2 fZeroZero;\n"
2975 " vec2 fZeroOne;\n"
2976 " vec4 fBlue;\n"
2977 " vec2 fOneZero;\n"
2978 " vec2 fOneOne;\n"
2979 " vec3 fZeroOneOne;\n"
2980 " float fTen;\n"
2981 " float fEleven;\n"
2982 " float fTwelve;\n"
2983 " vec3 fOneZeroZero;\n"
2984 " vec4 uvOffsets[4];\n"
2985 "};\n"
2986 "layout (location = 0) out vec4 color;"
2987 "void main() {\n"
2988
2989 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2990 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2991 " \n"
2992
2993 // do some exact comparisons, even though we should
2994 // really have an epsilon involved.
2995 " vec4 outColor = right;\n"
2996 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2997 " outColor = wrong;\n"
2998 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2999 " outColor = wrong;\n"
3000 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3001 " outColor = wrong;\n"
3002
3003 " color = outColor;\n"
3004
3005 // generic position stuff
3006 " vec2 vertices;\n"
3007 " int vertexSelector = gl_VertexID;\n"
3008 " if (vertexSelector == 0)\n"
3009 " vertices = vec2(-0.5, -0.5);\n"
3010 " else if (vertexSelector == 1)\n"
3011 " vertices = vec2( 0.5, -0.5);\n"
3012 " else if (vertexSelector == 2)\n"
3013 " vertices = vec2( 0.5, 0.5);\n"
3014 " else\n"
3015 " vertices = vec2( 0.0, 0.0);\n"
3016 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3017 "}\n";
3018
3019 static const char *fragShaderText =
3020 "#version 140\n"
3021 "#extension GL_ARB_separate_shader_objects : enable\n"
3022 "#extension GL_ARB_shading_language_420pack : enable\n"
3023 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3024 " vec4 fRed;\n"
3025 " vec4 fGreen;\n"
3026 " layout(row_major) mat4 worldToProj;\n"
3027 " layout(row_major) mat4 projToWorld;\n"
3028 " layout(row_major) mat4 worldToView;\n"
3029 " layout(row_major) mat4 viewToProj;\n"
3030 " layout(row_major) mat4 worldToShadow[4];\n"
3031 " float fZero;\n"
3032 " float fOne;\n"
3033 " float fTwo;\n"
3034 " float fThree;\n"
3035 " vec3 fZeroZeroZero;\n"
3036 " float fFour;\n"
3037 " vec3 fZeroZeroOne;\n"
3038 " float fFive;\n"
3039 " vec3 fZeroOneZero;\n"
3040 " float fSix;\n"
3041 " float fSeven;\n"
3042 " float fEight;\n"
3043 " float fNine;\n"
3044 " vec2 fZeroZero;\n"
3045 " vec2 fZeroOne;\n"
3046 " vec4 fBlue;\n"
3047 " vec2 fOneZero;\n"
3048 " vec2 fOneOne;\n"
3049 " vec3 fZeroOneOne;\n"
3050 " float fTen;\n"
3051 " float fEleven;\n"
3052 " float fTwelve;\n"
3053 " vec3 fOneZeroZero;\n"
3054 " vec4 uvOffsets[4];\n"
3055 "};\n"
3056 "layout (location = 0) in vec4 color;\n"
3057 "void main() {\n"
3058 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3059 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3060 " \n"
3061
3062 // start with VS value to ensure it passed
3063 " vec4 outColor = color;\n"
3064
3065 // do some exact comparisons, even though we should
3066 // really have an epsilon involved.
3067 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3068 " outColor = wrong;\n"
3069 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3070 " outColor = wrong;\n"
3071 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3072 " outColor = wrong;\n"
3073 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3074 " outColor = wrong;\n"
3075 " if (fTwo != 2.0)\n"
3076 " outColor = wrong;\n"
3077 " if (fOneOne != vec2(1.0, 1.0))\n"
3078 " outColor = wrong;\n"
3079 " if (fTen != 10.0)\n"
3080 " outColor = wrong;\n"
3081 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3082 " outColor = wrong;\n"
3083 " \n"
3084 " gl_FragColor = outColor;\n"
3085 "}\n";
3086
3087
3088 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3089 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3090 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3091 0.0, 1.0, 0.0, 1.0, // align
3092 0.0, 0.0, 1.0, 1.0, // align
3093 0.0, 0.0, 0.0, 1.0, // align
3094 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3095 0.0, 2.0, 0.0, 2.0, // align
3096 0.0, 0.0, 2.0, 2.0, // align
3097 0.0, 0.0, 0.0, 2.0, // align
3098 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3099 0.0, 3.0, 0.0, 3.0, // align
3100 0.0, 0.0, 3.0, 3.0, // align
3101 0.0, 0.0, 0.0, 3.0, // align
3102 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3103 0.0, 4.0, 0.0, 4.0, // align
3104 0.0, 0.0, 4.0, 4.0, // align
3105 0.0, 0.0, 0.0, 4.0, // align
3106 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3107 0.0, 5.0, 0.0, 5.0, // align
3108 0.0, 0.0, 5.0, 5.0, // align
3109 0.0, 0.0, 0.0, 5.0, // align
3110 6.0, 0.0, 0.0, 6.0, // align
3111 0.0, 6.0, 0.0, 6.0, // align
3112 0.0, 0.0, 6.0, 6.0, // align
3113 0.0, 0.0, 0.0, 6.0, // align
3114 7.0, 0.0, 0.0, 7.0, // align
3115 0.0, 7.0, 0.0, 7.0, // align
3116 0.0, 0.0, 7.0, 7.0, // align
3117 0.0, 0.0, 0.0, 7.0, // align
3118 8.0, 0.0, 0.0, 8.0, // align
3119 0.0, 8.0, 0.0, 8.0, // align
3120 0.0, 0.0, 8.0, 8.0, // align
3121 0.0, 0.0, 0.0, 8.0, // align
3122 0.0, // float fZero; // align
3123 1.0, // float fOne; // pack
3124 2.0, // float fTwo; // pack
3125 3.0, // float fThree; // pack
3126 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3127 4.0, // float fFour; // pack
3128 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3129 5.0, // float fFive; // pack
3130 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3131 6.0, // float fSix; // pack
3132 7.0, // float fSeven; // align
3133 8.0, // float fEight; // pack
3134 9.0, // float fNine; // pack
3135 0.0, // BUFFER
3136 0.0, 0.0, // vec2 fZeroZero; // align
3137 0.0, 1.0, // vec2 fZeroOne; // pack
3138 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3139 1.0, 0.0, // vec2 fOneZero; // align
3140 1.0, 1.0, // vec2 fOneOne; // pack
3141 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3142 10.0, // float fTen; // pack
3143 11.0, // float fEleven; // align
3144 12.0, // float fTwelve; // pack
3145 0.0, 0.0, // BUFFER
3146 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3147 0.0, // BUFFER
3148 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3149 0.5, 0.6, 0.7, 0.8, // align
3150 0.9, 1.0, 1.1, 1.2, // align
3151 1.3, 1.4, 1.5, 1.6, // align
3152 };
3153
3154 ASSERT_NO_FATAL_FAILURE(InitState());
3155 ASSERT_NO_FATAL_FAILURE(InitViewport());
3156
3157 const int constCount = sizeof(mixedVals) / sizeof(float);
3158
3159 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3160 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3161
3162 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Chia-I Wu714df452015-01-01 07:55:04 +08003163 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mixedBuffer);
3164 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003165
3166 XglPipelineObj pipelineobj(m_device);
3167 pipelineobj.AddShader(&vs);
3168 pipelineobj.AddShader(&ps);
3169
3170 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08003171 descriptorSet.AttachBufferView(&mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003172
3173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3174 XglCommandBufferObj cmdBuffer(m_device);
3175 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3176
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003177 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003178
3179 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3180
3181#ifdef DUMP_STATE_DOT
3182 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3183 pDSDumpDot((char*)"triTest2.dot");
3184#endif
3185 // render triangle
3186 cmdBuffer.Draw(0, 3, 0, 1);
3187
3188 // finalize recording of the command buffer
3189 cmdBuffer.EndCommandBuffer();
3190 cmdBuffer.QueueCommandBuffer(NULL, 0);
3191
3192 for (int i = 0; i < m_renderTargetCount; i++)
3193 RecordImage(m_renderTargets[i]);
3194}
3195
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003196int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003197 int result;
3198
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003199 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003200 XglTestFramework::InitArgs(&argc, argv);
3201
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003202 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003203
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003204 result = RUN_ALL_TESTS();
3205
3206 XglTestFramework::Finish();
3207 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003208}