blob: 6fded285dbbc56feb1c7fb3419781a2b36f68de5 [file] [log] [blame]
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Chia-I Wufe7c1de2014-08-28 11:56:29 +080075#include "icd-bil.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060076
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
83XGL_VOID XGLAPI myDbgFunc(
84 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
87 XGL_SIZE location,
88 XGL_INT msgCode,
89 const XGL_CHAR* pMsg,
90 XGL_VOID* pUserData)
91{
Tobin Ehlisca915872014-11-18 11:28:33 -070092 switch (msgType)
93 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700104}
105#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
116 XGL_FLOAT posX, posY, posZ, posW; // Position data
117 XGL_FLOAT r, g, b, a; // Color
118};
119
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600214public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600215
Tony Barboure2c58df2014-11-25 13:18:32 -0700216 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
217 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour664accc2015-01-09 12:55:14 -0700218 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
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 Barbour22e32a12015-01-08 17:08:28 -0700222 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -0700223 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
224
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600225 void InitDepthStencil();
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600226 void GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600227 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600228
Cody Northropee6586d2014-10-09 19:55:56 -0600229
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600230protected:
Cody Northrop7d2035d2014-10-06 15:42:00 -0600231 XGL_IMAGE m_texture;
232 XGL_IMAGE_VIEW m_textureView;
233 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
234 XGL_GPU_MEMORY m_textureMem;
235
236 XGL_SAMPLER m_sampler;
237
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600238 XGL_FORMAT m_depth_stencil_fmt;
239 XGL_IMAGE m_depthStencilImage;
240 XGL_GPU_MEMORY m_depthStencilMem;
241 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barboure2c58df2014-11-25 13:18:32 -0700242 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600243
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600244
245 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600246
247 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
248 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800249 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600250 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800251 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600252 this->app_info.engineVersion = 1;
253 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
254
Cody Northrop7d2035d2014-10-06 15:42:00 -0600255 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
256 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700257 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600258
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600259 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600260 }
261
262 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600263 // Clean up resources before we reset
264 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600265 }
266};
267
Tony Barbour22e32a12015-01-08 17:08:28 -0700268void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
269{
270 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
271 cmdBuffer->BindAttachments(&m_depthStencilBinding);
272 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
273 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
274 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
275 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
276 cmdBuffer->BindStateObject(XGL_STATE_BIND_MSAA, m_stateMsaa);
277 pipelineobj->CreateXGLPipeline(descriptorSet);
278 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
279 descriptorSet->CreateXGLDescriptorSet();
280 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
281}
Tony Barboure2c58df2014-11-25 13:18:32 -0700282
Tony Barbour2bd96162014-12-03 15:46:29 -0700283void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600284{
285 XGL_RESULT err = XGL_SUCCESS;
286
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600288 // Build command buffer
289 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
290 ASSERT_XGL_SUCCESS(err);
291
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600292 GenerateClearAndPrepareBufferCmds();
293 GenerateBindRenderTargetCmd();
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700294
Tony Barboure2c58df2014-11-25 13:18:32 -0700295 GenerateBindStateAndPipelineCmds();
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600296
Tony Barbour2bd96162014-12-03 15:46:29 -0700297 pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet);
Tony Barbour5420af02014-12-03 13:58:15 -0700298 descriptorSet->BindCommandBuffer(m_cmdBuffer);
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700299#ifdef DUMP_STATE_DOT
300 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
301 pDSDumpDot((char*)"triTest.dot");
302 DRAW_STATE_DUMP_PNG_FILE pDSDumpPng = (DRAW_STATE_DUMP_PNG_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpPngFile");
303 pDSDumpPng((char*)"triTest.png");
304#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700305 // render the triangle
306 xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 );
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600307
308 // finalize recording of the command buffer
309 err = xglEndCommandBuffer( m_cmdBuffer );
310 ASSERT_XGL_SUCCESS( err );
Tony Barboure2c58df2014-11-25 13:18:32 -0700311}
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600312
Tony Barboure2c58df2014-11-25 13:18:32 -0700313void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
314{
315 XGL_RESULT err = XGL_SUCCESS;
Chia-I Wuecebf752014-12-05 10:45:15 +0800316 XGL_UINT i;
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600317
318 // submit the command buffer to the universal queue
Tony Barboure2c58df2014-11-25 13:18:32 -0700319 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL );
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600320 ASSERT_XGL_SUCCESS( err );
321
Chia-I Wu113e9d92014-08-27 14:58:05 +0800322 err = xglQueueWaitIdle( m_device->m_queue );
323 ASSERT_XGL_SUCCESS( err );
324
Courtney Goeltzenleuchter464746c2014-08-26 18:16:41 -0600325 // Wait for work to finish before cleaning up.
326 xglDeviceWaitIdle(m_device->device());
327
Chia-I Wuecebf752014-12-05 10:45:15 +0800328 for (i = 0; i < m_renderTargetCount; i++)
329 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600330}
331
Tony Barboure2c58df2014-11-25 13:18:32 -0700332void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600333{
Cody Northropee6586d2014-10-09 19:55:56 -0600334 XGL_RESULT err;
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600335
Cody Northropee6586d2014-10-09 19:55:56 -0600336 ASSERT_NO_FATAL_FAILURE(InitState());
337 ASSERT_NO_FATAL_FAILURE(InitViewport());
338
Tony Barboure2c58df2014-11-25 13:18:32 -0700339 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
340 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Cody Northropee6586d2014-10-09 19:55:56 -0600341
Cody Northropee6586d2014-10-09 19:55:56 -0600342
Tony Barboure2c58df2014-11-25 13:18:32 -0700343 XglPipelineObj pipelineobj(m_device);
344 pipelineobj.AddShader(&vs);
345 pipelineobj.AddShader(&ps);
Cody Northropee6586d2014-10-09 19:55:56 -0600346
347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
348
Tony Barboure2c58df2014-11-25 13:18:32 -0700349 // Create descriptor set
350 XglDescriptorSetObj descriptorSet(m_device);
Cody Northropee6586d2014-10-09 19:55:56 -0600351
352 // Build command buffer
353 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
354 ASSERT_XGL_SUCCESS(err);
355
356 GenerateClearAndPrepareBufferCmds();
357 GenerateBindRenderTargetCmd();
Tony Barboure2c58df2014-11-25 13:18:32 -0700358 GenerateBindStateAndPipelineCmds();
Cody Northropee6586d2014-10-09 19:55:56 -0600359
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700360 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
361 descriptorSet.BindCommandBuffer(m_cmdBuffer);
Tobin Ehlis11e52132014-11-28 11:17:19 -0700362#ifdef DUMP_STATE_DOT
363 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
364 pDSDumpDot((char*)"triUniFS.dot");
365#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700366 // render the triangle
367 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
Cody Northropee6586d2014-10-09 19:55:56 -0600368
369 // finalize recording of the command buffer
370 err = xglEndCommandBuffer( m_cmdBuffer );
371 ASSERT_XGL_SUCCESS( err );
372
Cody Northropee6586d2014-10-09 19:55:56 -0600373 // submit the command buffer to the universal queue
Tony Barbour75e9ee42014-12-04 17:17:26 -0700374 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL );
Cody Northropee6586d2014-10-09 19:55:56 -0600375 ASSERT_XGL_SUCCESS( err );
376
377 err = xglQueueWaitIdle( m_device->m_queue );
378 ASSERT_XGL_SUCCESS( err );
379
380 // Wait for work to finish before cleaning up.
381 xglDeviceWaitIdle(m_device->device());
382
Chia-I Wuecebf752014-12-05 10:45:15 +0800383 assert(m_renderTargetCount == 1);
384 RecordImage(m_renderTargets[0]);
Cody Northropee6586d2014-10-09 19:55:56 -0600385
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600386}
387
Tony Barboure2c58df2014-11-25 13:18:32 -0700388void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour664accc2015-01-09 12:55:14 -0700389 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
390{
391 int i;
392 glm::mat4 MVP;
393 int matrixSize = sizeof(MVP);
394 XGL_RESULT err;
395
396 for (i = 0; i < 8; i++) {
397 void *pData = constantBuffer->map();
398
399 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
400 MVP = Projection * View * Model;
401 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
402
403 constantBuffer->unmap();
404
405 // submit the command buffer to the universal queue
406 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
407
408 // err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
409 // ASSERT_XGL_SUCCESS( err );
410
411 err = xglQueueWaitIdle( m_device->m_queue );
412 ASSERT_XGL_SUCCESS( err );
413
414 // Wait for work to finish before cleaning up.
415 xglDeviceWaitIdle(m_device->device());
416
417 assert(m_renderTargetCount == 1);
418 RecordImage(m_renderTargets[0]);
419 }
420}
421void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour1c042032014-12-03 16:13:23 -0700422 XglConstantBufferObj *constantBuffer)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600423{
424 int i;
425 glm::mat4 MVP;
426 int matrixSize = sizeof(MVP);
427 XGL_RESULT err;
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600428
429 for (i = 0; i < 8; i++) {
Chia-I Wua07fee62014-12-28 15:26:08 +0800430 void *pData = constantBuffer->map();
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600431
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600432 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
433 MVP = Projection * View * Model;
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600434 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
435
Chia-I Wua07fee62014-12-28 15:26:08 +0800436 constantBuffer->unmap();
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600437
438 // submit the command buffer to the universal queue
Tony Barboure2c58df2014-11-25 13:18:32 -0700439 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600440 ASSERT_XGL_SUCCESS( err );
441
442 err = xglQueueWaitIdle( m_device->m_queue );
443 ASSERT_XGL_SUCCESS( err );
444
445 // Wait for work to finish before cleaning up.
446 xglDeviceWaitIdle(m_device->device());
447
Chia-I Wuecebf752014-12-05 10:45:15 +0800448 assert(m_renderTargetCount == 1);
449 RecordImage(m_renderTargets[0]);
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600450 }
Cody Northrop66594a72014-10-10 14:49:36 -0600451}
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600452void dumpMatrix(const char *note, glm::mat4 MVP)
453{
Chia-I Wu6f184292014-12-15 23:57:34 +0800454 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600455
456 printf("%s: \n", note);
457 for (i=0; i<4; i++) {
458 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
459 }
460 printf("\n");
461 fflush(stdout);
462}
463
464void dumpVec4(const char *note, glm::vec4 vector)
465{
466 printf("%s: \n", note);
467 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
468 printf("\n");
469 fflush(stdout);
470}
471
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600472void XglRenderTest::GenerateClearAndPrepareBufferCmds()
473{
474 XglRenderFramework::GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchtera4276c02014-10-22 18:02:30 -0600475
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700476 if (m_depthStencilImage) {
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700477 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
478 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
479 dsRange.baseMipLevel = 0;
480 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
481 dsRange.baseArraySlice = 0;
482 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
Cody Northrop66594a72014-10-10 14:49:36 -0600483
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700484 // prepare the depth buffer for clear
485 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
486 transitionToClear.image = m_depthStencilImage;
487 transitionToClear.oldState = m_depthStencilBinding.depthState;
488 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
489 transitionToClear.subresourceRange = dsRange;
490 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
491 m_depthStencilBinding.depthState = transitionToClear.newState;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600492
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700493 xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600494
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700495 // prepare depth buffer for rendering
496 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wufc0c2842014-12-05 10:48:20 +0800497 transitionToRender.image = m_depthStencilImage;
Tony Barboure3e2e3f2014-12-04 17:14:45 -0700498 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
499 transitionToRender.newState = m_depthStencilBinding.depthState;
500 transitionToRender.subresourceRange = dsRange;
501 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
502 m_depthStencilBinding.depthState = transitionToClear.newState;
503 }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600504}
505
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600506void XglRenderTest::InitDepthStencil()
507{
508 XGL_RESULT err;
509 XGL_IMAGE_CREATE_INFO image;
510 XGL_MEMORY_ALLOC_INFO mem_alloc;
511 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
512 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburnb9e193f2014-11-21 11:33:20 -0700513 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600514
515 // Clean up default state created by framework
516 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
517
518 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
519 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
520
521 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
522 image.pNext = NULL;
523 image.imageType = XGL_IMAGE_2D;
524 image.format = m_depth_stencil_fmt;
525 image.extent.width = m_width;
526 image.extent.height = m_height;
527 image.extent.depth = 1;
528 image.mipLevels = 1;
529 image.arraySize = 1;
530 image.samples = 1;
531 image.tiling = XGL_OPTIMAL_TILING;
532 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
533 image.flags = 0;
534
535 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
536 mem_alloc.pNext = NULL;
537 mem_alloc.allocationSize = 0;
538 mem_alloc.alignment = 0;
539 mem_alloc.flags = 0;
540 mem_alloc.heapCount = 0;
541 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
542
543 /* create image */
544 err = xglCreateImage(device(), &image,
545 &m_depthStencilImage);
546 ASSERT_XGL_SUCCESS(err);
547
548 err = xglGetObjectInfo(m_depthStencilImage,
549 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
550 &mem_reqs_size, &mem_reqs);
551 ASSERT_XGL_SUCCESS(err);
552 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
553
554 mem_alloc.allocationSize = mem_reqs.size;
555 mem_alloc.alignment = mem_reqs.alignment;
556 mem_alloc.heapCount = mem_reqs.heapCount;
557 memcpy(mem_alloc.heaps, mem_reqs.heaps,
558 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
559
560 /* allocate memory */
561 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
562 ASSERT_XGL_SUCCESS(err);
563
564 /* bind memory */
565 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
566 ASSERT_XGL_SUCCESS(err);
567
568 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
569 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
570 depthStencil.depthTestEnable = XGL_TRUE;
571 depthStencil.depthWriteEnable = XGL_TRUE;
572 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
573 depthStencil.depthBoundsEnable = XGL_FALSE;
574 depthStencil.minDepth = 0.f;
575 depthStencil.maxDepth = 1.f;
576 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
577 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
578 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
579 depthStencil.back.stencilRef = 0x00;
580 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
581 depthStencil.front = depthStencil.back;
582
583 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
584 ASSERT_XGL_SUCCESS( err );
585
586 /* create image view */
587 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
588 view.pNext = NULL;
589 view.image = XGL_NULL_HANDLE;
590 view.mipLevel = 0;
591 view.baseArraySlice = 0;
592 view.arraySize = 1;
593 view.flags = 0;
594 view.image = m_depthStencilImage;
595 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
596 ASSERT_XGL_SUCCESS(err);
597
598 m_depthStencilBinding.view = m_depthStencilView;
599 m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
600 m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
601}
602
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600603struct xgltriangle_vs_uniform {
604 // Must start with MVP
605 XGL_FLOAT mvp[4][4];
606 XGL_FLOAT position[3][4];
607 XGL_FLOAT color[3][4];
608};
609
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600610void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600611{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700612#ifdef DEBUG_CALLBACK
613 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
614#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600615 // Create identity matrix
616 int i;
617 struct xgltriangle_vs_uniform data;
618
619 glm::mat4 Projection = glm::mat4(1.0f);
620 glm::mat4 View = glm::mat4(1.0f);
621 glm::mat4 Model = glm::mat4(1.0f);
622 glm::mat4 MVP = Projection * View * Model;
623 const int matrixSize = sizeof(MVP);
624 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
625 memcpy(&data.mvp, &MVP[0][0], matrixSize);
626
627 static const Vertex tri_data[] =
628 {
629 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
630 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
631 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
632 };
633
634 for (i=0; i<3; i++) {
635 data.position[i][0] = tri_data[i].posX;
636 data.position[i][1] = tri_data[i].posY;
637 data.position[i][2] = tri_data[i].posZ;
638 data.position[i][3] = tri_data[i].posW;
639 data.color[i][0] = tri_data[i].r;
640 data.color[i][1] = tri_data[i].g;
641 data.color[i][2] = tri_data[i].b;
642 data.color[i][3] = tri_data[i].a;
643 }
644
Tony Barboure2c58df2014-11-25 13:18:32 -0700645 ASSERT_NO_FATAL_FAILURE(InitState());
646 ASSERT_NO_FATAL_FAILURE(InitViewport());
647
648 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
649
650 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
651 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
652 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
653
654 XglPipelineObj pipelineobj(m_device);
655 pipelineobj.AddShader(&vs);
656 pipelineobj.AddShader(&ps);
657
658 XglDescriptorSetObj descriptorSet(m_device);
659 descriptorSet.AttachMemoryView(&constantBuffer);
660 m_memoryRefManager.AddMemoryRef(&constantBuffer);
661
Tony Barbour2bd96162014-12-03 15:46:29 -0700662 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700663 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
664
Tony Barbour1c042032014-12-03 16:13:23 -0700665 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tobin Ehlisca915872014-11-18 11:28:33 -0700666#ifdef PRINT_OBJECTS
667 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
668 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
669 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
670 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
671 printf("DEBUG : Number of Objects : %lu\n", numObjects);
672 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
673 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
674 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
675 for (i=0; i < numObjects; i++) {
676 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);
677 }
678 free(pObjNodeArray);
679#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700680
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600681}
682
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600683TEST_F(XglRenderTest, XGLTriangle_FragColor)
684{
685 static const char *vertShaderText =
686 "#version 140\n"
687 "#extension GL_ARB_separate_shader_objects : enable\n"
688 "#extension GL_ARB_shading_language_420pack : enable\n"
689 "\n"
690 "layout(binding = 0) uniform buf {\n"
691 " mat4 MVP;\n"
692 " vec4 position[3];\n"
693 " vec4 color[3];\n"
694 "} ubuf;\n"
695 "\n"
696 "layout (location = 0) out vec4 outColor;\n"
697 "\n"
698 "void main() \n"
699 "{\n"
700 " outColor = ubuf.color[gl_VertexID];\n"
701 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
702 "}\n";
703
704 static const char *fragShaderText =
705 "#version 140\n"
706 "#extension GL_ARB_separate_shader_objects : enable\n"
707 "#extension GL_ARB_shading_language_420pack : enable\n"
708 "\n"
709 "layout (location = 0) in vec4 inColor;\n"
710 "\n"
711 "void main()\n"
712 "{\n"
713 " gl_FragColor = inColor;\n"
714 "}\n";
715
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600716 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600717 XGLTriangleTest(vertShaderText, fragShaderText);
718}
719
720TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
721{
722 static const char *vertShaderText =
723 "#version 140\n"
724 "#extension GL_ARB_separate_shader_objects : enable\n"
725 "#extension GL_ARB_shading_language_420pack : enable\n"
726 "\n"
727 "layout(binding = 0) uniform buf {\n"
728 " mat4 MVP;\n"
729 " vec4 position[3];\n"
730 " vec4 color[3];\n"
731 "} ubuf;\n"
732 "\n"
733 "layout (location = 0) out vec4 outColor;\n"
734 "\n"
735 "void main() \n"
736 "{\n"
737 " outColor = ubuf.color[gl_VertexID];\n"
738 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
739 "}\n";
740
741 static const char *fragShaderText =
742 "#version 140\n"
743 "#extension GL_ARB_separate_shader_objects : enable\n"
744 "#extension GL_ARB_shading_language_420pack : enable\n"
745 "\n"
746 "layout (location = 0) in vec4 inColor;\n"
747 "layout (location = 0) out vec4 outColor;\n"
748 "\n"
749 "void main()\n"
750 "{\n"
751 " outColor = inColor;\n"
752 "}\n";
753
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600754 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 -0600755
756 XGLTriangleTest(vertShaderText, fragShaderText);
757}
758
Tony Barboure2c58df2014-11-25 13:18:32 -0700759TEST_F(XglRenderTest, BIL_XGLTriangle)
760{
761 bool saved_use_bil = XglTestFramework::m_use_bil;
762
763 static const char *vertShaderText =
764 "#version 140\n"
765 "#extension GL_ARB_separate_shader_objects : enable\n"
766 "#extension GL_ARB_shading_language_420pack : enable\n"
767 "\n"
768 "layout(binding = 0) uniform buf {\n"
769 " mat4 MVP;\n"
770 " vec4 position[3];\n"
771 " vec4 color[3];\n"
772 "} ubuf;\n"
773 "\n"
774 "layout (location = 0) out vec4 outColor;\n"
775 "\n"
776 "void main() \n"
777 "{\n"
778 " outColor = ubuf.color[gl_VertexID];\n"
779 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
780 "}\n";
781
782 static const char *fragShaderText =
783 "#version 140\n"
784 "#extension GL_ARB_separate_shader_objects : enable\n"
785 "#extension GL_ARB_shading_language_420pack : enable\n"
786 "\n"
787 "layout (location = 0) in vec4 inColor;\n"
788 "\n"
789 "void main()\n"
790 "{\n"
791 " gl_FragColor = inColor;\n"
792 "}\n";
793
794 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
795
796 XglTestFramework::m_use_bil = true;
797
798 XGLTriangleTest(vertShaderText, fragShaderText);
799
800 XglTestFramework::m_use_bil = saved_use_bil;
801}
802
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600803TEST_F(XglRenderTest, GreenTriangle)
Cody Northropd1a256b2014-10-09 21:26:47 -0600804{
805 static const char *vertShaderText =
806 "#version 130\n"
807 "vec2 vertices[3];\n"
808 "void main() {\n"
809 " vertices[0] = vec2(-1.0, -1.0);\n"
810 " vertices[1] = vec2( 1.0, -1.0);\n"
811 " vertices[2] = vec2( 0.0, 1.0);\n"
812 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
813 "}\n";
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600814
Cody Northropd1a256b2014-10-09 21:26:47 -0600815 static const char *fragShaderText =
816 "#version 130\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600817 "void main() {\n"
Steve Kc53f8632014-10-10 08:54:29 -0600818 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600819 "}\n";
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600820
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600821 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
822
Cody Northropd1a256b2014-10-09 21:26:47 -0600823 DrawTriangleTest(vertShaderText, fragShaderText);
824}
Cody Northropee6586d2014-10-09 19:55:56 -0600825
Tony Barboure2c58df2014-11-25 13:18:32 -0700826TEST_F(XglRenderTest, BIL_GreenTriangle)
827{
828 bool saved_use_bil = XglTestFramework::m_use_bil;
829
830 static const char *vertShaderText =
831 "#version 130\n"
832 "vec2 vertices[3];\n"
833 "void main() {\n"
834 " vertices[0] = vec2(-1.0, -1.0);\n"
835 " vertices[1] = vec2( 1.0, -1.0);\n"
836 " vertices[2] = vec2( 0.0, 1.0);\n"
837 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
838 "}\n";
839
840 static const char *fragShaderText =
841 "#version 130\n"
842 "void main() {\n"
843 " gl_FragColor = vec4(0,1,0,1);\n"
844 "}\n";
845
846 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
847
848 XglTestFramework::m_use_bil = true;
849 DrawTriangleTest(vertShaderText, fragShaderText);
850 XglTestFramework::m_use_bil = saved_use_bil;
851}
852
853TEST_F(XglRenderTest, YellowTriangle)
854{
855 static const char *vertShaderText =
856 "#version 130\n"
857 "void main() {\n"
858 " vec2 vertices[3];"
859 " vertices[0] = vec2(-0.5, -0.5);\n"
860 " vertices[1] = vec2( 0.5, -0.5);\n"
861 " vertices[2] = vec2( 0.5, 0.5);\n"
862 " vec4 colors[3];\n"
863 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
864 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
865 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
866 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
867 "}\n";
868
869 static const char *fragShaderText =
870 "#version 130\n"
871 "void main() {\n"
872 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
873 "}\n";
874
875 DrawTriangleTest(vertShaderText, fragShaderText);
876}
877
Courtney Goeltzenleuchter2f53dfa2014-10-10 17:02:53 -0600878TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600879{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600880 static const char *vertShaderText =
Tony Barboure2c58df2014-11-25 13:18:32 -0700881 "#version 130\n"
882 //XYZ1( -1, -1, -1 )
883 "in vec4 pos;\n"
884 //XYZ1( 0.f, 0.f, 0.f )
885 "in vec4 inColor;\n"
886 "out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600887 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600888 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600889 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600890 "}\n";
891
Cody Northropee6586d2014-10-09 19:55:56 -0600892
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600893 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700894 "#version 140\n"
895 "#extension GL_ARB_separate_shader_objects : enable\n"
896 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700897 "in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700898 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600899 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700900 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600901 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600902
Tony Barboure2c58df2014-11-25 13:18:32 -0700903
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906 ASSERT_NO_FATAL_FAILURE(InitViewport());
907
908 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -0700909 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -0700910
911 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
912 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
913
914 XglPipelineObj pipelineobj(m_device);
915 pipelineobj.AddShader(&vs);
916 pipelineobj.AddShader(&ps);
917
918 XglDescriptorSetObj descriptorSet(m_device);
919 descriptorSet.AttachMemoryView(&meshBuffer);
920
921 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
922 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
923 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
924 };
925
926 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
927 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
928 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
929 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
930 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
931 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
932 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
933 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
934 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
935
936 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
937 pipelineobj.AddVertexInputBindings(&vi_binding,1);
938 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
939
Tony Barbour1fde6942015-01-09 10:06:53 -0700940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
941 XglCommandBufferObj cmdBuffer(m_device);
942 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700943
Tony Barbour1fde6942015-01-09 10:06:53 -0700944 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
945 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
946
Tony Barbour1fde6942015-01-09 10:06:53 -0700947 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
948
949 // render two triangles
950 cmdBuffer.Draw(0, 6, 0, 1);
951
952 // finalize recording of the command buffer
953 cmdBuffer.EndCommandBuffer();
954 cmdBuffer.QueueCommandBuffer(NULL, 0);
955
956 for (int i = 0; i < m_renderTargetCount; i++)
957 RecordImage(m_renderTargets[i]);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600958}
959
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800960TEST_F(XglRenderTest, TriangleMRT)
961{
962 static const char *vertShaderText =
963 "#version 130\n"
964 "in vec4 pos;\n"
965 "void main() {\n"
966 " gl_Position = pos;\n"
967 "}\n";
968
969 static const char *fragShaderText =
970 "#version 130\n"
971 "void main() {\n"
972 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
973 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
974 "}\n";
975 const XGL_FLOAT vb_data[][2] = {
976 { -1.0f, -1.0f },
977 { 1.0f, -1.0f },
978 { -1.0f, 1.0f }
979 };
980
981 ASSERT_NO_FATAL_FAILURE(InitState());
982 ASSERT_NO_FATAL_FAILURE(InitViewport());
983
984 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Tony Barbour099a9eb2014-12-10 17:40:15 -0700985 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800986
987 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
988 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
989
990 XglPipelineObj pipelineobj(m_device);
991 pipelineobj.AddShader(&vs);
992 pipelineobj.AddShader(&ps);
993
994 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
995 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
996 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
997 };
998
999 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
1000 vi_attrib.binding = 0; // index into vertexBindingDescriptions
1001 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
1002 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
1003 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1004
1005 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
1006 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1007 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1008
1009 XglDescriptorSetObj descriptorSet(m_device);
1010
1011 m_renderTargetCount = 2;
Tony Barbour1fde6942015-01-09 10:06:53 -07001012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wufe7bb8f2014-12-05 10:32:23 +08001013
1014 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
1015 att.blendEnable = XGL_FALSE;
1016 att.format = m_render_target_fmt;
1017 att.channelWriteMask = 0xf;
1018 pipelineobj.SetColorAttachment(1, &att);
1019
Tony Barbour304ec8b2015-01-07 14:31:52 -07001020 XglCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -07001021
Tony Barbour304ec8b2015-01-07 14:31:52 -07001022 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1023 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barbour1fde6942015-01-09 10:06:53 -07001024
Tony Barbour304ec8b2015-01-07 14:31:52 -07001025 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
Tony Barbour304ec8b2015-01-07 14:31:52 -07001026
Tony Barbour1fde6942015-01-09 10:06:53 -07001027 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1028
Tony Barbour304ec8b2015-01-07 14:31:52 -07001029 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -07001030#ifdef DUMP_STATE_DOT
1031 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1032 pDSDumpDot((char*)"triTest2.dot");
1033#endif
1034 // render triangle
1035 cmdBuffer.Draw(0, 3, 0, 1);
1036
1037 // finalize recording of the command buffer
1038 cmdBuffer.EndCommandBuffer();
1039 cmdBuffer.QueueCommandBuffer(NULL, 0);
1040
1041 for (int i = 0; i < m_renderTargetCount; i++)
1042 RecordImage(m_renderTargets[i]);
1043
Chia-I Wufe7bb8f2014-12-05 10:32:23 +08001044}
1045
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001046TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
1047{
1048 static const char *vertShaderText =
1049 "#version 140\n"
1050 "#extension GL_ARB_separate_shader_objects : enable\n"
1051 "#extension GL_ARB_shading_language_420pack : enable\n"
1052 "layout(location = 0) in vec4 pos;\n"
1053 "layout(location = 1) in vec4 inColor;\n"
1054 "layout(location = 0) out vec4 outColor;\n"
1055 "void main() {\n"
1056 " outColor = inColor;\n"
1057 " gl_Position = pos;\n"
1058 "}\n";
1059
1060
1061 static const char *fragShaderText =
1062 "#version 140\n"
1063 "#extension GL_ARB_separate_shader_objects : enable\n"
1064 "#extension GL_ARB_shading_language_420pack : enable\n"
1065 "layout(location = 0) in vec4 color;\n"
1066 "void main() {\n"
1067 " gl_FragColor = color;\n"
1068 "}\n";
1069
1070 const Vertex g_vbData[] =
1071 {
1072 // first tri
1073 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
1074 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1075 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1076
1077 // second tri
1078 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1079 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1080 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
1081 };
1082
1083 const uint16_t g_idxData[6] = {
1084 0, 1, 2,
1085 3, 4, 5,
1086 };
1087
1088 ASSERT_NO_FATAL_FAILURE(InitState());
1089 ASSERT_NO_FATAL_FAILURE(InitViewport());
1090
1091 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001092 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001093
1094 XglIndexBufferObj indexBuffer(m_device);
1095 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001096 indexBuffer.SetMemoryState(XGL_MEMORY_STATE_INDEX_DATA);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001097
1098 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1099 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1100
1101 XglPipelineObj pipelineobj(m_device);
1102 pipelineobj.AddShader(&vs);
1103 pipelineobj.AddShader(&ps);
1104
1105 XglDescriptorSetObj descriptorSet(m_device);
1106
1107 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1108 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1109 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1110 };
1111
1112 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1113 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1114 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1115 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1116 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1117 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1118 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1119 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1120 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1121
1122 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1123 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001124
1125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourad8f1542014-12-17 11:16:05 -07001126 XglCommandBufferObj cmdBuffer(m_device);
1127 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1128 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
Tony Barbour1fde6942015-01-09 10:06:53 -07001129
1130 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001131
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001132#ifdef DUMP_STATE_DOT
1133 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -07001134 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001135#endif
Tony Barbour22e32a12015-01-08 17:08:28 -07001136
Tony Barbourad8f1542014-12-17 11:16:05 -07001137 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1138 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001139
1140 // render two triangles
Tony Barbourad8f1542014-12-17 11:16:05 -07001141 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001142
1143 // finalize recording of the command buffer
Tony Barbourad8f1542014-12-17 11:16:05 -07001144 cmdBuffer.EndCommandBuffer();
1145 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001146
Tony Barbourad8f1542014-12-17 11:16:05 -07001147 for (int i = 0; i < m_renderTargetCount; i++)
1148 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001149
1150}
1151
GregF3156cb02014-12-02 15:41:44 -07001152TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1153{
1154 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001155
GregF3156cb02014-12-02 15:41:44 -07001156 static const char *vertShaderText =
1157 "#version 140\n"
1158 "#extension GL_ARB_separate_shader_objects : enable\n"
1159 "#extension GL_ARB_shading_language_420pack : enable\n"
1160 "layout (location = 0) in vec4 pos;\n"
1161 "layout (location = 0) out vec4 outColor;\n"
1162 "layout (location = 1) out vec4 outColor2;\n"
1163 "void main() {\n"
1164 " gl_Position = pos;\n"
1165 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1166 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1167 "}\n";
1168
1169 static const char *fragShaderText =
1170 //"#version 140\n"
1171 "#version 330\n"
1172 "#extension GL_ARB_separate_shader_objects : enable\n"
1173 "#extension GL_ARB_shading_language_420pack : enable\n"
1174 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1175 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1176 "layout (location = 0) in vec4 color;\n"
1177 "layout (location = 1) in vec4 color2;\n"
1178 "void main() {\n"
1179 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1180 " float dist_squared = dot(pos, pos);\n"
1181 " gl_FragColor = (dist_squared < 400.0)\n"
1182 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1183 " : color2;\n"
1184 "}\n";
1185
1186 ASSERT_NO_FATAL_FAILURE(InitState());
1187 ASSERT_NO_FATAL_FAILURE(InitViewport());
1188
1189 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001190 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001191
1192 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1193 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1194
1195 XglPipelineObj pipelineobj(m_device);
1196 pipelineobj.AddShader(&vs);
1197 pipelineobj.AddShader(&ps);
1198
1199 XglDescriptorSetObj descriptorSet(m_device);
1200 descriptorSet.AttachMemoryView(&meshBuffer);
1201
1202 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1203 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1204 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1205 };
1206
1207 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1208 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1209 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1210 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1211 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1212 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1213 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1214 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1215 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1216
1217 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1218 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1219 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1220
Tony Barbour664accc2015-01-09 12:55:14 -07001221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1222 XglCommandBufferObj cmdBuffer(m_device);
1223 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1224
1225 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1226
1227 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1228
1229 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1230#ifdef DUMP_STATE_DOT
1231 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1232 pDSDumpDot((char*)"triTest2.dot");
1233#endif
1234 // render triangle
1235 cmdBuffer.Draw(0, 6, 0, 1);
1236
1237 // finalize recording of the command buffer
1238 cmdBuffer.EndCommandBuffer();
1239 cmdBuffer.QueueCommandBuffer(NULL, 0);
1240
1241 for (int i = 0; i < m_renderTargetCount; i++)
1242 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001243
1244}
1245
1246TEST_F(XglRenderTest, RedCirclesonBlue)
1247{
1248 // This tests that we correctly handle unread fragment inputs
1249
1250 static const char *vertShaderText =
1251 "#version 140\n"
1252 "#extension GL_ARB_separate_shader_objects : enable\n"
1253 "#extension GL_ARB_shading_language_420pack : enable\n"
1254 "layout (location = 0) in vec4 pos;\n"
1255 "layout (location = 0) out vec4 outColor;\n"
1256 "layout (location = 1) out vec4 outColor2;\n"
1257 "void main() {\n"
1258 " gl_Position = pos;\n"
1259 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1260 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1261 "}\n";
1262
1263 static const char *fragShaderText =
1264 //"#version 140\n"
1265 "#version 330\n"
1266 "#extension GL_ARB_separate_shader_objects : enable\n"
1267 "#extension GL_ARB_shading_language_420pack : enable\n"
1268 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1269 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1270 "layout (location = 0) in vec4 color;\n"
1271 "layout (location = 1) in vec4 color2;\n"
1272 "void main() {\n"
1273 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1274 " float dist_squared = dot(pos, pos);\n"
1275 " gl_FragColor = (dist_squared < 400.0)\n"
1276 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1277 " : color2;\n"
1278 "}\n";
1279
1280 ASSERT_NO_FATAL_FAILURE(InitState());
1281 ASSERT_NO_FATAL_FAILURE(InitViewport());
1282
1283 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001284 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001285
1286 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1287 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1288
1289 XglPipelineObj pipelineobj(m_device);
1290 pipelineobj.AddShader(&vs);
1291 pipelineobj.AddShader(&ps);
1292
1293 XglDescriptorSetObj descriptorSet(m_device);
1294 descriptorSet.AttachMemoryView(&meshBuffer);
1295
1296 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1297 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1298 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1299 };
1300
1301 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1302 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1303 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1304 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1305 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1306 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1307 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1308 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1309 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1310
1311 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1312 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1313 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1314
Tony Barbour664accc2015-01-09 12:55:14 -07001315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1316 XglCommandBufferObj cmdBuffer(m_device);
1317 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1318
1319 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1320
1321 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1322
1323 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1324#ifdef DUMP_STATE_DOT
1325 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1326 pDSDumpDot((char*)"triTest2.dot");
1327#endif
1328 // render triangle
1329 cmdBuffer.Draw(0, 6, 0, 1);
1330
1331 // finalize recording of the command buffer
1332 cmdBuffer.EndCommandBuffer();
1333 cmdBuffer.QueueCommandBuffer(NULL, 0);
1334
1335 for (int i = 0; i < m_renderTargetCount; i++)
1336 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001337
1338}
1339
1340TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1341{
1342 // This tests reading gl_ClipDistance from FS
1343
1344 static const char *vertShaderText =
1345 "#version 330\n"
1346 "#extension GL_ARB_separate_shader_objects : enable\n"
1347 "#extension GL_ARB_shading_language_420pack : enable\n"
1348 "out gl_PerVertex {\n"
1349 " vec4 gl_Position;\n"
1350 " float gl_ClipDistance[1];\n"
1351 "};\n"
1352 "layout (location = 0) in vec4 pos;\n"
1353 "layout (location = 0) out vec4 outColor;\n"
1354 "layout (location = 1) out vec4 outColor2;\n"
1355 "void main() {\n"
1356 " gl_Position = pos;\n"
1357 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1358 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1359 " float dists[3];\n"
1360 " dists[0] = 0.0;\n"
1361 " dists[1] = 1.0;\n"
1362 " dists[2] = 1.0;\n"
1363 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1364 "}\n";
1365
1366
1367 static const char *fragShaderText =
1368 //"#version 140\n"
1369 "#version 330\n"
1370 "#extension GL_ARB_separate_shader_objects : enable\n"
1371 "#extension GL_ARB_shading_language_420pack : enable\n"
1372 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1373 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1374 "layout (location = 0) in vec4 color;\n"
1375 "layout (location = 1) in vec4 color2;\n"
1376 "void main() {\n"
1377 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1378 " float dist_squared = dot(pos, pos);\n"
1379 " gl_FragColor = (dist_squared < 400.0)\n"
1380 " ? color * gl_ClipDistance[0]\n"
1381 " : color2;\n"
1382 "}\n";
1383
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385 ASSERT_NO_FATAL_FAILURE(InitViewport());
1386
1387 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001388 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF3156cb02014-12-02 15:41:44 -07001389
1390 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1391 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1392
1393 XglPipelineObj pipelineobj(m_device);
1394 pipelineobj.AddShader(&vs);
1395 pipelineobj.AddShader(&ps);
1396
1397 XglDescriptorSetObj descriptorSet(m_device);
1398 descriptorSet.AttachMemoryView(&meshBuffer);
1399
1400 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1401 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1402 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1403 };
1404
1405 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1406 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1407 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1408 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1409 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1410 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1411 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1412 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1413 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1414
1415 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1416 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1417 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1418
Tony Barbour664accc2015-01-09 12:55:14 -07001419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1420 XglCommandBufferObj cmdBuffer(m_device);
1421 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF3156cb02014-12-02 15:41:44 -07001422
Tony Barbour664accc2015-01-09 12:55:14 -07001423 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1424
1425 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1426
1427 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1428#ifdef DUMP_STATE_DOT
1429 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1430 pDSDumpDot((char*)"triTest2.dot");
1431#endif
1432 // render triangle
1433 cmdBuffer.Draw(0, 6, 0, 1);
1434
1435 // finalize recording of the command buffer
1436 cmdBuffer.EndCommandBuffer();
1437 cmdBuffer.QueueCommandBuffer(NULL, 0);
1438
1439 for (int i = 0; i < m_renderTargetCount; i++)
1440 RecordImage(m_renderTargets[i]);
GregF3156cb02014-12-02 15:41:44 -07001441}
Tony Barboure2c58df2014-11-25 13:18:32 -07001442
GregF42226582014-12-02 17:19:34 -07001443TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1444{
1445 static const char *vertShaderText =
1446 "#version 140\n"
1447 "#extension GL_ARB_separate_shader_objects : enable\n"
1448 "#extension GL_ARB_shading_language_420pack : enable\n"
1449 "layout (location = 0) in vec4 pos;\n"
1450 "layout (location = 0) out vec4 outColor;\n"
1451 "layout (location = 1) out vec4 outColor2;\n"
1452 "void main() {\n"
1453 " gl_Position = pos;\n"
1454 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1455 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1456 "}\n";
1457
1458
1459 static const char *fragShaderText =
1460 //"#version 140\n"
1461 "#version 330\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1465 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1466 "layout (location = 0) in vec4 color;\n"
1467 "layout (location = 1) in vec4 color2;\n"
1468 "void main() {\n"
1469 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1470 " float dist_squared = dot(pos, pos);\n"
1471 " if (dist_squared < 100.0)\n"
1472 " discard;\n"
1473 " gl_FragColor = (dist_squared < 400.0)\n"
1474 " ? color\n"
1475 " : color2;\n"
1476 "}\n";
1477
1478 ASSERT_NO_FATAL_FAILURE(InitState());
1479 ASSERT_NO_FATAL_FAILURE(InitViewport());
1480
1481 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001482 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF42226582014-12-02 17:19:34 -07001483
1484 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1485 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1486
1487 XglPipelineObj pipelineobj(m_device);
1488 pipelineobj.AddShader(&vs);
1489 pipelineobj.AddShader(&ps);
1490
1491 XglDescriptorSetObj descriptorSet(m_device);
1492 descriptorSet.AttachMemoryView(&meshBuffer);
1493
1494 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1495 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1496 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1497 };
1498
1499 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1500 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1501 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1502 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1503 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1504 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1505 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1506 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1507 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1508
1509 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1510 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1511 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1512
Tony Barbour664accc2015-01-09 12:55:14 -07001513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1514 XglCommandBufferObj cmdBuffer(m_device);
1515 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1516
1517 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1518
1519 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1520
1521 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1522#ifdef DUMP_STATE_DOT
1523 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1524 pDSDumpDot((char*)"triTest2.dot");
1525#endif
1526 // render triangle
1527 cmdBuffer.Draw(0, 6, 0, 1);
1528
1529 // finalize recording of the command buffer
1530 cmdBuffer.EndCommandBuffer();
1531 cmdBuffer.QueueCommandBuffer(NULL, 0);
1532
1533 for (int i = 0; i < m_renderTargetCount; i++)
1534 RecordImage(m_renderTargets[i]);
GregF42226582014-12-02 17:19:34 -07001535
1536}
1537
1538
Courtney Goeltzenleuchterd66e41e2014-10-27 13:06:08 -06001539TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001540{
1541 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001542 "#version 140\n"
1543 "#extension GL_ARB_separate_shader_objects : enable\n"
1544 "#extension GL_ARB_shading_language_420pack : enable\n"
1545 "\n"
1546 "layout(binding = 0) uniform buf {\n"
1547 " mat4 MVP;\n"
1548 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001549 "void main() {\n"
1550 " vec2 vertices[3];"
1551 " vertices[0] = vec2(-0.5, -0.5);\n"
1552 " vertices[1] = vec2( 0.5, -0.5);\n"
1553 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001554 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001555 "}\n";
1556
1557 static const char *fragShaderText =
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001558 "#version 130\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001559 "void main() {\n"
Cody Northropbb38ad32014-10-10 15:45:00 -06001560 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001561 "}\n";
1562
Tony Barboure2c58df2014-11-25 13:18:32 -07001563 ASSERT_NO_FATAL_FAILURE(InitState());
1564 ASSERT_NO_FATAL_FAILURE(InitViewport());
1565
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001566 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001567 glm::mat4 Projection = glm::mat4(1.0f);
1568 glm::mat4 View = glm::mat4(1.0f);
1569 glm::mat4 Model = glm::mat4(1.0f);
1570 glm::mat4 MVP = Projection * View * Model;
1571 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1572
Tony Barboure2c58df2014-11-25 13:18:32 -07001573 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1574 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1575 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001576
Tony Barboure2c58df2014-11-25 13:18:32 -07001577 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1578
1579 XglPipelineObj pipelineobj(m_device);
1580 pipelineobj.AddShader(&vs);
1581 pipelineobj.AddShader(&ps);
1582
1583 // Create descriptor set and attach the constant buffer to it
1584 XglDescriptorSetObj descriptorSet(m_device);
1585 descriptorSet.AttachMemoryView(&MVPBuffer);
1586
1587 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1588
Tony Barbour664accc2015-01-09 12:55:14 -07001589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1590 XglCommandBufferObj cmdBuffer(m_device);
1591 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001592
Tony Barbour664accc2015-01-09 12:55:14 -07001593 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1594
1595 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1596
1597 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1598#ifdef DUMP_STATE_DOT
1599 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1600 pDSDumpDot((char*)"triTest2.dot");
1601#endif
1602 // render triangle
1603 cmdBuffer.Draw(0, 6, 0, 1);
1604
1605 // finalize recording of the command buffer
1606 cmdBuffer.EndCommandBuffer();
1607 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1608
1609 for (int i = 0; i < m_renderTargetCount; i++)
1610 RecordImage(m_renderTargets[i]);
1611
1612 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001613}
1614
Tony Barboure2c58df2014-11-25 13:18:32 -07001615TEST_F(XglRenderTest, MixTriangle)
1616{
1617 // This tests location applied to varyings. Notice that we have switched foo
1618 // and bar in the FS. The triangle should be blended with red, green and blue
1619 // corners.
1620 static const char *vertShaderText =
1621 "#version 140\n"
1622 "#extension GL_ARB_separate_shader_objects : enable\n"
1623 "#extension GL_ARB_shading_language_420pack : enable\n"
1624 "layout (location=0) out vec4 bar;\n"
1625 "layout (location=1) out vec4 foo;\n"
1626 "layout (location=2) out float scale;\n"
1627 "vec2 vertices[3];\n"
1628 "void main() {\n"
1629 " vertices[0] = vec2(-1.0, -1.0);\n"
1630 " vertices[1] = vec2( 1.0, -1.0);\n"
1631 " vertices[2] = vec2( 0.0, 1.0);\n"
1632 "vec4 colors[3];\n"
1633 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1634 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1635 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1636 " foo = colors[gl_VertexID % 3];\n"
1637 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1638 " scale = 1.0;\n"
1639 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1640 "}\n";
1641
1642 static const char *fragShaderText =
1643 "#version 140\n"
1644 "#extension GL_ARB_separate_shader_objects : enable\n"
1645 "#extension GL_ARB_shading_language_420pack : enable\n"
1646 "layout (location = 1) in vec4 bar;\n"
1647 "layout (location = 0) in vec4 foo;\n"
1648 "layout (location = 2) in float scale;\n"
1649 "void main() {\n"
1650 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1651 "}\n";
1652
1653 ASSERT_NO_FATAL_FAILURE(InitState());
1654 ASSERT_NO_FATAL_FAILURE(InitViewport());
1655
1656 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1657 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1658
1659 XglPipelineObj pipelineobj(m_device);
1660 pipelineobj.AddShader(&vs);
1661 pipelineobj.AddShader(&ps);
1662
1663 XglDescriptorSetObj descriptorSet(m_device);
1664
Tony Barbour664accc2015-01-09 12:55:14 -07001665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1666 XglCommandBufferObj cmdBuffer(m_device);
1667 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1668
1669 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1670
1671 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1672
1673#ifdef DUMP_STATE_DOT
1674 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1675 pDSDumpDot((char*)"triTest2.dot");
1676#endif
1677 // render triangle
1678 cmdBuffer.Draw(0, 3, 0, 1);
1679
1680 // finalize recording of the command buffer
1681 cmdBuffer.EndCommandBuffer();
1682 cmdBuffer.QueueCommandBuffer(NULL, 0);
1683
1684 for (int i = 0; i < m_renderTargetCount; i++)
1685 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001686}
1687
1688TEST_F(XglRenderTest, TriVertFetchAndVertID)
1689{
1690 // This tests that attributes work in the presence of gl_VertexID
1691
1692 static const char *vertShaderText =
1693 "#version 140\n"
1694 "#extension GL_ARB_separate_shader_objects : enable\n"
1695 "#extension GL_ARB_shading_language_420pack : enable\n"
1696 //XYZ1( -1, -1, -1 )
1697 "layout (location = 0) in vec4 pos;\n"
1698 //XYZ1( 0.f, 0.f, 0.f )
1699 "layout (location = 1) in vec4 inColor;\n"
1700 "layout (location = 0) out vec4 outColor;\n"
1701 "void main() {\n"
1702 " outColor = inColor;\n"
1703 " vec4 vertices[3];"
1704 " vertices[gl_VertexID % 3] = pos;\n"
1705 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1706 "}\n";
1707
1708
1709 static const char *fragShaderText =
1710 "#version 140\n"
1711 "#extension GL_ARB_separate_shader_objects : enable\n"
1712 "#extension GL_ARB_shading_language_420pack : enable\n"
1713 "layout (location = 0) in vec4 color;\n"
1714 "void main() {\n"
1715 " gl_FragColor = color;\n"
1716 "}\n";
1717
1718 ASSERT_NO_FATAL_FAILURE(InitState());
1719 ASSERT_NO_FATAL_FAILURE(InitViewport());
1720
1721 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001722 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07001723
1724 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1725 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1726
1727 XglPipelineObj pipelineobj(m_device);
1728 pipelineobj.AddShader(&vs);
1729 pipelineobj.AddShader(&ps);
1730
1731 XglDescriptorSetObj descriptorSet(m_device);
1732 descriptorSet.AttachMemoryView(&meshBuffer);
1733
1734 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1735 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1736 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1737 };
1738
1739 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1740 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1741 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1742 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1743 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1744 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1745 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1746 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1747 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1748
1749 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1750 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1751 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1752
Tony Barbour664accc2015-01-09 12:55:14 -07001753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1754 XglCommandBufferObj cmdBuffer(m_device);
1755 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1756
1757 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1758
1759 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1760
1761 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1762#ifdef DUMP_STATE_DOT
1763 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1764 pDSDumpDot((char*)"triTest2.dot");
1765#endif
1766 // render triangle
1767 cmdBuffer.Draw(0, 6, 0, 1);
1768
1769 // finalize recording of the command buffer
1770 cmdBuffer.EndCommandBuffer();
1771 cmdBuffer.QueueCommandBuffer(NULL, 0);
1772
1773 for (int i = 0; i < m_renderTargetCount; i++)
1774 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001775}
1776
1777TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1778{
1779 // This tests that attributes work in the presence of gl_VertexID
1780 // and a dead attribute in position 0. Draws a triangle with yellow,
1781 // red and green corners, starting at top and going clockwise.
1782
1783 static const char *vertShaderText =
1784 "#version 140\n"
1785 "#extension GL_ARB_separate_shader_objects : enable\n"
1786 "#extension GL_ARB_shading_language_420pack : enable\n"
1787 //XYZ1( -1, -1, -1 )
1788 "layout (location = 0) in vec4 pos;\n"
1789 //XYZ1( 0.f, 0.f, 0.f )
1790 "layout (location = 1) in vec4 inColor;\n"
1791 "layout (location = 0) out vec4 outColor;\n"
1792 "void main() {\n"
1793 " outColor = inColor;\n"
1794 " vec2 vertices[3];"
1795 " vertices[0] = vec2(-1.0, -1.0);\n"
1796 " vertices[1] = vec2( 1.0, -1.0);\n"
1797 " vertices[2] = vec2( 0.0, 1.0);\n"
1798 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1799 "}\n";
1800
1801
1802 static const char *fragShaderText =
1803 "#version 140\n"
1804 "#extension GL_ARB_separate_shader_objects : enable\n"
1805 "#extension GL_ARB_shading_language_420pack : enable\n"
1806 "layout (location = 0) in vec4 color;\n"
1807 "void main() {\n"
1808 " gl_FragColor = color;\n"
1809 "}\n";
1810
1811 ASSERT_NO_FATAL_FAILURE(InitState());
1812 ASSERT_NO_FATAL_FAILURE(InitViewport());
1813
1814 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barbour099a9eb2014-12-10 17:40:15 -07001815 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07001816
1817 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1818 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1819
1820 XglPipelineObj pipelineobj(m_device);
1821 pipelineobj.AddShader(&vs);
1822 pipelineobj.AddShader(&ps);
1823
1824 XglDescriptorSetObj descriptorSet(m_device);
1825 descriptorSet.AttachMemoryView(&meshBuffer);
1826
1827 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1828 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1829 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1830 };
1831
1832 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1833 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1834 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1835 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1836 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1837 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1838 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1839 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1840 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1841
1842 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1843 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1844 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1845
Tony Barbour664accc2015-01-09 12:55:14 -07001846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1847 XglCommandBufferObj cmdBuffer(m_device);
1848 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001849
Tony Barbour664accc2015-01-09 12:55:14 -07001850 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1851
1852 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1853
1854 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1855#ifdef DUMP_STATE_DOT
1856 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1857 pDSDumpDot((char*)"triTest2.dot");
1858#endif
1859 // render triangle
1860 cmdBuffer.Draw(0, 6, 0, 1);
1861
1862 // finalize recording of the command buffer
1863 cmdBuffer.EndCommandBuffer();
1864 cmdBuffer.QueueCommandBuffer(NULL, 0);
1865
1866 for (int i = 0; i < m_renderTargetCount; i++)
1867 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001868}
1869
1870TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001871{
1872 static const char *vertShaderText =
1873 "#version 140\n"
1874 "layout (std140) uniform bufferVals {\n"
1875 " mat4 mvp;\n"
1876 "} myBufferVals;\n"
1877 "in vec4 pos;\n"
1878 "in vec4 inColor;\n"
1879 "out vec4 outColor;\n"
1880 "void main() {\n"
1881 " outColor = inColor;\n"
1882 " gl_Position = myBufferVals.mvp * pos;\n"
1883 "}\n";
1884
1885 static const char *fragShaderText =
1886 "#version 130\n"
1887 "in vec4 color;\n"
1888 "void main() {\n"
1889 " gl_FragColor = color;\n"
1890 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001891 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001892
Tony Barboure2c58df2014-11-25 13:18:32 -07001893 glm::mat4 View = glm::lookAt(
1894 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1895 glm::vec3(0,0,0), // and looks at the origin
1896 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1897 );
1898
1899 glm::mat4 Model = glm::mat4(1.0f);
1900
1901 glm::mat4 MVP = Projection * View * Model;
1902
1903 ASSERT_NO_FATAL_FAILURE(InitState());
1904 ASSERT_NO_FATAL_FAILURE(InitViewport());
1905 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1906
1907 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1908 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1909
1910 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1911
1912 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1913 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1914 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1915
1916 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1917
1918 XglPipelineObj pipelineobj(m_device);
1919 pipelineobj.AddShader(&vs);
1920 pipelineobj.AddShader(&ps);
1921
1922 XglDescriptorSetObj descriptorSet(m_device);
1923 descriptorSet.AttachMemoryView(&MVPBuffer);
1924
1925 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1926 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1927
1928 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1929 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1930 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1931 };
1932
1933 // this is the current description of g_vbData
1934 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1935 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1936 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1937 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1938 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1939 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1940 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1941 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1942 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1943
1944 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1945 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1946 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1947
Tony Barbour1fde6942015-01-09 10:06:53 -07001948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1949 XglCommandBufferObj cmdBuffer(m_device);
1950 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001951
Tony Barbour1fde6942015-01-09 10:06:53 -07001952 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1953 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001954
Tony Barbour1fde6942015-01-09 10:06:53 -07001955 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1956#ifdef DUMP_STATE_DOT
1957 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1958 pDSDumpDot((char*)"triTest2.dot");
1959#endif
1960 // render triangle
1961 cmdBuffer.Draw(0, 36, 0, 1);
1962
1963 // finalize recording of the command buffer
1964 cmdBuffer.EndCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001965 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour1fde6942015-01-09 10:06:53 -07001966
1967 for (int i = 0; i < m_renderTargetCount; i++)
1968 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001969}
1970
Tony Barboure2c58df2014-11-25 13:18:32 -07001971TEST_F(XglRenderTest, VSTexture)
1972{
1973 // The expected result from this test is a green and red triangle;
1974 // one red vertex on the left, two green vertices on the right.
1975 static const char *vertShaderText =
1976 "#version 130\n"
1977 "out vec4 texColor;\n"
1978 "uniform sampler2D surface;\n"
1979 "void main() {\n"
1980 " vec2 vertices[3];"
1981 " vertices[0] = vec2(-0.5, -0.5);\n"
1982 " vertices[1] = vec2( 0.5, -0.5);\n"
1983 " vertices[2] = vec2( 0.5, 0.5);\n"
1984 " vec2 positions[3];"
1985 " positions[0] = vec2( 0.0, 0.0);\n"
1986 " positions[1] = vec2( 0.25, 0.1);\n"
1987 " positions[2] = vec2( 0.1, 0.25);\n"
1988 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1989 " texColor = textureLod(surface, samplePos, 0.0);\n"
1990 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1991 "}\n";
1992
1993 static const char *fragShaderText =
1994 "#version 130\n"
1995 "in vec4 texColor;\n"
1996 "void main() {\n"
1997 " gl_FragColor = texColor;\n"
1998 "}\n";
1999
2000 ASSERT_NO_FATAL_FAILURE(InitState());
2001 ASSERT_NO_FATAL_FAILURE(InitViewport());
2002
2003 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2004 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2005 XglSamplerObj sampler(m_device);
2006 XglTextureObj texture(m_device);
2007
Cody Northropbd531de2014-12-09 19:08:54 -07002008 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002009 vs.BindShaderEntitySlotToSampler(0, &sampler);
2010
2011 XglPipelineObj pipelineobj(m_device);
2012 pipelineobj.AddShader(&vs);
2013 pipelineobj.AddShader(&ps);
2014
2015 XglDescriptorSetObj descriptorSet(m_device);
2016 descriptorSet.AttachImageView(&texture);
2017 descriptorSet.AttachSampler(&sampler);
2018
2019 m_memoryRefManager.AddMemoryRef(&texture);
2020
Tony Barbour664accc2015-01-09 12:55:14 -07002021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2022 XglCommandBufferObj cmdBuffer(m_device);
2023 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002024
Tony Barbour664accc2015-01-09 12:55:14 -07002025 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2026
2027 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2028
2029#ifdef DUMP_STATE_DOT
2030 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2031 pDSDumpDot((char*)"triTest2.dot");
2032#endif
2033 // render triangle
2034 cmdBuffer.Draw(0, 3, 0, 1);
2035
2036 // finalize recording of the command buffer
2037 cmdBuffer.EndCommandBuffer();
2038 cmdBuffer.QueueCommandBuffer(NULL, 0);
2039
2040 for (int i = 0; i < m_renderTargetCount; i++)
2041 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002042}
2043TEST_F(XglRenderTest, TexturedTriangle)
2044{
2045 // The expected result from this test is a red and green checkered triangle
2046 static const char *vertShaderText =
2047 "#version 140\n"
2048 "#extension GL_ARB_separate_shader_objects : enable\n"
2049 "#extension GL_ARB_shading_language_420pack : enable\n"
2050 "layout (location = 0) out vec2 samplePos;\n"
2051 "void main() {\n"
2052 " vec2 vertices[3];"
2053 " vertices[0] = vec2(-0.5, -0.5);\n"
2054 " vertices[1] = vec2( 0.5, -0.5);\n"
2055 " vertices[2] = vec2( 0.5, 0.5);\n"
2056 " vec2 positions[3];"
2057 " positions[0] = vec2( 0.0, 0.0);\n"
2058 " positions[1] = vec2( 1.0, 0.0);\n"
2059 " positions[2] = vec2( 1.0, 1.0);\n"
2060 " samplePos = positions[gl_VertexID % 3];\n"
2061 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2062 "}\n";
2063
2064 static const char *fragShaderText =
2065 "#version 140\n"
2066 "#extension GL_ARB_separate_shader_objects : enable\n"
2067 "#extension GL_ARB_shading_language_420pack : enable\n"
2068 "layout (location = 0) in vec2 samplePos;\n"
2069 "layout (binding = 0) uniform sampler2D surface;\n"
2070 "layout (location=0) out vec4 outColor;\n"
2071 "void main() {\n"
2072 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2073 " outColor = texColor;\n"
2074 "}\n";
2075
2076 ASSERT_NO_FATAL_FAILURE(InitState());
2077 ASSERT_NO_FATAL_FAILURE(InitViewport());
2078
2079 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2080 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2081 XglSamplerObj sampler(m_device);
2082 XglTextureObj texture(m_device);
2083
Cody Northropbd531de2014-12-09 19:08:54 -07002084 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002085 ps.BindShaderEntitySlotToSampler(0, &sampler);
2086
2087 XglPipelineObj pipelineobj(m_device);
2088 pipelineobj.AddShader(&vs);
2089 pipelineobj.AddShader(&ps);
2090
2091 XglDescriptorSetObj descriptorSet(m_device);
2092 descriptorSet.AttachImageView(&texture);
2093 descriptorSet.AttachSampler(&sampler);
2094
2095 m_memoryRefManager.AddMemoryRef(&texture);
2096
Tony Barbour664accc2015-01-09 12:55:14 -07002097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098 XglCommandBufferObj cmdBuffer(m_device);
2099 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2100
2101 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2102
2103 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2104
2105#ifdef DUMP_STATE_DOT
2106 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2107 pDSDumpDot((char*)"triTest2.dot");
2108#endif
2109 // render triangle
2110 cmdBuffer.Draw(0, 3, 0, 1);
2111
2112 // finalize recording of the command buffer
2113 cmdBuffer.EndCommandBuffer();
2114 cmdBuffer.QueueCommandBuffer(NULL, 0);
2115
2116 for (int i = 0; i < m_renderTargetCount; i++)
2117 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002118}
2119TEST_F(XglRenderTest, TexturedTriangleClip)
2120{
2121 // The expected result from this test is a red and green checkered triangle
2122 static const char *vertShaderText =
2123 "#version 330\n"
2124 "#extension GL_ARB_separate_shader_objects : enable\n"
2125 "#extension GL_ARB_shading_language_420pack : enable\n"
2126 "layout (location = 0) out vec2 samplePos;\n"
2127 "out gl_PerVertex {\n"
2128 " vec4 gl_Position;\n"
2129 " float gl_ClipDistance[1];\n"
2130 "};\n"
2131 "void main() {\n"
2132 " vec2 vertices[3];"
2133 " vertices[0] = vec2(-0.5, -0.5);\n"
2134 " vertices[1] = vec2( 0.5, -0.5);\n"
2135 " vertices[2] = vec2( 0.5, 0.5);\n"
2136 " vec2 positions[3];"
2137 " positions[0] = vec2( 0.0, 0.0);\n"
2138 " positions[1] = vec2( 1.0, 0.0);\n"
2139 " positions[2] = vec2( 1.0, 1.0);\n"
2140 " float dists[3];\n"
2141 " dists[0] = 1.0;\n"
2142 " dists[1] = 1.0;\n"
2143 " dists[2] = -1.0;\n"
2144 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2145 " samplePos = positions[gl_VertexID % 3];\n"
2146 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2147 "}\n";
2148
2149 static const char *fragShaderText =
2150 "#version 140\n"
2151 "#extension GL_ARB_separate_shader_objects : enable\n"
2152 "#extension GL_ARB_shading_language_420pack : enable\n"
2153 "layout (location = 0) in vec2 samplePos;\n"
2154 "layout (binding = 0) uniform sampler2D surface;\n"
2155 "layout (location=0) out vec4 outColor;\n"
2156 "void main() {\n"
2157 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2158 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2159 " outColor = texColor;\n"
2160 "}\n";
2161
2162
2163 ASSERT_NO_FATAL_FAILURE(InitState());
2164 ASSERT_NO_FATAL_FAILURE(InitViewport());
2165
2166 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2167 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2168 XglSamplerObj sampler(m_device);
2169 XglTextureObj texture(m_device);
2170
Cody Northropbd531de2014-12-09 19:08:54 -07002171 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002172 ps.BindShaderEntitySlotToSampler(0, &sampler);
2173
2174 XglPipelineObj pipelineobj(m_device);
2175 pipelineobj.AddShader(&vs);
2176 pipelineobj.AddShader(&ps);
2177
2178 XglDescriptorSetObj descriptorSet(m_device);
2179 descriptorSet.AttachImageView(&texture);
2180 descriptorSet.AttachSampler(&sampler);
2181
2182 m_memoryRefManager.AddMemoryRef(&texture);
2183
Tony Barbour664accc2015-01-09 12:55:14 -07002184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2185 XglCommandBufferObj cmdBuffer(m_device);
2186 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2187
2188 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2189
2190 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2191
2192#ifdef DUMP_STATE_DOT
2193 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2194 pDSDumpDot((char*)"triTest2.dot");
2195#endif
2196 // render triangle
2197 cmdBuffer.Draw(0, 3, 0, 1);
2198
2199 // finalize recording of the command buffer
2200 cmdBuffer.EndCommandBuffer();
2201 cmdBuffer.QueueCommandBuffer(NULL, 0);
2202
2203 for (int i = 0; i < m_renderTargetCount; i++)
2204 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002205}
2206TEST_F(XglRenderTest, FSTriangle)
2207{
2208 // The expected result from this test is a red and green checkered triangle
2209 static const char *vertShaderText =
2210 "#version 140\n"
2211 "#extension GL_ARB_separate_shader_objects : enable\n"
2212 "#extension GL_ARB_shading_language_420pack : enable\n"
2213 "layout (location = 0) out vec2 samplePos;\n"
2214 "void main() {\n"
2215 " vec2 vertices[3];"
2216 " vertices[0] = vec2(-0.5, -0.5);\n"
2217 " vertices[1] = vec2( 0.5, -0.5);\n"
2218 " vertices[2] = vec2( 0.5, 0.5);\n"
2219 " vec2 positions[3];"
2220 " positions[0] = vec2( 0.0, 0.0);\n"
2221 " positions[1] = vec2( 1.0, 0.0);\n"
2222 " positions[2] = vec2( 1.0, 1.0);\n"
2223 " samplePos = positions[gl_VertexID % 3];\n"
2224 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2225 "}\n";
2226
2227 static const char *fragShaderText =
2228 "#version 140\n"
2229 "#extension GL_ARB_separate_shader_objects : enable\n"
2230 "#extension GL_ARB_shading_language_420pack : enable\n"
2231 "layout (location = 0) in vec2 samplePos;\n"
2232 "layout (binding = 0) uniform sampler2D surface;\n"
2233 "layout (location=0) out vec4 outColor;\n"
2234 "void main() {\n"
2235 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2236 " outColor = texColor;\n"
2237 "}\n";
2238
2239 ASSERT_NO_FATAL_FAILURE(InitState());
2240 ASSERT_NO_FATAL_FAILURE(InitViewport());
2241
2242 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2243 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2244 XglSamplerObj sampler(m_device);
2245 XglTextureObj texture(m_device);
2246
Cody Northropbd531de2014-12-09 19:08:54 -07002247 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002248 ps.BindShaderEntitySlotToSampler(0, &sampler);
2249
2250 XglPipelineObj pipelineobj(m_device);
2251 pipelineobj.AddShader(&vs);
2252 pipelineobj.AddShader(&ps);
2253
2254 XglDescriptorSetObj descriptorSet(m_device);
2255 descriptorSet.AttachImageView(&texture);
2256 descriptorSet.AttachSampler(&sampler);
2257
2258 m_memoryRefManager.AddMemoryRef(&texture);
2259
Tony Barbour664accc2015-01-09 12:55:14 -07002260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2261 XglCommandBufferObj cmdBuffer(m_device);
2262 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2263
2264 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2265
2266 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2267
2268#ifdef DUMP_STATE_DOT
2269 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2270 pDSDumpDot((char*)"triTest2.dot");
2271#endif
2272 // render triangle
2273 cmdBuffer.Draw(0, 3, 0, 1);
2274
2275 // finalize recording of the command buffer
2276 cmdBuffer.EndCommandBuffer();
2277 cmdBuffer.QueueCommandBuffer(NULL, 0);
2278
2279 for (int i = 0; i < m_renderTargetCount; i++)
2280 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002281}
2282TEST_F(XglRenderTest, SamplerBindingsTriangle)
2283{
2284 // This test sets bindings on the samplers
2285 // For now we are asserting that sampler and texture pairs
2286 // march in lock step, and are set via GLSL binding. This can
2287 // and will probably change.
2288 // The sampler bindings should match the sampler and texture slot
2289 // number set up by the application.
2290 // This test will result in a blue triangle
2291 static const char *vertShaderText =
2292 "#version 140\n"
2293 "#extension GL_ARB_separate_shader_objects : enable\n"
2294 "#extension GL_ARB_shading_language_420pack : enable\n"
2295 "layout (location = 0) out vec4 samplePos;\n"
2296 "void main() {\n"
2297 " vec2 vertices[3];"
2298 " vertices[0] = vec2(-0.5, -0.5);\n"
2299 " vertices[1] = vec2( 0.5, -0.5);\n"
2300 " vertices[2] = vec2( 0.5, 0.5);\n"
2301 " vec2 positions[3];"
2302 " positions[0] = vec2( 0.0, 0.0);\n"
2303 " positions[1] = vec2( 1.0, 0.0);\n"
2304 " positions[2] = vec2( 1.0, 1.0);\n"
2305 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2306 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2307 "}\n";
2308
2309 static const char *fragShaderText =
2310 "#version 140\n"
2311 "#extension GL_ARB_separate_shader_objects : enable\n"
2312 "#extension GL_ARB_shading_language_420pack : enable\n"
2313 "layout (location = 0) in vec4 samplePos;\n"
2314 "layout (binding = 0) uniform sampler2D surface0;\n"
2315 "layout (binding = 1) uniform sampler2D surface1;\n"
2316 "layout (binding = 12) uniform sampler2D surface2;\n"
2317 "void main() {\n"
2318 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2319 "}\n";
2320
2321 ASSERT_NO_FATAL_FAILURE(InitState());
2322 ASSERT_NO_FATAL_FAILURE(InitViewport());
2323
2324 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2325 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2326
2327 XglSamplerObj sampler1(m_device);
2328 XglSamplerObj sampler2(m_device);
2329 XglSamplerObj sampler3(m_device);
2330
2331 XglTextureObj texture1(m_device); // Red
2332 texture1.ChangeColors(0xffff0000,0xffff0000);
2333 XglTextureObj texture2(m_device); // Green
2334 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2335 XglTextureObj texture3(m_device); // Blue
2336 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2337
Cody Northropbd531de2014-12-09 19:08:54 -07002338 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002339 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2340
Cody Northropbd531de2014-12-09 19:08:54 -07002341 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Tony Barboure2c58df2014-11-25 13:18:32 -07002342 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2343
Cody Northropbd531de2014-12-09 19:08:54 -07002344 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002345 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2346
2347 XglPipelineObj pipelineobj(m_device);
2348 pipelineobj.AddShader(&vs);
2349 pipelineobj.AddShader(&ps);
2350
2351 XglDescriptorSetObj descriptorSet(m_device);
2352 descriptorSet.AttachImageView(&texture1);
2353 descriptorSet.AttachSampler(&sampler1);
2354 descriptorSet.AttachImageView(&texture2);
2355 descriptorSet.AttachSampler(&sampler2);
2356 descriptorSet.AttachImageView(&texture3);
2357 descriptorSet.AttachSampler(&sampler3);
2358
2359 m_memoryRefManager.AddMemoryRef(&texture1);
2360 m_memoryRefManager.AddMemoryRef(&texture2);
2361 m_memoryRefManager.AddMemoryRef(&texture3);
2362
Tony Barbour664accc2015-01-09 12:55:14 -07002363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2364 XglCommandBufferObj cmdBuffer(m_device);
2365 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2366
2367 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2368
2369 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2370
2371#ifdef DUMP_STATE_DOT
2372 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2373 pDSDumpDot((char*)"triTest2.dot");
2374#endif
2375 // render triangle
2376 cmdBuffer.Draw(0, 3, 0, 1);
2377
2378 // finalize recording of the command buffer
2379 cmdBuffer.EndCommandBuffer();
2380 cmdBuffer.QueueCommandBuffer(NULL, 0);
2381
2382 for (int i = 0; i < m_renderTargetCount; i++)
2383 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002384
2385}
2386
2387TEST_F(XglRenderTest, TriangleVSUniformBlock)
2388{
2389 // The expected result from this test is a blue triangle
2390
2391 static const char *vertShaderText =
2392 "#version 140\n"
2393 "#extension GL_ARB_separate_shader_objects : enable\n"
2394 "#extension GL_ARB_shading_language_420pack : enable\n"
2395 "layout (location = 0) out vec4 outColor;\n"
2396 "layout (std140, binding = 0) uniform bufferVals {\n"
2397 " vec4 red;\n"
2398 " vec4 green;\n"
2399 " vec4 blue;\n"
2400 " vec4 white;\n"
2401 "} myBufferVals;\n"
2402 "void main() {\n"
2403 " vec2 vertices[3];"
2404 " vertices[0] = vec2(-0.5, -0.5);\n"
2405 " vertices[1] = vec2( 0.5, -0.5);\n"
2406 " vertices[2] = vec2( 0.5, 0.5);\n"
2407 " outColor = myBufferVals.blue;\n"
2408 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2409 "}\n";
2410
2411 static const char *fragShaderText =
2412 "#version 140\n"
2413 "#extension GL_ARB_separate_shader_objects : enable\n"
2414 "#extension GL_ARB_shading_language_420pack : enable\n"
2415 "layout (location = 0) in vec4 inColor;\n"
2416 "void main() {\n"
2417 " gl_FragColor = inColor;\n"
2418 "}\n";
2419
2420 ASSERT_NO_FATAL_FAILURE(InitState());
2421 ASSERT_NO_FATAL_FAILURE(InitViewport());
2422
2423 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2424 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2425
2426 // Let's populate our buffer with the following:
2427 // vec4 red;
2428 // vec4 green;
2429 // vec4 blue;
2430 // vec4 white;
2431 const int valCount = 4 * 4;
2432 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2433 0.0, 1.0, 0.0, 1.0,
2434 0.0, 0.0, 1.0, 1.0,
2435 1.0, 1.0, 1.0, 1.0 };
2436
2437 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
2438 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
2439
2440 XglPipelineObj pipelineobj(m_device);
2441 pipelineobj.AddShader(&vs);
2442 pipelineobj.AddShader(&ps);
2443
2444 XglDescriptorSetObj descriptorSet(m_device);
2445 descriptorSet.AttachMemoryView(&colorBuffer);
2446
Tony Barbour664accc2015-01-09 12:55:14 -07002447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2448 XglCommandBufferObj cmdBuffer(m_device);
2449 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2450
2451 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2452
2453 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2454
2455#ifdef DUMP_STATE_DOT
2456 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2457 pDSDumpDot((char*)"triTest2.dot");
2458#endif
2459 // render triangle
2460 cmdBuffer.Draw(0, 3, 0, 1);
2461
2462 // finalize recording of the command buffer
2463 cmdBuffer.EndCommandBuffer();
2464 cmdBuffer.QueueCommandBuffer(NULL, 0);
2465
2466 for (int i = 0; i < m_renderTargetCount; i++)
2467 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002468
2469}
2470
2471TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2472{
2473 // This test allows the shader to select which buffer it is
2474 // pulling from using layout binding qualifier.
2475 // There are corresponding changes in the compiler stack that
2476 // will select the buffer using binding directly.
2477 // The binding number should match the slot number set up by
2478 // the application.
2479 // The expected result from this test is a purple triangle
2480
2481 static const char *vertShaderText =
2482 "#version 140\n"
2483 "#extension GL_ARB_separate_shader_objects : enable\n"
2484 "#extension GL_ARB_shading_language_420pack : enable\n"
2485 "void main() {\n"
2486 " vec2 vertices[3];"
2487 " vertices[0] = vec2(-0.5, -0.5);\n"
2488 " vertices[1] = vec2( 0.5, -0.5);\n"
2489 " vertices[2] = vec2( 0.5, 0.5);\n"
2490 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2491 "}\n";
2492
2493 static const char *fragShaderText =
2494 "#version 140\n"
2495 "#extension GL_ARB_separate_shader_objects : enable\n"
2496 "#extension GL_ARB_shading_language_420pack : enable\n"
2497 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2498 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2499 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2500 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2501 "void main() {\n"
2502 " gl_FragColor = myBlueVal.color;\n"
2503 " gl_FragColor += myRedVal.color;\n"
2504 "}\n";
2505
2506 ASSERT_NO_FATAL_FAILURE(InitState());
2507 ASSERT_NO_FATAL_FAILURE(InitViewport());
2508
2509 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2510 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2511
2512 // We're going to create a number of uniform buffers, and then allow
2513 // the shader to select which it wants to read from with a binding
2514
2515 // Let's populate the buffers with a single color each:
2516 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2517 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2518 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2519 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2520
2521 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2522 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2523 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2524 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2525
2526 const int redCount = sizeof(redVals) / sizeof(float);
2527 const int greenCount = sizeof(greenVals) / sizeof(float);
2528 const int blueCount = sizeof(blueVals) / sizeof(float);
2529 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2530
2531 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2532 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2533
2534 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2535 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2536
2537 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2538 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2539
2540 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2541 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2542
2543 XglPipelineObj pipelineobj(m_device);
2544 pipelineobj.AddShader(&vs);
2545 pipelineobj.AddShader(&ps);
2546
2547 XglDescriptorSetObj descriptorSet(m_device);
2548 descriptorSet.AttachMemoryView(&redBuffer);
2549 descriptorSet.AttachMemoryView(&greenBuffer);
2550 descriptorSet.AttachMemoryView(&blueBuffer);
2551 descriptorSet.AttachMemoryView(&whiteBuffer);
2552
Tony Barbour664accc2015-01-09 12:55:14 -07002553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2554 XglCommandBufferObj cmdBuffer(m_device);
2555 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002556
Tony Barbour664accc2015-01-09 12:55:14 -07002557 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2558
2559 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2560
2561#ifdef DUMP_STATE_DOT
2562 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2563 pDSDumpDot((char*)"triTest2.dot");
2564#endif
2565 // render triangle
2566 cmdBuffer.Draw(0, 3, 0, 1);
2567
2568 // finalize recording of the command buffer
2569 cmdBuffer.EndCommandBuffer();
2570 cmdBuffer.QueueCommandBuffer(NULL, 0);
2571
2572 for (int i = 0; i < m_renderTargetCount; i++)
2573 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002574}
2575
2576TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2577{
2578 // This test is the same as TriangleFSUniformBlockBinding, but
2579 // it does not provide an instance name.
2580 // The expected result from this test is a purple triangle
2581
2582 static const char *vertShaderText =
2583 "#version 140\n"
2584 "#extension GL_ARB_separate_shader_objects : enable\n"
2585 "#extension GL_ARB_shading_language_420pack : enable\n"
2586 "void main() {\n"
2587 " vec2 vertices[3];"
2588 " vertices[0] = vec2(-0.5, -0.5);\n"
2589 " vertices[1] = vec2( 0.5, -0.5);\n"
2590 " vertices[2] = vec2( 0.5, 0.5);\n"
2591 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2592 "}\n";
2593
2594 static const char *fragShaderText =
2595 "#version 430\n"
2596 "#extension GL_ARB_separate_shader_objects : enable\n"
2597 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002598 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2599 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2600 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2601 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002602 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002603 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002604 " outColor = blue;\n"
2605 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002606 "}\n";
2607 ASSERT_NO_FATAL_FAILURE(InitState());
2608 ASSERT_NO_FATAL_FAILURE(InitViewport());
2609
2610 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2611 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2612
2613 // We're going to create a number of uniform buffers, and then allow
2614 // the shader to select which it wants to read from with a binding
2615
2616 // Let's populate the buffers with a single color each:
2617 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2618 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2619 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2620 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2621
2622 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2623 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2624 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2625 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2626
2627 const int redCount = sizeof(redVals) / sizeof(float);
2628 const int greenCount = sizeof(greenVals) / sizeof(float);
2629 const int blueCount = sizeof(blueVals) / sizeof(float);
2630 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2631
2632 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2633 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2634
2635 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2636 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2637
2638 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2639 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2640
2641 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002642 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002643
2644 XglPipelineObj pipelineobj(m_device);
2645 pipelineobj.AddShader(&vs);
2646 pipelineobj.AddShader(&ps);
2647
2648 XglDescriptorSetObj descriptorSet(m_device);
2649 descriptorSet.AttachMemoryView(&redBuffer);
2650 descriptorSet.AttachMemoryView(&greenBuffer);
2651 descriptorSet.AttachMemoryView(&blueBuffer);
2652 descriptorSet.AttachMemoryView(&whiteBuffer);
2653
Tony Barbour664accc2015-01-09 12:55:14 -07002654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2655 XglCommandBufferObj cmdBuffer(m_device);
2656 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2657
2658 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2659
2660 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2661
2662#ifdef DUMP_STATE_DOT
2663 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2664 pDSDumpDot((char*)"triTest2.dot");
2665#endif
2666 // render triangle
2667 cmdBuffer.Draw(0, 3, 0, 1);
2668
2669 // finalize recording of the command buffer
2670 cmdBuffer.EndCommandBuffer();
2671 cmdBuffer.QueueCommandBuffer(NULL, 0);
2672
2673 for (int i = 0; i < m_renderTargetCount; i++)
2674 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002675
2676}
2677
2678TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2679{
2680 static const char *vertShaderText =
2681 "#version 140\n"
2682 "#extension GL_ARB_separate_shader_objects : enable\n"
2683 "#extension GL_ARB_shading_language_420pack : enable\n"
2684 "layout (std140, binding=0) uniform bufferVals {\n"
2685 " mat4 mvp;\n"
2686 "} myBufferVals;\n"
2687 "layout (location=0) in vec4 pos;\n"
2688 "layout (location=0) out vec2 UV;\n"
2689 "void main() {\n"
2690 " vec2 positions[3];"
2691 " positions[0] = vec2( 0.0, 0.0);\n"
2692 " positions[1] = vec2( 0.25, 0.1);\n"
2693 " positions[2] = vec2( 0.1, 0.25);\n"
2694 " UV = positions[gl_VertexID % 3];\n"
2695 " gl_Position = myBufferVals.mvp * pos;\n"
2696 "}\n";
2697
2698 static const char *fragShaderText =
2699 "#version 140\n"
2700 "#extension GL_ARB_separate_shader_objects : enable\n"
2701 "#extension GL_ARB_shading_language_420pack : enable\n"
2702 "layout (binding=0) uniform sampler2D surface;\n"
2703 "layout (location=0) out vec4 outColor;\n"
2704 "layout (location=0) in vec2 UV;\n"
2705 "void main() {\n"
2706 " outColor= textureLod(surface, UV, 0.0);\n"
2707 "}\n";
2708 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2709
2710 glm::mat4 View = glm::lookAt(
2711 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2712 glm::vec3(0,0,0), // and looks at the origin
2713 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2714 );
2715
2716 glm::mat4 Model = glm::mat4(1.0f);
2717
2718 glm::mat4 MVP = Projection * View * Model;
2719
2720
2721 ASSERT_NO_FATAL_FAILURE(InitState());
2722 ASSERT_NO_FATAL_FAILURE(InitViewport());
2723 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2724
2725 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2726 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Tony Barbour099a9eb2014-12-10 17:40:15 -07002727 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barboure2c58df2014-11-25 13:18:32 -07002728
2729
2730 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2731
2732 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2733 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2734 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2735 XglSamplerObj sampler(m_device);
2736 XglTextureObj texture(m_device);
2737
2738 // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2739 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002740 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002741 ps.BindShaderEntitySlotToSampler(0, &sampler);
2742
2743 XglPipelineObj pipelineobj(m_device);
2744 pipelineobj.AddShader(&vs);
2745 pipelineobj.AddShader(&ps);
2746
2747 XglDescriptorSetObj descriptorSet(m_device);
2748
2749 descriptorSet.AttachMemoryView(&mvpBuffer);
2750 descriptorSet.AttachImageView(&texture);
2751 descriptorSet.AttachSampler(&sampler);
2752
2753 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2754 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2755 m_memoryRefManager.AddMemoryRef(&texture);
2756
2757 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2758 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2759 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2760 };
2761
2762 // this is the current description of g_vbData
2763 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2764 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2765 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2766 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2767 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2768 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2769 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2770 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2771 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2772
2773 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2774 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2775 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2776
Tony Barbour664accc2015-01-09 12:55:14 -07002777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2778 XglCommandBufferObj cmdBuffer(m_device);
2779 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002780
Tony Barbour664accc2015-01-09 12:55:14 -07002781 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2782 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2783
2784 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2785#ifdef DUMP_STATE_DOT
2786 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2787 pDSDumpDot((char*)"triTest2.dot");
2788#endif
2789 // render triangle
2790 cmdBuffer.Draw(0, 36, 0, 1);
2791
2792 // finalize recording of the command buffer
2793 cmdBuffer.EndCommandBuffer();
2794 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2795
2796 for (int i = 0; i < m_renderTargetCount; i++)
2797 RecordImage(m_renderTargets[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002798
2799}
Cody Northropf1990a92014-12-09 11:17:01 -07002800
2801TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2802{
2803 // This test mixes binding slots of textures and buffers, ensuring
2804 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002805 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002806 // you can modify it to move the desired result around.
2807
2808 static const char *vertShaderText =
2809 "#version 140\n"
2810 "#extension GL_ARB_separate_shader_objects : enable\n"
2811 "#extension GL_ARB_shading_language_420pack : enable\n"
2812 "void main() {\n"
2813 " vec2 vertices[3];"
2814 " vertices[0] = vec2(-0.5, -0.5);\n"
2815 " vertices[1] = vec2( 0.5, -0.5);\n"
2816 " vertices[2] = vec2( 0.5, 0.5);\n"
2817 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2818 "}\n";
2819
2820 static const char *fragShaderText =
2821 "#version 430\n"
2822 "#extension GL_ARB_separate_shader_objects : enable\n"
2823 "#extension GL_ARB_shading_language_420pack : enable\n"
2824 "layout (binding = 0) uniform sampler2D surface0;\n"
Courtney Goeltzenleuchterc97ceea2014-12-11 09:03:03 -07002825 "layout (binding = 9) uniform sampler2D surface1;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002826 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002827 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002828
Cody Northropb110b4f2014-12-09 13:59:39 -07002829
2830 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2831 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2832 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2833 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002834 "layout (location = 0) out vec4 outColor;\n"
2835 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002836 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002837 " outColor += white * vec4(0.00001);\n"
2838 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002839 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002840 "}\n";
2841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 ASSERT_NO_FATAL_FAILURE(InitViewport());
2843
2844 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2845 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2846
Cody Northropf1990a92014-12-09 11:17:01 -07002847 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2848 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2849 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2850 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2851
2852 const int redCount = sizeof(redVals) / sizeof(float);
2853 const int greenCount = sizeof(greenVals) / sizeof(float);
2854 const int blueCount = sizeof(blueVals) / sizeof(float);
2855 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2856
2857 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002858 ps.BindShaderEntitySlotToMemory(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002859
2860 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002861 ps.BindShaderEntitySlotToMemory(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002862
2863 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002864 ps.BindShaderEntitySlotToMemory(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002865
2866 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropb110b4f2014-12-09 13:59:39 -07002867 ps.BindShaderEntitySlotToMemory(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002868
2869 XglSamplerObj sampler0(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002870 XglTextureObj texture0(m_device); // Light Red
2871 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropbd531de2014-12-09 19:08:54 -07002872 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
Cody Northropf1990a92014-12-09 11:17:01 -07002873 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2874 XglSamplerObj sampler2(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002875 XglTextureObj texture2(m_device); // Light Blue
2876 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropbd531de2014-12-09 19:08:54 -07002877 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Cody Northropf1990a92014-12-09 11:17:01 -07002878 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2879 XglSamplerObj sampler4(m_device);
Cody Northropb110b4f2014-12-09 13:59:39 -07002880 XglTextureObj texture4(m_device); // Light Green
2881 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropbd531de2014-12-09 19:08:54 -07002882 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
Cody Northropf1990a92014-12-09 11:17:01 -07002883 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002884
2885 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2886 // TODO: Get back here ASAP and understand why.
2887 XglSamplerObj sampler7(m_device);
2888 XglTextureObj texture7(m_device); // Red and Blue
2889 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Courtney Goeltzenleuchterc97ceea2014-12-11 09:03:03 -07002890 ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2891 ps.BindShaderEntitySlotToSampler(9, &sampler7);
Cody Northropf1990a92014-12-09 11:17:01 -07002892
2893
2894 XglPipelineObj pipelineobj(m_device);
2895 pipelineobj.AddShader(&vs);
2896 pipelineobj.AddShader(&ps);
2897
2898 XglDescriptorSetObj descriptorSet(m_device);
2899 descriptorSet.AttachMemoryView(&redBuffer);
2900 descriptorSet.AttachMemoryView(&greenBuffer);
2901 descriptorSet.AttachMemoryView(&blueBuffer);
2902 descriptorSet.AttachMemoryView(&whiteBuffer);
2903 descriptorSet.AttachImageView(&texture0);
2904 descriptorSet.AttachSampler(&sampler0);
2905 descriptorSet.AttachImageView(&texture2);
2906 descriptorSet.AttachSampler(&sampler2);
2907 descriptorSet.AttachImageView(&texture4);
2908 descriptorSet.AttachSampler(&sampler4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002909 descriptorSet.AttachImageView(&texture7);
2910 descriptorSet.AttachSampler(&sampler7);
Cody Northropf1990a92014-12-09 11:17:01 -07002911
2912 m_memoryRefManager.AddMemoryRef(&texture0);
2913 m_memoryRefManager.AddMemoryRef(&texture2);
2914 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropb110b4f2014-12-09 13:59:39 -07002915 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropf1990a92014-12-09 11:17:01 -07002916
Tony Barbour664accc2015-01-09 12:55:14 -07002917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2918 XglCommandBufferObj cmdBuffer(m_device);
2919 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropf1990a92014-12-09 11:17:01 -07002920
Tony Barbour664accc2015-01-09 12:55:14 -07002921 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2922
2923 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2924
2925#ifdef DUMP_STATE_DOT
2926 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2927 pDSDumpDot((char*)"triTest2.dot");
2928#endif
2929 // render triangle
2930 cmdBuffer.Draw(0, 3, 0, 1);
2931
2932 // finalize recording of the command buffer
2933 cmdBuffer.EndCommandBuffer();
2934 cmdBuffer.QueueCommandBuffer(NULL, 0);
2935
2936 for (int i = 0; i < m_renderTargetCount; i++)
2937 RecordImage(m_renderTargets[i]);
Cody Northropf1990a92014-12-09 11:17:01 -07002938
2939}
2940
Cody Northropbd531de2014-12-09 19:08:54 -07002941TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2942{
2943 // This test matches binding slots of textures and buffers, requiring
2944 // the driver to give them distinct number spaces.
2945 // The expected result from this test is a red triangle, although
2946 // you can modify it to move the desired result around.
2947
2948 static const char *vertShaderText =
2949 "#version 140\n"
2950 "#extension GL_ARB_separate_shader_objects : enable\n"
2951 "#extension GL_ARB_shading_language_420pack : enable\n"
2952 "void main() {\n"
2953 " vec2 vertices[3];"
2954 " vertices[0] = vec2(-0.5, -0.5);\n"
2955 " vertices[1] = vec2( 0.5, -0.5);\n"
2956 " vertices[2] = vec2( 0.5, 0.5);\n"
2957 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2958 "}\n";
2959
2960 static const char *fragShaderText =
2961 "#version 430\n"
2962 "#extension GL_ARB_separate_shader_objects : enable\n"
2963 "#extension GL_ARB_shading_language_420pack : enable\n"
2964 "layout (binding = 0) uniform sampler2D surface0;\n"
2965 "layout (binding = 1) uniform sampler2D surface1;\n"
2966 "layout (binding = 2) uniform sampler2D surface2;\n"
2967 "layout (binding = 3) uniform sampler2D surface3;\n"
2968 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2969 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2970 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2971 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2972 "layout (location = 0) out vec4 outColor;\n"
2973 "void main() {\n"
2974 " outColor = red;// * vec4(0.00001);\n"
2975 " outColor += white * vec4(0.00001);\n"
2976 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2977 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2978 "}\n";
2979 ASSERT_NO_FATAL_FAILURE(InitState());
2980 ASSERT_NO_FATAL_FAILURE(InitViewport());
2981
2982 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2983 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2984
2985 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2986 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2987 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2988 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2989
2990 const int redCount = sizeof(redVals) / sizeof(float);
2991 const int greenCount = sizeof(greenVals) / sizeof(float);
2992 const int blueCount = sizeof(blueVals) / sizeof(float);
2993 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2994
2995 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2996 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2997
2998 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2999 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
3000
3001 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3002 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
3003
3004 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
3005 ps.BindShaderEntitySlotToMemory(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
3006
3007 XglSamplerObj sampler0(m_device);
3008 XglTextureObj texture0(m_device); // Light Red
3009 texture0.ChangeColors(0xff800000,0xff800000);
3010 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
3011 ps.BindShaderEntitySlotToSampler(0, &sampler0);
3012 XglSamplerObj sampler2(m_device);
3013 XglTextureObj texture2(m_device); // Light Blue
3014 texture2.ChangeColors(0xff000080,0xff000080);
3015 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
3016 ps.BindShaderEntitySlotToSampler(1, &sampler2);
3017 XglSamplerObj sampler4(m_device);
3018 XglTextureObj texture4(m_device); // Light Green
3019 texture4.ChangeColors(0xff008000,0xff008000);
3020 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
3021 ps.BindShaderEntitySlotToSampler(2, &sampler4);
3022 XglSamplerObj sampler7(m_device);
3023 XglTextureObj texture7(m_device); // Red and Blue
3024 texture7.ChangeColors(0xffff00ff,0xffff00ff);
3025 ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
3026 ps.BindShaderEntitySlotToSampler(3, &sampler7);
3027
3028
3029 XglPipelineObj pipelineobj(m_device);
3030 pipelineobj.AddShader(&vs);
3031 pipelineobj.AddShader(&ps);
3032
3033 XglDescriptorSetObj descriptorSet(m_device);
3034 descriptorSet.AttachMemoryView(&redBuffer);
3035 descriptorSet.AttachMemoryView(&greenBuffer);
3036 descriptorSet.AttachMemoryView(&blueBuffer);
3037 descriptorSet.AttachMemoryView(&whiteBuffer);
3038 descriptorSet.AttachImageView(&texture0);
3039 descriptorSet.AttachSampler(&sampler0);
3040 descriptorSet.AttachImageView(&texture2);
3041 descriptorSet.AttachSampler(&sampler2);
3042 descriptorSet.AttachImageView(&texture4);
3043 descriptorSet.AttachSampler(&sampler4);
3044 descriptorSet.AttachImageView(&texture7);
3045 descriptorSet.AttachSampler(&sampler7);
3046
3047 m_memoryRefManager.AddMemoryRef(&texture0);
3048 m_memoryRefManager.AddMemoryRef(&texture2);
3049 m_memoryRefManager.AddMemoryRef(&texture4);
3050 m_memoryRefManager.AddMemoryRef(&texture7);
3051
Tony Barbour664accc2015-01-09 12:55:14 -07003052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3053 XglCommandBufferObj cmdBuffer(m_device);
3054 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropbd531de2014-12-09 19:08:54 -07003055
Tony Barbour664accc2015-01-09 12:55:14 -07003056 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
3057
3058 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3059
3060#ifdef DUMP_STATE_DOT
3061 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3062 pDSDumpDot((char*)"triTest2.dot");
3063#endif
3064 // render triangle
3065 cmdBuffer.Draw(0, 3, 0, 1);
3066
3067 // finalize recording of the command buffer
3068 cmdBuffer.EndCommandBuffer();
3069 cmdBuffer.QueueCommandBuffer(NULL, 0);
3070
3071 for (int i = 0; i < m_renderTargetCount; i++)
3072 RecordImage(m_renderTargets[i]);
Cody Northropbd531de2014-12-09 19:08:54 -07003073
3074}
3075
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003076int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003077 int result;
3078
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003079 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003080 XglTestFramework::InitArgs(&argc, argv);
3081
Chia-I Wu6f184292014-12-15 23:57:34 +08003082 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06003083
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003084 result = RUN_ALL_TESTS();
3085
3086 XglTestFramework::Finish();
3087 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003088}