blob: 5683ea2500317cb2870210b22a1efc686ae3ba0d [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083void XGLAPI myDbgFunc(
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600214public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600215
Tony Barbourf43b6982014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700217 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700218 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600219 void InitDepthStencil();
Tony Barbourae442072015-01-12 13:27:11 -0700220 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600221
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600222 XGL_RESULT BeginCommandBuffer(XglCommandBufferObj &cmdBuffer);
223 XGL_RESULT EndCommandBuffer(XglCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600224
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600225protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600226 XGL_IMAGE m_texture;
227 XGL_IMAGE_VIEW m_textureView;
228 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
229 XGL_GPU_MEMORY m_textureMem;
230
231 XGL_SAMPLER m_sampler;
232
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600233 XGL_IMAGE m_depthStencilImage;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600234 uint32_t m_num_mem;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700235 XGL_GPU_MEMORY *m_depthStencilMem;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600236 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700237 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600238
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600239
240 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600241
242 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
243 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800244 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600245 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800246 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600247 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -0700248 this->app_info.apiVersion = XGL_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600249
Cody Northrop350727b2014-10-06 15:42:00 -0600250 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
251 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700252 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600253
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600254 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600255 }
256
257 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600258 // Clean up resources before we reset
259 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600260 }
261};
262
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600263XGL_RESULT XglRenderTest::BeginCommandBuffer(XglCommandBufferObj &cmdBuffer)
264{
265 XGL_RESULT result;
266
267 result = cmdBuffer.BeginCommandBuffer();
268
269 /*
270 * For render test all drawing happens in a single render pass
271 * on a single command buffer.
272 */
273 if (XGL_SUCCESS == result) {
274 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
275 }
276
277 return result;
278}
279
280XGL_RESULT XglRenderTest::EndCommandBuffer(XglCommandBufferObj &cmdBuffer)
281{
282 XGL_RESULT result;
283
284 cmdBuffer.EndRenderPass(renderPass());
285
286 result = cmdBuffer.EndCommandBuffer();
287
288 return result;
289}
290
291
Tony Barbour02472db2015-01-08 17:08:28 -0700292void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
293{
Courtney Goeltzenleuchter7e305322015-03-05 17:26:38 -0700294 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color,
295 &m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700296 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700297 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
298 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
299 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
300 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800301 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700302 pipelineobj->CreateXGLPipeline(descriptorSet);
303 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700304 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
305}
Tony Barbourf43b6982014-11-25 13:18:32 -0700306
Tony Barbourf43b6982014-11-25 13:18:32 -0700307void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700308 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
309{
310 int i;
311 glm::mat4 MVP;
312 int matrixSize = sizeof(MVP);
313 XGL_RESULT err;
314
315 for (i = 0; i < 8; i++) {
316 void *pData = constantBuffer->map();
317
318 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
319 MVP = Projection * View * Model;
320 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
321
322 constantBuffer->unmap();
323
324 // submit the command buffer to the universal queue
325 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
326
Tony Barbourdd4c9642015-01-09 12:55:14 -0700327 err = xglQueueWaitIdle( m_device->m_queue );
328 ASSERT_XGL_SUCCESS( err );
329
330 // Wait for work to finish before cleaning up.
331 xglDeviceWaitIdle(m_device->device());
332
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700333 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700334 RecordImage(m_renderTargets[0]);
335 }
336}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600337
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600338void dumpMatrix(const char *note, glm::mat4 MVP)
339{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800340 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600341
342 printf("%s: \n", note);
343 for (i=0; i<4; i++) {
344 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
345 }
346 printf("\n");
347 fflush(stdout);
348}
349
350void dumpVec4(const char *note, glm::vec4 vector)
351{
352 printf("%s: \n", note);
353 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
354 printf("\n");
355 fflush(stdout);
356}
357
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600358void XglRenderTest::InitDepthStencil()
359{
360 XGL_RESULT err;
361 XGL_IMAGE_CREATE_INFO image;
362 XGL_MEMORY_ALLOC_INFO mem_alloc;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700363 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600364 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700365 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600366 size_t mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700367 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600368 size_t img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
369 uint32_t num_allocations = 0;
370 size_t num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600371
372 // Clean up default state created by framework
373 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
374
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700375 m_depth_stencil_fmt = XGL_FMT_D16_UNORM;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600376
377 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
378 image.pNext = NULL;
379 image.imageType = XGL_IMAGE_2D;
380 image.format = m_depth_stencil_fmt;
381 image.extent.width = m_width;
382 image.extent.height = m_height;
383 image.extent.depth = 1;
384 image.mipLevels = 1;
385 image.arraySize = 1;
386 image.samples = 1;
387 image.tiling = XGL_OPTIMAL_TILING;
388 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
389 image.flags = 0;
390
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700391 img_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
392 img_alloc.pNext = NULL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600393 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700394 mem_alloc.pNext = &img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600395 mem_alloc.allocationSize = 0;
Jon Ashburn542cd092015-01-20 13:55:32 -0700396 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburn32769172015-01-20 15:06:59 -0700397 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600398 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
399
400 /* create image */
401 err = xglCreateImage(device(), &image,
402 &m_depthStencilImage);
403 ASSERT_XGL_SUCCESS(err);
404
405 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700406 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
407 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600408 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700409 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
410 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
411 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
412 m_num_mem = num_allocations;
413 err = xglGetObjectInfo(m_depthStencilImage,
414 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
415 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600416 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700417 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700418 err = xglGetObjectInfo(m_depthStencilImage,
419 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
420 &img_reqs_size, &img_reqs);
421 ASSERT_XGL_SUCCESS(err);
422 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
423 img_alloc.usage = img_reqs.usage;
424 img_alloc.formatClass = img_reqs.formatClass;
425 img_alloc.samples = img_reqs.samples;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600426 for (uint32_t i = 0; i < num_allocations; i ++) {
Jon Ashburna9ae3832015-01-16 09:37:43 -0700427 mem_alloc.allocationSize = mem_reqs[i].size;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700428
429 /* allocate memory */
430 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
431 ASSERT_XGL_SUCCESS(err);
432
433 /* bind memory */
434 err = xglBindObjectMemory(m_depthStencilImage, i,
435 m_depthStencilMem[i], 0);
436 ASSERT_XGL_SUCCESS(err);
437 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600438
Tony Barbourfa6cac72015-01-16 14:27:35 -0700439 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
440 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
441
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600442 depthStencil.minDepth = 0.f;
443 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700444 depthStencil.stencilBackRef = 0;
445 depthStencil.stencilFrontRef = 0;
446 depthStencil.stencilReadMask = 0xff;
447 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600448
Tony Barbourfa6cac72015-01-16 14:27:35 -0700449 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600450 ASSERT_XGL_SUCCESS( err );
451
452 /* create image view */
453 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
454 view.pNext = NULL;
455 view.image = XGL_NULL_HANDLE;
456 view.mipLevel = 0;
457 view.baseArraySlice = 0;
458 view.arraySize = 1;
459 view.flags = 0;
460 view.image = m_depthStencilImage;
461 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
462 ASSERT_XGL_SUCCESS(err);
463
464 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000465 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600466}
467
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600468struct xgltriangle_vs_uniform {
469 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600470 float mvp[4][4];
471 float position[3][4];
472 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600473};
474
Tony Barbourae442072015-01-12 13:27:11 -0700475void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600476{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700477#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600478 xglDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700479#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600480 // Create identity matrix
481 int i;
482 struct xgltriangle_vs_uniform data;
483
484 glm::mat4 Projection = glm::mat4(1.0f);
485 glm::mat4 View = glm::mat4(1.0f);
486 glm::mat4 Model = glm::mat4(1.0f);
487 glm::mat4 MVP = Projection * View * Model;
488 const int matrixSize = sizeof(MVP);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600489 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600490 memcpy(&data.mvp, &MVP[0][0], matrixSize);
491
492 static const Vertex tri_data[] =
493 {
494 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
495 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
496 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
497 };
498
499 for (i=0; i<3; i++) {
500 data.position[i][0] = tri_data[i].posX;
501 data.position[i][1] = tri_data[i].posY;
502 data.position[i][2] = tri_data[i].posZ;
503 data.position[i][3] = tri_data[i].posW;
504 data.color[i][0] = tri_data[i].r;
505 data.color[i][1] = tri_data[i].g;
506 data.color[i][2] = tri_data[i].b;
507 data.color[i][3] = tri_data[i].a;
508 }
509
Tony Barbourf43b6982014-11-25 13:18:32 -0700510 ASSERT_NO_FATAL_FAILURE(InitState());
511 ASSERT_NO_FATAL_FAILURE(InitViewport());
512
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600513 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700514
515 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
516 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700517
518 XglPipelineObj pipelineobj(m_device);
519 pipelineobj.AddShader(&vs);
520 pipelineobj.AddShader(&ps);
521
522 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800523 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700524 m_memoryRefManager.AddMemoryRef(&constantBuffer);
525
Tony Barbour71ba3612015-01-09 16:12:35 -0700526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700527 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour71ba3612015-01-09 16:12:35 -0700528 XglCommandBufferObj cmdBuffer(m_device);
529 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700530
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600531 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700532
533 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700534#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600535 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700536 pDSDumpDot((char*)"triTest2.dot");
537#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600538
Tony Barbour71ba3612015-01-09 16:12:35 -0700539 // render triangle
540 cmdBuffer.Draw(0, 3, 0, 1);
541
542 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600543 EndCommandBuffer(cmdBuffer);
544
Tony Barbour71ba3612015-01-09 16:12:35 -0700545 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
546
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700547 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour71ba3612015-01-09 16:12:35 -0700548 RecordImage(m_renderTargets[i]);
549
550 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600551 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700552
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700553#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600554 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
555 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
556 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
557 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700558 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600559 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700560 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
561 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
562 for (i=0; i < numObjects; i++) {
563 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);
564 }
565 free(pObjNodeArray);
566#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700567
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600568}
569
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600570TEST_F(XglRenderTest, XGLTriangle_FragColor)
571{
572 static const char *vertShaderText =
573 "#version 140\n"
574 "#extension GL_ARB_separate_shader_objects : enable\n"
575 "#extension GL_ARB_shading_language_420pack : enable\n"
576 "\n"
577 "layout(binding = 0) uniform buf {\n"
578 " mat4 MVP;\n"
579 " vec4 position[3];\n"
580 " vec4 color[3];\n"
581 "} ubuf;\n"
582 "\n"
583 "layout (location = 0) out vec4 outColor;\n"
584 "\n"
585 "void main() \n"
586 "{\n"
587 " outColor = ubuf.color[gl_VertexID];\n"
588 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
589 "}\n";
590
591 static const char *fragShaderText =
592 "#version 140\n"
593 "#extension GL_ARB_separate_shader_objects : enable\n"
594 "#extension GL_ARB_shading_language_420pack : enable\n"
595 "\n"
596 "layout (location = 0) in vec4 inColor;\n"
597 "\n"
598 "void main()\n"
599 "{\n"
600 " gl_FragColor = inColor;\n"
601 "}\n";
602
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600603 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700604 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600605}
606
607TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
608{
609 static const char *vertShaderText =
610 "#version 140\n"
611 "#extension GL_ARB_separate_shader_objects : enable\n"
612 "#extension GL_ARB_shading_language_420pack : enable\n"
613 "\n"
614 "layout(binding = 0) uniform buf {\n"
615 " mat4 MVP;\n"
616 " vec4 position[3];\n"
617 " vec4 color[3];\n"
618 "} ubuf;\n"
619 "\n"
620 "layout (location = 0) out vec4 outColor;\n"
621 "\n"
622 "void main() \n"
623 "{\n"
624 " outColor = ubuf.color[gl_VertexID];\n"
625 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
626 "}\n";
627
628 static const char *fragShaderText =
629 "#version 140\n"
630 "#extension GL_ARB_separate_shader_objects : enable\n"
631 "#extension GL_ARB_shading_language_420pack : enable\n"
632 "\n"
633 "layout (location = 0) in vec4 inColor;\n"
634 "layout (location = 0) out vec4 outColor;\n"
635 "\n"
636 "void main()\n"
637 "{\n"
638 " outColor = inColor;\n"
639 "}\n";
640
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600641 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 -0600642
Tony Barbourae442072015-01-12 13:27:11 -0700643 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600644}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600645#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600646TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700647{
Cody Northropacfb0492015-03-17 15:55:58 -0600648 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700649
650 static const char *vertShaderText =
651 "#version 140\n"
652 "#extension GL_ARB_separate_shader_objects : enable\n"
653 "#extension GL_ARB_shading_language_420pack : enable\n"
654 "\n"
655 "layout(binding = 0) uniform buf {\n"
656 " mat4 MVP;\n"
657 " vec4 position[3];\n"
658 " vec4 color[3];\n"
659 "} ubuf;\n"
660 "\n"
661 "layout (location = 0) out vec4 outColor;\n"
662 "\n"
663 "void main() \n"
664 "{\n"
665 " outColor = ubuf.color[gl_VertexID];\n"
666 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
667 "}\n";
668
669 static const char *fragShaderText =
670 "#version 140\n"
671 "#extension GL_ARB_separate_shader_objects : enable\n"
672 "#extension GL_ARB_shading_language_420pack : enable\n"
673 "\n"
674 "layout (location = 0) in vec4 inColor;\n"
675 "\n"
676 "void main()\n"
677 "{\n"
678 " gl_FragColor = inColor;\n"
679 "}\n";
680
Cody Northropacfb0492015-03-17 15:55:58 -0600681 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700682
Cody Northropacfb0492015-03-17 15:55:58 -0600683 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700684
Tony Barbourae442072015-01-12 13:27:11 -0700685 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700686
Cody Northropacfb0492015-03-17 15:55:58 -0600687 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700688}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600689#endif
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600690TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600691{
692 static const char *vertShaderText =
693 "#version 130\n"
694 "vec2 vertices[3];\n"
695 "void main() {\n"
696 " vertices[0] = vec2(-1.0, -1.0);\n"
697 " vertices[1] = vec2( 1.0, -1.0);\n"
698 " vertices[2] = vec2( 0.0, 1.0);\n"
699 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
700 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600701
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600702 static const char *fragShaderText =
703 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600704 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600705 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600706 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600707
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600708 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
709
Tony Barbourae442072015-01-12 13:27:11 -0700710 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600711}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600712#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600713TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700714{
Cody Northropacfb0492015-03-17 15:55:58 -0600715 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700716
717 static const char *vertShaderText =
718 "#version 130\n"
719 "vec2 vertices[3];\n"
720 "void main() {\n"
721 " vertices[0] = vec2(-1.0, -1.0);\n"
722 " vertices[1] = vec2( 1.0, -1.0);\n"
723 " vertices[2] = vec2( 0.0, 1.0);\n"
724 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
725 "}\n";
726
727 static const char *fragShaderText =
728 "#version 130\n"
729 "void main() {\n"
730 " gl_FragColor = vec4(0,1,0,1);\n"
731 "}\n";
732
Cody Northropacfb0492015-03-17 15:55:58 -0600733 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700734
Cody Northropacfb0492015-03-17 15:55:58 -0600735 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700736 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600737 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700738}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600739#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700740TEST_F(XglRenderTest, YellowTriangle)
741{
742 static const char *vertShaderText =
743 "#version 130\n"
744 "void main() {\n"
745 " vec2 vertices[3];"
746 " vertices[0] = vec2(-0.5, -0.5);\n"
747 " vertices[1] = vec2( 0.5, -0.5);\n"
748 " vertices[2] = vec2( 0.5, 0.5);\n"
749 " vec4 colors[3];\n"
750 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
751 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
752 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
753 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
754 "}\n";
755
756 static const char *fragShaderText =
757 "#version 130\n"
758 "void main() {\n"
759 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
760 "}\n";
761
Tony Barbourae442072015-01-12 13:27:11 -0700762 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700763}
764
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600765TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600766{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600767 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700768 "#version 130\n"
769 //XYZ1( -1, -1, -1 )
770 "in vec4 pos;\n"
771 //XYZ1( 0.f, 0.f, 0.f )
772 "in vec4 inColor;\n"
773 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600774 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600775 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600776 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600777 "}\n";
778
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600779
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600780 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700781 "#version 140\n"
782 "#extension GL_ARB_separate_shader_objects : enable\n"
783 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700784 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700785 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600786 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700787 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600788 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600789
Tony Barbourf43b6982014-11-25 13:18:32 -0700790
791
792 ASSERT_NO_FATAL_FAILURE(InitState());
793 ASSERT_NO_FATAL_FAILURE(InitViewport());
794
795 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000796 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700797
798 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
799 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
800
801 XglPipelineObj pipelineobj(m_device);
802 pipelineobj.AddShader(&vs);
803 pipelineobj.AddShader(&ps);
804
805 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800806 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700807
Mark Lobodzinski15427102015-02-18 16:38:17 -0600808 m_memoryRefManager.AddMemoryRef(&meshBuffer);
809
Tony Barbourf43b6982014-11-25 13:18:32 -0700810 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
811 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
812 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
813 };
814
815 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
816 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700817 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700818 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
819 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700820 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700821 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
822
823 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
824 pipelineobj.AddVertexInputBindings(&vi_binding,1);
825 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
826
Tony Barboure4ed9942015-01-09 10:06:53 -0700827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700828 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700829 XglCommandBufferObj cmdBuffer(m_device);
830 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700831
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600832 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
833
Tony Barboure4ed9942015-01-09 10:06:53 -0700834 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
835
Tony Barboure4ed9942015-01-09 10:06:53 -0700836 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
837
838 // render two triangles
839 cmdBuffer.Draw(0, 6, 0, 1);
840
841 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600842 EndCommandBuffer(cmdBuffer);
843
Mark Lobodzinski15427102015-02-18 16:38:17 -0600844 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700845
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700846 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -0700847 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600848}
849
Chia-I Wue09d1a72014-12-05 10:32:23 +0800850TEST_F(XglRenderTest, TriangleMRT)
851{
852 static const char *vertShaderText =
853 "#version 130\n"
854 "in vec4 pos;\n"
855 "void main() {\n"
856 " gl_Position = pos;\n"
857 "}\n";
858
859 static const char *fragShaderText =
860 "#version 130\n"
861 "void main() {\n"
862 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
863 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
864 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600865 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800866 { -1.0f, -1.0f },
867 { 1.0f, -1.0f },
868 { -1.0f, 1.0f }
869 };
870
871 ASSERT_NO_FATAL_FAILURE(InitState());
872 ASSERT_NO_FATAL_FAILURE(InitViewport());
873
874 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000875 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876
877 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
878 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
879
880 XglPipelineObj pipelineobj(m_device);
881 pipelineobj.AddShader(&vs);
882 pipelineobj.AddShader(&ps);
883
884 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
885 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
886 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
887 };
888
889 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
890 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700891 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wue09d1a72014-12-05 10:32:23 +0800892 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
893
894 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
895 pipelineobj.AddVertexInputBindings(&vi_binding,1);
896 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
897
898 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600899 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800900
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
902 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600903 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800904
905 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
906 att.blendEnable = XGL_FALSE;
907 att.format = m_render_target_fmt;
908 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700909 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800910
Tony Barbour5ed79702015-01-07 14:31:52 -0700911 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700912
Tony Barbour5ed79702015-01-07 14:31:52 -0700913 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
914 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700915
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600916 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700917
Tony Barboure4ed9942015-01-09 10:06:53 -0700918 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
919
Tony Barbour5ed79702015-01-07 14:31:52 -0700920 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700921#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600922 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700923 pDSDumpDot((char*)"triTest2.dot");
924#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600925
Tony Barbour5ed79702015-01-07 14:31:52 -0700926 // render triangle
927 cmdBuffer.Draw(0, 3, 0, 1);
928
929 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600930 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600931 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700932
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700933 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour5ed79702015-01-07 14:31:52 -0700934 RecordImage(m_renderTargets[i]);
935
Chia-I Wue09d1a72014-12-05 10:32:23 +0800936}
937
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700938TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
939{
940 static const char *vertShaderText =
941 "#version 140\n"
942 "#extension GL_ARB_separate_shader_objects : enable\n"
943 "#extension GL_ARB_shading_language_420pack : enable\n"
944 "layout(location = 0) in vec4 pos;\n"
945 "layout(location = 1) in vec4 inColor;\n"
946 "layout(location = 0) out vec4 outColor;\n"
947 "void main() {\n"
948 " outColor = inColor;\n"
949 " gl_Position = pos;\n"
950 "}\n";
951
952
953 static const char *fragShaderText =
954 "#version 140\n"
955 "#extension GL_ARB_separate_shader_objects : enable\n"
956 "#extension GL_ARB_shading_language_420pack : enable\n"
957 "layout(location = 0) in vec4 color;\n"
958 "void main() {\n"
959 " gl_FragColor = color;\n"
960 "}\n";
961
962 const Vertex g_vbData[] =
963 {
964 // first tri
965 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
966 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
967 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
968
969 // second tri
970 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
971 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
972 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
973 };
974
975 const uint16_t g_idxData[6] = {
976 0, 1, 2,
977 3, 4, 5,
978 };
979
980 ASSERT_NO_FATAL_FAILURE(InitState());
981 ASSERT_NO_FATAL_FAILURE(InitViewport());
982
983 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000984 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985
986 XglIndexBufferObj indexBuffer(m_device);
987 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600988 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700989
990 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
991 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
992
993 XglPipelineObj pipelineobj(m_device);
994 pipelineobj.AddShader(&vs);
995 pipelineobj.AddShader(&ps);
996
997 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600998 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
999 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
1000
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001001
Mark Lobodzinski15427102015-02-18 16:38:17 -06001002 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1003 m_memoryRefManager.AddMemoryRef(&indexBuffer);
1004
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001005 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1006 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1007 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1008 };
1009
1010 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1011 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001012 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001013 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1014 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001015 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001016 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1017
1018 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1019 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001020
1021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001022 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001023 XglCommandBufferObj cmdBuffer(m_device);
1024 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001025 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001026
1027 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001028
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001029#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001030 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -07001031 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001032#endif
Tony Barbour02472db2015-01-08 17:08:28 -07001033
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001034 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1035 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001036
1037 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001038 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001039
1040 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001041 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001042 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001043
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001044 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001045 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001046
1047}
1048
GregF6bef1212014-12-02 15:41:44 -07001049TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1050{
1051 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001052
GregF6bef1212014-12-02 15:41:44 -07001053 static const char *vertShaderText =
1054 "#version 140\n"
1055 "#extension GL_ARB_separate_shader_objects : enable\n"
1056 "#extension GL_ARB_shading_language_420pack : enable\n"
1057 "layout (location = 0) in vec4 pos;\n"
1058 "layout (location = 0) out vec4 outColor;\n"
1059 "layout (location = 1) out vec4 outColor2;\n"
1060 "void main() {\n"
1061 " gl_Position = pos;\n"
1062 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1063 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1064 "}\n";
1065
1066 static const char *fragShaderText =
1067 //"#version 140\n"
1068 "#version 330\n"
1069 "#extension GL_ARB_separate_shader_objects : enable\n"
1070 "#extension GL_ARB_shading_language_420pack : enable\n"
1071 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1072 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1073 "layout (location = 0) in vec4 color;\n"
1074 "layout (location = 1) in vec4 color2;\n"
1075 "void main() {\n"
1076 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1077 " float dist_squared = dot(pos, pos);\n"
1078 " gl_FragColor = (dist_squared < 400.0)\n"
1079 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1080 " : color2;\n"
1081 "}\n";
1082
1083 ASSERT_NO_FATAL_FAILURE(InitState());
1084 ASSERT_NO_FATAL_FAILURE(InitViewport());
1085
1086 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001087 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001088
1089 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1090 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1091
1092 XglPipelineObj pipelineobj(m_device);
1093 pipelineobj.AddShader(&vs);
1094 pipelineobj.AddShader(&ps);
1095
1096 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001097 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001098
Mark Lobodzinski15427102015-02-18 16:38:17 -06001099 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1100
GregF6bef1212014-12-02 15:41:44 -07001101 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1102 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1103 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1104 };
1105
1106 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1107 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001108 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001109 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1110 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001111 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001112 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1113
1114 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1115 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1116 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1117
Tony Barbourdd4c9642015-01-09 12:55:14 -07001118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001119 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001120 XglCommandBufferObj cmdBuffer(m_device);
1121 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1122
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001123 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001124
1125 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1126
1127 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1128#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001129 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001130 pDSDumpDot((char*)"triTest2.dot");
1131#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001132
Tony Barbourdd4c9642015-01-09 12:55:14 -07001133 // render triangle
1134 cmdBuffer.Draw(0, 6, 0, 1);
1135
1136 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001137 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001138 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001140 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001141 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001142
1143}
1144
1145TEST_F(XglRenderTest, RedCirclesonBlue)
1146{
1147 // This tests that we correctly handle unread fragment inputs
1148
1149 static const char *vertShaderText =
1150 "#version 140\n"
1151 "#extension GL_ARB_separate_shader_objects : enable\n"
1152 "#extension GL_ARB_shading_language_420pack : enable\n"
1153 "layout (location = 0) in vec4 pos;\n"
1154 "layout (location = 0) out vec4 outColor;\n"
1155 "layout (location = 1) out vec4 outColor2;\n"
1156 "void main() {\n"
1157 " gl_Position = pos;\n"
1158 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1159 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1160 "}\n";
1161
1162 static const char *fragShaderText =
1163 //"#version 140\n"
1164 "#version 330\n"
1165 "#extension GL_ARB_separate_shader_objects : enable\n"
1166 "#extension GL_ARB_shading_language_420pack : enable\n"
1167 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1168 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1169 "layout (location = 0) in vec4 color;\n"
1170 "layout (location = 1) in vec4 color2;\n"
1171 "void main() {\n"
1172 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1173 " float dist_squared = dot(pos, pos);\n"
1174 " gl_FragColor = (dist_squared < 400.0)\n"
1175 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1176 " : color2;\n"
1177 "}\n";
1178
1179 ASSERT_NO_FATAL_FAILURE(InitState());
1180 ASSERT_NO_FATAL_FAILURE(InitViewport());
1181
1182 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001183 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001184
1185 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1186 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1187
1188 XglPipelineObj pipelineobj(m_device);
1189 pipelineobj.AddShader(&vs);
1190 pipelineobj.AddShader(&ps);
1191
1192 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001193 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001194
Mark Lobodzinski15427102015-02-18 16:38:17 -06001195 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1196
GregF6bef1212014-12-02 15:41:44 -07001197 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1198 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1199 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1200 };
1201
1202 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1203 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001204 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001205 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1206 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001207 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001208 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1209
1210 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1211 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1212 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1213
Tony Barbourdd4c9642015-01-09 12:55:14 -07001214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001215 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001216 XglCommandBufferObj cmdBuffer(m_device);
1217 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1218
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001219 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001220
1221 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1222
1223 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1224#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001225 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001226 pDSDumpDot((char*)"triTest2.dot");
1227#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001228 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001229 cmdBuffer.Draw(0, 6, 0, 1);
1230
1231 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001232 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001233 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001234
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001235 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001236 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001237
1238}
1239
1240TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1241{
1242 // This tests reading gl_ClipDistance from FS
1243
1244 static const char *vertShaderText =
1245 "#version 330\n"
1246 "#extension GL_ARB_separate_shader_objects : enable\n"
1247 "#extension GL_ARB_shading_language_420pack : enable\n"
1248 "out gl_PerVertex {\n"
1249 " vec4 gl_Position;\n"
1250 " float gl_ClipDistance[1];\n"
1251 "};\n"
1252 "layout (location = 0) in vec4 pos;\n"
1253 "layout (location = 0) out vec4 outColor;\n"
1254 "layout (location = 1) out vec4 outColor2;\n"
1255 "void main() {\n"
1256 " gl_Position = pos;\n"
1257 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1258 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1259 " float dists[3];\n"
1260 " dists[0] = 0.0;\n"
1261 " dists[1] = 1.0;\n"
1262 " dists[2] = 1.0;\n"
1263 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1264 "}\n";
1265
1266
1267 static const char *fragShaderText =
1268 //"#version 140\n"
1269 "#version 330\n"
1270 "#extension GL_ARB_separate_shader_objects : enable\n"
1271 "#extension GL_ARB_shading_language_420pack : enable\n"
1272 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1273 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1274 "layout (location = 0) in vec4 color;\n"
1275 "layout (location = 1) in vec4 color2;\n"
1276 "void main() {\n"
1277 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1278 " float dist_squared = dot(pos, pos);\n"
1279 " gl_FragColor = (dist_squared < 400.0)\n"
1280 " ? color * gl_ClipDistance[0]\n"
1281 " : color2;\n"
1282 "}\n";
1283
1284 ASSERT_NO_FATAL_FAILURE(InitState());
1285 ASSERT_NO_FATAL_FAILURE(InitViewport());
1286
1287 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001288 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001289
1290 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1291 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1292
1293 XglPipelineObj pipelineobj(m_device);
1294 pipelineobj.AddShader(&vs);
1295 pipelineobj.AddShader(&ps);
1296
1297 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001298 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001299
Mark Lobodzinski15427102015-02-18 16:38:17 -06001300 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1301
GregF6bef1212014-12-02 15:41:44 -07001302 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1303 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1304 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1305 };
1306
1307 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1308 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001309 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001310 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1311 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001312 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001313 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1314
1315 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1316 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1317 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1318
Tony Barbourdd4c9642015-01-09 12:55:14 -07001319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001320 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001321 XglCommandBufferObj cmdBuffer(m_device);
1322 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001323
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001324 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001325
1326 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1327
1328 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1329#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001330 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001331 pDSDumpDot((char*)"triTest2.dot");
1332#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001333
1334 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001335 cmdBuffer.Draw(0, 6, 0, 1);
1336
1337 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001338 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001339 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001341 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001343}
Tony Barbourf43b6982014-11-25 13:18:32 -07001344
GregF7a23c792014-12-02 17:19:34 -07001345TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1346{
1347 static const char *vertShaderText =
1348 "#version 140\n"
1349 "#extension GL_ARB_separate_shader_objects : enable\n"
1350 "#extension GL_ARB_shading_language_420pack : enable\n"
1351 "layout (location = 0) in vec4 pos;\n"
1352 "layout (location = 0) out vec4 outColor;\n"
1353 "layout (location = 1) out vec4 outColor2;\n"
1354 "void main() {\n"
1355 " gl_Position = pos;\n"
1356 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1357 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1358 "}\n";
1359
1360
1361 static const char *fragShaderText =
1362 //"#version 140\n"
1363 "#version 330\n"
1364 "#extension GL_ARB_separate_shader_objects : enable\n"
1365 "#extension GL_ARB_shading_language_420pack : enable\n"
1366 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1367 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1368 "layout (location = 0) in vec4 color;\n"
1369 "layout (location = 1) in vec4 color2;\n"
1370 "void main() {\n"
1371 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1372 " float dist_squared = dot(pos, pos);\n"
1373 " if (dist_squared < 100.0)\n"
1374 " discard;\n"
1375 " gl_FragColor = (dist_squared < 400.0)\n"
1376 " ? color\n"
1377 " : color2;\n"
1378 "}\n";
1379
1380 ASSERT_NO_FATAL_FAILURE(InitState());
1381 ASSERT_NO_FATAL_FAILURE(InitViewport());
1382
1383 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001384 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001385
1386 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1387 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1388
1389 XglPipelineObj pipelineobj(m_device);
1390 pipelineobj.AddShader(&vs);
1391 pipelineobj.AddShader(&ps);
1392
1393 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001394 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001395
Mark Lobodzinski15427102015-02-18 16:38:17 -06001396 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1397
GregF7a23c792014-12-02 17:19:34 -07001398 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1399 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1400 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1401 };
1402
1403 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1404 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001405 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001406 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1407 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001408 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001409 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1410
1411 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1412 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1413 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1414
Tony Barbourdd4c9642015-01-09 12:55:14 -07001415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001416 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001417 XglCommandBufferObj cmdBuffer(m_device);
1418 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1419
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001420 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001421
1422 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1423
1424 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1425#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001426 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427 pDSDumpDot((char*)"triTest2.dot");
1428#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001429
1430 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001431 cmdBuffer.Draw(0, 6, 0, 1);
1432
1433 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001434 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001435 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001436
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001437 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001438 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001439
1440}
1441
1442
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001443TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001444{
1445 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001446 "#version 140\n"
1447 "#extension GL_ARB_separate_shader_objects : enable\n"
1448 "#extension GL_ARB_shading_language_420pack : enable\n"
1449 "\n"
1450 "layout(binding = 0) uniform buf {\n"
1451 " mat4 MVP;\n"
1452 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001453 "void main() {\n"
1454 " vec2 vertices[3];"
1455 " vertices[0] = vec2(-0.5, -0.5);\n"
1456 " vertices[1] = vec2( 0.5, -0.5);\n"
1457 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001458 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001459 "}\n";
1460
1461 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001462 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001463 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001464 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001465 "}\n";
1466
Tony Barbourf43b6982014-11-25 13:18:32 -07001467 ASSERT_NO_FATAL_FAILURE(InitState());
1468 ASSERT_NO_FATAL_FAILURE(InitViewport());
1469
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001470 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001471 glm::mat4 Projection = glm::mat4(1.0f);
1472 glm::mat4 View = glm::mat4(1.0f);
1473 glm::mat4 Model = glm::mat4(1.0f);
1474 glm::mat4 MVP = Projection * View * Model;
1475 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1476
Tony Barbourf43b6982014-11-25 13:18:32 -07001477 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1478 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1479 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001480
Tony Barbourf43b6982014-11-25 13:18:32 -07001481 XglPipelineObj pipelineobj(m_device);
1482 pipelineobj.AddShader(&vs);
1483 pipelineobj.AddShader(&ps);
1484
1485 // Create descriptor set and attach the constant buffer to it
1486 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001487 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001488
1489 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1490
Tony Barbourdd4c9642015-01-09 12:55:14 -07001491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001492 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001493 XglCommandBufferObj cmdBuffer(m_device);
1494 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001495
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001496 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001497
1498 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1499
1500 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1501#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001502 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001503 pDSDumpDot((char*)"triTest2.dot");
1504#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001505
1506 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507 cmdBuffer.Draw(0, 6, 0, 1);
1508
1509 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001510 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001511 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1512
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001513 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001514 RecordImage(m_renderTargets[i]);
1515
1516 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001517}
1518
Tony Barbourf43b6982014-11-25 13:18:32 -07001519TEST_F(XglRenderTest, MixTriangle)
1520{
1521 // This tests location applied to varyings. Notice that we have switched foo
1522 // and bar in the FS. The triangle should be blended with red, green and blue
1523 // corners.
1524 static const char *vertShaderText =
1525 "#version 140\n"
1526 "#extension GL_ARB_separate_shader_objects : enable\n"
1527 "#extension GL_ARB_shading_language_420pack : enable\n"
1528 "layout (location=0) out vec4 bar;\n"
1529 "layout (location=1) out vec4 foo;\n"
1530 "layout (location=2) out float scale;\n"
1531 "vec2 vertices[3];\n"
1532 "void main() {\n"
1533 " vertices[0] = vec2(-1.0, -1.0);\n"
1534 " vertices[1] = vec2( 1.0, -1.0);\n"
1535 " vertices[2] = vec2( 0.0, 1.0);\n"
1536 "vec4 colors[3];\n"
1537 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1538 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1539 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1540 " foo = colors[gl_VertexID % 3];\n"
1541 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1542 " scale = 1.0;\n"
1543 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1544 "}\n";
1545
1546 static const char *fragShaderText =
1547 "#version 140\n"
1548 "#extension GL_ARB_separate_shader_objects : enable\n"
1549 "#extension GL_ARB_shading_language_420pack : enable\n"
1550 "layout (location = 1) in vec4 bar;\n"
1551 "layout (location = 0) in vec4 foo;\n"
1552 "layout (location = 2) in float scale;\n"
1553 "void main() {\n"
1554 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1555 "}\n";
1556
1557 ASSERT_NO_FATAL_FAILURE(InitState());
1558 ASSERT_NO_FATAL_FAILURE(InitViewport());
1559
1560 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1561 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1562
1563 XglPipelineObj pipelineobj(m_device);
1564 pipelineobj.AddShader(&vs);
1565 pipelineobj.AddShader(&ps);
1566
1567 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001568 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001569
Tony Barbourdd4c9642015-01-09 12:55:14 -07001570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001571 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572 XglCommandBufferObj cmdBuffer(m_device);
1573 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1574
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001575 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001576
1577 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1578
1579#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001580 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001581 pDSDumpDot((char*)"triTest2.dot");
1582#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001583
Tony Barbourdd4c9642015-01-09 12:55:14 -07001584 // render triangle
1585 cmdBuffer.Draw(0, 3, 0, 1);
1586
1587 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001588 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001589 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001590
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001591 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001593}
1594
1595TEST_F(XglRenderTest, TriVertFetchAndVertID)
1596{
1597 // This tests that attributes work in the presence of gl_VertexID
1598
1599 static const char *vertShaderText =
1600 "#version 140\n"
1601 "#extension GL_ARB_separate_shader_objects : enable\n"
1602 "#extension GL_ARB_shading_language_420pack : enable\n"
1603 //XYZ1( -1, -1, -1 )
1604 "layout (location = 0) in vec4 pos;\n"
1605 //XYZ1( 0.f, 0.f, 0.f )
1606 "layout (location = 1) in vec4 inColor;\n"
1607 "layout (location = 0) out vec4 outColor;\n"
1608 "void main() {\n"
1609 " outColor = inColor;\n"
1610 " vec4 vertices[3];"
1611 " vertices[gl_VertexID % 3] = pos;\n"
1612 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1613 "}\n";
1614
1615
1616 static const char *fragShaderText =
1617 "#version 140\n"
1618 "#extension GL_ARB_separate_shader_objects : enable\n"
1619 "#extension GL_ARB_shading_language_420pack : enable\n"
1620 "layout (location = 0) in vec4 color;\n"
1621 "void main() {\n"
1622 " gl_FragColor = color;\n"
1623 "}\n";
1624
1625 ASSERT_NO_FATAL_FAILURE(InitState());
1626 ASSERT_NO_FATAL_FAILURE(InitViewport());
1627
1628 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001629 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001630
1631 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1632 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1633
1634 XglPipelineObj pipelineobj(m_device);
1635 pipelineobj.AddShader(&vs);
1636 pipelineobj.AddShader(&ps);
1637
1638 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001639 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001640
Mark Lobodzinski15427102015-02-18 16:38:17 -06001641 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1642
Tony Barbourf43b6982014-11-25 13:18:32 -07001643 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1644 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1645 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1646 };
1647
1648 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1649 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001650 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001651 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1652 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001653 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001654 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1655
1656 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1657 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1658 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1659
Tony Barbourdd4c9642015-01-09 12:55:14 -07001660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001661 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001662 XglCommandBufferObj cmdBuffer(m_device);
1663 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1664
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001665 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001666
1667 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1668
1669 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1670#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001671 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001672 pDSDumpDot((char*)"triTest2.dot");
1673#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001674
1675 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001676 cmdBuffer.Draw(0, 6, 0, 1);
1677
1678 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001679 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001680 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001681
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001682 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001683 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001684}
1685
1686TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1687{
1688 // This tests that attributes work in the presence of gl_VertexID
1689 // and a dead attribute in position 0. Draws a triangle with yellow,
1690 // red and green corners, starting at top and going clockwise.
1691
1692 static const char *vertShaderText =
1693 "#version 140\n"
1694 "#extension GL_ARB_separate_shader_objects : enable\n"
1695 "#extension GL_ARB_shading_language_420pack : enable\n"
1696 //XYZ1( -1, -1, -1 )
1697 "layout (location = 0) in vec4 pos;\n"
1698 //XYZ1( 0.f, 0.f, 0.f )
1699 "layout (location = 1) in vec4 inColor;\n"
1700 "layout (location = 0) out vec4 outColor;\n"
1701 "void main() {\n"
1702 " outColor = inColor;\n"
1703 " vec2 vertices[3];"
1704 " vertices[0] = vec2(-1.0, -1.0);\n"
1705 " vertices[1] = vec2( 1.0, -1.0);\n"
1706 " vertices[2] = vec2( 0.0, 1.0);\n"
1707 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1708 "}\n";
1709
1710
1711 static const char *fragShaderText =
1712 "#version 140\n"
1713 "#extension GL_ARB_separate_shader_objects : enable\n"
1714 "#extension GL_ARB_shading_language_420pack : enable\n"
1715 "layout (location = 0) in vec4 color;\n"
1716 "void main() {\n"
1717 " gl_FragColor = color;\n"
1718 "}\n";
1719
1720 ASSERT_NO_FATAL_FAILURE(InitState());
1721 ASSERT_NO_FATAL_FAILURE(InitViewport());
1722
1723 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001724 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001725
1726 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1727 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1728
1729 XglPipelineObj pipelineobj(m_device);
1730 pipelineobj.AddShader(&vs);
1731 pipelineobj.AddShader(&ps);
1732
1733 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001734 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001735
Mark Lobodzinski15427102015-02-18 16:38:17 -06001736 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1737
Tony Barbourf43b6982014-11-25 13:18:32 -07001738 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1739 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1740 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1741 };
1742
1743 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1744 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001745 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001746 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1747 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001748 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001749 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1750
1751 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1752 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1753 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1754
Tony Barbourdd4c9642015-01-09 12:55:14 -07001755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001756 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001757 XglCommandBufferObj cmdBuffer(m_device);
1758 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001759
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001760 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001761
1762 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1763
1764 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1765#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001766 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001767 pDSDumpDot((char*)"triTest2.dot");
1768#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001769
1770 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001771 cmdBuffer.Draw(0, 6, 0, 1);
1772
1773 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001774 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001775 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001776
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001777 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001778 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001779}
1780
1781TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001782{
1783 static const char *vertShaderText =
1784 "#version 140\n"
1785 "layout (std140) uniform bufferVals {\n"
1786 " mat4 mvp;\n"
1787 "} myBufferVals;\n"
1788 "in vec4 pos;\n"
1789 "in vec4 inColor;\n"
1790 "out vec4 outColor;\n"
1791 "void main() {\n"
1792 " outColor = inColor;\n"
1793 " gl_Position = myBufferVals.mvp * pos;\n"
1794 "}\n";
1795
1796 static const char *fragShaderText =
1797 "#version 130\n"
1798 "in vec4 color;\n"
1799 "void main() {\n"
1800 " gl_FragColor = color;\n"
1801 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001802 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001803
Tony Barbourf43b6982014-11-25 13:18:32 -07001804 glm::mat4 View = glm::lookAt(
1805 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1806 glm::vec3(0,0,0), // and looks at the origin
1807 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1808 );
1809
1810 glm::mat4 Model = glm::mat4(1.0f);
1811
1812 glm::mat4 MVP = Projection * View * Model;
1813
1814 ASSERT_NO_FATAL_FAILURE(InitState());
1815 ASSERT_NO_FATAL_FAILURE(InitViewport());
1816 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1817
1818 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1819 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1820
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001821 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001822
1823 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1824 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1825 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1826
Tony Barbourf43b6982014-11-25 13:18:32 -07001827 XglPipelineObj pipelineobj(m_device);
1828 pipelineobj.AddShader(&vs);
1829 pipelineobj.AddShader(&ps);
1830
Tony Barbourfa6cac72015-01-16 14:27:35 -07001831 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1832 ds_state.depthTestEnable = XGL_TRUE;
1833 ds_state.depthWriteEnable = XGL_TRUE;
1834 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1835 ds_state.depthBoundsEnable = XGL_FALSE;
1836 ds_state.stencilTestEnable = XGL_FALSE;
1837 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1838 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1839 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1840 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001841 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001842 ds_state.front = ds_state.back;
1843 pipelineobj.SetDepthStencil(&ds_state);
1844
Tony Barbourf43b6982014-11-25 13:18:32 -07001845 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001846 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001847
1848 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1849 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001850 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07001851
1852 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1853 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1854 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1855 };
1856
1857 // this is the current description of g_vbData
1858 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1859 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001860 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001861 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1862 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001863 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001864 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1865
1866 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1867 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1868 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1869
Tony Barboure4ed9942015-01-09 10:06:53 -07001870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001871 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -07001872 XglCommandBufferObj cmdBuffer(m_device);
1873 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001874
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001875 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001876 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001877
Tony Barboure4ed9942015-01-09 10:06:53 -07001878 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1879#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001880 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001881 pDSDumpDot((char*)"triTest2.dot");
1882#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001883
1884 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001885 cmdBuffer.Draw(0, 36, 0, 1);
1886
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001887
Tony Barboure4ed9942015-01-09 10:06:53 -07001888 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001889 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001890 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001891
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001892 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001893 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001894}
1895
Tony Barbourf43b6982014-11-25 13:18:32 -07001896TEST_F(XglRenderTest, VSTexture)
1897{
1898 // The expected result from this test is a green and red triangle;
1899 // one red vertex on the left, two green vertices on the right.
1900 static const char *vertShaderText =
1901 "#version 130\n"
1902 "out vec4 texColor;\n"
1903 "uniform sampler2D surface;\n"
1904 "void main() {\n"
1905 " vec2 vertices[3];"
1906 " vertices[0] = vec2(-0.5, -0.5);\n"
1907 " vertices[1] = vec2( 0.5, -0.5);\n"
1908 " vertices[2] = vec2( 0.5, 0.5);\n"
1909 " vec2 positions[3];"
1910 " positions[0] = vec2( 0.0, 0.0);\n"
1911 " positions[1] = vec2( 0.25, 0.1);\n"
1912 " positions[2] = vec2( 0.1, 0.25);\n"
1913 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1914 " texColor = textureLod(surface, samplePos, 0.0);\n"
1915 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1916 "}\n";
1917
1918 static const char *fragShaderText =
1919 "#version 130\n"
1920 "in vec4 texColor;\n"
1921 "void main() {\n"
1922 " gl_FragColor = texColor;\n"
1923 "}\n";
1924
1925 ASSERT_NO_FATAL_FAILURE(InitState());
1926 ASSERT_NO_FATAL_FAILURE(InitViewport());
1927
1928 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1929 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1930 XglSamplerObj sampler(m_device);
1931 XglTextureObj texture(m_device);
1932
Tony Barbourf43b6982014-11-25 13:18:32 -07001933 XglPipelineObj pipelineobj(m_device);
1934 pipelineobj.AddShader(&vs);
1935 pipelineobj.AddShader(&ps);
1936
1937 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001938 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001939
1940 m_memoryRefManager.AddMemoryRef(&texture);
1941
Tony Barbourdd4c9642015-01-09 12:55:14 -07001942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001943 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001944 XglCommandBufferObj cmdBuffer(m_device);
1945 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001946
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001947 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001948
1949 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1950
1951#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001952 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001953 pDSDumpDot((char*)"triTest2.dot");
1954#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001955
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956 // render triangle
1957 cmdBuffer.Draw(0, 3, 0, 1);
1958
1959 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001960 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001961 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001962
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001963 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001964 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001965}
1966TEST_F(XglRenderTest, TexturedTriangle)
1967{
1968 // The expected result from this test is a red and green checkered triangle
1969 static const char *vertShaderText =
1970 "#version 140\n"
1971 "#extension GL_ARB_separate_shader_objects : enable\n"
1972 "#extension GL_ARB_shading_language_420pack : enable\n"
1973 "layout (location = 0) out vec2 samplePos;\n"
1974 "void main() {\n"
1975 " vec2 vertices[3];"
1976 " vertices[0] = vec2(-0.5, -0.5);\n"
1977 " vertices[1] = vec2( 0.5, -0.5);\n"
1978 " vertices[2] = vec2( 0.5, 0.5);\n"
1979 " vec2 positions[3];"
1980 " positions[0] = vec2( 0.0, 0.0);\n"
1981 " positions[1] = vec2( 1.0, 0.0);\n"
1982 " positions[2] = vec2( 1.0, 1.0);\n"
1983 " samplePos = positions[gl_VertexID % 3];\n"
1984 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1985 "}\n";
1986
1987 static const char *fragShaderText =
1988 "#version 140\n"
1989 "#extension GL_ARB_separate_shader_objects : enable\n"
1990 "#extension GL_ARB_shading_language_420pack : enable\n"
1991 "layout (location = 0) in vec2 samplePos;\n"
1992 "layout (binding = 0) uniform sampler2D surface;\n"
1993 "layout (location=0) out vec4 outColor;\n"
1994 "void main() {\n"
1995 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1996 " outColor = texColor;\n"
1997 "}\n";
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());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002017 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002018 XglCommandBufferObj cmdBuffer(m_device);
2019 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2020
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002021 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002022
2023 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2024
2025#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002026 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002027 pDSDumpDot((char*)"triTest2.dot");
2028#endif
2029 // render triangle
2030 cmdBuffer.Draw(0, 3, 0, 1);
2031
2032 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002034 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002035
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002036 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002037 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002038}
2039TEST_F(XglRenderTest, TexturedTriangleClip)
2040{
2041 // The expected result from this test is a red and green checkered triangle
2042 static const char *vertShaderText =
2043 "#version 330\n"
2044 "#extension GL_ARB_separate_shader_objects : enable\n"
2045 "#extension GL_ARB_shading_language_420pack : enable\n"
2046 "layout (location = 0) out vec2 samplePos;\n"
2047 "out gl_PerVertex {\n"
2048 " vec4 gl_Position;\n"
2049 " float gl_ClipDistance[1];\n"
2050 "};\n"
2051 "void main() {\n"
2052 " vec2 vertices[3];"
2053 " vertices[0] = vec2(-0.5, -0.5);\n"
2054 " vertices[1] = vec2( 0.5, -0.5);\n"
2055 " vertices[2] = vec2( 0.5, 0.5);\n"
2056 " vec2 positions[3];"
2057 " positions[0] = vec2( 0.0, 0.0);\n"
2058 " positions[1] = vec2( 1.0, 0.0);\n"
2059 " positions[2] = vec2( 1.0, 1.0);\n"
2060 " float dists[3];\n"
2061 " dists[0] = 1.0;\n"
2062 " dists[1] = 1.0;\n"
2063 " dists[2] = -1.0;\n"
2064 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2065 " samplePos = positions[gl_VertexID % 3];\n"
2066 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2067 "}\n";
2068
2069 static const char *fragShaderText =
2070 "#version 140\n"
2071 "#extension GL_ARB_separate_shader_objects : enable\n"
2072 "#extension GL_ARB_shading_language_420pack : enable\n"
2073 "layout (location = 0) in vec2 samplePos;\n"
2074 "layout (binding = 0) uniform sampler2D surface;\n"
2075 "layout (location=0) out vec4 outColor;\n"
2076 "void main() {\n"
2077 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2078 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2079 " outColor = texColor;\n"
2080 "}\n";
2081
2082
2083 ASSERT_NO_FATAL_FAILURE(InitState());
2084 ASSERT_NO_FATAL_FAILURE(InitViewport());
2085
2086 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2087 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2088 XglSamplerObj sampler(m_device);
2089 XglTextureObj texture(m_device);
2090
Tony Barbourf43b6982014-11-25 13:18:32 -07002091 XglPipelineObj pipelineobj(m_device);
2092 pipelineobj.AddShader(&vs);
2093 pipelineobj.AddShader(&ps);
2094
2095 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002096 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002097
2098 m_memoryRefManager.AddMemoryRef(&texture);
2099
Tony Barbourdd4c9642015-01-09 12:55:14 -07002100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002101 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002102 XglCommandBufferObj cmdBuffer(m_device);
2103 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2104
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002105 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002106
2107 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2108
2109#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002110 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111 pDSDumpDot((char*)"triTest2.dot");
2112#endif
2113 // render triangle
2114 cmdBuffer.Draw(0, 3, 0, 1);
2115
2116 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002117 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002118 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002120 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002121 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002122}
2123TEST_F(XglRenderTest, FSTriangle)
2124{
2125 // The expected result from this test is a red and green checkered triangle
2126 static const char *vertShaderText =
2127 "#version 140\n"
2128 "#extension GL_ARB_separate_shader_objects : enable\n"
2129 "#extension GL_ARB_shading_language_420pack : enable\n"
2130 "layout (location = 0) out vec2 samplePos;\n"
2131 "void main() {\n"
2132 " vec2 vertices[3];"
2133 " vertices[0] = vec2(-0.5, -0.5);\n"
2134 " vertices[1] = vec2( 0.5, -0.5);\n"
2135 " vertices[2] = vec2( 0.5, 0.5);\n"
2136 " vec2 positions[3];"
2137 " positions[0] = vec2( 0.0, 0.0);\n"
2138 " positions[1] = vec2( 1.0, 0.0);\n"
2139 " positions[2] = vec2( 1.0, 1.0);\n"
2140 " samplePos = positions[gl_VertexID % 3];\n"
2141 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2142 "}\n";
2143
2144 static const char *fragShaderText =
2145 "#version 140\n"
2146 "#extension GL_ARB_separate_shader_objects : enable\n"
2147 "#extension GL_ARB_shading_language_420pack : enable\n"
2148 "layout (location = 0) in vec2 samplePos;\n"
2149 "layout (binding = 0) uniform sampler2D surface;\n"
2150 "layout (location=0) out vec4 outColor;\n"
2151 "void main() {\n"
2152 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2153 " outColor = texColor;\n"
2154 "}\n";
2155
2156 ASSERT_NO_FATAL_FAILURE(InitState());
2157 ASSERT_NO_FATAL_FAILURE(InitViewport());
2158
2159 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2160 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2161 XglSamplerObj sampler(m_device);
2162 XglTextureObj texture(m_device);
2163
Tony Barbourf43b6982014-11-25 13:18:32 -07002164 XglPipelineObj pipelineobj(m_device);
2165 pipelineobj.AddShader(&vs);
2166 pipelineobj.AddShader(&ps);
2167
2168 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002169 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002170
2171 m_memoryRefManager.AddMemoryRef(&texture);
2172
Tony Barbourdd4c9642015-01-09 12:55:14 -07002173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002174 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002175 XglCommandBufferObj cmdBuffer(m_device);
2176 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2177
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002178 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002179
2180 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2181
2182#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002183 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002184 pDSDumpDot((char*)"triTest2.dot");
2185#endif
2186 // render triangle
2187 cmdBuffer.Draw(0, 3, 0, 1);
2188
2189 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002190 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002191 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002192
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002193 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002194 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002195}
2196TEST_F(XglRenderTest, SamplerBindingsTriangle)
2197{
2198 // This test sets bindings on the samplers
2199 // For now we are asserting that sampler and texture pairs
2200 // march in lock step, and are set via GLSL binding. This can
2201 // and will probably change.
2202 // The sampler bindings should match the sampler and texture slot
2203 // number set up by the application.
2204 // This test will result in a blue triangle
2205 static const char *vertShaderText =
2206 "#version 140\n"
2207 "#extension GL_ARB_separate_shader_objects : enable\n"
2208 "#extension GL_ARB_shading_language_420pack : enable\n"
2209 "layout (location = 0) out vec4 samplePos;\n"
2210 "void main() {\n"
2211 " vec2 vertices[3];"
2212 " vertices[0] = vec2(-0.5, -0.5);\n"
2213 " vertices[1] = vec2( 0.5, -0.5);\n"
2214 " vertices[2] = vec2( 0.5, 0.5);\n"
2215 " vec2 positions[3];"
2216 " positions[0] = vec2( 0.0, 0.0);\n"
2217 " positions[1] = vec2( 1.0, 0.0);\n"
2218 " positions[2] = vec2( 1.0, 1.0);\n"
2219 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2220 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2221 "}\n";
2222
2223 static const char *fragShaderText =
2224 "#version 140\n"
2225 "#extension GL_ARB_separate_shader_objects : enable\n"
2226 "#extension GL_ARB_shading_language_420pack : enable\n"
2227 "layout (location = 0) in vec4 samplePos;\n"
2228 "layout (binding = 0) uniform sampler2D surface0;\n"
2229 "layout (binding = 1) uniform sampler2D surface1;\n"
2230 "layout (binding = 12) uniform sampler2D surface2;\n"
2231 "void main() {\n"
2232 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2233 "}\n";
2234
2235 ASSERT_NO_FATAL_FAILURE(InitState());
2236 ASSERT_NO_FATAL_FAILURE(InitViewport());
2237
2238 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2239 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2240
2241 XglSamplerObj sampler1(m_device);
2242 XglSamplerObj sampler2(m_device);
2243 XglSamplerObj sampler3(m_device);
2244
Tony Barbour2f421a02015-04-01 16:38:10 -06002245 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2246 XglTextureObj texture1(m_device, tex_colors); // Red
2247 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2248 XglTextureObj texture2(m_device, tex_colors); // Green
2249 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2250 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002251
Tony Barbourf43b6982014-11-25 13:18:32 -07002252 XglPipelineObj pipelineobj(m_device);
2253 pipelineobj.AddShader(&vs);
2254 pipelineobj.AddShader(&ps);
2255
2256 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002257 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2258 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2259 for (int i = 0; i < 10; i++)
2260 descriptorSet.AppendDummy();
2261 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002262
2263 m_memoryRefManager.AddMemoryRef(&texture1);
2264 m_memoryRefManager.AddMemoryRef(&texture2);
2265 m_memoryRefManager.AddMemoryRef(&texture3);
2266
Tony Barbourdd4c9642015-01-09 12:55:14 -07002267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002268 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002269 XglCommandBufferObj cmdBuffer(m_device);
2270 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2271
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002272 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273
2274 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2275
2276#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002277 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002278 pDSDumpDot((char*)"triTest2.dot");
2279#endif
2280 // render triangle
2281 cmdBuffer.Draw(0, 3, 0, 1);
2282
2283 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002284 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002285 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002286
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002287 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002288 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002289
2290}
2291
2292TEST_F(XglRenderTest, TriangleVSUniformBlock)
2293{
2294 // The expected result from this test is a blue triangle
2295
2296 static const char *vertShaderText =
2297 "#version 140\n"
2298 "#extension GL_ARB_separate_shader_objects : enable\n"
2299 "#extension GL_ARB_shading_language_420pack : enable\n"
2300 "layout (location = 0) out vec4 outColor;\n"
2301 "layout (std140, binding = 0) uniform bufferVals {\n"
2302 " vec4 red;\n"
2303 " vec4 green;\n"
2304 " vec4 blue;\n"
2305 " vec4 white;\n"
2306 "} myBufferVals;\n"
2307 "void main() {\n"
2308 " vec2 vertices[3];"
2309 " vertices[0] = vec2(-0.5, -0.5);\n"
2310 " vertices[1] = vec2( 0.5, -0.5);\n"
2311 " vertices[2] = vec2( 0.5, 0.5);\n"
2312 " outColor = myBufferVals.blue;\n"
2313 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2314 "}\n";
2315
2316 static const char *fragShaderText =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects : enable\n"
2319 "#extension GL_ARB_shading_language_420pack : enable\n"
2320 "layout (location = 0) in vec4 inColor;\n"
2321 "void main() {\n"
2322 " gl_FragColor = inColor;\n"
2323 "}\n";
2324
2325 ASSERT_NO_FATAL_FAILURE(InitState());
2326 ASSERT_NO_FATAL_FAILURE(InitViewport());
2327
2328 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2329 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2330
2331 // Let's populate our buffer with the following:
2332 // vec4 red;
2333 // vec4 green;
2334 // vec4 blue;
2335 // vec4 white;
2336 const int valCount = 4 * 4;
2337 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2338 0.0, 1.0, 0.0, 1.0,
2339 0.0, 0.0, 1.0, 1.0,
2340 1.0, 1.0, 1.0, 1.0 };
2341
2342 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002343
2344 XglPipelineObj pipelineobj(m_device);
2345 pipelineobj.AddShader(&vs);
2346 pipelineobj.AddShader(&ps);
2347
2348 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002349 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002350
Tony Barbourdd4c9642015-01-09 12:55:14 -07002351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002352 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002353 XglCommandBufferObj cmdBuffer(m_device);
2354 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2355
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002356 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002357
2358 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2359
2360#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002361 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002362 pDSDumpDot((char*)"triTest2.dot");
2363#endif
2364 // render triangle
2365 cmdBuffer.Draw(0, 3, 0, 1);
2366
2367 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002368 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002369 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002370
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002371 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002372 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373
2374}
2375
2376TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2377{
2378 // This test allows the shader to select which buffer it is
2379 // pulling from using layout binding qualifier.
2380 // There are corresponding changes in the compiler stack that
2381 // will select the buffer using binding directly.
2382 // The binding number should match the slot number set up by
2383 // the application.
2384 // The expected result from this test is a purple triangle
2385
2386 static const char *vertShaderText =
2387 "#version 140\n"
2388 "#extension GL_ARB_separate_shader_objects : enable\n"
2389 "#extension GL_ARB_shading_language_420pack : enable\n"
2390 "void main() {\n"
2391 " vec2 vertices[3];"
2392 " vertices[0] = vec2(-0.5, -0.5);\n"
2393 " vertices[1] = vec2( 0.5, -0.5);\n"
2394 " vertices[2] = vec2( 0.5, 0.5);\n"
2395 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2396 "}\n";
2397
2398 static const char *fragShaderText =
2399 "#version 140\n"
2400 "#extension GL_ARB_separate_shader_objects : enable\n"
2401 "#extension GL_ARB_shading_language_420pack : enable\n"
2402 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2403 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2404 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002405 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002406 "void main() {\n"
2407 " gl_FragColor = myBlueVal.color;\n"
2408 " gl_FragColor += myRedVal.color;\n"
2409 "}\n";
2410
2411 ASSERT_NO_FATAL_FAILURE(InitState());
2412 ASSERT_NO_FATAL_FAILURE(InitViewport());
2413
2414 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2415 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2416
2417 // We're going to create a number of uniform buffers, and then allow
2418 // the shader to select which it wants to read from with a binding
2419
2420 // Let's populate the buffers with a single color each:
2421 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2422 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2423 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002424 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002425
2426 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2427 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2428 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2429 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2430
2431 const int redCount = sizeof(redVals) / sizeof(float);
2432 const int greenCount = sizeof(greenVals) / sizeof(float);
2433 const int blueCount = sizeof(blueVals) / sizeof(float);
2434 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2435
2436 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002437
2438 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002439
2440 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002441
2442 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002443
2444 XglPipelineObj pipelineobj(m_device);
2445 pipelineobj.AddShader(&vs);
2446 pipelineobj.AddShader(&ps);
2447
2448 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002449 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2450 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2451 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2452 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002453
Tony Barbourdd4c9642015-01-09 12:55:14 -07002454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002455 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002456 XglCommandBufferObj cmdBuffer(m_device);
2457 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002458
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002459 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002460
2461 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2462
2463#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002464 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002465 pDSDumpDot((char*)"triTest2.dot");
2466#endif
2467 // render triangle
2468 cmdBuffer.Draw(0, 3, 0, 1);
2469
2470 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002471 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002472 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002473
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002474 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002475 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002476}
2477
2478TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2479{
2480 // This test is the same as TriangleFSUniformBlockBinding, but
2481 // it does not provide an instance name.
2482 // The expected result from this test is a purple triangle
2483
2484 static const char *vertShaderText =
2485 "#version 140\n"
2486 "#extension GL_ARB_separate_shader_objects : enable\n"
2487 "#extension GL_ARB_shading_language_420pack : enable\n"
2488 "void main() {\n"
2489 " vec2 vertices[3];"
2490 " vertices[0] = vec2(-0.5, -0.5);\n"
2491 " vertices[1] = vec2( 0.5, -0.5);\n"
2492 " vertices[2] = vec2( 0.5, 0.5);\n"
2493 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2494 "}\n";
2495
2496 static const char *fragShaderText =
2497 "#version 430\n"
2498 "#extension GL_ARB_separate_shader_objects : enable\n"
2499 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002500 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2501 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2502 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002503 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002504 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002505 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002506 " outColor = blue;\n"
2507 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002508 "}\n";
2509 ASSERT_NO_FATAL_FAILURE(InitState());
2510 ASSERT_NO_FATAL_FAILURE(InitViewport());
2511
2512 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2513 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2514
2515 // We're going to create a number of uniform buffers, and then allow
2516 // the shader to select which it wants to read from with a binding
2517
2518 // Let's populate the buffers with a single color each:
2519 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2520 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2521 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2522 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2523
2524 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2525 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2526 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2527 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2528
2529 const int redCount = sizeof(redVals) / sizeof(float);
2530 const int greenCount = sizeof(greenVals) / sizeof(float);
2531 const int blueCount = sizeof(blueVals) / sizeof(float);
2532 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2533
2534 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002535
2536 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002537
2538 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
2540 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002541
2542 XglPipelineObj pipelineobj(m_device);
2543 pipelineobj.AddShader(&vs);
2544 pipelineobj.AddShader(&ps);
2545
2546 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002547 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2548 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2549 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2550 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002551
Tony Barbourdd4c9642015-01-09 12:55:14 -07002552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002553 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002554 XglCommandBufferObj cmdBuffer(m_device);
2555 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2556
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002557 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002558
2559 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2560
2561#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002562 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002563 pDSDumpDot((char*)"triTest2.dot");
2564#endif
2565 // render triangle
2566 cmdBuffer.Draw(0, 3, 0, 1);
2567
2568 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002569 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002570 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002571
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002572 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002573 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002574
2575}
2576
2577TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2578{
2579 static const char *vertShaderText =
2580 "#version 140\n"
2581 "#extension GL_ARB_separate_shader_objects : enable\n"
2582 "#extension GL_ARB_shading_language_420pack : enable\n"
2583 "layout (std140, binding=0) uniform bufferVals {\n"
2584 " mat4 mvp;\n"
2585 "} myBufferVals;\n"
2586 "layout (location=0) in vec4 pos;\n"
2587 "layout (location=0) out vec2 UV;\n"
2588 "void main() {\n"
2589 " vec2 positions[3];"
2590 " positions[0] = vec2( 0.0, 0.0);\n"
2591 " positions[1] = vec2( 0.25, 0.1);\n"
2592 " positions[2] = vec2( 0.1, 0.25);\n"
2593 " UV = positions[gl_VertexID % 3];\n"
2594 " gl_Position = myBufferVals.mvp * pos;\n"
2595 "}\n";
2596
2597 static const char *fragShaderText =
2598 "#version 140\n"
2599 "#extension GL_ARB_separate_shader_objects : enable\n"
2600 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002601 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002602 "layout (location=0) out vec4 outColor;\n"
2603 "layout (location=0) in vec2 UV;\n"
2604 "void main() {\n"
2605 " outColor= textureLod(surface, UV, 0.0);\n"
2606 "}\n";
2607 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2608
2609 glm::mat4 View = glm::lookAt(
2610 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2611 glm::vec3(0,0,0), // and looks at the origin
2612 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2613 );
2614
2615 glm::mat4 Model = glm::mat4(1.0f);
2616
2617 glm::mat4 MVP = Projection * View * Model;
2618
2619
2620 ASSERT_NO_FATAL_FAILURE(InitState());
2621 ASSERT_NO_FATAL_FAILURE(InitViewport());
2622 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2623
2624 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2625 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002626 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002627
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002628 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002629
2630 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2631 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2632 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2633 XglSamplerObj sampler(m_device);
2634 XglTextureObj texture(m_device);
2635
Tony Barbourf43b6982014-11-25 13:18:32 -07002636 XglPipelineObj pipelineobj(m_device);
2637 pipelineobj.AddShader(&vs);
2638 pipelineobj.AddShader(&ps);
2639
2640 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002641 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002642 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2643 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002644
2645 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2646 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2647 m_memoryRefManager.AddMemoryRef(&texture);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002648 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07002649
2650 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2651 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2652 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2653 };
2654
2655 // this is the current description of g_vbData
2656 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2657 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002658 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002659 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2660 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002661 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002662 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2663
2664 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2665 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2666 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2667
Tony Barbourfa6cac72015-01-16 14:27:35 -07002668 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2669 ds_state.depthTestEnable = XGL_TRUE;
2670 ds_state.depthWriteEnable = XGL_TRUE;
2671 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2672 ds_state.depthBoundsEnable = XGL_FALSE;
2673 ds_state.stencilTestEnable = XGL_FALSE;
2674 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2675 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2676 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2677 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002678 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002679 ds_state.front = ds_state.back;
2680 pipelineobj.SetDepthStencil(&ds_state);
2681
Tony Barbourdd4c9642015-01-09 12:55:14 -07002682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002683 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002684 XglCommandBufferObj cmdBuffer(m_device);
2685 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002686
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002687 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2688
Tony Barbourdd4c9642015-01-09 12:55:14 -07002689 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2690
2691 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2692#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002693 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002694 pDSDumpDot((char*)"triTest2.dot");
2695#endif
2696 // render triangle
2697 cmdBuffer.Draw(0, 36, 0, 1);
2698
2699 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002700 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002701 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2702
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002703 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002704 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002705
2706}
Cody Northropd1ce7842014-12-09 11:17:01 -07002707
2708TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2709{
2710 // This test mixes binding slots of textures and buffers, ensuring
2711 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002712 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002713 // you can modify it to move the desired result around.
2714
2715 static const char *vertShaderText =
2716 "#version 140\n"
2717 "#extension GL_ARB_separate_shader_objects : enable\n"
2718 "#extension GL_ARB_shading_language_420pack : enable\n"
2719 "void main() {\n"
2720 " vec2 vertices[3];"
2721 " vertices[0] = vec2(-0.5, -0.5);\n"
2722 " vertices[1] = vec2( 0.5, -0.5);\n"
2723 " vertices[2] = vec2( 0.5, 0.5);\n"
2724 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2725 "}\n";
2726
2727 static const char *fragShaderText =
2728 "#version 430\n"
2729 "#extension GL_ARB_separate_shader_objects : enable\n"
2730 "#extension GL_ARB_shading_language_420pack : enable\n"
2731 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002732 "layout (binding = 3) uniform sampler2D surface1;\n"
2733 "layout (binding = 1) uniform sampler2D surface2;\n"
2734 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002735
Cody Northropa0410942014-12-09 13:59:39 -07002736
Chia-I Wuf8385062015-01-04 16:27:24 +08002737 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2738 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2739 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2740 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002741 "layout (location = 0) out vec4 outColor;\n"
2742 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002743 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002744 " outColor += white * vec4(0.00001);\n"
2745 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002746 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002747 "}\n";
2748 ASSERT_NO_FATAL_FAILURE(InitState());
2749 ASSERT_NO_FATAL_FAILURE(InitViewport());
2750
2751 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2752 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2753
Cody Northropd1ce7842014-12-09 11:17:01 -07002754 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2755 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2756 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2757 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2758
2759 const int redCount = sizeof(redVals) / sizeof(float);
2760 const int greenCount = sizeof(greenVals) / sizeof(float);
2761 const int blueCount = sizeof(blueVals) / sizeof(float);
2762 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2763
2764 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002765 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002766 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002767 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002768
Tony Barbour2f421a02015-04-01 16:38:10 -06002769 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002770 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002771 XglTextureObj texture0(m_device, tex_colors); // Light Red
2772 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002773 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002774 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2775 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002776 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002777 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002778
2779 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2780 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002781 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002782 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002783 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002784
2785 XglPipelineObj pipelineobj(m_device);
2786 pipelineobj.AddShader(&vs);
2787 pipelineobj.AddShader(&ps);
2788
2789 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002790 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2791 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2792 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2793 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2794 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2795 // swap blue and green
2796 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2797 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2798 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002799
2800 m_memoryRefManager.AddMemoryRef(&texture0);
2801 m_memoryRefManager.AddMemoryRef(&texture2);
2802 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002803 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002804
Tony Barbourdd4c9642015-01-09 12:55:14 -07002805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002806 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002807 XglCommandBufferObj cmdBuffer(m_device);
2808 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002809
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002810 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002811
2812 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2813
2814#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002815 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002816 pDSDumpDot((char*)"triTest2.dot");
2817#endif
2818 // render triangle
2819 cmdBuffer.Draw(0, 3, 0, 1);
2820
2821 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002822 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002823 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002824
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002825 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002826 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002827
2828}
2829
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002830TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2831{
2832 // This test matches binding slots of textures and buffers, requiring
2833 // the driver to give them distinct number spaces.
2834 // The expected result from this test is a red triangle, although
2835 // you can modify it to move the desired result around.
2836
2837 static const char *vertShaderText =
2838 "#version 140\n"
2839 "#extension GL_ARB_separate_shader_objects : enable\n"
2840 "#extension GL_ARB_shading_language_420pack : enable\n"
2841 "void main() {\n"
2842 " vec2 vertices[3];"
2843 " vertices[0] = vec2(-0.5, -0.5);\n"
2844 " vertices[1] = vec2( 0.5, -0.5);\n"
2845 " vertices[2] = vec2( 0.5, 0.5);\n"
2846 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2847 "}\n";
2848
2849 static const char *fragShaderText =
2850 "#version 430\n"
2851 "#extension GL_ARB_separate_shader_objects : enable\n"
2852 "#extension GL_ARB_shading_language_420pack : enable\n"
2853 "layout (binding = 0) uniform sampler2D surface0;\n"
2854 "layout (binding = 1) uniform sampler2D surface1;\n"
2855 "layout (binding = 2) uniform sampler2D surface2;\n"
2856 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002857 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2858 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2859 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2860 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002861 "layout (location = 0) out vec4 outColor;\n"
2862 "void main() {\n"
2863 " outColor = red;// * vec4(0.00001);\n"
2864 " outColor += white * vec4(0.00001);\n"
2865 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2866 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2867 "}\n";
2868 ASSERT_NO_FATAL_FAILURE(InitState());
2869 ASSERT_NO_FATAL_FAILURE(InitViewport());
2870
2871 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2872 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2873
2874 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2875 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2876 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2877 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2878
2879 const int redCount = sizeof(redVals) / sizeof(float);
2880 const int greenCount = sizeof(greenVals) / sizeof(float);
2881 const int blueCount = sizeof(blueVals) / sizeof(float);
2882 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2883
2884 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002885 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002886 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002887 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002888
Tony Barbour2f421a02015-04-01 16:38:10 -06002889 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002890 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002891 XglTextureObj texture0(m_device, tex_colors); // Light Red
2892 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002893 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002894 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2895 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002896 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002897 XglTextureObj texture4(m_device, tex_colors); // Light Green
2898 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002899 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002900 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002901
2902 XglPipelineObj pipelineobj(m_device);
2903 pipelineobj.AddShader(&vs);
2904 pipelineobj.AddShader(&ps);
2905
2906 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002907 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2908 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2909 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2910 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2911 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2912 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2913 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2914 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002915
2916 m_memoryRefManager.AddMemoryRef(&texture0);
2917 m_memoryRefManager.AddMemoryRef(&texture2);
2918 m_memoryRefManager.AddMemoryRef(&texture4);
2919 m_memoryRefManager.AddMemoryRef(&texture7);
2920
Tony Barbourdd4c9642015-01-09 12:55:14 -07002921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002922 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002923 XglCommandBufferObj cmdBuffer(m_device);
2924 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002925
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002926 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002927
2928 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2929
2930#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002931 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002932 pDSDumpDot((char*)"triTest2.dot");
2933#endif
2934 // render triangle
2935 cmdBuffer.Draw(0, 3, 0, 1);
2936
2937 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002938 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002939 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002940
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002941 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002942 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002943
2944}
2945
Cody Northrop02690bd2014-12-17 15:26:33 -07002946TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2947{
2948 // This test populates a buffer with a variety of different data
2949 // types, then reads them out with a shader.
2950 // The expected result from this test is a green triangle
2951
2952 static const char *vertShaderText =
2953 "#version 140\n"
2954 "#extension GL_ARB_separate_shader_objects : enable\n"
2955 "#extension GL_ARB_shading_language_420pack : enable\n"
2956 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2957 " vec4 fRed;\n"
2958 " vec4 fGreen;\n"
2959 " layout(row_major) mat4 worldToProj;\n"
2960 " layout(row_major) mat4 projToWorld;\n"
2961 " layout(row_major) mat4 worldToView;\n"
2962 " layout(row_major) mat4 viewToProj;\n"
2963 " layout(row_major) mat4 worldToShadow[4];\n"
2964 " float fZero;\n"
2965 " float fOne;\n"
2966 " float fTwo;\n"
2967 " float fThree;\n"
2968 " vec3 fZeroZeroZero;\n"
2969 " float fFour;\n"
2970 " vec3 fZeroZeroOne;\n"
2971 " float fFive;\n"
2972 " vec3 fZeroOneZero;\n"
2973 " float fSix;\n"
2974 " float fSeven;\n"
2975 " float fEight;\n"
2976 " float fNine;\n"
2977 " vec2 fZeroZero;\n"
2978 " vec2 fZeroOne;\n"
2979 " vec4 fBlue;\n"
2980 " vec2 fOneZero;\n"
2981 " vec2 fOneOne;\n"
2982 " vec3 fZeroOneOne;\n"
2983 " float fTen;\n"
2984 " float fEleven;\n"
2985 " float fTwelve;\n"
2986 " vec3 fOneZeroZero;\n"
2987 " vec4 uvOffsets[4];\n"
2988 "};\n"
2989 "layout (location = 0) out vec4 color;"
2990 "void main() {\n"
2991
2992 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2993 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2994 " \n"
2995
2996 // do some exact comparisons, even though we should
2997 // really have an epsilon involved.
2998 " vec4 outColor = right;\n"
2999 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3000 " outColor = wrong;\n"
3001 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3002 " outColor = wrong;\n"
3003 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3004 " outColor = wrong;\n"
3005
3006 " color = outColor;\n"
3007
3008 // generic position stuff
3009 " vec2 vertices;\n"
3010 " int vertexSelector = gl_VertexID;\n"
3011 " if (vertexSelector == 0)\n"
3012 " vertices = vec2(-0.5, -0.5);\n"
3013 " else if (vertexSelector == 1)\n"
3014 " vertices = vec2( 0.5, -0.5);\n"
3015 " else if (vertexSelector == 2)\n"
3016 " vertices = vec2( 0.5, 0.5);\n"
3017 " else\n"
3018 " vertices = vec2( 0.0, 0.0);\n"
3019 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3020 "}\n";
3021
3022 static const char *fragShaderText =
3023 "#version 140\n"
3024 "#extension GL_ARB_separate_shader_objects : enable\n"
3025 "#extension GL_ARB_shading_language_420pack : enable\n"
3026 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3027 " vec4 fRed;\n"
3028 " vec4 fGreen;\n"
3029 " layout(row_major) mat4 worldToProj;\n"
3030 " layout(row_major) mat4 projToWorld;\n"
3031 " layout(row_major) mat4 worldToView;\n"
3032 " layout(row_major) mat4 viewToProj;\n"
3033 " layout(row_major) mat4 worldToShadow[4];\n"
3034 " float fZero;\n"
3035 " float fOne;\n"
3036 " float fTwo;\n"
3037 " float fThree;\n"
3038 " vec3 fZeroZeroZero;\n"
3039 " float fFour;\n"
3040 " vec3 fZeroZeroOne;\n"
3041 " float fFive;\n"
3042 " vec3 fZeroOneZero;\n"
3043 " float fSix;\n"
3044 " float fSeven;\n"
3045 " float fEight;\n"
3046 " float fNine;\n"
3047 " vec2 fZeroZero;\n"
3048 " vec2 fZeroOne;\n"
3049 " vec4 fBlue;\n"
3050 " vec2 fOneZero;\n"
3051 " vec2 fOneOne;\n"
3052 " vec3 fZeroOneOne;\n"
3053 " float fTen;\n"
3054 " float fEleven;\n"
3055 " float fTwelve;\n"
3056 " vec3 fOneZeroZero;\n"
3057 " vec4 uvOffsets[4];\n"
3058 "};\n"
3059 "layout (location = 0) in vec4 color;\n"
3060 "void main() {\n"
3061 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3062 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3063 " \n"
3064
3065 // start with VS value to ensure it passed
3066 " vec4 outColor = color;\n"
3067
3068 // do some exact comparisons, even though we should
3069 // really have an epsilon involved.
3070 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3071 " outColor = wrong;\n"
3072 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3073 " outColor = wrong;\n"
3074 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3075 " outColor = wrong;\n"
3076 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3077 " outColor = wrong;\n"
3078 " if (fTwo != 2.0)\n"
3079 " outColor = wrong;\n"
3080 " if (fOneOne != vec2(1.0, 1.0))\n"
3081 " outColor = wrong;\n"
3082 " if (fTen != 10.0)\n"
3083 " outColor = wrong;\n"
3084 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3085 " outColor = wrong;\n"
3086 " \n"
3087 " gl_FragColor = outColor;\n"
3088 "}\n";
3089
3090
3091 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3092 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3093 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3094 0.0, 1.0, 0.0, 1.0, // align
3095 0.0, 0.0, 1.0, 1.0, // align
3096 0.0, 0.0, 0.0, 1.0, // align
3097 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3098 0.0, 2.0, 0.0, 2.0, // align
3099 0.0, 0.0, 2.0, 2.0, // align
3100 0.0, 0.0, 0.0, 2.0, // align
3101 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3102 0.0, 3.0, 0.0, 3.0, // align
3103 0.0, 0.0, 3.0, 3.0, // align
3104 0.0, 0.0, 0.0, 3.0, // align
3105 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3106 0.0, 4.0, 0.0, 4.0, // align
3107 0.0, 0.0, 4.0, 4.0, // align
3108 0.0, 0.0, 0.0, 4.0, // align
3109 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3110 0.0, 5.0, 0.0, 5.0, // align
3111 0.0, 0.0, 5.0, 5.0, // align
3112 0.0, 0.0, 0.0, 5.0, // align
3113 6.0, 0.0, 0.0, 6.0, // align
3114 0.0, 6.0, 0.0, 6.0, // align
3115 0.0, 0.0, 6.0, 6.0, // align
3116 0.0, 0.0, 0.0, 6.0, // align
3117 7.0, 0.0, 0.0, 7.0, // align
3118 0.0, 7.0, 0.0, 7.0, // align
3119 0.0, 0.0, 7.0, 7.0, // align
3120 0.0, 0.0, 0.0, 7.0, // align
3121 8.0, 0.0, 0.0, 8.0, // align
3122 0.0, 8.0, 0.0, 8.0, // align
3123 0.0, 0.0, 8.0, 8.0, // align
3124 0.0, 0.0, 0.0, 8.0, // align
3125 0.0, // float fZero; // align
3126 1.0, // float fOne; // pack
3127 2.0, // float fTwo; // pack
3128 3.0, // float fThree; // pack
3129 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3130 4.0, // float fFour; // pack
3131 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3132 5.0, // float fFive; // pack
3133 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3134 6.0, // float fSix; // pack
3135 7.0, // float fSeven; // align
3136 8.0, // float fEight; // pack
3137 9.0, // float fNine; // pack
3138 0.0, // BUFFER
3139 0.0, 0.0, // vec2 fZeroZero; // align
3140 0.0, 1.0, // vec2 fZeroOne; // pack
3141 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3142 1.0, 0.0, // vec2 fOneZero; // align
3143 1.0, 1.0, // vec2 fOneOne; // pack
3144 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3145 10.0, // float fTen; // pack
3146 11.0, // float fEleven; // align
3147 12.0, // float fTwelve; // pack
3148 0.0, 0.0, // BUFFER
3149 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3150 0.0, // BUFFER
3151 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3152 0.5, 0.6, 0.7, 0.8, // align
3153 0.9, 1.0, 1.1, 1.2, // align
3154 1.3, 1.4, 1.5, 1.6, // align
3155 };
3156
3157 ASSERT_NO_FATAL_FAILURE(InitState());
3158 ASSERT_NO_FATAL_FAILURE(InitViewport());
3159
3160 const int constCount = sizeof(mixedVals) / sizeof(float);
3161
3162 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3163 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3164
3165 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003166
3167 XglPipelineObj pipelineobj(m_device);
3168 pipelineobj.AddShader(&vs);
3169 pipelineobj.AddShader(&ps);
3170
3171 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003172 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003173
3174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003175 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003176 XglCommandBufferObj cmdBuffer(m_device);
3177 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3178
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003179 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003180
3181 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3182
3183#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003184 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003185 pDSDumpDot((char*)"triTest2.dot");
3186#endif
3187 // render triangle
3188 cmdBuffer.Draw(0, 3, 0, 1);
3189
3190 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003191 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003192 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003193
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003194 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003195 RecordImage(m_renderTargets[i]);
3196}
3197
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003198int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003199 int result;
3200
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003201 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003202 XglTestFramework::InitArgs(&argc, argv);
3203
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003204 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003205
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003206 result = RUN_ALL_TESTS();
3207
3208 XglTestFramework::Finish();
3209 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003210}