blob: fb54b698401ed7c979604a5e2e0f4e2bdad9f56b [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;
416 m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
417 m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
418}
419
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600420struct xgltriangle_vs_uniform {
421 // Must start with MVP
422 XGL_FLOAT mvp[4][4];
423 XGL_FLOAT position[3][4];
424 XGL_FLOAT color[3][4];
425};
426
Tony Barbourae442072015-01-12 13:27:11 -0700427void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600428{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700429#ifdef DEBUG_CALLBACK
430 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
431#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600432 // Create identity matrix
433 int i;
434 struct xgltriangle_vs_uniform data;
435
436 glm::mat4 Projection = glm::mat4(1.0f);
437 glm::mat4 View = glm::mat4(1.0f);
438 glm::mat4 Model = glm::mat4(1.0f);
439 glm::mat4 MVP = Projection * View * Model;
440 const int matrixSize = sizeof(MVP);
441 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
442 memcpy(&data.mvp, &MVP[0][0], matrixSize);
443
444 static const Vertex tri_data[] =
445 {
446 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
447 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
448 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
449 };
450
451 for (i=0; i<3; i++) {
452 data.position[i][0] = tri_data[i].posX;
453 data.position[i][1] = tri_data[i].posY;
454 data.position[i][2] = tri_data[i].posZ;
455 data.position[i][3] = tri_data[i].posW;
456 data.color[i][0] = tri_data[i].r;
457 data.color[i][1] = tri_data[i].g;
458 data.color[i][2] = tri_data[i].b;
459 data.color[i][3] = tri_data[i].a;
460 }
461
Tony Barbourf43b6982014-11-25 13:18:32 -0700462 ASSERT_NO_FATAL_FAILURE(InitState());
463 ASSERT_NO_FATAL_FAILURE(InitViewport());
464
465 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
466
467 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
468 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Chia-I Wu714df452015-01-01 07:55:04 +0800469 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700470
471 XglPipelineObj pipelineobj(m_device);
472 pipelineobj.AddShader(&vs);
473 pipelineobj.AddShader(&ps);
474
475 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +0800476 descriptorSet.AttachBufferView(&constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700477 m_memoryRefManager.AddMemoryRef(&constantBuffer);
478
Tony Barbour71ba3612015-01-09 16:12:35 -0700479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
480 XglCommandBufferObj cmdBuffer(m_device);
481 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700482
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700483 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700484
485 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
486
487 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
488#ifdef DUMP_STATE_DOT
489 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
490 pDSDumpDot((char*)"triTest2.dot");
491#endif
492 // render triangle
493 cmdBuffer.Draw(0, 3, 0, 1);
494
495 // finalize recording of the command buffer
496 cmdBuffer.EndCommandBuffer();
497 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
498
499 for (int i = 0; i < m_renderTargetCount; i++)
500 RecordImage(m_renderTargets[i]);
501
502 if (rotate)
503 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
504
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700505#ifdef PRINT_OBJECTS
506 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
507 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
508 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
509 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
510 printf("DEBUG : Number of Objects : %lu\n", numObjects);
511 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
512 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
513 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
514 for (i=0; i < numObjects; i++) {
515 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);
516 }
517 free(pObjNodeArray);
518#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700519
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600520}
521
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600522TEST_F(XglRenderTest, XGLTriangle_FragColor)
523{
524 static const char *vertShaderText =
525 "#version 140\n"
526 "#extension GL_ARB_separate_shader_objects : enable\n"
527 "#extension GL_ARB_shading_language_420pack : enable\n"
528 "\n"
529 "layout(binding = 0) uniform buf {\n"
530 " mat4 MVP;\n"
531 " vec4 position[3];\n"
532 " vec4 color[3];\n"
533 "} ubuf;\n"
534 "\n"
535 "layout (location = 0) out vec4 outColor;\n"
536 "\n"
537 "void main() \n"
538 "{\n"
539 " outColor = ubuf.color[gl_VertexID];\n"
540 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
541 "}\n";
542
543 static const char *fragShaderText =
544 "#version 140\n"
545 "#extension GL_ARB_separate_shader_objects : enable\n"
546 "#extension GL_ARB_shading_language_420pack : enable\n"
547 "\n"
548 "layout (location = 0) in vec4 inColor;\n"
549 "\n"
550 "void main()\n"
551 "{\n"
552 " gl_FragColor = inColor;\n"
553 "}\n";
554
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600555 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700556 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600557}
558
559TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
560{
561 static const char *vertShaderText =
562 "#version 140\n"
563 "#extension GL_ARB_separate_shader_objects : enable\n"
564 "#extension GL_ARB_shading_language_420pack : enable\n"
565 "\n"
566 "layout(binding = 0) uniform buf {\n"
567 " mat4 MVP;\n"
568 " vec4 position[3];\n"
569 " vec4 color[3];\n"
570 "} ubuf;\n"
571 "\n"
572 "layout (location = 0) out vec4 outColor;\n"
573 "\n"
574 "void main() \n"
575 "{\n"
576 " outColor = ubuf.color[gl_VertexID];\n"
577 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
578 "}\n";
579
580 static const char *fragShaderText =
581 "#version 140\n"
582 "#extension GL_ARB_separate_shader_objects : enable\n"
583 "#extension GL_ARB_shading_language_420pack : enable\n"
584 "\n"
585 "layout (location = 0) in vec4 inColor;\n"
586 "layout (location = 0) out vec4 outColor;\n"
587 "\n"
588 "void main()\n"
589 "{\n"
590 " outColor = inColor;\n"
591 "}\n";
592
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600593 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 -0600594
Tony Barbourae442072015-01-12 13:27:11 -0700595 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600596}
597
Tony Barbourf43b6982014-11-25 13:18:32 -0700598TEST_F(XglRenderTest, BIL_XGLTriangle)
599{
600 bool saved_use_bil = XglTestFramework::m_use_bil;
601
602 static const char *vertShaderText =
603 "#version 140\n"
604 "#extension GL_ARB_separate_shader_objects : enable\n"
605 "#extension GL_ARB_shading_language_420pack : enable\n"
606 "\n"
607 "layout(binding = 0) uniform buf {\n"
608 " mat4 MVP;\n"
609 " vec4 position[3];\n"
610 " vec4 color[3];\n"
611 "} ubuf;\n"
612 "\n"
613 "layout (location = 0) out vec4 outColor;\n"
614 "\n"
615 "void main() \n"
616 "{\n"
617 " outColor = ubuf.color[gl_VertexID];\n"
618 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
619 "}\n";
620
621 static const char *fragShaderText =
622 "#version 140\n"
623 "#extension GL_ARB_separate_shader_objects : enable\n"
624 "#extension GL_ARB_shading_language_420pack : enable\n"
625 "\n"
626 "layout (location = 0) in vec4 inColor;\n"
627 "\n"
628 "void main()\n"
629 "{\n"
630 " gl_FragColor = inColor;\n"
631 "}\n";
632
633 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
634
635 XglTestFramework::m_use_bil = true;
636
Tony Barbourae442072015-01-12 13:27:11 -0700637 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700638
639 XglTestFramework::m_use_bil = saved_use_bil;
640}
641
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600642TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600643{
644 static const char *vertShaderText =
645 "#version 130\n"
646 "vec2 vertices[3];\n"
647 "void main() {\n"
648 " vertices[0] = vec2(-1.0, -1.0);\n"
649 " vertices[1] = vec2( 1.0, -1.0);\n"
650 " vertices[2] = vec2( 0.0, 1.0);\n"
651 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
652 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600653
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600654 static const char *fragShaderText =
655 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600656 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600657 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600658 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600659
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600660 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
661
Tony Barbourae442072015-01-12 13:27:11 -0700662 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600663}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600664
Tony Barbourf43b6982014-11-25 13:18:32 -0700665TEST_F(XglRenderTest, BIL_GreenTriangle)
666{
667 bool saved_use_bil = XglTestFramework::m_use_bil;
668
669 static const char *vertShaderText =
670 "#version 130\n"
671 "vec2 vertices[3];\n"
672 "void main() {\n"
673 " vertices[0] = vec2(-1.0, -1.0);\n"
674 " vertices[1] = vec2( 1.0, -1.0);\n"
675 " vertices[2] = vec2( 0.0, 1.0);\n"
676 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
677 "}\n";
678
679 static const char *fragShaderText =
680 "#version 130\n"
681 "void main() {\n"
682 " gl_FragColor = vec4(0,1,0,1);\n"
683 "}\n";
684
685 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
686
687 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700688 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700689 XglTestFramework::m_use_bil = saved_use_bil;
690}
691
692TEST_F(XglRenderTest, YellowTriangle)
693{
694 static const char *vertShaderText =
695 "#version 130\n"
696 "void main() {\n"
697 " vec2 vertices[3];"
698 " vertices[0] = vec2(-0.5, -0.5);\n"
699 " vertices[1] = vec2( 0.5, -0.5);\n"
700 " vertices[2] = vec2( 0.5, 0.5);\n"
701 " vec4 colors[3];\n"
702 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
703 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
704 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
705 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
706 "}\n";
707
708 static const char *fragShaderText =
709 "#version 130\n"
710 "void main() {\n"
711 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
712 "}\n";
713
Tony Barbourae442072015-01-12 13:27:11 -0700714 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700715}
716
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600717TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600718{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600719 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700720 "#version 130\n"
721 //XYZ1( -1, -1, -1 )
722 "in vec4 pos;\n"
723 //XYZ1( 0.f, 0.f, 0.f )
724 "in vec4 inColor;\n"
725 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600726 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600727 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600728 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600729 "}\n";
730
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600731
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600732 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700733 "#version 140\n"
734 "#extension GL_ARB_separate_shader_objects : enable\n"
735 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700736 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700737 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600738 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700739 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600740 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600741
Tony Barbourf43b6982014-11-25 13:18:32 -0700742
743
744 ASSERT_NO_FATAL_FAILURE(InitState());
745 ASSERT_NO_FATAL_FAILURE(InitViewport());
746
747 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +0800748 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -0700749
750 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
751 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
752
753 XglPipelineObj pipelineobj(m_device);
754 pipelineobj.AddShader(&vs);
755 pipelineobj.AddShader(&ps);
756
757 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +0800758 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700759
760 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
761 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
762 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
763 };
764
765 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
766 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
767 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
768 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
769 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
770 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
771 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
772 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
773 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
774
775 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
776 pipelineobj.AddVertexInputBindings(&vi_binding,1);
777 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
778
Tony Barboure4ed9942015-01-09 10:06:53 -0700779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
780 XglCommandBufferObj cmdBuffer(m_device);
781 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700782
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700783 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700784 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
785
Tony Barboure4ed9942015-01-09 10:06:53 -0700786 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
787
788 // render two triangles
789 cmdBuffer.Draw(0, 6, 0, 1);
790
791 // finalize recording of the command buffer
792 cmdBuffer.EndCommandBuffer();
793 cmdBuffer.QueueCommandBuffer(NULL, 0);
794
795 for (int i = 0; i < m_renderTargetCount; i++)
796 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600797}
798
Chia-I Wue09d1a72014-12-05 10:32:23 +0800799TEST_F(XglRenderTest, TriangleMRT)
800{
801 static const char *vertShaderText =
802 "#version 130\n"
803 "in vec4 pos;\n"
804 "void main() {\n"
805 " gl_Position = pos;\n"
806 "}\n";
807
808 static const char *fragShaderText =
809 "#version 130\n"
810 "void main() {\n"
811 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
812 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
813 "}\n";
814 const XGL_FLOAT vb_data[][2] = {
815 { -1.0f, -1.0f },
816 { 1.0f, -1.0f },
817 { -1.0f, 1.0f }
818 };
819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821 ASSERT_NO_FATAL_FAILURE(InitViewport());
822
823 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Chia-I Wu714df452015-01-01 07:55:04 +0800824 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800825
826 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
827 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
828
829 XglPipelineObj pipelineobj(m_device);
830 pipelineobj.AddShader(&vs);
831 pipelineobj.AddShader(&ps);
832
833 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
834 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
835 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
836 };
837
838 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
839 vi_attrib.binding = 0; // index into vertexBindingDescriptions
840 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
841 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
842 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
843
844 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
845 pipelineobj.AddVertexInputBindings(&vi_binding,1);
846 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
847
848 XglDescriptorSetObj descriptorSet(m_device);
849
850 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800852
853 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
854 att.blendEnable = XGL_FALSE;
855 att.format = m_render_target_fmt;
856 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700857 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800858
Tony Barbour5ed79702015-01-07 14:31:52 -0700859 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700860
Tony Barbour5ed79702015-01-07 14:31:52 -0700861 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
862 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700863
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700864 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700865
Tony Barboure4ed9942015-01-09 10:06:53 -0700866 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
867
Tony Barbour5ed79702015-01-07 14:31:52 -0700868 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700869#ifdef DUMP_STATE_DOT
870 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
871 pDSDumpDot((char*)"triTest2.dot");
872#endif
873 // render triangle
874 cmdBuffer.Draw(0, 3, 0, 1);
875
876 // finalize recording of the command buffer
877 cmdBuffer.EndCommandBuffer();
878 cmdBuffer.QueueCommandBuffer(NULL, 0);
879
880 for (int i = 0; i < m_renderTargetCount; i++)
881 RecordImage(m_renderTargets[i]);
882
Chia-I Wue09d1a72014-12-05 10:32:23 +0800883}
884
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700885TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
886{
887 static const char *vertShaderText =
888 "#version 140\n"
889 "#extension GL_ARB_separate_shader_objects : enable\n"
890 "#extension GL_ARB_shading_language_420pack : enable\n"
891 "layout(location = 0) in vec4 pos;\n"
892 "layout(location = 1) in vec4 inColor;\n"
893 "layout(location = 0) out vec4 outColor;\n"
894 "void main() {\n"
895 " outColor = inColor;\n"
896 " gl_Position = pos;\n"
897 "}\n";
898
899
900 static const char *fragShaderText =
901 "#version 140\n"
902 "#extension GL_ARB_separate_shader_objects : enable\n"
903 "#extension GL_ARB_shading_language_420pack : enable\n"
904 "layout(location = 0) in vec4 color;\n"
905 "void main() {\n"
906 " gl_FragColor = color;\n"
907 "}\n";
908
909 const Vertex g_vbData[] =
910 {
911 // first tri
912 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
913 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
914 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
915
916 // second tri
917 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
918 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
919 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
920 };
921
922 const uint16_t g_idxData[6] = {
923 0, 1, 2,
924 3, 4, 5,
925 };
926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928 ASSERT_NO_FATAL_FAILURE(InitViewport());
929
930 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +0800931 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700932
933 XglIndexBufferObj indexBuffer(m_device);
934 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Chia-I Wu714df452015-01-01 07:55:04 +0800935 indexBuffer.SetBufferState(XGL_BUFFER_STATE_INDEX_DATA);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700936
937 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
938 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
939
940 XglPipelineObj pipelineobj(m_device);
941 pipelineobj.AddShader(&vs);
942 pipelineobj.AddShader(&ps);
943
944 XglDescriptorSetObj descriptorSet(m_device);
945
946 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
947 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
948 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
949 };
950
951 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
952 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
953 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
954 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
955 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
956 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
957 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
958 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
959 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
960
961 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
962 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700963
964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700965 XglCommandBufferObj cmdBuffer(m_device);
966 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700967 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700968
969 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700971#ifdef DUMP_STATE_DOT
972 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700973 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700974#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700975
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700976 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
977 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978
979 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700980 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981
982 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700983 cmdBuffer.EndCommandBuffer();
984 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700986 for (int i = 0; i < m_renderTargetCount; i++)
987 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989}
990
GregF6bef1212014-12-02 15:41:44 -0700991TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
992{
993 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700994
GregF6bef1212014-12-02 15:41:44 -0700995 static const char *vertShaderText =
996 "#version 140\n"
997 "#extension GL_ARB_separate_shader_objects : enable\n"
998 "#extension GL_ARB_shading_language_420pack : enable\n"
999 "layout (location = 0) in vec4 pos;\n"
1000 "layout (location = 0) out vec4 outColor;\n"
1001 "layout (location = 1) out vec4 outColor2;\n"
1002 "void main() {\n"
1003 " gl_Position = pos;\n"
1004 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1005 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1006 "}\n";
1007
1008 static const char *fragShaderText =
1009 //"#version 140\n"
1010 "#version 330\n"
1011 "#extension GL_ARB_separate_shader_objects : enable\n"
1012 "#extension GL_ARB_shading_language_420pack : enable\n"
1013 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1014 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1015 "layout (location = 0) in vec4 color;\n"
1016 "layout (location = 1) in vec4 color2;\n"
1017 "void main() {\n"
1018 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1019 " float dist_squared = dot(pos, pos);\n"
1020 " gl_FragColor = (dist_squared < 400.0)\n"
1021 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1022 " : color2;\n"
1023 "}\n";
1024
1025 ASSERT_NO_FATAL_FAILURE(InitState());
1026 ASSERT_NO_FATAL_FAILURE(InitViewport());
1027
1028 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001029 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001030
1031 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1032 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1033
1034 XglPipelineObj pipelineobj(m_device);
1035 pipelineobj.AddShader(&vs);
1036 pipelineobj.AddShader(&ps);
1037
1038 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001039 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001040
1041 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1042 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1043 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1044 };
1045
1046 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1047 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1048 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1049 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1050 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1051 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1052 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1053 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1054 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1055
1056 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1057 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1058 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1059
Tony Barbourdd4c9642015-01-09 12:55:14 -07001060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1061 XglCommandBufferObj cmdBuffer(m_device);
1062 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1063
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001064 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001065
1066 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1067
1068 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1069#ifdef DUMP_STATE_DOT
1070 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1071 pDSDumpDot((char*)"triTest2.dot");
1072#endif
1073 // render triangle
1074 cmdBuffer.Draw(0, 6, 0, 1);
1075
1076 // finalize recording of the command buffer
1077 cmdBuffer.EndCommandBuffer();
1078 cmdBuffer.QueueCommandBuffer(NULL, 0);
1079
1080 for (int i = 0; i < m_renderTargetCount; i++)
1081 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001082
1083}
1084
1085TEST_F(XglRenderTest, RedCirclesonBlue)
1086{
1087 // This tests that we correctly handle unread fragment inputs
1088
1089 static const char *vertShaderText =
1090 "#version 140\n"
1091 "#extension GL_ARB_separate_shader_objects : enable\n"
1092 "#extension GL_ARB_shading_language_420pack : enable\n"
1093 "layout (location = 0) in vec4 pos;\n"
1094 "layout (location = 0) out vec4 outColor;\n"
1095 "layout (location = 1) out vec4 outColor2;\n"
1096 "void main() {\n"
1097 " gl_Position = pos;\n"
1098 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1099 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1100 "}\n";
1101
1102 static const char *fragShaderText =
1103 //"#version 140\n"
1104 "#version 330\n"
1105 "#extension GL_ARB_separate_shader_objects : enable\n"
1106 "#extension GL_ARB_shading_language_420pack : enable\n"
1107 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1108 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1109 "layout (location = 0) in vec4 color;\n"
1110 "layout (location = 1) in vec4 color2;\n"
1111 "void main() {\n"
1112 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1113 " float dist_squared = dot(pos, pos);\n"
1114 " gl_FragColor = (dist_squared < 400.0)\n"
1115 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1116 " : color2;\n"
1117 "}\n";
1118
1119 ASSERT_NO_FATAL_FAILURE(InitState());
1120 ASSERT_NO_FATAL_FAILURE(InitViewport());
1121
1122 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001123 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001124
1125 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1126 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1127
1128 XglPipelineObj pipelineobj(m_device);
1129 pipelineobj.AddShader(&vs);
1130 pipelineobj.AddShader(&ps);
1131
1132 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001133 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001134
1135 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1136 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1137 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1138 };
1139
1140 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1141 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1142 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1143 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1144 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1145 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1146 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1147 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1148 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1149
1150 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1151 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1152 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1153
Tony Barbourdd4c9642015-01-09 12:55:14 -07001154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1155 XglCommandBufferObj cmdBuffer(m_device);
1156 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1157
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001158 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001159
1160 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1161
1162 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1163#ifdef DUMP_STATE_DOT
1164 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1165 pDSDumpDot((char*)"triTest2.dot");
1166#endif
1167 // render triangle
1168 cmdBuffer.Draw(0, 6, 0, 1);
1169
1170 // finalize recording of the command buffer
1171 cmdBuffer.EndCommandBuffer();
1172 cmdBuffer.QueueCommandBuffer(NULL, 0);
1173
1174 for (int i = 0; i < m_renderTargetCount; i++)
1175 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001176
1177}
1178
1179TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1180{
1181 // This tests reading gl_ClipDistance from FS
1182
1183 static const char *vertShaderText =
1184 "#version 330\n"
1185 "#extension GL_ARB_separate_shader_objects : enable\n"
1186 "#extension GL_ARB_shading_language_420pack : enable\n"
1187 "out gl_PerVertex {\n"
1188 " vec4 gl_Position;\n"
1189 " float gl_ClipDistance[1];\n"
1190 "};\n"
1191 "layout (location = 0) in vec4 pos;\n"
1192 "layout (location = 0) out vec4 outColor;\n"
1193 "layout (location = 1) out vec4 outColor2;\n"
1194 "void main() {\n"
1195 " gl_Position = pos;\n"
1196 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1197 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1198 " float dists[3];\n"
1199 " dists[0] = 0.0;\n"
1200 " dists[1] = 1.0;\n"
1201 " dists[2] = 1.0;\n"
1202 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1203 "}\n";
1204
1205
1206 static const char *fragShaderText =
1207 //"#version 140\n"
1208 "#version 330\n"
1209 "#extension GL_ARB_separate_shader_objects : enable\n"
1210 "#extension GL_ARB_shading_language_420pack : enable\n"
1211 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1212 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1213 "layout (location = 0) in vec4 color;\n"
1214 "layout (location = 1) in vec4 color2;\n"
1215 "void main() {\n"
1216 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1217 " float dist_squared = dot(pos, pos);\n"
1218 " gl_FragColor = (dist_squared < 400.0)\n"
1219 " ? color * gl_ClipDistance[0]\n"
1220 " : color2;\n"
1221 "}\n";
1222
1223 ASSERT_NO_FATAL_FAILURE(InitState());
1224 ASSERT_NO_FATAL_FAILURE(InitViewport());
1225
1226 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001227 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001228
1229 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1230 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1231
1232 XglPipelineObj pipelineobj(m_device);
1233 pipelineobj.AddShader(&vs);
1234 pipelineobj.AddShader(&ps);
1235
1236 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001237 descriptorSet.AttachBufferView(&meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001238
1239 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1240 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1241 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1242 };
1243
1244 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1245 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1246 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1247 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1248 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1249 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1250 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1251 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1252 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1253
1254 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1255 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1256 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1257
Tony Barbourdd4c9642015-01-09 12:55:14 -07001258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1259 XglCommandBufferObj cmdBuffer(m_device);
1260 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001261
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001262 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263
1264 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1265
1266 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1267#ifdef DUMP_STATE_DOT
1268 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1269 pDSDumpDot((char*)"triTest2.dot");
1270#endif
1271 // render triangle
1272 cmdBuffer.Draw(0, 6, 0, 1);
1273
1274 // finalize recording of the command buffer
1275 cmdBuffer.EndCommandBuffer();
1276 cmdBuffer.QueueCommandBuffer(NULL, 0);
1277
1278 for (int i = 0; i < m_renderTargetCount; i++)
1279 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001280}
Tony Barbourf43b6982014-11-25 13:18:32 -07001281
GregF7a23c792014-12-02 17:19:34 -07001282TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1283{
1284 static const char *vertShaderText =
1285 "#version 140\n"
1286 "#extension GL_ARB_separate_shader_objects : enable\n"
1287 "#extension GL_ARB_shading_language_420pack : enable\n"
1288 "layout (location = 0) in vec4 pos;\n"
1289 "layout (location = 0) out vec4 outColor;\n"
1290 "layout (location = 1) out vec4 outColor2;\n"
1291 "void main() {\n"
1292 " gl_Position = pos;\n"
1293 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1294 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1295 "}\n";
1296
1297
1298 static const char *fragShaderText =
1299 //"#version 140\n"
1300 "#version 330\n"
1301 "#extension GL_ARB_separate_shader_objects : enable\n"
1302 "#extension GL_ARB_shading_language_420pack : enable\n"
1303 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1304 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1305 "layout (location = 0) in vec4 color;\n"
1306 "layout (location = 1) in vec4 color2;\n"
1307 "void main() {\n"
1308 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1309 " float dist_squared = dot(pos, pos);\n"
1310 " if (dist_squared < 100.0)\n"
1311 " discard;\n"
1312 " gl_FragColor = (dist_squared < 400.0)\n"
1313 " ? color\n"
1314 " : color2;\n"
1315 "}\n";
1316
1317 ASSERT_NO_FATAL_FAILURE(InitState());
1318 ASSERT_NO_FATAL_FAILURE(InitViewport());
1319
1320 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001321 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF7a23c792014-12-02 17:19:34 -07001322
1323 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1324 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1325
1326 XglPipelineObj pipelineobj(m_device);
1327 pipelineobj.AddShader(&vs);
1328 pipelineobj.AddShader(&ps);
1329
1330 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001331 descriptorSet.AttachBufferView(&meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001332
1333 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1334 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1335 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1336 };
1337
1338 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1339 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1340 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1341 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1342 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1343 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1344 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1345 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1346 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1347
1348 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1349 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1350 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1351
Tony Barbourdd4c9642015-01-09 12:55:14 -07001352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1353 XglCommandBufferObj cmdBuffer(m_device);
1354 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1355
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001356 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357
1358 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1359
1360 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1361#ifdef DUMP_STATE_DOT
1362 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1363 pDSDumpDot((char*)"triTest2.dot");
1364#endif
1365 // render triangle
1366 cmdBuffer.Draw(0, 6, 0, 1);
1367
1368 // finalize recording of the command buffer
1369 cmdBuffer.EndCommandBuffer();
1370 cmdBuffer.QueueCommandBuffer(NULL, 0);
1371
1372 for (int i = 0; i < m_renderTargetCount; i++)
1373 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001374
1375}
1376
1377
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001378TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001379{
1380 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001381 "#version 140\n"
1382 "#extension GL_ARB_separate_shader_objects : enable\n"
1383 "#extension GL_ARB_shading_language_420pack : enable\n"
1384 "\n"
1385 "layout(binding = 0) uniform buf {\n"
1386 " mat4 MVP;\n"
1387 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001388 "void main() {\n"
1389 " vec2 vertices[3];"
1390 " vertices[0] = vec2(-0.5, -0.5);\n"
1391 " vertices[1] = vec2( 0.5, -0.5);\n"
1392 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001393 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001394 "}\n";
1395
1396 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001397 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001398 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001399 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001400 "}\n";
1401
Tony Barbourf43b6982014-11-25 13:18:32 -07001402 ASSERT_NO_FATAL_FAILURE(InitState());
1403 ASSERT_NO_FATAL_FAILURE(InitViewport());
1404
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001405 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001406 glm::mat4 Projection = glm::mat4(1.0f);
1407 glm::mat4 View = glm::mat4(1.0f);
1408 glm::mat4 Model = glm::mat4(1.0f);
1409 glm::mat4 MVP = Projection * View * Model;
1410 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1411
Tony Barbourf43b6982014-11-25 13:18:32 -07001412 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1413 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1414 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001415
Chia-I Wu714df452015-01-01 07:55:04 +08001416 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001417
1418 XglPipelineObj pipelineobj(m_device);
1419 pipelineobj.AddShader(&vs);
1420 pipelineobj.AddShader(&ps);
1421
1422 // Create descriptor set and attach the constant buffer to it
1423 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001424 descriptorSet.AttachBufferView(&MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001425
1426 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1427
Tony Barbourdd4c9642015-01-09 12:55:14 -07001428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1429 XglCommandBufferObj cmdBuffer(m_device);
1430 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001431
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001432 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001433
1434 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1435
1436 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1437#ifdef DUMP_STATE_DOT
1438 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1439 pDSDumpDot((char*)"triTest2.dot");
1440#endif
1441 // render triangle
1442 cmdBuffer.Draw(0, 6, 0, 1);
1443
1444 // finalize recording of the command buffer
1445 cmdBuffer.EndCommandBuffer();
1446 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1447
1448 for (int i = 0; i < m_renderTargetCount; i++)
1449 RecordImage(m_renderTargets[i]);
1450
1451 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001452}
1453
Tony Barbourf43b6982014-11-25 13:18:32 -07001454TEST_F(XglRenderTest, MixTriangle)
1455{
1456 // This tests location applied to varyings. Notice that we have switched foo
1457 // and bar in the FS. The triangle should be blended with red, green and blue
1458 // corners.
1459 static const char *vertShaderText =
1460 "#version 140\n"
1461 "#extension GL_ARB_separate_shader_objects : enable\n"
1462 "#extension GL_ARB_shading_language_420pack : enable\n"
1463 "layout (location=0) out vec4 bar;\n"
1464 "layout (location=1) out vec4 foo;\n"
1465 "layout (location=2) out float scale;\n"
1466 "vec2 vertices[3];\n"
1467 "void main() {\n"
1468 " vertices[0] = vec2(-1.0, -1.0);\n"
1469 " vertices[1] = vec2( 1.0, -1.0);\n"
1470 " vertices[2] = vec2( 0.0, 1.0);\n"
1471 "vec4 colors[3];\n"
1472 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1473 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1474 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1475 " foo = colors[gl_VertexID % 3];\n"
1476 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1477 " scale = 1.0;\n"
1478 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1479 "}\n";
1480
1481 static const char *fragShaderText =
1482 "#version 140\n"
1483 "#extension GL_ARB_separate_shader_objects : enable\n"
1484 "#extension GL_ARB_shading_language_420pack : enable\n"
1485 "layout (location = 1) in vec4 bar;\n"
1486 "layout (location = 0) in vec4 foo;\n"
1487 "layout (location = 2) in float scale;\n"
1488 "void main() {\n"
1489 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1490 "}\n";
1491
1492 ASSERT_NO_FATAL_FAILURE(InitState());
1493 ASSERT_NO_FATAL_FAILURE(InitViewport());
1494
1495 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1496 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1497
1498 XglPipelineObj pipelineobj(m_device);
1499 pipelineobj.AddShader(&vs);
1500 pipelineobj.AddShader(&ps);
1501
1502 XglDescriptorSetObj descriptorSet(m_device);
1503
Tony Barbourdd4c9642015-01-09 12:55:14 -07001504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1505 XglCommandBufferObj cmdBuffer(m_device);
1506 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1507
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001508 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509
1510 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1511
1512#ifdef DUMP_STATE_DOT
1513 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1514 pDSDumpDot((char*)"triTest2.dot");
1515#endif
1516 // render triangle
1517 cmdBuffer.Draw(0, 3, 0, 1);
1518
1519 // finalize recording of the command buffer
1520 cmdBuffer.EndCommandBuffer();
1521 cmdBuffer.QueueCommandBuffer(NULL, 0);
1522
1523 for (int i = 0; i < m_renderTargetCount; i++)
1524 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001525}
1526
1527TEST_F(XglRenderTest, TriVertFetchAndVertID)
1528{
1529 // This tests that attributes work in the presence of gl_VertexID
1530
1531 static const char *vertShaderText =
1532 "#version 140\n"
1533 "#extension GL_ARB_separate_shader_objects : enable\n"
1534 "#extension GL_ARB_shading_language_420pack : enable\n"
1535 //XYZ1( -1, -1, -1 )
1536 "layout (location = 0) in vec4 pos;\n"
1537 //XYZ1( 0.f, 0.f, 0.f )
1538 "layout (location = 1) in vec4 inColor;\n"
1539 "layout (location = 0) out vec4 outColor;\n"
1540 "void main() {\n"
1541 " outColor = inColor;\n"
1542 " vec4 vertices[3];"
1543 " vertices[gl_VertexID % 3] = pos;\n"
1544 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1545 "}\n";
1546
1547
1548 static const char *fragShaderText =
1549 "#version 140\n"
1550 "#extension GL_ARB_separate_shader_objects : enable\n"
1551 "#extension GL_ARB_shading_language_420pack : enable\n"
1552 "layout (location = 0) in vec4 color;\n"
1553 "void main() {\n"
1554 " gl_FragColor = color;\n"
1555 "}\n";
1556
1557 ASSERT_NO_FATAL_FAILURE(InitState());
1558 ASSERT_NO_FATAL_FAILURE(InitViewport());
1559
1560 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001561 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562
1563 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1564 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1565
1566 XglPipelineObj pipelineobj(m_device);
1567 pipelineobj.AddShader(&vs);
1568 pipelineobj.AddShader(&ps);
1569
1570 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001571 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001572
1573 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1574 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1575 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1576 };
1577
1578 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1579 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1580 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1581 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1582 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1583 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1584 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1585 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1586 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1587
1588 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1589 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1590 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1591
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1593 XglCommandBufferObj cmdBuffer(m_device);
1594 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1595
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001596 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001597
1598 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1599
1600 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1601#ifdef DUMP_STATE_DOT
1602 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1603 pDSDumpDot((char*)"triTest2.dot");
1604#endif
1605 // render triangle
1606 cmdBuffer.Draw(0, 6, 0, 1);
1607
1608 // finalize recording of the command buffer
1609 cmdBuffer.EndCommandBuffer();
1610 cmdBuffer.QueueCommandBuffer(NULL, 0);
1611
1612 for (int i = 0; i < m_renderTargetCount; i++)
1613 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001614}
1615
1616TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1617{
1618 // This tests that attributes work in the presence of gl_VertexID
1619 // and a dead attribute in position 0. Draws a triangle with yellow,
1620 // red and green corners, starting at top and going clockwise.
1621
1622 static const char *vertShaderText =
1623 "#version 140\n"
1624 "#extension GL_ARB_separate_shader_objects : enable\n"
1625 "#extension GL_ARB_shading_language_420pack : enable\n"
1626 //XYZ1( -1, -1, -1 )
1627 "layout (location = 0) in vec4 pos;\n"
1628 //XYZ1( 0.f, 0.f, 0.f )
1629 "layout (location = 1) in vec4 inColor;\n"
1630 "layout (location = 0) out vec4 outColor;\n"
1631 "void main() {\n"
1632 " outColor = inColor;\n"
1633 " vec2 vertices[3];"
1634 " vertices[0] = vec2(-1.0, -1.0);\n"
1635 " vertices[1] = vec2( 1.0, -1.0);\n"
1636 " vertices[2] = vec2( 0.0, 1.0);\n"
1637 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1638 "}\n";
1639
1640
1641 static const char *fragShaderText =
1642 "#version 140\n"
1643 "#extension GL_ARB_separate_shader_objects : enable\n"
1644 "#extension GL_ARB_shading_language_420pack : enable\n"
1645 "layout (location = 0) in vec4 color;\n"
1646 "void main() {\n"
1647 " gl_FragColor = color;\n"
1648 "}\n";
1649
1650 ASSERT_NO_FATAL_FAILURE(InitState());
1651 ASSERT_NO_FATAL_FAILURE(InitViewport());
1652
1653 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Chia-I Wu714df452015-01-01 07:55:04 +08001654 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07001655
1656 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1657 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1658
1659 XglPipelineObj pipelineobj(m_device);
1660 pipelineobj.AddShader(&vs);
1661 pipelineobj.AddShader(&ps);
1662
1663 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001664 descriptorSet.AttachBufferView(&meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001665
1666 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1667 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1668 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1669 };
1670
1671 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1672 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1673 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1674 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1675 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1676 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1677 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1678 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1679 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1680
1681 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1682 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1683 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1684
Tony Barbourdd4c9642015-01-09 12:55:14 -07001685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1686 XglCommandBufferObj cmdBuffer(m_device);
1687 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001688
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001689 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001690
1691 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1692
1693 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1694#ifdef DUMP_STATE_DOT
1695 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1696 pDSDumpDot((char*)"triTest2.dot");
1697#endif
1698 // render triangle
1699 cmdBuffer.Draw(0, 6, 0, 1);
1700
1701 // finalize recording of the command buffer
1702 cmdBuffer.EndCommandBuffer();
1703 cmdBuffer.QueueCommandBuffer(NULL, 0);
1704
1705 for (int i = 0; i < m_renderTargetCount; i++)
1706 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001707}
1708
1709TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001710{
1711 static const char *vertShaderText =
1712 "#version 140\n"
1713 "layout (std140) uniform bufferVals {\n"
1714 " mat4 mvp;\n"
1715 "} myBufferVals;\n"
1716 "in vec4 pos;\n"
1717 "in vec4 inColor;\n"
1718 "out vec4 outColor;\n"
1719 "void main() {\n"
1720 " outColor = inColor;\n"
1721 " gl_Position = myBufferVals.mvp * pos;\n"
1722 "}\n";
1723
1724 static const char *fragShaderText =
1725 "#version 130\n"
1726 "in vec4 color;\n"
1727 "void main() {\n"
1728 " gl_FragColor = color;\n"
1729 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001730 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001731
Tony Barbourf43b6982014-11-25 13:18:32 -07001732 glm::mat4 View = glm::lookAt(
1733 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1734 glm::vec3(0,0,0), // and looks at the origin
1735 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1736 );
1737
1738 glm::mat4 Model = glm::mat4(1.0f);
1739
1740 glm::mat4 MVP = Projection * View * Model;
1741
1742 ASSERT_NO_FATAL_FAILURE(InitState());
1743 ASSERT_NO_FATAL_FAILURE(InitViewport());
1744 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1745
1746 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1747 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1748
1749 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1750
1751 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1752 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1753 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1754
Chia-I Wu714df452015-01-01 07:55:04 +08001755 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001756
1757 XglPipelineObj pipelineobj(m_device);
1758 pipelineobj.AddShader(&vs);
1759 pipelineobj.AddShader(&ps);
1760
Tony Barbourfa6cac72015-01-16 14:27:35 -07001761 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1762 ds_state.depthTestEnable = XGL_TRUE;
1763 ds_state.depthWriteEnable = XGL_TRUE;
1764 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1765 ds_state.depthBoundsEnable = XGL_FALSE;
1766 ds_state.stencilTestEnable = XGL_FALSE;
1767 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1768 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1769 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1770 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1771 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1772 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1773 ds_state.front = ds_state.back;
1774 pipelineobj.SetDepthStencil(&ds_state);
1775
Tony Barbourf43b6982014-11-25 13:18:32 -07001776 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08001777 descriptorSet.AttachBufferView(&MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001778
1779 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1780 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1781
1782 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1783 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1784 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1785 };
1786
1787 // this is the current description of g_vbData
1788 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1789 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1790 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1791 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1792 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1793 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1794 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1795 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1796 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1797
1798 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1799 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1800 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1801
Tony Barboure4ed9942015-01-09 10:06:53 -07001802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1803 XglCommandBufferObj cmdBuffer(m_device);
1804 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001805
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001806 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001807 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001808
Tony Barboure4ed9942015-01-09 10:06:53 -07001809 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1810#ifdef DUMP_STATE_DOT
1811 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1812 pDSDumpDot((char*)"triTest2.dot");
1813#endif
1814 // render triangle
1815 cmdBuffer.Draw(0, 36, 0, 1);
1816
1817 // finalize recording of the command buffer
1818 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001819 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001820
1821 for (int i = 0; i < m_renderTargetCount; i++)
1822 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001823}
1824
Tony Barbourf43b6982014-11-25 13:18:32 -07001825TEST_F(XglRenderTest, VSTexture)
1826{
1827 // The expected result from this test is a green and red triangle;
1828 // one red vertex on the left, two green vertices on the right.
1829 static const char *vertShaderText =
1830 "#version 130\n"
1831 "out vec4 texColor;\n"
1832 "uniform sampler2D surface;\n"
1833 "void main() {\n"
1834 " vec2 vertices[3];"
1835 " vertices[0] = vec2(-0.5, -0.5);\n"
1836 " vertices[1] = vec2( 0.5, -0.5);\n"
1837 " vertices[2] = vec2( 0.5, 0.5);\n"
1838 " vec2 positions[3];"
1839 " positions[0] = vec2( 0.0, 0.0);\n"
1840 " positions[1] = vec2( 0.25, 0.1);\n"
1841 " positions[2] = vec2( 0.1, 0.25);\n"
1842 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1843 " texColor = textureLod(surface, samplePos, 0.0);\n"
1844 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1845 "}\n";
1846
1847 static const char *fragShaderText =
1848 "#version 130\n"
1849 "in vec4 texColor;\n"
1850 "void main() {\n"
1851 " gl_FragColor = texColor;\n"
1852 "}\n";
1853
1854 ASSERT_NO_FATAL_FAILURE(InitState());
1855 ASSERT_NO_FATAL_FAILURE(InitViewport());
1856
1857 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1858 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1859 XglSamplerObj sampler(m_device);
1860 XglTextureObj texture(m_device);
1861
Cody Northrop5fcacbc2014-12-09 19:08:54 -07001862 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001863 vs.BindShaderEntitySlotToSampler(0, &sampler);
1864
1865 XglPipelineObj pipelineobj(m_device);
1866 pipelineobj.AddShader(&vs);
1867 pipelineobj.AddShader(&ps);
1868
1869 XglDescriptorSetObj descriptorSet(m_device);
1870 descriptorSet.AttachImageView(&texture);
1871 descriptorSet.AttachSampler(&sampler);
1872
1873 m_memoryRefManager.AddMemoryRef(&texture);
1874
Tony Barbourdd4c9642015-01-09 12:55:14 -07001875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1876 XglCommandBufferObj cmdBuffer(m_device);
1877 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001878
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001879 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001880
1881 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1882
1883#ifdef DUMP_STATE_DOT
1884 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1885 pDSDumpDot((char*)"triTest2.dot");
1886#endif
1887 // render triangle
1888 cmdBuffer.Draw(0, 3, 0, 1);
1889
1890 // finalize recording of the command buffer
1891 cmdBuffer.EndCommandBuffer();
1892 cmdBuffer.QueueCommandBuffer(NULL, 0);
1893
1894 for (int i = 0; i < m_renderTargetCount; i++)
1895 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001896}
1897TEST_F(XglRenderTest, TexturedTriangle)
1898{
1899 // The expected result from this test is a red and green checkered triangle
1900 static const char *vertShaderText =
1901 "#version 140\n"
1902 "#extension GL_ARB_separate_shader_objects : enable\n"
1903 "#extension GL_ARB_shading_language_420pack : enable\n"
1904 "layout (location = 0) out vec2 samplePos;\n"
1905 "void main() {\n"
1906 " vec2 vertices[3];"
1907 " vertices[0] = vec2(-0.5, -0.5);\n"
1908 " vertices[1] = vec2( 0.5, -0.5);\n"
1909 " vertices[2] = vec2( 0.5, 0.5);\n"
1910 " vec2 positions[3];"
1911 " positions[0] = vec2( 0.0, 0.0);\n"
1912 " positions[1] = vec2( 1.0, 0.0);\n"
1913 " positions[2] = vec2( 1.0, 1.0);\n"
1914 " samplePos = positions[gl_VertexID % 3];\n"
1915 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1916 "}\n";
1917
1918 static const char *fragShaderText =
1919 "#version 140\n"
1920 "#extension GL_ARB_separate_shader_objects : enable\n"
1921 "#extension GL_ARB_shading_language_420pack : enable\n"
1922 "layout (location = 0) in vec2 samplePos;\n"
1923 "layout (binding = 0) uniform sampler2D surface;\n"
1924 "layout (location=0) out vec4 outColor;\n"
1925 "void main() {\n"
1926 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1927 " outColor = texColor;\n"
1928 "}\n";
1929
1930 ASSERT_NO_FATAL_FAILURE(InitState());
1931 ASSERT_NO_FATAL_FAILURE(InitViewport());
1932
1933 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1934 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1935 XglSamplerObj sampler(m_device);
1936 XglTextureObj texture(m_device);
1937
Cody Northrop5fcacbc2014-12-09 19:08:54 -07001938 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001939 ps.BindShaderEntitySlotToSampler(0, &sampler);
1940
1941 XglPipelineObj pipelineobj(m_device);
1942 pipelineobj.AddShader(&vs);
1943 pipelineobj.AddShader(&ps);
1944
1945 XglDescriptorSetObj descriptorSet(m_device);
1946 descriptorSet.AttachImageView(&texture);
1947 descriptorSet.AttachSampler(&sampler);
1948
1949 m_memoryRefManager.AddMemoryRef(&texture);
1950
Tony Barbourdd4c9642015-01-09 12:55:14 -07001951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1952 XglCommandBufferObj cmdBuffer(m_device);
1953 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1954
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001955 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956
1957 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1958
1959#ifdef DUMP_STATE_DOT
1960 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1961 pDSDumpDot((char*)"triTest2.dot");
1962#endif
1963 // render triangle
1964 cmdBuffer.Draw(0, 3, 0, 1);
1965
1966 // finalize recording of the command buffer
1967 cmdBuffer.EndCommandBuffer();
1968 cmdBuffer.QueueCommandBuffer(NULL, 0);
1969
1970 for (int i = 0; i < m_renderTargetCount; i++)
1971 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001972}
1973TEST_F(XglRenderTest, TexturedTriangleClip)
1974{
1975 // The expected result from this test is a red and green checkered triangle
1976 static const char *vertShaderText =
1977 "#version 330\n"
1978 "#extension GL_ARB_separate_shader_objects : enable\n"
1979 "#extension GL_ARB_shading_language_420pack : enable\n"
1980 "layout (location = 0) out vec2 samplePos;\n"
1981 "out gl_PerVertex {\n"
1982 " vec4 gl_Position;\n"
1983 " float gl_ClipDistance[1];\n"
1984 "};\n"
1985 "void main() {\n"
1986 " vec2 vertices[3];"
1987 " vertices[0] = vec2(-0.5, -0.5);\n"
1988 " vertices[1] = vec2( 0.5, -0.5);\n"
1989 " vertices[2] = vec2( 0.5, 0.5);\n"
1990 " vec2 positions[3];"
1991 " positions[0] = vec2( 0.0, 0.0);\n"
1992 " positions[1] = vec2( 1.0, 0.0);\n"
1993 " positions[2] = vec2( 1.0, 1.0);\n"
1994 " float dists[3];\n"
1995 " dists[0] = 1.0;\n"
1996 " dists[1] = 1.0;\n"
1997 " dists[2] = -1.0;\n"
1998 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1999 " samplePos = positions[gl_VertexID % 3];\n"
2000 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2001 "}\n";
2002
2003 static const char *fragShaderText =
2004 "#version 140\n"
2005 "#extension GL_ARB_separate_shader_objects : enable\n"
2006 "#extension GL_ARB_shading_language_420pack : enable\n"
2007 "layout (location = 0) in vec2 samplePos;\n"
2008 "layout (binding = 0) uniform sampler2D surface;\n"
2009 "layout (location=0) out vec4 outColor;\n"
2010 "void main() {\n"
2011 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2012 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2013 " outColor = texColor;\n"
2014 "}\n";
2015
2016
2017 ASSERT_NO_FATAL_FAILURE(InitState());
2018 ASSERT_NO_FATAL_FAILURE(InitViewport());
2019
2020 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2021 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2022 XglSamplerObj sampler(m_device);
2023 XglTextureObj texture(m_device);
2024
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002025 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002026 ps.BindShaderEntitySlotToSampler(0, &sampler);
2027
2028 XglPipelineObj pipelineobj(m_device);
2029 pipelineobj.AddShader(&vs);
2030 pipelineobj.AddShader(&ps);
2031
2032 XglDescriptorSetObj descriptorSet(m_device);
2033 descriptorSet.AttachImageView(&texture);
2034 descriptorSet.AttachSampler(&sampler);
2035
2036 m_memoryRefManager.AddMemoryRef(&texture);
2037
Tony Barbourdd4c9642015-01-09 12:55:14 -07002038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2039 XglCommandBufferObj cmdBuffer(m_device);
2040 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2041
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002042 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002043
2044 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2045
2046#ifdef DUMP_STATE_DOT
2047 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2048 pDSDumpDot((char*)"triTest2.dot");
2049#endif
2050 // render triangle
2051 cmdBuffer.Draw(0, 3, 0, 1);
2052
2053 // finalize recording of the command buffer
2054 cmdBuffer.EndCommandBuffer();
2055 cmdBuffer.QueueCommandBuffer(NULL, 0);
2056
2057 for (int i = 0; i < m_renderTargetCount; i++)
2058 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002059}
2060TEST_F(XglRenderTest, FSTriangle)
2061{
2062 // The expected result from this test is a red and green checkered triangle
2063 static const char *vertShaderText =
2064 "#version 140\n"
2065 "#extension GL_ARB_separate_shader_objects : enable\n"
2066 "#extension GL_ARB_shading_language_420pack : enable\n"
2067 "layout (location = 0) out vec2 samplePos;\n"
2068 "void main() {\n"
2069 " vec2 vertices[3];"
2070 " vertices[0] = vec2(-0.5, -0.5);\n"
2071 " vertices[1] = vec2( 0.5, -0.5);\n"
2072 " vertices[2] = vec2( 0.5, 0.5);\n"
2073 " vec2 positions[3];"
2074 " positions[0] = vec2( 0.0, 0.0);\n"
2075 " positions[1] = vec2( 1.0, 0.0);\n"
2076 " positions[2] = vec2( 1.0, 1.0);\n"
2077 " samplePos = positions[gl_VertexID % 3];\n"
2078 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2079 "}\n";
2080
2081 static const char *fragShaderText =
2082 "#version 140\n"
2083 "#extension GL_ARB_separate_shader_objects : enable\n"
2084 "#extension GL_ARB_shading_language_420pack : enable\n"
2085 "layout (location = 0) in vec2 samplePos;\n"
2086 "layout (binding = 0) uniform sampler2D surface;\n"
2087 "layout (location=0) out vec4 outColor;\n"
2088 "void main() {\n"
2089 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2090 " outColor = texColor;\n"
2091 "}\n";
2092
2093 ASSERT_NO_FATAL_FAILURE(InitState());
2094 ASSERT_NO_FATAL_FAILURE(InitViewport());
2095
2096 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2097 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2098 XglSamplerObj sampler(m_device);
2099 XglTextureObj texture(m_device);
2100
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002101 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002102 ps.BindShaderEntitySlotToSampler(0, &sampler);
2103
2104 XglPipelineObj pipelineobj(m_device);
2105 pipelineobj.AddShader(&vs);
2106 pipelineobj.AddShader(&ps);
2107
2108 XglDescriptorSetObj descriptorSet(m_device);
2109 descriptorSet.AttachImageView(&texture);
2110 descriptorSet.AttachSampler(&sampler);
2111
2112 m_memoryRefManager.AddMemoryRef(&texture);
2113
Tony Barbourdd4c9642015-01-09 12:55:14 -07002114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2115 XglCommandBufferObj cmdBuffer(m_device);
2116 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2117
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002118 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119
2120 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2121
2122#ifdef DUMP_STATE_DOT
2123 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2124 pDSDumpDot((char*)"triTest2.dot");
2125#endif
2126 // render triangle
2127 cmdBuffer.Draw(0, 3, 0, 1);
2128
2129 // finalize recording of the command buffer
2130 cmdBuffer.EndCommandBuffer();
2131 cmdBuffer.QueueCommandBuffer(NULL, 0);
2132
2133 for (int i = 0; i < m_renderTargetCount; i++)
2134 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002135}
2136TEST_F(XglRenderTest, SamplerBindingsTriangle)
2137{
2138 // This test sets bindings on the samplers
2139 // For now we are asserting that sampler and texture pairs
2140 // march in lock step, and are set via GLSL binding. This can
2141 // and will probably change.
2142 // The sampler bindings should match the sampler and texture slot
2143 // number set up by the application.
2144 // This test will result in a blue triangle
2145 static const char *vertShaderText =
2146 "#version 140\n"
2147 "#extension GL_ARB_separate_shader_objects : enable\n"
2148 "#extension GL_ARB_shading_language_420pack : enable\n"
2149 "layout (location = 0) out vec4 samplePos;\n"
2150 "void main() {\n"
2151 " vec2 vertices[3];"
2152 " vertices[0] = vec2(-0.5, -0.5);\n"
2153 " vertices[1] = vec2( 0.5, -0.5);\n"
2154 " vertices[2] = vec2( 0.5, 0.5);\n"
2155 " vec2 positions[3];"
2156 " positions[0] = vec2( 0.0, 0.0);\n"
2157 " positions[1] = vec2( 1.0, 0.0);\n"
2158 " positions[2] = vec2( 1.0, 1.0);\n"
2159 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2160 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2161 "}\n";
2162
2163 static const char *fragShaderText =
2164 "#version 140\n"
2165 "#extension GL_ARB_separate_shader_objects : enable\n"
2166 "#extension GL_ARB_shading_language_420pack : enable\n"
2167 "layout (location = 0) in vec4 samplePos;\n"
2168 "layout (binding = 0) uniform sampler2D surface0;\n"
2169 "layout (binding = 1) uniform sampler2D surface1;\n"
2170 "layout (binding = 12) uniform sampler2D surface2;\n"
2171 "void main() {\n"
2172 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2173 "}\n";
2174
2175 ASSERT_NO_FATAL_FAILURE(InitState());
2176 ASSERT_NO_FATAL_FAILURE(InitViewport());
2177
2178 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2179 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2180
2181 XglSamplerObj sampler1(m_device);
2182 XglSamplerObj sampler2(m_device);
2183 XglSamplerObj sampler3(m_device);
2184
2185 XglTextureObj texture1(m_device); // Red
2186 texture1.ChangeColors(0xffff0000,0xffff0000);
2187 XglTextureObj texture2(m_device); // Green
2188 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2189 XglTextureObj texture3(m_device); // Blue
2190 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2191
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002192 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002193 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2194
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002195 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Tony Barbourf43b6982014-11-25 13:18:32 -07002196 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2197
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002198 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002199 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2200
2201 XglPipelineObj pipelineobj(m_device);
2202 pipelineobj.AddShader(&vs);
2203 pipelineobj.AddShader(&ps);
2204
2205 XglDescriptorSetObj descriptorSet(m_device);
2206 descriptorSet.AttachImageView(&texture1);
2207 descriptorSet.AttachSampler(&sampler1);
2208 descriptorSet.AttachImageView(&texture2);
2209 descriptorSet.AttachSampler(&sampler2);
2210 descriptorSet.AttachImageView(&texture3);
2211 descriptorSet.AttachSampler(&sampler3);
2212
2213 m_memoryRefManager.AddMemoryRef(&texture1);
2214 m_memoryRefManager.AddMemoryRef(&texture2);
2215 m_memoryRefManager.AddMemoryRef(&texture3);
2216
Tony Barbourdd4c9642015-01-09 12:55:14 -07002217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2218 XglCommandBufferObj cmdBuffer(m_device);
2219 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2220
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002221 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002222
2223 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2224
2225#ifdef DUMP_STATE_DOT
2226 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2227 pDSDumpDot((char*)"triTest2.dot");
2228#endif
2229 // render triangle
2230 cmdBuffer.Draw(0, 3, 0, 1);
2231
2232 // finalize recording of the command buffer
2233 cmdBuffer.EndCommandBuffer();
2234 cmdBuffer.QueueCommandBuffer(NULL, 0);
2235
2236 for (int i = 0; i < m_renderTargetCount; i++)
2237 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002238
2239}
2240
2241TEST_F(XglRenderTest, TriangleVSUniformBlock)
2242{
2243 // The expected result from this test is a blue triangle
2244
2245 static const char *vertShaderText =
2246 "#version 140\n"
2247 "#extension GL_ARB_separate_shader_objects : enable\n"
2248 "#extension GL_ARB_shading_language_420pack : enable\n"
2249 "layout (location = 0) out vec4 outColor;\n"
2250 "layout (std140, binding = 0) uniform bufferVals {\n"
2251 " vec4 red;\n"
2252 " vec4 green;\n"
2253 " vec4 blue;\n"
2254 " vec4 white;\n"
2255 "} myBufferVals;\n"
2256 "void main() {\n"
2257 " vec2 vertices[3];"
2258 " vertices[0] = vec2(-0.5, -0.5);\n"
2259 " vertices[1] = vec2( 0.5, -0.5);\n"
2260 " vertices[2] = vec2( 0.5, 0.5);\n"
2261 " outColor = myBufferVals.blue;\n"
2262 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2263 "}\n";
2264
2265 static const char *fragShaderText =
2266 "#version 140\n"
2267 "#extension GL_ARB_separate_shader_objects : enable\n"
2268 "#extension GL_ARB_shading_language_420pack : enable\n"
2269 "layout (location = 0) in vec4 inColor;\n"
2270 "void main() {\n"
2271 " gl_FragColor = inColor;\n"
2272 "}\n";
2273
2274 ASSERT_NO_FATAL_FAILURE(InitState());
2275 ASSERT_NO_FATAL_FAILURE(InitViewport());
2276
2277 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2278 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2279
2280 // Let's populate our buffer with the following:
2281 // vec4 red;
2282 // vec4 green;
2283 // vec4 blue;
2284 // vec4 white;
2285 const int valCount = 4 * 4;
2286 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2287 0.0, 1.0, 0.0, 1.0,
2288 0.0, 0.0, 1.0, 1.0,
2289 1.0, 1.0, 1.0, 1.0 };
2290
2291 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002292 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002293
2294 XglPipelineObj pipelineobj(m_device);
2295 pipelineobj.AddShader(&vs);
2296 pipelineobj.AddShader(&ps);
2297
2298 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002299 descriptorSet.AttachBufferView(&colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002300
Tony Barbourdd4c9642015-01-09 12:55:14 -07002301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2302 XglCommandBufferObj cmdBuffer(m_device);
2303 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2304
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002305 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002306
2307 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2308
2309#ifdef DUMP_STATE_DOT
2310 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2311 pDSDumpDot((char*)"triTest2.dot");
2312#endif
2313 // render triangle
2314 cmdBuffer.Draw(0, 3, 0, 1);
2315
2316 // finalize recording of the command buffer
2317 cmdBuffer.EndCommandBuffer();
2318 cmdBuffer.QueueCommandBuffer(NULL, 0);
2319
2320 for (int i = 0; i < m_renderTargetCount; i++)
2321 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002322
2323}
2324
2325TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2326{
2327 // This test allows the shader to select which buffer it is
2328 // pulling from using layout binding qualifier.
2329 // There are corresponding changes in the compiler stack that
2330 // will select the buffer using binding directly.
2331 // The binding number should match the slot number set up by
2332 // the application.
2333 // The expected result from this test is a purple triangle
2334
2335 static const char *vertShaderText =
2336 "#version 140\n"
2337 "#extension GL_ARB_separate_shader_objects : enable\n"
2338 "#extension GL_ARB_shading_language_420pack : enable\n"
2339 "void main() {\n"
2340 " vec2 vertices[3];"
2341 " vertices[0] = vec2(-0.5, -0.5);\n"
2342 " vertices[1] = vec2( 0.5, -0.5);\n"
2343 " vertices[2] = vec2( 0.5, 0.5);\n"
2344 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2345 "}\n";
2346
2347 static const char *fragShaderText =
2348 "#version 140\n"
2349 "#extension GL_ARB_separate_shader_objects : enable\n"
2350 "#extension GL_ARB_shading_language_420pack : enable\n"
2351 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2352 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2353 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2354 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2355 "void main() {\n"
2356 " gl_FragColor = myBlueVal.color;\n"
2357 " gl_FragColor += myRedVal.color;\n"
2358 "}\n";
2359
2360 ASSERT_NO_FATAL_FAILURE(InitState());
2361 ASSERT_NO_FATAL_FAILURE(InitViewport());
2362
2363 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2364 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2365
2366 // We're going to create a number of uniform buffers, and then allow
2367 // the shader to select which it wants to read from with a binding
2368
2369 // Let's populate the buffers with a single color each:
2370 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2371 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2372 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2373 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2374
2375 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2376 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2377 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2378 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2379
2380 const int redCount = sizeof(redVals) / sizeof(float);
2381 const int greenCount = sizeof(greenVals) / sizeof(float);
2382 const int blueCount = sizeof(blueVals) / sizeof(float);
2383 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2384
2385 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002386 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002387
2388 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002389 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002390
2391 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002392 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002393
2394 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002395 ps.BindShaderEntitySlotToBuffer(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002396
2397 XglPipelineObj pipelineobj(m_device);
2398 pipelineobj.AddShader(&vs);
2399 pipelineobj.AddShader(&ps);
2400
2401 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002402 descriptorSet.AttachBufferView(&redBuffer);
2403 descriptorSet.AttachBufferView(&greenBuffer);
2404 descriptorSet.AttachBufferView(&blueBuffer);
2405 descriptorSet.AttachBufferView(&whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002406
Tony Barbourdd4c9642015-01-09 12:55:14 -07002407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2408 XglCommandBufferObj cmdBuffer(m_device);
2409 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002410
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002411 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002412
2413 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2414
2415#ifdef DUMP_STATE_DOT
2416 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2417 pDSDumpDot((char*)"triTest2.dot");
2418#endif
2419 // render triangle
2420 cmdBuffer.Draw(0, 3, 0, 1);
2421
2422 // finalize recording of the command buffer
2423 cmdBuffer.EndCommandBuffer();
2424 cmdBuffer.QueueCommandBuffer(NULL, 0);
2425
2426 for (int i = 0; i < m_renderTargetCount; i++)
2427 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002428}
2429
2430TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2431{
2432 // This test is the same as TriangleFSUniformBlockBinding, but
2433 // it does not provide an instance name.
2434 // The expected result from this test is a purple triangle
2435
2436 static const char *vertShaderText =
2437 "#version 140\n"
2438 "#extension GL_ARB_separate_shader_objects : enable\n"
2439 "#extension GL_ARB_shading_language_420pack : enable\n"
2440 "void main() {\n"
2441 " vec2 vertices[3];"
2442 " vertices[0] = vec2(-0.5, -0.5);\n"
2443 " vertices[1] = vec2( 0.5, -0.5);\n"
2444 " vertices[2] = vec2( 0.5, 0.5);\n"
2445 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2446 "}\n";
2447
2448 static const char *fragShaderText =
2449 "#version 430\n"
2450 "#extension GL_ARB_separate_shader_objects : enable\n"
2451 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002452 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2453 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2454 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2455 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002456 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002457 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002458 " outColor = blue;\n"
2459 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002460 "}\n";
2461 ASSERT_NO_FATAL_FAILURE(InitState());
2462 ASSERT_NO_FATAL_FAILURE(InitViewport());
2463
2464 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2465 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2466
2467 // We're going to create a number of uniform buffers, and then allow
2468 // the shader to select which it wants to read from with a binding
2469
2470 // Let's populate the buffers with a single color each:
2471 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2472 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2473 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2474 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2475
2476 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2477 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2478 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2479 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2480
2481 const int redCount = sizeof(redVals) / sizeof(float);
2482 const int greenCount = sizeof(greenVals) / sizeof(float);
2483 const int blueCount = sizeof(blueVals) / sizeof(float);
2484 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2485
2486 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002487 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002488
2489 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002490 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002491
2492 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002493 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002494
2495 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002496 ps.BindShaderEntitySlotToBuffer(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002497
2498 XglPipelineObj pipelineobj(m_device);
2499 pipelineobj.AddShader(&vs);
2500 pipelineobj.AddShader(&ps);
2501
2502 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002503 descriptorSet.AttachBufferView(&redBuffer);
2504 descriptorSet.AttachBufferView(&greenBuffer);
2505 descriptorSet.AttachBufferView(&blueBuffer);
2506 descriptorSet.AttachBufferView(&whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002507
Tony Barbourdd4c9642015-01-09 12:55:14 -07002508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2509 XglCommandBufferObj cmdBuffer(m_device);
2510 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2511
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002512 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002513
2514 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2515
2516#ifdef DUMP_STATE_DOT
2517 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2518 pDSDumpDot((char*)"triTest2.dot");
2519#endif
2520 // render triangle
2521 cmdBuffer.Draw(0, 3, 0, 1);
2522
2523 // finalize recording of the command buffer
2524 cmdBuffer.EndCommandBuffer();
2525 cmdBuffer.QueueCommandBuffer(NULL, 0);
2526
2527 for (int i = 0; i < m_renderTargetCount; i++)
2528 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002529
2530}
2531
2532TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2533{
2534 static const char *vertShaderText =
2535 "#version 140\n"
2536 "#extension GL_ARB_separate_shader_objects : enable\n"
2537 "#extension GL_ARB_shading_language_420pack : enable\n"
2538 "layout (std140, binding=0) uniform bufferVals {\n"
2539 " mat4 mvp;\n"
2540 "} myBufferVals;\n"
2541 "layout (location=0) in vec4 pos;\n"
2542 "layout (location=0) out vec2 UV;\n"
2543 "void main() {\n"
2544 " vec2 positions[3];"
2545 " positions[0] = vec2( 0.0, 0.0);\n"
2546 " positions[1] = vec2( 0.25, 0.1);\n"
2547 " positions[2] = vec2( 0.1, 0.25);\n"
2548 " UV = positions[gl_VertexID % 3];\n"
2549 " gl_Position = myBufferVals.mvp * pos;\n"
2550 "}\n";
2551
2552 static const char *fragShaderText =
2553 "#version 140\n"
2554 "#extension GL_ARB_separate_shader_objects : enable\n"
2555 "#extension GL_ARB_shading_language_420pack : enable\n"
2556 "layout (binding=0) uniform sampler2D surface;\n"
2557 "layout (location=0) out vec4 outColor;\n"
2558 "layout (location=0) in vec2 UV;\n"
2559 "void main() {\n"
2560 " outColor= textureLod(surface, UV, 0.0);\n"
2561 "}\n";
2562 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2563
2564 glm::mat4 View = glm::lookAt(
2565 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2566 glm::vec3(0,0,0), // and looks at the origin
2567 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2568 );
2569
2570 glm::mat4 Model = glm::mat4(1.0f);
2571
2572 glm::mat4 MVP = Projection * View * Model;
2573
2574
2575 ASSERT_NO_FATAL_FAILURE(InitState());
2576 ASSERT_NO_FATAL_FAILURE(InitViewport());
2577 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2578
2579 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2580 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Chia-I Wu714df452015-01-01 07:55:04 +08002581 meshBuffer.SetBufferState(XGL_BUFFER_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07002582
2583
2584 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2585
2586 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2587 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2588 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2589 XglSamplerObj sampler(m_device);
2590 XglTextureObj texture(m_device);
2591
Chia-I Wu714df452015-01-01 07:55:04 +08002592 // vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2593 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002594 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002595 ps.BindShaderEntitySlotToSampler(0, &sampler);
2596
2597 XglPipelineObj pipelineobj(m_device);
2598 pipelineobj.AddShader(&vs);
2599 pipelineobj.AddShader(&ps);
2600
2601 XglDescriptorSetObj descriptorSet(m_device);
2602
Chia-I Wu714df452015-01-01 07:55:04 +08002603 descriptorSet.AttachBufferView(&mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002604 descriptorSet.AttachImageView(&texture);
2605 descriptorSet.AttachSampler(&sampler);
2606
2607 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2608 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2609 m_memoryRefManager.AddMemoryRef(&texture);
2610
2611 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2612 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2613 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2614 };
2615
2616 // this is the current description of g_vbData
2617 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2618 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2619 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2620 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2621 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2622 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2623 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2624 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2625 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2626
2627 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2628 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2629 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2630
Tony Barbourfa6cac72015-01-16 14:27:35 -07002631 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2632 ds_state.depthTestEnable = XGL_TRUE;
2633 ds_state.depthWriteEnable = XGL_TRUE;
2634 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2635 ds_state.depthBoundsEnable = XGL_FALSE;
2636 ds_state.stencilTestEnable = XGL_FALSE;
2637 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2638 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2639 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2640 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2641 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2642 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2643 ds_state.front = ds_state.back;
2644 pipelineobj.SetDepthStencil(&ds_state);
2645
Tony Barbourdd4c9642015-01-09 12:55:14 -07002646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2647 XglCommandBufferObj cmdBuffer(m_device);
2648 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002649
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002650 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002651 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2652
2653 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2654#ifdef DUMP_STATE_DOT
2655 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2656 pDSDumpDot((char*)"triTest2.dot");
2657#endif
2658 // render triangle
2659 cmdBuffer.Draw(0, 36, 0, 1);
2660
2661 // finalize recording of the command buffer
2662 cmdBuffer.EndCommandBuffer();
2663 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2664
2665 for (int i = 0; i < m_renderTargetCount; i++)
2666 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002667
2668}
Cody Northropd1ce7842014-12-09 11:17:01 -07002669
2670TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2671{
2672 // This test mixes binding slots of textures and buffers, ensuring
2673 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002674 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002675 // you can modify it to move the desired result around.
2676
2677 static const char *vertShaderText =
2678 "#version 140\n"
2679 "#extension GL_ARB_separate_shader_objects : enable\n"
2680 "#extension GL_ARB_shading_language_420pack : enable\n"
2681 "void main() {\n"
2682 " vec2 vertices[3];"
2683 " vertices[0] = vec2(-0.5, -0.5);\n"
2684 " vertices[1] = vec2( 0.5, -0.5);\n"
2685 " vertices[2] = vec2( 0.5, 0.5);\n"
2686 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2687 "}\n";
2688
2689 static const char *fragShaderText =
2690 "#version 430\n"
2691 "#extension GL_ARB_separate_shader_objects : enable\n"
2692 "#extension GL_ARB_shading_language_420pack : enable\n"
2693 "layout (binding = 0) uniform sampler2D surface0;\n"
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002694 "layout (binding = 9) uniform sampler2D surface1;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002695 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropa0410942014-12-09 13:59:39 -07002696 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002697
Cody Northropa0410942014-12-09 13:59:39 -07002698
2699 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2700 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2701 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2702 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002703 "layout (location = 0) out vec4 outColor;\n"
2704 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002705 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002706 " outColor += white * vec4(0.00001);\n"
2707 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002708 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002709 "}\n";
2710 ASSERT_NO_FATAL_FAILURE(InitState());
2711 ASSERT_NO_FATAL_FAILURE(InitViewport());
2712
2713 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2714 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2715
Cody Northropd1ce7842014-12-09 11:17:01 -07002716 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2717 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2718 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2719 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2720
2721 const int redCount = sizeof(redVals) / sizeof(float);
2722 const int greenCount = sizeof(greenVals) / sizeof(float);
2723 const int blueCount = sizeof(blueVals) / sizeof(float);
2724 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2725
2726 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002727 ps.BindShaderEntitySlotToBuffer(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002728
2729 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002730 ps.BindShaderEntitySlotToBuffer(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002731
2732 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002733 ps.BindShaderEntitySlotToBuffer(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002734
2735 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002736 ps.BindShaderEntitySlotToBuffer(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002737
2738 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002739 XglTextureObj texture0(m_device); // Light Red
2740 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002741 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
Cody Northropd1ce7842014-12-09 11:17:01 -07002742 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2743 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002744 XglTextureObj texture2(m_device); // Light Blue
2745 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002746 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Cody Northropd1ce7842014-12-09 11:17:01 -07002747 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2748 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002749 XglTextureObj texture4(m_device); // Light Green
2750 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002751 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
Cody Northropd1ce7842014-12-09 11:17:01 -07002752 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002753
2754 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2755 // TODO: Get back here ASAP and understand why.
2756 XglSamplerObj sampler7(m_device);
2757 XglTextureObj texture7(m_device); // Red and Blue
2758 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002759 ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2760 ps.BindShaderEntitySlotToSampler(9, &sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002761
2762
2763 XglPipelineObj pipelineobj(m_device);
2764 pipelineobj.AddShader(&vs);
2765 pipelineobj.AddShader(&ps);
2766
2767 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002768 descriptorSet.AttachBufferView(&redBuffer);
2769 descriptorSet.AttachBufferView(&greenBuffer);
2770 descriptorSet.AttachBufferView(&blueBuffer);
2771 descriptorSet.AttachBufferView(&whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002772 descriptorSet.AttachImageView(&texture0);
2773 descriptorSet.AttachSampler(&sampler0);
2774 descriptorSet.AttachImageView(&texture2);
2775 descriptorSet.AttachSampler(&sampler2);
2776 descriptorSet.AttachImageView(&texture4);
2777 descriptorSet.AttachSampler(&sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002778 descriptorSet.AttachImageView(&texture7);
2779 descriptorSet.AttachSampler(&sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002780
2781 m_memoryRefManager.AddMemoryRef(&texture0);
2782 m_memoryRefManager.AddMemoryRef(&texture2);
2783 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002784 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002785
Tony Barbourdd4c9642015-01-09 12:55:14 -07002786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2787 XglCommandBufferObj cmdBuffer(m_device);
2788 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002789
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002790 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002791
2792 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2793
2794#ifdef DUMP_STATE_DOT
2795 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2796 pDSDumpDot((char*)"triTest2.dot");
2797#endif
2798 // render triangle
2799 cmdBuffer.Draw(0, 3, 0, 1);
2800
2801 // finalize recording of the command buffer
2802 cmdBuffer.EndCommandBuffer();
2803 cmdBuffer.QueueCommandBuffer(NULL, 0);
2804
2805 for (int i = 0; i < m_renderTargetCount; i++)
2806 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002807
2808}
2809
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002810TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2811{
2812 // This test matches binding slots of textures and buffers, requiring
2813 // the driver to give them distinct number spaces.
2814 // The expected result from this test is a red triangle, although
2815 // you can modify it to move the desired result around.
2816
2817 static const char *vertShaderText =
2818 "#version 140\n"
2819 "#extension GL_ARB_separate_shader_objects : enable\n"
2820 "#extension GL_ARB_shading_language_420pack : enable\n"
2821 "void main() {\n"
2822 " vec2 vertices[3];"
2823 " vertices[0] = vec2(-0.5, -0.5);\n"
2824 " vertices[1] = vec2( 0.5, -0.5);\n"
2825 " vertices[2] = vec2( 0.5, 0.5);\n"
2826 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2827 "}\n";
2828
2829 static const char *fragShaderText =
2830 "#version 430\n"
2831 "#extension GL_ARB_separate_shader_objects : enable\n"
2832 "#extension GL_ARB_shading_language_420pack : enable\n"
2833 "layout (binding = 0) uniform sampler2D surface0;\n"
2834 "layout (binding = 1) uniform sampler2D surface1;\n"
2835 "layout (binding = 2) uniform sampler2D surface2;\n"
2836 "layout (binding = 3) uniform sampler2D surface3;\n"
2837 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2838 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2839 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2840 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2841 "layout (location = 0) out vec4 outColor;\n"
2842 "void main() {\n"
2843 " outColor = red;// * vec4(0.00001);\n"
2844 " outColor += white * vec4(0.00001);\n"
2845 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2846 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2847 "}\n";
2848 ASSERT_NO_FATAL_FAILURE(InitState());
2849 ASSERT_NO_FATAL_FAILURE(InitViewport());
2850
2851 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2852 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2853
2854 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2855 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2856 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2857 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2858
2859 const int redCount = sizeof(redVals) / sizeof(float);
2860 const int greenCount = sizeof(greenVals) / sizeof(float);
2861 const int blueCount = sizeof(blueVals) / sizeof(float);
2862 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2863
2864 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002865 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002866
2867 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002868 ps.BindShaderEntitySlotToBuffer(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002869
2870 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002871 ps.BindShaderEntitySlotToBuffer(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002872
2873 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Chia-I Wu714df452015-01-01 07:55:04 +08002874 ps.BindShaderEntitySlotToBuffer(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002875
2876 XglSamplerObj sampler0(m_device);
2877 XglTextureObj texture0(m_device); // Light Red
2878 texture0.ChangeColors(0xff800000,0xff800000);
2879 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
2880 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2881 XglSamplerObj sampler2(m_device);
2882 XglTextureObj texture2(m_device); // Light Blue
2883 texture2.ChangeColors(0xff000080,0xff000080);
2884 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
2885 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2886 XglSamplerObj sampler4(m_device);
2887 XglTextureObj texture4(m_device); // Light Green
2888 texture4.ChangeColors(0xff008000,0xff008000);
2889 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
2890 ps.BindShaderEntitySlotToSampler(2, &sampler4);
2891 XglSamplerObj sampler7(m_device);
2892 XglTextureObj texture7(m_device); // Red and Blue
2893 texture7.ChangeColors(0xffff00ff,0xffff00ff);
2894 ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2895 ps.BindShaderEntitySlotToSampler(3, &sampler7);
2896
2897
2898 XglPipelineObj pipelineobj(m_device);
2899 pipelineobj.AddShader(&vs);
2900 pipelineobj.AddShader(&ps);
2901
2902 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08002903 descriptorSet.AttachBufferView(&redBuffer);
2904 descriptorSet.AttachBufferView(&greenBuffer);
2905 descriptorSet.AttachBufferView(&blueBuffer);
2906 descriptorSet.AttachBufferView(&whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002907 descriptorSet.AttachImageView(&texture0);
2908 descriptorSet.AttachSampler(&sampler0);
2909 descriptorSet.AttachImageView(&texture2);
2910 descriptorSet.AttachSampler(&sampler2);
2911 descriptorSet.AttachImageView(&texture4);
2912 descriptorSet.AttachSampler(&sampler4);
2913 descriptorSet.AttachImageView(&texture7);
2914 descriptorSet.AttachSampler(&sampler7);
2915
2916 m_memoryRefManager.AddMemoryRef(&texture0);
2917 m_memoryRefManager.AddMemoryRef(&texture2);
2918 m_memoryRefManager.AddMemoryRef(&texture4);
2919 m_memoryRefManager.AddMemoryRef(&texture7);
2920
Tony Barbourdd4c9642015-01-09 12:55:14 -07002921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2922 XglCommandBufferObj cmdBuffer(m_device);
2923 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002925 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002926
2927 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2928
2929#ifdef DUMP_STATE_DOT
2930 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2931 pDSDumpDot((char*)"triTest2.dot");
2932#endif
2933 // render triangle
2934 cmdBuffer.Draw(0, 3, 0, 1);
2935
2936 // finalize recording of the command buffer
2937 cmdBuffer.EndCommandBuffer();
2938 cmdBuffer.QueueCommandBuffer(NULL, 0);
2939
2940 for (int i = 0; i < m_renderTargetCount; i++)
2941 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002942
2943}
2944
Cody Northrop02690bd2014-12-17 15:26:33 -07002945TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2946{
2947 // This test populates a buffer with a variety of different data
2948 // types, then reads them out with a shader.
2949 // The expected result from this test is a green triangle
2950
2951 static const char *vertShaderText =
2952 "#version 140\n"
2953 "#extension GL_ARB_separate_shader_objects : enable\n"
2954 "#extension GL_ARB_shading_language_420pack : enable\n"
2955 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2956 " vec4 fRed;\n"
2957 " vec4 fGreen;\n"
2958 " layout(row_major) mat4 worldToProj;\n"
2959 " layout(row_major) mat4 projToWorld;\n"
2960 " layout(row_major) mat4 worldToView;\n"
2961 " layout(row_major) mat4 viewToProj;\n"
2962 " layout(row_major) mat4 worldToShadow[4];\n"
2963 " float fZero;\n"
2964 " float fOne;\n"
2965 " float fTwo;\n"
2966 " float fThree;\n"
2967 " vec3 fZeroZeroZero;\n"
2968 " float fFour;\n"
2969 " vec3 fZeroZeroOne;\n"
2970 " float fFive;\n"
2971 " vec3 fZeroOneZero;\n"
2972 " float fSix;\n"
2973 " float fSeven;\n"
2974 " float fEight;\n"
2975 " float fNine;\n"
2976 " vec2 fZeroZero;\n"
2977 " vec2 fZeroOne;\n"
2978 " vec4 fBlue;\n"
2979 " vec2 fOneZero;\n"
2980 " vec2 fOneOne;\n"
2981 " vec3 fZeroOneOne;\n"
2982 " float fTen;\n"
2983 " float fEleven;\n"
2984 " float fTwelve;\n"
2985 " vec3 fOneZeroZero;\n"
2986 " vec4 uvOffsets[4];\n"
2987 "};\n"
2988 "layout (location = 0) out vec4 color;"
2989 "void main() {\n"
2990
2991 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2992 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2993 " \n"
2994
2995 // do some exact comparisons, even though we should
2996 // really have an epsilon involved.
2997 " vec4 outColor = right;\n"
2998 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2999 " outColor = wrong;\n"
3000 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3001 " outColor = wrong;\n"
3002 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3003 " outColor = wrong;\n"
3004
3005 " color = outColor;\n"
3006
3007 // generic position stuff
3008 " vec2 vertices;\n"
3009 " int vertexSelector = gl_VertexID;\n"
3010 " if (vertexSelector == 0)\n"
3011 " vertices = vec2(-0.5, -0.5);\n"
3012 " else if (vertexSelector == 1)\n"
3013 " vertices = vec2( 0.5, -0.5);\n"
3014 " else if (vertexSelector == 2)\n"
3015 " vertices = vec2( 0.5, 0.5);\n"
3016 " else\n"
3017 " vertices = vec2( 0.0, 0.0);\n"
3018 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3019 "}\n";
3020
3021 static const char *fragShaderText =
3022 "#version 140\n"
3023 "#extension GL_ARB_separate_shader_objects : enable\n"
3024 "#extension GL_ARB_shading_language_420pack : enable\n"
3025 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3026 " vec4 fRed;\n"
3027 " vec4 fGreen;\n"
3028 " layout(row_major) mat4 worldToProj;\n"
3029 " layout(row_major) mat4 projToWorld;\n"
3030 " layout(row_major) mat4 worldToView;\n"
3031 " layout(row_major) mat4 viewToProj;\n"
3032 " layout(row_major) mat4 worldToShadow[4];\n"
3033 " float fZero;\n"
3034 " float fOne;\n"
3035 " float fTwo;\n"
3036 " float fThree;\n"
3037 " vec3 fZeroZeroZero;\n"
3038 " float fFour;\n"
3039 " vec3 fZeroZeroOne;\n"
3040 " float fFive;\n"
3041 " vec3 fZeroOneZero;\n"
3042 " float fSix;\n"
3043 " float fSeven;\n"
3044 " float fEight;\n"
3045 " float fNine;\n"
3046 " vec2 fZeroZero;\n"
3047 " vec2 fZeroOne;\n"
3048 " vec4 fBlue;\n"
3049 " vec2 fOneZero;\n"
3050 " vec2 fOneOne;\n"
3051 " vec3 fZeroOneOne;\n"
3052 " float fTen;\n"
3053 " float fEleven;\n"
3054 " float fTwelve;\n"
3055 " vec3 fOneZeroZero;\n"
3056 " vec4 uvOffsets[4];\n"
3057 "};\n"
3058 "layout (location = 0) in vec4 color;\n"
3059 "void main() {\n"
3060 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3061 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3062 " \n"
3063
3064 // start with VS value to ensure it passed
3065 " vec4 outColor = color;\n"
3066
3067 // do some exact comparisons, even though we should
3068 // really have an epsilon involved.
3069 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3070 " outColor = wrong;\n"
3071 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3072 " outColor = wrong;\n"
3073 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3074 " outColor = wrong;\n"
3075 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3076 " outColor = wrong;\n"
3077 " if (fTwo != 2.0)\n"
3078 " outColor = wrong;\n"
3079 " if (fOneOne != vec2(1.0, 1.0))\n"
3080 " outColor = wrong;\n"
3081 " if (fTen != 10.0)\n"
3082 " outColor = wrong;\n"
3083 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3084 " outColor = wrong;\n"
3085 " \n"
3086 " gl_FragColor = outColor;\n"
3087 "}\n";
3088
3089
3090 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3091 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3092 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3093 0.0, 1.0, 0.0, 1.0, // align
3094 0.0, 0.0, 1.0, 1.0, // align
3095 0.0, 0.0, 0.0, 1.0, // align
3096 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3097 0.0, 2.0, 0.0, 2.0, // align
3098 0.0, 0.0, 2.0, 2.0, // align
3099 0.0, 0.0, 0.0, 2.0, // align
3100 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3101 0.0, 3.0, 0.0, 3.0, // align
3102 0.0, 0.0, 3.0, 3.0, // align
3103 0.0, 0.0, 0.0, 3.0, // align
3104 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3105 0.0, 4.0, 0.0, 4.0, // align
3106 0.0, 0.0, 4.0, 4.0, // align
3107 0.0, 0.0, 0.0, 4.0, // align
3108 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3109 0.0, 5.0, 0.0, 5.0, // align
3110 0.0, 0.0, 5.0, 5.0, // align
3111 0.0, 0.0, 0.0, 5.0, // align
3112 6.0, 0.0, 0.0, 6.0, // align
3113 0.0, 6.0, 0.0, 6.0, // align
3114 0.0, 0.0, 6.0, 6.0, // align
3115 0.0, 0.0, 0.0, 6.0, // align
3116 7.0, 0.0, 0.0, 7.0, // align
3117 0.0, 7.0, 0.0, 7.0, // align
3118 0.0, 0.0, 7.0, 7.0, // align
3119 0.0, 0.0, 0.0, 7.0, // align
3120 8.0, 0.0, 0.0, 8.0, // align
3121 0.0, 8.0, 0.0, 8.0, // align
3122 0.0, 0.0, 8.0, 8.0, // align
3123 0.0, 0.0, 0.0, 8.0, // align
3124 0.0, // float fZero; // align
3125 1.0, // float fOne; // pack
3126 2.0, // float fTwo; // pack
3127 3.0, // float fThree; // pack
3128 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3129 4.0, // float fFour; // pack
3130 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3131 5.0, // float fFive; // pack
3132 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3133 6.0, // float fSix; // pack
3134 7.0, // float fSeven; // align
3135 8.0, // float fEight; // pack
3136 9.0, // float fNine; // pack
3137 0.0, // BUFFER
3138 0.0, 0.0, // vec2 fZeroZero; // align
3139 0.0, 1.0, // vec2 fZeroOne; // pack
3140 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3141 1.0, 0.0, // vec2 fOneZero; // align
3142 1.0, 1.0, // vec2 fOneOne; // pack
3143 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3144 10.0, // float fTen; // pack
3145 11.0, // float fEleven; // align
3146 12.0, // float fTwelve; // pack
3147 0.0, 0.0, // BUFFER
3148 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3149 0.0, // BUFFER
3150 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3151 0.5, 0.6, 0.7, 0.8, // align
3152 0.9, 1.0, 1.1, 1.2, // align
3153 1.3, 1.4, 1.5, 1.6, // align
3154 };
3155
3156 ASSERT_NO_FATAL_FAILURE(InitState());
3157 ASSERT_NO_FATAL_FAILURE(InitViewport());
3158
3159 const int constCount = sizeof(mixedVals) / sizeof(float);
3160
3161 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3162 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3163
3164 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Chia-I Wu714df452015-01-01 07:55:04 +08003165 vs.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mixedBuffer);
3166 ps.BindShaderEntitySlotToBuffer(0, XGL_SLOT_SHADER_RESOURCE, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003167
3168 XglPipelineObj pipelineobj(m_device);
3169 pipelineobj.AddShader(&vs);
3170 pipelineobj.AddShader(&ps);
3171
3172 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu714df452015-01-01 07:55:04 +08003173 descriptorSet.AttachBufferView(&mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003174
3175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3176 XglCommandBufferObj cmdBuffer(m_device);
3177 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3178
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003179 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003180
3181 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3182
3183#ifdef DUMP_STATE_DOT
3184 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3185 pDSDumpDot((char*)"triTest2.dot");
3186#endif
3187 // render triangle
3188 cmdBuffer.Draw(0, 3, 0, 1);
3189
3190 // finalize recording of the command buffer
3191 cmdBuffer.EndCommandBuffer();
3192 cmdBuffer.QueueCommandBuffer(NULL, 0);
3193
3194 for (int i = 0; i < m_renderTargetCount; i++)
3195 RecordImage(m_renderTargets[i]);
3196}
3197
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003198int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003199 int result;
3200
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003201 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003202 XglTestFramework::InitArgs(&argc, argv);
3203
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003204 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003205
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003206 result = RUN_ALL_TESTS();
3207
3208 XglTestFramework::Finish();
3209 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003210}