blob: 24db85f7663f5f9fb4f142085739c9142d4f84c7 [file] [log] [blame]
Courtney Goeltzenleuchtercc5eb3a2014-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 Goeltzenleuchtercc5eb3a2014-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 Goeltzenleuchterda91b952014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Chia-I Wufe7c1de2014-08-28 11:56:29 +080075#include "icd-bil.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060076
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
83XGL_VOID XGLAPI myDbgFunc(
84 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
87 XGL_SIZE location,
88 XGL_INT msgCode,
89 const XGL_CHAR* pMsg,
90 XGL_VOID* pUserData)
91{
Tobin Ehlisca915872014-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 Ehlis6663f492014-11-10 12:29:12 -0700104}
105#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
116 XGL_FLOAT posX, posY, posZ, posW; // Position data
117 XGL_FLOAT r, g, b, a; // Color
118};
119
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchter83884952014-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 Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600214public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600215
Tony Barboure2c58df2014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour664accc2015-01-09 12:55:14 -0700217 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
Tony Barbour22e32a12015-01-08 17:08:28 -0700218 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600219 void InitDepthStencil();
Tony Barbourc4442362015-01-12 13:27:11 -0700220 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600221
Cody Northropee6586d2014-10-09 19:55:56 -0600222
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600223protected:
Cody Northrop7d2035d2014-10-06 15:42:00 -0600224 XGL_IMAGE m_texture;
225 XGL_IMAGE_VIEW m_textureView;
226 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
227 XGL_GPU_MEMORY m_textureMem;
228
229 XGL_SAMPLER m_sampler;
230
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600231 XGL_FORMAT m_depth_stencil_fmt;
232 XGL_IMAGE m_depthStencilImage;
Jon Ashburn7e781952015-01-16 09:37:43 -0700233 XGL_UINT m_num_mem;
234 XGL_GPU_MEMORY *m_depthStencilMem;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600235 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barboure2c58df2014-11-25 13:18:32 -0700236 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600237
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600238
239 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600240
241 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
242 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800243 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600244 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800245 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600246 this->app_info.engineVersion = 1;
247 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
248
Cody Northrop7d2035d2014-10-06 15:42:00 -0600249 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
250 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700251 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600252
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600253 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600254 }
255
256 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600257 // Clean up resources before we reset
258 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600259 }
260};
261
Tony Barbour22e32a12015-01-08 17:08:28 -0700262void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
263{
264 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700265 cmdBuffer->PrepareAttachments();
Tony Barbour22e32a12015-01-08 17:08:28 -0700266 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
269 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wu11078b02015-01-04 16:27:24 +0800270 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour22e32a12015-01-08 17:08:28 -0700271 pipelineobj->CreateXGLPipeline(descriptorSet);
272 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour22e32a12015-01-08 17:08:28 -0700273 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
274}
Tony Barboure2c58df2014-11-25 13:18:32 -0700275
Tony Barboure2c58df2014-11-25 13:18:32 -0700276void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour664accc2015-01-09 12:55:14 -0700277 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
278{
279 int i;
280 glm::mat4 MVP;
281 int matrixSize = sizeof(MVP);
282 XGL_RESULT err;
283
284 for (i = 0; i < 8; i++) {
285 void *pData = constantBuffer->map();
286
287 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
288 MVP = Projection * View * Model;
289 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
290
291 constantBuffer->unmap();
292
293 // submit the command buffer to the universal queue
294 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
295
Tony Barbour664accc2015-01-09 12:55:14 -0700296 err = xglQueueWaitIdle( m_device->m_queue );
297 ASSERT_XGL_SUCCESS( err );
298
299 // Wait for work to finish before cleaning up.
300 xglDeviceWaitIdle(m_device->device());
301
302 assert(m_renderTargetCount == 1);
303 RecordImage(m_renderTargets[0]);
304 }
305}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600306
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600307void dumpMatrix(const char *note, glm::mat4 MVP)
308{
Chia-I Wu6f184292014-12-15 23:57:34 +0800309 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600310
311 printf("%s: \n", note);
312 for (i=0; i<4; i++) {
313 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
314 }
315 printf("\n");
316 fflush(stdout);
317}
318
319void dumpVec4(const char *note, glm::vec4 vector)
320{
321 printf("%s: \n", note);
322 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
323 printf("\n");
324 fflush(stdout);
325}
326
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600327void XglRenderTest::InitDepthStencil()
328{
329 XGL_RESULT err;
330 XGL_IMAGE_CREATE_INFO image;
331 XGL_MEMORY_ALLOC_INFO mem_alloc;
Jon Ashburn8a5da752015-01-19 15:00:26 -0700332 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600333 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburn7e781952015-01-16 09:37:43 -0700334 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Jon Ashburnb9e193f2014-11-21 11:33:20 -0700335 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburn8a5da752015-01-19 15:00:26 -0700336 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
337 XGL_SIZE img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
Jon Ashburn7e781952015-01-16 09:37:43 -0700338 XGL_UINT num_allocations = 0;
339 XGL_SIZE num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600340
341 // Clean up default state created by framework
342 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
343
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700344 m_depth_stencil_fmt = XGL_FMT_D16_UNORM;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600345
346 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
347 image.pNext = NULL;
348 image.imageType = XGL_IMAGE_2D;
349 image.format = m_depth_stencil_fmt;
350 image.extent.width = m_width;
351 image.extent.height = m_height;
352 image.extent.depth = 1;
353 image.mipLevels = 1;
354 image.arraySize = 1;
355 image.samples = 1;
356 image.tiling = XGL_OPTIMAL_TILING;
357 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
358 image.flags = 0;
359
Jon Ashburn8a5da752015-01-19 15:00:26 -0700360 img_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
361 img_alloc.pNext = NULL;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600362 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburn8a5da752015-01-19 15:00:26 -0700363 mem_alloc.pNext = &img_alloc;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600364 mem_alloc.allocationSize = 0;
Jon Ashburne4792432015-01-20 13:55:32 -0700365 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburne01ff7a2015-01-20 15:06:59 -0700366 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600367 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
368
369 /* create image */
370 err = xglCreateImage(device(), &image,
371 &m_depthStencilImage);
372 ASSERT_XGL_SUCCESS(err);
373
374 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburn7e781952015-01-16 09:37:43 -0700375 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
376 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600377 ASSERT_XGL_SUCCESS(err);
Jon Ashburn7e781952015-01-16 09:37:43 -0700378 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
379 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
380 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
381 m_num_mem = num_allocations;
382 err = xglGetObjectInfo(m_depthStencilImage,
383 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
384 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600385 ASSERT_XGL_SUCCESS(err);
Jon Ashburn7e781952015-01-16 09:37:43 -0700386 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburn8a5da752015-01-19 15:00:26 -0700387 err = xglGetObjectInfo(m_depthStencilImage,
388 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
389 &img_reqs_size, &img_reqs);
390 ASSERT_XGL_SUCCESS(err);
391 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
392 img_alloc.usage = img_reqs.usage;
393 img_alloc.formatClass = img_reqs.formatClass;
394 img_alloc.samples = img_reqs.samples;
Jon Ashburn7e781952015-01-16 09:37:43 -0700395 for (XGL_UINT i = 0; i < num_allocations; i ++) {
396 mem_alloc.allocationSize = mem_reqs[i].size;
Jon Ashburn7e781952015-01-16 09:37:43 -0700397
398 /* allocate memory */
399 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
400 ASSERT_XGL_SUCCESS(err);
401
402 /* bind memory */
403 err = xglBindObjectMemory(m_depthStencilImage, i,
404 m_depthStencilMem[i], 0);
405 ASSERT_XGL_SUCCESS(err);
406 }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600407
Tony Barbourf52346d2015-01-16 14:27:35 -0700408 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
409 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
410
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600411 depthStencil.minDepth = 0.f;
412 depthStencil.maxDepth = 1.f;
Tony Barbourf52346d2015-01-16 14:27:35 -0700413 depthStencil.stencilBackRef = 0;
414 depthStencil.stencilFrontRef = 0;
415 depthStencil.stencilReadMask = 0xff;
416 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600417
Tony Barbourf52346d2015-01-16 14:27:35 -0700418 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600419 ASSERT_XGL_SUCCESS( err );
420
421 /* create image view */
422 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
423 view.pNext = NULL;
424 view.image = XGL_NULL_HANDLE;
425 view.mipLevel = 0;
426 view.baseArraySlice = 0;
427 view.arraySize = 1;
428 view.flags = 0;
429 view.image = m_depthStencilImage;
430 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
431 ASSERT_XGL_SUCCESS(err);
432
433 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000434 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600435}
436
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600437struct xgltriangle_vs_uniform {
438 // Must start with MVP
439 XGL_FLOAT mvp[4][4];
440 XGL_FLOAT position[3][4];
441 XGL_FLOAT color[3][4];
442};
443
Tony Barbourc4442362015-01-12 13:27:11 -0700444void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600445{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700446#ifdef DEBUG_CALLBACK
447 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
448#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600449 // Create identity matrix
450 int i;
451 struct xgltriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
457 const int matrixSize = sizeof(MVP);
458 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
459 memcpy(&data.mvp, &MVP[0][0], matrixSize);
460
461 static const Vertex tri_data[] =
462 {
463 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
464 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
465 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
466 };
467
468 for (i=0; i<3; i++) {
469 data.position[i][0] = tri_data[i].posX;
470 data.position[i][1] = tri_data[i].posY;
471 data.position[i][2] = tri_data[i].posZ;
472 data.position[i][3] = tri_data[i].posW;
473 data.color[i][0] = tri_data[i].r;
474 data.color[i][1] = tri_data[i].g;
475 data.color[i][2] = tri_data[i].b;
476 data.color[i][3] = tri_data[i].a;
477 }
478
Tony Barboure2c58df2014-11-25 13:18:32 -0700479 ASSERT_NO_FATAL_FAILURE(InitState());
480 ASSERT_NO_FATAL_FAILURE(InitViewport());
481
482 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
483
484 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
485 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700486
487 XglPipelineObj pipelineobj(m_device);
488 pipelineobj.AddShader(&vs);
489 pipelineobj.AddShader(&ps);
490
491 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +0800492 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700493 m_memoryRefManager.AddMemoryRef(&constantBuffer);
494
Tony Barbourd726a172015-01-09 16:12:35 -0700495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
496 XglCommandBufferObj cmdBuffer(m_device);
497 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700498
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700499 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourd726a172015-01-09 16:12:35 -0700500
501 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
502
503 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
504#ifdef DUMP_STATE_DOT
505 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
506 pDSDumpDot((char*)"triTest2.dot");
507#endif
508 // render triangle
509 cmdBuffer.Draw(0, 3, 0, 1);
510
511 // finalize recording of the command buffer
512 cmdBuffer.EndCommandBuffer();
513 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
514
515 for (int i = 0; i < m_renderTargetCount; i++)
516 RecordImage(m_renderTargets[i]);
517
518 if (rotate)
519 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
520
Tobin Ehlisca915872014-11-18 11:28:33 -0700521#ifdef PRINT_OBJECTS
522 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
523 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
524 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
525 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
526 printf("DEBUG : Number of Objects : %lu\n", numObjects);
527 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
528 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
529 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
530 for (i=0; i < numObjects; i++) {
531 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);
532 }
533 free(pObjNodeArray);
534#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700535
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600536}
537
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600538TEST_F(XglRenderTest, XGLTriangle_FragColor)
539{
540 static const char *vertShaderText =
541 "#version 140\n"
542 "#extension GL_ARB_separate_shader_objects : enable\n"
543 "#extension GL_ARB_shading_language_420pack : enable\n"
544 "\n"
545 "layout(binding = 0) uniform buf {\n"
546 " mat4 MVP;\n"
547 " vec4 position[3];\n"
548 " vec4 color[3];\n"
549 "} ubuf;\n"
550 "\n"
551 "layout (location = 0) out vec4 outColor;\n"
552 "\n"
553 "void main() \n"
554 "{\n"
555 " outColor = ubuf.color[gl_VertexID];\n"
556 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
557 "}\n";
558
559 static const char *fragShaderText =
560 "#version 140\n"
561 "#extension GL_ARB_separate_shader_objects : enable\n"
562 "#extension GL_ARB_shading_language_420pack : enable\n"
563 "\n"
564 "layout (location = 0) in vec4 inColor;\n"
565 "\n"
566 "void main()\n"
567 "{\n"
568 " gl_FragColor = inColor;\n"
569 "}\n";
570
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600571 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourc4442362015-01-12 13:27:11 -0700572 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600573}
574
575TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
576{
577 static const char *vertShaderText =
578 "#version 140\n"
579 "#extension GL_ARB_separate_shader_objects : enable\n"
580 "#extension GL_ARB_shading_language_420pack : enable\n"
581 "\n"
582 "layout(binding = 0) uniform buf {\n"
583 " mat4 MVP;\n"
584 " vec4 position[3];\n"
585 " vec4 color[3];\n"
586 "} ubuf;\n"
587 "\n"
588 "layout (location = 0) out vec4 outColor;\n"
589 "\n"
590 "void main() \n"
591 "{\n"
592 " outColor = ubuf.color[gl_VertexID];\n"
593 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
594 "}\n";
595
596 static const char *fragShaderText =
597 "#version 140\n"
598 "#extension GL_ARB_separate_shader_objects : enable\n"
599 "#extension GL_ARB_shading_language_420pack : enable\n"
600 "\n"
601 "layout (location = 0) in vec4 inColor;\n"
602 "layout (location = 0) out vec4 outColor;\n"
603 "\n"
604 "void main()\n"
605 "{\n"
606 " outColor = inColor;\n"
607 "}\n";
608
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600609 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600610
Tony Barbourc4442362015-01-12 13:27:11 -0700611 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600612}
613
Tony Barboure2c58df2014-11-25 13:18:32 -0700614TEST_F(XglRenderTest, BIL_XGLTriangle)
615{
616 bool saved_use_bil = XglTestFramework::m_use_bil;
617
618 static const char *vertShaderText =
619 "#version 140\n"
620 "#extension GL_ARB_separate_shader_objects : enable\n"
621 "#extension GL_ARB_shading_language_420pack : enable\n"
622 "\n"
623 "layout(binding = 0) uniform buf {\n"
624 " mat4 MVP;\n"
625 " vec4 position[3];\n"
626 " vec4 color[3];\n"
627 "} ubuf;\n"
628 "\n"
629 "layout (location = 0) out vec4 outColor;\n"
630 "\n"
631 "void main() \n"
632 "{\n"
633 " outColor = ubuf.color[gl_VertexID];\n"
634 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
635 "}\n";
636
637 static const char *fragShaderText =
638 "#version 140\n"
639 "#extension GL_ARB_separate_shader_objects : enable\n"
640 "#extension GL_ARB_shading_language_420pack : enable\n"
641 "\n"
642 "layout (location = 0) in vec4 inColor;\n"
643 "\n"
644 "void main()\n"
645 "{\n"
646 " gl_FragColor = inColor;\n"
647 "}\n";
648
649 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
650
651 XglTestFramework::m_use_bil = true;
652
Tony Barbourc4442362015-01-12 13:27:11 -0700653 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700654
655 XglTestFramework::m_use_bil = saved_use_bil;
656}
657
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600658TEST_F(XglRenderTest, GreenTriangle)
Cody Northropd1a256b2014-10-09 21:26:47 -0600659{
660 static const char *vertShaderText =
661 "#version 130\n"
662 "vec2 vertices[3];\n"
663 "void main() {\n"
664 " vertices[0] = vec2(-1.0, -1.0);\n"
665 " vertices[1] = vec2( 1.0, -1.0);\n"
666 " vertices[2] = vec2( 0.0, 1.0);\n"
667 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
668 "}\n";
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600669
Cody Northropd1a256b2014-10-09 21:26:47 -0600670 static const char *fragShaderText =
671 "#version 130\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600672 "void main() {\n"
Steve Kc53f8632014-10-10 08:54:29 -0600673 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600674 "}\n";
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600675
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600676 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
677
Tony Barbourc4442362015-01-12 13:27:11 -0700678 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropd1a256b2014-10-09 21:26:47 -0600679}
Cody Northropee6586d2014-10-09 19:55:56 -0600680
Tony Barboure2c58df2014-11-25 13:18:32 -0700681TEST_F(XglRenderTest, BIL_GreenTriangle)
682{
683 bool saved_use_bil = XglTestFramework::m_use_bil;
684
685 static const char *vertShaderText =
686 "#version 130\n"
687 "vec2 vertices[3];\n"
688 "void main() {\n"
689 " vertices[0] = vec2(-1.0, -1.0);\n"
690 " vertices[1] = vec2( 1.0, -1.0);\n"
691 " vertices[2] = vec2( 0.0, 1.0);\n"
692 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
693 "}\n";
694
695 static const char *fragShaderText =
696 "#version 130\n"
697 "void main() {\n"
698 " gl_FragColor = vec4(0,1,0,1);\n"
699 "}\n";
700
701 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
702
703 XglTestFramework::m_use_bil = true;
Tony Barbourc4442362015-01-12 13:27:11 -0700704 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700705 XglTestFramework::m_use_bil = saved_use_bil;
706}
707
708TEST_F(XglRenderTest, YellowTriangle)
709{
710 static const char *vertShaderText =
711 "#version 130\n"
712 "void main() {\n"
713 " vec2 vertices[3];"
714 " vertices[0] = vec2(-0.5, -0.5);\n"
715 " vertices[1] = vec2( 0.5, -0.5);\n"
716 " vertices[2] = vec2( 0.5, 0.5);\n"
717 " vec4 colors[3];\n"
718 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
719 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
720 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
721 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
722 "}\n";
723
724 static const char *fragShaderText =
725 "#version 130\n"
726 "void main() {\n"
727 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
728 "}\n";
729
Tony Barbourc4442362015-01-12 13:27:11 -0700730 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700731}
732
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600733TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600734{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600735 static const char *vertShaderText =
Tony Barboure2c58df2014-11-25 13:18:32 -0700736 "#version 130\n"
737 //XYZ1( -1, -1, -1 )
738 "in vec4 pos;\n"
739 //XYZ1( 0.f, 0.f, 0.f )
740 "in vec4 inColor;\n"
741 "out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600742 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600743 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600744 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600745 "}\n";
746
Cody Northropee6586d2014-10-09 19:55:56 -0600747
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600748 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700749 "#version 140\n"
750 "#extension GL_ARB_separate_shader_objects : enable\n"
751 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700752 "in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700753 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600754 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700755 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600756 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600757
Tony Barboure2c58df2014-11-25 13:18:32 -0700758
759
760 ASSERT_NO_FATAL_FAILURE(InitState());
761 ASSERT_NO_FATAL_FAILURE(InitViewport());
762
763 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000764 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700765
766 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
767 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
768
769 XglPipelineObj pipelineobj(m_device);
770 pipelineobj.AddShader(&vs);
771 pipelineobj.AddShader(&ps);
772
773 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +0800774 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700775
776 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
777 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
778 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
779 };
780
781 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
782 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700783 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -0700784 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
785 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700786 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -0700787 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
788
789 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
791 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
792
Tony Barbour1fde6942015-01-09 10:06:53 -0700793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
794 XglCommandBufferObj cmdBuffer(m_device);
795 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700796
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700797 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour1fde6942015-01-09 10:06:53 -0700798 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
799
Tony Barbour1fde6942015-01-09 10:06:53 -0700800 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
801
802 // render two triangles
803 cmdBuffer.Draw(0, 6, 0, 1);
804
805 // finalize recording of the command buffer
806 cmdBuffer.EndCommandBuffer();
807 cmdBuffer.QueueCommandBuffer(NULL, 0);
808
809 for (int i = 0; i < m_renderTargetCount; i++)
810 RecordImage(m_renderTargets[i]);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600811}
812
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800813TEST_F(XglRenderTest, TriangleMRT)
814{
815 static const char *vertShaderText =
816 "#version 130\n"
817 "in vec4 pos;\n"
818 "void main() {\n"
819 " gl_Position = pos;\n"
820 "}\n";
821
822 static const char *fragShaderText =
823 "#version 130\n"
824 "void main() {\n"
825 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
826 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
827 "}\n";
828 const XGL_FLOAT vb_data[][2] = {
829 { -1.0f, -1.0f },
830 { 1.0f, -1.0f },
831 { -1.0f, 1.0f }
832 };
833
834 ASSERT_NO_FATAL_FAILURE(InitState());
835 ASSERT_NO_FATAL_FAILURE(InitViewport());
836
837 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000838 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800839
840 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
841 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
842
843 XglPipelineObj pipelineobj(m_device);
844 pipelineobj.AddShader(&vs);
845 pipelineobj.AddShader(&ps);
846
847 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
848 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
849 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
850 };
851
852 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
853 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700854 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800855 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
856
857 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
858 pipelineobj.AddVertexInputBindings(&vi_binding,1);
859 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
860
861 XglDescriptorSetObj descriptorSet(m_device);
862
863 m_renderTargetCount = 2;
Tony Barbour1fde6942015-01-09 10:06:53 -0700864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800865
866 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
867 att.blendEnable = XGL_FALSE;
868 att.format = m_render_target_fmt;
869 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700870 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800871
Tony Barbour304ec8b2015-01-07 14:31:52 -0700872 XglCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -0700873
Tony Barbour304ec8b2015-01-07 14:31:52 -0700874 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
875 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barbour1fde6942015-01-09 10:06:53 -0700876
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700877 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour304ec8b2015-01-07 14:31:52 -0700878
Tony Barbour1fde6942015-01-09 10:06:53 -0700879 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
880
Tony Barbour304ec8b2015-01-07 14:31:52 -0700881 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700882#ifdef DUMP_STATE_DOT
883 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
884 pDSDumpDot((char*)"triTest2.dot");
885#endif
886 // render triangle
887 cmdBuffer.Draw(0, 3, 0, 1);
888
889 // finalize recording of the command buffer
890 cmdBuffer.EndCommandBuffer();
891 cmdBuffer.QueueCommandBuffer(NULL, 0);
892
893 for (int i = 0; i < m_renderTargetCount; i++)
894 RecordImage(m_renderTargets[i]);
895
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800896}
897
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700898TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
899{
900 static const char *vertShaderText =
901 "#version 140\n"
902 "#extension GL_ARB_separate_shader_objects : enable\n"
903 "#extension GL_ARB_shading_language_420pack : enable\n"
904 "layout(location = 0) in vec4 pos;\n"
905 "layout(location = 1) in vec4 inColor;\n"
906 "layout(location = 0) out vec4 outColor;\n"
907 "void main() {\n"
908 " outColor = inColor;\n"
909 " gl_Position = pos;\n"
910 "}\n";
911
912
913 static const char *fragShaderText =
914 "#version 140\n"
915 "#extension GL_ARB_separate_shader_objects : enable\n"
916 "#extension GL_ARB_shading_language_420pack : enable\n"
917 "layout(location = 0) in vec4 color;\n"
918 "void main() {\n"
919 " gl_FragColor = color;\n"
920 "}\n";
921
922 const Vertex g_vbData[] =
923 {
924 // first tri
925 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
926 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
927 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
928
929 // second tri
930 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
931 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
932 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
933 };
934
935 const uint16_t g_idxData[6] = {
936 0, 1, 2,
937 3, 4, 5,
938 };
939
940 ASSERT_NO_FATAL_FAILURE(InitState());
941 ASSERT_NO_FATAL_FAILURE(InitViewport());
942
943 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000944 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700945
946 XglIndexBufferObj indexBuffer(m_device);
947 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000948 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700949
950 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
951 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
952
953 XglPipelineObj pipelineobj(m_device);
954 pipelineobj.AddShader(&vs);
955 pipelineobj.AddShader(&ps);
956
957 XglDescriptorSetObj descriptorSet(m_device);
958
959 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
960 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
961 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
962 };
963
964 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
965 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700966 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700967 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
968 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -0700969 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700970 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
971
972 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
973 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700974
975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourad8f1542014-12-17 11:16:05 -0700976 XglCommandBufferObj cmdBuffer(m_device);
977 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700978 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour1fde6942015-01-09 10:06:53 -0700979
980 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700981
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700982#ifdef DUMP_STATE_DOT
983 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700984 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700985#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700986
Tony Barbourad8f1542014-12-17 11:16:05 -0700987 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
988 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700989
990 // render two triangles
Tony Barbourad8f1542014-12-17 11:16:05 -0700991 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700992
993 // finalize recording of the command buffer
Tony Barbourad8f1542014-12-17 11:16:05 -0700994 cmdBuffer.EndCommandBuffer();
995 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700996
Tony Barbourad8f1542014-12-17 11:16:05 -0700997 for (int i = 0; i < m_renderTargetCount; i++)
998 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700999
1000}
1001
GregF3156cb02014-12-02 15:41:44 -07001002TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1003{
1004 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001005
GregF3156cb02014-12-02 15:41:44 -07001006 static const char *vertShaderText =
1007 "#version 140\n"
1008 "#extension GL_ARB_separate_shader_objects : enable\n"
1009 "#extension GL_ARB_shading_language_420pack : enable\n"
1010 "layout (location = 0) in vec4 pos;\n"
1011 "layout (location = 0) out vec4 outColor;\n"
1012 "layout (location = 1) out vec4 outColor2;\n"
1013 "void main() {\n"
1014 " gl_Position = pos;\n"
1015 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1016 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1017 "}\n";
1018
1019 static const char *fragShaderText =
1020 //"#version 140\n"
1021 "#version 330\n"
1022 "#extension GL_ARB_separate_shader_objects : enable\n"
1023 "#extension GL_ARB_shading_language_420pack : enable\n"
1024 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1025 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1026 "layout (location = 0) in vec4 color;\n"
1027 "layout (location = 1) in vec4 color2;\n"
1028 "void main() {\n"
1029 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1030 " float dist_squared = dot(pos, pos);\n"
1031 " gl_FragColor = (dist_squared < 400.0)\n"
1032 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1033 " : color2;\n"
1034 "}\n";
1035
1036 ASSERT_NO_FATAL_FAILURE(InitState());
1037 ASSERT_NO_FATAL_FAILURE(InitViewport());
1038
1039 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001040 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001041
1042 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1043 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1044
1045 XglPipelineObj pipelineobj(m_device);
1046 pipelineobj.AddShader(&vs);
1047 pipelineobj.AddShader(&ps);
1048
1049 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001050 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF3156cb02014-12-02 15:41:44 -07001051
1052 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1053 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1054 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1055 };
1056
1057 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1058 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001059 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001060 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1061 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001062 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001063 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1064
1065 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1066 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1067 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1068
Tony Barbour664accc2015-01-09 12:55:14 -07001069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1070 XglCommandBufferObj cmdBuffer(m_device);
1071 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1072
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001073 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001074
1075 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1076
1077 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1078#ifdef DUMP_STATE_DOT
1079 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1080 pDSDumpDot((char*)"triTest2.dot");
1081#endif
1082 // render triangle
1083 cmdBuffer.Draw(0, 6, 0, 1);
1084
1085 // finalize recording of the command buffer
1086 cmdBuffer.EndCommandBuffer();
1087 cmdBuffer.QueueCommandBuffer(NULL, 0);
1088
1089 for (int i = 0; i < m_renderTargetCount; i++)
1090 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001091
1092}
1093
1094TEST_F(XglRenderTest, RedCirclesonBlue)
1095{
1096 // This tests that we correctly handle unread fragment inputs
1097
1098 static const char *vertShaderText =
1099 "#version 140\n"
1100 "#extension GL_ARB_separate_shader_objects : enable\n"
1101 "#extension GL_ARB_shading_language_420pack : enable\n"
1102 "layout (location = 0) in vec4 pos;\n"
1103 "layout (location = 0) out vec4 outColor;\n"
1104 "layout (location = 1) out vec4 outColor2;\n"
1105 "void main() {\n"
1106 " gl_Position = pos;\n"
1107 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1108 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1109 "}\n";
1110
1111 static const char *fragShaderText =
1112 //"#version 140\n"
1113 "#version 330\n"
1114 "#extension GL_ARB_separate_shader_objects : enable\n"
1115 "#extension GL_ARB_shading_language_420pack : enable\n"
1116 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1117 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1118 "layout (location = 0) in vec4 color;\n"
1119 "layout (location = 1) in vec4 color2;\n"
1120 "void main() {\n"
1121 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1122 " float dist_squared = dot(pos, pos);\n"
1123 " gl_FragColor = (dist_squared < 400.0)\n"
1124 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1125 " : color2;\n"
1126 "}\n";
1127
1128 ASSERT_NO_FATAL_FAILURE(InitState());
1129 ASSERT_NO_FATAL_FAILURE(InitViewport());
1130
1131 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001132 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001133
1134 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1135 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1136
1137 XglPipelineObj pipelineobj(m_device);
1138 pipelineobj.AddShader(&vs);
1139 pipelineobj.AddShader(&ps);
1140
1141 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001142 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF3156cb02014-12-02 15:41:44 -07001143
1144 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1145 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1146 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1147 };
1148
1149 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1150 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001151 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001152 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1153 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001154 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001155 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1156
1157 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1158 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1159 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1160
Tony Barbour664accc2015-01-09 12:55:14 -07001161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1162 XglCommandBufferObj cmdBuffer(m_device);
1163 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1164
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001165 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001166
1167 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1168
1169 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1170#ifdef DUMP_STATE_DOT
1171 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1172 pDSDumpDot((char*)"triTest2.dot");
1173#endif
1174 // render triangle
1175 cmdBuffer.Draw(0, 6, 0, 1);
1176
1177 // finalize recording of the command buffer
1178 cmdBuffer.EndCommandBuffer();
1179 cmdBuffer.QueueCommandBuffer(NULL, 0);
1180
1181 for (int i = 0; i < m_renderTargetCount; i++)
1182 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001183
1184}
1185
1186TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1187{
1188 // This tests reading gl_ClipDistance from FS
1189
1190 static const char *vertShaderText =
1191 "#version 330\n"
1192 "#extension GL_ARB_separate_shader_objects : enable\n"
1193 "#extension GL_ARB_shading_language_420pack : enable\n"
1194 "out gl_PerVertex {\n"
1195 " vec4 gl_Position;\n"
1196 " float gl_ClipDistance[1];\n"
1197 "};\n"
1198 "layout (location = 0) in vec4 pos;\n"
1199 "layout (location = 0) out vec4 outColor;\n"
1200 "layout (location = 1) out vec4 outColor2;\n"
1201 "void main() {\n"
1202 " gl_Position = pos;\n"
1203 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1204 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1205 " float dists[3];\n"
1206 " dists[0] = 0.0;\n"
1207 " dists[1] = 1.0;\n"
1208 " dists[2] = 1.0;\n"
1209 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1210 "}\n";
1211
1212
1213 static const char *fragShaderText =
1214 //"#version 140\n"
1215 "#version 330\n"
1216 "#extension GL_ARB_separate_shader_objects : enable\n"
1217 "#extension GL_ARB_shading_language_420pack : enable\n"
1218 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1219 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1220 "layout (location = 0) in vec4 color;\n"
1221 "layout (location = 1) in vec4 color2;\n"
1222 "void main() {\n"
1223 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1224 " float dist_squared = dot(pos, pos);\n"
1225 " gl_FragColor = (dist_squared < 400.0)\n"
1226 " ? color * gl_ClipDistance[0]\n"
1227 " : color2;\n"
1228 "}\n";
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 ASSERT_NO_FATAL_FAILURE(InitViewport());
1232
1233 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001234 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001235
1236 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1237 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1238
1239 XglPipelineObj pipelineobj(m_device);
1240 pipelineobj.AddShader(&vs);
1241 pipelineobj.AddShader(&ps);
1242
1243 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001244 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF3156cb02014-12-02 15:41:44 -07001245
1246 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1247 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1248 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1249 };
1250
1251 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1252 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001253 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001254 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1255 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001256 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF3156cb02014-12-02 15:41:44 -07001257 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1258
1259 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1260 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1261 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1262
Tony Barbour664accc2015-01-09 12:55:14 -07001263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1264 XglCommandBufferObj cmdBuffer(m_device);
1265 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF3156cb02014-12-02 15:41:44 -07001266
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001267 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001268
1269 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1270
1271 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1272#ifdef DUMP_STATE_DOT
1273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1274 pDSDumpDot((char*)"triTest2.dot");
1275#endif
1276 // render triangle
1277 cmdBuffer.Draw(0, 6, 0, 1);
1278
1279 // finalize recording of the command buffer
1280 cmdBuffer.EndCommandBuffer();
1281 cmdBuffer.QueueCommandBuffer(NULL, 0);
1282
1283 for (int i = 0; i < m_renderTargetCount; i++)
1284 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001285}
Tony Barboure2c58df2014-11-25 13:18:32 -07001286
GregF42226582014-12-02 17:19:34 -07001287TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1288{
1289 static const char *vertShaderText =
1290 "#version 140\n"
1291 "#extension GL_ARB_separate_shader_objects : enable\n"
1292 "#extension GL_ARB_shading_language_420pack : enable\n"
1293 "layout (location = 0) in vec4 pos;\n"
1294 "layout (location = 0) out vec4 outColor;\n"
1295 "layout (location = 1) out vec4 outColor2;\n"
1296 "void main() {\n"
1297 " gl_Position = pos;\n"
1298 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1299 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1300 "}\n";
1301
1302
1303 static const char *fragShaderText =
1304 //"#version 140\n"
1305 "#version 330\n"
1306 "#extension GL_ARB_separate_shader_objects : enable\n"
1307 "#extension GL_ARB_shading_language_420pack : enable\n"
1308 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1309 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1310 "layout (location = 0) in vec4 color;\n"
1311 "layout (location = 1) in vec4 color2;\n"
1312 "void main() {\n"
1313 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1314 " float dist_squared = dot(pos, pos);\n"
1315 " if (dist_squared < 100.0)\n"
1316 " discard;\n"
1317 " gl_FragColor = (dist_squared < 400.0)\n"
1318 " ? color\n"
1319 " : color2;\n"
1320 "}\n";
1321
1322 ASSERT_NO_FATAL_FAILURE(InitState());
1323 ASSERT_NO_FATAL_FAILURE(InitViewport());
1324
1325 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001326 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001327
1328 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1329 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1330
1331 XglPipelineObj pipelineobj(m_device);
1332 pipelineobj.AddShader(&vs);
1333 pipelineobj.AddShader(&ps);
1334
1335 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001336 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF42226582014-12-02 17:19:34 -07001337
1338 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1339 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1340 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1341 };
1342
1343 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1344 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001345 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF42226582014-12-02 17:19:34 -07001346 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1347 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001348 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF42226582014-12-02 17:19:34 -07001349 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1350
1351 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1352 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1353 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1354
Tony Barbour664accc2015-01-09 12:55:14 -07001355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1356 XglCommandBufferObj cmdBuffer(m_device);
1357 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1358
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001359 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001360
1361 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1362
1363 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1364#ifdef DUMP_STATE_DOT
1365 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1366 pDSDumpDot((char*)"triTest2.dot");
1367#endif
1368 // render triangle
1369 cmdBuffer.Draw(0, 6, 0, 1);
1370
1371 // finalize recording of the command buffer
1372 cmdBuffer.EndCommandBuffer();
1373 cmdBuffer.QueueCommandBuffer(NULL, 0);
1374
1375 for (int i = 0; i < m_renderTargetCount; i++)
1376 RecordImage(m_renderTargets[i]);
GregF42226582014-12-02 17:19:34 -07001377
1378}
1379
1380
Courtney Goeltzenleuchterd66e41e2014-10-27 13:06:08 -06001381TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001382{
1383 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001384 "#version 140\n"
1385 "#extension GL_ARB_separate_shader_objects : enable\n"
1386 "#extension GL_ARB_shading_language_420pack : enable\n"
1387 "\n"
1388 "layout(binding = 0) uniform buf {\n"
1389 " mat4 MVP;\n"
1390 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001391 "void main() {\n"
1392 " vec2 vertices[3];"
1393 " vertices[0] = vec2(-0.5, -0.5);\n"
1394 " vertices[1] = vec2( 0.5, -0.5);\n"
1395 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001396 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001397 "}\n";
1398
1399 static const char *fragShaderText =
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001400 "#version 130\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001401 "void main() {\n"
Cody Northropbb38ad32014-10-10 15:45:00 -06001402 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001403 "}\n";
1404
Tony Barboure2c58df2014-11-25 13:18:32 -07001405 ASSERT_NO_FATAL_FAILURE(InitState());
1406 ASSERT_NO_FATAL_FAILURE(InitViewport());
1407
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001408 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001409 glm::mat4 Projection = glm::mat4(1.0f);
1410 glm::mat4 View = glm::mat4(1.0f);
1411 glm::mat4 Model = glm::mat4(1.0f);
1412 glm::mat4 MVP = Projection * View * Model;
1413 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1414
Tony Barboure2c58df2014-11-25 13:18:32 -07001415 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1416 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1417 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001418
Tony Barboure2c58df2014-11-25 13:18:32 -07001419 XglPipelineObj pipelineobj(m_device);
1420 pipelineobj.AddShader(&vs);
1421 pipelineobj.AddShader(&ps);
1422
1423 // Create descriptor set and attach the constant buffer to it
1424 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001425 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001426
1427 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1428
Tony Barbour664accc2015-01-09 12:55:14 -07001429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1430 XglCommandBufferObj cmdBuffer(m_device);
1431 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001432
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001433 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001434
1435 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1436
1437 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1438#ifdef DUMP_STATE_DOT
1439 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1440 pDSDumpDot((char*)"triTest2.dot");
1441#endif
1442 // render triangle
1443 cmdBuffer.Draw(0, 6, 0, 1);
1444
1445 // finalize recording of the command buffer
1446 cmdBuffer.EndCommandBuffer();
1447 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1448
1449 for (int i = 0; i < m_renderTargetCount; i++)
1450 RecordImage(m_renderTargets[i]);
1451
1452 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001453}
1454
Tony Barboure2c58df2014-11-25 13:18:32 -07001455TEST_F(XglRenderTest, MixTriangle)
1456{
1457 // This tests location applied to varyings. Notice that we have switched foo
1458 // and bar in the FS. The triangle should be blended with red, green and blue
1459 // corners.
1460 static const char *vertShaderText =
1461 "#version 140\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 "layout (location=0) out vec4 bar;\n"
1465 "layout (location=1) out vec4 foo;\n"
1466 "layout (location=2) out float scale;\n"
1467 "vec2 vertices[3];\n"
1468 "void main() {\n"
1469 " vertices[0] = vec2(-1.0, -1.0);\n"
1470 " vertices[1] = vec2( 1.0, -1.0);\n"
1471 " vertices[2] = vec2( 0.0, 1.0);\n"
1472 "vec4 colors[3];\n"
1473 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1474 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1475 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1476 " foo = colors[gl_VertexID % 3];\n"
1477 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1478 " scale = 1.0;\n"
1479 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1480 "}\n";
1481
1482 static const char *fragShaderText =
1483 "#version 140\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 "layout (location = 1) in vec4 bar;\n"
1487 "layout (location = 0) in vec4 foo;\n"
1488 "layout (location = 2) in float scale;\n"
1489 "void main() {\n"
1490 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1491 "}\n";
1492
1493 ASSERT_NO_FATAL_FAILURE(InitState());
1494 ASSERT_NO_FATAL_FAILURE(InitViewport());
1495
1496 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1497 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1498
1499 XglPipelineObj pipelineobj(m_device);
1500 pipelineobj.AddShader(&vs);
1501 pipelineobj.AddShader(&ps);
1502
1503 XglDescriptorSetObj descriptorSet(m_device);
1504
Tony Barbour664accc2015-01-09 12:55:14 -07001505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1506 XglCommandBufferObj cmdBuffer(m_device);
1507 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1508
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001509 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001510
1511 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1512
1513#ifdef DUMP_STATE_DOT
1514 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1515 pDSDumpDot((char*)"triTest2.dot");
1516#endif
1517 // render triangle
1518 cmdBuffer.Draw(0, 3, 0, 1);
1519
1520 // finalize recording of the command buffer
1521 cmdBuffer.EndCommandBuffer();
1522 cmdBuffer.QueueCommandBuffer(NULL, 0);
1523
1524 for (int i = 0; i < m_renderTargetCount; i++)
1525 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001526}
1527
1528TEST_F(XglRenderTest, TriVertFetchAndVertID)
1529{
1530 // This tests that attributes work in the presence of gl_VertexID
1531
1532 static const char *vertShaderText =
1533 "#version 140\n"
1534 "#extension GL_ARB_separate_shader_objects : enable\n"
1535 "#extension GL_ARB_shading_language_420pack : enable\n"
1536 //XYZ1( -1, -1, -1 )
1537 "layout (location = 0) in vec4 pos;\n"
1538 //XYZ1( 0.f, 0.f, 0.f )
1539 "layout (location = 1) in vec4 inColor;\n"
1540 "layout (location = 0) out vec4 outColor;\n"
1541 "void main() {\n"
1542 " outColor = inColor;\n"
1543 " vec4 vertices[3];"
1544 " vertices[gl_VertexID % 3] = pos;\n"
1545 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1546 "}\n";
1547
1548
1549 static const char *fragShaderText =
1550 "#version 140\n"
1551 "#extension GL_ARB_separate_shader_objects : enable\n"
1552 "#extension GL_ARB_shading_language_420pack : enable\n"
1553 "layout (location = 0) in vec4 color;\n"
1554 "void main() {\n"
1555 " gl_FragColor = color;\n"
1556 "}\n";
1557
1558 ASSERT_NO_FATAL_FAILURE(InitState());
1559 ASSERT_NO_FATAL_FAILURE(InitViewport());
1560
1561 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001562 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001563
1564 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1565 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1566
1567 XglPipelineObj pipelineobj(m_device);
1568 pipelineobj.AddShader(&vs);
1569 pipelineobj.AddShader(&ps);
1570
1571 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001572 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001573
1574 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1575 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1576 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1577 };
1578
1579 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1580 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001581 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001582 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1583 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001584 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001585 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1586
1587 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1588 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1589 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1590
Tony Barbour664accc2015-01-09 12:55:14 -07001591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1592 XglCommandBufferObj cmdBuffer(m_device);
1593 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1594
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001595 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001596
1597 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1598
1599 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1600#ifdef DUMP_STATE_DOT
1601 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1602 pDSDumpDot((char*)"triTest2.dot");
1603#endif
1604 // render triangle
1605 cmdBuffer.Draw(0, 6, 0, 1);
1606
1607 // finalize recording of the command buffer
1608 cmdBuffer.EndCommandBuffer();
1609 cmdBuffer.QueueCommandBuffer(NULL, 0);
1610
1611 for (int i = 0; i < m_renderTargetCount; i++)
1612 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001613}
1614
1615TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1616{
1617 // This tests that attributes work in the presence of gl_VertexID
1618 // and a dead attribute in position 0. Draws a triangle with yellow,
1619 // red and green corners, starting at top and going clockwise.
1620
1621 static const char *vertShaderText =
1622 "#version 140\n"
1623 "#extension GL_ARB_separate_shader_objects : enable\n"
1624 "#extension GL_ARB_shading_language_420pack : enable\n"
1625 //XYZ1( -1, -1, -1 )
1626 "layout (location = 0) in vec4 pos;\n"
1627 //XYZ1( 0.f, 0.f, 0.f )
1628 "layout (location = 1) in vec4 inColor;\n"
1629 "layout (location = 0) out vec4 outColor;\n"
1630 "void main() {\n"
1631 " outColor = inColor;\n"
1632 " vec2 vertices[3];"
1633 " vertices[0] = vec2(-1.0, -1.0);\n"
1634 " vertices[1] = vec2( 1.0, -1.0);\n"
1635 " vertices[2] = vec2( 0.0, 1.0);\n"
1636 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1637 "}\n";
1638
1639
1640 static const char *fragShaderText =
1641 "#version 140\n"
1642 "#extension GL_ARB_separate_shader_objects : enable\n"
1643 "#extension GL_ARB_shading_language_420pack : enable\n"
1644 "layout (location = 0) in vec4 color;\n"
1645 "void main() {\n"
1646 " gl_FragColor = color;\n"
1647 "}\n";
1648
1649 ASSERT_NO_FATAL_FAILURE(InitState());
1650 ASSERT_NO_FATAL_FAILURE(InitViewport());
1651
1652 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001653 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001654
1655 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1656 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1657
1658 XglPipelineObj pipelineobj(m_device);
1659 pipelineobj.AddShader(&vs);
1660 pipelineobj.AddShader(&ps);
1661
1662 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001663 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001664
1665 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1666 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1667 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1668 };
1669
1670 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1671 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001672 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001673 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1674 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001675 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001676 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1677
1678 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1679 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1680 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1681
Tony Barbour664accc2015-01-09 12:55:14 -07001682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1683 XglCommandBufferObj cmdBuffer(m_device);
1684 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001685
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001686 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001687
1688 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1689
1690 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1691#ifdef DUMP_STATE_DOT
1692 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1693 pDSDumpDot((char*)"triTest2.dot");
1694#endif
1695 // render triangle
1696 cmdBuffer.Draw(0, 6, 0, 1);
1697
1698 // finalize recording of the command buffer
1699 cmdBuffer.EndCommandBuffer();
1700 cmdBuffer.QueueCommandBuffer(NULL, 0);
1701
1702 for (int i = 0; i < m_renderTargetCount; i++)
1703 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001704}
1705
1706TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001707{
1708 static const char *vertShaderText =
1709 "#version 140\n"
1710 "layout (std140) uniform bufferVals {\n"
1711 " mat4 mvp;\n"
1712 "} myBufferVals;\n"
1713 "in vec4 pos;\n"
1714 "in vec4 inColor;\n"
1715 "out vec4 outColor;\n"
1716 "void main() {\n"
1717 " outColor = inColor;\n"
1718 " gl_Position = myBufferVals.mvp * pos;\n"
1719 "}\n";
1720
1721 static const char *fragShaderText =
1722 "#version 130\n"
1723 "in vec4 color;\n"
1724 "void main() {\n"
1725 " gl_FragColor = color;\n"
1726 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001727 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001728
Tony Barboure2c58df2014-11-25 13:18:32 -07001729 glm::mat4 View = glm::lookAt(
1730 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1731 glm::vec3(0,0,0), // and looks at the origin
1732 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1733 );
1734
1735 glm::mat4 Model = glm::mat4(1.0f);
1736
1737 glm::mat4 MVP = Projection * View * Model;
1738
1739 ASSERT_NO_FATAL_FAILURE(InitState());
1740 ASSERT_NO_FATAL_FAILURE(InitViewport());
1741 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1742
1743 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1744 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1745
1746 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1747
1748 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1749 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1750 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1751
Tony Barboure2c58df2014-11-25 13:18:32 -07001752 XglPipelineObj pipelineobj(m_device);
1753 pipelineobj.AddShader(&vs);
1754 pipelineobj.AddShader(&ps);
1755
Tony Barbourf52346d2015-01-16 14:27:35 -07001756 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1757 ds_state.depthTestEnable = XGL_TRUE;
1758 ds_state.depthWriteEnable = XGL_TRUE;
1759 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1760 ds_state.depthBoundsEnable = XGL_FALSE;
1761 ds_state.stencilTestEnable = XGL_FALSE;
1762 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1763 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1764 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1765 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001766 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07001767 ds_state.front = ds_state.back;
1768 pipelineobj.SetDepthStencil(&ds_state);
1769
Tony Barboure2c58df2014-11-25 13:18:32 -07001770 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001771 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001772
1773 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1774 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1775
1776 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1777 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1778 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1779 };
1780
1781 // this is the current description of g_vbData
1782 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1783 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001784 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001785 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1786 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001787 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07001788 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1789
1790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1791 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1792 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1793
Tony Barbour1fde6942015-01-09 10:06:53 -07001794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1795 XglCommandBufferObj cmdBuffer(m_device);
1796 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001797
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001798 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour1fde6942015-01-09 10:06:53 -07001799 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001800
Tony Barbour1fde6942015-01-09 10:06:53 -07001801 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1802#ifdef DUMP_STATE_DOT
1803 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1804 pDSDumpDot((char*)"triTest2.dot");
1805#endif
1806 // render triangle
1807 cmdBuffer.Draw(0, 36, 0, 1);
1808
1809 // finalize recording of the command buffer
1810 cmdBuffer.EndCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001811 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour1fde6942015-01-09 10:06:53 -07001812
1813 for (int i = 0; i < m_renderTargetCount; i++)
1814 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001815}
1816
Tony Barboure2c58df2014-11-25 13:18:32 -07001817TEST_F(XglRenderTest, VSTexture)
1818{
1819 // The expected result from this test is a green and red triangle;
1820 // one red vertex on the left, two green vertices on the right.
1821 static const char *vertShaderText =
1822 "#version 130\n"
1823 "out vec4 texColor;\n"
1824 "uniform sampler2D surface;\n"
1825 "void main() {\n"
1826 " vec2 vertices[3];"
1827 " vertices[0] = vec2(-0.5, -0.5);\n"
1828 " vertices[1] = vec2( 0.5, -0.5);\n"
1829 " vertices[2] = vec2( 0.5, 0.5);\n"
1830 " vec2 positions[3];"
1831 " positions[0] = vec2( 0.0, 0.0);\n"
1832 " positions[1] = vec2( 0.25, 0.1);\n"
1833 " positions[2] = vec2( 0.1, 0.25);\n"
1834 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1835 " texColor = textureLod(surface, samplePos, 0.0);\n"
1836 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1837 "}\n";
1838
1839 static const char *fragShaderText =
1840 "#version 130\n"
1841 "in vec4 texColor;\n"
1842 "void main() {\n"
1843 " gl_FragColor = texColor;\n"
1844 "}\n";
1845
1846 ASSERT_NO_FATAL_FAILURE(InitState());
1847 ASSERT_NO_FATAL_FAILURE(InitViewport());
1848
1849 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1850 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1851 XglSamplerObj sampler(m_device);
1852 XglTextureObj texture(m_device);
1853
Tony Barboure2c58df2014-11-25 13:18:32 -07001854 XglPipelineObj pipelineobj(m_device);
1855 pipelineobj.AddShader(&vs);
1856 pipelineobj.AddShader(&ps);
1857
1858 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001859 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001860
1861 m_memoryRefManager.AddMemoryRef(&texture);
1862
Tony Barbour664accc2015-01-09 12:55:14 -07001863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1864 XglCommandBufferObj cmdBuffer(m_device);
1865 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001866
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001867 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001868
1869 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1870
1871#ifdef DUMP_STATE_DOT
1872 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1873 pDSDumpDot((char*)"triTest2.dot");
1874#endif
1875 // render triangle
1876 cmdBuffer.Draw(0, 3, 0, 1);
1877
1878 // finalize recording of the command buffer
1879 cmdBuffer.EndCommandBuffer();
1880 cmdBuffer.QueueCommandBuffer(NULL, 0);
1881
1882 for (int i = 0; i < m_renderTargetCount; i++)
1883 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001884}
1885TEST_F(XglRenderTest, TexturedTriangle)
1886{
1887 // The expected result from this test is a red and green checkered triangle
1888 static const char *vertShaderText =
1889 "#version 140\n"
1890 "#extension GL_ARB_separate_shader_objects : enable\n"
1891 "#extension GL_ARB_shading_language_420pack : enable\n"
1892 "layout (location = 0) out vec2 samplePos;\n"
1893 "void main() {\n"
1894 " vec2 vertices[3];"
1895 " vertices[0] = vec2(-0.5, -0.5);\n"
1896 " vertices[1] = vec2( 0.5, -0.5);\n"
1897 " vertices[2] = vec2( 0.5, 0.5);\n"
1898 " vec2 positions[3];"
1899 " positions[0] = vec2( 0.0, 0.0);\n"
1900 " positions[1] = vec2( 1.0, 0.0);\n"
1901 " positions[2] = vec2( 1.0, 1.0);\n"
1902 " samplePos = positions[gl_VertexID % 3];\n"
1903 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1904 "}\n";
1905
1906 static const char *fragShaderText =
1907 "#version 140\n"
1908 "#extension GL_ARB_separate_shader_objects : enable\n"
1909 "#extension GL_ARB_shading_language_420pack : enable\n"
1910 "layout (location = 0) in vec2 samplePos;\n"
1911 "layout (binding = 0) uniform sampler2D surface;\n"
1912 "layout (location=0) out vec4 outColor;\n"
1913 "void main() {\n"
1914 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1915 " outColor = texColor;\n"
1916 "}\n";
1917
1918 ASSERT_NO_FATAL_FAILURE(InitState());
1919 ASSERT_NO_FATAL_FAILURE(InitViewport());
1920
1921 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1922 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1923 XglSamplerObj sampler(m_device);
1924 XglTextureObj texture(m_device);
1925
Tony Barboure2c58df2014-11-25 13:18:32 -07001926 XglPipelineObj pipelineobj(m_device);
1927 pipelineobj.AddShader(&vs);
1928 pipelineobj.AddShader(&ps);
1929
1930 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001931 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001932
1933 m_memoryRefManager.AddMemoryRef(&texture);
1934
Tony Barbour664accc2015-01-09 12:55:14 -07001935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1936 XglCommandBufferObj cmdBuffer(m_device);
1937 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1938
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001939 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07001940
1941 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1942
1943#ifdef DUMP_STATE_DOT
1944 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1945 pDSDumpDot((char*)"triTest2.dot");
1946#endif
1947 // render triangle
1948 cmdBuffer.Draw(0, 3, 0, 1);
1949
1950 // finalize recording of the command buffer
1951 cmdBuffer.EndCommandBuffer();
1952 cmdBuffer.QueueCommandBuffer(NULL, 0);
1953
1954 for (int i = 0; i < m_renderTargetCount; i++)
1955 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001956}
1957TEST_F(XglRenderTest, TexturedTriangleClip)
1958{
1959 // The expected result from this test is a red and green checkered triangle
1960 static const char *vertShaderText =
1961 "#version 330\n"
1962 "#extension GL_ARB_separate_shader_objects : enable\n"
1963 "#extension GL_ARB_shading_language_420pack : enable\n"
1964 "layout (location = 0) out vec2 samplePos;\n"
1965 "out gl_PerVertex {\n"
1966 " vec4 gl_Position;\n"
1967 " float gl_ClipDistance[1];\n"
1968 "};\n"
1969 "void main() {\n"
1970 " vec2 vertices[3];"
1971 " vertices[0] = vec2(-0.5, -0.5);\n"
1972 " vertices[1] = vec2( 0.5, -0.5);\n"
1973 " vertices[2] = vec2( 0.5, 0.5);\n"
1974 " vec2 positions[3];"
1975 " positions[0] = vec2( 0.0, 0.0);\n"
1976 " positions[1] = vec2( 1.0, 0.0);\n"
1977 " positions[2] = vec2( 1.0, 1.0);\n"
1978 " float dists[3];\n"
1979 " dists[0] = 1.0;\n"
1980 " dists[1] = 1.0;\n"
1981 " dists[2] = -1.0;\n"
1982 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\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 + gl_ClipDistance[0]);\n"
1996 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1997 " outColor = texColor;\n"
1998 "}\n";
1999
2000
2001 ASSERT_NO_FATAL_FAILURE(InitState());
2002 ASSERT_NO_FATAL_FAILURE(InitViewport());
2003
2004 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2005 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2006 XglSamplerObj sampler(m_device);
2007 XglTextureObj texture(m_device);
2008
Tony Barboure2c58df2014-11-25 13:18:32 -07002009 XglPipelineObj pipelineobj(m_device);
2010 pipelineobj.AddShader(&vs);
2011 pipelineobj.AddShader(&ps);
2012
2013 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002014 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002015
2016 m_memoryRefManager.AddMemoryRef(&texture);
2017
Tony Barbour664accc2015-01-09 12:55:14 -07002018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2019 XglCommandBufferObj cmdBuffer(m_device);
2020 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2021
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002022 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002023
2024 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2025
2026#ifdef DUMP_STATE_DOT
2027 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2028 pDSDumpDot((char*)"triTest2.dot");
2029#endif
2030 // render triangle
2031 cmdBuffer.Draw(0, 3, 0, 1);
2032
2033 // finalize recording of the command buffer
2034 cmdBuffer.EndCommandBuffer();
2035 cmdBuffer.QueueCommandBuffer(NULL, 0);
2036
2037 for (int i = 0; i < m_renderTargetCount; i++)
2038 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002039}
2040TEST_F(XglRenderTest, FSTriangle)
2041{
2042 // The expected result from this test is a red and green checkered triangle
2043 static const char *vertShaderText =
2044 "#version 140\n"
2045 "#extension GL_ARB_separate_shader_objects : enable\n"
2046 "#extension GL_ARB_shading_language_420pack : enable\n"
2047 "layout (location = 0) out vec2 samplePos;\n"
2048 "void main() {\n"
2049 " vec2 vertices[3];"
2050 " vertices[0] = vec2(-0.5, -0.5);\n"
2051 " vertices[1] = vec2( 0.5, -0.5);\n"
2052 " vertices[2] = vec2( 0.5, 0.5);\n"
2053 " vec2 positions[3];"
2054 " positions[0] = vec2( 0.0, 0.0);\n"
2055 " positions[1] = vec2( 1.0, 0.0);\n"
2056 " positions[2] = vec2( 1.0, 1.0);\n"
2057 " samplePos = positions[gl_VertexID % 3];\n"
2058 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2059 "}\n";
2060
2061 static const char *fragShaderText =
2062 "#version 140\n"
2063 "#extension GL_ARB_separate_shader_objects : enable\n"
2064 "#extension GL_ARB_shading_language_420pack : enable\n"
2065 "layout (location = 0) in vec2 samplePos;\n"
2066 "layout (binding = 0) uniform sampler2D surface;\n"
2067 "layout (location=0) out vec4 outColor;\n"
2068 "void main() {\n"
2069 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2070 " outColor = texColor;\n"
2071 "}\n";
2072
2073 ASSERT_NO_FATAL_FAILURE(InitState());
2074 ASSERT_NO_FATAL_FAILURE(InitViewport());
2075
2076 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2077 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2078 XglSamplerObj sampler(m_device);
2079 XglTextureObj texture(m_device);
2080
Tony Barboure2c58df2014-11-25 13:18:32 -07002081 XglPipelineObj pipelineobj(m_device);
2082 pipelineobj.AddShader(&vs);
2083 pipelineobj.AddShader(&ps);
2084
2085 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002086 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002087
2088 m_memoryRefManager.AddMemoryRef(&texture);
2089
Tony Barbour664accc2015-01-09 12:55:14 -07002090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2091 XglCommandBufferObj cmdBuffer(m_device);
2092 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2093
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002094 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002095
2096 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2097
2098#ifdef DUMP_STATE_DOT
2099 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2100 pDSDumpDot((char*)"triTest2.dot");
2101#endif
2102 // render triangle
2103 cmdBuffer.Draw(0, 3, 0, 1);
2104
2105 // finalize recording of the command buffer
2106 cmdBuffer.EndCommandBuffer();
2107 cmdBuffer.QueueCommandBuffer(NULL, 0);
2108
2109 for (int i = 0; i < m_renderTargetCount; i++)
2110 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002111}
2112TEST_F(XglRenderTest, SamplerBindingsTriangle)
2113{
2114 // This test sets bindings on the samplers
2115 // For now we are asserting that sampler and texture pairs
2116 // march in lock step, and are set via GLSL binding. This can
2117 // and will probably change.
2118 // The sampler bindings should match the sampler and texture slot
2119 // number set up by the application.
2120 // This test will result in a blue triangle
2121 static const char *vertShaderText =
2122 "#version 140\n"
2123 "#extension GL_ARB_separate_shader_objects : enable\n"
2124 "#extension GL_ARB_shading_language_420pack : enable\n"
2125 "layout (location = 0) out vec4 samplePos;\n"
2126 "void main() {\n"
2127 " vec2 vertices[3];"
2128 " vertices[0] = vec2(-0.5, -0.5);\n"
2129 " vertices[1] = vec2( 0.5, -0.5);\n"
2130 " vertices[2] = vec2( 0.5, 0.5);\n"
2131 " vec2 positions[3];"
2132 " positions[0] = vec2( 0.0, 0.0);\n"
2133 " positions[1] = vec2( 1.0, 0.0);\n"
2134 " positions[2] = vec2( 1.0, 1.0);\n"
2135 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2136 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2137 "}\n";
2138
2139 static const char *fragShaderText =
2140 "#version 140\n"
2141 "#extension GL_ARB_separate_shader_objects : enable\n"
2142 "#extension GL_ARB_shading_language_420pack : enable\n"
2143 "layout (location = 0) in vec4 samplePos;\n"
2144 "layout (binding = 0) uniform sampler2D surface0;\n"
2145 "layout (binding = 1) uniform sampler2D surface1;\n"
2146 "layout (binding = 12) uniform sampler2D surface2;\n"
2147 "void main() {\n"
2148 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2149 "}\n";
2150
2151 ASSERT_NO_FATAL_FAILURE(InitState());
2152 ASSERT_NO_FATAL_FAILURE(InitViewport());
2153
2154 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2155 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2156
2157 XglSamplerObj sampler1(m_device);
2158 XglSamplerObj sampler2(m_device);
2159 XglSamplerObj sampler3(m_device);
2160
2161 XglTextureObj texture1(m_device); // Red
2162 texture1.ChangeColors(0xffff0000,0xffff0000);
2163 XglTextureObj texture2(m_device); // Green
2164 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2165 XglTextureObj texture3(m_device); // Blue
2166 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2167
Tony Barboure2c58df2014-11-25 13:18:32 -07002168 XglPipelineObj pipelineobj(m_device);
2169 pipelineobj.AddShader(&vs);
2170 pipelineobj.AddShader(&ps);
2171
2172 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002173 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2174 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2175 for (int i = 0; i < 10; i++)
2176 descriptorSet.AppendDummy();
2177 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002178
2179 m_memoryRefManager.AddMemoryRef(&texture1);
2180 m_memoryRefManager.AddMemoryRef(&texture2);
2181 m_memoryRefManager.AddMemoryRef(&texture3);
2182
Tony Barbour664accc2015-01-09 12:55:14 -07002183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2184 XglCommandBufferObj cmdBuffer(m_device);
2185 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2186
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002187 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002188
2189 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2190
2191#ifdef DUMP_STATE_DOT
2192 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2193 pDSDumpDot((char*)"triTest2.dot");
2194#endif
2195 // render triangle
2196 cmdBuffer.Draw(0, 3, 0, 1);
2197
2198 // finalize recording of the command buffer
2199 cmdBuffer.EndCommandBuffer();
2200 cmdBuffer.QueueCommandBuffer(NULL, 0);
2201
2202 for (int i = 0; i < m_renderTargetCount; i++)
2203 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002204
2205}
2206
2207TEST_F(XglRenderTest, TriangleVSUniformBlock)
2208{
2209 // The expected result from this test is a blue triangle
2210
2211 static const char *vertShaderText =
2212 "#version 140\n"
2213 "#extension GL_ARB_separate_shader_objects : enable\n"
2214 "#extension GL_ARB_shading_language_420pack : enable\n"
2215 "layout (location = 0) out vec4 outColor;\n"
2216 "layout (std140, binding = 0) uniform bufferVals {\n"
2217 " vec4 red;\n"
2218 " vec4 green;\n"
2219 " vec4 blue;\n"
2220 " vec4 white;\n"
2221 "} myBufferVals;\n"
2222 "void main() {\n"
2223 " vec2 vertices[3];"
2224 " vertices[0] = vec2(-0.5, -0.5);\n"
2225 " vertices[1] = vec2( 0.5, -0.5);\n"
2226 " vertices[2] = vec2( 0.5, 0.5);\n"
2227 " outColor = myBufferVals.blue;\n"
2228 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2229 "}\n";
2230
2231 static const char *fragShaderText =
2232 "#version 140\n"
2233 "#extension GL_ARB_separate_shader_objects : enable\n"
2234 "#extension GL_ARB_shading_language_420pack : enable\n"
2235 "layout (location = 0) in vec4 inColor;\n"
2236 "void main() {\n"
2237 " gl_FragColor = inColor;\n"
2238 "}\n";
2239
2240 ASSERT_NO_FATAL_FAILURE(InitState());
2241 ASSERT_NO_FATAL_FAILURE(InitViewport());
2242
2243 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2244 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2245
2246 // Let's populate our buffer with the following:
2247 // vec4 red;
2248 // vec4 green;
2249 // vec4 blue;
2250 // vec4 white;
2251 const int valCount = 4 * 4;
2252 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2253 0.0, 1.0, 0.0, 1.0,
2254 0.0, 0.0, 1.0, 1.0,
2255 1.0, 1.0, 1.0, 1.0 };
2256
2257 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002258
2259 XglPipelineObj pipelineobj(m_device);
2260 pipelineobj.AddShader(&vs);
2261 pipelineobj.AddShader(&ps);
2262
2263 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002264 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002265
Tony Barbour664accc2015-01-09 12:55:14 -07002266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2267 XglCommandBufferObj cmdBuffer(m_device);
2268 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2269
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002270 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002271
2272 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2273
2274#ifdef DUMP_STATE_DOT
2275 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2276 pDSDumpDot((char*)"triTest2.dot");
2277#endif
2278 // render triangle
2279 cmdBuffer.Draw(0, 3, 0, 1);
2280
2281 // finalize recording of the command buffer
2282 cmdBuffer.EndCommandBuffer();
2283 cmdBuffer.QueueCommandBuffer(NULL, 0);
2284
2285 for (int i = 0; i < m_renderTargetCount; i++)
2286 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002287
2288}
2289
2290TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2291{
2292 // This test allows the shader to select which buffer it is
2293 // pulling from using layout binding qualifier.
2294 // There are corresponding changes in the compiler stack that
2295 // will select the buffer using binding directly.
2296 // The binding number should match the slot number set up by
2297 // the application.
2298 // The expected result from this test is a purple triangle
2299
2300 static const char *vertShaderText =
2301 "#version 140\n"
2302 "#extension GL_ARB_separate_shader_objects : enable\n"
2303 "#extension GL_ARB_shading_language_420pack : enable\n"
2304 "void main() {\n"
2305 " vec2 vertices[3];"
2306 " vertices[0] = vec2(-0.5, -0.5);\n"
2307 " vertices[1] = vec2( 0.5, -0.5);\n"
2308 " vertices[2] = vec2( 0.5, 0.5);\n"
2309 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2310 "}\n";
2311
2312 static const char *fragShaderText =
2313 "#version 140\n"
2314 "#extension GL_ARB_separate_shader_objects : enable\n"
2315 "#extension GL_ARB_shading_language_420pack : enable\n"
2316 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2317 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2318 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002319 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barboure2c58df2014-11-25 13:18:32 -07002320 "void main() {\n"
2321 " gl_FragColor = myBlueVal.color;\n"
2322 " gl_FragColor += myRedVal.color;\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 // We're going to create a number of uniform buffers, and then allow
2332 // the shader to select which it wants to read from with a binding
2333
2334 // Let's populate the buffers with a single color each:
2335 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2336 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2337 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002338 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002339
2340 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2341 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2342 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2343 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2344
2345 const int redCount = sizeof(redVals) / sizeof(float);
2346 const int greenCount = sizeof(greenVals) / sizeof(float);
2347 const int blueCount = sizeof(blueVals) / sizeof(float);
2348 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2349
2350 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002351
2352 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002353
2354 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002355
2356 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002357
2358 XglPipelineObj pipelineobj(m_device);
2359 pipelineobj.AddShader(&vs);
2360 pipelineobj.AddShader(&ps);
2361
2362 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002363 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2364 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2365 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2366 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002367
Tony Barbour664accc2015-01-09 12:55:14 -07002368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2369 XglCommandBufferObj cmdBuffer(m_device);
2370 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002371
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002372 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002373
2374 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2375
2376#ifdef DUMP_STATE_DOT
2377 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2378 pDSDumpDot((char*)"triTest2.dot");
2379#endif
2380 // render triangle
2381 cmdBuffer.Draw(0, 3, 0, 1);
2382
2383 // finalize recording of the command buffer
2384 cmdBuffer.EndCommandBuffer();
2385 cmdBuffer.QueueCommandBuffer(NULL, 0);
2386
2387 for (int i = 0; i < m_renderTargetCount; i++)
2388 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002389}
2390
2391TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2392{
2393 // This test is the same as TriangleFSUniformBlockBinding, but
2394 // it does not provide an instance name.
2395 // The expected result from this test is a purple triangle
2396
2397 static const char *vertShaderText =
2398 "#version 140\n"
2399 "#extension GL_ARB_separate_shader_objects : enable\n"
2400 "#extension GL_ARB_shading_language_420pack : enable\n"
2401 "void main() {\n"
2402 " vec2 vertices[3];"
2403 " vertices[0] = vec2(-0.5, -0.5);\n"
2404 " vertices[1] = vec2( 0.5, -0.5);\n"
2405 " vertices[2] = vec2( 0.5, 0.5);\n"
2406 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2407 "}\n";
2408
2409 static const char *fragShaderText =
2410 "#version 430\n"
2411 "#extension GL_ARB_separate_shader_objects : enable\n"
2412 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002413 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2414 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2415 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002416 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002417 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002418 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002419 " outColor = blue;\n"
2420 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002421 "}\n";
2422 ASSERT_NO_FATAL_FAILURE(InitState());
2423 ASSERT_NO_FATAL_FAILURE(InitViewport());
2424
2425 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2426 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2427
2428 // We're going to create a number of uniform buffers, and then allow
2429 // the shader to select which it wants to read from with a binding
2430
2431 // Let's populate the buffers with a single color each:
2432 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2433 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2434 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2435 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2436
2437 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2438 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2439 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2440 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2441
2442 const int redCount = sizeof(redVals) / sizeof(float);
2443 const int greenCount = sizeof(greenVals) / sizeof(float);
2444 const int blueCount = sizeof(blueVals) / sizeof(float);
2445 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2446
2447 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002448
2449 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002450
2451 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002452
2453 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002454
2455 XglPipelineObj pipelineobj(m_device);
2456 pipelineobj.AddShader(&vs);
2457 pipelineobj.AddShader(&ps);
2458
2459 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002460 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2461 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2462 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2463 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002464
Tony Barbour664accc2015-01-09 12:55:14 -07002465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2466 XglCommandBufferObj cmdBuffer(m_device);
2467 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2468
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002469 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002470
2471 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2472
2473#ifdef DUMP_STATE_DOT
2474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2475 pDSDumpDot((char*)"triTest2.dot");
2476#endif
2477 // render triangle
2478 cmdBuffer.Draw(0, 3, 0, 1);
2479
2480 // finalize recording of the command buffer
2481 cmdBuffer.EndCommandBuffer();
2482 cmdBuffer.QueueCommandBuffer(NULL, 0);
2483
2484 for (int i = 0; i < m_renderTargetCount; i++)
2485 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002486
2487}
2488
2489TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2490{
2491 static const char *vertShaderText =
2492 "#version 140\n"
2493 "#extension GL_ARB_separate_shader_objects : enable\n"
2494 "#extension GL_ARB_shading_language_420pack : enable\n"
2495 "layout (std140, binding=0) uniform bufferVals {\n"
2496 " mat4 mvp;\n"
2497 "} myBufferVals;\n"
2498 "layout (location=0) in vec4 pos;\n"
2499 "layout (location=0) out vec2 UV;\n"
2500 "void main() {\n"
2501 " vec2 positions[3];"
2502 " positions[0] = vec2( 0.0, 0.0);\n"
2503 " positions[1] = vec2( 0.25, 0.1);\n"
2504 " positions[2] = vec2( 0.1, 0.25);\n"
2505 " UV = positions[gl_VertexID % 3];\n"
2506 " gl_Position = myBufferVals.mvp * pos;\n"
2507 "}\n";
2508
2509 static const char *fragShaderText =
2510 "#version 140\n"
2511 "#extension GL_ARB_separate_shader_objects : enable\n"
2512 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002513 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002514 "layout (location=0) out vec4 outColor;\n"
2515 "layout (location=0) in vec2 UV;\n"
2516 "void main() {\n"
2517 " outColor= textureLod(surface, UV, 0.0);\n"
2518 "}\n";
2519 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2520
2521 glm::mat4 View = glm::lookAt(
2522 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2523 glm::vec3(0,0,0), // and looks at the origin
2524 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2525 );
2526
2527 glm::mat4 Model = glm::mat4(1.0f);
2528
2529 glm::mat4 MVP = Projection * View * Model;
2530
2531
2532 ASSERT_NO_FATAL_FAILURE(InitState());
2533 ASSERT_NO_FATAL_FAILURE(InitViewport());
2534 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2535
2536 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2537 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002538 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002539
2540 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2541
2542 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2543 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2544 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2545 XglSamplerObj sampler(m_device);
2546 XglTextureObj texture(m_device);
2547
Tony Barboure2c58df2014-11-25 13:18:32 -07002548 XglPipelineObj pipelineobj(m_device);
2549 pipelineobj.AddShader(&vs);
2550 pipelineobj.AddShader(&ps);
2551
2552 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002553 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2554 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002555
2556 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2557 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2558 m_memoryRefManager.AddMemoryRef(&texture);
2559
2560 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2561 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2562 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2563 };
2564
2565 // this is the current description of g_vbData
2566 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2567 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07002568 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07002569 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2570 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayesa058eee2015-01-23 08:51:43 -07002571 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barboure2c58df2014-11-25 13:18:32 -07002572 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2573
2574 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2575 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2576 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2577
Tony Barbourf52346d2015-01-16 14:27:35 -07002578 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2579 ds_state.depthTestEnable = XGL_TRUE;
2580 ds_state.depthWriteEnable = XGL_TRUE;
2581 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2582 ds_state.depthBoundsEnable = XGL_FALSE;
2583 ds_state.stencilTestEnable = XGL_FALSE;
2584 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2585 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2586 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2587 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayesa058eee2015-01-23 08:51:43 -07002588 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07002589 ds_state.front = ds_state.back;
2590 pipelineobj.SetDepthStencil(&ds_state);
2591
Tony Barbour664accc2015-01-09 12:55:14 -07002592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2593 XglCommandBufferObj cmdBuffer(m_device);
2594 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002595
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002596 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002597 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2598
2599 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2600#ifdef DUMP_STATE_DOT
2601 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2602 pDSDumpDot((char*)"triTest2.dot");
2603#endif
2604 // render triangle
2605 cmdBuffer.Draw(0, 36, 0, 1);
2606
2607 // finalize recording of the command buffer
2608 cmdBuffer.EndCommandBuffer();
2609 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2610
2611 for (int i = 0; i < m_renderTargetCount; i++)
2612 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002613
2614}
Cody Northropf1990a92014-12-09 11:17:01 -07002615
2616TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2617{
2618 // This test mixes binding slots of textures and buffers, ensuring
2619 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002620 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002621 // you can modify it to move the desired result around.
2622
2623 static const char *vertShaderText =
2624 "#version 140\n"
2625 "#extension GL_ARB_separate_shader_objects : enable\n"
2626 "#extension GL_ARB_shading_language_420pack : enable\n"
2627 "void main() {\n"
2628 " vec2 vertices[3];"
2629 " vertices[0] = vec2(-0.5, -0.5);\n"
2630 " vertices[1] = vec2( 0.5, -0.5);\n"
2631 " vertices[2] = vec2( 0.5, 0.5);\n"
2632 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2633 "}\n";
2634
2635 static const char *fragShaderText =
2636 "#version 430\n"
2637 "#extension GL_ARB_separate_shader_objects : enable\n"
2638 "#extension GL_ARB_shading_language_420pack : enable\n"
2639 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002640 "layout (binding = 3) uniform sampler2D surface1;\n"
2641 "layout (binding = 1) uniform sampler2D surface2;\n"
2642 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002643
Cody Northropb110b4f2014-12-09 13:59:39 -07002644
Chia-I Wu11078b02015-01-04 16:27:24 +08002645 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2646 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2647 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2648 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002649 "layout (location = 0) out vec4 outColor;\n"
2650 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002651 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002652 " outColor += white * vec4(0.00001);\n"
2653 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002654 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002655 "}\n";
2656 ASSERT_NO_FATAL_FAILURE(InitState());
2657 ASSERT_NO_FATAL_FAILURE(InitViewport());
2658
2659 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2660 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2661
Cody Northropf1990a92014-12-09 11:17:01 -07002662 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2663 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2664 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2665 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2666
2667 const int redCount = sizeof(redVals) / sizeof(float);
2668 const int greenCount = sizeof(greenVals) / sizeof(float);
2669 const int blueCount = sizeof(blueVals) / sizeof(float);
2670 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2671
2672 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002673 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002674 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002675 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002676
2677 XglSamplerObj sampler0(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002678 XglTextureObj texture0(m_device); // Light Red
2679 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropf1990a92014-12-09 11:17:01 -07002680 XglSamplerObj sampler2(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002681 XglTextureObj texture2(m_device); // Light Blue
2682 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropf1990a92014-12-09 11:17:01 -07002683 XglSamplerObj sampler4(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002684 XglTextureObj texture4(m_device); // Light Green
2685 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropb110b4f2014-12-09 13:59:39 -07002686
2687 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2688 // TODO: Get back here ASAP and understand why.
2689 XglSamplerObj sampler7(m_device);
2690 XglTextureObj texture7(m_device); // Red and Blue
2691 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropf1990a92014-12-09 11:17:01 -07002692
2693 XglPipelineObj pipelineobj(m_device);
2694 pipelineobj.AddShader(&vs);
2695 pipelineobj.AddShader(&ps);
2696
2697 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002698 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2699 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2700 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2701 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2702 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2703 // swap blue and green
2704 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2705 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2706 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002707
2708 m_memoryRefManager.AddMemoryRef(&texture0);
2709 m_memoryRefManager.AddMemoryRef(&texture2);
2710 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002711 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropf1990a92014-12-09 11:17:01 -07002712
Tony Barbour664accc2015-01-09 12:55:14 -07002713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2714 XglCommandBufferObj cmdBuffer(m_device);
2715 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropf1990a92014-12-09 11:17:01 -07002716
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002717 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002718
2719 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2720
2721#ifdef DUMP_STATE_DOT
2722 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2723 pDSDumpDot((char*)"triTest2.dot");
2724#endif
2725 // render triangle
2726 cmdBuffer.Draw(0, 3, 0, 1);
2727
2728 // finalize recording of the command buffer
2729 cmdBuffer.EndCommandBuffer();
2730 cmdBuffer.QueueCommandBuffer(NULL, 0);
2731
2732 for (int i = 0; i < m_renderTargetCount; i++)
2733 RecordImage(m_renderTargets[i]);
Cody Northropf1990a92014-12-09 11:17:01 -07002734
2735}
2736
Cody Northropbd531de2014-12-09 19:08:54 -07002737TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2738{
2739 // This test matches binding slots of textures and buffers, requiring
2740 // the driver to give them distinct number spaces.
2741 // The expected result from this test is a red triangle, although
2742 // you can modify it to move the desired result around.
2743
2744 static const char *vertShaderText =
2745 "#version 140\n"
2746 "#extension GL_ARB_separate_shader_objects : enable\n"
2747 "#extension GL_ARB_shading_language_420pack : enable\n"
2748 "void main() {\n"
2749 " vec2 vertices[3];"
2750 " vertices[0] = vec2(-0.5, -0.5);\n"
2751 " vertices[1] = vec2( 0.5, -0.5);\n"
2752 " vertices[2] = vec2( 0.5, 0.5);\n"
2753 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2754 "}\n";
2755
2756 static const char *fragShaderText =
2757 "#version 430\n"
2758 "#extension GL_ARB_separate_shader_objects : enable\n"
2759 "#extension GL_ARB_shading_language_420pack : enable\n"
2760 "layout (binding = 0) uniform sampler2D surface0;\n"
2761 "layout (binding = 1) uniform sampler2D surface1;\n"
2762 "layout (binding = 2) uniform sampler2D surface2;\n"
2763 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002764 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2765 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2766 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2767 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002768 "layout (location = 0) out vec4 outColor;\n"
2769 "void main() {\n"
2770 " outColor = red;// * vec4(0.00001);\n"
2771 " outColor += white * vec4(0.00001);\n"
2772 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2773 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2774 "}\n";
2775 ASSERT_NO_FATAL_FAILURE(InitState());
2776 ASSERT_NO_FATAL_FAILURE(InitViewport());
2777
2778 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2779 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2780
2781 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2782 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2783 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2784 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2785
2786 const int redCount = sizeof(redVals) / sizeof(float);
2787 const int greenCount = sizeof(greenVals) / sizeof(float);
2788 const int blueCount = sizeof(blueVals) / sizeof(float);
2789 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2790
2791 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002792 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002793 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002794 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002795
2796 XglSamplerObj sampler0(m_device);
2797 XglTextureObj texture0(m_device); // Light Red
2798 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropbd531de2014-12-09 19:08:54 -07002799 XglSamplerObj sampler2(m_device);
2800 XglTextureObj texture2(m_device); // Light Blue
2801 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropbd531de2014-12-09 19:08:54 -07002802 XglSamplerObj sampler4(m_device);
2803 XglTextureObj texture4(m_device); // Light Green
2804 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropbd531de2014-12-09 19:08:54 -07002805 XglSamplerObj sampler7(m_device);
2806 XglTextureObj texture7(m_device); // Red and Blue
2807 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropbd531de2014-12-09 19:08:54 -07002808
2809
2810 XglPipelineObj pipelineobj(m_device);
2811 pipelineobj.AddShader(&vs);
2812 pipelineobj.AddShader(&ps);
2813
2814 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002815 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2816 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2817 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2818 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2819 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2820 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2821 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2822 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002823
2824 m_memoryRefManager.AddMemoryRef(&texture0);
2825 m_memoryRefManager.AddMemoryRef(&texture2);
2826 m_memoryRefManager.AddMemoryRef(&texture4);
2827 m_memoryRefManager.AddMemoryRef(&texture7);
2828
Tony Barbour664accc2015-01-09 12:55:14 -07002829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2830 XglCommandBufferObj cmdBuffer(m_device);
2831 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropbd531de2014-12-09 19:08:54 -07002832
Jeremy Hayesd65ae082015-01-14 16:17:08 -07002833 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour664accc2015-01-09 12:55:14 -07002834
2835 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2836
2837#ifdef DUMP_STATE_DOT
2838 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2839 pDSDumpDot((char*)"triTest2.dot");
2840#endif
2841 // render triangle
2842 cmdBuffer.Draw(0, 3, 0, 1);
2843
2844 // finalize recording of the command buffer
2845 cmdBuffer.EndCommandBuffer();
2846 cmdBuffer.QueueCommandBuffer(NULL, 0);
2847
2848 for (int i = 0; i < m_renderTargetCount; i++)
2849 RecordImage(m_renderTargets[i]);
Cody Northropbd531de2014-12-09 19:08:54 -07002850
2851}
2852
Cody Northrop04ad1202014-12-17 15:26:33 -07002853TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2854{
2855 // This test populates a buffer with a variety of different data
2856 // types, then reads them out with a shader.
2857 // The expected result from this test is a green triangle
2858
2859 static const char *vertShaderText =
2860 "#version 140\n"
2861 "#extension GL_ARB_separate_shader_objects : enable\n"
2862 "#extension GL_ARB_shading_language_420pack : enable\n"
2863 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2864 " vec4 fRed;\n"
2865 " vec4 fGreen;\n"
2866 " layout(row_major) mat4 worldToProj;\n"
2867 " layout(row_major) mat4 projToWorld;\n"
2868 " layout(row_major) mat4 worldToView;\n"
2869 " layout(row_major) mat4 viewToProj;\n"
2870 " layout(row_major) mat4 worldToShadow[4];\n"
2871 " float fZero;\n"
2872 " float fOne;\n"
2873 " float fTwo;\n"
2874 " float fThree;\n"
2875 " vec3 fZeroZeroZero;\n"
2876 " float fFour;\n"
2877 " vec3 fZeroZeroOne;\n"
2878 " float fFive;\n"
2879 " vec3 fZeroOneZero;\n"
2880 " float fSix;\n"
2881 " float fSeven;\n"
2882 " float fEight;\n"
2883 " float fNine;\n"
2884 " vec2 fZeroZero;\n"
2885 " vec2 fZeroOne;\n"
2886 " vec4 fBlue;\n"
2887 " vec2 fOneZero;\n"
2888 " vec2 fOneOne;\n"
2889 " vec3 fZeroOneOne;\n"
2890 " float fTen;\n"
2891 " float fEleven;\n"
2892 " float fTwelve;\n"
2893 " vec3 fOneZeroZero;\n"
2894 " vec4 uvOffsets[4];\n"
2895 "};\n"
2896 "layout (location = 0) out vec4 color;"
2897 "void main() {\n"
2898
2899 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2900 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2901 " \n"
2902
2903 // do some exact comparisons, even though we should
2904 // really have an epsilon involved.
2905 " vec4 outColor = right;\n"
2906 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2907 " outColor = wrong;\n"
2908 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2909 " outColor = wrong;\n"
2910 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2911 " outColor = wrong;\n"
2912
2913 " color = outColor;\n"
2914
2915 // generic position stuff
2916 " vec2 vertices;\n"
2917 " int vertexSelector = gl_VertexID;\n"
2918 " if (vertexSelector == 0)\n"
2919 " vertices = vec2(-0.5, -0.5);\n"
2920 " else if (vertexSelector == 1)\n"
2921 " vertices = vec2( 0.5, -0.5);\n"
2922 " else if (vertexSelector == 2)\n"
2923 " vertices = vec2( 0.5, 0.5);\n"
2924 " else\n"
2925 " vertices = vec2( 0.0, 0.0);\n"
2926 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2927 "}\n";
2928
2929 static const char *fragShaderText =
2930 "#version 140\n"
2931 "#extension GL_ARB_separate_shader_objects : enable\n"
2932 "#extension GL_ARB_shading_language_420pack : enable\n"
2933 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2934 " vec4 fRed;\n"
2935 " vec4 fGreen;\n"
2936 " layout(row_major) mat4 worldToProj;\n"
2937 " layout(row_major) mat4 projToWorld;\n"
2938 " layout(row_major) mat4 worldToView;\n"
2939 " layout(row_major) mat4 viewToProj;\n"
2940 " layout(row_major) mat4 worldToShadow[4];\n"
2941 " float fZero;\n"
2942 " float fOne;\n"
2943 " float fTwo;\n"
2944 " float fThree;\n"
2945 " vec3 fZeroZeroZero;\n"
2946 " float fFour;\n"
2947 " vec3 fZeroZeroOne;\n"
2948 " float fFive;\n"
2949 " vec3 fZeroOneZero;\n"
2950 " float fSix;\n"
2951 " float fSeven;\n"
2952 " float fEight;\n"
2953 " float fNine;\n"
2954 " vec2 fZeroZero;\n"
2955 " vec2 fZeroOne;\n"
2956 " vec4 fBlue;\n"
2957 " vec2 fOneZero;\n"
2958 " vec2 fOneOne;\n"
2959 " vec3 fZeroOneOne;\n"
2960 " float fTen;\n"
2961 " float fEleven;\n"
2962 " float fTwelve;\n"
2963 " vec3 fOneZeroZero;\n"
2964 " vec4 uvOffsets[4];\n"
2965 "};\n"
2966 "layout (location = 0) in vec4 color;\n"
2967 "void main() {\n"
2968 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2969 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2970 " \n"
2971
2972 // start with VS value to ensure it passed
2973 " vec4 outColor = color;\n"
2974
2975 // do some exact comparisons, even though we should
2976 // really have an epsilon involved.
2977 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2978 " outColor = wrong;\n"
2979 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2980 " outColor = wrong;\n"
2981 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2982 " outColor = wrong;\n"
2983 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2984 " outColor = wrong;\n"
2985 " if (fTwo != 2.0)\n"
2986 " outColor = wrong;\n"
2987 " if (fOneOne != vec2(1.0, 1.0))\n"
2988 " outColor = wrong;\n"
2989 " if (fTen != 10.0)\n"
2990 " outColor = wrong;\n"
2991 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
2992 " outColor = wrong;\n"
2993 " \n"
2994 " gl_FragColor = outColor;\n"
2995 "}\n";
2996
2997
2998 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
2999 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3000 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3001 0.0, 1.0, 0.0, 1.0, // align
3002 0.0, 0.0, 1.0, 1.0, // align
3003 0.0, 0.0, 0.0, 1.0, // align
3004 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3005 0.0, 2.0, 0.0, 2.0, // align
3006 0.0, 0.0, 2.0, 2.0, // align
3007 0.0, 0.0, 0.0, 2.0, // align
3008 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3009 0.0, 3.0, 0.0, 3.0, // align
3010 0.0, 0.0, 3.0, 3.0, // align
3011 0.0, 0.0, 0.0, 3.0, // align
3012 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3013 0.0, 4.0, 0.0, 4.0, // align
3014 0.0, 0.0, 4.0, 4.0, // align
3015 0.0, 0.0, 0.0, 4.0, // align
3016 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3017 0.0, 5.0, 0.0, 5.0, // align
3018 0.0, 0.0, 5.0, 5.0, // align
3019 0.0, 0.0, 0.0, 5.0, // align
3020 6.0, 0.0, 0.0, 6.0, // align
3021 0.0, 6.0, 0.0, 6.0, // align
3022 0.0, 0.0, 6.0, 6.0, // align
3023 0.0, 0.0, 0.0, 6.0, // align
3024 7.0, 0.0, 0.0, 7.0, // align
3025 0.0, 7.0, 0.0, 7.0, // align
3026 0.0, 0.0, 7.0, 7.0, // align
3027 0.0, 0.0, 0.0, 7.0, // align
3028 8.0, 0.0, 0.0, 8.0, // align
3029 0.0, 8.0, 0.0, 8.0, // align
3030 0.0, 0.0, 8.0, 8.0, // align
3031 0.0, 0.0, 0.0, 8.0, // align
3032 0.0, // float fZero; // align
3033 1.0, // float fOne; // pack
3034 2.0, // float fTwo; // pack
3035 3.0, // float fThree; // pack
3036 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3037 4.0, // float fFour; // pack
3038 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3039 5.0, // float fFive; // pack
3040 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3041 6.0, // float fSix; // pack
3042 7.0, // float fSeven; // align
3043 8.0, // float fEight; // pack
3044 9.0, // float fNine; // pack
3045 0.0, // BUFFER
3046 0.0, 0.0, // vec2 fZeroZero; // align
3047 0.0, 1.0, // vec2 fZeroOne; // pack
3048 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3049 1.0, 0.0, // vec2 fOneZero; // align
3050 1.0, 1.0, // vec2 fOneOne; // pack
3051 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3052 10.0, // float fTen; // pack
3053 11.0, // float fEleven; // align
3054 12.0, // float fTwelve; // pack
3055 0.0, 0.0, // BUFFER
3056 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3057 0.0, // BUFFER
3058 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3059 0.5, 0.6, 0.7, 0.8, // align
3060 0.9, 1.0, 1.1, 1.2, // align
3061 1.3, 1.4, 1.5, 1.6, // align
3062 };
3063
3064 ASSERT_NO_FATAL_FAILURE(InitState());
3065 ASSERT_NO_FATAL_FAILURE(InitViewport());
3066
3067 const int constCount = sizeof(mixedVals) / sizeof(float);
3068
3069 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3070 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3071
3072 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003073
3074 XglPipelineObj pipelineobj(m_device);
3075 pipelineobj.AddShader(&vs);
3076 pipelineobj.AddShader(&ps);
3077
3078 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08003079 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003080
3081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3082 XglCommandBufferObj cmdBuffer(m_device);
3083 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3084
Jeremy Hayesd65ae082015-01-14 16:17:08 -07003085 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop04ad1202014-12-17 15:26:33 -07003086
3087 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3088
3089#ifdef DUMP_STATE_DOT
3090 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3091 pDSDumpDot((char*)"triTest2.dot");
3092#endif
3093 // render triangle
3094 cmdBuffer.Draw(0, 3, 0, 1);
3095
3096 // finalize recording of the command buffer
3097 cmdBuffer.EndCommandBuffer();
3098 cmdBuffer.QueueCommandBuffer(NULL, 0);
3099
3100 for (int i = 0; i < m_renderTargetCount; i++)
3101 RecordImage(m_renderTargets[i]);
3102}
3103
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003104int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003105 int result;
3106
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003107 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003108 XglTestFramework::InitArgs(&argc, argv);
3109
Chia-I Wu6f184292014-12-15 23:57:34 +08003110 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06003111
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003112 result = RUN_ALL_TESTS();
3113
3114 XglTestFramework::Finish();
3115 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003116}