blob: 26388ca1784b415ac590c01f353e8beafecaf089 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Chia-I Wu4115c892014-08-28 11:56:29 +080075#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
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;
247 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
248
Cody Northrop350727b2014-10-06 15:42:00 -0600249 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
250 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700251 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600252
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600253 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255
256 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600257 // Clean up resources before we reset
258 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260};
261
Tony Barbour02472db2015-01-08 17:08:28 -0700262void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
263{
264 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700265 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700266 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
269 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800270 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700271 pipelineobj->CreateXGLPipeline(descriptorSet);
272 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700273 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
274}
Tony Barbourf43b6982014-11-25 13:18:32 -0700275
Tony Barbourf43b6982014-11-25 13:18:32 -0700276void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700277 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
278{
279 int i;
280 glm::mat4 MVP;
281 int matrixSize = sizeof(MVP);
282 XGL_RESULT err;
283
284 for (i = 0; i < 8; i++) {
285 void *pData = constantBuffer->map();
286
287 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
288 MVP = Projection * View * Model;
289 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
290
291 constantBuffer->unmap();
292
293 // submit the command buffer to the universal queue
294 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
295
Tony Barbourdd4c9642015-01-09 12:55:14 -0700296 err = xglQueueWaitIdle( m_device->m_queue );
297 ASSERT_XGL_SUCCESS( err );
298
299 // Wait for work to finish before cleaning up.
300 xglDeviceWaitIdle(m_device->device());
301
302 assert(m_renderTargetCount == 1);
303 RecordImage(m_renderTargets[0]);
304 }
305}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600306
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600307void dumpMatrix(const char *note, glm::mat4 MVP)
308{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800309 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600310
311 printf("%s: \n", note);
312 for (i=0; i<4; i++) {
313 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
314 }
315 printf("\n");
316 fflush(stdout);
317}
318
319void dumpVec4(const char *note, glm::vec4 vector)
320{
321 printf("%s: \n", note);
322 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
323 printf("\n");
324 fflush(stdout);
325}
326
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600327void XglRenderTest::InitDepthStencil()
328{
329 XGL_RESULT err;
330 XGL_IMAGE_CREATE_INFO image;
331 XGL_MEMORY_ALLOC_INFO mem_alloc;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700332 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600333 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700334 XGL_MEMORY_REQUIREMENTS *mem_reqs;
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
447 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
448#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());
496 XglCommandBufferObj cmdBuffer(m_device);
497 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700498
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700499 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700500
501 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700502#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600503 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700504 pDSDumpDot((char*)"triTest2.dot");
505#endif
506 // render triangle
507 cmdBuffer.Draw(0, 3, 0, 1);
508
509 // finalize recording of the command buffer
510 cmdBuffer.EndCommandBuffer();
511 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
512
513 for (int i = 0; i < m_renderTargetCount; i++)
514 RecordImage(m_renderTargets[i]);
515
516 if (rotate)
517 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
518
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700519#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600520 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
521 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
522 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
523 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700524 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600525 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700526 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
527 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
528 for (i=0; i < numObjects; i++) {
529 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);
530 }
531 free(pObjNodeArray);
532#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700533
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600534}
535
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600536TEST_F(XglRenderTest, XGLTriangle_FragColor)
537{
538 static const char *vertShaderText =
539 "#version 140\n"
540 "#extension GL_ARB_separate_shader_objects : enable\n"
541 "#extension GL_ARB_shading_language_420pack : enable\n"
542 "\n"
543 "layout(binding = 0) uniform buf {\n"
544 " mat4 MVP;\n"
545 " vec4 position[3];\n"
546 " vec4 color[3];\n"
547 "} ubuf;\n"
548 "\n"
549 "layout (location = 0) out vec4 outColor;\n"
550 "\n"
551 "void main() \n"
552 "{\n"
553 " outColor = ubuf.color[gl_VertexID];\n"
554 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
555 "}\n";
556
557 static const char *fragShaderText =
558 "#version 140\n"
559 "#extension GL_ARB_separate_shader_objects : enable\n"
560 "#extension GL_ARB_shading_language_420pack : enable\n"
561 "\n"
562 "layout (location = 0) in vec4 inColor;\n"
563 "\n"
564 "void main()\n"
565 "{\n"
566 " gl_FragColor = inColor;\n"
567 "}\n";
568
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600569 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700570 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600571}
572
573TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
574{
575 static const char *vertShaderText =
576 "#version 140\n"
577 "#extension GL_ARB_separate_shader_objects : enable\n"
578 "#extension GL_ARB_shading_language_420pack : enable\n"
579 "\n"
580 "layout(binding = 0) uniform buf {\n"
581 " mat4 MVP;\n"
582 " vec4 position[3];\n"
583 " vec4 color[3];\n"
584 "} ubuf;\n"
585 "\n"
586 "layout (location = 0) out vec4 outColor;\n"
587 "\n"
588 "void main() \n"
589 "{\n"
590 " outColor = ubuf.color[gl_VertexID];\n"
591 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
592 "}\n";
593
594 static const char *fragShaderText =
595 "#version 140\n"
596 "#extension GL_ARB_separate_shader_objects : enable\n"
597 "#extension GL_ARB_shading_language_420pack : enable\n"
598 "\n"
599 "layout (location = 0) in vec4 inColor;\n"
600 "layout (location = 0) out vec4 outColor;\n"
601 "\n"
602 "void main()\n"
603 "{\n"
604 " outColor = inColor;\n"
605 "}\n";
606
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600607 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 -0600608
Tony Barbourae442072015-01-12 13:27:11 -0700609 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600610}
611
Tony Barbourf43b6982014-11-25 13:18:32 -0700612TEST_F(XglRenderTest, BIL_XGLTriangle)
613{
614 bool saved_use_bil = XglTestFramework::m_use_bil;
615
616 static const char *vertShaderText =
617 "#version 140\n"
618 "#extension GL_ARB_separate_shader_objects : enable\n"
619 "#extension GL_ARB_shading_language_420pack : enable\n"
620 "\n"
621 "layout(binding = 0) uniform buf {\n"
622 " mat4 MVP;\n"
623 " vec4 position[3];\n"
624 " vec4 color[3];\n"
625 "} ubuf;\n"
626 "\n"
627 "layout (location = 0) out vec4 outColor;\n"
628 "\n"
629 "void main() \n"
630 "{\n"
631 " outColor = ubuf.color[gl_VertexID];\n"
632 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
633 "}\n";
634
635 static const char *fragShaderText =
636 "#version 140\n"
637 "#extension GL_ARB_separate_shader_objects : enable\n"
638 "#extension GL_ARB_shading_language_420pack : enable\n"
639 "\n"
640 "layout (location = 0) in vec4 inColor;\n"
641 "\n"
642 "void main()\n"
643 "{\n"
644 " gl_FragColor = inColor;\n"
645 "}\n";
646
647 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
648
649 XglTestFramework::m_use_bil = true;
650
Tony Barbourae442072015-01-12 13:27:11 -0700651 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700652
653 XglTestFramework::m_use_bil = saved_use_bil;
654}
655
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600656TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600657{
658 static const char *vertShaderText =
659 "#version 130\n"
660 "vec2 vertices[3];\n"
661 "void main() {\n"
662 " vertices[0] = vec2(-1.0, -1.0);\n"
663 " vertices[1] = vec2( 1.0, -1.0);\n"
664 " vertices[2] = vec2( 0.0, 1.0);\n"
665 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
666 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600667
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600668 static const char *fragShaderText =
669 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600670 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600671 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600672 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600673
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600674 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
675
Tony Barbourae442072015-01-12 13:27:11 -0700676 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600677}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600678
Tony Barbourf43b6982014-11-25 13:18:32 -0700679TEST_F(XglRenderTest, BIL_GreenTriangle)
680{
681 bool saved_use_bil = XglTestFramework::m_use_bil;
682
683 static const char *vertShaderText =
684 "#version 130\n"
685 "vec2 vertices[3];\n"
686 "void main() {\n"
687 " vertices[0] = vec2(-1.0, -1.0);\n"
688 " vertices[1] = vec2( 1.0, -1.0);\n"
689 " vertices[2] = vec2( 0.0, 1.0);\n"
690 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
691 "}\n";
692
693 static const char *fragShaderText =
694 "#version 130\n"
695 "void main() {\n"
696 " gl_FragColor = vec4(0,1,0,1);\n"
697 "}\n";
698
699 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
700
701 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700702 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700703 XglTestFramework::m_use_bil = saved_use_bil;
704}
705
706TEST_F(XglRenderTest, YellowTriangle)
707{
708 static const char *vertShaderText =
709 "#version 130\n"
710 "void main() {\n"
711 " vec2 vertices[3];"
712 " vertices[0] = vec2(-0.5, -0.5);\n"
713 " vertices[1] = vec2( 0.5, -0.5);\n"
714 " vertices[2] = vec2( 0.5, 0.5);\n"
715 " vec4 colors[3];\n"
716 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
717 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
718 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
719 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
720 "}\n";
721
722 static const char *fragShaderText =
723 "#version 130\n"
724 "void main() {\n"
725 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
726 "}\n";
727
Tony Barbourae442072015-01-12 13:27:11 -0700728 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700729}
730
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600731TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600732{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600733 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700734 "#version 130\n"
735 //XYZ1( -1, -1, -1 )
736 "in vec4 pos;\n"
737 //XYZ1( 0.f, 0.f, 0.f )
738 "in vec4 inColor;\n"
739 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600740 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600741 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600742 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600743 "}\n";
744
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600745
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600746 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700747 "#version 140\n"
748 "#extension GL_ARB_separate_shader_objects : enable\n"
749 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700750 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700751 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600752 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700753 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600754 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600755
Tony Barbourf43b6982014-11-25 13:18:32 -0700756
757
758 ASSERT_NO_FATAL_FAILURE(InitState());
759 ASSERT_NO_FATAL_FAILURE(InitViewport());
760
761 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000762 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700763
764 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
765 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
766
767 XglPipelineObj pipelineobj(m_device);
768 pipelineobj.AddShader(&vs);
769 pipelineobj.AddShader(&ps);
770
771 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800772 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700773
774 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
775 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
776 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
777 };
778
779 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
780 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700781 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700782 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
783 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700784 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700785 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
786
787 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
788 pipelineobj.AddVertexInputBindings(&vi_binding,1);
789 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
790
Tony Barboure4ed9942015-01-09 10:06:53 -0700791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
792 XglCommandBufferObj cmdBuffer(m_device);
793 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700794
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700795 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700796 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
797
Tony Barboure4ed9942015-01-09 10:06:53 -0700798 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
799
800 // render two triangles
801 cmdBuffer.Draw(0, 6, 0, 1);
802
803 // finalize recording of the command buffer
804 cmdBuffer.EndCommandBuffer();
805 cmdBuffer.QueueCommandBuffer(NULL, 0);
806
807 for (int i = 0; i < m_renderTargetCount; i++)
808 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600809}
810
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811TEST_F(XglRenderTest, TriangleMRT)
812{
813 static const char *vertShaderText =
814 "#version 130\n"
815 "in vec4 pos;\n"
816 "void main() {\n"
817 " gl_Position = pos;\n"
818 "}\n";
819
820 static const char *fragShaderText =
821 "#version 130\n"
822 "void main() {\n"
823 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
824 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
825 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600826 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800827 { -1.0f, -1.0f },
828 { 1.0f, -1.0f },
829 { -1.0f, 1.0f }
830 };
831
832 ASSERT_NO_FATAL_FAILURE(InitState());
833 ASSERT_NO_FATAL_FAILURE(InitViewport());
834
835 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000836 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837
838 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
839 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
840
841 XglPipelineObj pipelineobj(m_device);
842 pipelineobj.AddShader(&vs);
843 pipelineobj.AddShader(&ps);
844
845 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
846 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
847 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
848 };
849
850 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
851 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700852 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wue09d1a72014-12-05 10:32:23 +0800853 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
854
855 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
856 pipelineobj.AddVertexInputBindings(&vi_binding,1);
857 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
858
859 XglDescriptorSetObj descriptorSet(m_device);
860
861 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800863
864 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
865 att.blendEnable = XGL_FALSE;
866 att.format = m_render_target_fmt;
867 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700868 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869
Tony Barbour5ed79702015-01-07 14:31:52 -0700870 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700871
Tony Barbour5ed79702015-01-07 14:31:52 -0700872 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
873 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700874
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700875 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700876
Tony Barboure4ed9942015-01-09 10:06:53 -0700877 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
878
Tony Barbour5ed79702015-01-07 14:31:52 -0700879 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700880#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600881 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700882 pDSDumpDot((char*)"triTest2.dot");
883#endif
884 // render triangle
885 cmdBuffer.Draw(0, 3, 0, 1);
886
887 // finalize recording of the command buffer
888 cmdBuffer.EndCommandBuffer();
889 cmdBuffer.QueueCommandBuffer(NULL, 0);
890
891 for (int i = 0; i < m_renderTargetCount; i++)
892 RecordImage(m_renderTargets[i]);
893
Chia-I Wue09d1a72014-12-05 10:32:23 +0800894}
895
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700896TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
897{
898 static const char *vertShaderText =
899 "#version 140\n"
900 "#extension GL_ARB_separate_shader_objects : enable\n"
901 "#extension GL_ARB_shading_language_420pack : enable\n"
902 "layout(location = 0) in vec4 pos;\n"
903 "layout(location = 1) in vec4 inColor;\n"
904 "layout(location = 0) out vec4 outColor;\n"
905 "void main() {\n"
906 " outColor = inColor;\n"
907 " gl_Position = pos;\n"
908 "}\n";
909
910
911 static const char *fragShaderText =
912 "#version 140\n"
913 "#extension GL_ARB_separate_shader_objects : enable\n"
914 "#extension GL_ARB_shading_language_420pack : enable\n"
915 "layout(location = 0) in vec4 color;\n"
916 "void main() {\n"
917 " gl_FragColor = color;\n"
918 "}\n";
919
920 const Vertex g_vbData[] =
921 {
922 // first tri
923 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
924 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
925 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
926
927 // second tri
928 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
929 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
930 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
931 };
932
933 const uint16_t g_idxData[6] = {
934 0, 1, 2,
935 3, 4, 5,
936 };
937
938 ASSERT_NO_FATAL_FAILURE(InitState());
939 ASSERT_NO_FATAL_FAILURE(InitViewport());
940
941 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000942 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700943
944 XglIndexBufferObj indexBuffer(m_device);
945 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600946 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947
948 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
949 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
950
951 XglPipelineObj pipelineobj(m_device);
952 pipelineobj.AddShader(&vs);
953 pipelineobj.AddShader(&ps);
954
955 XglDescriptorSetObj descriptorSet(m_device);
956
957 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
958 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
959 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
960 };
961
962 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
963 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700964 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700965 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
966 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700967 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
969
970 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
971 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700972
973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700974 XglCommandBufferObj cmdBuffer(m_device);
975 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700976 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700977
978 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700979
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600981 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700982 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700984
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700985 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
986 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987
988 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700989 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700990
991 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700992 cmdBuffer.EndCommandBuffer();
993 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700995 for (int i = 0; i < m_renderTargetCount; i++)
996 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997
998}
999
GregF6bef1212014-12-02 15:41:44 -07001000TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1001{
1002 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001003
GregF6bef1212014-12-02 15:41:44 -07001004 static const char *vertShaderText =
1005 "#version 140\n"
1006 "#extension GL_ARB_separate_shader_objects : enable\n"
1007 "#extension GL_ARB_shading_language_420pack : enable\n"
1008 "layout (location = 0) in vec4 pos;\n"
1009 "layout (location = 0) out vec4 outColor;\n"
1010 "layout (location = 1) out vec4 outColor2;\n"
1011 "void main() {\n"
1012 " gl_Position = pos;\n"
1013 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1014 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1015 "}\n";
1016
1017 static const char *fragShaderText =
1018 //"#version 140\n"
1019 "#version 330\n"
1020 "#extension GL_ARB_separate_shader_objects : enable\n"
1021 "#extension GL_ARB_shading_language_420pack : enable\n"
1022 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1023 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1024 "layout (location = 0) in vec4 color;\n"
1025 "layout (location = 1) in vec4 color2;\n"
1026 "void main() {\n"
1027 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1028 " float dist_squared = dot(pos, pos);\n"
1029 " gl_FragColor = (dist_squared < 400.0)\n"
1030 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1031 " : color2;\n"
1032 "}\n";
1033
1034 ASSERT_NO_FATAL_FAILURE(InitState());
1035 ASSERT_NO_FATAL_FAILURE(InitViewport());
1036
1037 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001038 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001039
1040 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1041 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1042
1043 XglPipelineObj pipelineobj(m_device);
1044 pipelineobj.AddShader(&vs);
1045 pipelineobj.AddShader(&ps);
1046
1047 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001048 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001049
1050 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1051 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1052 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1053 };
1054
1055 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1056 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001057 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001058 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1059 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001060 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001061 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1062
1063 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1064 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1065 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1066
Tony Barbourdd4c9642015-01-09 12:55:14 -07001067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1068 XglCommandBufferObj cmdBuffer(m_device);
1069 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1070
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001071 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001072
1073 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1074
1075 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1076#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001077 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001078 pDSDumpDot((char*)"triTest2.dot");
1079#endif
1080 // render triangle
1081 cmdBuffer.Draw(0, 6, 0, 1);
1082
1083 // finalize recording of the command buffer
1084 cmdBuffer.EndCommandBuffer();
1085 cmdBuffer.QueueCommandBuffer(NULL, 0);
1086
1087 for (int i = 0; i < m_renderTargetCount; i++)
1088 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001089
1090}
1091
1092TEST_F(XglRenderTest, RedCirclesonBlue)
1093{
1094 // This tests that we correctly handle unread fragment inputs
1095
1096 static const char *vertShaderText =
1097 "#version 140\n"
1098 "#extension GL_ARB_separate_shader_objects : enable\n"
1099 "#extension GL_ARB_shading_language_420pack : enable\n"
1100 "layout (location = 0) in vec4 pos;\n"
1101 "layout (location = 0) out vec4 outColor;\n"
1102 "layout (location = 1) out vec4 outColor2;\n"
1103 "void main() {\n"
1104 " gl_Position = pos;\n"
1105 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1106 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1107 "}\n";
1108
1109 static const char *fragShaderText =
1110 //"#version 140\n"
1111 "#version 330\n"
1112 "#extension GL_ARB_separate_shader_objects : enable\n"
1113 "#extension GL_ARB_shading_language_420pack : enable\n"
1114 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1115 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1116 "layout (location = 0) in vec4 color;\n"
1117 "layout (location = 1) in vec4 color2;\n"
1118 "void main() {\n"
1119 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1120 " float dist_squared = dot(pos, pos);\n"
1121 " gl_FragColor = (dist_squared < 400.0)\n"
1122 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1123 " : color2;\n"
1124 "}\n";
1125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitViewport());
1128
1129 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001130 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001131
1132 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1133 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1134
1135 XglPipelineObj pipelineobj(m_device);
1136 pipelineobj.AddShader(&vs);
1137 pipelineobj.AddShader(&ps);
1138
1139 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001140 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001141
1142 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1143 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1144 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1145 };
1146
1147 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1148 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001149 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001150 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1151 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001152 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001153 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1154
1155 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1156 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1157 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1158
Tony Barbourdd4c9642015-01-09 12:55:14 -07001159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1160 XglCommandBufferObj cmdBuffer(m_device);
1161 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1162
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001163 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001164
1165 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1166
1167 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1168#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001169 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001170 pDSDumpDot((char*)"triTest2.dot");
1171#endif
1172 // render triangle
1173 cmdBuffer.Draw(0, 6, 0, 1);
1174
1175 // finalize recording of the command buffer
1176 cmdBuffer.EndCommandBuffer();
1177 cmdBuffer.QueueCommandBuffer(NULL, 0);
1178
1179 for (int i = 0; i < m_renderTargetCount; i++)
1180 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001181
1182}
1183
1184TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1185{
1186 // This tests reading gl_ClipDistance from FS
1187
1188 static const char *vertShaderText =
1189 "#version 330\n"
1190 "#extension GL_ARB_separate_shader_objects : enable\n"
1191 "#extension GL_ARB_shading_language_420pack : enable\n"
1192 "out gl_PerVertex {\n"
1193 " vec4 gl_Position;\n"
1194 " float gl_ClipDistance[1];\n"
1195 "};\n"
1196 "layout (location = 0) in vec4 pos;\n"
1197 "layout (location = 0) out vec4 outColor;\n"
1198 "layout (location = 1) out vec4 outColor2;\n"
1199 "void main() {\n"
1200 " gl_Position = pos;\n"
1201 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1202 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1203 " float dists[3];\n"
1204 " dists[0] = 0.0;\n"
1205 " dists[1] = 1.0;\n"
1206 " dists[2] = 1.0;\n"
1207 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1208 "}\n";
1209
1210
1211 static const char *fragShaderText =
1212 //"#version 140\n"
1213 "#version 330\n"
1214 "#extension GL_ARB_separate_shader_objects : enable\n"
1215 "#extension GL_ARB_shading_language_420pack : enable\n"
1216 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1217 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1218 "layout (location = 0) in vec4 color;\n"
1219 "layout (location = 1) in vec4 color2;\n"
1220 "void main() {\n"
1221 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1222 " float dist_squared = dot(pos, pos);\n"
1223 " gl_FragColor = (dist_squared < 400.0)\n"
1224 " ? color * gl_ClipDistance[0]\n"
1225 " : color2;\n"
1226 "}\n";
1227
1228 ASSERT_NO_FATAL_FAILURE(InitState());
1229 ASSERT_NO_FATAL_FAILURE(InitViewport());
1230
1231 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001232 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001233
1234 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1235 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1236
1237 XglPipelineObj pipelineobj(m_device);
1238 pipelineobj.AddShader(&vs);
1239 pipelineobj.AddShader(&ps);
1240
1241 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001242 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001243
1244 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1245 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1246 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1247 };
1248
1249 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1250 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001251 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001252 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1253 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001254 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001255 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1256
1257 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1258 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1259 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1260
Tony Barbourdd4c9642015-01-09 12:55:14 -07001261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1262 XglCommandBufferObj cmdBuffer(m_device);
1263 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001264
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001265 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001266
1267 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1268
1269 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1270#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001271 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001272 pDSDumpDot((char*)"triTest2.dot");
1273#endif
1274 // render triangle
1275 cmdBuffer.Draw(0, 6, 0, 1);
1276
1277 // finalize recording of the command buffer
1278 cmdBuffer.EndCommandBuffer();
1279 cmdBuffer.QueueCommandBuffer(NULL, 0);
1280
1281 for (int i = 0; i < m_renderTargetCount; i++)
1282 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001283}
Tony Barbourf43b6982014-11-25 13:18:32 -07001284
GregF7a23c792014-12-02 17:19:34 -07001285TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1286{
1287 static const char *vertShaderText =
1288 "#version 140\n"
1289 "#extension GL_ARB_separate_shader_objects : enable\n"
1290 "#extension GL_ARB_shading_language_420pack : enable\n"
1291 "layout (location = 0) in vec4 pos;\n"
1292 "layout (location = 0) out vec4 outColor;\n"
1293 "layout (location = 1) out vec4 outColor2;\n"
1294 "void main() {\n"
1295 " gl_Position = pos;\n"
1296 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1297 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1298 "}\n";
1299
1300
1301 static const char *fragShaderText =
1302 //"#version 140\n"
1303 "#version 330\n"
1304 "#extension GL_ARB_separate_shader_objects : enable\n"
1305 "#extension GL_ARB_shading_language_420pack : enable\n"
1306 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1307 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1308 "layout (location = 0) in vec4 color;\n"
1309 "layout (location = 1) in vec4 color2;\n"
1310 "void main() {\n"
1311 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1312 " float dist_squared = dot(pos, pos);\n"
1313 " if (dist_squared < 100.0)\n"
1314 " discard;\n"
1315 " gl_FragColor = (dist_squared < 400.0)\n"
1316 " ? color\n"
1317 " : color2;\n"
1318 "}\n";
1319
1320 ASSERT_NO_FATAL_FAILURE(InitState());
1321 ASSERT_NO_FATAL_FAILURE(InitViewport());
1322
1323 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001324 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001325
1326 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1327 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1328
1329 XglPipelineObj pipelineobj(m_device);
1330 pipelineobj.AddShader(&vs);
1331 pipelineobj.AddShader(&ps);
1332
1333 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001334 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001335
1336 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1337 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1338 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1339 };
1340
1341 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1342 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001343 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001344 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1345 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001346 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001347 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1348
1349 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1350 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1351 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1352
Tony Barbourdd4c9642015-01-09 12:55:14 -07001353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1354 XglCommandBufferObj cmdBuffer(m_device);
1355 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1356
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001357 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001358
1359 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1360
1361 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1362#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001363 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001364 pDSDumpDot((char*)"triTest2.dot");
1365#endif
1366 // render triangle
1367 cmdBuffer.Draw(0, 6, 0, 1);
1368
1369 // finalize recording of the command buffer
1370 cmdBuffer.EndCommandBuffer();
1371 cmdBuffer.QueueCommandBuffer(NULL, 0);
1372
1373 for (int i = 0; i < m_renderTargetCount; i++)
1374 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001375
1376}
1377
1378
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001379TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001380{
1381 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001382 "#version 140\n"
1383 "#extension GL_ARB_separate_shader_objects : enable\n"
1384 "#extension GL_ARB_shading_language_420pack : enable\n"
1385 "\n"
1386 "layout(binding = 0) uniform buf {\n"
1387 " mat4 MVP;\n"
1388 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001389 "void main() {\n"
1390 " vec2 vertices[3];"
1391 " vertices[0] = vec2(-0.5, -0.5);\n"
1392 " vertices[1] = vec2( 0.5, -0.5);\n"
1393 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001394 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001395 "}\n";
1396
1397 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001398 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001399 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001400 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001401 "}\n";
1402
Tony Barbourf43b6982014-11-25 13:18:32 -07001403 ASSERT_NO_FATAL_FAILURE(InitState());
1404 ASSERT_NO_FATAL_FAILURE(InitViewport());
1405
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001406 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001407 glm::mat4 Projection = glm::mat4(1.0f);
1408 glm::mat4 View = glm::mat4(1.0f);
1409 glm::mat4 Model = glm::mat4(1.0f);
1410 glm::mat4 MVP = Projection * View * Model;
1411 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1412
Tony Barbourf43b6982014-11-25 13:18:32 -07001413 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1414 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1415 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001416
Tony Barbourf43b6982014-11-25 13:18:32 -07001417 XglPipelineObj pipelineobj(m_device);
1418 pipelineobj.AddShader(&vs);
1419 pipelineobj.AddShader(&ps);
1420
1421 // Create descriptor set and attach the constant buffer to it
1422 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001423 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001424
1425 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1426
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1428 XglCommandBufferObj cmdBuffer(m_device);
1429 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001430
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001431 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001432
1433 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1434
1435 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1436#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001437 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001438 pDSDumpDot((char*)"triTest2.dot");
1439#endif
1440 // render triangle
1441 cmdBuffer.Draw(0, 6, 0, 1);
1442
1443 // finalize recording of the command buffer
1444 cmdBuffer.EndCommandBuffer();
1445 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1446
1447 for (int i = 0; i < m_renderTargetCount; i++)
1448 RecordImage(m_renderTargets[i]);
1449
1450 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001451}
1452
Tony Barbourf43b6982014-11-25 13:18:32 -07001453TEST_F(XglRenderTest, MixTriangle)
1454{
1455 // This tests location applied to varyings. Notice that we have switched foo
1456 // and bar in the FS. The triangle should be blended with red, green and blue
1457 // corners.
1458 static const char *vertShaderText =
1459 "#version 140\n"
1460 "#extension GL_ARB_separate_shader_objects : enable\n"
1461 "#extension GL_ARB_shading_language_420pack : enable\n"
1462 "layout (location=0) out vec4 bar;\n"
1463 "layout (location=1) out vec4 foo;\n"
1464 "layout (location=2) out float scale;\n"
1465 "vec2 vertices[3];\n"
1466 "void main() {\n"
1467 " vertices[0] = vec2(-1.0, -1.0);\n"
1468 " vertices[1] = vec2( 1.0, -1.0);\n"
1469 " vertices[2] = vec2( 0.0, 1.0);\n"
1470 "vec4 colors[3];\n"
1471 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1472 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1473 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1474 " foo = colors[gl_VertexID % 3];\n"
1475 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1476 " scale = 1.0;\n"
1477 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1478 "}\n";
1479
1480 static const char *fragShaderText =
1481 "#version 140\n"
1482 "#extension GL_ARB_separate_shader_objects : enable\n"
1483 "#extension GL_ARB_shading_language_420pack : enable\n"
1484 "layout (location = 1) in vec4 bar;\n"
1485 "layout (location = 0) in vec4 foo;\n"
1486 "layout (location = 2) in float scale;\n"
1487 "void main() {\n"
1488 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1489 "}\n";
1490
1491 ASSERT_NO_FATAL_FAILURE(InitState());
1492 ASSERT_NO_FATAL_FAILURE(InitViewport());
1493
1494 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1495 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1496
1497 XglPipelineObj pipelineobj(m_device);
1498 pipelineobj.AddShader(&vs);
1499 pipelineobj.AddShader(&ps);
1500
1501 XglDescriptorSetObj descriptorSet(m_device);
1502
Tony Barbourdd4c9642015-01-09 12:55:14 -07001503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504 XglCommandBufferObj cmdBuffer(m_device);
1505 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1506
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001507 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001508
1509 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1510
1511#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001512 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001513 pDSDumpDot((char*)"triTest2.dot");
1514#endif
1515 // render triangle
1516 cmdBuffer.Draw(0, 3, 0, 1);
1517
1518 // finalize recording of the command buffer
1519 cmdBuffer.EndCommandBuffer();
1520 cmdBuffer.QueueCommandBuffer(NULL, 0);
1521
1522 for (int i = 0; i < m_renderTargetCount; i++)
1523 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001524}
1525
1526TEST_F(XglRenderTest, TriVertFetchAndVertID)
1527{
1528 // This tests that attributes work in the presence of gl_VertexID
1529
1530 static const char *vertShaderText =
1531 "#version 140\n"
1532 "#extension GL_ARB_separate_shader_objects : enable\n"
1533 "#extension GL_ARB_shading_language_420pack : enable\n"
1534 //XYZ1( -1, -1, -1 )
1535 "layout (location = 0) in vec4 pos;\n"
1536 //XYZ1( 0.f, 0.f, 0.f )
1537 "layout (location = 1) in vec4 inColor;\n"
1538 "layout (location = 0) out vec4 outColor;\n"
1539 "void main() {\n"
1540 " outColor = inColor;\n"
1541 " vec4 vertices[3];"
1542 " vertices[gl_VertexID % 3] = pos;\n"
1543 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1544 "}\n";
1545
1546
1547 static const char *fragShaderText =
1548 "#version 140\n"
1549 "#extension GL_ARB_separate_shader_objects : enable\n"
1550 "#extension GL_ARB_shading_language_420pack : enable\n"
1551 "layout (location = 0) in vec4 color;\n"
1552 "void main() {\n"
1553 " gl_FragColor = color;\n"
1554 "}\n";
1555
1556 ASSERT_NO_FATAL_FAILURE(InitState());
1557 ASSERT_NO_FATAL_FAILURE(InitViewport());
1558
1559 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001560 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001561
1562 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1563 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1564
1565 XglPipelineObj pipelineobj(m_device);
1566 pipelineobj.AddShader(&vs);
1567 pipelineobj.AddShader(&ps);
1568
1569 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001570 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001571
1572 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1573 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1574 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1575 };
1576
1577 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1578 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001579 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001580 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1581 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001582 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001583 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1584
1585 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1586 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1587 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1588
Tony Barbourdd4c9642015-01-09 12:55:14 -07001589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1590 XglCommandBufferObj cmdBuffer(m_device);
1591 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1592
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001593 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001594
1595 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1596
1597 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1598#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001599 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001600 pDSDumpDot((char*)"triTest2.dot");
1601#endif
1602 // render triangle
1603 cmdBuffer.Draw(0, 6, 0, 1);
1604
1605 // finalize recording of the command buffer
1606 cmdBuffer.EndCommandBuffer();
1607 cmdBuffer.QueueCommandBuffer(NULL, 0);
1608
1609 for (int i = 0; i < m_renderTargetCount; i++)
1610 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001611}
1612
1613TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1614{
1615 // This tests that attributes work in the presence of gl_VertexID
1616 // and a dead attribute in position 0. Draws a triangle with yellow,
1617 // red and green corners, starting at top and going clockwise.
1618
1619 static const char *vertShaderText =
1620 "#version 140\n"
1621 "#extension GL_ARB_separate_shader_objects : enable\n"
1622 "#extension GL_ARB_shading_language_420pack : enable\n"
1623 //XYZ1( -1, -1, -1 )
1624 "layout (location = 0) in vec4 pos;\n"
1625 //XYZ1( 0.f, 0.f, 0.f )
1626 "layout (location = 1) in vec4 inColor;\n"
1627 "layout (location = 0) out vec4 outColor;\n"
1628 "void main() {\n"
1629 " outColor = inColor;\n"
1630 " vec2 vertices[3];"
1631 " vertices[0] = vec2(-1.0, -1.0);\n"
1632 " vertices[1] = vec2( 1.0, -1.0);\n"
1633 " vertices[2] = vec2( 0.0, 1.0);\n"
1634 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1635 "}\n";
1636
1637
1638 static const char *fragShaderText =
1639 "#version 140\n"
1640 "#extension GL_ARB_separate_shader_objects : enable\n"
1641 "#extension GL_ARB_shading_language_420pack : enable\n"
1642 "layout (location = 0) in vec4 color;\n"
1643 "void main() {\n"
1644 " gl_FragColor = color;\n"
1645 "}\n";
1646
1647 ASSERT_NO_FATAL_FAILURE(InitState());
1648 ASSERT_NO_FATAL_FAILURE(InitViewport());
1649
1650 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001651 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001652
1653 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1654 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1655
1656 XglPipelineObj pipelineobj(m_device);
1657 pipelineobj.AddShader(&vs);
1658 pipelineobj.AddShader(&ps);
1659
1660 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001661 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001662
1663 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1664 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1665 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1666 };
1667
1668 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1669 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001670 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001671 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1672 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001673 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001674 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1675
1676 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1677 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1678 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1679
Tony Barbourdd4c9642015-01-09 12:55:14 -07001680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1681 XglCommandBufferObj cmdBuffer(m_device);
1682 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001683
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001684 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001685
1686 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1687
1688 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1689#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001690 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001691 pDSDumpDot((char*)"triTest2.dot");
1692#endif
1693 // render triangle
1694 cmdBuffer.Draw(0, 6, 0, 1);
1695
1696 // finalize recording of the command buffer
1697 cmdBuffer.EndCommandBuffer();
1698 cmdBuffer.QueueCommandBuffer(NULL, 0);
1699
1700 for (int i = 0; i < m_renderTargetCount; i++)
1701 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001702}
1703
1704TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001705{
1706 static const char *vertShaderText =
1707 "#version 140\n"
1708 "layout (std140) uniform bufferVals {\n"
1709 " mat4 mvp;\n"
1710 "} myBufferVals;\n"
1711 "in vec4 pos;\n"
1712 "in vec4 inColor;\n"
1713 "out vec4 outColor;\n"
1714 "void main() {\n"
1715 " outColor = inColor;\n"
1716 " gl_Position = myBufferVals.mvp * pos;\n"
1717 "}\n";
1718
1719 static const char *fragShaderText =
1720 "#version 130\n"
1721 "in vec4 color;\n"
1722 "void main() {\n"
1723 " gl_FragColor = color;\n"
1724 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001725 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001726
Tony Barbourf43b6982014-11-25 13:18:32 -07001727 glm::mat4 View = glm::lookAt(
1728 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1729 glm::vec3(0,0,0), // and looks at the origin
1730 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1731 );
1732
1733 glm::mat4 Model = glm::mat4(1.0f);
1734
1735 glm::mat4 MVP = Projection * View * Model;
1736
1737 ASSERT_NO_FATAL_FAILURE(InitState());
1738 ASSERT_NO_FATAL_FAILURE(InitViewport());
1739 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1740
1741 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1742 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1743
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001744 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001745
1746 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1747 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1748 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1749
Tony Barbourf43b6982014-11-25 13:18:32 -07001750 XglPipelineObj pipelineobj(m_device);
1751 pipelineobj.AddShader(&vs);
1752 pipelineobj.AddShader(&ps);
1753
Tony Barbourfa6cac72015-01-16 14:27:35 -07001754 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1755 ds_state.depthTestEnable = XGL_TRUE;
1756 ds_state.depthWriteEnable = XGL_TRUE;
1757 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1758 ds_state.depthBoundsEnable = XGL_FALSE;
1759 ds_state.stencilTestEnable = XGL_FALSE;
1760 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1761 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1762 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1763 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001764 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001765 ds_state.front = ds_state.back;
1766 pipelineobj.SetDepthStencil(&ds_state);
1767
Tony Barbourf43b6982014-11-25 13:18:32 -07001768 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001769 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
1771 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1772 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1773
1774 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1775 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1776 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1777 };
1778
1779 // this is the current description of g_vbData
1780 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1781 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001782 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001783 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1784 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001785 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001786 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1787
1788 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1789 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1790 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1791
Tony Barboure4ed9942015-01-09 10:06:53 -07001792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1793 XglCommandBufferObj cmdBuffer(m_device);
1794 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001795
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001796 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001797 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001798
Tony Barboure4ed9942015-01-09 10:06:53 -07001799 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1800#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001801 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001802 pDSDumpDot((char*)"triTest2.dot");
1803#endif
1804 // render triangle
1805 cmdBuffer.Draw(0, 36, 0, 1);
1806
1807 // finalize recording of the command buffer
1808 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001809 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001810
1811 for (int i = 0; i < m_renderTargetCount; i++)
1812 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001813}
1814
Tony Barbourf43b6982014-11-25 13:18:32 -07001815TEST_F(XglRenderTest, VSTexture)
1816{
1817 // The expected result from this test is a green and red triangle;
1818 // one red vertex on the left, two green vertices on the right.
1819 static const char *vertShaderText =
1820 "#version 130\n"
1821 "out vec4 texColor;\n"
1822 "uniform sampler2D surface;\n"
1823 "void main() {\n"
1824 " vec2 vertices[3];"
1825 " vertices[0] = vec2(-0.5, -0.5);\n"
1826 " vertices[1] = vec2( 0.5, -0.5);\n"
1827 " vertices[2] = vec2( 0.5, 0.5);\n"
1828 " vec2 positions[3];"
1829 " positions[0] = vec2( 0.0, 0.0);\n"
1830 " positions[1] = vec2( 0.25, 0.1);\n"
1831 " positions[2] = vec2( 0.1, 0.25);\n"
1832 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1833 " texColor = textureLod(surface, samplePos, 0.0);\n"
1834 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1835 "}\n";
1836
1837 static const char *fragShaderText =
1838 "#version 130\n"
1839 "in vec4 texColor;\n"
1840 "void main() {\n"
1841 " gl_FragColor = texColor;\n"
1842 "}\n";
1843
1844 ASSERT_NO_FATAL_FAILURE(InitState());
1845 ASSERT_NO_FATAL_FAILURE(InitViewport());
1846
1847 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1848 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1849 XglSamplerObj sampler(m_device);
1850 XglTextureObj texture(m_device);
1851
Tony Barbourf43b6982014-11-25 13:18:32 -07001852 XglPipelineObj pipelineobj(m_device);
1853 pipelineobj.AddShader(&vs);
1854 pipelineobj.AddShader(&ps);
1855
1856 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001857 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001858
1859 m_memoryRefManager.AddMemoryRef(&texture);
1860
Tony Barbourdd4c9642015-01-09 12:55:14 -07001861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1862 XglCommandBufferObj cmdBuffer(m_device);
1863 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001864
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001865 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001866
1867 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1868
1869#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001870 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001871 pDSDumpDot((char*)"triTest2.dot");
1872#endif
1873 // render triangle
1874 cmdBuffer.Draw(0, 3, 0, 1);
1875
1876 // finalize recording of the command buffer
1877 cmdBuffer.EndCommandBuffer();
1878 cmdBuffer.QueueCommandBuffer(NULL, 0);
1879
1880 for (int i = 0; i < m_renderTargetCount; i++)
1881 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001882}
1883TEST_F(XglRenderTest, TexturedTriangle)
1884{
1885 // The expected result from this test is a red and green checkered triangle
1886 static const char *vertShaderText =
1887 "#version 140\n"
1888 "#extension GL_ARB_separate_shader_objects : enable\n"
1889 "#extension GL_ARB_shading_language_420pack : enable\n"
1890 "layout (location = 0) out vec2 samplePos;\n"
1891 "void main() {\n"
1892 " vec2 vertices[3];"
1893 " vertices[0] = vec2(-0.5, -0.5);\n"
1894 " vertices[1] = vec2( 0.5, -0.5);\n"
1895 " vertices[2] = vec2( 0.5, 0.5);\n"
1896 " vec2 positions[3];"
1897 " positions[0] = vec2( 0.0, 0.0);\n"
1898 " positions[1] = vec2( 1.0, 0.0);\n"
1899 " positions[2] = vec2( 1.0, 1.0);\n"
1900 " samplePos = positions[gl_VertexID % 3];\n"
1901 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1902 "}\n";
1903
1904 static const char *fragShaderText =
1905 "#version 140\n"
1906 "#extension GL_ARB_separate_shader_objects : enable\n"
1907 "#extension GL_ARB_shading_language_420pack : enable\n"
1908 "layout (location = 0) in vec2 samplePos;\n"
1909 "layout (binding = 0) uniform sampler2D surface;\n"
1910 "layout (location=0) out vec4 outColor;\n"
1911 "void main() {\n"
1912 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1913 " outColor = texColor;\n"
1914 "}\n";
1915
1916 ASSERT_NO_FATAL_FAILURE(InitState());
1917 ASSERT_NO_FATAL_FAILURE(InitViewport());
1918
1919 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1920 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1921 XglSamplerObj sampler(m_device);
1922 XglTextureObj texture(m_device);
1923
Tony Barbourf43b6982014-11-25 13:18:32 -07001924 XglPipelineObj pipelineobj(m_device);
1925 pipelineobj.AddShader(&vs);
1926 pipelineobj.AddShader(&ps);
1927
1928 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001929 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001930
1931 m_memoryRefManager.AddMemoryRef(&texture);
1932
Tony Barbourdd4c9642015-01-09 12:55:14 -07001933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1934 XglCommandBufferObj cmdBuffer(m_device);
1935 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1936
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001937 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001938
1939 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1940
1941#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001942 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001943 pDSDumpDot((char*)"triTest2.dot");
1944#endif
1945 // render triangle
1946 cmdBuffer.Draw(0, 3, 0, 1);
1947
1948 // finalize recording of the command buffer
1949 cmdBuffer.EndCommandBuffer();
1950 cmdBuffer.QueueCommandBuffer(NULL, 0);
1951
1952 for (int i = 0; i < m_renderTargetCount; i++)
1953 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001954}
1955TEST_F(XglRenderTest, TexturedTriangleClip)
1956{
1957 // The expected result from this test is a red and green checkered triangle
1958 static const char *vertShaderText =
1959 "#version 330\n"
1960 "#extension GL_ARB_separate_shader_objects : enable\n"
1961 "#extension GL_ARB_shading_language_420pack : enable\n"
1962 "layout (location = 0) out vec2 samplePos;\n"
1963 "out gl_PerVertex {\n"
1964 " vec4 gl_Position;\n"
1965 " float gl_ClipDistance[1];\n"
1966 "};\n"
1967 "void main() {\n"
1968 " vec2 vertices[3];"
1969 " vertices[0] = vec2(-0.5, -0.5);\n"
1970 " vertices[1] = vec2( 0.5, -0.5);\n"
1971 " vertices[2] = vec2( 0.5, 0.5);\n"
1972 " vec2 positions[3];"
1973 " positions[0] = vec2( 0.0, 0.0);\n"
1974 " positions[1] = vec2( 1.0, 0.0);\n"
1975 " positions[2] = vec2( 1.0, 1.0);\n"
1976 " float dists[3];\n"
1977 " dists[0] = 1.0;\n"
1978 " dists[1] = 1.0;\n"
1979 " dists[2] = -1.0;\n"
1980 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1981 " samplePos = positions[gl_VertexID % 3];\n"
1982 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1983 "}\n";
1984
1985 static const char *fragShaderText =
1986 "#version 140\n"
1987 "#extension GL_ARB_separate_shader_objects : enable\n"
1988 "#extension GL_ARB_shading_language_420pack : enable\n"
1989 "layout (location = 0) in vec2 samplePos;\n"
1990 "layout (binding = 0) uniform sampler2D surface;\n"
1991 "layout (location=0) out vec4 outColor;\n"
1992 "void main() {\n"
1993 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1994 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1995 " outColor = texColor;\n"
1996 "}\n";
1997
1998
1999 ASSERT_NO_FATAL_FAILURE(InitState());
2000 ASSERT_NO_FATAL_FAILURE(InitViewport());
2001
2002 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2003 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2004 XglSamplerObj sampler(m_device);
2005 XglTextureObj texture(m_device);
2006
Tony Barbourf43b6982014-11-25 13:18:32 -07002007 XglPipelineObj pipelineobj(m_device);
2008 pipelineobj.AddShader(&vs);
2009 pipelineobj.AddShader(&ps);
2010
2011 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002012 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002013
2014 m_memoryRefManager.AddMemoryRef(&texture);
2015
Tony Barbourdd4c9642015-01-09 12:55:14 -07002016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2017 XglCommandBufferObj cmdBuffer(m_device);
2018 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2019
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002020 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002021
2022 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2023
2024#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002025 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002026 pDSDumpDot((char*)"triTest2.dot");
2027#endif
2028 // render triangle
2029 cmdBuffer.Draw(0, 3, 0, 1);
2030
2031 // finalize recording of the command buffer
2032 cmdBuffer.EndCommandBuffer();
2033 cmdBuffer.QueueCommandBuffer(NULL, 0);
2034
2035 for (int i = 0; i < m_renderTargetCount; i++)
2036 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002037}
2038TEST_F(XglRenderTest, FSTriangle)
2039{
2040 // The expected result from this test is a red and green checkered triangle
2041 static const char *vertShaderText =
2042 "#version 140\n"
2043 "#extension GL_ARB_separate_shader_objects : enable\n"
2044 "#extension GL_ARB_shading_language_420pack : enable\n"
2045 "layout (location = 0) out vec2 samplePos;\n"
2046 "void main() {\n"
2047 " vec2 vertices[3];"
2048 " vertices[0] = vec2(-0.5, -0.5);\n"
2049 " vertices[1] = vec2( 0.5, -0.5);\n"
2050 " vertices[2] = vec2( 0.5, 0.5);\n"
2051 " vec2 positions[3];"
2052 " positions[0] = vec2( 0.0, 0.0);\n"
2053 " positions[1] = vec2( 1.0, 0.0);\n"
2054 " positions[2] = vec2( 1.0, 1.0);\n"
2055 " samplePos = positions[gl_VertexID % 3];\n"
2056 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2057 "}\n";
2058
2059 static const char *fragShaderText =
2060 "#version 140\n"
2061 "#extension GL_ARB_separate_shader_objects : enable\n"
2062 "#extension GL_ARB_shading_language_420pack : enable\n"
2063 "layout (location = 0) in vec2 samplePos;\n"
2064 "layout (binding = 0) uniform sampler2D surface;\n"
2065 "layout (location=0) out vec4 outColor;\n"
2066 "void main() {\n"
2067 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2068 " outColor = texColor;\n"
2069 "}\n";
2070
2071 ASSERT_NO_FATAL_FAILURE(InitState());
2072 ASSERT_NO_FATAL_FAILURE(InitViewport());
2073
2074 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2075 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2076 XglSamplerObj sampler(m_device);
2077 XglTextureObj texture(m_device);
2078
Tony Barbourf43b6982014-11-25 13:18:32 -07002079 XglPipelineObj pipelineobj(m_device);
2080 pipelineobj.AddShader(&vs);
2081 pipelineobj.AddShader(&ps);
2082
2083 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002084 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002085
2086 m_memoryRefManager.AddMemoryRef(&texture);
2087
Tony Barbourdd4c9642015-01-09 12:55:14 -07002088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2089 XglCommandBufferObj cmdBuffer(m_device);
2090 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2091
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002092 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002093
2094 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2095
2096#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002097 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002098 pDSDumpDot((char*)"triTest2.dot");
2099#endif
2100 // render triangle
2101 cmdBuffer.Draw(0, 3, 0, 1);
2102
2103 // finalize recording of the command buffer
2104 cmdBuffer.EndCommandBuffer();
2105 cmdBuffer.QueueCommandBuffer(NULL, 0);
2106
2107 for (int i = 0; i < m_renderTargetCount; i++)
2108 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002109}
2110TEST_F(XglRenderTest, SamplerBindingsTriangle)
2111{
2112 // This test sets bindings on the samplers
2113 // For now we are asserting that sampler and texture pairs
2114 // march in lock step, and are set via GLSL binding. This can
2115 // and will probably change.
2116 // The sampler bindings should match the sampler and texture slot
2117 // number set up by the application.
2118 // This test will result in a blue triangle
2119 static const char *vertShaderText =
2120 "#version 140\n"
2121 "#extension GL_ARB_separate_shader_objects : enable\n"
2122 "#extension GL_ARB_shading_language_420pack : enable\n"
2123 "layout (location = 0) out vec4 samplePos;\n"
2124 "void main() {\n"
2125 " vec2 vertices[3];"
2126 " vertices[0] = vec2(-0.5, -0.5);\n"
2127 " vertices[1] = vec2( 0.5, -0.5);\n"
2128 " vertices[2] = vec2( 0.5, 0.5);\n"
2129 " vec2 positions[3];"
2130 " positions[0] = vec2( 0.0, 0.0);\n"
2131 " positions[1] = vec2( 1.0, 0.0);\n"
2132 " positions[2] = vec2( 1.0, 1.0);\n"
2133 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2134 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2135 "}\n";
2136
2137 static const char *fragShaderText =
2138 "#version 140\n"
2139 "#extension GL_ARB_separate_shader_objects : enable\n"
2140 "#extension GL_ARB_shading_language_420pack : enable\n"
2141 "layout (location = 0) in vec4 samplePos;\n"
2142 "layout (binding = 0) uniform sampler2D surface0;\n"
2143 "layout (binding = 1) uniform sampler2D surface1;\n"
2144 "layout (binding = 12) uniform sampler2D surface2;\n"
2145 "void main() {\n"
2146 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2147 "}\n";
2148
2149 ASSERT_NO_FATAL_FAILURE(InitState());
2150 ASSERT_NO_FATAL_FAILURE(InitViewport());
2151
2152 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2153 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2154
2155 XglSamplerObj sampler1(m_device);
2156 XglSamplerObj sampler2(m_device);
2157 XglSamplerObj sampler3(m_device);
2158
2159 XglTextureObj texture1(m_device); // Red
2160 texture1.ChangeColors(0xffff0000,0xffff0000);
2161 XglTextureObj texture2(m_device); // Green
2162 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2163 XglTextureObj texture3(m_device); // Blue
2164 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2165
Tony Barbourf43b6982014-11-25 13:18:32 -07002166 XglPipelineObj pipelineobj(m_device);
2167 pipelineobj.AddShader(&vs);
2168 pipelineobj.AddShader(&ps);
2169
2170 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002171 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2172 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2173 for (int i = 0; i < 10; i++)
2174 descriptorSet.AppendDummy();
2175 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002176
2177 m_memoryRefManager.AddMemoryRef(&texture1);
2178 m_memoryRefManager.AddMemoryRef(&texture2);
2179 m_memoryRefManager.AddMemoryRef(&texture3);
2180
Tony Barbourdd4c9642015-01-09 12:55:14 -07002181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2182 XglCommandBufferObj cmdBuffer(m_device);
2183 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2184
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002185 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002186
2187 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2188
2189#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002190 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002191 pDSDumpDot((char*)"triTest2.dot");
2192#endif
2193 // render triangle
2194 cmdBuffer.Draw(0, 3, 0, 1);
2195
2196 // finalize recording of the command buffer
2197 cmdBuffer.EndCommandBuffer();
2198 cmdBuffer.QueueCommandBuffer(NULL, 0);
2199
2200 for (int i = 0; i < m_renderTargetCount; i++)
2201 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002202
2203}
2204
2205TEST_F(XglRenderTest, TriangleVSUniformBlock)
2206{
2207 // The expected result from this test is a blue triangle
2208
2209 static const char *vertShaderText =
2210 "#version 140\n"
2211 "#extension GL_ARB_separate_shader_objects : enable\n"
2212 "#extension GL_ARB_shading_language_420pack : enable\n"
2213 "layout (location = 0) out vec4 outColor;\n"
2214 "layout (std140, binding = 0) uniform bufferVals {\n"
2215 " vec4 red;\n"
2216 " vec4 green;\n"
2217 " vec4 blue;\n"
2218 " vec4 white;\n"
2219 "} myBufferVals;\n"
2220 "void main() {\n"
2221 " vec2 vertices[3];"
2222 " vertices[0] = vec2(-0.5, -0.5);\n"
2223 " vertices[1] = vec2( 0.5, -0.5);\n"
2224 " vertices[2] = vec2( 0.5, 0.5);\n"
2225 " outColor = myBufferVals.blue;\n"
2226 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2227 "}\n";
2228
2229 static const char *fragShaderText =
2230 "#version 140\n"
2231 "#extension GL_ARB_separate_shader_objects : enable\n"
2232 "#extension GL_ARB_shading_language_420pack : enable\n"
2233 "layout (location = 0) in vec4 inColor;\n"
2234 "void main() {\n"
2235 " gl_FragColor = inColor;\n"
2236 "}\n";
2237
2238 ASSERT_NO_FATAL_FAILURE(InitState());
2239 ASSERT_NO_FATAL_FAILURE(InitViewport());
2240
2241 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2242 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2243
2244 // Let's populate our buffer with the following:
2245 // vec4 red;
2246 // vec4 green;
2247 // vec4 blue;
2248 // vec4 white;
2249 const int valCount = 4 * 4;
2250 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2251 0.0, 1.0, 0.0, 1.0,
2252 0.0, 0.0, 1.0, 1.0,
2253 1.0, 1.0, 1.0, 1.0 };
2254
2255 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002256
2257 XglPipelineObj pipelineobj(m_device);
2258 pipelineobj.AddShader(&vs);
2259 pipelineobj.AddShader(&ps);
2260
2261 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002262 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002263
Tony Barbourdd4c9642015-01-09 12:55:14 -07002264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2265 XglCommandBufferObj cmdBuffer(m_device);
2266 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2267
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002268 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002269
2270 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2271
2272#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002274 pDSDumpDot((char*)"triTest2.dot");
2275#endif
2276 // render triangle
2277 cmdBuffer.Draw(0, 3, 0, 1);
2278
2279 // finalize recording of the command buffer
2280 cmdBuffer.EndCommandBuffer();
2281 cmdBuffer.QueueCommandBuffer(NULL, 0);
2282
2283 for (int i = 0; i < m_renderTargetCount; i++)
2284 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002285
2286}
2287
2288TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2289{
2290 // This test allows the shader to select which buffer it is
2291 // pulling from using layout binding qualifier.
2292 // There are corresponding changes in the compiler stack that
2293 // will select the buffer using binding directly.
2294 // The binding number should match the slot number set up by
2295 // the application.
2296 // The expected result from this test is a purple triangle
2297
2298 static const char *vertShaderText =
2299 "#version 140\n"
2300 "#extension GL_ARB_separate_shader_objects : enable\n"
2301 "#extension GL_ARB_shading_language_420pack : enable\n"
2302 "void main() {\n"
2303 " vec2 vertices[3];"
2304 " vertices[0] = vec2(-0.5, -0.5);\n"
2305 " vertices[1] = vec2( 0.5, -0.5);\n"
2306 " vertices[2] = vec2( 0.5, 0.5);\n"
2307 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2308 "}\n";
2309
2310 static const char *fragShaderText =
2311 "#version 140\n"
2312 "#extension GL_ARB_separate_shader_objects : enable\n"
2313 "#extension GL_ARB_shading_language_420pack : enable\n"
2314 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2315 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2316 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002317 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002318 "void main() {\n"
2319 " gl_FragColor = myBlueVal.color;\n"
2320 " gl_FragColor += myRedVal.color;\n"
2321 "}\n";
2322
2323 ASSERT_NO_FATAL_FAILURE(InitState());
2324 ASSERT_NO_FATAL_FAILURE(InitViewport());
2325
2326 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2327 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2328
2329 // We're going to create a number of uniform buffers, and then allow
2330 // the shader to select which it wants to read from with a binding
2331
2332 // Let's populate the buffers with a single color each:
2333 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2334 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2335 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002336 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002337
2338 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2339 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2340 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2341 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2342
2343 const int redCount = sizeof(redVals) / sizeof(float);
2344 const int greenCount = sizeof(greenVals) / sizeof(float);
2345 const int blueCount = sizeof(blueVals) / sizeof(float);
2346 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2347
2348 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002349
2350 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002351
2352 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002353
2354 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002355
2356 XglPipelineObj pipelineobj(m_device);
2357 pipelineobj.AddShader(&vs);
2358 pipelineobj.AddShader(&ps);
2359
2360 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002361 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2362 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2363 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2364 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002365
Tony Barbourdd4c9642015-01-09 12:55:14 -07002366 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2367 XglCommandBufferObj cmdBuffer(m_device);
2368 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002369
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002370 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002371
2372 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2373
2374#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002375 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002376 pDSDumpDot((char*)"triTest2.dot");
2377#endif
2378 // render triangle
2379 cmdBuffer.Draw(0, 3, 0, 1);
2380
2381 // finalize recording of the command buffer
2382 cmdBuffer.EndCommandBuffer();
2383 cmdBuffer.QueueCommandBuffer(NULL, 0);
2384
2385 for (int i = 0; i < m_renderTargetCount; i++)
2386 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002387}
2388
2389TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2390{
2391 // This test is the same as TriangleFSUniformBlockBinding, but
2392 // it does not provide an instance name.
2393 // The expected result from this test is a purple triangle
2394
2395 static const char *vertShaderText =
2396 "#version 140\n"
2397 "#extension GL_ARB_separate_shader_objects : enable\n"
2398 "#extension GL_ARB_shading_language_420pack : enable\n"
2399 "void main() {\n"
2400 " vec2 vertices[3];"
2401 " vertices[0] = vec2(-0.5, -0.5);\n"
2402 " vertices[1] = vec2( 0.5, -0.5);\n"
2403 " vertices[2] = vec2( 0.5, 0.5);\n"
2404 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2405 "}\n";
2406
2407 static const char *fragShaderText =
2408 "#version 430\n"
2409 "#extension GL_ARB_separate_shader_objects : enable\n"
2410 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002411 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2412 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2413 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002414 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002415 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002416 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002417 " outColor = blue;\n"
2418 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002419 "}\n";
2420 ASSERT_NO_FATAL_FAILURE(InitState());
2421 ASSERT_NO_FATAL_FAILURE(InitViewport());
2422
2423 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2424 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2425
2426 // We're going to create a number of uniform buffers, and then allow
2427 // the shader to select which it wants to read from with a binding
2428
2429 // Let's populate the buffers with a single color each:
2430 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2431 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2432 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2433 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2434
2435 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2436 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2437 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2438 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2439
2440 const int redCount = sizeof(redVals) / sizeof(float);
2441 const int greenCount = sizeof(greenVals) / sizeof(float);
2442 const int blueCount = sizeof(blueVals) / sizeof(float);
2443 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2444
2445 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002446
2447 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002448
2449 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002450
2451 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002452
2453 XglPipelineObj pipelineobj(m_device);
2454 pipelineobj.AddShader(&vs);
2455 pipelineobj.AddShader(&ps);
2456
2457 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002458 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2459 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2460 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2461 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002462
Tony Barbourdd4c9642015-01-09 12:55:14 -07002463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2464 XglCommandBufferObj cmdBuffer(m_device);
2465 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2466
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002467 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002468
2469 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2470
2471#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002472 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002473 pDSDumpDot((char*)"triTest2.dot");
2474#endif
2475 // render triangle
2476 cmdBuffer.Draw(0, 3, 0, 1);
2477
2478 // finalize recording of the command buffer
2479 cmdBuffer.EndCommandBuffer();
2480 cmdBuffer.QueueCommandBuffer(NULL, 0);
2481
2482 for (int i = 0; i < m_renderTargetCount; i++)
2483 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002484
2485}
2486
2487TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2488{
2489 static const char *vertShaderText =
2490 "#version 140\n"
2491 "#extension GL_ARB_separate_shader_objects : enable\n"
2492 "#extension GL_ARB_shading_language_420pack : enable\n"
2493 "layout (std140, binding=0) uniform bufferVals {\n"
2494 " mat4 mvp;\n"
2495 "} myBufferVals;\n"
2496 "layout (location=0) in vec4 pos;\n"
2497 "layout (location=0) out vec2 UV;\n"
2498 "void main() {\n"
2499 " vec2 positions[3];"
2500 " positions[0] = vec2( 0.0, 0.0);\n"
2501 " positions[1] = vec2( 0.25, 0.1);\n"
2502 " positions[2] = vec2( 0.1, 0.25);\n"
2503 " UV = positions[gl_VertexID % 3];\n"
2504 " gl_Position = myBufferVals.mvp * pos;\n"
2505 "}\n";
2506
2507 static const char *fragShaderText =
2508 "#version 140\n"
2509 "#extension GL_ARB_separate_shader_objects : enable\n"
2510 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002511 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002512 "layout (location=0) out vec4 outColor;\n"
2513 "layout (location=0) in vec2 UV;\n"
2514 "void main() {\n"
2515 " outColor= textureLod(surface, UV, 0.0);\n"
2516 "}\n";
2517 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2518
2519 glm::mat4 View = glm::lookAt(
2520 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2521 glm::vec3(0,0,0), // and looks at the origin
2522 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2523 );
2524
2525 glm::mat4 Model = glm::mat4(1.0f);
2526
2527 glm::mat4 MVP = Projection * View * Model;
2528
2529
2530 ASSERT_NO_FATAL_FAILURE(InitState());
2531 ASSERT_NO_FATAL_FAILURE(InitViewport());
2532 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2533
2534 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2535 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002536 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002537
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002538 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
2540 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2541 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2542 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2543 XglSamplerObj sampler(m_device);
2544 XglTextureObj texture(m_device);
2545
Tony Barbourf43b6982014-11-25 13:18:32 -07002546 XglPipelineObj pipelineobj(m_device);
2547 pipelineobj.AddShader(&vs);
2548 pipelineobj.AddShader(&ps);
2549
2550 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002551 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2552 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002553
2554 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2555 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2556 m_memoryRefManager.AddMemoryRef(&texture);
2557
2558 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2559 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2560 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2561 };
2562
2563 // this is the current description of g_vbData
2564 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2565 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002566 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002567 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2568 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002569 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002570 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2571
2572 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2573 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2574 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2575
Tony Barbourfa6cac72015-01-16 14:27:35 -07002576 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2577 ds_state.depthTestEnable = XGL_TRUE;
2578 ds_state.depthWriteEnable = XGL_TRUE;
2579 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2580 ds_state.depthBoundsEnable = XGL_FALSE;
2581 ds_state.stencilTestEnable = XGL_FALSE;
2582 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2583 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2584 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2585 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002586 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002587 ds_state.front = ds_state.back;
2588 pipelineobj.SetDepthStencil(&ds_state);
2589
Tony Barbourdd4c9642015-01-09 12:55:14 -07002590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2591 XglCommandBufferObj cmdBuffer(m_device);
2592 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002593
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002594 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002595 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2596
2597 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2598#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002599 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002600 pDSDumpDot((char*)"triTest2.dot");
2601#endif
2602 // render triangle
2603 cmdBuffer.Draw(0, 36, 0, 1);
2604
2605 // finalize recording of the command buffer
2606 cmdBuffer.EndCommandBuffer();
2607 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2608
2609 for (int i = 0; i < m_renderTargetCount; i++)
2610 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002611
2612}
Cody Northropd1ce7842014-12-09 11:17:01 -07002613
2614TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2615{
2616 // This test mixes binding slots of textures and buffers, ensuring
2617 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002618 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002619 // you can modify it to move the desired result around.
2620
2621 static const char *vertShaderText =
2622 "#version 140\n"
2623 "#extension GL_ARB_separate_shader_objects : enable\n"
2624 "#extension GL_ARB_shading_language_420pack : enable\n"
2625 "void main() {\n"
2626 " vec2 vertices[3];"
2627 " vertices[0] = vec2(-0.5, -0.5);\n"
2628 " vertices[1] = vec2( 0.5, -0.5);\n"
2629 " vertices[2] = vec2( 0.5, 0.5);\n"
2630 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2631 "}\n";
2632
2633 static const char *fragShaderText =
2634 "#version 430\n"
2635 "#extension GL_ARB_separate_shader_objects : enable\n"
2636 "#extension GL_ARB_shading_language_420pack : enable\n"
2637 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002638 "layout (binding = 3) uniform sampler2D surface1;\n"
2639 "layout (binding = 1) uniform sampler2D surface2;\n"
2640 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002641
Cody Northropa0410942014-12-09 13:59:39 -07002642
Chia-I Wuf8385062015-01-04 16:27:24 +08002643 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2644 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2645 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2646 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002647 "layout (location = 0) out vec4 outColor;\n"
2648 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002649 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002650 " outColor += white * vec4(0.00001);\n"
2651 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002652 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002653 "}\n";
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitViewport());
2656
2657 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2658 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2659
Cody Northropd1ce7842014-12-09 11:17:01 -07002660 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2661 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2662 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2663 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2664
2665 const int redCount = sizeof(redVals) / sizeof(float);
2666 const int greenCount = sizeof(greenVals) / sizeof(float);
2667 const int blueCount = sizeof(blueVals) / sizeof(float);
2668 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2669
2670 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002671 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002672 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002673 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002674
2675 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002676 XglTextureObj texture0(m_device); // Light Red
2677 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002678 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002679 XglTextureObj texture2(m_device); // Light Blue
2680 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002681 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002682 XglTextureObj texture4(m_device); // Light Green
2683 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002684
2685 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2686 // TODO: Get back here ASAP and understand why.
2687 XglSamplerObj sampler7(m_device);
2688 XglTextureObj texture7(m_device); // Red and Blue
2689 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002690
2691 XglPipelineObj pipelineobj(m_device);
2692 pipelineobj.AddShader(&vs);
2693 pipelineobj.AddShader(&ps);
2694
2695 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002696 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2697 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2698 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2699 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2700 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2701 // swap blue and green
2702 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2703 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2704 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002705
2706 m_memoryRefManager.AddMemoryRef(&texture0);
2707 m_memoryRefManager.AddMemoryRef(&texture2);
2708 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002709 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002710
Tony Barbourdd4c9642015-01-09 12:55:14 -07002711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2712 XglCommandBufferObj cmdBuffer(m_device);
2713 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002714
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002715 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002716
2717 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2718
2719#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002720 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002721 pDSDumpDot((char*)"triTest2.dot");
2722#endif
2723 // render triangle
2724 cmdBuffer.Draw(0, 3, 0, 1);
2725
2726 // finalize recording of the command buffer
2727 cmdBuffer.EndCommandBuffer();
2728 cmdBuffer.QueueCommandBuffer(NULL, 0);
2729
2730 for (int i = 0; i < m_renderTargetCount; i++)
2731 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002732
2733}
2734
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002735TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2736{
2737 // This test matches binding slots of textures and buffers, requiring
2738 // the driver to give them distinct number spaces.
2739 // The expected result from this test is a red triangle, although
2740 // you can modify it to move the desired result around.
2741
2742 static const char *vertShaderText =
2743 "#version 140\n"
2744 "#extension GL_ARB_separate_shader_objects : enable\n"
2745 "#extension GL_ARB_shading_language_420pack : enable\n"
2746 "void main() {\n"
2747 " vec2 vertices[3];"
2748 " vertices[0] = vec2(-0.5, -0.5);\n"
2749 " vertices[1] = vec2( 0.5, -0.5);\n"
2750 " vertices[2] = vec2( 0.5, 0.5);\n"
2751 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2752 "}\n";
2753
2754 static const char *fragShaderText =
2755 "#version 430\n"
2756 "#extension GL_ARB_separate_shader_objects : enable\n"
2757 "#extension GL_ARB_shading_language_420pack : enable\n"
2758 "layout (binding = 0) uniform sampler2D surface0;\n"
2759 "layout (binding = 1) uniform sampler2D surface1;\n"
2760 "layout (binding = 2) uniform sampler2D surface2;\n"
2761 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002762 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2763 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2764 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2765 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002766 "layout (location = 0) out vec4 outColor;\n"
2767 "void main() {\n"
2768 " outColor = red;// * vec4(0.00001);\n"
2769 " outColor += white * vec4(0.00001);\n"
2770 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2771 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2772 "}\n";
2773 ASSERT_NO_FATAL_FAILURE(InitState());
2774 ASSERT_NO_FATAL_FAILURE(InitViewport());
2775
2776 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2777 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2778
2779 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2780 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2781 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2782 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2783
2784 const int redCount = sizeof(redVals) / sizeof(float);
2785 const int greenCount = sizeof(greenVals) / sizeof(float);
2786 const int blueCount = sizeof(blueVals) / sizeof(float);
2787 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2788
2789 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002790 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002791 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002792 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002793
2794 XglSamplerObj sampler0(m_device);
2795 XglTextureObj texture0(m_device); // Light Red
2796 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002797 XglSamplerObj sampler2(m_device);
2798 XglTextureObj texture2(m_device); // Light Blue
2799 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002800 XglSamplerObj sampler4(m_device);
2801 XglTextureObj texture4(m_device); // Light Green
2802 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002803 XglSamplerObj sampler7(m_device);
2804 XglTextureObj texture7(m_device); // Red and Blue
2805 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002806
2807
2808 XglPipelineObj pipelineobj(m_device);
2809 pipelineobj.AddShader(&vs);
2810 pipelineobj.AddShader(&ps);
2811
2812 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002813 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2814 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2815 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2816 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2817 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2818 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2819 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2820 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002821
2822 m_memoryRefManager.AddMemoryRef(&texture0);
2823 m_memoryRefManager.AddMemoryRef(&texture2);
2824 m_memoryRefManager.AddMemoryRef(&texture4);
2825 m_memoryRefManager.AddMemoryRef(&texture7);
2826
Tony Barbourdd4c9642015-01-09 12:55:14 -07002827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2828 XglCommandBufferObj cmdBuffer(m_device);
2829 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002830
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002831 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002832
2833 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2834
2835#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002836 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002837 pDSDumpDot((char*)"triTest2.dot");
2838#endif
2839 // render triangle
2840 cmdBuffer.Draw(0, 3, 0, 1);
2841
2842 // finalize recording of the command buffer
2843 cmdBuffer.EndCommandBuffer();
2844 cmdBuffer.QueueCommandBuffer(NULL, 0);
2845
2846 for (int i = 0; i < m_renderTargetCount; i++)
2847 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002848
2849}
2850
Cody Northrop02690bd2014-12-17 15:26:33 -07002851TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2852{
2853 // This test populates a buffer with a variety of different data
2854 // types, then reads them out with a shader.
2855 // The expected result from this test is a green triangle
2856
2857 static const char *vertShaderText =
2858 "#version 140\n"
2859 "#extension GL_ARB_separate_shader_objects : enable\n"
2860 "#extension GL_ARB_shading_language_420pack : enable\n"
2861 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2862 " vec4 fRed;\n"
2863 " vec4 fGreen;\n"
2864 " layout(row_major) mat4 worldToProj;\n"
2865 " layout(row_major) mat4 projToWorld;\n"
2866 " layout(row_major) mat4 worldToView;\n"
2867 " layout(row_major) mat4 viewToProj;\n"
2868 " layout(row_major) mat4 worldToShadow[4];\n"
2869 " float fZero;\n"
2870 " float fOne;\n"
2871 " float fTwo;\n"
2872 " float fThree;\n"
2873 " vec3 fZeroZeroZero;\n"
2874 " float fFour;\n"
2875 " vec3 fZeroZeroOne;\n"
2876 " float fFive;\n"
2877 " vec3 fZeroOneZero;\n"
2878 " float fSix;\n"
2879 " float fSeven;\n"
2880 " float fEight;\n"
2881 " float fNine;\n"
2882 " vec2 fZeroZero;\n"
2883 " vec2 fZeroOne;\n"
2884 " vec4 fBlue;\n"
2885 " vec2 fOneZero;\n"
2886 " vec2 fOneOne;\n"
2887 " vec3 fZeroOneOne;\n"
2888 " float fTen;\n"
2889 " float fEleven;\n"
2890 " float fTwelve;\n"
2891 " vec3 fOneZeroZero;\n"
2892 " vec4 uvOffsets[4];\n"
2893 "};\n"
2894 "layout (location = 0) out vec4 color;"
2895 "void main() {\n"
2896
2897 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2898 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2899 " \n"
2900
2901 // do some exact comparisons, even though we should
2902 // really have an epsilon involved.
2903 " vec4 outColor = right;\n"
2904 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2905 " outColor = wrong;\n"
2906 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2907 " outColor = wrong;\n"
2908 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2909 " outColor = wrong;\n"
2910
2911 " color = outColor;\n"
2912
2913 // generic position stuff
2914 " vec2 vertices;\n"
2915 " int vertexSelector = gl_VertexID;\n"
2916 " if (vertexSelector == 0)\n"
2917 " vertices = vec2(-0.5, -0.5);\n"
2918 " else if (vertexSelector == 1)\n"
2919 " vertices = vec2( 0.5, -0.5);\n"
2920 " else if (vertexSelector == 2)\n"
2921 " vertices = vec2( 0.5, 0.5);\n"
2922 " else\n"
2923 " vertices = vec2( 0.0, 0.0);\n"
2924 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2925 "}\n";
2926
2927 static const char *fragShaderText =
2928 "#version 140\n"
2929 "#extension GL_ARB_separate_shader_objects : enable\n"
2930 "#extension GL_ARB_shading_language_420pack : enable\n"
2931 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2932 " vec4 fRed;\n"
2933 " vec4 fGreen;\n"
2934 " layout(row_major) mat4 worldToProj;\n"
2935 " layout(row_major) mat4 projToWorld;\n"
2936 " layout(row_major) mat4 worldToView;\n"
2937 " layout(row_major) mat4 viewToProj;\n"
2938 " layout(row_major) mat4 worldToShadow[4];\n"
2939 " float fZero;\n"
2940 " float fOne;\n"
2941 " float fTwo;\n"
2942 " float fThree;\n"
2943 " vec3 fZeroZeroZero;\n"
2944 " float fFour;\n"
2945 " vec3 fZeroZeroOne;\n"
2946 " float fFive;\n"
2947 " vec3 fZeroOneZero;\n"
2948 " float fSix;\n"
2949 " float fSeven;\n"
2950 " float fEight;\n"
2951 " float fNine;\n"
2952 " vec2 fZeroZero;\n"
2953 " vec2 fZeroOne;\n"
2954 " vec4 fBlue;\n"
2955 " vec2 fOneZero;\n"
2956 " vec2 fOneOne;\n"
2957 " vec3 fZeroOneOne;\n"
2958 " float fTen;\n"
2959 " float fEleven;\n"
2960 " float fTwelve;\n"
2961 " vec3 fOneZeroZero;\n"
2962 " vec4 uvOffsets[4];\n"
2963 "};\n"
2964 "layout (location = 0) in vec4 color;\n"
2965 "void main() {\n"
2966 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2967 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2968 " \n"
2969
2970 // start with VS value to ensure it passed
2971 " vec4 outColor = color;\n"
2972
2973 // do some exact comparisons, even though we should
2974 // really have an epsilon involved.
2975 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2976 " outColor = wrong;\n"
2977 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2978 " outColor = wrong;\n"
2979 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2980 " outColor = wrong;\n"
2981 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2982 " outColor = wrong;\n"
2983 " if (fTwo != 2.0)\n"
2984 " outColor = wrong;\n"
2985 " if (fOneOne != vec2(1.0, 1.0))\n"
2986 " outColor = wrong;\n"
2987 " if (fTen != 10.0)\n"
2988 " outColor = wrong;\n"
2989 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
2990 " outColor = wrong;\n"
2991 " \n"
2992 " gl_FragColor = outColor;\n"
2993 "}\n";
2994
2995
2996 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
2997 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
2998 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
2999 0.0, 1.0, 0.0, 1.0, // align
3000 0.0, 0.0, 1.0, 1.0, // align
3001 0.0, 0.0, 0.0, 1.0, // align
3002 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3003 0.0, 2.0, 0.0, 2.0, // align
3004 0.0, 0.0, 2.0, 2.0, // align
3005 0.0, 0.0, 0.0, 2.0, // align
3006 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3007 0.0, 3.0, 0.0, 3.0, // align
3008 0.0, 0.0, 3.0, 3.0, // align
3009 0.0, 0.0, 0.0, 3.0, // align
3010 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3011 0.0, 4.0, 0.0, 4.0, // align
3012 0.0, 0.0, 4.0, 4.0, // align
3013 0.0, 0.0, 0.0, 4.0, // align
3014 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3015 0.0, 5.0, 0.0, 5.0, // align
3016 0.0, 0.0, 5.0, 5.0, // align
3017 0.0, 0.0, 0.0, 5.0, // align
3018 6.0, 0.0, 0.0, 6.0, // align
3019 0.0, 6.0, 0.0, 6.0, // align
3020 0.0, 0.0, 6.0, 6.0, // align
3021 0.0, 0.0, 0.0, 6.0, // align
3022 7.0, 0.0, 0.0, 7.0, // align
3023 0.0, 7.0, 0.0, 7.0, // align
3024 0.0, 0.0, 7.0, 7.0, // align
3025 0.0, 0.0, 0.0, 7.0, // align
3026 8.0, 0.0, 0.0, 8.0, // align
3027 0.0, 8.0, 0.0, 8.0, // align
3028 0.0, 0.0, 8.0, 8.0, // align
3029 0.0, 0.0, 0.0, 8.0, // align
3030 0.0, // float fZero; // align
3031 1.0, // float fOne; // pack
3032 2.0, // float fTwo; // pack
3033 3.0, // float fThree; // pack
3034 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3035 4.0, // float fFour; // pack
3036 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3037 5.0, // float fFive; // pack
3038 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3039 6.0, // float fSix; // pack
3040 7.0, // float fSeven; // align
3041 8.0, // float fEight; // pack
3042 9.0, // float fNine; // pack
3043 0.0, // BUFFER
3044 0.0, 0.0, // vec2 fZeroZero; // align
3045 0.0, 1.0, // vec2 fZeroOne; // pack
3046 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3047 1.0, 0.0, // vec2 fOneZero; // align
3048 1.0, 1.0, // vec2 fOneOne; // pack
3049 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3050 10.0, // float fTen; // pack
3051 11.0, // float fEleven; // align
3052 12.0, // float fTwelve; // pack
3053 0.0, 0.0, // BUFFER
3054 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3055 0.0, // BUFFER
3056 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3057 0.5, 0.6, 0.7, 0.8, // align
3058 0.9, 1.0, 1.1, 1.2, // align
3059 1.3, 1.4, 1.5, 1.6, // align
3060 };
3061
3062 ASSERT_NO_FATAL_FAILURE(InitState());
3063 ASSERT_NO_FATAL_FAILURE(InitViewport());
3064
3065 const int constCount = sizeof(mixedVals) / sizeof(float);
3066
3067 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3068 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3069
3070 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003071
3072 XglPipelineObj pipelineobj(m_device);
3073 pipelineobj.AddShader(&vs);
3074 pipelineobj.AddShader(&ps);
3075
3076 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003077 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003078
3079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3080 XglCommandBufferObj cmdBuffer(m_device);
3081 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3082
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003083 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003084
3085 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3086
3087#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003088 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003089 pDSDumpDot((char*)"triTest2.dot");
3090#endif
3091 // render triangle
3092 cmdBuffer.Draw(0, 3, 0, 1);
3093
3094 // finalize recording of the command buffer
3095 cmdBuffer.EndCommandBuffer();
3096 cmdBuffer.QueueCommandBuffer(NULL, 0);
3097
3098 for (int i = 0; i < m_renderTargetCount; i++)
3099 RecordImage(m_renderTargets[i]);
3100}
3101
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003102int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003103 int result;
3104
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003105 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003106 XglTestFramework::InitArgs(&argc, argv);
3107
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003108 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003109
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003110 result = RUN_ALL_TESTS();
3111
3112 XglTestFramework::Finish();
3113 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003114}