blob: 947c8fe4e668d8daa2ae5d182f134f0fbc64196a [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
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.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
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083void XGLAPI myDbgFunc(
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
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{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
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;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600233 uint32_t m_num_mem;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700234 XGL_GPU_MEMORY *m_depthStencilMem;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600235 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700236 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600237
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600238
239 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600240
241 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
242 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800243 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800245 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600246 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -0700247 this->app_info.apiVersion = XGL_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600248
Cody Northrop350727b2014-10-06 15:42:00 -0600249 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
250 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700251 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600252
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600253 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255
256 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600257 // Clean up resources before we reset
258 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260};
261
Tony Barbour02472db2015-01-08 17:08:28 -0700262void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
263{
264 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700265 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700266 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
269 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800270 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700271 pipelineobj->CreateXGLPipeline(descriptorSet);
272 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700273 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
274}
Tony Barbourf43b6982014-11-25 13:18:32 -0700275
Tony Barbourf43b6982014-11-25 13:18:32 -0700276void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700277 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
278{
279 int i;
280 glm::mat4 MVP;
281 int matrixSize = sizeof(MVP);
282 XGL_RESULT err;
283
284 for (i = 0; i < 8; i++) {
285 void *pData = constantBuffer->map();
286
287 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
288 MVP = Projection * View * Model;
289 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
290
291 constantBuffer->unmap();
292
293 // submit the command buffer to the universal queue
294 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
295
Tony Barbourdd4c9642015-01-09 12:55:14 -0700296 err = xglQueueWaitIdle( m_device->m_queue );
297 ASSERT_XGL_SUCCESS( err );
298
299 // Wait for work to finish before cleaning up.
300 xglDeviceWaitIdle(m_device->device());
301
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700302 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700303 RecordImage(m_renderTargets[0]);
304 }
305}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600306
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600307void dumpMatrix(const char *note, glm::mat4 MVP)
308{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800309 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600310
311 printf("%s: \n", note);
312 for (i=0; i<4; i++) {
313 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
314 }
315 printf("\n");
316 fflush(stdout);
317}
318
319void dumpVec4(const char *note, glm::vec4 vector)
320{
321 printf("%s: \n", note);
322 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
323 printf("\n");
324 fflush(stdout);
325}
326
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600327void XglRenderTest::InitDepthStencil()
328{
329 XGL_RESULT err;
330 XGL_IMAGE_CREATE_INFO image;
331 XGL_MEMORY_ALLOC_INFO mem_alloc;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700332 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600333 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700334 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600335 size_t mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700336 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600337 size_t img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
338 uint32_t num_allocations = 0;
339 size_t num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600340
341 // Clean up default state created by framework
342 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
343
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700344 m_depth_stencil_fmt = XGL_FMT_D16_UNORM;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600345
346 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
347 image.pNext = NULL;
348 image.imageType = XGL_IMAGE_2D;
349 image.format = m_depth_stencil_fmt;
350 image.extent.width = m_width;
351 image.extent.height = m_height;
352 image.extent.depth = 1;
353 image.mipLevels = 1;
354 image.arraySize = 1;
355 image.samples = 1;
356 image.tiling = XGL_OPTIMAL_TILING;
357 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
358 image.flags = 0;
359
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700360 img_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
361 img_alloc.pNext = NULL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600362 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700363 mem_alloc.pNext = &img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600364 mem_alloc.allocationSize = 0;
Jon Ashburn542cd092015-01-20 13:55:32 -0700365 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburn32769172015-01-20 15:06:59 -0700366 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600367 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
368
369 /* create image */
370 err = xglCreateImage(device(), &image,
371 &m_depthStencilImage);
372 ASSERT_XGL_SUCCESS(err);
373
374 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700375 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
376 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600377 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700378 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
379 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
380 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
381 m_num_mem = num_allocations;
382 err = xglGetObjectInfo(m_depthStencilImage,
383 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
384 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600385 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700386 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700387 err = xglGetObjectInfo(m_depthStencilImage,
388 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
389 &img_reqs_size, &img_reqs);
390 ASSERT_XGL_SUCCESS(err);
391 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
392 img_alloc.usage = img_reqs.usage;
393 img_alloc.formatClass = img_reqs.formatClass;
394 img_alloc.samples = img_reqs.samples;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600395 for (uint32_t i = 0; i < num_allocations; i ++) {
Jon Ashburna9ae3832015-01-16 09:37:43 -0700396 mem_alloc.allocationSize = mem_reqs[i].size;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700397
398 /* allocate memory */
399 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
400 ASSERT_XGL_SUCCESS(err);
401
402 /* bind memory */
403 err = xglBindObjectMemory(m_depthStencilImage, i,
404 m_depthStencilMem[i], 0);
405 ASSERT_XGL_SUCCESS(err);
406 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600407
Tony Barbourfa6cac72015-01-16 14:27:35 -0700408 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
409 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
410
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600411 depthStencil.minDepth = 0.f;
412 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 depthStencil.stencilBackRef = 0;
414 depthStencil.stencilFrontRef = 0;
415 depthStencil.stencilReadMask = 0xff;
416 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600417
Tony Barbourfa6cac72015-01-16 14:27:35 -0700418 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600419 ASSERT_XGL_SUCCESS( err );
420
421 /* create image view */
422 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
423 view.pNext = NULL;
424 view.image = XGL_NULL_HANDLE;
425 view.mipLevel = 0;
426 view.baseArraySlice = 0;
427 view.arraySize = 1;
428 view.flags = 0;
429 view.image = m_depthStencilImage;
430 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
431 ASSERT_XGL_SUCCESS(err);
432
433 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000434 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600435}
436
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600437struct xgltriangle_vs_uniform {
438 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600439 float mvp[4][4];
440 float position[3][4];
441 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600442};
443
Tony Barbourae442072015-01-12 13:27:11 -0700444void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600445{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700446#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600447 xglDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700448#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600449 // Create identity matrix
450 int i;
451 struct xgltriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
457 const int matrixSize = sizeof(MVP);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600458 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600459 memcpy(&data.mvp, &MVP[0][0], matrixSize);
460
461 static const Vertex tri_data[] =
462 {
463 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
464 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
465 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
466 };
467
468 for (i=0; i<3; i++) {
469 data.position[i][0] = tri_data[i].posX;
470 data.position[i][1] = tri_data[i].posY;
471 data.position[i][2] = tri_data[i].posZ;
472 data.position[i][3] = tri_data[i].posW;
473 data.color[i][0] = tri_data[i].r;
474 data.color[i][1] = tri_data[i].g;
475 data.color[i][2] = tri_data[i].b;
476 data.color[i][3] = tri_data[i].a;
477 }
478
Tony Barbourf43b6982014-11-25 13:18:32 -0700479 ASSERT_NO_FATAL_FAILURE(InitState());
480 ASSERT_NO_FATAL_FAILURE(InitViewport());
481
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600482 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700483
484 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
485 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700486
487 XglPipelineObj pipelineobj(m_device);
488 pipelineobj.AddShader(&vs);
489 pipelineobj.AddShader(&ps);
490
491 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800492 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700493 m_memoryRefManager.AddMemoryRef(&constantBuffer);
494
Tony Barbour71ba3612015-01-09 16:12:35 -0700495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700496 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour71ba3612015-01-09 16:12:35 -0700497 XglCommandBufferObj cmdBuffer(m_device);
498 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700499
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700500 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700501
502 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700503#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600504 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700505 pDSDumpDot((char*)"triTest2.dot");
506#endif
507 // render triangle
508 cmdBuffer.Draw(0, 3, 0, 1);
509
510 // finalize recording of the command buffer
511 cmdBuffer.EndCommandBuffer();
512 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
513
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700514 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour71ba3612015-01-09 16:12:35 -0700515 RecordImage(m_renderTargets[i]);
516
517 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600518 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700519
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700520#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600521 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
522 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
523 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
524 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700525 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600526 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700527 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
528 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
529 for (i=0; i < numObjects; i++) {
530 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);
531 }
532 free(pObjNodeArray);
533#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700534
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600535}
536
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600537TEST_F(XglRenderTest, XGLTriangle_FragColor)
538{
539 static const char *vertShaderText =
540 "#version 140\n"
541 "#extension GL_ARB_separate_shader_objects : enable\n"
542 "#extension GL_ARB_shading_language_420pack : enable\n"
543 "\n"
544 "layout(binding = 0) uniform buf {\n"
545 " mat4 MVP;\n"
546 " vec4 position[3];\n"
547 " vec4 color[3];\n"
548 "} ubuf;\n"
549 "\n"
550 "layout (location = 0) out vec4 outColor;\n"
551 "\n"
552 "void main() \n"
553 "{\n"
554 " outColor = ubuf.color[gl_VertexID];\n"
555 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
556 "}\n";
557
558 static const char *fragShaderText =
559 "#version 140\n"
560 "#extension GL_ARB_separate_shader_objects : enable\n"
561 "#extension GL_ARB_shading_language_420pack : enable\n"
562 "\n"
563 "layout (location = 0) in vec4 inColor;\n"
564 "\n"
565 "void main()\n"
566 "{\n"
567 " gl_FragColor = inColor;\n"
568 "}\n";
569
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600570 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700571 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600572}
573
574TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
575{
576 static const char *vertShaderText =
577 "#version 140\n"
578 "#extension GL_ARB_separate_shader_objects : enable\n"
579 "#extension GL_ARB_shading_language_420pack : enable\n"
580 "\n"
581 "layout(binding = 0) uniform buf {\n"
582 " mat4 MVP;\n"
583 " vec4 position[3];\n"
584 " vec4 color[3];\n"
585 "} ubuf;\n"
586 "\n"
587 "layout (location = 0) out vec4 outColor;\n"
588 "\n"
589 "void main() \n"
590 "{\n"
591 " outColor = ubuf.color[gl_VertexID];\n"
592 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
593 "}\n";
594
595 static const char *fragShaderText =
596 "#version 140\n"
597 "#extension GL_ARB_separate_shader_objects : enable\n"
598 "#extension GL_ARB_shading_language_420pack : enable\n"
599 "\n"
600 "layout (location = 0) in vec4 inColor;\n"
601 "layout (location = 0) out vec4 outColor;\n"
602 "\n"
603 "void main()\n"
604 "{\n"
605 " outColor = inColor;\n"
606 "}\n";
607
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600608 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 -0600609
Tony Barbourae442072015-01-12 13:27:11 -0700610 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600611}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600612#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600613TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700614{
Cody Northropacfb0492015-03-17 15:55:58 -0600615 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700616
617 static const char *vertShaderText =
618 "#version 140\n"
619 "#extension GL_ARB_separate_shader_objects : enable\n"
620 "#extension GL_ARB_shading_language_420pack : enable\n"
621 "\n"
622 "layout(binding = 0) uniform buf {\n"
623 " mat4 MVP;\n"
624 " vec4 position[3];\n"
625 " vec4 color[3];\n"
626 "} ubuf;\n"
627 "\n"
628 "layout (location = 0) out vec4 outColor;\n"
629 "\n"
630 "void main() \n"
631 "{\n"
632 " outColor = ubuf.color[gl_VertexID];\n"
633 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
634 "}\n";
635
636 static const char *fragShaderText =
637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "\n"
641 "layout (location = 0) in vec4 inColor;\n"
642 "\n"
643 "void main()\n"
644 "{\n"
645 " gl_FragColor = inColor;\n"
646 "}\n";
647
Cody Northropacfb0492015-03-17 15:55:58 -0600648 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700649
Cody Northropacfb0492015-03-17 15:55:58 -0600650 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700651
Tony Barbourae442072015-01-12 13:27:11 -0700652 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700653
Cody Northropacfb0492015-03-17 15:55:58 -0600654 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700655}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600656#endif
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600657TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600658{
659 static const char *vertShaderText =
660 "#version 130\n"
661 "vec2 vertices[3];\n"
662 "void main() {\n"
663 " vertices[0] = vec2(-1.0, -1.0);\n"
664 " vertices[1] = vec2( 1.0, -1.0);\n"
665 " vertices[2] = vec2( 0.0, 1.0);\n"
666 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
667 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600668
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600669 static const char *fragShaderText =
670 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600671 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600672 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600673 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600674
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600675 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
676
Tony Barbourae442072015-01-12 13:27:11 -0700677 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600678}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600679#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600680TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700681{
Cody Northropacfb0492015-03-17 15:55:58 -0600682 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700683
684 static const char *vertShaderText =
685 "#version 130\n"
686 "vec2 vertices[3];\n"
687 "void main() {\n"
688 " vertices[0] = vec2(-1.0, -1.0);\n"
689 " vertices[1] = vec2( 1.0, -1.0);\n"
690 " vertices[2] = vec2( 0.0, 1.0);\n"
691 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
692 "}\n";
693
694 static const char *fragShaderText =
695 "#version 130\n"
696 "void main() {\n"
697 " gl_FragColor = vec4(0,1,0,1);\n"
698 "}\n";
699
Cody Northropacfb0492015-03-17 15:55:58 -0600700 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700701
Cody Northropacfb0492015-03-17 15:55:58 -0600702 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700703 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600704 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700705}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600706#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700707TEST_F(XglRenderTest, YellowTriangle)
708{
709 static const char *vertShaderText =
710 "#version 130\n"
711 "void main() {\n"
712 " vec2 vertices[3];"
713 " vertices[0] = vec2(-0.5, -0.5);\n"
714 " vertices[1] = vec2( 0.5, -0.5);\n"
715 " vertices[2] = vec2( 0.5, 0.5);\n"
716 " vec4 colors[3];\n"
717 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
718 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
719 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
720 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
721 "}\n";
722
723 static const char *fragShaderText =
724 "#version 130\n"
725 "void main() {\n"
726 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
727 "}\n";
728
Tony Barbourae442072015-01-12 13:27:11 -0700729 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700730}
731
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600732TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600733{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600734 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700735 "#version 130\n"
736 //XYZ1( -1, -1, -1 )
737 "in vec4 pos;\n"
738 //XYZ1( 0.f, 0.f, 0.f )
739 "in vec4 inColor;\n"
740 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600741 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600742 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600743 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600744 "}\n";
745
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600746
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600747 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700748 "#version 140\n"
749 "#extension GL_ARB_separate_shader_objects : enable\n"
750 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700751 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700752 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600753 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700754 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600755 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600756
Tony Barbourf43b6982014-11-25 13:18:32 -0700757
758
759 ASSERT_NO_FATAL_FAILURE(InitState());
760 ASSERT_NO_FATAL_FAILURE(InitViewport());
761
762 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000763 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700764
765 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
766 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
767
768 XglPipelineObj pipelineobj(m_device);
769 pipelineobj.AddShader(&vs);
770 pipelineobj.AddShader(&ps);
771
772 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800773 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700774
Mark Lobodzinski15427102015-02-18 16:38:17 -0600775 m_memoryRefManager.AddMemoryRef(&meshBuffer);
776
Tony Barbourf43b6982014-11-25 13:18:32 -0700777 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
778 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
779 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
780 };
781
782 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
783 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700784 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700785 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
786 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700787 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700788 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
789
790 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
791 pipelineobj.AddVertexInputBindings(&vi_binding,1);
792 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
793
Tony Barboure4ed9942015-01-09 10:06:53 -0700794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700795 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700796 XglCommandBufferObj cmdBuffer(m_device);
797 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700798
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700799 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700800 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
801
Tony Barboure4ed9942015-01-09 10:06:53 -0700802 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
803
804 // render two triangles
805 cmdBuffer.Draw(0, 6, 0, 1);
806
807 // finalize recording of the command buffer
808 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -0600809 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700810
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700811 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -0700812 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600813}
814
Chia-I Wue09d1a72014-12-05 10:32:23 +0800815TEST_F(XglRenderTest, TriangleMRT)
816{
817 static const char *vertShaderText =
818 "#version 130\n"
819 "in vec4 pos;\n"
820 "void main() {\n"
821 " gl_Position = pos;\n"
822 "}\n";
823
824 static const char *fragShaderText =
825 "#version 130\n"
826 "void main() {\n"
827 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
828 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
829 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600830 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 { -1.0f, -1.0f },
832 { 1.0f, -1.0f },
833 { -1.0f, 1.0f }
834 };
835
836 ASSERT_NO_FATAL_FAILURE(InitState());
837 ASSERT_NO_FATAL_FAILURE(InitViewport());
838
839 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000840 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841
842 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
843 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
844
845 XglPipelineObj pipelineobj(m_device);
846 pipelineobj.AddShader(&vs);
847 pipelineobj.AddShader(&ps);
848
849 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
850 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
851 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
852 };
853
854 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
855 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700856 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
858
859 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
860 pipelineobj.AddVertexInputBindings(&vi_binding,1);
861 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
862
863 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600864 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800865
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
867 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600868 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869
870 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
871 att.blendEnable = XGL_FALSE;
872 att.format = m_render_target_fmt;
873 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700874 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800875
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700877
Tony Barbour5ed79702015-01-07 14:31:52 -0700878 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
879 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700880
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700881 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700882
Tony Barboure4ed9942015-01-09 10:06:53 -0700883 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
884
Tony Barbour5ed79702015-01-07 14:31:52 -0700885 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700886#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600887 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700888 pDSDumpDot((char*)"triTest2.dot");
889#endif
890 // render triangle
891 cmdBuffer.Draw(0, 3, 0, 1);
892
893 // finalize recording of the command buffer
894 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -0600895 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700896
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700897 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour5ed79702015-01-07 14:31:52 -0700898 RecordImage(m_renderTargets[i]);
899
Chia-I Wue09d1a72014-12-05 10:32:23 +0800900}
901
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700902TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
903{
904 static const char *vertShaderText =
905 "#version 140\n"
906 "#extension GL_ARB_separate_shader_objects : enable\n"
907 "#extension GL_ARB_shading_language_420pack : enable\n"
908 "layout(location = 0) in vec4 pos;\n"
909 "layout(location = 1) in vec4 inColor;\n"
910 "layout(location = 0) out vec4 outColor;\n"
911 "void main() {\n"
912 " outColor = inColor;\n"
913 " gl_Position = pos;\n"
914 "}\n";
915
916
917 static const char *fragShaderText =
918 "#version 140\n"
919 "#extension GL_ARB_separate_shader_objects : enable\n"
920 "#extension GL_ARB_shading_language_420pack : enable\n"
921 "layout(location = 0) in vec4 color;\n"
922 "void main() {\n"
923 " gl_FragColor = color;\n"
924 "}\n";
925
926 const Vertex g_vbData[] =
927 {
928 // first tri
929 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
930 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
931 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
932
933 // second tri
934 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
935 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
936 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
937 };
938
939 const uint16_t g_idxData[6] = {
940 0, 1, 2,
941 3, 4, 5,
942 };
943
944 ASSERT_NO_FATAL_FAILURE(InitState());
945 ASSERT_NO_FATAL_FAILURE(InitViewport());
946
947 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000948 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700949
950 XglIndexBufferObj indexBuffer(m_device);
951 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600952 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953
954 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
955 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
956
957 XglPipelineObj pipelineobj(m_device);
958 pipelineobj.AddShader(&vs);
959 pipelineobj.AddShader(&ps);
960
961 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600962 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
963 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
964
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700965
Mark Lobodzinski15427102015-02-18 16:38:17 -0600966 m_memoryRefManager.AddMemoryRef(&meshBuffer);
967 m_memoryRefManager.AddMemoryRef(&indexBuffer);
968
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
970 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
971 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
972 };
973
974 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
975 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700976 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700977 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
978 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700979 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
981
982 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
983 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984
985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700986 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700987 XglCommandBufferObj cmdBuffer(m_device);
988 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700989 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700990
991 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700992
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700993#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600994 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700995 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700996#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700997
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700998 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
999 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001000
1001 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001002 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001003
1004 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001005 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001006 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001007
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001008 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001009 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001010
1011}
1012
GregF6bef1212014-12-02 15:41:44 -07001013TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1014{
1015 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001016
GregF6bef1212014-12-02 15:41:44 -07001017 static const char *vertShaderText =
1018 "#version 140\n"
1019 "#extension GL_ARB_separate_shader_objects : enable\n"
1020 "#extension GL_ARB_shading_language_420pack : enable\n"
1021 "layout (location = 0) in vec4 pos;\n"
1022 "layout (location = 0) out vec4 outColor;\n"
1023 "layout (location = 1) out vec4 outColor2;\n"
1024 "void main() {\n"
1025 " gl_Position = pos;\n"
1026 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1027 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1028 "}\n";
1029
1030 static const char *fragShaderText =
1031 //"#version 140\n"
1032 "#version 330\n"
1033 "#extension GL_ARB_separate_shader_objects : enable\n"
1034 "#extension GL_ARB_shading_language_420pack : enable\n"
1035 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1036 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1037 "layout (location = 0) in vec4 color;\n"
1038 "layout (location = 1) in vec4 color2;\n"
1039 "void main() {\n"
1040 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1041 " float dist_squared = dot(pos, pos);\n"
1042 " gl_FragColor = (dist_squared < 400.0)\n"
1043 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1044 " : color2;\n"
1045 "}\n";
1046
1047 ASSERT_NO_FATAL_FAILURE(InitState());
1048 ASSERT_NO_FATAL_FAILURE(InitViewport());
1049
1050 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001051 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001052
1053 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1054 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1055
1056 XglPipelineObj pipelineobj(m_device);
1057 pipelineobj.AddShader(&vs);
1058 pipelineobj.AddShader(&ps);
1059
1060 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001061 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001062
Mark Lobodzinski15427102015-02-18 16:38:17 -06001063 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1064
GregF6bef1212014-12-02 15:41:44 -07001065 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1066 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1067 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1068 };
1069
1070 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1071 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001072 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001073 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1074 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001075 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001076 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1077
1078 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1079 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1080 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1081
Tony Barbourdd4c9642015-01-09 12:55:14 -07001082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001083 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001084 XglCommandBufferObj cmdBuffer(m_device);
1085 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1086
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001087 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001088
1089 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1090
1091 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1092#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001093 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001094 pDSDumpDot((char*)"triTest2.dot");
1095#endif
1096 // render triangle
1097 cmdBuffer.Draw(0, 6, 0, 1);
1098
1099 // finalize recording of the command buffer
1100 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001101 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001102
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001103 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001104 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001105
1106}
1107
1108TEST_F(XglRenderTest, RedCirclesonBlue)
1109{
1110 // This tests that we correctly handle unread fragment inputs
1111
1112 static const char *vertShaderText =
1113 "#version 140\n"
1114 "#extension GL_ARB_separate_shader_objects : enable\n"
1115 "#extension GL_ARB_shading_language_420pack : enable\n"
1116 "layout (location = 0) in vec4 pos;\n"
1117 "layout (location = 0) out vec4 outColor;\n"
1118 "layout (location = 1) out vec4 outColor2;\n"
1119 "void main() {\n"
1120 " gl_Position = pos;\n"
1121 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1122 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1123 "}\n";
1124
1125 static const char *fragShaderText =
1126 //"#version 140\n"
1127 "#version 330\n"
1128 "#extension GL_ARB_separate_shader_objects : enable\n"
1129 "#extension GL_ARB_shading_language_420pack : enable\n"
1130 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1131 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1132 "layout (location = 0) in vec4 color;\n"
1133 "layout (location = 1) in vec4 color2;\n"
1134 "void main() {\n"
1135 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1136 " float dist_squared = dot(pos, pos);\n"
1137 " gl_FragColor = (dist_squared < 400.0)\n"
1138 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1139 " : color2;\n"
1140 "}\n";
1141
1142 ASSERT_NO_FATAL_FAILURE(InitState());
1143 ASSERT_NO_FATAL_FAILURE(InitViewport());
1144
1145 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001146 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001147
1148 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1149 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1150
1151 XglPipelineObj pipelineobj(m_device);
1152 pipelineobj.AddShader(&vs);
1153 pipelineobj.AddShader(&ps);
1154
1155 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001156 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001157
Mark Lobodzinski15427102015-02-18 16:38:17 -06001158 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1159
GregF6bef1212014-12-02 15:41:44 -07001160 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1161 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1162 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1163 };
1164
1165 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1166 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001167 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001168 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1169 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001170 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001171 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1172
1173 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1174 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1175 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1176
Tony Barbourdd4c9642015-01-09 12:55:14 -07001177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001178 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001179 XglCommandBufferObj cmdBuffer(m_device);
1180 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1181
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001182 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001183
1184 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1185
1186 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1187#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001188 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001189 pDSDumpDot((char*)"triTest2.dot");
1190#endif
1191 // render triangle
1192 cmdBuffer.Draw(0, 6, 0, 1);
1193
1194 // finalize recording of the command buffer
1195 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001196 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001197
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001198 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001199 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001200
1201}
1202
1203TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1204{
1205 // This tests reading gl_ClipDistance from FS
1206
1207 static const char *vertShaderText =
1208 "#version 330\n"
1209 "#extension GL_ARB_separate_shader_objects : enable\n"
1210 "#extension GL_ARB_shading_language_420pack : enable\n"
1211 "out gl_PerVertex {\n"
1212 " vec4 gl_Position;\n"
1213 " float gl_ClipDistance[1];\n"
1214 "};\n"
1215 "layout (location = 0) in vec4 pos;\n"
1216 "layout (location = 0) out vec4 outColor;\n"
1217 "layout (location = 1) out vec4 outColor2;\n"
1218 "void main() {\n"
1219 " gl_Position = pos;\n"
1220 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1221 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1222 " float dists[3];\n"
1223 " dists[0] = 0.0;\n"
1224 " dists[1] = 1.0;\n"
1225 " dists[2] = 1.0;\n"
1226 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1227 "}\n";
1228
1229
1230 static const char *fragShaderText =
1231 //"#version 140\n"
1232 "#version 330\n"
1233 "#extension GL_ARB_separate_shader_objects : enable\n"
1234 "#extension GL_ARB_shading_language_420pack : enable\n"
1235 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1236 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1237 "layout (location = 0) in vec4 color;\n"
1238 "layout (location = 1) in vec4 color2;\n"
1239 "void main() {\n"
1240 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1241 " float dist_squared = dot(pos, pos);\n"
1242 " gl_FragColor = (dist_squared < 400.0)\n"
1243 " ? color * gl_ClipDistance[0]\n"
1244 " : color2;\n"
1245 "}\n";
1246
1247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249
1250 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001251 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001252
1253 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1254 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1255
1256 XglPipelineObj pipelineobj(m_device);
1257 pipelineobj.AddShader(&vs);
1258 pipelineobj.AddShader(&ps);
1259
1260 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001261 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001262
Mark Lobodzinski15427102015-02-18 16:38:17 -06001263 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1264
GregF6bef1212014-12-02 15:41:44 -07001265 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1266 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1267 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1268 };
1269
1270 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1271 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001272 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001273 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1274 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001275 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001276 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1277
1278 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1279 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1280 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1281
Tony Barbourdd4c9642015-01-09 12:55:14 -07001282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001283 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001284 XglCommandBufferObj cmdBuffer(m_device);
1285 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001286
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001287 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001288
1289 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1290
1291 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1292#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001293 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001294 pDSDumpDot((char*)"triTest2.dot");
1295#endif
1296 // render triangle
1297 cmdBuffer.Draw(0, 6, 0, 1);
1298
1299 // finalize recording of the command buffer
1300 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001301 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001302
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001303 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001304 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001305}
Tony Barbourf43b6982014-11-25 13:18:32 -07001306
GregF7a23c792014-12-02 17:19:34 -07001307TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1308{
1309 static const char *vertShaderText =
1310 "#version 140\n"
1311 "#extension GL_ARB_separate_shader_objects : enable\n"
1312 "#extension GL_ARB_shading_language_420pack : enable\n"
1313 "layout (location = 0) in vec4 pos;\n"
1314 "layout (location = 0) out vec4 outColor;\n"
1315 "layout (location = 1) out vec4 outColor2;\n"
1316 "void main() {\n"
1317 " gl_Position = pos;\n"
1318 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1319 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1320 "}\n";
1321
1322
1323 static const char *fragShaderText =
1324 //"#version 140\n"
1325 "#version 330\n"
1326 "#extension GL_ARB_separate_shader_objects : enable\n"
1327 "#extension GL_ARB_shading_language_420pack : enable\n"
1328 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1329 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1330 "layout (location = 0) in vec4 color;\n"
1331 "layout (location = 1) in vec4 color2;\n"
1332 "void main() {\n"
1333 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1334 " float dist_squared = dot(pos, pos);\n"
1335 " if (dist_squared < 100.0)\n"
1336 " discard;\n"
1337 " gl_FragColor = (dist_squared < 400.0)\n"
1338 " ? color\n"
1339 " : color2;\n"
1340 "}\n";
1341
1342 ASSERT_NO_FATAL_FAILURE(InitState());
1343 ASSERT_NO_FATAL_FAILURE(InitViewport());
1344
1345 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001346 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001347
1348 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1349 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1350
1351 XglPipelineObj pipelineobj(m_device);
1352 pipelineobj.AddShader(&vs);
1353 pipelineobj.AddShader(&ps);
1354
1355 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001356 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001357
Mark Lobodzinski15427102015-02-18 16:38:17 -06001358 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1359
GregF7a23c792014-12-02 17:19:34 -07001360 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1361 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1362 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1363 };
1364
1365 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1366 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001367 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001368 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1369 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001370 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001371 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1372
1373 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1374 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1375 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1376
Tony Barbourdd4c9642015-01-09 12:55:14 -07001377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001378 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001379 XglCommandBufferObj cmdBuffer(m_device);
1380 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1381
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001382 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001383
1384 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1385
1386 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1387#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001388 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001389 pDSDumpDot((char*)"triTest2.dot");
1390#endif
1391 // render triangle
1392 cmdBuffer.Draw(0, 6, 0, 1);
1393
1394 // finalize recording of the command buffer
1395 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001396 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001397
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001398 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001399 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001400
1401}
1402
1403
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001404TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405{
1406 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001407 "#version 140\n"
1408 "#extension GL_ARB_separate_shader_objects : enable\n"
1409 "#extension GL_ARB_shading_language_420pack : enable\n"
1410 "\n"
1411 "layout(binding = 0) uniform buf {\n"
1412 " mat4 MVP;\n"
1413 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001414 "void main() {\n"
1415 " vec2 vertices[3];"
1416 " vertices[0] = vec2(-0.5, -0.5);\n"
1417 " vertices[1] = vec2( 0.5, -0.5);\n"
1418 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001419 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001420 "}\n";
1421
1422 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001423 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001424 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001425 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001426 "}\n";
1427
Tony Barbourf43b6982014-11-25 13:18:32 -07001428 ASSERT_NO_FATAL_FAILURE(InitState());
1429 ASSERT_NO_FATAL_FAILURE(InitViewport());
1430
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001431 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001432 glm::mat4 Projection = glm::mat4(1.0f);
1433 glm::mat4 View = glm::mat4(1.0f);
1434 glm::mat4 Model = glm::mat4(1.0f);
1435 glm::mat4 MVP = Projection * View * Model;
1436 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1437
Tony Barbourf43b6982014-11-25 13:18:32 -07001438 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1439 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1440 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001441
Tony Barbourf43b6982014-11-25 13:18:32 -07001442 XglPipelineObj pipelineobj(m_device);
1443 pipelineobj.AddShader(&vs);
1444 pipelineobj.AddShader(&ps);
1445
1446 // Create descriptor set and attach the constant buffer to it
1447 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001448 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001449
1450 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1451
Tony Barbourdd4c9642015-01-09 12:55:14 -07001452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001453 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001454 XglCommandBufferObj cmdBuffer(m_device);
1455 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001456
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001457 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001458
1459 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1460
1461 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1462#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001463 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001464 pDSDumpDot((char*)"triTest2.dot");
1465#endif
1466 // render triangle
1467 cmdBuffer.Draw(0, 6, 0, 1);
1468
1469 // finalize recording of the command buffer
1470 cmdBuffer.EndCommandBuffer();
1471 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1472
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001473 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001474 RecordImage(m_renderTargets[i]);
1475
1476 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001477}
1478
Tony Barbourf43b6982014-11-25 13:18:32 -07001479TEST_F(XglRenderTest, MixTriangle)
1480{
1481 // This tests location applied to varyings. Notice that we have switched foo
1482 // and bar in the FS. The triangle should be blended with red, green and blue
1483 // corners.
1484 static const char *vertShaderText =
1485 "#version 140\n"
1486 "#extension GL_ARB_separate_shader_objects : enable\n"
1487 "#extension GL_ARB_shading_language_420pack : enable\n"
1488 "layout (location=0) out vec4 bar;\n"
1489 "layout (location=1) out vec4 foo;\n"
1490 "layout (location=2) out float scale;\n"
1491 "vec2 vertices[3];\n"
1492 "void main() {\n"
1493 " vertices[0] = vec2(-1.0, -1.0);\n"
1494 " vertices[1] = vec2( 1.0, -1.0);\n"
1495 " vertices[2] = vec2( 0.0, 1.0);\n"
1496 "vec4 colors[3];\n"
1497 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1498 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1499 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1500 " foo = colors[gl_VertexID % 3];\n"
1501 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1502 " scale = 1.0;\n"
1503 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1504 "}\n";
1505
1506 static const char *fragShaderText =
1507 "#version 140\n"
1508 "#extension GL_ARB_separate_shader_objects : enable\n"
1509 "#extension GL_ARB_shading_language_420pack : enable\n"
1510 "layout (location = 1) in vec4 bar;\n"
1511 "layout (location = 0) in vec4 foo;\n"
1512 "layout (location = 2) in float scale;\n"
1513 "void main() {\n"
1514 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1515 "}\n";
1516
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518 ASSERT_NO_FATAL_FAILURE(InitViewport());
1519
1520 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1521 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1522
1523 XglPipelineObj pipelineobj(m_device);
1524 pipelineobj.AddShader(&vs);
1525 pipelineobj.AddShader(&ps);
1526
1527 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001528 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001529
Tony Barbourdd4c9642015-01-09 12:55:14 -07001530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001531 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001532 XglCommandBufferObj cmdBuffer(m_device);
1533 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1534
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001535 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001536
1537 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1538
1539#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001540 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001541 pDSDumpDot((char*)"triTest2.dot");
1542#endif
1543 // render triangle
1544 cmdBuffer.Draw(0, 3, 0, 1);
1545
1546 // finalize recording of the command buffer
1547 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001548 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001549
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001550 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001551 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001552}
1553
1554TEST_F(XglRenderTest, TriVertFetchAndVertID)
1555{
1556 // This tests that attributes work in the presence of gl_VertexID
1557
1558 static const char *vertShaderText =
1559 "#version 140\n"
1560 "#extension GL_ARB_separate_shader_objects : enable\n"
1561 "#extension GL_ARB_shading_language_420pack : enable\n"
1562 //XYZ1( -1, -1, -1 )
1563 "layout (location = 0) in vec4 pos;\n"
1564 //XYZ1( 0.f, 0.f, 0.f )
1565 "layout (location = 1) in vec4 inColor;\n"
1566 "layout (location = 0) out vec4 outColor;\n"
1567 "void main() {\n"
1568 " outColor = inColor;\n"
1569 " vec4 vertices[3];"
1570 " vertices[gl_VertexID % 3] = pos;\n"
1571 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1572 "}\n";
1573
1574
1575 static const char *fragShaderText =
1576 "#version 140\n"
1577 "#extension GL_ARB_separate_shader_objects : enable\n"
1578 "#extension GL_ARB_shading_language_420pack : enable\n"
1579 "layout (location = 0) in vec4 color;\n"
1580 "void main() {\n"
1581 " gl_FragColor = color;\n"
1582 "}\n";
1583
1584 ASSERT_NO_FATAL_FAILURE(InitState());
1585 ASSERT_NO_FATAL_FAILURE(InitViewport());
1586
1587 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001588 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001589
1590 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1591 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1592
1593 XglPipelineObj pipelineobj(m_device);
1594 pipelineobj.AddShader(&vs);
1595 pipelineobj.AddShader(&ps);
1596
1597 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001599
Mark Lobodzinski15427102015-02-18 16:38:17 -06001600 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1601
Tony Barbourf43b6982014-11-25 13:18:32 -07001602 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1603 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1604 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1605 };
1606
1607 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1608 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001609 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001610 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1611 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001612 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001613 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1614
1615 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1616 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1617 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1618
Tony Barbourdd4c9642015-01-09 12:55:14 -07001619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001620 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001621 XglCommandBufferObj cmdBuffer(m_device);
1622 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1623
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001624 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001625
1626 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1627
1628 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1629#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001630 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001631 pDSDumpDot((char*)"triTest2.dot");
1632#endif
1633 // render triangle
1634 cmdBuffer.Draw(0, 6, 0, 1);
1635
1636 // finalize recording of the command buffer
1637 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001638 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001639
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001640 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001641 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001642}
1643
1644TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1645{
1646 // This tests that attributes work in the presence of gl_VertexID
1647 // and a dead attribute in position 0. Draws a triangle with yellow,
1648 // red and green corners, starting at top and going clockwise.
1649
1650 static const char *vertShaderText =
1651 "#version 140\n"
1652 "#extension GL_ARB_separate_shader_objects : enable\n"
1653 "#extension GL_ARB_shading_language_420pack : enable\n"
1654 //XYZ1( -1, -1, -1 )
1655 "layout (location = 0) in vec4 pos;\n"
1656 //XYZ1( 0.f, 0.f, 0.f )
1657 "layout (location = 1) in vec4 inColor;\n"
1658 "layout (location = 0) out vec4 outColor;\n"
1659 "void main() {\n"
1660 " outColor = inColor;\n"
1661 " vec2 vertices[3];"
1662 " vertices[0] = vec2(-1.0, -1.0);\n"
1663 " vertices[1] = vec2( 1.0, -1.0);\n"
1664 " vertices[2] = vec2( 0.0, 1.0);\n"
1665 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1666 "}\n";
1667
1668
1669 static const char *fragShaderText =
1670 "#version 140\n"
1671 "#extension GL_ARB_separate_shader_objects : enable\n"
1672 "#extension GL_ARB_shading_language_420pack : enable\n"
1673 "layout (location = 0) in vec4 color;\n"
1674 "void main() {\n"
1675 " gl_FragColor = color;\n"
1676 "}\n";
1677
1678 ASSERT_NO_FATAL_FAILURE(InitState());
1679 ASSERT_NO_FATAL_FAILURE(InitViewport());
1680
1681 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001682 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001683
1684 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1685 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1686
1687 XglPipelineObj pipelineobj(m_device);
1688 pipelineobj.AddShader(&vs);
1689 pipelineobj.AddShader(&ps);
1690
1691 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001692 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001693
Mark Lobodzinski15427102015-02-18 16:38:17 -06001694 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1695
Tony Barbourf43b6982014-11-25 13:18:32 -07001696 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1697 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1698 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1699 };
1700
1701 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1702 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001703 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001704 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1705 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001706 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001707 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1708
1709 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1710 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1711 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1712
Tony Barbourdd4c9642015-01-09 12:55:14 -07001713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001714 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001715 XglCommandBufferObj cmdBuffer(m_device);
1716 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001717
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001718 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001719
1720 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1721
1722 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1723#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001724 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001725 pDSDumpDot((char*)"triTest2.dot");
1726#endif
1727 // render triangle
1728 cmdBuffer.Draw(0, 6, 0, 1);
1729
1730 // finalize recording of the command buffer
1731 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001732 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001733
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001734 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001735 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001736}
1737
1738TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001739{
1740 static const char *vertShaderText =
1741 "#version 140\n"
1742 "layout (std140) uniform bufferVals {\n"
1743 " mat4 mvp;\n"
1744 "} myBufferVals;\n"
1745 "in vec4 pos;\n"
1746 "in vec4 inColor;\n"
1747 "out vec4 outColor;\n"
1748 "void main() {\n"
1749 " outColor = inColor;\n"
1750 " gl_Position = myBufferVals.mvp * pos;\n"
1751 "}\n";
1752
1753 static const char *fragShaderText =
1754 "#version 130\n"
1755 "in vec4 color;\n"
1756 "void main() {\n"
1757 " gl_FragColor = color;\n"
1758 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001759 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001760
Tony Barbourf43b6982014-11-25 13:18:32 -07001761 glm::mat4 View = glm::lookAt(
1762 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1763 glm::vec3(0,0,0), // and looks at the origin
1764 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1765 );
1766
1767 glm::mat4 Model = glm::mat4(1.0f);
1768
1769 glm::mat4 MVP = Projection * View * Model;
1770
1771 ASSERT_NO_FATAL_FAILURE(InitState());
1772 ASSERT_NO_FATAL_FAILURE(InitViewport());
1773 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1774
1775 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1776 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1777
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001778 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001779
1780 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1781 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1782 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1783
Tony Barbourf43b6982014-11-25 13:18:32 -07001784 XglPipelineObj pipelineobj(m_device);
1785 pipelineobj.AddShader(&vs);
1786 pipelineobj.AddShader(&ps);
1787
Tony Barbourfa6cac72015-01-16 14:27:35 -07001788 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1789 ds_state.depthTestEnable = XGL_TRUE;
1790 ds_state.depthWriteEnable = XGL_TRUE;
1791 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1792 ds_state.depthBoundsEnable = XGL_FALSE;
1793 ds_state.stencilTestEnable = XGL_FALSE;
1794 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1795 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1796 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1797 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001798 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001799 ds_state.front = ds_state.back;
1800 pipelineobj.SetDepthStencil(&ds_state);
1801
Tony Barbourf43b6982014-11-25 13:18:32 -07001802 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001803 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001804
1805 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1806 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001807 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07001808
1809 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1810 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1811 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1812 };
1813
1814 // this is the current description of g_vbData
1815 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1816 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001817 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001818 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1819 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001820 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001821 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1822
1823 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1824 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1825 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1826
Tony Barboure4ed9942015-01-09 10:06:53 -07001827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001828 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -07001829 XglCommandBufferObj cmdBuffer(m_device);
1830 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001831
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001832 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001833 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001834
Tony Barboure4ed9942015-01-09 10:06:53 -07001835 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1836#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001837 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001838 pDSDumpDot((char*)"triTest2.dot");
1839#endif
1840 // render triangle
1841 cmdBuffer.Draw(0, 36, 0, 1);
1842
1843 // finalize recording of the command buffer
1844 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001845 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001846
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001847 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001848 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001849}
1850
Tony Barbourf43b6982014-11-25 13:18:32 -07001851TEST_F(XglRenderTest, VSTexture)
1852{
1853 // The expected result from this test is a green and red triangle;
1854 // one red vertex on the left, two green vertices on the right.
1855 static const char *vertShaderText =
1856 "#version 130\n"
1857 "out vec4 texColor;\n"
1858 "uniform sampler2D surface;\n"
1859 "void main() {\n"
1860 " vec2 vertices[3];"
1861 " vertices[0] = vec2(-0.5, -0.5);\n"
1862 " vertices[1] = vec2( 0.5, -0.5);\n"
1863 " vertices[2] = vec2( 0.5, 0.5);\n"
1864 " vec2 positions[3];"
1865 " positions[0] = vec2( 0.0, 0.0);\n"
1866 " positions[1] = vec2( 0.25, 0.1);\n"
1867 " positions[2] = vec2( 0.1, 0.25);\n"
1868 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1869 " texColor = textureLod(surface, samplePos, 0.0);\n"
1870 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1871 "}\n";
1872
1873 static const char *fragShaderText =
1874 "#version 130\n"
1875 "in vec4 texColor;\n"
1876 "void main() {\n"
1877 " gl_FragColor = texColor;\n"
1878 "}\n";
1879
1880 ASSERT_NO_FATAL_FAILURE(InitState());
1881 ASSERT_NO_FATAL_FAILURE(InitViewport());
1882
1883 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1884 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1885 XglSamplerObj sampler(m_device);
1886 XglTextureObj texture(m_device);
1887
Tony Barbourf43b6982014-11-25 13:18:32 -07001888 XglPipelineObj pipelineobj(m_device);
1889 pipelineobj.AddShader(&vs);
1890 pipelineobj.AddShader(&ps);
1891
1892 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001893 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
1895 m_memoryRefManager.AddMemoryRef(&texture);
1896
Tony Barbourdd4c9642015-01-09 12:55:14 -07001897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001898 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001899 XglCommandBufferObj cmdBuffer(m_device);
1900 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001901
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001902 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001903
1904 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1905
1906#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001907 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001908 pDSDumpDot((char*)"triTest2.dot");
1909#endif
1910 // render triangle
1911 cmdBuffer.Draw(0, 3, 0, 1);
1912
1913 // finalize recording of the command buffer
1914 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001915 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001916
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001917 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001918 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001919}
1920TEST_F(XglRenderTest, TexturedTriangle)
1921{
1922 // The expected result from this test is a red and green checkered triangle
1923 static const char *vertShaderText =
1924 "#version 140\n"
1925 "#extension GL_ARB_separate_shader_objects : enable\n"
1926 "#extension GL_ARB_shading_language_420pack : enable\n"
1927 "layout (location = 0) out vec2 samplePos;\n"
1928 "void main() {\n"
1929 " vec2 vertices[3];"
1930 " vertices[0] = vec2(-0.5, -0.5);\n"
1931 " vertices[1] = vec2( 0.5, -0.5);\n"
1932 " vertices[2] = vec2( 0.5, 0.5);\n"
1933 " vec2 positions[3];"
1934 " positions[0] = vec2( 0.0, 0.0);\n"
1935 " positions[1] = vec2( 1.0, 0.0);\n"
1936 " positions[2] = vec2( 1.0, 1.0);\n"
1937 " samplePos = positions[gl_VertexID % 3];\n"
1938 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1939 "}\n";
1940
1941 static const char *fragShaderText =
1942 "#version 140\n"
1943 "#extension GL_ARB_separate_shader_objects : enable\n"
1944 "#extension GL_ARB_shading_language_420pack : enable\n"
1945 "layout (location = 0) in vec2 samplePos;\n"
1946 "layout (binding = 0) uniform sampler2D surface;\n"
1947 "layout (location=0) out vec4 outColor;\n"
1948 "void main() {\n"
1949 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1950 " outColor = texColor;\n"
1951 "}\n";
1952
1953 ASSERT_NO_FATAL_FAILURE(InitState());
1954 ASSERT_NO_FATAL_FAILURE(InitViewport());
1955
1956 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1957 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1958 XglSamplerObj sampler(m_device);
1959 XglTextureObj texture(m_device);
1960
Tony Barbourf43b6982014-11-25 13:18:32 -07001961 XglPipelineObj pipelineobj(m_device);
1962 pipelineobj.AddShader(&vs);
1963 pipelineobj.AddShader(&ps);
1964
1965 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001966 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001967
1968 m_memoryRefManager.AddMemoryRef(&texture);
1969
Tony Barbourdd4c9642015-01-09 12:55:14 -07001970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001971 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001972 XglCommandBufferObj cmdBuffer(m_device);
1973 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1974
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001975 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001976
1977 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1978
1979#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001980 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001981 pDSDumpDot((char*)"triTest2.dot");
1982#endif
1983 // render triangle
1984 cmdBuffer.Draw(0, 3, 0, 1);
1985
1986 // finalize recording of the command buffer
1987 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001988 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001989
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001990 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001991 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001992}
1993TEST_F(XglRenderTest, TexturedTriangleClip)
1994{
1995 // The expected result from this test is a red and green checkered triangle
1996 static const char *vertShaderText =
1997 "#version 330\n"
1998 "#extension GL_ARB_separate_shader_objects : enable\n"
1999 "#extension GL_ARB_shading_language_420pack : enable\n"
2000 "layout (location = 0) out vec2 samplePos;\n"
2001 "out gl_PerVertex {\n"
2002 " vec4 gl_Position;\n"
2003 " float gl_ClipDistance[1];\n"
2004 "};\n"
2005 "void main() {\n"
2006 " vec2 vertices[3];"
2007 " vertices[0] = vec2(-0.5, -0.5);\n"
2008 " vertices[1] = vec2( 0.5, -0.5);\n"
2009 " vertices[2] = vec2( 0.5, 0.5);\n"
2010 " vec2 positions[3];"
2011 " positions[0] = vec2( 0.0, 0.0);\n"
2012 " positions[1] = vec2( 1.0, 0.0);\n"
2013 " positions[2] = vec2( 1.0, 1.0);\n"
2014 " float dists[3];\n"
2015 " dists[0] = 1.0;\n"
2016 " dists[1] = 1.0;\n"
2017 " dists[2] = -1.0;\n"
2018 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2019 " samplePos = positions[gl_VertexID % 3];\n"
2020 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2021 "}\n";
2022
2023 static const char *fragShaderText =
2024 "#version 140\n"
2025 "#extension GL_ARB_separate_shader_objects : enable\n"
2026 "#extension GL_ARB_shading_language_420pack : enable\n"
2027 "layout (location = 0) in vec2 samplePos;\n"
2028 "layout (binding = 0) uniform sampler2D surface;\n"
2029 "layout (location=0) out vec4 outColor;\n"
2030 "void main() {\n"
2031 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2032 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2033 " outColor = texColor;\n"
2034 "}\n";
2035
2036
2037 ASSERT_NO_FATAL_FAILURE(InitState());
2038 ASSERT_NO_FATAL_FAILURE(InitViewport());
2039
2040 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2041 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2042 XglSamplerObj sampler(m_device);
2043 XglTextureObj texture(m_device);
2044
Tony Barbourf43b6982014-11-25 13:18:32 -07002045 XglPipelineObj pipelineobj(m_device);
2046 pipelineobj.AddShader(&vs);
2047 pipelineobj.AddShader(&ps);
2048
2049 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002050 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002051
2052 m_memoryRefManager.AddMemoryRef(&texture);
2053
Tony Barbourdd4c9642015-01-09 12:55:14 -07002054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002055 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002056 XglCommandBufferObj cmdBuffer(m_device);
2057 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2058
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002059 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002060
2061 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2062
2063#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002064 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002065 pDSDumpDot((char*)"triTest2.dot");
2066#endif
2067 // render triangle
2068 cmdBuffer.Draw(0, 3, 0, 1);
2069
2070 // finalize recording of the command buffer
2071 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002072 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002073
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002074 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002075 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002076}
2077TEST_F(XglRenderTest, FSTriangle)
2078{
2079 // The expected result from this test is a red and green checkered triangle
2080 static const char *vertShaderText =
2081 "#version 140\n"
2082 "#extension GL_ARB_separate_shader_objects : enable\n"
2083 "#extension GL_ARB_shading_language_420pack : enable\n"
2084 "layout (location = 0) out vec2 samplePos;\n"
2085 "void main() {\n"
2086 " vec2 vertices[3];"
2087 " vertices[0] = vec2(-0.5, -0.5);\n"
2088 " vertices[1] = vec2( 0.5, -0.5);\n"
2089 " vertices[2] = vec2( 0.5, 0.5);\n"
2090 " vec2 positions[3];"
2091 " positions[0] = vec2( 0.0, 0.0);\n"
2092 " positions[1] = vec2( 1.0, 0.0);\n"
2093 " positions[2] = vec2( 1.0, 1.0);\n"
2094 " samplePos = positions[gl_VertexID % 3];\n"
2095 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2096 "}\n";
2097
2098 static const char *fragShaderText =
2099 "#version 140\n"
2100 "#extension GL_ARB_separate_shader_objects : enable\n"
2101 "#extension GL_ARB_shading_language_420pack : enable\n"
2102 "layout (location = 0) in vec2 samplePos;\n"
2103 "layout (binding = 0) uniform sampler2D surface;\n"
2104 "layout (location=0) out vec4 outColor;\n"
2105 "void main() {\n"
2106 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2107 " outColor = texColor;\n"
2108 "}\n";
2109
2110 ASSERT_NO_FATAL_FAILURE(InitState());
2111 ASSERT_NO_FATAL_FAILURE(InitViewport());
2112
2113 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2114 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2115 XglSamplerObj sampler(m_device);
2116 XglTextureObj texture(m_device);
2117
Tony Barbourf43b6982014-11-25 13:18:32 -07002118 XglPipelineObj pipelineobj(m_device);
2119 pipelineobj.AddShader(&vs);
2120 pipelineobj.AddShader(&ps);
2121
2122 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002123 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002124
2125 m_memoryRefManager.AddMemoryRef(&texture);
2126
Tony Barbourdd4c9642015-01-09 12:55:14 -07002127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002128 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002129 XglCommandBufferObj cmdBuffer(m_device);
2130 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2131
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002132 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002133
2134 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2135
2136#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002137 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002138 pDSDumpDot((char*)"triTest2.dot");
2139#endif
2140 // render triangle
2141 cmdBuffer.Draw(0, 3, 0, 1);
2142
2143 // finalize recording of the command buffer
2144 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002145 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002146
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002147 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002148 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002149}
2150TEST_F(XglRenderTest, SamplerBindingsTriangle)
2151{
2152 // This test sets bindings on the samplers
2153 // For now we are asserting that sampler and texture pairs
2154 // march in lock step, and are set via GLSL binding. This can
2155 // and will probably change.
2156 // The sampler bindings should match the sampler and texture slot
2157 // number set up by the application.
2158 // This test will result in a blue triangle
2159 static const char *vertShaderText =
2160 "#version 140\n"
2161 "#extension GL_ARB_separate_shader_objects : enable\n"
2162 "#extension GL_ARB_shading_language_420pack : enable\n"
2163 "layout (location = 0) out vec4 samplePos;\n"
2164 "void main() {\n"
2165 " vec2 vertices[3];"
2166 " vertices[0] = vec2(-0.5, -0.5);\n"
2167 " vertices[1] = vec2( 0.5, -0.5);\n"
2168 " vertices[2] = vec2( 0.5, 0.5);\n"
2169 " vec2 positions[3];"
2170 " positions[0] = vec2( 0.0, 0.0);\n"
2171 " positions[1] = vec2( 1.0, 0.0);\n"
2172 " positions[2] = vec2( 1.0, 1.0);\n"
2173 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2174 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2175 "}\n";
2176
2177 static const char *fragShaderText =
2178 "#version 140\n"
2179 "#extension GL_ARB_separate_shader_objects : enable\n"
2180 "#extension GL_ARB_shading_language_420pack : enable\n"
2181 "layout (location = 0) in vec4 samplePos;\n"
2182 "layout (binding = 0) uniform sampler2D surface0;\n"
2183 "layout (binding = 1) uniform sampler2D surface1;\n"
2184 "layout (binding = 12) uniform sampler2D surface2;\n"
2185 "void main() {\n"
2186 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2187 "}\n";
2188
2189 ASSERT_NO_FATAL_FAILURE(InitState());
2190 ASSERT_NO_FATAL_FAILURE(InitViewport());
2191
2192 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2193 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2194
2195 XglSamplerObj sampler1(m_device);
2196 XglSamplerObj sampler2(m_device);
2197 XglSamplerObj sampler3(m_device);
2198
Tony Barbour2f421a02015-04-01 16:38:10 -06002199 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2200 XglTextureObj texture1(m_device, tex_colors); // Red
2201 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2202 XglTextureObj texture2(m_device, tex_colors); // Green
2203 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2204 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002205
Tony Barbourf43b6982014-11-25 13:18:32 -07002206 XglPipelineObj pipelineobj(m_device);
2207 pipelineobj.AddShader(&vs);
2208 pipelineobj.AddShader(&ps);
2209
2210 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002211 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2212 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2213 for (int i = 0; i < 10; i++)
2214 descriptorSet.AppendDummy();
2215 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002216
2217 m_memoryRefManager.AddMemoryRef(&texture1);
2218 m_memoryRefManager.AddMemoryRef(&texture2);
2219 m_memoryRefManager.AddMemoryRef(&texture3);
2220
Tony Barbourdd4c9642015-01-09 12:55:14 -07002221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002222 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002223 XglCommandBufferObj cmdBuffer(m_device);
2224 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2225
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002226 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002227
2228 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2229
2230#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002231 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002232 pDSDumpDot((char*)"triTest2.dot");
2233#endif
2234 // render triangle
2235 cmdBuffer.Draw(0, 3, 0, 1);
2236
2237 // finalize recording of the command buffer
2238 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002239 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002240
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002241 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002242 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002243
2244}
2245
2246TEST_F(XglRenderTest, TriangleVSUniformBlock)
2247{
2248 // The expected result from this test is a blue triangle
2249
2250 static const char *vertShaderText =
2251 "#version 140\n"
2252 "#extension GL_ARB_separate_shader_objects : enable\n"
2253 "#extension GL_ARB_shading_language_420pack : enable\n"
2254 "layout (location = 0) out vec4 outColor;\n"
2255 "layout (std140, binding = 0) uniform bufferVals {\n"
2256 " vec4 red;\n"
2257 " vec4 green;\n"
2258 " vec4 blue;\n"
2259 " vec4 white;\n"
2260 "} myBufferVals;\n"
2261 "void main() {\n"
2262 " vec2 vertices[3];"
2263 " vertices[0] = vec2(-0.5, -0.5);\n"
2264 " vertices[1] = vec2( 0.5, -0.5);\n"
2265 " vertices[2] = vec2( 0.5, 0.5);\n"
2266 " outColor = myBufferVals.blue;\n"
2267 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2268 "}\n";
2269
2270 static const char *fragShaderText =
2271 "#version 140\n"
2272 "#extension GL_ARB_separate_shader_objects : enable\n"
2273 "#extension GL_ARB_shading_language_420pack : enable\n"
2274 "layout (location = 0) in vec4 inColor;\n"
2275 "void main() {\n"
2276 " gl_FragColor = inColor;\n"
2277 "}\n";
2278
2279 ASSERT_NO_FATAL_FAILURE(InitState());
2280 ASSERT_NO_FATAL_FAILURE(InitViewport());
2281
2282 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2283 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2284
2285 // Let's populate our buffer with the following:
2286 // vec4 red;
2287 // vec4 green;
2288 // vec4 blue;
2289 // vec4 white;
2290 const int valCount = 4 * 4;
2291 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2292 0.0, 1.0, 0.0, 1.0,
2293 0.0, 0.0, 1.0, 1.0,
2294 1.0, 1.0, 1.0, 1.0 };
2295
2296 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002297
2298 XglPipelineObj pipelineobj(m_device);
2299 pipelineobj.AddShader(&vs);
2300 pipelineobj.AddShader(&ps);
2301
2302 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002303 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002304
Tony Barbourdd4c9642015-01-09 12:55:14 -07002305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002306 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002307 XglCommandBufferObj cmdBuffer(m_device);
2308 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2309
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002310 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002311
2312 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2313
2314#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002315 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002316 pDSDumpDot((char*)"triTest2.dot");
2317#endif
2318 // render triangle
2319 cmdBuffer.Draw(0, 3, 0, 1);
2320
2321 // finalize recording of the command buffer
2322 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002323 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002324
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002325 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002326 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002327
2328}
2329
2330TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2331{
2332 // This test allows the shader to select which buffer it is
2333 // pulling from using layout binding qualifier.
2334 // There are corresponding changes in the compiler stack that
2335 // will select the buffer using binding directly.
2336 // The binding number should match the slot number set up by
2337 // the application.
2338 // The expected result from this test is a purple triangle
2339
2340 static const char *vertShaderText =
2341 "#version 140\n"
2342 "#extension GL_ARB_separate_shader_objects : enable\n"
2343 "#extension GL_ARB_shading_language_420pack : enable\n"
2344 "void main() {\n"
2345 " vec2 vertices[3];"
2346 " vertices[0] = vec2(-0.5, -0.5);\n"
2347 " vertices[1] = vec2( 0.5, -0.5);\n"
2348 " vertices[2] = vec2( 0.5, 0.5);\n"
2349 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2350 "}\n";
2351
2352 static const char *fragShaderText =
2353 "#version 140\n"
2354 "#extension GL_ARB_separate_shader_objects : enable\n"
2355 "#extension GL_ARB_shading_language_420pack : enable\n"
2356 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2357 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2358 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002359 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002360 "void main() {\n"
2361 " gl_FragColor = myBlueVal.color;\n"
2362 " gl_FragColor += myRedVal.color;\n"
2363 "}\n";
2364
2365 ASSERT_NO_FATAL_FAILURE(InitState());
2366 ASSERT_NO_FATAL_FAILURE(InitViewport());
2367
2368 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2369 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2370
2371 // We're going to create a number of uniform buffers, and then allow
2372 // the shader to select which it wants to read from with a binding
2373
2374 // Let's populate the buffers with a single color each:
2375 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2376 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2377 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002378 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002379
2380 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2381 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2382 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2383 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2384
2385 const int redCount = sizeof(redVals) / sizeof(float);
2386 const int greenCount = sizeof(greenVals) / sizeof(float);
2387 const int blueCount = sizeof(blueVals) / sizeof(float);
2388 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2389
2390 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002391
2392 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002393
2394 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002395
2396 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002397
2398 XglPipelineObj pipelineobj(m_device);
2399 pipelineobj.AddShader(&vs);
2400 pipelineobj.AddShader(&ps);
2401
2402 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002403 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2404 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2405 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2406 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002407
Tony Barbourdd4c9642015-01-09 12:55:14 -07002408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002409 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002410 XglCommandBufferObj cmdBuffer(m_device);
2411 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002412
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002413 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002414
2415 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2416
2417#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002418 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002419 pDSDumpDot((char*)"triTest2.dot");
2420#endif
2421 // render triangle
2422 cmdBuffer.Draw(0, 3, 0, 1);
2423
2424 // finalize recording of the command buffer
2425 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002426 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002427
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002428 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002429 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002430}
2431
2432TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2433{
2434 // This test is the same as TriangleFSUniformBlockBinding, but
2435 // it does not provide an instance name.
2436 // The expected result from this test is a purple triangle
2437
2438 static const char *vertShaderText =
2439 "#version 140\n"
2440 "#extension GL_ARB_separate_shader_objects : enable\n"
2441 "#extension GL_ARB_shading_language_420pack : enable\n"
2442 "void main() {\n"
2443 " vec2 vertices[3];"
2444 " vertices[0] = vec2(-0.5, -0.5);\n"
2445 " vertices[1] = vec2( 0.5, -0.5);\n"
2446 " vertices[2] = vec2( 0.5, 0.5);\n"
2447 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2448 "}\n";
2449
2450 static const char *fragShaderText =
2451 "#version 430\n"
2452 "#extension GL_ARB_separate_shader_objects : enable\n"
2453 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002454 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2455 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2456 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002457 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002458 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002459 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002460 " outColor = blue;\n"
2461 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002462 "}\n";
2463 ASSERT_NO_FATAL_FAILURE(InitState());
2464 ASSERT_NO_FATAL_FAILURE(InitViewport());
2465
2466 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2467 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2468
2469 // We're going to create a number of uniform buffers, and then allow
2470 // the shader to select which it wants to read from with a binding
2471
2472 // Let's populate the buffers with a single color each:
2473 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2474 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2475 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2476 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2477
2478 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2479 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2480 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2481 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2482
2483 const int redCount = sizeof(redVals) / sizeof(float);
2484 const int greenCount = sizeof(greenVals) / sizeof(float);
2485 const int blueCount = sizeof(blueVals) / sizeof(float);
2486 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2487
2488 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002489
2490 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002491
2492 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002493
2494 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002495
2496 XglPipelineObj pipelineobj(m_device);
2497 pipelineobj.AddShader(&vs);
2498 pipelineobj.AddShader(&ps);
2499
2500 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002501 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2502 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2503 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2504 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002505
Tony Barbourdd4c9642015-01-09 12:55:14 -07002506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002507 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002508 XglCommandBufferObj cmdBuffer(m_device);
2509 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2510
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002511 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002512
2513 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2514
2515#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002516 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002517 pDSDumpDot((char*)"triTest2.dot");
2518#endif
2519 // render triangle
2520 cmdBuffer.Draw(0, 3, 0, 1);
2521
2522 // finalize recording of the command buffer
2523 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002524 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002525
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002526 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002527 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
2529}
2530
2531TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2532{
2533 static const char *vertShaderText =
2534 "#version 140\n"
2535 "#extension GL_ARB_separate_shader_objects : enable\n"
2536 "#extension GL_ARB_shading_language_420pack : enable\n"
2537 "layout (std140, binding=0) uniform bufferVals {\n"
2538 " mat4 mvp;\n"
2539 "} myBufferVals;\n"
2540 "layout (location=0) in vec4 pos;\n"
2541 "layout (location=0) out vec2 UV;\n"
2542 "void main() {\n"
2543 " vec2 positions[3];"
2544 " positions[0] = vec2( 0.0, 0.0);\n"
2545 " positions[1] = vec2( 0.25, 0.1);\n"
2546 " positions[2] = vec2( 0.1, 0.25);\n"
2547 " UV = positions[gl_VertexID % 3];\n"
2548 " gl_Position = myBufferVals.mvp * pos;\n"
2549 "}\n";
2550
2551 static const char *fragShaderText =
2552 "#version 140\n"
2553 "#extension GL_ARB_separate_shader_objects : enable\n"
2554 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002555 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002556 "layout (location=0) out vec4 outColor;\n"
2557 "layout (location=0) in vec2 UV;\n"
2558 "void main() {\n"
2559 " outColor= textureLod(surface, UV, 0.0);\n"
2560 "}\n";
2561 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2562
2563 glm::mat4 View = glm::lookAt(
2564 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2565 glm::vec3(0,0,0), // and looks at the origin
2566 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2567 );
2568
2569 glm::mat4 Model = glm::mat4(1.0f);
2570
2571 glm::mat4 MVP = Projection * View * Model;
2572
2573
2574 ASSERT_NO_FATAL_FAILURE(InitState());
2575 ASSERT_NO_FATAL_FAILURE(InitViewport());
2576 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2577
2578 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2579 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002580 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002581
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002582 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002583
2584 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2585 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2586 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2587 XglSamplerObj sampler(m_device);
2588 XglTextureObj texture(m_device);
2589
Tony Barbourf43b6982014-11-25 13:18:32 -07002590 XglPipelineObj pipelineobj(m_device);
2591 pipelineobj.AddShader(&vs);
2592 pipelineobj.AddShader(&ps);
2593
2594 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002595 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002596 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2597 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002598
2599 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2600 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2601 m_memoryRefManager.AddMemoryRef(&texture);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002602 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07002603
2604 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2605 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2606 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2607 };
2608
2609 // this is the current description of g_vbData
2610 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2611 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002612 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002613 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2614 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002615 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002616 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2617
2618 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2619 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2620 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2621
Tony Barbourfa6cac72015-01-16 14:27:35 -07002622 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2623 ds_state.depthTestEnable = XGL_TRUE;
2624 ds_state.depthWriteEnable = XGL_TRUE;
2625 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2626 ds_state.depthBoundsEnable = XGL_FALSE;
2627 ds_state.stencilTestEnable = XGL_FALSE;
2628 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2629 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2630 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2631 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002632 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002633 ds_state.front = ds_state.back;
2634 pipelineobj.SetDepthStencil(&ds_state);
2635
Tony Barbourdd4c9642015-01-09 12:55:14 -07002636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002637 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002638 XglCommandBufferObj cmdBuffer(m_device);
2639 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002640
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002641 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002642 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2643
2644 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2645#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002646 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002647 pDSDumpDot((char*)"triTest2.dot");
2648#endif
2649 // render triangle
2650 cmdBuffer.Draw(0, 36, 0, 1);
2651
2652 // finalize recording of the command buffer
2653 cmdBuffer.EndCommandBuffer();
2654 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2655
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002656 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002657 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002658
2659}
Cody Northropd1ce7842014-12-09 11:17:01 -07002660
2661TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2662{
2663 // This test mixes binding slots of textures and buffers, ensuring
2664 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002665 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002666 // you can modify it to move the desired result around.
2667
2668 static const char *vertShaderText =
2669 "#version 140\n"
2670 "#extension GL_ARB_separate_shader_objects : enable\n"
2671 "#extension GL_ARB_shading_language_420pack : enable\n"
2672 "void main() {\n"
2673 " vec2 vertices[3];"
2674 " vertices[0] = vec2(-0.5, -0.5);\n"
2675 " vertices[1] = vec2( 0.5, -0.5);\n"
2676 " vertices[2] = vec2( 0.5, 0.5);\n"
2677 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2678 "}\n";
2679
2680 static const char *fragShaderText =
2681 "#version 430\n"
2682 "#extension GL_ARB_separate_shader_objects : enable\n"
2683 "#extension GL_ARB_shading_language_420pack : enable\n"
2684 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002685 "layout (binding = 3) uniform sampler2D surface1;\n"
2686 "layout (binding = 1) uniform sampler2D surface2;\n"
2687 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002688
Cody Northropa0410942014-12-09 13:59:39 -07002689
Chia-I Wuf8385062015-01-04 16:27:24 +08002690 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2691 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2692 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2693 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002694 "layout (location = 0) out vec4 outColor;\n"
2695 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002696 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002697 " outColor += white * vec4(0.00001);\n"
2698 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002699 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002700 "}\n";
2701 ASSERT_NO_FATAL_FAILURE(InitState());
2702 ASSERT_NO_FATAL_FAILURE(InitViewport());
2703
2704 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2705 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2706
Cody Northropd1ce7842014-12-09 11:17:01 -07002707 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2708 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2709 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2710 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2711
2712 const int redCount = sizeof(redVals) / sizeof(float);
2713 const int greenCount = sizeof(greenVals) / sizeof(float);
2714 const int blueCount = sizeof(blueVals) / sizeof(float);
2715 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2716
2717 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002718 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002719 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002720 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002721
Tony Barbour2f421a02015-04-01 16:38:10 -06002722 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002723 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002724 XglTextureObj texture0(m_device, tex_colors); // Light Red
2725 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002726 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002727 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2728 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002729 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002730 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002731
2732 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2733 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002734 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002735 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002736 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002737
2738 XglPipelineObj pipelineobj(m_device);
2739 pipelineobj.AddShader(&vs);
2740 pipelineobj.AddShader(&ps);
2741
2742 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002743 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2744 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2745 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2746 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2747 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2748 // swap blue and green
2749 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2750 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2751 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002752
2753 m_memoryRefManager.AddMemoryRef(&texture0);
2754 m_memoryRefManager.AddMemoryRef(&texture2);
2755 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002756 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002757
Tony Barbourdd4c9642015-01-09 12:55:14 -07002758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002759 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002760 XglCommandBufferObj cmdBuffer(m_device);
2761 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002762
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002763 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002764
2765 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2766
2767#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002768 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002769 pDSDumpDot((char*)"triTest2.dot");
2770#endif
2771 // render triangle
2772 cmdBuffer.Draw(0, 3, 0, 1);
2773
2774 // finalize recording of the command buffer
2775 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002776 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002777
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002778 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002779 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002780
2781}
2782
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002783TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2784{
2785 // This test matches binding slots of textures and buffers, requiring
2786 // the driver to give them distinct number spaces.
2787 // The expected result from this test is a red triangle, although
2788 // you can modify it to move the desired result around.
2789
2790 static const char *vertShaderText =
2791 "#version 140\n"
2792 "#extension GL_ARB_separate_shader_objects : enable\n"
2793 "#extension GL_ARB_shading_language_420pack : enable\n"
2794 "void main() {\n"
2795 " vec2 vertices[3];"
2796 " vertices[0] = vec2(-0.5, -0.5);\n"
2797 " vertices[1] = vec2( 0.5, -0.5);\n"
2798 " vertices[2] = vec2( 0.5, 0.5);\n"
2799 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2800 "}\n";
2801
2802 static const char *fragShaderText =
2803 "#version 430\n"
2804 "#extension GL_ARB_separate_shader_objects : enable\n"
2805 "#extension GL_ARB_shading_language_420pack : enable\n"
2806 "layout (binding = 0) uniform sampler2D surface0;\n"
2807 "layout (binding = 1) uniform sampler2D surface1;\n"
2808 "layout (binding = 2) uniform sampler2D surface2;\n"
2809 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002810 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2811 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2812 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2813 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002814 "layout (location = 0) out vec4 outColor;\n"
2815 "void main() {\n"
2816 " outColor = red;// * vec4(0.00001);\n"
2817 " outColor += white * vec4(0.00001);\n"
2818 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2819 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2820 "}\n";
2821 ASSERT_NO_FATAL_FAILURE(InitState());
2822 ASSERT_NO_FATAL_FAILURE(InitViewport());
2823
2824 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2825 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2826
2827 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2828 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2829 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2830 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2831
2832 const int redCount = sizeof(redVals) / sizeof(float);
2833 const int greenCount = sizeof(greenVals) / sizeof(float);
2834 const int blueCount = sizeof(blueVals) / sizeof(float);
2835 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2836
2837 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002838 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002839 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002840 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002841
Tony Barbour2f421a02015-04-01 16:38:10 -06002842 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002843 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002844 XglTextureObj texture0(m_device, tex_colors); // Light Red
2845 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002846 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002847 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2848 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002849 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002850 XglTextureObj texture4(m_device, tex_colors); // Light Green
2851 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002852 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002853 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002854
2855 XglPipelineObj pipelineobj(m_device);
2856 pipelineobj.AddShader(&vs);
2857 pipelineobj.AddShader(&ps);
2858
2859 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002860 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2861 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2862 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2863 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2864 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2865 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2866 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2867 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002868
2869 m_memoryRefManager.AddMemoryRef(&texture0);
2870 m_memoryRefManager.AddMemoryRef(&texture2);
2871 m_memoryRefManager.AddMemoryRef(&texture4);
2872 m_memoryRefManager.AddMemoryRef(&texture7);
2873
Tony Barbourdd4c9642015-01-09 12:55:14 -07002874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002875 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002876 XglCommandBufferObj cmdBuffer(m_device);
2877 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002878
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002879 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002880
2881 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2882
2883#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002884 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002885 pDSDumpDot((char*)"triTest2.dot");
2886#endif
2887 // render triangle
2888 cmdBuffer.Draw(0, 3, 0, 1);
2889
2890 // finalize recording of the command buffer
2891 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002892 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002893
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002894 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002895 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002896
2897}
2898
Cody Northrop02690bd2014-12-17 15:26:33 -07002899TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2900{
2901 // This test populates a buffer with a variety of different data
2902 // types, then reads them out with a shader.
2903 // The expected result from this test is a green triangle
2904
2905 static const char *vertShaderText =
2906 "#version 140\n"
2907 "#extension GL_ARB_separate_shader_objects : enable\n"
2908 "#extension GL_ARB_shading_language_420pack : enable\n"
2909 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2910 " vec4 fRed;\n"
2911 " vec4 fGreen;\n"
2912 " layout(row_major) mat4 worldToProj;\n"
2913 " layout(row_major) mat4 projToWorld;\n"
2914 " layout(row_major) mat4 worldToView;\n"
2915 " layout(row_major) mat4 viewToProj;\n"
2916 " layout(row_major) mat4 worldToShadow[4];\n"
2917 " float fZero;\n"
2918 " float fOne;\n"
2919 " float fTwo;\n"
2920 " float fThree;\n"
2921 " vec3 fZeroZeroZero;\n"
2922 " float fFour;\n"
2923 " vec3 fZeroZeroOne;\n"
2924 " float fFive;\n"
2925 " vec3 fZeroOneZero;\n"
2926 " float fSix;\n"
2927 " float fSeven;\n"
2928 " float fEight;\n"
2929 " float fNine;\n"
2930 " vec2 fZeroZero;\n"
2931 " vec2 fZeroOne;\n"
2932 " vec4 fBlue;\n"
2933 " vec2 fOneZero;\n"
2934 " vec2 fOneOne;\n"
2935 " vec3 fZeroOneOne;\n"
2936 " float fTen;\n"
2937 " float fEleven;\n"
2938 " float fTwelve;\n"
2939 " vec3 fOneZeroZero;\n"
2940 " vec4 uvOffsets[4];\n"
2941 "};\n"
2942 "layout (location = 0) out vec4 color;"
2943 "void main() {\n"
2944
2945 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2946 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2947 " \n"
2948
2949 // do some exact comparisons, even though we should
2950 // really have an epsilon involved.
2951 " vec4 outColor = right;\n"
2952 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2953 " outColor = wrong;\n"
2954 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2955 " outColor = wrong;\n"
2956 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2957 " outColor = wrong;\n"
2958
2959 " color = outColor;\n"
2960
2961 // generic position stuff
2962 " vec2 vertices;\n"
2963 " int vertexSelector = gl_VertexID;\n"
2964 " if (vertexSelector == 0)\n"
2965 " vertices = vec2(-0.5, -0.5);\n"
2966 " else if (vertexSelector == 1)\n"
2967 " vertices = vec2( 0.5, -0.5);\n"
2968 " else if (vertexSelector == 2)\n"
2969 " vertices = vec2( 0.5, 0.5);\n"
2970 " else\n"
2971 " vertices = vec2( 0.0, 0.0);\n"
2972 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2973 "}\n";
2974
2975 static const char *fragShaderText =
2976 "#version 140\n"
2977 "#extension GL_ARB_separate_shader_objects : enable\n"
2978 "#extension GL_ARB_shading_language_420pack : enable\n"
2979 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2980 " vec4 fRed;\n"
2981 " vec4 fGreen;\n"
2982 " layout(row_major) mat4 worldToProj;\n"
2983 " layout(row_major) mat4 projToWorld;\n"
2984 " layout(row_major) mat4 worldToView;\n"
2985 " layout(row_major) mat4 viewToProj;\n"
2986 " layout(row_major) mat4 worldToShadow[4];\n"
2987 " float fZero;\n"
2988 " float fOne;\n"
2989 " float fTwo;\n"
2990 " float fThree;\n"
2991 " vec3 fZeroZeroZero;\n"
2992 " float fFour;\n"
2993 " vec3 fZeroZeroOne;\n"
2994 " float fFive;\n"
2995 " vec3 fZeroOneZero;\n"
2996 " float fSix;\n"
2997 " float fSeven;\n"
2998 " float fEight;\n"
2999 " float fNine;\n"
3000 " vec2 fZeroZero;\n"
3001 " vec2 fZeroOne;\n"
3002 " vec4 fBlue;\n"
3003 " vec2 fOneZero;\n"
3004 " vec2 fOneOne;\n"
3005 " vec3 fZeroOneOne;\n"
3006 " float fTen;\n"
3007 " float fEleven;\n"
3008 " float fTwelve;\n"
3009 " vec3 fOneZeroZero;\n"
3010 " vec4 uvOffsets[4];\n"
3011 "};\n"
3012 "layout (location = 0) in vec4 color;\n"
3013 "void main() {\n"
3014 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3015 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3016 " \n"
3017
3018 // start with VS value to ensure it passed
3019 " vec4 outColor = color;\n"
3020
3021 // do some exact comparisons, even though we should
3022 // really have an epsilon involved.
3023 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3024 " outColor = wrong;\n"
3025 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3026 " outColor = wrong;\n"
3027 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3028 " outColor = wrong;\n"
3029 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3030 " outColor = wrong;\n"
3031 " if (fTwo != 2.0)\n"
3032 " outColor = wrong;\n"
3033 " if (fOneOne != vec2(1.0, 1.0))\n"
3034 " outColor = wrong;\n"
3035 " if (fTen != 10.0)\n"
3036 " outColor = wrong;\n"
3037 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3038 " outColor = wrong;\n"
3039 " \n"
3040 " gl_FragColor = outColor;\n"
3041 "}\n";
3042
3043
3044 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3045 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3046 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3047 0.0, 1.0, 0.0, 1.0, // align
3048 0.0, 0.0, 1.0, 1.0, // align
3049 0.0, 0.0, 0.0, 1.0, // align
3050 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3051 0.0, 2.0, 0.0, 2.0, // align
3052 0.0, 0.0, 2.0, 2.0, // align
3053 0.0, 0.0, 0.0, 2.0, // align
3054 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3055 0.0, 3.0, 0.0, 3.0, // align
3056 0.0, 0.0, 3.0, 3.0, // align
3057 0.0, 0.0, 0.0, 3.0, // align
3058 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3059 0.0, 4.0, 0.0, 4.0, // align
3060 0.0, 0.0, 4.0, 4.0, // align
3061 0.0, 0.0, 0.0, 4.0, // align
3062 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3063 0.0, 5.0, 0.0, 5.0, // align
3064 0.0, 0.0, 5.0, 5.0, // align
3065 0.0, 0.0, 0.0, 5.0, // align
3066 6.0, 0.0, 0.0, 6.0, // align
3067 0.0, 6.0, 0.0, 6.0, // align
3068 0.0, 0.0, 6.0, 6.0, // align
3069 0.0, 0.0, 0.0, 6.0, // align
3070 7.0, 0.0, 0.0, 7.0, // align
3071 0.0, 7.0, 0.0, 7.0, // align
3072 0.0, 0.0, 7.0, 7.0, // align
3073 0.0, 0.0, 0.0, 7.0, // align
3074 8.0, 0.0, 0.0, 8.0, // align
3075 0.0, 8.0, 0.0, 8.0, // align
3076 0.0, 0.0, 8.0, 8.0, // align
3077 0.0, 0.0, 0.0, 8.0, // align
3078 0.0, // float fZero; // align
3079 1.0, // float fOne; // pack
3080 2.0, // float fTwo; // pack
3081 3.0, // float fThree; // pack
3082 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3083 4.0, // float fFour; // pack
3084 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3085 5.0, // float fFive; // pack
3086 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3087 6.0, // float fSix; // pack
3088 7.0, // float fSeven; // align
3089 8.0, // float fEight; // pack
3090 9.0, // float fNine; // pack
3091 0.0, // BUFFER
3092 0.0, 0.0, // vec2 fZeroZero; // align
3093 0.0, 1.0, // vec2 fZeroOne; // pack
3094 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3095 1.0, 0.0, // vec2 fOneZero; // align
3096 1.0, 1.0, // vec2 fOneOne; // pack
3097 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3098 10.0, // float fTen; // pack
3099 11.0, // float fEleven; // align
3100 12.0, // float fTwelve; // pack
3101 0.0, 0.0, // BUFFER
3102 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3103 0.0, // BUFFER
3104 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3105 0.5, 0.6, 0.7, 0.8, // align
3106 0.9, 1.0, 1.1, 1.2, // align
3107 1.3, 1.4, 1.5, 1.6, // align
3108 };
3109
3110 ASSERT_NO_FATAL_FAILURE(InitState());
3111 ASSERT_NO_FATAL_FAILURE(InitViewport());
3112
3113 const int constCount = sizeof(mixedVals) / sizeof(float);
3114
3115 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3116 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3117
3118 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003119
3120 XglPipelineObj pipelineobj(m_device);
3121 pipelineobj.AddShader(&vs);
3122 pipelineobj.AddShader(&ps);
3123
3124 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003125 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003126
3127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003128 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003129 XglCommandBufferObj cmdBuffer(m_device);
3130 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3131
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003132 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003133
3134 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3135
3136#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003137 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003138 pDSDumpDot((char*)"triTest2.dot");
3139#endif
3140 // render triangle
3141 cmdBuffer.Draw(0, 3, 0, 1);
3142
3143 // finalize recording of the command buffer
3144 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06003145 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003146
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003147 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003148 RecordImage(m_renderTargets[i]);
3149}
3150
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003151int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003152 int result;
3153
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003154 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003155 XglTestFramework::InitArgs(&argc, argv);
3156
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003157 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003158
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003159 result = RUN_ALL_TESTS();
3160
3161 XglTestFramework::Finish();
3162 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003163}