blob: 0a655e8c59bf2f027feeea4e1e7d951f1228a68d [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
75#include "xgldevice.h"
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -060076#include "xglimage.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080077#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060078
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060079#define GLM_FORCE_RADIANS
80#include "glm/glm.hpp"
81#include <glm/gtc/matrix_transform.hpp>
82
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060083#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084#ifdef DEBUG_CALLBACK
85XGL_VOID XGLAPI myDbgFunc(
86 XGL_DBG_MSG_TYPE msgType,
87 XGL_VALIDATION_LEVEL validationLevel,
88 XGL_BASE_OBJECT srcObject,
89 XGL_SIZE location,
90 XGL_INT msgCode,
91 const XGL_CHAR* pMsg,
92 XGL_VOID* pUserData)
93{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070094 switch (msgType)
95 {
96 case XGL_DBG_MSG_WARNING:
97 printf("CALLBACK WARNING : %s\n", pMsg);
98 break;
99 case XGL_DBG_MSG_ERROR:
100 printf("CALLBACK ERROR : %s\n", pMsg);
101 break;
102 default:
103 printf("EATING Msg of type %u\n", msgType);
104 break;
105 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700106}
107#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700108
109
110#undef ASSERT_NO_FATAL_FAILURE
111#define ASSERT_NO_FATAL_FAILURE(x) x
112
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600113//--------------------------------------------------------------------------------------
114// Mesh and VertexFormat Data
115//--------------------------------------------------------------------------------------
116struct Vertex
117{
118 XGL_FLOAT posX, posY, posZ, posW; // Position data
119 XGL_FLOAT r, g, b, a; // Color
120};
121
122#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
123
124static const Vertex g_vbData[] =
125{
126 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
127 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
128 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
129 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
130 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
131 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
132
133 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
134 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
135 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
136 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
137 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139
140 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
141 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
142 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
143 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
144 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
145 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
146
147 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
148 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
149 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
150 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
151 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
152 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
153
154 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
155 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
156 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
157 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
158 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
159 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
160
161 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
162 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
163 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
164 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
165 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
166 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
167};
168
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600169static const Vertex g_vb_solid_face_colors_Data[] =
170{
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 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
176 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
177
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 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184
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 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
190 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
191
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 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
197 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
198
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 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
204 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
205
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 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
211 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
212};
213
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600214class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600215{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600216public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600217
Tony Barbourf43b6982014-11-25 13:18:32 -0700218 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
219 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour09da2212014-12-03 16:13:23 -0700220 XglConstantBufferObj *constantBuffer);
Tony Barboura3953b82014-12-03 15:46:29 -0700221 void GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet, int numTris);
Tony Barbourf43b6982014-11-25 13:18:32 -0700222 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
223
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600224 void InitDepthStencil();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600225 void GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600226 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600227
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600228
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600229protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600230 XGL_IMAGE m_texture;
231 XGL_IMAGE_VIEW m_textureView;
232 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
233 XGL_GPU_MEMORY m_textureMem;
234
235 XGL_SAMPLER m_sampler;
236
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600237 XGL_FORMAT m_depth_stencil_fmt;
238 XGL_IMAGE m_depthStencilImage;
239 XGL_GPU_MEMORY m_depthStencilMem;
240 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700241 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600242
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600243
244 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600245
246 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
247 this->app_info.pNext = NULL;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600248 this->app_info.pAppName = (const XGL_CHAR *) "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600249 this->app_info.appVersion = 1;
250 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
251 this->app_info.engineVersion = 1;
252 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
253
Cody Northrop350727b2014-10-06 15:42:00 -0600254 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
255 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700256 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600257
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600258 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260
261 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600262 // Clean up resources before we reset
263 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600264 }
265};
266
Tony Barbourf43b6982014-11-25 13:18:32 -0700267
Tony Barboura3953b82014-12-03 15:46:29 -0700268void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600269{
270 XGL_RESULT err = XGL_SUCCESS;
271
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600273 // Build command buffer
274 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
275 ASSERT_XGL_SUCCESS(err);
276
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600277 GenerateClearAndPrepareBufferCmds();
278 GenerateBindRenderTargetCmd();
Tobin Ehlis31446e52014-11-28 11:17:19 -0700279#ifdef DUMP_STATE_DOT
280 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
281 pDSDumpDot((char*)"triTest.dot");
282#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700283 GenerateBindStateAndPipelineCmds();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600284
Tony Barboura3953b82014-12-03 15:46:29 -0700285 pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet);
Tony Barbourbf678472014-12-03 13:58:15 -0700286 descriptorSet->BindCommandBuffer(m_cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700287
288 // render the triangle
289 xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600290
291 // finalize recording of the command buffer
292 err = xglEndCommandBuffer( m_cmdBuffer );
293 ASSERT_XGL_SUCCESS( err );
Tony Barbourf43b6982014-11-25 13:18:32 -0700294}
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600295
Tony Barbourf43b6982014-11-25 13:18:32 -0700296void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
297{
298 XGL_RESULT err = XGL_SUCCESS;
Chia-I Wue7748802014-12-05 10:45:15 +0800299 XGL_UINT i;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600300
301 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700302 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600303 ASSERT_XGL_SUCCESS( err );
304
Chia-I Wuf34ac502014-08-27 14:58:05 +0800305 err = xglQueueWaitIdle( m_device->m_queue );
306 ASSERT_XGL_SUCCESS( err );
307
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600308 // Wait for work to finish before cleaning up.
309 xglDeviceWaitIdle(m_device->device());
310
Chia-I Wue7748802014-12-05 10:45:15 +0800311 for (i = 0; i < m_renderTargetCount; i++)
312 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600313}
314
Tony Barbourf43b6982014-11-25 13:18:32 -0700315void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600316{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600317 XGL_RESULT err;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600318
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600319 ASSERT_NO_FATAL_FAILURE(InitState());
320 ASSERT_NO_FATAL_FAILURE(InitViewport());
321
Tony Barbourf43b6982014-11-25 13:18:32 -0700322 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
323 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600324
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600325
Tony Barbourf43b6982014-11-25 13:18:32 -0700326 XglPipelineObj pipelineobj(m_device);
327 pipelineobj.AddShader(&vs);
328 pipelineobj.AddShader(&ps);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600329
330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
331
Tony Barbourf43b6982014-11-25 13:18:32 -0700332 // Create descriptor set
333 XglDescriptorSetObj descriptorSet(m_device);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600334
335 // Build command buffer
336 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
337 ASSERT_XGL_SUCCESS(err);
338
339 GenerateClearAndPrepareBufferCmds();
340 GenerateBindRenderTargetCmd();
Tony Barbourf43b6982014-11-25 13:18:32 -0700341 GenerateBindStateAndPipelineCmds();
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600342
Tobin Ehlis31446e52014-11-28 11:17:19 -0700343#ifdef DUMP_STATE_DOT
344 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
345 pDSDumpDot((char*)"triUniFS.dot");
346#endif
Tony Barbourbf678472014-12-03 13:58:15 -0700347 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -0700348 descriptorSet.BindCommandBuffer(m_cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600349
Tony Barbourf43b6982014-11-25 13:18:32 -0700350 // render the triangle
351 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600352
353 // finalize recording of the command buffer
354 err = xglEndCommandBuffer( m_cmdBuffer );
355 ASSERT_XGL_SUCCESS( err );
356
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600357 // submit the command buffer to the universal queue
Tony Barbour75420772014-12-04 17:17:26 -0700358 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL );
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600359 ASSERT_XGL_SUCCESS( err );
360
361 err = xglQueueWaitIdle( m_device->m_queue );
362 ASSERT_XGL_SUCCESS( err );
363
364 // Wait for work to finish before cleaning up.
365 xglDeviceWaitIdle(m_device->device());
366
Chia-I Wue7748802014-12-05 10:45:15 +0800367 assert(m_renderTargetCount == 1);
368 RecordImage(m_renderTargets[0]);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600369
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600370}
371
Tony Barbourf43b6982014-11-25 13:18:32 -0700372void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour09da2212014-12-03 16:13:23 -0700373 XglConstantBufferObj *constantBuffer)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600374{
375 int i;
376 glm::mat4 MVP;
377 int matrixSize = sizeof(MVP);
378 XGL_RESULT err;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600379
380 for (i = 0; i < 8; i++) {
381 XGL_UINT8 *pData;
Tony Barbour09da2212014-12-03 16:13:23 -0700382 err = xglMapMemory(constantBuffer->m_constantBufferMem, 0, (XGL_VOID **) &pData);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600383 ASSERT_XGL_SUCCESS(err);
384
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600385 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
386 MVP = Projection * View * Model;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600387 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
388
Tony Barbour09da2212014-12-03 16:13:23 -0700389 err = xglUnmapMemory(constantBuffer->m_constantBufferMem);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600390 ASSERT_XGL_SUCCESS(err);
391
392 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700393 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600394 ASSERT_XGL_SUCCESS( err );
395
396 err = xglQueueWaitIdle( m_device->m_queue );
397 ASSERT_XGL_SUCCESS( err );
398
399 // Wait for work to finish before cleaning up.
400 xglDeviceWaitIdle(m_device->device());
401
Chia-I Wue7748802014-12-05 10:45:15 +0800402 assert(m_renderTargetCount == 1);
403 RecordImage(m_renderTargets[0]);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600404 }
Cody Northrop7a1f0462014-10-10 14:49:36 -0600405}
406
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600407void dumpMatrix(const char *note, glm::mat4 MVP)
408{
409 int i,j;
410
411 printf("%s: \n", note);
412 for (i=0; i<4; i++) {
413 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
414 }
415 printf("\n");
416 fflush(stdout);
417}
418
419void dumpVec4(const char *note, glm::vec4 vector)
420{
421 printf("%s: \n", note);
422 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
423 printf("\n");
424 fflush(stdout);
425}
426
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600427void XglRenderTest::GenerateClearAndPrepareBufferCmds()
428{
429 XglRenderFramework::GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600430
Tony Barbour97a36232014-12-04 17:14:45 -0700431 if (m_depthStencilImage) {
432 printf("Clearing Depth Stencil\n");fflush(stdout);
433 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
434 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
435 dsRange.baseMipLevel = 0;
436 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
437 dsRange.baseArraySlice = 0;
438 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
Cody Northrop7a1f0462014-10-10 14:49:36 -0600439
Tony Barbour97a36232014-12-04 17:14:45 -0700440 // prepare the depth buffer for clear
441 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
442 transitionToClear.image = m_depthStencilImage;
443 transitionToClear.oldState = m_depthStencilBinding.depthState;
444 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
445 transitionToClear.subresourceRange = dsRange;
446 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
447 m_depthStencilBinding.depthState = transitionToClear.newState;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600448
Tony Barbour97a36232014-12-04 17:14:45 -0700449 xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600450
Tony Barbour97a36232014-12-04 17:14:45 -0700451 // prepare depth buffer for rendering
452 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wu18749b02014-12-05 10:48:20 +0800453 transitionToRender.image = m_depthStencilImage;
Tony Barbour97a36232014-12-04 17:14:45 -0700454 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
455 transitionToRender.newState = m_depthStencilBinding.depthState;
456 transitionToRender.subresourceRange = dsRange;
457 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
458 m_depthStencilBinding.depthState = transitionToClear.newState;
459 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600460}
461
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600462void XglRenderTest::InitDepthStencil()
463{
464 XGL_RESULT err;
465 XGL_IMAGE_CREATE_INFO image;
466 XGL_MEMORY_ALLOC_INFO mem_alloc;
467 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
468 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700469 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600470
471 // Clean up default state created by framework
472 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
473
474 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
475 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
476
477 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
478 image.pNext = NULL;
479 image.imageType = XGL_IMAGE_2D;
480 image.format = m_depth_stencil_fmt;
481 image.extent.width = m_width;
482 image.extent.height = m_height;
483 image.extent.depth = 1;
484 image.mipLevels = 1;
485 image.arraySize = 1;
486 image.samples = 1;
487 image.tiling = XGL_OPTIMAL_TILING;
488 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
489 image.flags = 0;
490
491 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
492 mem_alloc.pNext = NULL;
493 mem_alloc.allocationSize = 0;
494 mem_alloc.alignment = 0;
495 mem_alloc.flags = 0;
496 mem_alloc.heapCount = 0;
497 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
498
499 /* create image */
500 err = xglCreateImage(device(), &image,
501 &m_depthStencilImage);
502 ASSERT_XGL_SUCCESS(err);
503
504 err = xglGetObjectInfo(m_depthStencilImage,
505 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
506 &mem_reqs_size, &mem_reqs);
507 ASSERT_XGL_SUCCESS(err);
508 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
509
510 mem_alloc.allocationSize = mem_reqs.size;
511 mem_alloc.alignment = mem_reqs.alignment;
512 mem_alloc.heapCount = mem_reqs.heapCount;
513 memcpy(mem_alloc.heaps, mem_reqs.heaps,
514 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
515
516 /* allocate memory */
517 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
518 ASSERT_XGL_SUCCESS(err);
519
520 /* bind memory */
521 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
522 ASSERT_XGL_SUCCESS(err);
523
524 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
525 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
526 depthStencil.depthTestEnable = XGL_TRUE;
527 depthStencil.depthWriteEnable = XGL_TRUE;
528 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
529 depthStencil.depthBoundsEnable = XGL_FALSE;
530 depthStencil.minDepth = 0.f;
531 depthStencil.maxDepth = 1.f;
532 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
533 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
534 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
535 depthStencil.back.stencilRef = 0x00;
536 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
537 depthStencil.front = depthStencil.back;
538
539 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
540 ASSERT_XGL_SUCCESS( err );
541
542 /* create image view */
543 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
544 view.pNext = NULL;
545 view.image = XGL_NULL_HANDLE;
546 view.mipLevel = 0;
547 view.baseArraySlice = 0;
548 view.arraySize = 1;
549 view.flags = 0;
550 view.image = m_depthStencilImage;
551 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
552 ASSERT_XGL_SUCCESS(err);
553
554 m_depthStencilBinding.view = m_depthStencilView;
555 m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
556 m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
557}
558
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600559struct xgltriangle_vs_uniform {
560 // Must start with MVP
561 XGL_FLOAT mvp[4][4];
562 XGL_FLOAT position[3][4];
563 XGL_FLOAT color[3][4];
564};
565
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600566void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600567{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700568#ifdef DEBUG_CALLBACK
569 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
570#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600571 // Create identity matrix
572 int i;
573 struct xgltriangle_vs_uniform data;
574
575 glm::mat4 Projection = glm::mat4(1.0f);
576 glm::mat4 View = glm::mat4(1.0f);
577 glm::mat4 Model = glm::mat4(1.0f);
578 glm::mat4 MVP = Projection * View * Model;
579 const int matrixSize = sizeof(MVP);
580 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
581 memcpy(&data.mvp, &MVP[0][0], matrixSize);
582
583 static const Vertex tri_data[] =
584 {
585 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
586 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
587 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
588 };
589
590 for (i=0; i<3; i++) {
591 data.position[i][0] = tri_data[i].posX;
592 data.position[i][1] = tri_data[i].posY;
593 data.position[i][2] = tri_data[i].posZ;
594 data.position[i][3] = tri_data[i].posW;
595 data.color[i][0] = tri_data[i].r;
596 data.color[i][1] = tri_data[i].g;
597 data.color[i][2] = tri_data[i].b;
598 data.color[i][3] = tri_data[i].a;
599 }
600
Tony Barbourf43b6982014-11-25 13:18:32 -0700601 ASSERT_NO_FATAL_FAILURE(InitState());
602 ASSERT_NO_FATAL_FAILURE(InitViewport());
603
604 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
605
606 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
607 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
608 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
609
610 XglPipelineObj pipelineobj(m_device);
611 pipelineobj.AddShader(&vs);
612 pipelineobj.AddShader(&ps);
613
614 XglDescriptorSetObj descriptorSet(m_device);
615 descriptorSet.AttachMemoryView(&constantBuffer);
616 m_memoryRefManager.AddMemoryRef(&constantBuffer);
617
Tony Barboura3953b82014-12-03 15:46:29 -0700618 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700619 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
620
Tony Barbour09da2212014-12-03 16:13:23 -0700621 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700622#ifdef PRINT_OBJECTS
623 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
624 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
625 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
626 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
627 printf("DEBUG : Number of Objects : %lu\n", numObjects);
628 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
629 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
630 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
631 for (i=0; i < numObjects; i++) {
632 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);
633 }
634 free(pObjNodeArray);
635#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700636
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600637}
638
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600639TEST_F(XglRenderTest, XGLTriangle_FragColor)
640{
641 static const char *vertShaderText =
642 "#version 140\n"
643 "#extension GL_ARB_separate_shader_objects : enable\n"
644 "#extension GL_ARB_shading_language_420pack : enable\n"
645 "\n"
646 "layout(binding = 0) uniform buf {\n"
647 " mat4 MVP;\n"
648 " vec4 position[3];\n"
649 " vec4 color[3];\n"
650 "} ubuf;\n"
651 "\n"
652 "layout (location = 0) out vec4 outColor;\n"
653 "\n"
654 "void main() \n"
655 "{\n"
656 " outColor = ubuf.color[gl_VertexID];\n"
657 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
658 "}\n";
659
660 static const char *fragShaderText =
661 "#version 140\n"
662 "#extension GL_ARB_separate_shader_objects : enable\n"
663 "#extension GL_ARB_shading_language_420pack : enable\n"
664 "\n"
665 "layout (location = 0) in vec4 inColor;\n"
666 "\n"
667 "void main()\n"
668 "{\n"
669 " gl_FragColor = inColor;\n"
670 "}\n";
671
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600672 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600673 XGLTriangleTest(vertShaderText, fragShaderText);
674}
675
676TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
677{
678 static const char *vertShaderText =
679 "#version 140\n"
680 "#extension GL_ARB_separate_shader_objects : enable\n"
681 "#extension GL_ARB_shading_language_420pack : enable\n"
682 "\n"
683 "layout(binding = 0) uniform buf {\n"
684 " mat4 MVP;\n"
685 " vec4 position[3];\n"
686 " vec4 color[3];\n"
687 "} ubuf;\n"
688 "\n"
689 "layout (location = 0) out vec4 outColor;\n"
690 "\n"
691 "void main() \n"
692 "{\n"
693 " outColor = ubuf.color[gl_VertexID];\n"
694 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
695 "}\n";
696
697 static const char *fragShaderText =
698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
701 "\n"
702 "layout (location = 0) in vec4 inColor;\n"
703 "layout (location = 0) out vec4 outColor;\n"
704 "\n"
705 "void main()\n"
706 "{\n"
707 " outColor = inColor;\n"
708 "}\n";
709
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600710 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600711
712 XGLTriangleTest(vertShaderText, fragShaderText);
713}
714
Tony Barbourf43b6982014-11-25 13:18:32 -0700715TEST_F(XglRenderTest, BIL_XGLTriangle)
716{
717 bool saved_use_bil = XglTestFramework::m_use_bil;
718
719 static const char *vertShaderText =
720 "#version 140\n"
721 "#extension GL_ARB_separate_shader_objects : enable\n"
722 "#extension GL_ARB_shading_language_420pack : enable\n"
723 "\n"
724 "layout(binding = 0) uniform buf {\n"
725 " mat4 MVP;\n"
726 " vec4 position[3];\n"
727 " vec4 color[3];\n"
728 "} ubuf;\n"
729 "\n"
730 "layout (location = 0) out vec4 outColor;\n"
731 "\n"
732 "void main() \n"
733 "{\n"
734 " outColor = ubuf.color[gl_VertexID];\n"
735 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
736 "}\n";
737
738 static const char *fragShaderText =
739 "#version 140\n"
740 "#extension GL_ARB_separate_shader_objects : enable\n"
741 "#extension GL_ARB_shading_language_420pack : enable\n"
742 "\n"
743 "layout (location = 0) in vec4 inColor;\n"
744 "\n"
745 "void main()\n"
746 "{\n"
747 " gl_FragColor = inColor;\n"
748 "}\n";
749
750 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
751
752 XglTestFramework::m_use_bil = true;
753
754 XGLTriangleTest(vertShaderText, fragShaderText);
755
756 XglTestFramework::m_use_bil = saved_use_bil;
757}
758
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600759TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600760{
761 static const char *vertShaderText =
762 "#version 130\n"
763 "vec2 vertices[3];\n"
764 "void main() {\n"
765 " vertices[0] = vec2(-1.0, -1.0);\n"
766 " vertices[1] = vec2( 1.0, -1.0);\n"
767 " vertices[2] = vec2( 0.0, 1.0);\n"
768 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
769 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600770
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600771 static const char *fragShaderText =
772 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600773 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600774 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600775 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600776
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600777 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
778
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600779 DrawTriangleTest(vertShaderText, fragShaderText);
780}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600781
Tony Barbourf43b6982014-11-25 13:18:32 -0700782TEST_F(XglRenderTest, BIL_GreenTriangle)
783{
784 bool saved_use_bil = XglTestFramework::m_use_bil;
785
786 static const char *vertShaderText =
787 "#version 130\n"
788 "vec2 vertices[3];\n"
789 "void main() {\n"
790 " vertices[0] = vec2(-1.0, -1.0);\n"
791 " vertices[1] = vec2( 1.0, -1.0);\n"
792 " vertices[2] = vec2( 0.0, 1.0);\n"
793 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
794 "}\n";
795
796 static const char *fragShaderText =
797 "#version 130\n"
798 "void main() {\n"
799 " gl_FragColor = vec4(0,1,0,1);\n"
800 "}\n";
801
802 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
803
804 XglTestFramework::m_use_bil = true;
805 DrawTriangleTest(vertShaderText, fragShaderText);
806 XglTestFramework::m_use_bil = saved_use_bil;
807}
808
809TEST_F(XglRenderTest, YellowTriangle)
810{
811 static const char *vertShaderText =
812 "#version 130\n"
813 "void main() {\n"
814 " vec2 vertices[3];"
815 " vertices[0] = vec2(-0.5, -0.5);\n"
816 " vertices[1] = vec2( 0.5, -0.5);\n"
817 " vertices[2] = vec2( 0.5, 0.5);\n"
818 " vec4 colors[3];\n"
819 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
820 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
821 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
822 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
823 "}\n";
824
825 static const char *fragShaderText =
826 "#version 130\n"
827 "void main() {\n"
828 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
829 "}\n";
830
831 DrawTriangleTest(vertShaderText, fragShaderText);
832}
833
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600834TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600835{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600836 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700837 "#version 130\n"
838 //XYZ1( -1, -1, -1 )
839 "in vec4 pos;\n"
840 //XYZ1( 0.f, 0.f, 0.f )
841 "in vec4 inColor;\n"
842 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600843 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600844 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600845 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600846 "}\n";
847
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600848
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600849 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700850 "#version 140\n"
851 "#extension GL_ARB_separate_shader_objects : enable\n"
852 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700853 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700854 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600855 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700856 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600857 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600858
Tony Barbourf43b6982014-11-25 13:18:32 -0700859
860
861 ASSERT_NO_FATAL_FAILURE(InitState());
862 ASSERT_NO_FATAL_FAILURE(InitViewport());
863
864 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
865 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
866
867 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
868 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
869
870 XglPipelineObj pipelineobj(m_device);
871 pipelineobj.AddShader(&vs);
872 pipelineobj.AddShader(&ps);
873
874 XglDescriptorSetObj descriptorSet(m_device);
875 descriptorSet.AttachMemoryView(&meshBuffer);
876
877 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
878 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
879 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
880 };
881
882 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
883 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
884 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
885 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
886 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
887 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
888 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
889 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
890 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
891
892 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
893 pipelineobj.AddVertexInputBindings(&vi_binding,1);
894 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
895
Tony Barboura3953b82014-12-03 15:46:29 -0700896 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -0700897 QueueCommandBuffer(NULL, 0);
898
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600899}
900
Chia-I Wue09d1a72014-12-05 10:32:23 +0800901TEST_F(XglRenderTest, TriangleMRT)
902{
903 static const char *vertShaderText =
904 "#version 130\n"
905 "in vec4 pos;\n"
906 "void main() {\n"
907 " gl_Position = pos;\n"
908 "}\n";
909
910 static const char *fragShaderText =
911 "#version 130\n"
912 "void main() {\n"
913 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
914 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
915 "}\n";
916 const XGL_FLOAT vb_data[][2] = {
917 { -1.0f, -1.0f },
918 { 1.0f, -1.0f },
919 { -1.0f, 1.0f }
920 };
921
922 ASSERT_NO_FATAL_FAILURE(InitState());
923 ASSERT_NO_FATAL_FAILURE(InitViewport());
924
925 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
926 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
927
928 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
929 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
930
931 XglPipelineObj pipelineobj(m_device);
932 pipelineobj.AddShader(&vs);
933 pipelineobj.AddShader(&ps);
934
935 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
936 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
937 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
938 };
939
940 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
941 vi_attrib.binding = 0; // index into vertexBindingDescriptions
942 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
943 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
944 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
945
946 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
947 pipelineobj.AddVertexInputBindings(&vi_binding,1);
948 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
949
950 XglDescriptorSetObj descriptorSet(m_device);
951
952 m_renderTargetCount = 2;
953
954 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
955 att.blendEnable = XGL_FALSE;
956 att.format = m_render_target_fmt;
957 att.channelWriteMask = 0xf;
958 pipelineobj.SetColorAttachment(1, &att);
959
960 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
961 QueueCommandBuffer(NULL, 0);
962}
963
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700964TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
965{
966 static const char *vertShaderText =
967 "#version 140\n"
968 "#extension GL_ARB_separate_shader_objects : enable\n"
969 "#extension GL_ARB_shading_language_420pack : enable\n"
970 "layout(location = 0) in vec4 pos;\n"
971 "layout(location = 1) in vec4 inColor;\n"
972 "layout(location = 0) out vec4 outColor;\n"
973 "void main() {\n"
974 " outColor = inColor;\n"
975 " gl_Position = pos;\n"
976 "}\n";
977
978
979 static const char *fragShaderText =
980 "#version 140\n"
981 "#extension GL_ARB_separate_shader_objects : enable\n"
982 "#extension GL_ARB_shading_language_420pack : enable\n"
983 "layout(location = 0) in vec4 color;\n"
984 "void main() {\n"
985 " gl_FragColor = color;\n"
986 "}\n";
987
988 const Vertex g_vbData[] =
989 {
990 // first tri
991 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
992 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
993 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
994
995 // second tri
996 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
997 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
998 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
999 };
1000
1001 const uint16_t g_idxData[6] = {
1002 0, 1, 2,
1003 3, 4, 5,
1004 };
1005
1006 ASSERT_NO_FATAL_FAILURE(InitState());
1007 ASSERT_NO_FATAL_FAILURE(InitViewport());
1008
1009 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1010 meshBuffer.SetMemoryState(m_cmdBuffer, XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1011
1012 XglIndexBufferObj indexBuffer(m_device);
1013 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
1014 indexBuffer.SetMemoryState(m_cmdBuffer, XGL_MEMORY_STATE_INDEX_DATA);
1015
1016 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1017 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1018
1019 XglPipelineObj pipelineobj(m_device);
1020 pipelineobj.AddShader(&vs);
1021 pipelineobj.AddShader(&ps);
1022
1023 XglDescriptorSetObj descriptorSet(m_device);
1024
1025 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1026 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1027 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1028 };
1029
1030 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1031 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1032 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1033 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1034 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1035 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1036 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1037 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1038 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1039
1040 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1041 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1042
1043 XGL_RESULT err = XGL_SUCCESS;
1044
1045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1046 // Build command buffer
1047 // TODO: SetMemoryState above also uses this command buffer, do we need to make sure
1048 // that job is complete? Or maybe we shouldn't queue those actions?
1049 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1050 ASSERT_XGL_SUCCESS(err);
1051
1052 GenerateClearAndPrepareBufferCmds();
1053 GenerateBindRenderTargetCmd();
1054#ifdef DUMP_STATE_DOT
1055 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1056 pDSDumpDot((char*)"triTest.dot");
1057#endif
1058 GenerateBindStateAndPipelineCmds();
1059
Tony Barbour9d3c3172014-12-04 17:27:08 -07001060 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001061 descriptorSet.BindCommandBuffer(m_cmdBuffer);
1062
1063 meshBuffer.Bind(m_cmdBuffer, 0, 0);
1064 indexBuffer.Bind(m_cmdBuffer, /* offset */ 0);
1065
1066 // render two triangles
1067 xglCmdDrawIndexed(m_cmdBuffer, 0, 6, 0, 0, 1);
1068
1069 // finalize recording of the command buffer
1070 err = xglEndCommandBuffer( m_cmdBuffer );
1071 ASSERT_XGL_SUCCESS( err );
1072
1073 QueueCommandBuffer(NULL, 0);
1074
1075}
1076
GregF6bef1212014-12-02 15:41:44 -07001077TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1078{
1079 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001080
GregF6bef1212014-12-02 15:41:44 -07001081 static const char *vertShaderText =
1082 "#version 140\n"
1083 "#extension GL_ARB_separate_shader_objects : enable\n"
1084 "#extension GL_ARB_shading_language_420pack : enable\n"
1085 "layout (location = 0) in vec4 pos;\n"
1086 "layout (location = 0) out vec4 outColor;\n"
1087 "layout (location = 1) out vec4 outColor2;\n"
1088 "void main() {\n"
1089 " gl_Position = pos;\n"
1090 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1091 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1092 "}\n";
1093
1094 static const char *fragShaderText =
1095 //"#version 140\n"
1096 "#version 330\n"
1097 "#extension GL_ARB_separate_shader_objects : enable\n"
1098 "#extension GL_ARB_shading_language_420pack : enable\n"
1099 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1100 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1101 "layout (location = 0) in vec4 color;\n"
1102 "layout (location = 1) in vec4 color2;\n"
1103 "void main() {\n"
1104 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1105 " float dist_squared = dot(pos, pos);\n"
1106 " gl_FragColor = (dist_squared < 400.0)\n"
1107 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1108 " : color2;\n"
1109 "}\n";
1110
1111 ASSERT_NO_FATAL_FAILURE(InitState());
1112 ASSERT_NO_FATAL_FAILURE(InitViewport());
1113
1114 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1115 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1116
1117 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1118 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1119
1120 XglPipelineObj pipelineobj(m_device);
1121 pipelineobj.AddShader(&vs);
1122 pipelineobj.AddShader(&ps);
1123
1124 XglDescriptorSetObj descriptorSet(m_device);
1125 descriptorSet.AttachMemoryView(&meshBuffer);
1126
1127 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1128 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1129 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1130 };
1131
1132 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1133 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1134 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1135 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1136 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1137 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1138 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1139 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1140 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1141
1142 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1143 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1144 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1145
Tony Barbour09da2212014-12-03 16:13:23 -07001146 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001147 QueueCommandBuffer(NULL, 0);
1148
1149}
1150
1151TEST_F(XglRenderTest, RedCirclesonBlue)
1152{
1153 // This tests that we correctly handle unread fragment inputs
1154
1155 static const char *vertShaderText =
1156 "#version 140\n"
1157 "#extension GL_ARB_separate_shader_objects : enable\n"
1158 "#extension GL_ARB_shading_language_420pack : enable\n"
1159 "layout (location = 0) in vec4 pos;\n"
1160 "layout (location = 0) out vec4 outColor;\n"
1161 "layout (location = 1) out vec4 outColor2;\n"
1162 "void main() {\n"
1163 " gl_Position = pos;\n"
1164 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1165 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1166 "}\n";
1167
1168 static const char *fragShaderText =
1169 //"#version 140\n"
1170 "#version 330\n"
1171 "#extension GL_ARB_separate_shader_objects : enable\n"
1172 "#extension GL_ARB_shading_language_420pack : enable\n"
1173 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1174 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1175 "layout (location = 0) in vec4 color;\n"
1176 "layout (location = 1) in vec4 color2;\n"
1177 "void main() {\n"
1178 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1179 " float dist_squared = dot(pos, pos);\n"
1180 " gl_FragColor = (dist_squared < 400.0)\n"
1181 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1182 " : color2;\n"
1183 "}\n";
1184
1185 ASSERT_NO_FATAL_FAILURE(InitState());
1186 ASSERT_NO_FATAL_FAILURE(InitViewport());
1187
1188 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1189 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1190
1191 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1192 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1193
1194 XglPipelineObj pipelineobj(m_device);
1195 pipelineobj.AddShader(&vs);
1196 pipelineobj.AddShader(&ps);
1197
1198 XglDescriptorSetObj descriptorSet(m_device);
1199 descriptorSet.AttachMemoryView(&meshBuffer);
1200
1201 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1202 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1203 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1204 };
1205
1206 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1207 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1208 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1209 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1210 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1211 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1212 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1213 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1214 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1215
1216 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1217 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1218 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1219
Tony Barbour09da2212014-12-03 16:13:23 -07001220 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001221 QueueCommandBuffer(NULL, 0);
1222
1223}
1224
1225TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1226{
1227 // This tests reading gl_ClipDistance from FS
1228
1229 static const char *vertShaderText =
1230 "#version 330\n"
1231 "#extension GL_ARB_separate_shader_objects : enable\n"
1232 "#extension GL_ARB_shading_language_420pack : enable\n"
1233 "out gl_PerVertex {\n"
1234 " vec4 gl_Position;\n"
1235 " float gl_ClipDistance[1];\n"
1236 "};\n"
1237 "layout (location = 0) in vec4 pos;\n"
1238 "layout (location = 0) out vec4 outColor;\n"
1239 "layout (location = 1) out vec4 outColor2;\n"
1240 "void main() {\n"
1241 " gl_Position = pos;\n"
1242 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1243 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1244 " float dists[3];\n"
1245 " dists[0] = 0.0;\n"
1246 " dists[1] = 1.0;\n"
1247 " dists[2] = 1.0;\n"
1248 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1249 "}\n";
1250
1251
1252 static const char *fragShaderText =
1253 //"#version 140\n"
1254 "#version 330\n"
1255 "#extension GL_ARB_separate_shader_objects : enable\n"
1256 "#extension GL_ARB_shading_language_420pack : enable\n"
1257 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1258 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1259 "layout (location = 0) in vec4 color;\n"
1260 "layout (location = 1) in vec4 color2;\n"
1261 "void main() {\n"
1262 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1263 " float dist_squared = dot(pos, pos);\n"
1264 " gl_FragColor = (dist_squared < 400.0)\n"
1265 " ? color * gl_ClipDistance[0]\n"
1266 " : color2;\n"
1267 "}\n";
1268
1269 ASSERT_NO_FATAL_FAILURE(InitState());
1270 ASSERT_NO_FATAL_FAILURE(InitViewport());
1271
1272 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1273 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1274
1275 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1276 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1277
1278 XglPipelineObj pipelineobj(m_device);
1279 pipelineobj.AddShader(&vs);
1280 pipelineobj.AddShader(&ps);
1281
1282 XglDescriptorSetObj descriptorSet(m_device);
1283 descriptorSet.AttachMemoryView(&meshBuffer);
1284
1285 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1286 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1287 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1288 };
1289
1290 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1291 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1292 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1293 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1294 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1295 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1296 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1297 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1298 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1299
1300 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1301 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1302 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1303
Tony Barboura3953b82014-12-03 15:46:29 -07001304 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001305 QueueCommandBuffer(NULL, 0);
1306
1307}
Tony Barbourf43b6982014-11-25 13:18:32 -07001308
GregF7a23c792014-12-02 17:19:34 -07001309TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1310{
1311 static const char *vertShaderText =
1312 "#version 140\n"
1313 "#extension GL_ARB_separate_shader_objects : enable\n"
1314 "#extension GL_ARB_shading_language_420pack : enable\n"
1315 "layout (location = 0) in vec4 pos;\n"
1316 "layout (location = 0) out vec4 outColor;\n"
1317 "layout (location = 1) out vec4 outColor2;\n"
1318 "void main() {\n"
1319 " gl_Position = pos;\n"
1320 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1321 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1322 "}\n";
1323
1324
1325 static const char *fragShaderText =
1326 //"#version 140\n"
1327 "#version 330\n"
1328 "#extension GL_ARB_separate_shader_objects : enable\n"
1329 "#extension GL_ARB_shading_language_420pack : enable\n"
1330 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1331 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1332 "layout (location = 0) in vec4 color;\n"
1333 "layout (location = 1) in vec4 color2;\n"
1334 "void main() {\n"
1335 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1336 " float dist_squared = dot(pos, pos);\n"
1337 " if (dist_squared < 100.0)\n"
1338 " discard;\n"
1339 " gl_FragColor = (dist_squared < 400.0)\n"
1340 " ? color\n"
1341 " : color2;\n"
1342 "}\n";
1343
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345 ASSERT_NO_FATAL_FAILURE(InitViewport());
1346
1347 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1348 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1349
1350 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1351 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1352
1353 XglPipelineObj pipelineobj(m_device);
1354 pipelineobj.AddShader(&vs);
1355 pipelineobj.AddShader(&ps);
1356
1357 XglDescriptorSetObj descriptorSet(m_device);
1358 descriptorSet.AttachMemoryView(&meshBuffer);
1359
1360 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1361 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1362 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1363 };
1364
1365 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1366 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1367 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1368 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1369 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1370 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1371 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1372 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1373 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1374
1375 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1376 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1377 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1378
Tony Barbour09da2212014-12-03 16:13:23 -07001379 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF7a23c792014-12-02 17:19:34 -07001380 QueueCommandBuffer(NULL, 0);
1381
1382}
1383
1384
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001385TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001386{
1387 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001388 "#version 140\n"
1389 "#extension GL_ARB_separate_shader_objects : enable\n"
1390 "#extension GL_ARB_shading_language_420pack : enable\n"
1391 "\n"
1392 "layout(binding = 0) uniform buf {\n"
1393 " mat4 MVP;\n"
1394 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001395 "void main() {\n"
1396 " vec2 vertices[3];"
1397 " vertices[0] = vec2(-0.5, -0.5);\n"
1398 " vertices[1] = vec2( 0.5, -0.5);\n"
1399 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001400 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001401 "}\n";
1402
1403 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001404 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001406 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001407 "}\n";
1408
Tony Barbourf43b6982014-11-25 13:18:32 -07001409 ASSERT_NO_FATAL_FAILURE(InitState());
1410 ASSERT_NO_FATAL_FAILURE(InitViewport());
1411
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001412 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001413 glm::mat4 Projection = glm::mat4(1.0f);
1414 glm::mat4 View = glm::mat4(1.0f);
1415 glm::mat4 Model = glm::mat4(1.0f);
1416 glm::mat4 MVP = Projection * View * Model;
1417 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1418
Tony Barbourf43b6982014-11-25 13:18:32 -07001419 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1420 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1421 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001422
Tony Barbourf43b6982014-11-25 13:18:32 -07001423 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1424
1425 XglPipelineObj pipelineobj(m_device);
1426 pipelineobj.AddShader(&vs);
1427 pipelineobj.AddShader(&ps);
1428
1429 // Create descriptor set and attach the constant buffer to it
1430 XglDescriptorSetObj descriptorSet(m_device);
1431 descriptorSet.AttachMemoryView(&MVPBuffer);
1432
1433 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1434
Tony Barboura3953b82014-12-03 15:46:29 -07001435 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001436 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1437
Tony Barbour09da2212014-12-03 16:13:23 -07001438 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001439}
1440
Tony Barbourf43b6982014-11-25 13:18:32 -07001441TEST_F(XglRenderTest, MixTriangle)
1442{
1443 // This tests location applied to varyings. Notice that we have switched foo
1444 // and bar in the FS. The triangle should be blended with red, green and blue
1445 // corners.
1446 static const char *vertShaderText =
1447 "#version 140\n"
1448 "#extension GL_ARB_separate_shader_objects : enable\n"
1449 "#extension GL_ARB_shading_language_420pack : enable\n"
1450 "layout (location=0) out vec4 bar;\n"
1451 "layout (location=1) out vec4 foo;\n"
1452 "layout (location=2) out float scale;\n"
1453 "vec2 vertices[3];\n"
1454 "void main() {\n"
1455 " vertices[0] = vec2(-1.0, -1.0);\n"
1456 " vertices[1] = vec2( 1.0, -1.0);\n"
1457 " vertices[2] = vec2( 0.0, 1.0);\n"
1458 "vec4 colors[3];\n"
1459 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1460 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1461 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1462 " foo = colors[gl_VertexID % 3];\n"
1463 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1464 " scale = 1.0;\n"
1465 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1466 "}\n";
1467
1468 static const char *fragShaderText =
1469 "#version 140\n"
1470 "#extension GL_ARB_separate_shader_objects : enable\n"
1471 "#extension GL_ARB_shading_language_420pack : enable\n"
1472 "layout (location = 1) in vec4 bar;\n"
1473 "layout (location = 0) in vec4 foo;\n"
1474 "layout (location = 2) in float scale;\n"
1475 "void main() {\n"
1476 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1477 "}\n";
1478
1479 ASSERT_NO_FATAL_FAILURE(InitState());
1480 ASSERT_NO_FATAL_FAILURE(InitViewport());
1481
1482 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1483 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1484
1485 XglPipelineObj pipelineobj(m_device);
1486 pipelineobj.AddShader(&vs);
1487 pipelineobj.AddShader(&ps);
1488
1489 XglDescriptorSetObj descriptorSet(m_device);
1490
Tony Barboura3953b82014-12-03 15:46:29 -07001491 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001492 QueueCommandBuffer(NULL, 0);
1493}
1494
1495TEST_F(XglRenderTest, TriVertFetchAndVertID)
1496{
1497 // This tests that attributes work in the presence of gl_VertexID
1498
1499 static const char *vertShaderText =
1500 "#version 140\n"
1501 "#extension GL_ARB_separate_shader_objects : enable\n"
1502 "#extension GL_ARB_shading_language_420pack : enable\n"
1503 //XYZ1( -1, -1, -1 )
1504 "layout (location = 0) in vec4 pos;\n"
1505 //XYZ1( 0.f, 0.f, 0.f )
1506 "layout (location = 1) in vec4 inColor;\n"
1507 "layout (location = 0) out vec4 outColor;\n"
1508 "void main() {\n"
1509 " outColor = inColor;\n"
1510 " vec4 vertices[3];"
1511 " vertices[gl_VertexID % 3] = pos;\n"
1512 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1513 "}\n";
1514
1515
1516 static const char *fragShaderText =
1517 "#version 140\n"
1518 "#extension GL_ARB_separate_shader_objects : enable\n"
1519 "#extension GL_ARB_shading_language_420pack : enable\n"
1520 "layout (location = 0) in vec4 color;\n"
1521 "void main() {\n"
1522 " gl_FragColor = color;\n"
1523 "}\n";
1524
1525 ASSERT_NO_FATAL_FAILURE(InitState());
1526 ASSERT_NO_FATAL_FAILURE(InitViewport());
1527
1528 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1529 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1530
1531 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1532 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1533
1534 XglPipelineObj pipelineobj(m_device);
1535 pipelineobj.AddShader(&vs);
1536 pipelineobj.AddShader(&ps);
1537
1538 XglDescriptorSetObj descriptorSet(m_device);
1539 descriptorSet.AttachMemoryView(&meshBuffer);
1540
1541 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1542 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1543 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1544 };
1545
1546 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1547 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1548 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1549 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1550 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1551 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1552 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1553 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1554 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1555
1556 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1557 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1558 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1559
Tony Barboura3953b82014-12-03 15:46:29 -07001560 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001561 QueueCommandBuffer(NULL, 0);
1562}
1563
1564TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1565{
1566 // This tests that attributes work in the presence of gl_VertexID
1567 // and a dead attribute in position 0. Draws a triangle with yellow,
1568 // red and green corners, starting at top and going clockwise.
1569
1570 static const char *vertShaderText =
1571 "#version 140\n"
1572 "#extension GL_ARB_separate_shader_objects : enable\n"
1573 "#extension GL_ARB_shading_language_420pack : enable\n"
1574 //XYZ1( -1, -1, -1 )
1575 "layout (location = 0) in vec4 pos;\n"
1576 //XYZ1( 0.f, 0.f, 0.f )
1577 "layout (location = 1) in vec4 inColor;\n"
1578 "layout (location = 0) out vec4 outColor;\n"
1579 "void main() {\n"
1580 " outColor = inColor;\n"
1581 " vec2 vertices[3];"
1582 " vertices[0] = vec2(-1.0, -1.0);\n"
1583 " vertices[1] = vec2( 1.0, -1.0);\n"
1584 " vertices[2] = vec2( 0.0, 1.0);\n"
1585 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1586 "}\n";
1587
1588
1589 static const char *fragShaderText =
1590 "#version 140\n"
1591 "#extension GL_ARB_separate_shader_objects : enable\n"
1592 "#extension GL_ARB_shading_language_420pack : enable\n"
1593 "layout (location = 0) in vec4 color;\n"
1594 "void main() {\n"
1595 " gl_FragColor = color;\n"
1596 "}\n";
1597
1598 ASSERT_NO_FATAL_FAILURE(InitState());
1599 ASSERT_NO_FATAL_FAILURE(InitViewport());
1600
1601 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1602 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1603
1604 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1605 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1606
1607 XglPipelineObj pipelineobj(m_device);
1608 pipelineobj.AddShader(&vs);
1609 pipelineobj.AddShader(&ps);
1610
1611 XglDescriptorSetObj descriptorSet(m_device);
1612 descriptorSet.AttachMemoryView(&meshBuffer);
1613
1614 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1615 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1616 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1617 };
1618
1619 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1620 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1621 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1622 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1623 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1624 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1625 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1626 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1627 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1628
1629 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1630 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1631 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1632
Tony Barbour09da2212014-12-03 16:13:23 -07001633 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001634 QueueCommandBuffer(NULL, 0);
1635
1636}
1637
1638TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001639{
1640 static const char *vertShaderText =
1641 "#version 140\n"
1642 "layout (std140) uniform bufferVals {\n"
1643 " mat4 mvp;\n"
1644 "} myBufferVals;\n"
1645 "in vec4 pos;\n"
1646 "in vec4 inColor;\n"
1647 "out vec4 outColor;\n"
1648 "void main() {\n"
1649 " outColor = inColor;\n"
1650 " gl_Position = myBufferVals.mvp * pos;\n"
1651 "}\n";
1652
1653 static const char *fragShaderText =
1654 "#version 130\n"
1655 "in vec4 color;\n"
1656 "void main() {\n"
1657 " gl_FragColor = color;\n"
1658 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001659 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001660
Tony Barbourf43b6982014-11-25 13:18:32 -07001661 glm::mat4 View = glm::lookAt(
1662 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1663 glm::vec3(0,0,0), // and looks at the origin
1664 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1665 );
1666
1667 glm::mat4 Model = glm::mat4(1.0f);
1668
1669 glm::mat4 MVP = Projection * View * Model;
1670
1671 ASSERT_NO_FATAL_FAILURE(InitState());
1672 ASSERT_NO_FATAL_FAILURE(InitViewport());
1673 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1674
1675 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1676 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1677
1678 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1679
1680 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1681 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1682 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1683
1684 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1685
1686 XglPipelineObj pipelineobj(m_device);
1687 pipelineobj.AddShader(&vs);
1688 pipelineobj.AddShader(&ps);
1689
1690 XglDescriptorSetObj descriptorSet(m_device);
1691 descriptorSet.AttachMemoryView(&MVPBuffer);
1692
1693 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1694 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1695
1696 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1697 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1698 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1699 };
1700
1701 // this is the current description of g_vbData
1702 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1703 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1704 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1705 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1706 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1707 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1708 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1709 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1710 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1711
1712 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1713 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1714 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1715
Tony Barboura3953b82014-12-03 15:46:29 -07001716 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barbourf43b6982014-11-25 13:18:32 -07001717
1718 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1719
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001720}
1721
Tony Barbourf43b6982014-11-25 13:18:32 -07001722TEST_F(XglRenderTest, VSTexture)
1723{
1724 // The expected result from this test is a green and red triangle;
1725 // one red vertex on the left, two green vertices on the right.
1726 static const char *vertShaderText =
1727 "#version 130\n"
1728 "out vec4 texColor;\n"
1729 "uniform sampler2D surface;\n"
1730 "void main() {\n"
1731 " vec2 vertices[3];"
1732 " vertices[0] = vec2(-0.5, -0.5);\n"
1733 " vertices[1] = vec2( 0.5, -0.5);\n"
1734 " vertices[2] = vec2( 0.5, 0.5);\n"
1735 " vec2 positions[3];"
1736 " positions[0] = vec2( 0.0, 0.0);\n"
1737 " positions[1] = vec2( 0.25, 0.1);\n"
1738 " positions[2] = vec2( 0.1, 0.25);\n"
1739 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1740 " texColor = textureLod(surface, samplePos, 0.0);\n"
1741 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1742 "}\n";
1743
1744 static const char *fragShaderText =
1745 "#version 130\n"
1746 "in vec4 texColor;\n"
1747 "void main() {\n"
1748 " gl_FragColor = texColor;\n"
1749 "}\n";
1750
1751 ASSERT_NO_FATAL_FAILURE(InitState());
1752 ASSERT_NO_FATAL_FAILURE(InitViewport());
1753
1754 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1755 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1756 XglSamplerObj sampler(m_device);
1757 XglTextureObj texture(m_device);
1758
1759 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1760 vs.BindShaderEntitySlotToSampler(0, &sampler);
1761
1762 XglPipelineObj pipelineobj(m_device);
1763 pipelineobj.AddShader(&vs);
1764 pipelineobj.AddShader(&ps);
1765
1766 XglDescriptorSetObj descriptorSet(m_device);
1767 descriptorSet.AttachImageView(&texture);
1768 descriptorSet.AttachSampler(&sampler);
1769
1770 m_memoryRefManager.AddMemoryRef(&texture);
1771
Tony Barboura3953b82014-12-03 15:46:29 -07001772 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001773 QueueCommandBuffer(NULL, 0);
1774
1775}
1776TEST_F(XglRenderTest, TexturedTriangle)
1777{
1778 // The expected result from this test is a red and green checkered triangle
1779 static const char *vertShaderText =
1780 "#version 140\n"
1781 "#extension GL_ARB_separate_shader_objects : enable\n"
1782 "#extension GL_ARB_shading_language_420pack : enable\n"
1783 "layout (location = 0) out vec2 samplePos;\n"
1784 "void main() {\n"
1785 " vec2 vertices[3];"
1786 " vertices[0] = vec2(-0.5, -0.5);\n"
1787 " vertices[1] = vec2( 0.5, -0.5);\n"
1788 " vertices[2] = vec2( 0.5, 0.5);\n"
1789 " vec2 positions[3];"
1790 " positions[0] = vec2( 0.0, 0.0);\n"
1791 " positions[1] = vec2( 1.0, 0.0);\n"
1792 " positions[2] = vec2( 1.0, 1.0);\n"
1793 " samplePos = positions[gl_VertexID % 3];\n"
1794 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1795 "}\n";
1796
1797 static const char *fragShaderText =
1798 "#version 140\n"
1799 "#extension GL_ARB_separate_shader_objects : enable\n"
1800 "#extension GL_ARB_shading_language_420pack : enable\n"
1801 "layout (location = 0) in vec2 samplePos;\n"
1802 "layout (binding = 0) uniform sampler2D surface;\n"
1803 "layout (location=0) out vec4 outColor;\n"
1804 "void main() {\n"
1805 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1806 " outColor = texColor;\n"
1807 "}\n";
1808
1809 ASSERT_NO_FATAL_FAILURE(InitState());
1810 ASSERT_NO_FATAL_FAILURE(InitViewport());
1811
1812 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1813 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1814 XglSamplerObj sampler(m_device);
1815 XglTextureObj texture(m_device);
1816
1817 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1818 ps.BindShaderEntitySlotToSampler(0, &sampler);
1819
1820 XglPipelineObj pipelineobj(m_device);
1821 pipelineobj.AddShader(&vs);
1822 pipelineobj.AddShader(&ps);
1823
1824 XglDescriptorSetObj descriptorSet(m_device);
1825 descriptorSet.AttachImageView(&texture);
1826 descriptorSet.AttachSampler(&sampler);
1827
1828 m_memoryRefManager.AddMemoryRef(&texture);
1829
Tony Barboura3953b82014-12-03 15:46:29 -07001830 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001831 QueueCommandBuffer(NULL, 0);
1832}
1833TEST_F(XglRenderTest, TexturedTriangleClip)
1834{
1835 // The expected result from this test is a red and green checkered triangle
1836 static const char *vertShaderText =
1837 "#version 330\n"
1838 "#extension GL_ARB_separate_shader_objects : enable\n"
1839 "#extension GL_ARB_shading_language_420pack : enable\n"
1840 "layout (location = 0) out vec2 samplePos;\n"
1841 "out gl_PerVertex {\n"
1842 " vec4 gl_Position;\n"
1843 " float gl_ClipDistance[1];\n"
1844 "};\n"
1845 "void main() {\n"
1846 " vec2 vertices[3];"
1847 " vertices[0] = vec2(-0.5, -0.5);\n"
1848 " vertices[1] = vec2( 0.5, -0.5);\n"
1849 " vertices[2] = vec2( 0.5, 0.5);\n"
1850 " vec2 positions[3];"
1851 " positions[0] = vec2( 0.0, 0.0);\n"
1852 " positions[1] = vec2( 1.0, 0.0);\n"
1853 " positions[2] = vec2( 1.0, 1.0);\n"
1854 " float dists[3];\n"
1855 " dists[0] = 1.0;\n"
1856 " dists[1] = 1.0;\n"
1857 " dists[2] = -1.0;\n"
1858 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1859 " samplePos = positions[gl_VertexID % 3];\n"
1860 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1861 "}\n";
1862
1863 static const char *fragShaderText =
1864 "#version 140\n"
1865 "#extension GL_ARB_separate_shader_objects : enable\n"
1866 "#extension GL_ARB_shading_language_420pack : enable\n"
1867 "layout (location = 0) in vec2 samplePos;\n"
1868 "layout (binding = 0) uniform sampler2D surface;\n"
1869 "layout (location=0) out vec4 outColor;\n"
1870 "void main() {\n"
1871 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1872 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1873 " outColor = texColor;\n"
1874 "}\n";
1875
1876
1877 ASSERT_NO_FATAL_FAILURE(InitState());
1878 ASSERT_NO_FATAL_FAILURE(InitViewport());
1879
1880 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1881 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1882 XglSamplerObj sampler(m_device);
1883 XglTextureObj texture(m_device);
1884
1885 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1886 ps.BindShaderEntitySlotToSampler(0, &sampler);
1887
1888 XglPipelineObj pipelineobj(m_device);
1889 pipelineobj.AddShader(&vs);
1890 pipelineobj.AddShader(&ps);
1891
1892 XglDescriptorSetObj descriptorSet(m_device);
1893 descriptorSet.AttachImageView(&texture);
1894 descriptorSet.AttachSampler(&sampler);
1895
1896 m_memoryRefManager.AddMemoryRef(&texture);
1897
Tony Barboura3953b82014-12-03 15:46:29 -07001898 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001899 QueueCommandBuffer(NULL, 0);
1900}
1901TEST_F(XglRenderTest, FSTriangle)
1902{
1903 // The expected result from this test is a red and green checkered triangle
1904 static const char *vertShaderText =
1905 "#version 140\n"
1906 "#extension GL_ARB_separate_shader_objects : enable\n"
1907 "#extension GL_ARB_shading_language_420pack : enable\n"
1908 "layout (location = 0) out vec2 samplePos;\n"
1909 "void main() {\n"
1910 " vec2 vertices[3];"
1911 " vertices[0] = vec2(-0.5, -0.5);\n"
1912 " vertices[1] = vec2( 0.5, -0.5);\n"
1913 " vertices[2] = vec2( 0.5, 0.5);\n"
1914 " vec2 positions[3];"
1915 " positions[0] = vec2( 0.0, 0.0);\n"
1916 " positions[1] = vec2( 1.0, 0.0);\n"
1917 " positions[2] = vec2( 1.0, 1.0);\n"
1918 " samplePos = positions[gl_VertexID % 3];\n"
1919 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1920 "}\n";
1921
1922 static const char *fragShaderText =
1923 "#version 140\n"
1924 "#extension GL_ARB_separate_shader_objects : enable\n"
1925 "#extension GL_ARB_shading_language_420pack : enable\n"
1926 "layout (location = 0) in vec2 samplePos;\n"
1927 "layout (binding = 0) uniform sampler2D surface;\n"
1928 "layout (location=0) out vec4 outColor;\n"
1929 "void main() {\n"
1930 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1931 " outColor = texColor;\n"
1932 "}\n";
1933
1934 ASSERT_NO_FATAL_FAILURE(InitState());
1935 ASSERT_NO_FATAL_FAILURE(InitViewport());
1936
1937 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1938 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1939 XglSamplerObj sampler(m_device);
1940 XglTextureObj texture(m_device);
1941
1942 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1943 ps.BindShaderEntitySlotToSampler(0, &sampler);
1944
1945 XglPipelineObj pipelineobj(m_device);
1946 pipelineobj.AddShader(&vs);
1947 pipelineobj.AddShader(&ps);
1948
1949 XglDescriptorSetObj descriptorSet(m_device);
1950 descriptorSet.AttachImageView(&texture);
1951 descriptorSet.AttachSampler(&sampler);
1952
1953 m_memoryRefManager.AddMemoryRef(&texture);
1954
Tony Barboura3953b82014-12-03 15:46:29 -07001955 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001956 QueueCommandBuffer(NULL, 0);
1957}
1958TEST_F(XglRenderTest, SamplerBindingsTriangle)
1959{
1960 // This test sets bindings on the samplers
1961 // For now we are asserting that sampler and texture pairs
1962 // march in lock step, and are set via GLSL binding. This can
1963 // and will probably change.
1964 // The sampler bindings should match the sampler and texture slot
1965 // number set up by the application.
1966 // This test will result in a blue triangle
1967 static const char *vertShaderText =
1968 "#version 140\n"
1969 "#extension GL_ARB_separate_shader_objects : enable\n"
1970 "#extension GL_ARB_shading_language_420pack : enable\n"
1971 "layout (location = 0) out vec4 samplePos;\n"
1972 "void main() {\n"
1973 " vec2 vertices[3];"
1974 " vertices[0] = vec2(-0.5, -0.5);\n"
1975 " vertices[1] = vec2( 0.5, -0.5);\n"
1976 " vertices[2] = vec2( 0.5, 0.5);\n"
1977 " vec2 positions[3];"
1978 " positions[0] = vec2( 0.0, 0.0);\n"
1979 " positions[1] = vec2( 1.0, 0.0);\n"
1980 " positions[2] = vec2( 1.0, 1.0);\n"
1981 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
1982 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1983 "}\n";
1984
1985 static const char *fragShaderText =
1986 "#version 140\n"
1987 "#extension GL_ARB_separate_shader_objects : enable\n"
1988 "#extension GL_ARB_shading_language_420pack : enable\n"
1989 "layout (location = 0) in vec4 samplePos;\n"
1990 "layout (binding = 0) uniform sampler2D surface0;\n"
1991 "layout (binding = 1) uniform sampler2D surface1;\n"
1992 "layout (binding = 12) uniform sampler2D surface2;\n"
1993 "void main() {\n"
1994 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
1995 "}\n";
1996
1997 ASSERT_NO_FATAL_FAILURE(InitState());
1998 ASSERT_NO_FATAL_FAILURE(InitViewport());
1999
2000 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2001 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2002
2003 XglSamplerObj sampler1(m_device);
2004 XglSamplerObj sampler2(m_device);
2005 XglSamplerObj sampler3(m_device);
2006
2007 XglTextureObj texture1(m_device); // Red
2008 texture1.ChangeColors(0xffff0000,0xffff0000);
2009 XglTextureObj texture2(m_device); // Green
2010 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2011 XglTextureObj texture3(m_device); // Blue
2012 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2013
2014 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture1);
2015 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2016
2017 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_RESOURCE, &texture2);
2018 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2019
2020 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_RESOURCE, &texture3);
2021 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2022
2023 XglPipelineObj pipelineobj(m_device);
2024 pipelineobj.AddShader(&vs);
2025 pipelineobj.AddShader(&ps);
2026
2027 XglDescriptorSetObj descriptorSet(m_device);
2028 descriptorSet.AttachImageView(&texture1);
2029 descriptorSet.AttachSampler(&sampler1);
2030 descriptorSet.AttachImageView(&texture2);
2031 descriptorSet.AttachSampler(&sampler2);
2032 descriptorSet.AttachImageView(&texture3);
2033 descriptorSet.AttachSampler(&sampler3);
2034
2035 m_memoryRefManager.AddMemoryRef(&texture1);
2036 m_memoryRefManager.AddMemoryRef(&texture2);
2037 m_memoryRefManager.AddMemoryRef(&texture3);
2038
Tony Barboura3953b82014-12-03 15:46:29 -07002039 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002040 QueueCommandBuffer(NULL, 0);
2041
2042}
2043
2044TEST_F(XglRenderTest, TriangleVSUniformBlock)
2045{
2046 // The expected result from this test is a blue triangle
2047
2048 static const char *vertShaderText =
2049 "#version 140\n"
2050 "#extension GL_ARB_separate_shader_objects : enable\n"
2051 "#extension GL_ARB_shading_language_420pack : enable\n"
2052 "layout (location = 0) out vec4 outColor;\n"
2053 "layout (std140, binding = 0) uniform bufferVals {\n"
2054 " vec4 red;\n"
2055 " vec4 green;\n"
2056 " vec4 blue;\n"
2057 " vec4 white;\n"
2058 "} myBufferVals;\n"
2059 "void main() {\n"
2060 " vec2 vertices[3];"
2061 " vertices[0] = vec2(-0.5, -0.5);\n"
2062 " vertices[1] = vec2( 0.5, -0.5);\n"
2063 " vertices[2] = vec2( 0.5, 0.5);\n"
2064 " outColor = myBufferVals.blue;\n"
2065 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2066 "}\n";
2067
2068 static const char *fragShaderText =
2069 "#version 140\n"
2070 "#extension GL_ARB_separate_shader_objects : enable\n"
2071 "#extension GL_ARB_shading_language_420pack : enable\n"
2072 "layout (location = 0) in vec4 inColor;\n"
2073 "void main() {\n"
2074 " gl_FragColor = inColor;\n"
2075 "}\n";
2076
2077 ASSERT_NO_FATAL_FAILURE(InitState());
2078 ASSERT_NO_FATAL_FAILURE(InitViewport());
2079
2080 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2081 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2082
2083 // Let's populate our buffer with the following:
2084 // vec4 red;
2085 // vec4 green;
2086 // vec4 blue;
2087 // vec4 white;
2088 const int valCount = 4 * 4;
2089 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2090 0.0, 1.0, 0.0, 1.0,
2091 0.0, 0.0, 1.0, 1.0,
2092 1.0, 1.0, 1.0, 1.0 };
2093
2094 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
2095 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
2096
2097 XglPipelineObj pipelineobj(m_device);
2098 pipelineobj.AddShader(&vs);
2099 pipelineobj.AddShader(&ps);
2100
2101 XglDescriptorSetObj descriptorSet(m_device);
2102 descriptorSet.AttachMemoryView(&colorBuffer);
2103
Tony Barboura3953b82014-12-03 15:46:29 -07002104 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002105 QueueCommandBuffer(NULL, 0);
2106
2107}
2108
2109TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2110{
2111 // This test allows the shader to select which buffer it is
2112 // pulling from using layout binding qualifier.
2113 // There are corresponding changes in the compiler stack that
2114 // will select the buffer using binding directly.
2115 // The binding number should match the slot number set up by
2116 // the application.
2117 // The expected result from this test is a purple triangle
2118
2119 static const char *vertShaderText =
2120 "#version 140\n"
2121 "#extension GL_ARB_separate_shader_objects : enable\n"
2122 "#extension GL_ARB_shading_language_420pack : enable\n"
2123 "void main() {\n"
2124 " vec2 vertices[3];"
2125 " vertices[0] = vec2(-0.5, -0.5);\n"
2126 " vertices[1] = vec2( 0.5, -0.5);\n"
2127 " vertices[2] = vec2( 0.5, 0.5);\n"
2128 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2129 "}\n";
2130
2131 static const char *fragShaderText =
2132 "#version 140\n"
2133 "#extension GL_ARB_separate_shader_objects : enable\n"
2134 "#extension GL_ARB_shading_language_420pack : enable\n"
2135 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2136 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2137 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2138 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2139 "void main() {\n"
2140 " gl_FragColor = myBlueVal.color;\n"
2141 " gl_FragColor += myRedVal.color;\n"
2142 "}\n";
2143
2144 ASSERT_NO_FATAL_FAILURE(InitState());
2145 ASSERT_NO_FATAL_FAILURE(InitViewport());
2146
2147 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2148 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2149
2150 // We're going to create a number of uniform buffers, and then allow
2151 // the shader to select which it wants to read from with a binding
2152
2153 // Let's populate the buffers with a single color each:
2154 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2155 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2156 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2157 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2158
2159 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2160 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2161 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2162 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2163
2164 const int redCount = sizeof(redVals) / sizeof(float);
2165 const int greenCount = sizeof(greenVals) / sizeof(float);
2166 const int blueCount = sizeof(blueVals) / sizeof(float);
2167 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2168
2169 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2170 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2171
2172 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2173 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2174
2175 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2176 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2177
2178 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2179 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2180
2181 XglPipelineObj pipelineobj(m_device);
2182 pipelineobj.AddShader(&vs);
2183 pipelineobj.AddShader(&ps);
2184
2185 XglDescriptorSetObj descriptorSet(m_device);
2186 descriptorSet.AttachMemoryView(&redBuffer);
2187 descriptorSet.AttachMemoryView(&greenBuffer);
2188 descriptorSet.AttachMemoryView(&blueBuffer);
2189 descriptorSet.AttachMemoryView(&whiteBuffer);
2190
Tony Barboura3953b82014-12-03 15:46:29 -07002191 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002192 QueueCommandBuffer(NULL, 0);
2193
2194}
2195
2196TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2197{
2198 // This test is the same as TriangleFSUniformBlockBinding, but
2199 // it does not provide an instance name.
2200 // The expected result from this test is a purple triangle
2201
2202 static const char *vertShaderText =
2203 "#version 140\n"
2204 "#extension GL_ARB_separate_shader_objects : enable\n"
2205 "#extension GL_ARB_shading_language_420pack : enable\n"
2206 "void main() {\n"
2207 " vec2 vertices[3];"
2208 " vertices[0] = vec2(-0.5, -0.5);\n"
2209 " vertices[1] = vec2( 0.5, -0.5);\n"
2210 " vertices[2] = vec2( 0.5, 0.5);\n"
2211 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2212 "}\n";
2213
2214 static const char *fragShaderText =
2215 "#version 430\n"
2216 "#extension GL_ARB_separate_shader_objects : enable\n"
2217 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002218 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2219 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2220 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2221 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002222 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002223 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002224 " outColor = blue;\n"
2225 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002226 "}\n";
2227 ASSERT_NO_FATAL_FAILURE(InitState());
2228 ASSERT_NO_FATAL_FAILURE(InitViewport());
2229
2230 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2231 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2232
2233 // We're going to create a number of uniform buffers, and then allow
2234 // the shader to select which it wants to read from with a binding
2235
2236 // Let's populate the buffers with a single color each:
2237 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2238 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2239 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2240 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2241
2242 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2243 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2244 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2245 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2246
2247 const int redCount = sizeof(redVals) / sizeof(float);
2248 const int greenCount = sizeof(greenVals) / sizeof(float);
2249 const int blueCount = sizeof(blueVals) / sizeof(float);
2250 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2251
2252 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2253 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2254
2255 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2256 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2257
2258 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2259 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2260
2261 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002262 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002263
2264 XglPipelineObj pipelineobj(m_device);
2265 pipelineobj.AddShader(&vs);
2266 pipelineobj.AddShader(&ps);
2267
2268 XglDescriptorSetObj descriptorSet(m_device);
2269 descriptorSet.AttachMemoryView(&redBuffer);
2270 descriptorSet.AttachMemoryView(&greenBuffer);
2271 descriptorSet.AttachMemoryView(&blueBuffer);
2272 descriptorSet.AttachMemoryView(&whiteBuffer);
2273
Tony Barboura3953b82014-12-03 15:46:29 -07002274 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002275 QueueCommandBuffer(NULL, 0);
2276
2277}
2278
2279TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2280{
2281 static const char *vertShaderText =
2282 "#version 140\n"
2283 "#extension GL_ARB_separate_shader_objects : enable\n"
2284 "#extension GL_ARB_shading_language_420pack : enable\n"
2285 "layout (std140, binding=0) uniform bufferVals {\n"
2286 " mat4 mvp;\n"
2287 "} myBufferVals;\n"
2288 "layout (location=0) in vec4 pos;\n"
2289 "layout (location=0) out vec2 UV;\n"
2290 "void main() {\n"
2291 " vec2 positions[3];"
2292 " positions[0] = vec2( 0.0, 0.0);\n"
2293 " positions[1] = vec2( 0.25, 0.1);\n"
2294 " positions[2] = vec2( 0.1, 0.25);\n"
2295 " UV = positions[gl_VertexID % 3];\n"
2296 " gl_Position = myBufferVals.mvp * pos;\n"
2297 "}\n";
2298
2299 static const char *fragShaderText =
2300 "#version 140\n"
2301 "#extension GL_ARB_separate_shader_objects : enable\n"
2302 "#extension GL_ARB_shading_language_420pack : enable\n"
2303 "layout (binding=0) uniform sampler2D surface;\n"
2304 "layout (location=0) out vec4 outColor;\n"
2305 "layout (location=0) in vec2 UV;\n"
2306 "void main() {\n"
2307 " outColor= textureLod(surface, UV, 0.0);\n"
2308 "}\n";
2309 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2310
2311 glm::mat4 View = glm::lookAt(
2312 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2313 glm::vec3(0,0,0), // and looks at the origin
2314 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2315 );
2316
2317 glm::mat4 Model = glm::mat4(1.0f);
2318
2319 glm::mat4 MVP = Projection * View * Model;
2320
2321
2322 ASSERT_NO_FATAL_FAILURE(InitState());
2323 ASSERT_NO_FATAL_FAILURE(InitViewport());
2324 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2325
2326 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2327 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
2328 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
2329
2330
2331 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2332
2333 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2334 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2335 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2336 XglSamplerObj sampler(m_device);
2337 XglTextureObj texture(m_device);
2338
2339 // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2340 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
2341 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
2342 ps.BindShaderEntitySlotToSampler(0, &sampler);
2343
2344 XglPipelineObj pipelineobj(m_device);
2345 pipelineobj.AddShader(&vs);
2346 pipelineobj.AddShader(&ps);
2347
2348 XglDescriptorSetObj descriptorSet(m_device);
2349
2350 descriptorSet.AttachMemoryView(&mvpBuffer);
2351 descriptorSet.AttachImageView(&texture);
2352 descriptorSet.AttachSampler(&sampler);
2353
2354 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2355 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2356 m_memoryRefManager.AddMemoryRef(&texture);
2357
2358 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2359 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2360 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2361 };
2362
2363 // this is the current description of g_vbData
2364 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2365 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2366 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2367 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2368 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2369 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2370 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2371 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2372 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2373
2374 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2375 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2376 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2377
Tony Barboura3953b82014-12-03 15:46:29 -07002378 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barbourf43b6982014-11-25 13:18:32 -07002379
2380 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2381
2382}
Cody Northropd1ce7842014-12-09 11:17:01 -07002383
2384TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2385{
2386 // This test mixes binding slots of textures and buffers, ensuring
2387 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002388 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002389 // you can modify it to move the desired result around.
2390
2391 static const char *vertShaderText =
2392 "#version 140\n"
2393 "#extension GL_ARB_separate_shader_objects : enable\n"
2394 "#extension GL_ARB_shading_language_420pack : enable\n"
2395 "void main() {\n"
2396 " vec2 vertices[3];"
2397 " vertices[0] = vec2(-0.5, -0.5);\n"
2398 " vertices[1] = vec2( 0.5, -0.5);\n"
2399 " vertices[2] = vec2( 0.5, 0.5);\n"
2400 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2401 "}\n";
2402
2403 static const char *fragShaderText =
2404 "#version 430\n"
2405 "#extension GL_ARB_separate_shader_objects : enable\n"
2406 "#extension GL_ARB_shading_language_420pack : enable\n"
2407 "layout (binding = 0) uniform sampler2D surface0;\n"
Cody Northropa0410942014-12-09 13:59:39 -07002408 "layout (binding = 16) uniform sampler2D surface1;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002409 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropa0410942014-12-09 13:59:39 -07002410 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002411
Cody Northropa0410942014-12-09 13:59:39 -07002412
2413 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2414 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2415 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2416 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002417 "layout (location = 0) out vec4 outColor;\n"
2418 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002419 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002420 " outColor += white * vec4(0.00001);\n"
2421 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002422 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002423 "}\n";
2424 ASSERT_NO_FATAL_FAILURE(InitState());
2425 ASSERT_NO_FATAL_FAILURE(InitViewport());
2426
2427 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2428 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2429
Cody Northropd1ce7842014-12-09 11:17:01 -07002430 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2431 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2432 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2433 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2434
2435 const int redCount = sizeof(redVals) / sizeof(float);
2436 const int greenCount = sizeof(greenVals) / sizeof(float);
2437 const int blueCount = sizeof(blueVals) / sizeof(float);
2438 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2439
2440 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropa0410942014-12-09 13:59:39 -07002441 ps.BindShaderEntitySlotToMemory(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002442
2443 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropa0410942014-12-09 13:59:39 -07002444 ps.BindShaderEntitySlotToMemory(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002445
2446 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropa0410942014-12-09 13:59:39 -07002447 ps.BindShaderEntitySlotToMemory(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002448
2449 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropa0410942014-12-09 13:59:39 -07002450 ps.BindShaderEntitySlotToMemory(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002451
2452 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002453 XglTextureObj texture0(m_device); // Light Red
2454 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002455 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture0);
2456 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2457 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002458 XglTextureObj texture2(m_device); // Light Blue
2459 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002460 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_RESOURCE, &texture2);
2461 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2462 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002463 XglTextureObj texture4(m_device); // Light Green
2464 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002465 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_RESOURCE, &texture4);
2466 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002467
2468 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2469 // TODO: Get back here ASAP and understand why.
2470 XglSamplerObj sampler7(m_device);
2471 XglTextureObj texture7(m_device); // Red and Blue
2472 texture7.ChangeColors(0xffff00ff,0xffff00ff);
2473 ps.BindShaderEntitySlotToImage(16, XGL_SLOT_SHADER_RESOURCE, &texture7);
2474 ps.BindShaderEntitySlotToSampler(16, &sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002475
2476
2477 XglPipelineObj pipelineobj(m_device);
2478 pipelineobj.AddShader(&vs);
2479 pipelineobj.AddShader(&ps);
2480
2481 XglDescriptorSetObj descriptorSet(m_device);
2482 descriptorSet.AttachMemoryView(&redBuffer);
2483 descriptorSet.AttachMemoryView(&greenBuffer);
2484 descriptorSet.AttachMemoryView(&blueBuffer);
2485 descriptorSet.AttachMemoryView(&whiteBuffer);
2486 descriptorSet.AttachImageView(&texture0);
2487 descriptorSet.AttachSampler(&sampler0);
2488 descriptorSet.AttachImageView(&texture2);
2489 descriptorSet.AttachSampler(&sampler2);
2490 descriptorSet.AttachImageView(&texture4);
2491 descriptorSet.AttachSampler(&sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002492 descriptorSet.AttachImageView(&texture7);
2493 descriptorSet.AttachSampler(&sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002494
2495 m_memoryRefManager.AddMemoryRef(&texture0);
2496 m_memoryRefManager.AddMemoryRef(&texture2);
2497 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002498 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002499
2500
2501 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
2502 QueueCommandBuffer(NULL, 0);
2503
2504}
2505
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002506int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002507 int result;
2508
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002509 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002510 XglTestFramework::InitArgs(&argc, argv);
2511
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06002512 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2513
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002514 result = RUN_ALL_TESTS();
2515
2516 XglTestFramework::Finish();
2517 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002518}