blob: b1950354cb97f1fcaf7e6be3f1617bb048d444a6 [file] [log] [blame]
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
75#include "xgldevice.h"
Courtney Goeltzenleuchterefd4e0a2014-09-01 16:37:18 -060076#include "xglimage.h"
Chia-I Wufe7c1de2014-08-28 11:56:29 +080077#include "icd-bil.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060078
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060079#define GLM_FORCE_RADIANS
80#include "glm/glm.hpp"
81#include <glm/gtc/matrix_transform.hpp>
82
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060083#include "xglrenderframework.h"
Tobin Ehlis6663f492014-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 Ehlisca915872014-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 Ehlis6663f492014-11-10 12:29:12 -0700106}
107#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700108
109
110#undef ASSERT_NO_FATAL_FAILURE
111#define ASSERT_NO_FATAL_FAILURE(x) x
112
Courtney Goeltzenleuchter02461882014-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 Goeltzenleuchter83884952014-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 Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600214class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600215{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600216public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600217
Tony Barboure2c58df2014-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 Barbour1c042032014-12-03 16:13:23 -0700220 XglConstantBufferObj *constantBuffer);
Tony Barbour2bd96162014-12-03 15:46:29 -0700221 void GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet, int numTris);
Tony Barboure2c58df2014-11-25 13:18:32 -0700222 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
223
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600224 void InitDepthStencil();
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600225 void GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600226 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600227
Cody Northropee6586d2014-10-09 19:55:56 -0600228
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600229protected:
Cody Northrop7d2035d2014-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 Goeltzenleuchter83884952014-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 Barboure2c58df2014-11-25 13:18:32 -0700241 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600242
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600243
244 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600245
246 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
247 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800248 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600249 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800250 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600251 this->app_info.engineVersion = 1;
252 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
253
Cody Northrop7d2035d2014-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 Barboure3e2e3f2014-12-04 17:14:45 -0700256 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600257
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600258 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600259 }
260
261 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600262 // Clean up resources before we reset
263 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600264 }
265};
266
Tony Barboure2c58df2014-11-25 13:18:32 -0700267
Tony Barbour2bd96162014-12-03 15:46:29 -0700268void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600269{
270 XGL_RESULT err = XGL_SUCCESS;
271
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600273 // Build command buffer
274 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
275 ASSERT_XGL_SUCCESS(err);
276
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600277 GenerateClearAndPrepareBufferCmds();
278 GenerateBindRenderTargetCmd();
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700279
Tony Barboure2c58df2014-11-25 13:18:32 -0700280 GenerateBindStateAndPipelineCmds();
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600281
Tony Barbour2bd96162014-12-03 15:46:29 -0700282 pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet);
Tony Barbour5420af02014-12-03 13:58:15 -0700283 descriptorSet->BindCommandBuffer(m_cmdBuffer);
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700284#ifdef DUMP_STATE_DOT
285 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
286 pDSDumpDot((char*)"triTest.dot");
287 DRAW_STATE_DUMP_PNG_FILE pDSDumpPng = (DRAW_STATE_DUMP_PNG_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpPngFile");
288 pDSDumpPng((char*)"triTest.png");
289#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700290 // render the triangle
291 xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 );
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600292
293 // finalize recording of the command buffer
294 err = xglEndCommandBuffer( m_cmdBuffer );
295 ASSERT_XGL_SUCCESS( err );
Tony Barboure2c58df2014-11-25 13:18:32 -0700296}
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600297
Tony Barboure2c58df2014-11-25 13:18:32 -0700298void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
299{
300 XGL_RESULT err = XGL_SUCCESS;
Chia-I Wuecebf752014-12-05 10:45:15 +0800301 XGL_UINT i;
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600302
303 // submit the command buffer to the universal queue
Tony Barboure2c58df2014-11-25 13:18:32 -0700304 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL );
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600305 ASSERT_XGL_SUCCESS( err );
306
Chia-I Wu113e9d92014-08-27 14:58:05 +0800307 err = xglQueueWaitIdle( m_device->m_queue );
308 ASSERT_XGL_SUCCESS( err );
309
Courtney Goeltzenleuchter464746c2014-08-26 18:16:41 -0600310 // Wait for work to finish before cleaning up.
311 xglDeviceWaitIdle(m_device->device());
312
Chia-I Wuecebf752014-12-05 10:45:15 +0800313 for (i = 0; i < m_renderTargetCount; i++)
314 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600315}
316
Tony Barboure2c58df2014-11-25 13:18:32 -0700317void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600318{
Cody Northropee6586d2014-10-09 19:55:56 -0600319 XGL_RESULT err;
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600320
Cody Northropee6586d2014-10-09 19:55:56 -0600321 ASSERT_NO_FATAL_FAILURE(InitState());
322 ASSERT_NO_FATAL_FAILURE(InitViewport());
323
Tony Barboure2c58df2014-11-25 13:18:32 -0700324 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
325 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Cody Northropee6586d2014-10-09 19:55:56 -0600326
Cody Northropee6586d2014-10-09 19:55:56 -0600327
Tony Barboure2c58df2014-11-25 13:18:32 -0700328 XglPipelineObj pipelineobj(m_device);
329 pipelineobj.AddShader(&vs);
330 pipelineobj.AddShader(&ps);
Cody Northropee6586d2014-10-09 19:55:56 -0600331
332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
333
Tony Barboure2c58df2014-11-25 13:18:32 -0700334 // Create descriptor set
335 XglDescriptorSetObj descriptorSet(m_device);
Cody Northropee6586d2014-10-09 19:55:56 -0600336
337 // Build command buffer
338 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
339 ASSERT_XGL_SUCCESS(err);
340
341 GenerateClearAndPrepareBufferCmds();
342 GenerateBindRenderTargetCmd();
Tony Barboure2c58df2014-11-25 13:18:32 -0700343 GenerateBindStateAndPipelineCmds();
Cody Northropee6586d2014-10-09 19:55:56 -0600344
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700345 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
346 descriptorSet.BindCommandBuffer(m_cmdBuffer);
Tobin Ehlis11e52132014-11-28 11:17:19 -0700347#ifdef DUMP_STATE_DOT
348 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
349 pDSDumpDot((char*)"triUniFS.dot");
350#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700351 // render the triangle
352 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
Cody Northropee6586d2014-10-09 19:55:56 -0600353
354 // finalize recording of the command buffer
355 err = xglEndCommandBuffer( m_cmdBuffer );
356 ASSERT_XGL_SUCCESS( err );
357
Cody Northropee6586d2014-10-09 19:55:56 -0600358 // submit the command buffer to the universal queue
Tony Barbour75e9ee42014-12-04 17:17:26 -0700359 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL );
Cody Northropee6586d2014-10-09 19:55:56 -0600360 ASSERT_XGL_SUCCESS( err );
361
362 err = xglQueueWaitIdle( m_device->m_queue );
363 ASSERT_XGL_SUCCESS( err );
364
365 // Wait for work to finish before cleaning up.
366 xglDeviceWaitIdle(m_device->device());
367
Chia-I Wuecebf752014-12-05 10:45:15 +0800368 assert(m_renderTargetCount == 1);
369 RecordImage(m_renderTargets[0]);
Cody Northropee6586d2014-10-09 19:55:56 -0600370
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600371}
372
Tony Barboure2c58df2014-11-25 13:18:32 -0700373void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour1c042032014-12-03 16:13:23 -0700374 XglConstantBufferObj *constantBuffer)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600375{
376 int i;
377 glm::mat4 MVP;
378 int matrixSize = sizeof(MVP);
379 XGL_RESULT err;
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600380
381 for (i = 0; i < 8; i++) {
Chia-I Wua07fee62014-12-28 15:26:08 +0800382 void *pData = constantBuffer->map();
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600383
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600384 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
385 MVP = Projection * View * Model;
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600386 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
387
Chia-I Wua07fee62014-12-28 15:26:08 +0800388 constantBuffer->unmap();
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600389
390 // submit the command buffer to the universal queue
Tony Barboure2c58df2014-11-25 13:18:32 -0700391 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600392 ASSERT_XGL_SUCCESS( err );
393
394 err = xglQueueWaitIdle( m_device->m_queue );
395 ASSERT_XGL_SUCCESS( err );
396
397 // Wait for work to finish before cleaning up.
398 xglDeviceWaitIdle(m_device->device());
399
Chia-I Wuecebf752014-12-05 10:45:15 +0800400 assert(m_renderTargetCount == 1);
401 RecordImage(m_renderTargets[0]);
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600402 }
Cody Northrop66594a72014-10-10 14:49:36 -0600403}
404
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600405void dumpMatrix(const char *note, glm::mat4 MVP)
406{
Chia-I Wu6f184292014-12-15 23:57:34 +0800407 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600408
409 printf("%s: \n", note);
410 for (i=0; i<4; i++) {
411 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
412 }
413 printf("\n");
414 fflush(stdout);
415}
416
417void dumpVec4(const char *note, glm::vec4 vector)
418{
419 printf("%s: \n", note);
420 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
421 printf("\n");
422 fflush(stdout);
423}
424
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600425void XglRenderTest::GenerateClearAndPrepareBufferCmds()
426{
427 XglRenderFramework::GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600428
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700429 if (m_depthStencilImage) {
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700430 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
431 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
432 dsRange.baseMipLevel = 0;
433 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
434 dsRange.baseArraySlice = 0;
435 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
Cody Northrop66594a72014-10-10 14:49:36 -0600436
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700437 // prepare the depth buffer for clear
438 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
439 transitionToClear.image = m_depthStencilImage;
440 transitionToClear.oldState = m_depthStencilBinding.depthState;
441 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
442 transitionToClear.subresourceRange = dsRange;
443 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
444 m_depthStencilBinding.depthState = transitionToClear.newState;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600445
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700446 xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600447
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700448 // prepare depth buffer for rendering
449 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wufc0c2842014-12-05 10:48:20 +0800450 transitionToRender.image = m_depthStencilImage;
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700451 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
452 transitionToRender.newState = m_depthStencilBinding.depthState;
453 transitionToRender.subresourceRange = dsRange;
454 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
455 m_depthStencilBinding.depthState = transitionToClear.newState;
456 }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600457}
458
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600459void XglRenderTest::InitDepthStencil()
460{
461 XGL_RESULT err;
462 XGL_IMAGE_CREATE_INFO image;
463 XGL_MEMORY_ALLOC_INFO mem_alloc;
464 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
465 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburnb9e193f2014-11-21 11:33:20 -0700466 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600467
468 // Clean up default state created by framework
469 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
470
471 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
472 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
473
474 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
475 image.pNext = NULL;
476 image.imageType = XGL_IMAGE_2D;
477 image.format = m_depth_stencil_fmt;
478 image.extent.width = m_width;
479 image.extent.height = m_height;
480 image.extent.depth = 1;
481 image.mipLevels = 1;
482 image.arraySize = 1;
483 image.samples = 1;
484 image.tiling = XGL_OPTIMAL_TILING;
485 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
486 image.flags = 0;
487
488 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
489 mem_alloc.pNext = NULL;
490 mem_alloc.allocationSize = 0;
491 mem_alloc.alignment = 0;
492 mem_alloc.flags = 0;
493 mem_alloc.heapCount = 0;
494 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
495
496 /* create image */
497 err = xglCreateImage(device(), &image,
498 &m_depthStencilImage);
499 ASSERT_XGL_SUCCESS(err);
500
501 err = xglGetObjectInfo(m_depthStencilImage,
502 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
503 &mem_reqs_size, &mem_reqs);
504 ASSERT_XGL_SUCCESS(err);
505 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
506
507 mem_alloc.allocationSize = mem_reqs.size;
508 mem_alloc.alignment = mem_reqs.alignment;
509 mem_alloc.heapCount = mem_reqs.heapCount;
510 memcpy(mem_alloc.heaps, mem_reqs.heaps,
511 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
512
513 /* allocate memory */
514 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
515 ASSERT_XGL_SUCCESS(err);
516
517 /* bind memory */
518 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
519 ASSERT_XGL_SUCCESS(err);
520
521 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
522 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
523 depthStencil.depthTestEnable = XGL_TRUE;
524 depthStencil.depthWriteEnable = XGL_TRUE;
525 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
526 depthStencil.depthBoundsEnable = XGL_FALSE;
527 depthStencil.minDepth = 0.f;
528 depthStencil.maxDepth = 1.f;
529 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
530 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
531 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
532 depthStencil.back.stencilRef = 0x00;
533 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
534 depthStencil.front = depthStencil.back;
535
536 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
537 ASSERT_XGL_SUCCESS( err );
538
539 /* create image view */
540 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
541 view.pNext = NULL;
542 view.image = XGL_NULL_HANDLE;
543 view.mipLevel = 0;
544 view.baseArraySlice = 0;
545 view.arraySize = 1;
546 view.flags = 0;
547 view.image = m_depthStencilImage;
548 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
549 ASSERT_XGL_SUCCESS(err);
550
551 m_depthStencilBinding.view = m_depthStencilView;
552 m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
553 m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
554}
555
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600556struct xgltriangle_vs_uniform {
557 // Must start with MVP
558 XGL_FLOAT mvp[4][4];
559 XGL_FLOAT position[3][4];
560 XGL_FLOAT color[3][4];
561};
562
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600563void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600564{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700565#ifdef DEBUG_CALLBACK
566 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
567#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600568 // Create identity matrix
569 int i;
570 struct xgltriangle_vs_uniform data;
571
572 glm::mat4 Projection = glm::mat4(1.0f);
573 glm::mat4 View = glm::mat4(1.0f);
574 glm::mat4 Model = glm::mat4(1.0f);
575 glm::mat4 MVP = Projection * View * Model;
576 const int matrixSize = sizeof(MVP);
577 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
578 memcpy(&data.mvp, &MVP[0][0], matrixSize);
579
580 static const Vertex tri_data[] =
581 {
582 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
583 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
584 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
585 };
586
587 for (i=0; i<3; i++) {
588 data.position[i][0] = tri_data[i].posX;
589 data.position[i][1] = tri_data[i].posY;
590 data.position[i][2] = tri_data[i].posZ;
591 data.position[i][3] = tri_data[i].posW;
592 data.color[i][0] = tri_data[i].r;
593 data.color[i][1] = tri_data[i].g;
594 data.color[i][2] = tri_data[i].b;
595 data.color[i][3] = tri_data[i].a;
596 }
597
Tony Barboure2c58df2014-11-25 13:18:32 -0700598 ASSERT_NO_FATAL_FAILURE(InitState());
599 ASSERT_NO_FATAL_FAILURE(InitViewport());
600
601 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
602
603 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
604 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
605 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
606
607 XglPipelineObj pipelineobj(m_device);
608 pipelineobj.AddShader(&vs);
609 pipelineobj.AddShader(&ps);
610
611 XglDescriptorSetObj descriptorSet(m_device);
612 descriptorSet.AttachMemoryView(&constantBuffer);
613 m_memoryRefManager.AddMemoryRef(&constantBuffer);
614
Tony Barbour2bd96162014-12-03 15:46:29 -0700615 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700616 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
617
Tony Barbour1c042032014-12-03 16:13:23 -0700618 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tobin Ehlisca915872014-11-18 11:28:33 -0700619#ifdef PRINT_OBJECTS
620 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
621 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
622 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
623 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
624 printf("DEBUG : Number of Objects : %lu\n", numObjects);
625 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
626 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
627 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
628 for (i=0; i < numObjects; i++) {
629 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);
630 }
631 free(pObjNodeArray);
632#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700633
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600634}
635
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600636TEST_F(XglRenderTest, XGLTriangle_FragColor)
637{
638 static const char *vertShaderText =
639 "#version 140\n"
640 "#extension GL_ARB_separate_shader_objects : enable\n"
641 "#extension GL_ARB_shading_language_420pack : enable\n"
642 "\n"
643 "layout(binding = 0) uniform buf {\n"
644 " mat4 MVP;\n"
645 " vec4 position[3];\n"
646 " vec4 color[3];\n"
647 "} ubuf;\n"
648 "\n"
649 "layout (location = 0) out vec4 outColor;\n"
650 "\n"
651 "void main() \n"
652 "{\n"
653 " outColor = ubuf.color[gl_VertexID];\n"
654 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
655 "}\n";
656
657 static const char *fragShaderText =
658 "#version 140\n"
659 "#extension GL_ARB_separate_shader_objects : enable\n"
660 "#extension GL_ARB_shading_language_420pack : enable\n"
661 "\n"
662 "layout (location = 0) in vec4 inColor;\n"
663 "\n"
664 "void main()\n"
665 "{\n"
666 " gl_FragColor = inColor;\n"
667 "}\n";
668
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600669 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600670 XGLTriangleTest(vertShaderText, fragShaderText);
671}
672
673TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
674{
675 static const char *vertShaderText =
676 "#version 140\n"
677 "#extension GL_ARB_separate_shader_objects : enable\n"
678 "#extension GL_ARB_shading_language_420pack : enable\n"
679 "\n"
680 "layout(binding = 0) uniform buf {\n"
681 " mat4 MVP;\n"
682 " vec4 position[3];\n"
683 " vec4 color[3];\n"
684 "} ubuf;\n"
685 "\n"
686 "layout (location = 0) out vec4 outColor;\n"
687 "\n"
688 "void main() \n"
689 "{\n"
690 " outColor = ubuf.color[gl_VertexID];\n"
691 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
692 "}\n";
693
694 static const char *fragShaderText =
695 "#version 140\n"
696 "#extension GL_ARB_separate_shader_objects : enable\n"
697 "#extension GL_ARB_shading_language_420pack : enable\n"
698 "\n"
699 "layout (location = 0) in vec4 inColor;\n"
700 "layout (location = 0) out vec4 outColor;\n"
701 "\n"
702 "void main()\n"
703 "{\n"
704 " outColor = inColor;\n"
705 "}\n";
706
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600707 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600708
709 XGLTriangleTest(vertShaderText, fragShaderText);
710}
711
Tony Barboure2c58df2014-11-25 13:18:32 -0700712TEST_F(XglRenderTest, BIL_XGLTriangle)
713{
714 bool saved_use_bil = XglTestFramework::m_use_bil;
715
716 static const char *vertShaderText =
717 "#version 140\n"
718 "#extension GL_ARB_separate_shader_objects : enable\n"
719 "#extension GL_ARB_shading_language_420pack : enable\n"
720 "\n"
721 "layout(binding = 0) uniform buf {\n"
722 " mat4 MVP;\n"
723 " vec4 position[3];\n"
724 " vec4 color[3];\n"
725 "} ubuf;\n"
726 "\n"
727 "layout (location = 0) out vec4 outColor;\n"
728 "\n"
729 "void main() \n"
730 "{\n"
731 " outColor = ubuf.color[gl_VertexID];\n"
732 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
733 "}\n";
734
735 static const char *fragShaderText =
736 "#version 140\n"
737 "#extension GL_ARB_separate_shader_objects : enable\n"
738 "#extension GL_ARB_shading_language_420pack : enable\n"
739 "\n"
740 "layout (location = 0) in vec4 inColor;\n"
741 "\n"
742 "void main()\n"
743 "{\n"
744 " gl_FragColor = inColor;\n"
745 "}\n";
746
747 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
748
749 XglTestFramework::m_use_bil = true;
750
751 XGLTriangleTest(vertShaderText, fragShaderText);
752
753 XglTestFramework::m_use_bil = saved_use_bil;
754}
755
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600756TEST_F(XglRenderTest, GreenTriangle)
Cody Northropd1a256b2014-10-09 21:26:47 -0600757{
758 static const char *vertShaderText =
759 "#version 130\n"
760 "vec2 vertices[3];\n"
761 "void main() {\n"
762 " vertices[0] = vec2(-1.0, -1.0);\n"
763 " vertices[1] = vec2( 1.0, -1.0);\n"
764 " vertices[2] = vec2( 0.0, 1.0);\n"
765 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
766 "}\n";
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600767
Cody Northropd1a256b2014-10-09 21:26:47 -0600768 static const char *fragShaderText =
769 "#version 130\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600770 "void main() {\n"
Steve Kc53f8632014-10-10 08:54:29 -0600771 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600772 "}\n";
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600773
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600774 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
775
Cody Northropd1a256b2014-10-09 21:26:47 -0600776 DrawTriangleTest(vertShaderText, fragShaderText);
777}
Cody Northropee6586d2014-10-09 19:55:56 -0600778
Tony Barboure2c58df2014-11-25 13:18:32 -0700779TEST_F(XglRenderTest, BIL_GreenTriangle)
780{
781 bool saved_use_bil = XglTestFramework::m_use_bil;
782
783 static const char *vertShaderText =
784 "#version 130\n"
785 "vec2 vertices[3];\n"
786 "void main() {\n"
787 " vertices[0] = vec2(-1.0, -1.0);\n"
788 " vertices[1] = vec2( 1.0, -1.0);\n"
789 " vertices[2] = vec2( 0.0, 1.0);\n"
790 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
791 "}\n";
792
793 static const char *fragShaderText =
794 "#version 130\n"
795 "void main() {\n"
796 " gl_FragColor = vec4(0,1,0,1);\n"
797 "}\n";
798
799 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
800
801 XglTestFramework::m_use_bil = true;
802 DrawTriangleTest(vertShaderText, fragShaderText);
803 XglTestFramework::m_use_bil = saved_use_bil;
804}
805
806TEST_F(XglRenderTest, YellowTriangle)
807{
808 static const char *vertShaderText =
809 "#version 130\n"
810 "void main() {\n"
811 " vec2 vertices[3];"
812 " vertices[0] = vec2(-0.5, -0.5);\n"
813 " vertices[1] = vec2( 0.5, -0.5);\n"
814 " vertices[2] = vec2( 0.5, 0.5);\n"
815 " vec4 colors[3];\n"
816 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
817 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
818 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
819 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
820 "}\n";
821
822 static const char *fragShaderText =
823 "#version 130\n"
824 "void main() {\n"
825 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
826 "}\n";
827
828 DrawTriangleTest(vertShaderText, fragShaderText);
829}
830
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600831TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600832{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600833 static const char *vertShaderText =
Tony Barboure2c58df2014-11-25 13:18:32 -0700834 "#version 130\n"
835 //XYZ1( -1, -1, -1 )
836 "in vec4 pos;\n"
837 //XYZ1( 0.f, 0.f, 0.f )
838 "in vec4 inColor;\n"
839 "out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600840 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600841 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600842 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600843 "}\n";
844
Cody Northropee6586d2014-10-09 19:55:56 -0600845
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600846 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700847 "#version 140\n"
848 "#extension GL_ARB_separate_shader_objects : enable\n"
849 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700850 "in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700851 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600852 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700853 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600854 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600855
Tony Barboure2c58df2014-11-25 13:18:32 -0700856
857
858 ASSERT_NO_FATAL_FAILURE(InitState());
859 ASSERT_NO_FATAL_FAILURE(InitViewport());
860
861 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -0700862 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -0700863
864 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
865 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
866
867 XglPipelineObj pipelineobj(m_device);
868 pipelineobj.AddShader(&vs);
869 pipelineobj.AddShader(&ps);
870
871 XglDescriptorSetObj descriptorSet(m_device);
872 descriptorSet.AttachMemoryView(&meshBuffer);
873
874 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
875 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
876 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
877 };
878
879 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
880 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
881 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
882 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
883 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
884 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
885 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
886 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
887 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
888
889 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
890 pipelineobj.AddVertexInputBindings(&vi_binding,1);
891 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
892
Tony Barbour2bd96162014-12-03 15:46:29 -0700893 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -0700894 QueueCommandBuffer(NULL, 0);
895
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600896}
897
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800898TEST_F(XglRenderTest, TriangleMRT)
899{
900 static const char *vertShaderText =
901 "#version 130\n"
902 "in vec4 pos;\n"
903 "void main() {\n"
904 " gl_Position = pos;\n"
905 "}\n";
906
907 static const char *fragShaderText =
908 "#version 130\n"
909 "void main() {\n"
910 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
911 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
912 "}\n";
913 const XGL_FLOAT vb_data[][2] = {
914 { -1.0f, -1.0f },
915 { 1.0f, -1.0f },
916 { -1.0f, 1.0f }
917 };
918
919 ASSERT_NO_FATAL_FAILURE(InitState());
920 ASSERT_NO_FATAL_FAILURE(InitViewport());
921
922 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Tony Barbour099a9eb2014-12-10 17:40:15 -0700923 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800924
925 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
926 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
927
928 XglPipelineObj pipelineobj(m_device);
929 pipelineobj.AddShader(&vs);
930 pipelineobj.AddShader(&ps);
931
932 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
933 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
934 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
935 };
936
937 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
938 vi_attrib.binding = 0; // index into vertexBindingDescriptions
939 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
940 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
941 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
942
943 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
944 pipelineobj.AddVertexInputBindings(&vi_binding,1);
945 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
946
947 XglDescriptorSetObj descriptorSet(m_device);
948
949 m_renderTargetCount = 2;
950
951 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
952 att.blendEnable = XGL_FALSE;
953 att.format = m_render_target_fmt;
954 att.channelWriteMask = 0xf;
955 pipelineobj.SetColorAttachment(1, &att);
956
957 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
958 QueueCommandBuffer(NULL, 0);
959}
960
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700961TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
962{
963 static const char *vertShaderText =
964 "#version 140\n"
965 "#extension GL_ARB_separate_shader_objects : enable\n"
966 "#extension GL_ARB_shading_language_420pack : enable\n"
967 "layout(location = 0) in vec4 pos;\n"
968 "layout(location = 1) in vec4 inColor;\n"
969 "layout(location = 0) out vec4 outColor;\n"
970 "void main() {\n"
971 " outColor = inColor;\n"
972 " gl_Position = pos;\n"
973 "}\n";
974
975
976 static const char *fragShaderText =
977 "#version 140\n"
978 "#extension GL_ARB_separate_shader_objects : enable\n"
979 "#extension GL_ARB_shading_language_420pack : enable\n"
980 "layout(location = 0) in vec4 color;\n"
981 "void main() {\n"
982 " gl_FragColor = color;\n"
983 "}\n";
984
985 const Vertex g_vbData[] =
986 {
987 // first tri
988 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
989 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
990 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
991
992 // second tri
993 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
994 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
995 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
996 };
997
998 const uint16_t g_idxData[6] = {
999 0, 1, 2,
1000 3, 4, 5,
1001 };
1002
1003 ASSERT_NO_FATAL_FAILURE(InitState());
1004 ASSERT_NO_FATAL_FAILURE(InitViewport());
1005
1006 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001007 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001008
1009 XglIndexBufferObj indexBuffer(m_device);
1010 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001011 indexBuffer.SetMemoryState(XGL_MEMORY_STATE_INDEX_DATA);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001012
1013 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1014 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1015
1016 XglPipelineObj pipelineobj(m_device);
1017 pipelineobj.AddShader(&vs);
1018 pipelineobj.AddShader(&ps);
1019
1020 XglDescriptorSetObj descriptorSet(m_device);
1021
1022 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1023 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1024 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1025 };
1026
1027 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1028 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1029 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1030 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1031 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1032 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1033 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1034 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1035 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1036
1037 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1038 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourad8f1542014-12-17 11:16:05 -07001039 pipelineobj.CreateXGLPipeline(&descriptorSet);
1040 descriptorSet.CreateXGLDescriptorSet();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001041
1042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourad8f1542014-12-17 11:16:05 -07001043 XglCommandBufferObj cmdBuffer(m_device);
1044 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1045 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1046 cmdBuffer.ClearAllBuffers(NULL, NULL);
1047 cmdBuffer.BindAttachments(NULL);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001048
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001049#ifdef DUMP_STATE_DOT
1050 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -07001051 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001052#endif
Tony Barbourad8f1542014-12-17 11:16:05 -07001053 cmdBuffer.BindState(m_stateRaster, m_stateViewport, m_colorBlend, m_stateDepthStencil, m_stateMsaa);
1054 cmdBuffer.BindPipeline(pipelineobj.GetPipelineHandle());
1055 cmdBuffer.BindDescriptorSet(descriptorSet.GetDescriptorSetHandle());
1056 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1057 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001058
1059 // render two triangles
Tony Barbourad8f1542014-12-17 11:16:05 -07001060 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001061
1062 // finalize recording of the command buffer
Tony Barbourad8f1542014-12-17 11:16:05 -07001063 cmdBuffer.EndCommandBuffer();
1064 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001065
Tony Barbourad8f1542014-12-17 11:16:05 -07001066 for (int i = 0; i < m_renderTargetCount; i++)
1067 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001068
1069}
1070
GregF3156cb02014-12-02 15:41:44 -07001071TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1072{
1073 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001074
GregF3156cb02014-12-02 15:41:44 -07001075 static const char *vertShaderText =
1076 "#version 140\n"
1077 "#extension GL_ARB_separate_shader_objects : enable\n"
1078 "#extension GL_ARB_shading_language_420pack : enable\n"
1079 "layout (location = 0) in vec4 pos;\n"
1080 "layout (location = 0) out vec4 outColor;\n"
1081 "layout (location = 1) out vec4 outColor2;\n"
1082 "void main() {\n"
1083 " gl_Position = pos;\n"
1084 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1085 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1086 "}\n";
1087
1088 static const char *fragShaderText =
1089 //"#version 140\n"
1090 "#version 330\n"
1091 "#extension GL_ARB_separate_shader_objects : enable\n"
1092 "#extension GL_ARB_shading_language_420pack : enable\n"
1093 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1094 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1095 "layout (location = 0) in vec4 color;\n"
1096 "layout (location = 1) in vec4 color2;\n"
1097 "void main() {\n"
1098 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1099 " float dist_squared = dot(pos, pos);\n"
1100 " gl_FragColor = (dist_squared < 400.0)\n"
1101 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1102 " : color2;\n"
1103 "}\n";
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106 ASSERT_NO_FATAL_FAILURE(InitViewport());
1107
1108 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001109 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001110
1111 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1112 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1113
1114 XglPipelineObj pipelineobj(m_device);
1115 pipelineobj.AddShader(&vs);
1116 pipelineobj.AddShader(&ps);
1117
1118 XglDescriptorSetObj descriptorSet(m_device);
1119 descriptorSet.AttachMemoryView(&meshBuffer);
1120
1121 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1122 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1123 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1124 };
1125
1126 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1127 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1128 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1129 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1130 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1131 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1132 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1133 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1134 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1135
1136 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1137 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1138 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1139
Tony Barbour1c042032014-12-03 16:13:23 -07001140 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF3156cb02014-12-02 15:41:44 -07001141 QueueCommandBuffer(NULL, 0);
1142
1143}
1144
1145TEST_F(XglRenderTest, RedCirclesonBlue)
1146{
1147 // This tests that we correctly handle unread fragment inputs
1148
1149 static const char *vertShaderText =
1150 "#version 140\n"
1151 "#extension GL_ARB_separate_shader_objects : enable\n"
1152 "#extension GL_ARB_shading_language_420pack : enable\n"
1153 "layout (location = 0) in vec4 pos;\n"
1154 "layout (location = 0) out vec4 outColor;\n"
1155 "layout (location = 1) out vec4 outColor2;\n"
1156 "void main() {\n"
1157 " gl_Position = pos;\n"
1158 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1159 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1160 "}\n";
1161
1162 static const char *fragShaderText =
1163 //"#version 140\n"
1164 "#version 330\n"
1165 "#extension GL_ARB_separate_shader_objects : enable\n"
1166 "#extension GL_ARB_shading_language_420pack : enable\n"
1167 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1168 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1169 "layout (location = 0) in vec4 color;\n"
1170 "layout (location = 1) in vec4 color2;\n"
1171 "void main() {\n"
1172 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1173 " float dist_squared = dot(pos, pos);\n"
1174 " gl_FragColor = (dist_squared < 400.0)\n"
1175 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1176 " : color2;\n"
1177 "}\n";
1178
1179 ASSERT_NO_FATAL_FAILURE(InitState());
1180 ASSERT_NO_FATAL_FAILURE(InitViewport());
1181
1182 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001183 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001184
1185 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1186 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1187
1188 XglPipelineObj pipelineobj(m_device);
1189 pipelineobj.AddShader(&vs);
1190 pipelineobj.AddShader(&ps);
1191
1192 XglDescriptorSetObj descriptorSet(m_device);
1193 descriptorSet.AttachMemoryView(&meshBuffer);
1194
1195 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1196 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1197 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1198 };
1199
1200 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1201 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1202 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1203 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1204 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1205 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1206 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1207 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1208 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1209
1210 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1211 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1212 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1213
Tony Barbour1c042032014-12-03 16:13:23 -07001214 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF3156cb02014-12-02 15:41:44 -07001215 QueueCommandBuffer(NULL, 0);
1216
1217}
1218
1219TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1220{
1221 // This tests reading gl_ClipDistance from FS
1222
1223 static const char *vertShaderText =
1224 "#version 330\n"
1225 "#extension GL_ARB_separate_shader_objects : enable\n"
1226 "#extension GL_ARB_shading_language_420pack : enable\n"
1227 "out gl_PerVertex {\n"
1228 " vec4 gl_Position;\n"
1229 " float gl_ClipDistance[1];\n"
1230 "};\n"
1231 "layout (location = 0) in vec4 pos;\n"
1232 "layout (location = 0) out vec4 outColor;\n"
1233 "layout (location = 1) out vec4 outColor2;\n"
1234 "void main() {\n"
1235 " gl_Position = pos;\n"
1236 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1237 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1238 " float dists[3];\n"
1239 " dists[0] = 0.0;\n"
1240 " dists[1] = 1.0;\n"
1241 " dists[2] = 1.0;\n"
1242 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1243 "}\n";
1244
1245
1246 static const char *fragShaderText =
1247 //"#version 140\n"
1248 "#version 330\n"
1249 "#extension GL_ARB_separate_shader_objects : enable\n"
1250 "#extension GL_ARB_shading_language_420pack : enable\n"
1251 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1252 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1253 "layout (location = 0) in vec4 color;\n"
1254 "layout (location = 1) in vec4 color2;\n"
1255 "void main() {\n"
1256 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1257 " float dist_squared = dot(pos, pos);\n"
1258 " gl_FragColor = (dist_squared < 400.0)\n"
1259 " ? color * gl_ClipDistance[0]\n"
1260 " : color2;\n"
1261 "}\n";
1262
1263 ASSERT_NO_FATAL_FAILURE(InitState());
1264 ASSERT_NO_FATAL_FAILURE(InitViewport());
1265
1266 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001267 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001268
1269 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1270 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1271
1272 XglPipelineObj pipelineobj(m_device);
1273 pipelineobj.AddShader(&vs);
1274 pipelineobj.AddShader(&ps);
1275
1276 XglDescriptorSetObj descriptorSet(m_device);
1277 descriptorSet.AttachMemoryView(&meshBuffer);
1278
1279 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1280 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1281 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1282 };
1283
1284 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1285 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1286 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1287 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1288 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1289 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1290 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1291 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1292 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1293
1294 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1295 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1296 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1297
Tony Barbour2bd96162014-12-03 15:46:29 -07001298 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF3156cb02014-12-02 15:41:44 -07001299 QueueCommandBuffer(NULL, 0);
1300
1301}
Tony Barboure2c58df2014-11-25 13:18:32 -07001302
GregF42226582014-12-02 17:19:34 -07001303TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1304{
1305 static const char *vertShaderText =
1306 "#version 140\n"
1307 "#extension GL_ARB_separate_shader_objects : enable\n"
1308 "#extension GL_ARB_shading_language_420pack : enable\n"
1309 "layout (location = 0) in vec4 pos;\n"
1310 "layout (location = 0) out vec4 outColor;\n"
1311 "layout (location = 1) out vec4 outColor2;\n"
1312 "void main() {\n"
1313 " gl_Position = pos;\n"
1314 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1315 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1316 "}\n";
1317
1318
1319 static const char *fragShaderText =
1320 //"#version 140\n"
1321 "#version 330\n"
1322 "#extension GL_ARB_separate_shader_objects : enable\n"
1323 "#extension GL_ARB_shading_language_420pack : enable\n"
1324 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1325 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1326 "layout (location = 0) in vec4 color;\n"
1327 "layout (location = 1) in vec4 color2;\n"
1328 "void main() {\n"
1329 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1330 " float dist_squared = dot(pos, pos);\n"
1331 " if (dist_squared < 100.0)\n"
1332 " discard;\n"
1333 " gl_FragColor = (dist_squared < 400.0)\n"
1334 " ? color\n"
1335 " : color2;\n"
1336 "}\n";
1337
1338 ASSERT_NO_FATAL_FAILURE(InitState());
1339 ASSERT_NO_FATAL_FAILURE(InitViewport());
1340
1341 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001342 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF42226582014-12-02 17:19:34 -07001343
1344 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1345 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1346
1347 XglPipelineObj pipelineobj(m_device);
1348 pipelineobj.AddShader(&vs);
1349 pipelineobj.AddShader(&ps);
1350
1351 XglDescriptorSetObj descriptorSet(m_device);
1352 descriptorSet.AttachMemoryView(&meshBuffer);
1353
1354 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1355 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1356 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1357 };
1358
1359 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1360 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1361 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1362 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1363 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1364 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1365 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1366 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1367 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1368
1369 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1370 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1371 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1372
Tony Barbour1c042032014-12-03 16:13:23 -07001373 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF42226582014-12-02 17:19:34 -07001374 QueueCommandBuffer(NULL, 0);
1375
1376}
1377
1378
Courtney Goeltzenleuchterd66e41e2014-10-27 13:06:08 -06001379TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001380{
1381 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001382 "#version 140\n"
1383 "#extension GL_ARB_separate_shader_objects : enable\n"
1384 "#extension GL_ARB_shading_language_420pack : enable\n"
1385 "\n"
1386 "layout(binding = 0) uniform buf {\n"
1387 " mat4 MVP;\n"
1388 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001389 "void main() {\n"
1390 " vec2 vertices[3];"
1391 " vertices[0] = vec2(-0.5, -0.5);\n"
1392 " vertices[1] = vec2( 0.5, -0.5);\n"
1393 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001394 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001395 "}\n";
1396
1397 static const char *fragShaderText =
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001398 "#version 130\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001399 "void main() {\n"
Cody Northropbb38ad32014-10-10 15:45:00 -06001400 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001401 "}\n";
1402
Tony Barboure2c58df2014-11-25 13:18:32 -07001403 ASSERT_NO_FATAL_FAILURE(InitState());
1404 ASSERT_NO_FATAL_FAILURE(InitViewport());
1405
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001406 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001407 glm::mat4 Projection = glm::mat4(1.0f);
1408 glm::mat4 View = glm::mat4(1.0f);
1409 glm::mat4 Model = glm::mat4(1.0f);
1410 glm::mat4 MVP = Projection * View * Model;
1411 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1412
Tony Barboure2c58df2014-11-25 13:18:32 -07001413 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1414 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1415 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001416
Tony Barboure2c58df2014-11-25 13:18:32 -07001417 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1418
1419 XglPipelineObj pipelineobj(m_device);
1420 pipelineobj.AddShader(&vs);
1421 pipelineobj.AddShader(&ps);
1422
1423 // Create descriptor set and attach the constant buffer to it
1424 XglDescriptorSetObj descriptorSet(m_device);
1425 descriptorSet.AttachMemoryView(&MVPBuffer);
1426
1427 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1428
Tony Barbour2bd96162014-12-03 15:46:29 -07001429 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001430 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1431
Tony Barbour1c042032014-12-03 16:13:23 -07001432 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001433}
1434
Tony Barboure2c58df2014-11-25 13:18:32 -07001435TEST_F(XglRenderTest, MixTriangle)
1436{
1437 // This tests location applied to varyings. Notice that we have switched foo
1438 // and bar in the FS. The triangle should be blended with red, green and blue
1439 // corners.
1440 static const char *vertShaderText =
1441 "#version 140\n"
1442 "#extension GL_ARB_separate_shader_objects : enable\n"
1443 "#extension GL_ARB_shading_language_420pack : enable\n"
1444 "layout (location=0) out vec4 bar;\n"
1445 "layout (location=1) out vec4 foo;\n"
1446 "layout (location=2) out float scale;\n"
1447 "vec2 vertices[3];\n"
1448 "void main() {\n"
1449 " vertices[0] = vec2(-1.0, -1.0);\n"
1450 " vertices[1] = vec2( 1.0, -1.0);\n"
1451 " vertices[2] = vec2( 0.0, 1.0);\n"
1452 "vec4 colors[3];\n"
1453 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1454 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1455 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1456 " foo = colors[gl_VertexID % 3];\n"
1457 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1458 " scale = 1.0;\n"
1459 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1460 "}\n";
1461
1462 static const char *fragShaderText =
1463 "#version 140\n"
1464 "#extension GL_ARB_separate_shader_objects : enable\n"
1465 "#extension GL_ARB_shading_language_420pack : enable\n"
1466 "layout (location = 1) in vec4 bar;\n"
1467 "layout (location = 0) in vec4 foo;\n"
1468 "layout (location = 2) in float scale;\n"
1469 "void main() {\n"
1470 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1471 "}\n";
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474 ASSERT_NO_FATAL_FAILURE(InitViewport());
1475
1476 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1477 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1478
1479 XglPipelineObj pipelineobj(m_device);
1480 pipelineobj.AddShader(&vs);
1481 pipelineobj.AddShader(&ps);
1482
1483 XglDescriptorSetObj descriptorSet(m_device);
1484
Tony Barbour2bd96162014-12-03 15:46:29 -07001485 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001486 QueueCommandBuffer(NULL, 0);
1487}
1488
1489TEST_F(XglRenderTest, TriVertFetchAndVertID)
1490{
1491 // This tests that attributes work in the presence of gl_VertexID
1492
1493 static const char *vertShaderText =
1494 "#version 140\n"
1495 "#extension GL_ARB_separate_shader_objects : enable\n"
1496 "#extension GL_ARB_shading_language_420pack : enable\n"
1497 //XYZ1( -1, -1, -1 )
1498 "layout (location = 0) in vec4 pos;\n"
1499 //XYZ1( 0.f, 0.f, 0.f )
1500 "layout (location = 1) in vec4 inColor;\n"
1501 "layout (location = 0) out vec4 outColor;\n"
1502 "void main() {\n"
1503 " outColor = inColor;\n"
1504 " vec4 vertices[3];"
1505 " vertices[gl_VertexID % 3] = pos;\n"
1506 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1507 "}\n";
1508
1509
1510 static const char *fragShaderText =
1511 "#version 140\n"
1512 "#extension GL_ARB_separate_shader_objects : enable\n"
1513 "#extension GL_ARB_shading_language_420pack : enable\n"
1514 "layout (location = 0) in vec4 color;\n"
1515 "void main() {\n"
1516 " gl_FragColor = color;\n"
1517 "}\n";
1518
1519 ASSERT_NO_FATAL_FAILURE(InitState());
1520 ASSERT_NO_FATAL_FAILURE(InitViewport());
1521
1522 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001523 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07001524
1525 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1526 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1527
1528 XglPipelineObj pipelineobj(m_device);
1529 pipelineobj.AddShader(&vs);
1530 pipelineobj.AddShader(&ps);
1531
1532 XglDescriptorSetObj descriptorSet(m_device);
1533 descriptorSet.AttachMemoryView(&meshBuffer);
1534
1535 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1536 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1537 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1538 };
1539
1540 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1541 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1542 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1543 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1544 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1545 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1546 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1547 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1548 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1549
1550 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1551 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1552 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1553
Tony Barbour2bd96162014-12-03 15:46:29 -07001554 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001555 QueueCommandBuffer(NULL, 0);
1556}
1557
1558TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1559{
1560 // This tests that attributes work in the presence of gl_VertexID
1561 // and a dead attribute in position 0. Draws a triangle with yellow,
1562 // red and green corners, starting at top and going clockwise.
1563
1564 static const char *vertShaderText =
1565 "#version 140\n"
1566 "#extension GL_ARB_separate_shader_objects : enable\n"
1567 "#extension GL_ARB_shading_language_420pack : enable\n"
1568 //XYZ1( -1, -1, -1 )
1569 "layout (location = 0) in vec4 pos;\n"
1570 //XYZ1( 0.f, 0.f, 0.f )
1571 "layout (location = 1) in vec4 inColor;\n"
1572 "layout (location = 0) out vec4 outColor;\n"
1573 "void main() {\n"
1574 " outColor = inColor;\n"
1575 " vec2 vertices[3];"
1576 " vertices[0] = vec2(-1.0, -1.0);\n"
1577 " vertices[1] = vec2( 1.0, -1.0);\n"
1578 " vertices[2] = vec2( 0.0, 1.0);\n"
1579 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1580 "}\n";
1581
1582
1583 static const char *fragShaderText =
1584 "#version 140\n"
1585 "#extension GL_ARB_separate_shader_objects : enable\n"
1586 "#extension GL_ARB_shading_language_420pack : enable\n"
1587 "layout (location = 0) in vec4 color;\n"
1588 "void main() {\n"
1589 " gl_FragColor = color;\n"
1590 "}\n";
1591
1592 ASSERT_NO_FATAL_FAILURE(InitState());
1593 ASSERT_NO_FATAL_FAILURE(InitViewport());
1594
1595 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001596 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07001597
1598 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1599 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1600
1601 XglPipelineObj pipelineobj(m_device);
1602 pipelineobj.AddShader(&vs);
1603 pipelineobj.AddShader(&ps);
1604
1605 XglDescriptorSetObj descriptorSet(m_device);
1606 descriptorSet.AttachMemoryView(&meshBuffer);
1607
1608 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1609 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1610 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1611 };
1612
1613 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1614 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1615 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1616 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1617 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1618 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1619 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1620 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1621 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1622
1623 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1624 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1625 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1626
Tony Barbour1c042032014-12-03 16:13:23 -07001627 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001628 QueueCommandBuffer(NULL, 0);
1629
1630}
1631
1632TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001633{
1634 static const char *vertShaderText =
1635 "#version 140\n"
1636 "layout (std140) uniform bufferVals {\n"
1637 " mat4 mvp;\n"
1638 "} myBufferVals;\n"
1639 "in vec4 pos;\n"
1640 "in vec4 inColor;\n"
1641 "out vec4 outColor;\n"
1642 "void main() {\n"
1643 " outColor = inColor;\n"
1644 " gl_Position = myBufferVals.mvp * pos;\n"
1645 "}\n";
1646
1647 static const char *fragShaderText =
1648 "#version 130\n"
1649 "in vec4 color;\n"
1650 "void main() {\n"
1651 " gl_FragColor = color;\n"
1652 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001653 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001654
Tony Barboure2c58df2014-11-25 13:18:32 -07001655 glm::mat4 View = glm::lookAt(
1656 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1657 glm::vec3(0,0,0), // and looks at the origin
1658 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1659 );
1660
1661 glm::mat4 Model = glm::mat4(1.0f);
1662
1663 glm::mat4 MVP = Projection * View * Model;
1664
1665 ASSERT_NO_FATAL_FAILURE(InitState());
1666 ASSERT_NO_FATAL_FAILURE(InitViewport());
1667 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1668
1669 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1670 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1671
1672 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1673
1674 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1675 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1676 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1677
1678 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1679
1680 XglPipelineObj pipelineobj(m_device);
1681 pipelineobj.AddShader(&vs);
1682 pipelineobj.AddShader(&ps);
1683
1684 XglDescriptorSetObj descriptorSet(m_device);
1685 descriptorSet.AttachMemoryView(&MVPBuffer);
1686
1687 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1688 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1689
1690 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1691 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1692 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1693 };
1694
1695 // this is the current description of g_vbData
1696 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1697 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1698 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1699 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1700 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1701 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1702 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1703 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1704 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1705
1706 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1707 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1708 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1709
Tony Barbour2bd96162014-12-03 15:46:29 -07001710 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barboure2c58df2014-11-25 13:18:32 -07001711
1712 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1713
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001714}
1715
Tony Barboure2c58df2014-11-25 13:18:32 -07001716TEST_F(XglRenderTest, VSTexture)
1717{
1718 // The expected result from this test is a green and red triangle;
1719 // one red vertex on the left, two green vertices on the right.
1720 static const char *vertShaderText =
1721 "#version 130\n"
1722 "out vec4 texColor;\n"
1723 "uniform sampler2D surface;\n"
1724 "void main() {\n"
1725 " vec2 vertices[3];"
1726 " vertices[0] = vec2(-0.5, -0.5);\n"
1727 " vertices[1] = vec2( 0.5, -0.5);\n"
1728 " vertices[2] = vec2( 0.5, 0.5);\n"
1729 " vec2 positions[3];"
1730 " positions[0] = vec2( 0.0, 0.0);\n"
1731 " positions[1] = vec2( 0.25, 0.1);\n"
1732 " positions[2] = vec2( 0.1, 0.25);\n"
1733 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1734 " texColor = textureLod(surface, samplePos, 0.0);\n"
1735 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1736 "}\n";
1737
1738 static const char *fragShaderText =
1739 "#version 130\n"
1740 "in vec4 texColor;\n"
1741 "void main() {\n"
1742 " gl_FragColor = texColor;\n"
1743 "}\n";
1744
1745 ASSERT_NO_FATAL_FAILURE(InitState());
1746 ASSERT_NO_FATAL_FAILURE(InitViewport());
1747
1748 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1749 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1750 XglSamplerObj sampler(m_device);
1751 XglTextureObj texture(m_device);
1752
Cody Northropbd531de2014-12-09 19:08:54 -07001753 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001754 vs.BindShaderEntitySlotToSampler(0, &sampler);
1755
1756 XglPipelineObj pipelineobj(m_device);
1757 pipelineobj.AddShader(&vs);
1758 pipelineobj.AddShader(&ps);
1759
1760 XglDescriptorSetObj descriptorSet(m_device);
1761 descriptorSet.AttachImageView(&texture);
1762 descriptorSet.AttachSampler(&sampler);
1763
1764 m_memoryRefManager.AddMemoryRef(&texture);
1765
Tony Barbour2bd96162014-12-03 15:46:29 -07001766 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001767 QueueCommandBuffer(NULL, 0);
1768
1769}
1770TEST_F(XglRenderTest, TexturedTriangle)
1771{
1772 // The expected result from this test is a red and green checkered triangle
1773 static const char *vertShaderText =
1774 "#version 140\n"
1775 "#extension GL_ARB_separate_shader_objects : enable\n"
1776 "#extension GL_ARB_shading_language_420pack : enable\n"
1777 "layout (location = 0) out vec2 samplePos;\n"
1778 "void main() {\n"
1779 " vec2 vertices[3];"
1780 " vertices[0] = vec2(-0.5, -0.5);\n"
1781 " vertices[1] = vec2( 0.5, -0.5);\n"
1782 " vertices[2] = vec2( 0.5, 0.5);\n"
1783 " vec2 positions[3];"
1784 " positions[0] = vec2( 0.0, 0.0);\n"
1785 " positions[1] = vec2( 1.0, 0.0);\n"
1786 " positions[2] = vec2( 1.0, 1.0);\n"
1787 " samplePos = positions[gl_VertexID % 3];\n"
1788 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1789 "}\n";
1790
1791 static const char *fragShaderText =
1792 "#version 140\n"
1793 "#extension GL_ARB_separate_shader_objects : enable\n"
1794 "#extension GL_ARB_shading_language_420pack : enable\n"
1795 "layout (location = 0) in vec2 samplePos;\n"
1796 "layout (binding = 0) uniform sampler2D surface;\n"
1797 "layout (location=0) out vec4 outColor;\n"
1798 "void main() {\n"
1799 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1800 " outColor = texColor;\n"
1801 "}\n";
1802
1803 ASSERT_NO_FATAL_FAILURE(InitState());
1804 ASSERT_NO_FATAL_FAILURE(InitViewport());
1805
1806 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1807 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1808 XglSamplerObj sampler(m_device);
1809 XglTextureObj texture(m_device);
1810
Cody Northropbd531de2014-12-09 19:08:54 -07001811 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001812 ps.BindShaderEntitySlotToSampler(0, &sampler);
1813
1814 XglPipelineObj pipelineobj(m_device);
1815 pipelineobj.AddShader(&vs);
1816 pipelineobj.AddShader(&ps);
1817
1818 XglDescriptorSetObj descriptorSet(m_device);
1819 descriptorSet.AttachImageView(&texture);
1820 descriptorSet.AttachSampler(&sampler);
1821
1822 m_memoryRefManager.AddMemoryRef(&texture);
1823
Tony Barbour2bd96162014-12-03 15:46:29 -07001824 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001825 QueueCommandBuffer(NULL, 0);
1826}
1827TEST_F(XglRenderTest, TexturedTriangleClip)
1828{
1829 // The expected result from this test is a red and green checkered triangle
1830 static const char *vertShaderText =
1831 "#version 330\n"
1832 "#extension GL_ARB_separate_shader_objects : enable\n"
1833 "#extension GL_ARB_shading_language_420pack : enable\n"
1834 "layout (location = 0) out vec2 samplePos;\n"
1835 "out gl_PerVertex {\n"
1836 " vec4 gl_Position;\n"
1837 " float gl_ClipDistance[1];\n"
1838 "};\n"
1839 "void main() {\n"
1840 " vec2 vertices[3];"
1841 " vertices[0] = vec2(-0.5, -0.5);\n"
1842 " vertices[1] = vec2( 0.5, -0.5);\n"
1843 " vertices[2] = vec2( 0.5, 0.5);\n"
1844 " vec2 positions[3];"
1845 " positions[0] = vec2( 0.0, 0.0);\n"
1846 " positions[1] = vec2( 1.0, 0.0);\n"
1847 " positions[2] = vec2( 1.0, 1.0);\n"
1848 " float dists[3];\n"
1849 " dists[0] = 1.0;\n"
1850 " dists[1] = 1.0;\n"
1851 " dists[2] = -1.0;\n"
1852 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1853 " samplePos = positions[gl_VertexID % 3];\n"
1854 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1855 "}\n";
1856
1857 static const char *fragShaderText =
1858 "#version 140\n"
1859 "#extension GL_ARB_separate_shader_objects : enable\n"
1860 "#extension GL_ARB_shading_language_420pack : enable\n"
1861 "layout (location = 0) in vec2 samplePos;\n"
1862 "layout (binding = 0) uniform sampler2D surface;\n"
1863 "layout (location=0) out vec4 outColor;\n"
1864 "void main() {\n"
1865 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1866 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1867 " outColor = texColor;\n"
1868 "}\n";
1869
1870
1871 ASSERT_NO_FATAL_FAILURE(InitState());
1872 ASSERT_NO_FATAL_FAILURE(InitViewport());
1873
1874 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1875 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1876 XglSamplerObj sampler(m_device);
1877 XglTextureObj texture(m_device);
1878
Cody Northropbd531de2014-12-09 19:08:54 -07001879 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001880 ps.BindShaderEntitySlotToSampler(0, &sampler);
1881
1882 XglPipelineObj pipelineobj(m_device);
1883 pipelineobj.AddShader(&vs);
1884 pipelineobj.AddShader(&ps);
1885
1886 XglDescriptorSetObj descriptorSet(m_device);
1887 descriptorSet.AttachImageView(&texture);
1888 descriptorSet.AttachSampler(&sampler);
1889
1890 m_memoryRefManager.AddMemoryRef(&texture);
1891
Tony Barbour2bd96162014-12-03 15:46:29 -07001892 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001893 QueueCommandBuffer(NULL, 0);
1894}
1895TEST_F(XglRenderTest, FSTriangle)
1896{
1897 // The expected result from this test is a red and green checkered triangle
1898 static const char *vertShaderText =
1899 "#version 140\n"
1900 "#extension GL_ARB_separate_shader_objects : enable\n"
1901 "#extension GL_ARB_shading_language_420pack : enable\n"
1902 "layout (location = 0) out vec2 samplePos;\n"
1903 "void main() {\n"
1904 " vec2 vertices[3];"
1905 " vertices[0] = vec2(-0.5, -0.5);\n"
1906 " vertices[1] = vec2( 0.5, -0.5);\n"
1907 " vertices[2] = vec2( 0.5, 0.5);\n"
1908 " vec2 positions[3];"
1909 " positions[0] = vec2( 0.0, 0.0);\n"
1910 " positions[1] = vec2( 1.0, 0.0);\n"
1911 " positions[2] = vec2( 1.0, 1.0);\n"
1912 " samplePos = positions[gl_VertexID % 3];\n"
1913 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1914 "}\n";
1915
1916 static const char *fragShaderText =
1917 "#version 140\n"
1918 "#extension GL_ARB_separate_shader_objects : enable\n"
1919 "#extension GL_ARB_shading_language_420pack : enable\n"
1920 "layout (location = 0) in vec2 samplePos;\n"
1921 "layout (binding = 0) uniform sampler2D surface;\n"
1922 "layout (location=0) out vec4 outColor;\n"
1923 "void main() {\n"
1924 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1925 " outColor = texColor;\n"
1926 "}\n";
1927
1928 ASSERT_NO_FATAL_FAILURE(InitState());
1929 ASSERT_NO_FATAL_FAILURE(InitViewport());
1930
1931 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1932 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1933 XglSamplerObj sampler(m_device);
1934 XglTextureObj texture(m_device);
1935
Cody Northropbd531de2014-12-09 19:08:54 -07001936 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001937 ps.BindShaderEntitySlotToSampler(0, &sampler);
1938
1939 XglPipelineObj pipelineobj(m_device);
1940 pipelineobj.AddShader(&vs);
1941 pipelineobj.AddShader(&ps);
1942
1943 XglDescriptorSetObj descriptorSet(m_device);
1944 descriptorSet.AttachImageView(&texture);
1945 descriptorSet.AttachSampler(&sampler);
1946
1947 m_memoryRefManager.AddMemoryRef(&texture);
1948
Tony Barbour2bd96162014-12-03 15:46:29 -07001949 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001950 QueueCommandBuffer(NULL, 0);
1951}
1952TEST_F(XglRenderTest, SamplerBindingsTriangle)
1953{
1954 // This test sets bindings on the samplers
1955 // For now we are asserting that sampler and texture pairs
1956 // march in lock step, and are set via GLSL binding. This can
1957 // and will probably change.
1958 // The sampler bindings should match the sampler and texture slot
1959 // number set up by the application.
1960 // This test will result in a blue triangle
1961 static const char *vertShaderText =
1962 "#version 140\n"
1963 "#extension GL_ARB_separate_shader_objects : enable\n"
1964 "#extension GL_ARB_shading_language_420pack : enable\n"
1965 "layout (location = 0) out vec4 samplePos;\n"
1966 "void main() {\n"
1967 " vec2 vertices[3];"
1968 " vertices[0] = vec2(-0.5, -0.5);\n"
1969 " vertices[1] = vec2( 0.5, -0.5);\n"
1970 " vertices[2] = vec2( 0.5, 0.5);\n"
1971 " vec2 positions[3];"
1972 " positions[0] = vec2( 0.0, 0.0);\n"
1973 " positions[1] = vec2( 1.0, 0.0);\n"
1974 " positions[2] = vec2( 1.0, 1.0);\n"
1975 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
1976 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1977 "}\n";
1978
1979 static const char *fragShaderText =
1980 "#version 140\n"
1981 "#extension GL_ARB_separate_shader_objects : enable\n"
1982 "#extension GL_ARB_shading_language_420pack : enable\n"
1983 "layout (location = 0) in vec4 samplePos;\n"
1984 "layout (binding = 0) uniform sampler2D surface0;\n"
1985 "layout (binding = 1) uniform sampler2D surface1;\n"
1986 "layout (binding = 12) uniform sampler2D surface2;\n"
1987 "void main() {\n"
1988 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
1989 "}\n";
1990
1991 ASSERT_NO_FATAL_FAILURE(InitState());
1992 ASSERT_NO_FATAL_FAILURE(InitViewport());
1993
1994 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1995 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1996
1997 XglSamplerObj sampler1(m_device);
1998 XglSamplerObj sampler2(m_device);
1999 XglSamplerObj sampler3(m_device);
2000
2001 XglTextureObj texture1(m_device); // Red
2002 texture1.ChangeColors(0xffff0000,0xffff0000);
2003 XglTextureObj texture2(m_device); // Green
2004 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2005 XglTextureObj texture3(m_device); // Blue
2006 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2007
Cody Northropbd531de2014-12-09 19:08:54 -07002008 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002009 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2010
Cody Northropbd531de2014-12-09 19:08:54 -07002011 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Tony Barboure2c58df2014-11-25 13:18:32 -07002012 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2013
Cody Northropbd531de2014-12-09 19:08:54 -07002014 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002015 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2016
2017 XglPipelineObj pipelineobj(m_device);
2018 pipelineobj.AddShader(&vs);
2019 pipelineobj.AddShader(&ps);
2020
2021 XglDescriptorSetObj descriptorSet(m_device);
2022 descriptorSet.AttachImageView(&texture1);
2023 descriptorSet.AttachSampler(&sampler1);
2024 descriptorSet.AttachImageView(&texture2);
2025 descriptorSet.AttachSampler(&sampler2);
2026 descriptorSet.AttachImageView(&texture3);
2027 descriptorSet.AttachSampler(&sampler3);
2028
2029 m_memoryRefManager.AddMemoryRef(&texture1);
2030 m_memoryRefManager.AddMemoryRef(&texture2);
2031 m_memoryRefManager.AddMemoryRef(&texture3);
2032
Tony Barbour2bd96162014-12-03 15:46:29 -07002033 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002034 QueueCommandBuffer(NULL, 0);
2035
2036}
2037
2038TEST_F(XglRenderTest, TriangleVSUniformBlock)
2039{
2040 // The expected result from this test is a blue triangle
2041
2042 static const char *vertShaderText =
2043 "#version 140\n"
2044 "#extension GL_ARB_separate_shader_objects : enable\n"
2045 "#extension GL_ARB_shading_language_420pack : enable\n"
2046 "layout (location = 0) out vec4 outColor;\n"
2047 "layout (std140, binding = 0) uniform bufferVals {\n"
2048 " vec4 red;\n"
2049 " vec4 green;\n"
2050 " vec4 blue;\n"
2051 " vec4 white;\n"
2052 "} myBufferVals;\n"
2053 "void main() {\n"
2054 " vec2 vertices[3];"
2055 " vertices[0] = vec2(-0.5, -0.5);\n"
2056 " vertices[1] = vec2( 0.5, -0.5);\n"
2057 " vertices[2] = vec2( 0.5, 0.5);\n"
2058 " outColor = myBufferVals.blue;\n"
2059 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2060 "}\n";
2061
2062 static const char *fragShaderText =
2063 "#version 140\n"
2064 "#extension GL_ARB_separate_shader_objects : enable\n"
2065 "#extension GL_ARB_shading_language_420pack : enable\n"
2066 "layout (location = 0) in vec4 inColor;\n"
2067 "void main() {\n"
2068 " gl_FragColor = inColor;\n"
2069 "}\n";
2070
2071 ASSERT_NO_FATAL_FAILURE(InitState());
2072 ASSERT_NO_FATAL_FAILURE(InitViewport());
2073
2074 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2075 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2076
2077 // Let's populate our buffer with the following:
2078 // vec4 red;
2079 // vec4 green;
2080 // vec4 blue;
2081 // vec4 white;
2082 const int valCount = 4 * 4;
2083 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2084 0.0, 1.0, 0.0, 1.0,
2085 0.0, 0.0, 1.0, 1.0,
2086 1.0, 1.0, 1.0, 1.0 };
2087
2088 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
2089 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
2090
2091 XglPipelineObj pipelineobj(m_device);
2092 pipelineobj.AddShader(&vs);
2093 pipelineobj.AddShader(&ps);
2094
2095 XglDescriptorSetObj descriptorSet(m_device);
2096 descriptorSet.AttachMemoryView(&colorBuffer);
2097
Tony Barbour2bd96162014-12-03 15:46:29 -07002098 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002099 QueueCommandBuffer(NULL, 0);
2100
2101}
2102
2103TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2104{
2105 // This test allows the shader to select which buffer it is
2106 // pulling from using layout binding qualifier.
2107 // There are corresponding changes in the compiler stack that
2108 // will select the buffer using binding directly.
2109 // The binding number should match the slot number set up by
2110 // the application.
2111 // The expected result from this test is a purple triangle
2112
2113 static const char *vertShaderText =
2114 "#version 140\n"
2115 "#extension GL_ARB_separate_shader_objects : enable\n"
2116 "#extension GL_ARB_shading_language_420pack : enable\n"
2117 "void main() {\n"
2118 " vec2 vertices[3];"
2119 " vertices[0] = vec2(-0.5, -0.5);\n"
2120 " vertices[1] = vec2( 0.5, -0.5);\n"
2121 " vertices[2] = vec2( 0.5, 0.5);\n"
2122 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2123 "}\n";
2124
2125 static const char *fragShaderText =
2126 "#version 140\n"
2127 "#extension GL_ARB_separate_shader_objects : enable\n"
2128 "#extension GL_ARB_shading_language_420pack : enable\n"
2129 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2130 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2131 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2132 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2133 "void main() {\n"
2134 " gl_FragColor = myBlueVal.color;\n"
2135 " gl_FragColor += myRedVal.color;\n"
2136 "}\n";
2137
2138 ASSERT_NO_FATAL_FAILURE(InitState());
2139 ASSERT_NO_FATAL_FAILURE(InitViewport());
2140
2141 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2142 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2143
2144 // We're going to create a number of uniform buffers, and then allow
2145 // the shader to select which it wants to read from with a binding
2146
2147 // Let's populate the buffers with a single color each:
2148 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2149 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2150 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2151 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2152
2153 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2154 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2155 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2156 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2157
2158 const int redCount = sizeof(redVals) / sizeof(float);
2159 const int greenCount = sizeof(greenVals) / sizeof(float);
2160 const int blueCount = sizeof(blueVals) / sizeof(float);
2161 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2162
2163 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2164 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2165
2166 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2167 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2168
2169 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2170 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2171
2172 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2173 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2174
2175 XglPipelineObj pipelineobj(m_device);
2176 pipelineobj.AddShader(&vs);
2177 pipelineobj.AddShader(&ps);
2178
2179 XglDescriptorSetObj descriptorSet(m_device);
2180 descriptorSet.AttachMemoryView(&redBuffer);
2181 descriptorSet.AttachMemoryView(&greenBuffer);
2182 descriptorSet.AttachMemoryView(&blueBuffer);
2183 descriptorSet.AttachMemoryView(&whiteBuffer);
2184
Tony Barbour2bd96162014-12-03 15:46:29 -07002185 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002186 QueueCommandBuffer(NULL, 0);
2187
2188}
2189
2190TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2191{
2192 // This test is the same as TriangleFSUniformBlockBinding, but
2193 // it does not provide an instance name.
2194 // The expected result from this test is a purple triangle
2195
2196 static const char *vertShaderText =
2197 "#version 140\n"
2198 "#extension GL_ARB_separate_shader_objects : enable\n"
2199 "#extension GL_ARB_shading_language_420pack : enable\n"
2200 "void main() {\n"
2201 " vec2 vertices[3];"
2202 " vertices[0] = vec2(-0.5, -0.5);\n"
2203 " vertices[1] = vec2( 0.5, -0.5);\n"
2204 " vertices[2] = vec2( 0.5, 0.5);\n"
2205 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2206 "}\n";
2207
2208 static const char *fragShaderText =
2209 "#version 430\n"
2210 "#extension GL_ARB_separate_shader_objects : enable\n"
2211 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002212 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2213 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2214 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2215 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002216 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002217 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002218 " outColor = blue;\n"
2219 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002220 "}\n";
2221 ASSERT_NO_FATAL_FAILURE(InitState());
2222 ASSERT_NO_FATAL_FAILURE(InitViewport());
2223
2224 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2225 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2226
2227 // We're going to create a number of uniform buffers, and then allow
2228 // the shader to select which it wants to read from with a binding
2229
2230 // Let's populate the buffers with a single color each:
2231 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2232 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2233 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2234 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2235
2236 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2237 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2238 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2239 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2240
2241 const int redCount = sizeof(redVals) / sizeof(float);
2242 const int greenCount = sizeof(greenVals) / sizeof(float);
2243 const int blueCount = sizeof(blueVals) / sizeof(float);
2244 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2245
2246 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2247 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2248
2249 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2250 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2251
2252 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2253 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2254
2255 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002256 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002257
2258 XglPipelineObj pipelineobj(m_device);
2259 pipelineobj.AddShader(&vs);
2260 pipelineobj.AddShader(&ps);
2261
2262 XglDescriptorSetObj descriptorSet(m_device);
2263 descriptorSet.AttachMemoryView(&redBuffer);
2264 descriptorSet.AttachMemoryView(&greenBuffer);
2265 descriptorSet.AttachMemoryView(&blueBuffer);
2266 descriptorSet.AttachMemoryView(&whiteBuffer);
2267
Tony Barbour2bd96162014-12-03 15:46:29 -07002268 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002269 QueueCommandBuffer(NULL, 0);
2270
2271}
2272
2273TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2274{
2275 static const char *vertShaderText =
2276 "#version 140\n"
2277 "#extension GL_ARB_separate_shader_objects : enable\n"
2278 "#extension GL_ARB_shading_language_420pack : enable\n"
2279 "layout (std140, binding=0) uniform bufferVals {\n"
2280 " mat4 mvp;\n"
2281 "} myBufferVals;\n"
2282 "layout (location=0) in vec4 pos;\n"
2283 "layout (location=0) out vec2 UV;\n"
2284 "void main() {\n"
2285 " vec2 positions[3];"
2286 " positions[0] = vec2( 0.0, 0.0);\n"
2287 " positions[1] = vec2( 0.25, 0.1);\n"
2288 " positions[2] = vec2( 0.1, 0.25);\n"
2289 " UV = positions[gl_VertexID % 3];\n"
2290 " gl_Position = myBufferVals.mvp * pos;\n"
2291 "}\n";
2292
2293 static const char *fragShaderText =
2294 "#version 140\n"
2295 "#extension GL_ARB_separate_shader_objects : enable\n"
2296 "#extension GL_ARB_shading_language_420pack : enable\n"
2297 "layout (binding=0) uniform sampler2D surface;\n"
2298 "layout (location=0) out vec4 outColor;\n"
2299 "layout (location=0) in vec2 UV;\n"
2300 "void main() {\n"
2301 " outColor= textureLod(surface, UV, 0.0);\n"
2302 "}\n";
2303 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2304
2305 glm::mat4 View = glm::lookAt(
2306 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2307 glm::vec3(0,0,0), // and looks at the origin
2308 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2309 );
2310
2311 glm::mat4 Model = glm::mat4(1.0f);
2312
2313 glm::mat4 MVP = Projection * View * Model;
2314
2315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitViewport());
2318 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2319
2320 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2321 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Tony Barbour099a9eb2014-12-10 17:40:15 -07002322 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07002323
2324
2325 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2326
2327 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2328 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2329 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2330 XglSamplerObj sampler(m_device);
2331 XglTextureObj texture(m_device);
2332
2333 // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2334 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002335 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002336 ps.BindShaderEntitySlotToSampler(0, &sampler);
2337
2338 XglPipelineObj pipelineobj(m_device);
2339 pipelineobj.AddShader(&vs);
2340 pipelineobj.AddShader(&ps);
2341
2342 XglDescriptorSetObj descriptorSet(m_device);
2343
2344 descriptorSet.AttachMemoryView(&mvpBuffer);
2345 descriptorSet.AttachImageView(&texture);
2346 descriptorSet.AttachSampler(&sampler);
2347
2348 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2349 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2350 m_memoryRefManager.AddMemoryRef(&texture);
2351
2352 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2353 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2354 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2355 };
2356
2357 // this is the current description of g_vbData
2358 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2359 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2360 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2361 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2362 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2363 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2364 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2365 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2366 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2367
2368 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2369 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2370 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2371
Tony Barbour2bd96162014-12-03 15:46:29 -07002372 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barboure2c58df2014-11-25 13:18:32 -07002373
2374 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2375
2376}
Cody Northropf1990a92014-12-09 11:17:01 -07002377
2378TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2379{
2380 // This test mixes binding slots of textures and buffers, ensuring
2381 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002382 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002383 // you can modify it to move the desired result around.
2384
2385 static const char *vertShaderText =
2386 "#version 140\n"
2387 "#extension GL_ARB_separate_shader_objects : enable\n"
2388 "#extension GL_ARB_shading_language_420pack : enable\n"
2389 "void main() {\n"
2390 " vec2 vertices[3];"
2391 " vertices[0] = vec2(-0.5, -0.5);\n"
2392 " vertices[1] = vec2( 0.5, -0.5);\n"
2393 " vertices[2] = vec2( 0.5, 0.5);\n"
2394 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2395 "}\n";
2396
2397 static const char *fragShaderText =
2398 "#version 430\n"
2399 "#extension GL_ARB_separate_shader_objects : enable\n"
2400 "#extension GL_ARB_shading_language_420pack : enable\n"
2401 "layout (binding = 0) uniform sampler2D surface0;\n"
Courtney Goeltzenleuchterc97ceea2014-12-11 09:03:03 -07002402 "layout (binding = 9) uniform sampler2D surface1;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002403 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002404 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002405
Cody Northropb110b4f2014-12-09 13:59:39 -07002406
2407 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2408 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2409 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2410 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002411 "layout (location = 0) out vec4 outColor;\n"
2412 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002413 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002414 " outColor += white * vec4(0.00001);\n"
2415 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002416 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002417 "}\n";
2418 ASSERT_NO_FATAL_FAILURE(InitState());
2419 ASSERT_NO_FATAL_FAILURE(InitViewport());
2420
2421 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2422 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2423
Cody Northropf1990a92014-12-09 11:17:01 -07002424 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2425 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2426 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2427 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2428
2429 const int redCount = sizeof(redVals) / sizeof(float);
2430 const int greenCount = sizeof(greenVals) / sizeof(float);
2431 const int blueCount = sizeof(blueVals) / sizeof(float);
2432 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2433
2434 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002435 ps.BindShaderEntitySlotToMemory(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002436
2437 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002438 ps.BindShaderEntitySlotToMemory(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002439
2440 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002441 ps.BindShaderEntitySlotToMemory(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002442
2443 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002444 ps.BindShaderEntitySlotToMemory(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002445
2446 XglSamplerObj sampler0(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002447 XglTextureObj texture0(m_device); // Light Red
2448 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropbd531de2014-12-09 19:08:54 -07002449 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
Cody Northropf1990a92014-12-09 11:17:01 -07002450 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2451 XglSamplerObj sampler2(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002452 XglTextureObj texture2(m_device); // Light Blue
2453 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropbd531de2014-12-09 19:08:54 -07002454 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Cody Northropf1990a92014-12-09 11:17:01 -07002455 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2456 XglSamplerObj sampler4(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002457 XglTextureObj texture4(m_device); // Light Green
2458 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropbd531de2014-12-09 19:08:54 -07002459 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
Cody Northropf1990a92014-12-09 11:17:01 -07002460 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002461
2462 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2463 // TODO: Get back here ASAP and understand why.
2464 XglSamplerObj sampler7(m_device);
2465 XglTextureObj texture7(m_device); // Red and Blue
2466 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Courtney Goeltzenleuchterc97ceea2014-12-11 09:03:03 -07002467 ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2468 ps.BindShaderEntitySlotToSampler(9, &sampler7);
Cody Northropf1990a92014-12-09 11:17:01 -07002469
2470
2471 XglPipelineObj pipelineobj(m_device);
2472 pipelineobj.AddShader(&vs);
2473 pipelineobj.AddShader(&ps);
2474
2475 XglDescriptorSetObj descriptorSet(m_device);
2476 descriptorSet.AttachMemoryView(&redBuffer);
2477 descriptorSet.AttachMemoryView(&greenBuffer);
2478 descriptorSet.AttachMemoryView(&blueBuffer);
2479 descriptorSet.AttachMemoryView(&whiteBuffer);
2480 descriptorSet.AttachImageView(&texture0);
2481 descriptorSet.AttachSampler(&sampler0);
2482 descriptorSet.AttachImageView(&texture2);
2483 descriptorSet.AttachSampler(&sampler2);
2484 descriptorSet.AttachImageView(&texture4);
2485 descriptorSet.AttachSampler(&sampler4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002486 descriptorSet.AttachImageView(&texture7);
2487 descriptorSet.AttachSampler(&sampler7);
Cody Northropf1990a92014-12-09 11:17:01 -07002488
2489 m_memoryRefManager.AddMemoryRef(&texture0);
2490 m_memoryRefManager.AddMemoryRef(&texture2);
2491 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002492 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropf1990a92014-12-09 11:17:01 -07002493
2494
2495 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
2496 QueueCommandBuffer(NULL, 0);
2497
2498}
2499
Cody Northropbd531de2014-12-09 19:08:54 -07002500TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2501{
2502 // This test matches binding slots of textures and buffers, requiring
2503 // the driver to give them distinct number spaces.
2504 // The expected result from this test is a red triangle, although
2505 // you can modify it to move the desired result around.
2506
2507 static const char *vertShaderText =
2508 "#version 140\n"
2509 "#extension GL_ARB_separate_shader_objects : enable\n"
2510 "#extension GL_ARB_shading_language_420pack : enable\n"
2511 "void main() {\n"
2512 " vec2 vertices[3];"
2513 " vertices[0] = vec2(-0.5, -0.5);\n"
2514 " vertices[1] = vec2( 0.5, -0.5);\n"
2515 " vertices[2] = vec2( 0.5, 0.5);\n"
2516 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2517 "}\n";
2518
2519 static const char *fragShaderText =
2520 "#version 430\n"
2521 "#extension GL_ARB_separate_shader_objects : enable\n"
2522 "#extension GL_ARB_shading_language_420pack : enable\n"
2523 "layout (binding = 0) uniform sampler2D surface0;\n"
2524 "layout (binding = 1) uniform sampler2D surface1;\n"
2525 "layout (binding = 2) uniform sampler2D surface2;\n"
2526 "layout (binding = 3) uniform sampler2D surface3;\n"
2527 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2528 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2529 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2530 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2531 "layout (location = 0) out vec4 outColor;\n"
2532 "void main() {\n"
2533 " outColor = red;// * vec4(0.00001);\n"
2534 " outColor += white * vec4(0.00001);\n"
2535 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2536 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2537 "}\n";
2538 ASSERT_NO_FATAL_FAILURE(InitState());
2539 ASSERT_NO_FATAL_FAILURE(InitViewport());
2540
2541 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2542 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2543
2544 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2545 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2546 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2547 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2548
2549 const int redCount = sizeof(redVals) / sizeof(float);
2550 const int greenCount = sizeof(greenVals) / sizeof(float);
2551 const int blueCount = sizeof(blueVals) / sizeof(float);
2552 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2553
2554 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2555 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2556
2557 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2558 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2559
2560 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2561 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2562
2563 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2564 ps.BindShaderEntitySlotToMemory(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2565
2566 XglSamplerObj sampler0(m_device);
2567 XglTextureObj texture0(m_device); // Light Red
2568 texture0.ChangeColors(0xff800000,0xff800000);
2569 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
2570 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2571 XglSamplerObj sampler2(m_device);
2572 XglTextureObj texture2(m_device); // Light Blue
2573 texture2.ChangeColors(0xff000080,0xff000080);
2574 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
2575 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2576 XglSamplerObj sampler4(m_device);
2577 XglTextureObj texture4(m_device); // Light Green
2578 texture4.ChangeColors(0xff008000,0xff008000);
2579 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
2580 ps.BindShaderEntitySlotToSampler(2, &sampler4);
2581 XglSamplerObj sampler7(m_device);
2582 XglTextureObj texture7(m_device); // Red and Blue
2583 texture7.ChangeColors(0xffff00ff,0xffff00ff);
2584 ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2585 ps.BindShaderEntitySlotToSampler(3, &sampler7);
2586
2587
2588 XglPipelineObj pipelineobj(m_device);
2589 pipelineobj.AddShader(&vs);
2590 pipelineobj.AddShader(&ps);
2591
2592 XglDescriptorSetObj descriptorSet(m_device);
2593 descriptorSet.AttachMemoryView(&redBuffer);
2594 descriptorSet.AttachMemoryView(&greenBuffer);
2595 descriptorSet.AttachMemoryView(&blueBuffer);
2596 descriptorSet.AttachMemoryView(&whiteBuffer);
2597 descriptorSet.AttachImageView(&texture0);
2598 descriptorSet.AttachSampler(&sampler0);
2599 descriptorSet.AttachImageView(&texture2);
2600 descriptorSet.AttachSampler(&sampler2);
2601 descriptorSet.AttachImageView(&texture4);
2602 descriptorSet.AttachSampler(&sampler4);
2603 descriptorSet.AttachImageView(&texture7);
2604 descriptorSet.AttachSampler(&sampler7);
2605
2606 m_memoryRefManager.AddMemoryRef(&texture0);
2607 m_memoryRefManager.AddMemoryRef(&texture2);
2608 m_memoryRefManager.AddMemoryRef(&texture4);
2609 m_memoryRefManager.AddMemoryRef(&texture7);
2610
2611
2612 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
2613 QueueCommandBuffer(NULL, 0);
2614
2615}
2616
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06002617int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06002618 int result;
2619
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06002620 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06002621 XglTestFramework::InitArgs(&argc, argv);
2622
Chia-I Wu6f184292014-12-15 23:57:34 +08002623 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06002624
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06002625 result = RUN_ALL_TESTS();
2626
2627 XglTestFramework::Finish();
2628 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06002629}