blob: 431fb471ce4bb3bb8e1e5de6522541b69766b985 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Chia-I Wu4115c892014-08-28 11:56:29 +080075#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
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 Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
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 Goeltzenleuchterd0556292014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600214public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600215
Tony Barbourf43b6982014-11-25 13:18:32 -0700216 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
217 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700218 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
219 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour09da2212014-12-03 16:13:23 -0700220 XglConstantBufferObj *constantBuffer);
Tony Barboura3953b82014-12-03 15:46:29 -0700221 void GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet, int numTris);
Tony Barbour02472db2015-01-08 17:08:28 -0700222 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -0700223 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
224
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600225 void InitDepthStencil();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600226 void GenerateClearAndPrepareBufferCmds();
Tony Barbour71ba3612015-01-09 16:12:35 -0700227 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const int rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600228
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600229
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600230protected:
Cody Northrop350727b2014-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 Goeltzenleuchterd0556292014-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 Barbourf43b6982014-11-25 13:18:32 -0700242 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600243
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244
245 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600246
247 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
248 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800249 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600250 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800251 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600252 this->app_info.engineVersion = 1;
253 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
254
Cody Northrop350727b2014-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 Barbour97a36232014-12-04 17:14:45 -0700257 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600258
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600259 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600260 }
261
262 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600263 // Clean up resources before we reset
264 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600265 }
266};
267
Tony Barbour02472db2015-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 Barbourf43b6982014-11-25 13:18:32 -0700282
Tony Barboura3953b82014-12-03 15:46:29 -0700283void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600284{
285 XGL_RESULT err = XGL_SUCCESS;
286
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600288 // Build command buffer
289 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
290 ASSERT_XGL_SUCCESS(err);
291
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600292 GenerateClearAndPrepareBufferCmds();
293 GenerateBindRenderTargetCmd();
Tobin Ehlis266473d2014-12-16 17:34:50 -0700294
Tony Barbourf43b6982014-11-25 13:18:32 -0700295 GenerateBindStateAndPipelineCmds();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600296
Tony Barboura3953b82014-12-03 15:46:29 -0700297 pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet);
Tony Barbourbf678472014-12-03 13:58:15 -0700298 descriptorSet->BindCommandBuffer(m_cmdBuffer);
Tobin Ehlis266473d2014-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 Barbourf43b6982014-11-25 13:18:32 -0700305 // render the triangle
306 xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600307
308 // finalize recording of the command buffer
309 err = xglEndCommandBuffer( m_cmdBuffer );
310 ASSERT_XGL_SUCCESS( err );
Tony Barbourf43b6982014-11-25 13:18:32 -0700311}
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600312
Tony Barbourf43b6982014-11-25 13:18:32 -0700313void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
314{
315 XGL_RESULT err = XGL_SUCCESS;
Chia-I Wue7748802014-12-05 10:45:15 +0800316 XGL_UINT i;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600317
318 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700319 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600320 ASSERT_XGL_SUCCESS( err );
321
Chia-I Wuf34ac502014-08-27 14:58:05 +0800322 err = xglQueueWaitIdle( m_device->m_queue );
323 ASSERT_XGL_SUCCESS( err );
324
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600325 // Wait for work to finish before cleaning up.
326 xglDeviceWaitIdle(m_device->device());
327
Chia-I Wue7748802014-12-05 10:45:15 +0800328 for (i = 0; i < m_renderTargetCount; i++)
329 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600330}
331
Tony Barbourf43b6982014-11-25 13:18:32 -0700332void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600333{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600334 XGL_RESULT err;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600335
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600336 ASSERT_NO_FATAL_FAILURE(InitState());
337 ASSERT_NO_FATAL_FAILURE(InitViewport());
338
Tony Barbourf43b6982014-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 Northrop0dbe84f2014-10-09 19:55:56 -0600341
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600342
Tony Barbourf43b6982014-11-25 13:18:32 -0700343 XglPipelineObj pipelineobj(m_device);
344 pipelineobj.AddShader(&vs);
345 pipelineobj.AddShader(&ps);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600346
347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
348
Tony Barbourf43b6982014-11-25 13:18:32 -0700349 // Create descriptor set
350 XglDescriptorSetObj descriptorSet(m_device);
Cody Northrop0dbe84f2014-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 Barbourf43b6982014-11-25 13:18:32 -0700358 GenerateBindStateAndPipelineCmds();
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600359
Tobin Ehlis266473d2014-12-16 17:34:50 -0700360 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
361 descriptorSet.BindCommandBuffer(m_cmdBuffer);
Tobin Ehlis31446e52014-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 Barbourf43b6982014-11-25 13:18:32 -0700366 // render the triangle
367 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
Cody Northrop0dbe84f2014-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 Northrop0dbe84f2014-10-09 19:55:56 -0600373 // submit the command buffer to the universal queue
Tony Barbour75420772014-12-04 17:17:26 -0700374 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL );
Cody Northrop0dbe84f2014-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 Wue7748802014-12-05 10:45:15 +0800383 assert(m_renderTargetCount == 1);
384 RecordImage(m_renderTargets[0]);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600385
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600386}
387
Tony Barbourf43b6982014-11-25 13:18:32 -0700388void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-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 Barbour09da2212014-12-03 16:13:23 -0700422 XglConstantBufferObj *constantBuffer)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600423{
424 int i;
425 glm::mat4 MVP;
426 int matrixSize = sizeof(MVP);
427 XGL_RESULT err;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600428
429 for (i = 0; i < 8; i++) {
Chia-I Wu67ee00f2014-12-28 15:26:08 +0800430 void *pData = constantBuffer->map();
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600431
Courtney Goeltzenleuchter7bbb4202014-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 Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600434 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
435
Chia-I Wu67ee00f2014-12-28 15:26:08 +0800436 constantBuffer->unmap();
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600437
438 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700439 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
Courtney Goeltzenleuchter3c601d82014-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 Wue7748802014-12-05 10:45:15 +0800448 assert(m_renderTargetCount == 1);
449 RecordImage(m_renderTargets[0]);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600450 }
Cody Northrop7a1f0462014-10-10 14:49:36 -0600451}
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600452void dumpMatrix(const char *note, glm::mat4 MVP)
453{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800454 int i;
Courtney Goeltzenleuchterd0556292014-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 Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600472void XglRenderTest::GenerateClearAndPrepareBufferCmds()
473{
474 XglRenderFramework::GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600475
Tony Barbour97a36232014-12-04 17:14:45 -0700476 if (m_depthStencilImage) {
Tony Barbour97a36232014-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 Northrop7a1f0462014-10-10 14:49:36 -0600483
Tony Barbour97a36232014-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 Goeltzenleuchterd0556292014-10-20 16:33:15 -0600492
Tony Barbour97a36232014-12-04 17:14:45 -0700493 xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600494
Tony Barbour97a36232014-12-04 17:14:45 -0700495 // prepare depth buffer for rendering
496 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wu18749b02014-12-05 10:48:20 +0800497 transitionToRender.image = m_depthStencilImage;
Tony Barbour97a36232014-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 Goeltzenleuchterd0556292014-10-20 16:33:15 -0600504}
505
Courtney Goeltzenleuchterd0556292014-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 Ashburn6317c492014-11-21 11:33:20 -0700513 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchterd0556292014-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 Goeltzenleuchter7bbb4202014-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
Tony Barbour71ba3612015-01-09 16:12:35 -0700610void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const int rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600611{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700612#ifdef DEBUG_CALLBACK
613 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
614#endif
Courtney Goeltzenleuchter7bbb4202014-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 Barbourf43b6982014-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 Barbour71ba3612015-01-09 16:12:35 -0700662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
663 XglCommandBufferObj cmdBuffer(m_device);
664 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700665
Tony Barbour71ba3612015-01-09 16:12:35 -0700666 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
667
668 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
669
670 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
671#ifdef DUMP_STATE_DOT
672 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
673 pDSDumpDot((char*)"triTest2.dot");
674#endif
675 // render triangle
676 cmdBuffer.Draw(0, 3, 0, 1);
677
678 // finalize recording of the command buffer
679 cmdBuffer.EndCommandBuffer();
680 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
681
682 for (int i = 0; i < m_renderTargetCount; i++)
683 RecordImage(m_renderTargets[i]);
684
685 if (rotate)
686 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
687
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700688#ifdef PRINT_OBJECTS
689 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
690 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
691 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
692 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
693 printf("DEBUG : Number of Objects : %lu\n", numObjects);
694 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
695 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
696 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
697 for (i=0; i < numObjects; i++) {
698 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);
699 }
700 free(pObjNodeArray);
701#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700702
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600703}
704
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600705TEST_F(XglRenderTest, XGLTriangle_FragColor)
706{
707 static const char *vertShaderText =
708 "#version 140\n"
709 "#extension GL_ARB_separate_shader_objects : enable\n"
710 "#extension GL_ARB_shading_language_420pack : enable\n"
711 "\n"
712 "layout(binding = 0) uniform buf {\n"
713 " mat4 MVP;\n"
714 " vec4 position[3];\n"
715 " vec4 color[3];\n"
716 "} ubuf;\n"
717 "\n"
718 "layout (location = 0) out vec4 outColor;\n"
719 "\n"
720 "void main() \n"
721 "{\n"
722 " outColor = ubuf.color[gl_VertexID];\n"
723 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
724 "}\n";
725
726 static const char *fragShaderText =
727 "#version 140\n"
728 "#extension GL_ARB_separate_shader_objects : enable\n"
729 "#extension GL_ARB_shading_language_420pack : enable\n"
730 "\n"
731 "layout (location = 0) in vec4 inColor;\n"
732 "\n"
733 "void main()\n"
734 "{\n"
735 " gl_FragColor = inColor;\n"
736 "}\n";
737
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600738 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbour71ba3612015-01-09 16:12:35 -0700739 XGLTriangleTest(vertShaderText, fragShaderText, 1);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600740}
741
742TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
743{
744 static const char *vertShaderText =
745 "#version 140\n"
746 "#extension GL_ARB_separate_shader_objects : enable\n"
747 "#extension GL_ARB_shading_language_420pack : enable\n"
748 "\n"
749 "layout(binding = 0) uniform buf {\n"
750 " mat4 MVP;\n"
751 " vec4 position[3];\n"
752 " vec4 color[3];\n"
753 "} ubuf;\n"
754 "\n"
755 "layout (location = 0) out vec4 outColor;\n"
756 "\n"
757 "void main() \n"
758 "{\n"
759 " outColor = ubuf.color[gl_VertexID];\n"
760 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
761 "}\n";
762
763 static const char *fragShaderText =
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 (location = 0) in vec4 inColor;\n"
769 "layout (location = 0) out vec4 outColor;\n"
770 "\n"
771 "void main()\n"
772 "{\n"
773 " outColor = inColor;\n"
774 "}\n";
775
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600776 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600777
Tony Barbour71ba3612015-01-09 16:12:35 -0700778 XGLTriangleTest(vertShaderText, fragShaderText, 1);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600779}
780
Tony Barbourf43b6982014-11-25 13:18:32 -0700781TEST_F(XglRenderTest, BIL_XGLTriangle)
782{
783 bool saved_use_bil = XglTestFramework::m_use_bil;
784
785 static const char *vertShaderText =
786 "#version 140\n"
787 "#extension GL_ARB_separate_shader_objects : enable\n"
788 "#extension GL_ARB_shading_language_420pack : enable\n"
789 "\n"
790 "layout(binding = 0) uniform buf {\n"
791 " mat4 MVP;\n"
792 " vec4 position[3];\n"
793 " vec4 color[3];\n"
794 "} ubuf;\n"
795 "\n"
796 "layout (location = 0) out vec4 outColor;\n"
797 "\n"
798 "void main() \n"
799 "{\n"
800 " outColor = ubuf.color[gl_VertexID];\n"
801 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
802 "}\n";
803
804 static const char *fragShaderText =
805 "#version 140\n"
806 "#extension GL_ARB_separate_shader_objects : enable\n"
807 "#extension GL_ARB_shading_language_420pack : enable\n"
808 "\n"
809 "layout (location = 0) in vec4 inColor;\n"
810 "\n"
811 "void main()\n"
812 "{\n"
813 " gl_FragColor = inColor;\n"
814 "}\n";
815
816 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
817
818 XglTestFramework::m_use_bil = true;
819
Tony Barbour71ba3612015-01-09 16:12:35 -0700820 XGLTriangleTest(vertShaderText, fragShaderText, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700821
822 XglTestFramework::m_use_bil = saved_use_bil;
823}
824
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600825TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600826{
827 static const char *vertShaderText =
828 "#version 130\n"
829 "vec2 vertices[3];\n"
830 "void main() {\n"
831 " vertices[0] = vec2(-1.0, -1.0);\n"
832 " vertices[1] = vec2( 1.0, -1.0);\n"
833 " vertices[2] = vec2( 0.0, 1.0);\n"
834 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
835 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600836
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600837 static const char *fragShaderText =
838 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600839 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600840 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600841 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600842
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600843 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
844
Tony Barbour71ba3612015-01-09 16:12:35 -0700845 XGLTriangleTest(vertShaderText, fragShaderText, 0);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600846}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600847
Tony Barbourf43b6982014-11-25 13:18:32 -0700848TEST_F(XglRenderTest, BIL_GreenTriangle)
849{
850 bool saved_use_bil = XglTestFramework::m_use_bil;
851
852 static const char *vertShaderText =
853 "#version 130\n"
854 "vec2 vertices[3];\n"
855 "void main() {\n"
856 " vertices[0] = vec2(-1.0, -1.0);\n"
857 " vertices[1] = vec2( 1.0, -1.0);\n"
858 " vertices[2] = vec2( 0.0, 1.0);\n"
859 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
860 "}\n";
861
862 static const char *fragShaderText =
863 "#version 130\n"
864 "void main() {\n"
865 " gl_FragColor = vec4(0,1,0,1);\n"
866 "}\n";
867
868 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
869
870 XglTestFramework::m_use_bil = true;
Tony Barbour71ba3612015-01-09 16:12:35 -0700871 XGLTriangleTest(vertShaderText, fragShaderText, 0);
Tony Barbourf43b6982014-11-25 13:18:32 -0700872 XglTestFramework::m_use_bil = saved_use_bil;
873}
874
875TEST_F(XglRenderTest, YellowTriangle)
876{
877 static const char *vertShaderText =
878 "#version 130\n"
879 "void main() {\n"
880 " vec2 vertices[3];"
881 " vertices[0] = vec2(-0.5, -0.5);\n"
882 " vertices[1] = vec2( 0.5, -0.5);\n"
883 " vertices[2] = vec2( 0.5, 0.5);\n"
884 " vec4 colors[3];\n"
885 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
886 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
887 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
888 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
889 "}\n";
890
891 static const char *fragShaderText =
892 "#version 130\n"
893 "void main() {\n"
894 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
895 "}\n";
896
Tony Barbour71ba3612015-01-09 16:12:35 -0700897 XGLTriangleTest(vertShaderText, fragShaderText, 0);
Tony Barbourf43b6982014-11-25 13:18:32 -0700898}
899
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600900TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600901{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600902 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700903 "#version 130\n"
904 //XYZ1( -1, -1, -1 )
905 "in vec4 pos;\n"
906 //XYZ1( 0.f, 0.f, 0.f )
907 "in vec4 inColor;\n"
908 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600909 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600910 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600911 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600912 "}\n";
913
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600914
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600915 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700916 "#version 140\n"
917 "#extension GL_ARB_separate_shader_objects : enable\n"
918 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700919 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700920 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600921 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700922 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600923 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600924
Tony Barbourf43b6982014-11-25 13:18:32 -0700925
926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928 ASSERT_NO_FATAL_FAILURE(InitViewport());
929
930 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -0700931 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -0700932
933 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
934 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
935
936 XglPipelineObj pipelineobj(m_device);
937 pipelineobj.AddShader(&vs);
938 pipelineobj.AddShader(&ps);
939
940 XglDescriptorSetObj descriptorSet(m_device);
941 descriptorSet.AttachMemoryView(&meshBuffer);
942
943 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
944 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
945 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
946 };
947
948 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
949 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
950 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
951 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
952 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
953 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
954 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
955 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
956 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
957
958 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
959 pipelineobj.AddVertexInputBindings(&vi_binding,1);
960 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
961
Tony Barboure4ed9942015-01-09 10:06:53 -0700962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
963 XglCommandBufferObj cmdBuffer(m_device);
964 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700965
Tony Barboure4ed9942015-01-09 10:06:53 -0700966 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
967 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
968
Tony Barboure4ed9942015-01-09 10:06:53 -0700969 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
970
971 // render two triangles
972 cmdBuffer.Draw(0, 6, 0, 1);
973
974 // finalize recording of the command buffer
975 cmdBuffer.EndCommandBuffer();
976 cmdBuffer.QueueCommandBuffer(NULL, 0);
977
978 for (int i = 0; i < m_renderTargetCount; i++)
979 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600980}
981
Chia-I Wue09d1a72014-12-05 10:32:23 +0800982TEST_F(XglRenderTest, TriangleMRT)
983{
984 static const char *vertShaderText =
985 "#version 130\n"
986 "in vec4 pos;\n"
987 "void main() {\n"
988 " gl_Position = pos;\n"
989 "}\n";
990
991 static const char *fragShaderText =
992 "#version 130\n"
993 "void main() {\n"
994 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
995 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
996 "}\n";
997 const XGL_FLOAT vb_data[][2] = {
998 { -1.0f, -1.0f },
999 { 1.0f, -1.0f },
1000 { -1.0f, 1.0f }
1001 };
1002
1003 ASSERT_NO_FATAL_FAILURE(InitState());
1004 ASSERT_NO_FATAL_FAILURE(InitViewport());
1005
1006 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Tony Barboure6152042014-12-10 17:40:15 -07001007 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Chia-I Wue09d1a72014-12-05 10:32:23 +08001008
1009 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1010 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1011
1012 XglPipelineObj pipelineobj(m_device);
1013 pipelineobj.AddShader(&vs);
1014 pipelineobj.AddShader(&ps);
1015
1016 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1017 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1018 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1019 };
1020
1021 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
1022 vi_attrib.binding = 0; // index into vertexBindingDescriptions
1023 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
1024 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
1025 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1026
1027 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
1028 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1029 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1030
1031 XglDescriptorSetObj descriptorSet(m_device);
1032
1033 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -07001034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +08001035
1036 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
1037 att.blendEnable = XGL_FALSE;
1038 att.format = m_render_target_fmt;
1039 att.channelWriteMask = 0xf;
1040 pipelineobj.SetColorAttachment(1, &att);
1041
Tony Barbour5ed79702015-01-07 14:31:52 -07001042 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001043
Tony Barbour5ed79702015-01-07 14:31:52 -07001044 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1045 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -07001046
Tony Barbour5ed79702015-01-07 14:31:52 -07001047 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
Tony Barbour5ed79702015-01-07 14:31:52 -07001048
Tony Barboure4ed9942015-01-09 10:06:53 -07001049 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1050
Tony Barbour5ed79702015-01-07 14:31:52 -07001051 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -07001052#ifdef DUMP_STATE_DOT
1053 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1054 pDSDumpDot((char*)"triTest2.dot");
1055#endif
1056 // render triangle
1057 cmdBuffer.Draw(0, 3, 0, 1);
1058
1059 // finalize recording of the command buffer
1060 cmdBuffer.EndCommandBuffer();
1061 cmdBuffer.QueueCommandBuffer(NULL, 0);
1062
1063 for (int i = 0; i < m_renderTargetCount; i++)
1064 RecordImage(m_renderTargets[i]);
1065
Chia-I Wue09d1a72014-12-05 10:32:23 +08001066}
1067
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001068TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
1069{
1070 static const char *vertShaderText =
1071 "#version 140\n"
1072 "#extension GL_ARB_separate_shader_objects : enable\n"
1073 "#extension GL_ARB_shading_language_420pack : enable\n"
1074 "layout(location = 0) in vec4 pos;\n"
1075 "layout(location = 1) in vec4 inColor;\n"
1076 "layout(location = 0) out vec4 outColor;\n"
1077 "void main() {\n"
1078 " outColor = inColor;\n"
1079 " gl_Position = pos;\n"
1080 "}\n";
1081
1082
1083 static const char *fragShaderText =
1084 "#version 140\n"
1085 "#extension GL_ARB_separate_shader_objects : enable\n"
1086 "#extension GL_ARB_shading_language_420pack : enable\n"
1087 "layout(location = 0) in vec4 color;\n"
1088 "void main() {\n"
1089 " gl_FragColor = color;\n"
1090 "}\n";
1091
1092 const Vertex g_vbData[] =
1093 {
1094 // first tri
1095 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
1096 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1097 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1098
1099 // second tri
1100 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1101 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1102 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
1103 };
1104
1105 const uint16_t g_idxData[6] = {
1106 0, 1, 2,
1107 3, 4, 5,
1108 };
1109
1110 ASSERT_NO_FATAL_FAILURE(InitState());
1111 ASSERT_NO_FATAL_FAILURE(InitViewport());
1112
1113 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001114 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001115
1116 XglIndexBufferObj indexBuffer(m_device);
1117 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Tony Barboure6152042014-12-10 17:40:15 -07001118 indexBuffer.SetMemoryState(XGL_MEMORY_STATE_INDEX_DATA);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001119
1120 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1121 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1122
1123 XglPipelineObj pipelineobj(m_device);
1124 pipelineobj.AddShader(&vs);
1125 pipelineobj.AddShader(&ps);
1126
1127 XglDescriptorSetObj descriptorSet(m_device);
1128
1129 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1130 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1131 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1132 };
1133
1134 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1135 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1136 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1137 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1138 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1139 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1140 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1141 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1142 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1143
1144 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1145 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001146
1147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001148 XglCommandBufferObj cmdBuffer(m_device);
1149 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1150 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
Tony Barboure4ed9942015-01-09 10:06:53 -07001151
1152 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001153
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001154#ifdef DUMP_STATE_DOT
1155 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -07001156 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001157#endif
Tony Barbour02472db2015-01-08 17:08:28 -07001158
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001159 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1160 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001161
1162 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001163 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001164
1165 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001166 cmdBuffer.EndCommandBuffer();
1167 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001168
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001169 for (int i = 0; i < m_renderTargetCount; i++)
1170 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001171
1172}
1173
GregF6bef1212014-12-02 15:41:44 -07001174TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1175{
1176 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001177
GregF6bef1212014-12-02 15:41:44 -07001178 static const char *vertShaderText =
1179 "#version 140\n"
1180 "#extension GL_ARB_separate_shader_objects : enable\n"
1181 "#extension GL_ARB_shading_language_420pack : enable\n"
1182 "layout (location = 0) in vec4 pos;\n"
1183 "layout (location = 0) out vec4 outColor;\n"
1184 "layout (location = 1) out vec4 outColor2;\n"
1185 "void main() {\n"
1186 " gl_Position = pos;\n"
1187 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1188 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1189 "}\n";
1190
1191 static const char *fragShaderText =
1192 //"#version 140\n"
1193 "#version 330\n"
1194 "#extension GL_ARB_separate_shader_objects : enable\n"
1195 "#extension GL_ARB_shading_language_420pack : enable\n"
1196 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1197 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1198 "layout (location = 0) in vec4 color;\n"
1199 "layout (location = 1) in vec4 color2;\n"
1200 "void main() {\n"
1201 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1202 " float dist_squared = dot(pos, pos);\n"
1203 " gl_FragColor = (dist_squared < 400.0)\n"
1204 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1205 " : color2;\n"
1206 "}\n";
1207
1208 ASSERT_NO_FATAL_FAILURE(InitState());
1209 ASSERT_NO_FATAL_FAILURE(InitViewport());
1210
1211 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001212 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001213
1214 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1215 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1216
1217 XglPipelineObj pipelineobj(m_device);
1218 pipelineobj.AddShader(&vs);
1219 pipelineobj.AddShader(&ps);
1220
1221 XglDescriptorSetObj descriptorSet(m_device);
1222 descriptorSet.AttachMemoryView(&meshBuffer);
1223
1224 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1225 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1226 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1227 };
1228
1229 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1230 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1231 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1232 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1233 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1234 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1235 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1236 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1237 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1238
1239 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1240 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1241 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1242
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1244 XglCommandBufferObj cmdBuffer(m_device);
1245 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1246
1247 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1248
1249 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1250
1251 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1252#ifdef DUMP_STATE_DOT
1253 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1254 pDSDumpDot((char*)"triTest2.dot");
1255#endif
1256 // render triangle
1257 cmdBuffer.Draw(0, 6, 0, 1);
1258
1259 // finalize recording of the command buffer
1260 cmdBuffer.EndCommandBuffer();
1261 cmdBuffer.QueueCommandBuffer(NULL, 0);
1262
1263 for (int i = 0; i < m_renderTargetCount; i++)
1264 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001265
1266}
1267
1268TEST_F(XglRenderTest, RedCirclesonBlue)
1269{
1270 // This tests that we correctly handle unread fragment inputs
1271
1272 static const char *vertShaderText =
1273 "#version 140\n"
1274 "#extension GL_ARB_separate_shader_objects : enable\n"
1275 "#extension GL_ARB_shading_language_420pack : enable\n"
1276 "layout (location = 0) in vec4 pos;\n"
1277 "layout (location = 0) out vec4 outColor;\n"
1278 "layout (location = 1) out vec4 outColor2;\n"
1279 "void main() {\n"
1280 " gl_Position = pos;\n"
1281 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1282 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1283 "}\n";
1284
1285 static const char *fragShaderText =
1286 //"#version 140\n"
1287 "#version 330\n"
1288 "#extension GL_ARB_separate_shader_objects : enable\n"
1289 "#extension GL_ARB_shading_language_420pack : enable\n"
1290 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1291 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1292 "layout (location = 0) in vec4 color;\n"
1293 "layout (location = 1) in vec4 color2;\n"
1294 "void main() {\n"
1295 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1296 " float dist_squared = dot(pos, pos);\n"
1297 " gl_FragColor = (dist_squared < 400.0)\n"
1298 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1299 " : color2;\n"
1300 "}\n";
1301
1302 ASSERT_NO_FATAL_FAILURE(InitState());
1303 ASSERT_NO_FATAL_FAILURE(InitViewport());
1304
1305 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001306 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001307
1308 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1309 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1310
1311 XglPipelineObj pipelineobj(m_device);
1312 pipelineobj.AddShader(&vs);
1313 pipelineobj.AddShader(&ps);
1314
1315 XglDescriptorSetObj descriptorSet(m_device);
1316 descriptorSet.AttachMemoryView(&meshBuffer);
1317
1318 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1319 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1320 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1321 };
1322
1323 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1324 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1325 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1326 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1327 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1328 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1329 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1330 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1331 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1332
1333 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1334 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1335 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1336
Tony Barbourdd4c9642015-01-09 12:55:14 -07001337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1338 XglCommandBufferObj cmdBuffer(m_device);
1339 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1340
1341 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1342
1343 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1344
1345 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1346#ifdef DUMP_STATE_DOT
1347 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1348 pDSDumpDot((char*)"triTest2.dot");
1349#endif
1350 // render triangle
1351 cmdBuffer.Draw(0, 6, 0, 1);
1352
1353 // finalize recording of the command buffer
1354 cmdBuffer.EndCommandBuffer();
1355 cmdBuffer.QueueCommandBuffer(NULL, 0);
1356
1357 for (int i = 0; i < m_renderTargetCount; i++)
1358 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001359
1360}
1361
1362TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1363{
1364 // This tests reading gl_ClipDistance from FS
1365
1366 static const char *vertShaderText =
1367 "#version 330\n"
1368 "#extension GL_ARB_separate_shader_objects : enable\n"
1369 "#extension GL_ARB_shading_language_420pack : enable\n"
1370 "out gl_PerVertex {\n"
1371 " vec4 gl_Position;\n"
1372 " float gl_ClipDistance[1];\n"
1373 "};\n"
1374 "layout (location = 0) in vec4 pos;\n"
1375 "layout (location = 0) out vec4 outColor;\n"
1376 "layout (location = 1) out vec4 outColor2;\n"
1377 "void main() {\n"
1378 " gl_Position = pos;\n"
1379 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1380 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1381 " float dists[3];\n"
1382 " dists[0] = 0.0;\n"
1383 " dists[1] = 1.0;\n"
1384 " dists[2] = 1.0;\n"
1385 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1386 "}\n";
1387
1388
1389 static const char *fragShaderText =
1390 //"#version 140\n"
1391 "#version 330\n"
1392 "#extension GL_ARB_separate_shader_objects : enable\n"
1393 "#extension GL_ARB_shading_language_420pack : enable\n"
1394 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1395 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1396 "layout (location = 0) in vec4 color;\n"
1397 "layout (location = 1) in vec4 color2;\n"
1398 "void main() {\n"
1399 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1400 " float dist_squared = dot(pos, pos);\n"
1401 " gl_FragColor = (dist_squared < 400.0)\n"
1402 " ? color * gl_ClipDistance[0]\n"
1403 " : color2;\n"
1404 "}\n";
1405
1406 ASSERT_NO_FATAL_FAILURE(InitState());
1407 ASSERT_NO_FATAL_FAILURE(InitViewport());
1408
1409 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001410 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF6bef1212014-12-02 15:41:44 -07001411
1412 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1413 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1414
1415 XglPipelineObj pipelineobj(m_device);
1416 pipelineobj.AddShader(&vs);
1417 pipelineobj.AddShader(&ps);
1418
1419 XglDescriptorSetObj descriptorSet(m_device);
1420 descriptorSet.AttachMemoryView(&meshBuffer);
1421
1422 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1423 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1424 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1425 };
1426
1427 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1428 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1429 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1430 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1431 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1432 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1433 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1434 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1435 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1436
1437 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1438 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1439 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1440
Tony Barbourdd4c9642015-01-09 12:55:14 -07001441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1442 XglCommandBufferObj cmdBuffer(m_device);
1443 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001444
Tony Barbourdd4c9642015-01-09 12:55:14 -07001445 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1446
1447 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1448
1449 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1450#ifdef DUMP_STATE_DOT
1451 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1452 pDSDumpDot((char*)"triTest2.dot");
1453#endif
1454 // render triangle
1455 cmdBuffer.Draw(0, 6, 0, 1);
1456
1457 // finalize recording of the command buffer
1458 cmdBuffer.EndCommandBuffer();
1459 cmdBuffer.QueueCommandBuffer(NULL, 0);
1460
1461 for (int i = 0; i < m_renderTargetCount; i++)
1462 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001463}
Tony Barbourf43b6982014-11-25 13:18:32 -07001464
GregF7a23c792014-12-02 17:19:34 -07001465TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1466{
1467 static const char *vertShaderText =
1468 "#version 140\n"
1469 "#extension GL_ARB_separate_shader_objects : enable\n"
1470 "#extension GL_ARB_shading_language_420pack : enable\n"
1471 "layout (location = 0) in vec4 pos;\n"
1472 "layout (location = 0) out vec4 outColor;\n"
1473 "layout (location = 1) out vec4 outColor2;\n"
1474 "void main() {\n"
1475 " gl_Position = pos;\n"
1476 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1477 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1478 "}\n";
1479
1480
1481 static const char *fragShaderText =
1482 //"#version 140\n"
1483 "#version 330\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1487 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1488 "layout (location = 0) in vec4 color;\n"
1489 "layout (location = 1) in vec4 color2;\n"
1490 "void main() {\n"
1491 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1492 " float dist_squared = dot(pos, pos);\n"
1493 " if (dist_squared < 100.0)\n"
1494 " discard;\n"
1495 " gl_FragColor = (dist_squared < 400.0)\n"
1496 " ? color\n"
1497 " : color2;\n"
1498 "}\n";
1499
1500 ASSERT_NO_FATAL_FAILURE(InitState());
1501 ASSERT_NO_FATAL_FAILURE(InitViewport());
1502
1503 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001504 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
GregF7a23c792014-12-02 17:19:34 -07001505
1506 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1507 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1508
1509 XglPipelineObj pipelineobj(m_device);
1510 pipelineobj.AddShader(&vs);
1511 pipelineobj.AddShader(&ps);
1512
1513 XglDescriptorSetObj descriptorSet(m_device);
1514 descriptorSet.AttachMemoryView(&meshBuffer);
1515
1516 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1517 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1518 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1519 };
1520
1521 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1522 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1523 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1524 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1525 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1526 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1527 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1528 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1529 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1530
1531 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1532 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1533 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1534
Tony Barbourdd4c9642015-01-09 12:55:14 -07001535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1536 XglCommandBufferObj cmdBuffer(m_device);
1537 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1538
1539 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1540
1541 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1542
1543 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1544#ifdef DUMP_STATE_DOT
1545 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1546 pDSDumpDot((char*)"triTest2.dot");
1547#endif
1548 // render triangle
1549 cmdBuffer.Draw(0, 6, 0, 1);
1550
1551 // finalize recording of the command buffer
1552 cmdBuffer.EndCommandBuffer();
1553 cmdBuffer.QueueCommandBuffer(NULL, 0);
1554
1555 for (int i = 0; i < m_renderTargetCount; i++)
1556 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001557
1558}
1559
1560
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001561TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001562{
1563 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001564 "#version 140\n"
1565 "#extension GL_ARB_separate_shader_objects : enable\n"
1566 "#extension GL_ARB_shading_language_420pack : enable\n"
1567 "\n"
1568 "layout(binding = 0) uniform buf {\n"
1569 " mat4 MVP;\n"
1570 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001571 "void main() {\n"
1572 " vec2 vertices[3];"
1573 " vertices[0] = vec2(-0.5, -0.5);\n"
1574 " vertices[1] = vec2( 0.5, -0.5);\n"
1575 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001576 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001577 "}\n";
1578
1579 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001580 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001581 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001582 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001583 "}\n";
1584
Tony Barbourf43b6982014-11-25 13:18:32 -07001585 ASSERT_NO_FATAL_FAILURE(InitState());
1586 ASSERT_NO_FATAL_FAILURE(InitViewport());
1587
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001588 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001589 glm::mat4 Projection = glm::mat4(1.0f);
1590 glm::mat4 View = glm::mat4(1.0f);
1591 glm::mat4 Model = glm::mat4(1.0f);
1592 glm::mat4 MVP = Projection * View * Model;
1593 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1594
Tony Barbourf43b6982014-11-25 13:18:32 -07001595 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1596 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1597 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001598
Tony Barbourf43b6982014-11-25 13:18:32 -07001599 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1600
1601 XglPipelineObj pipelineobj(m_device);
1602 pipelineobj.AddShader(&vs);
1603 pipelineobj.AddShader(&ps);
1604
1605 // Create descriptor set and attach the constant buffer to it
1606 XglDescriptorSetObj descriptorSet(m_device);
1607 descriptorSet.AttachMemoryView(&MVPBuffer);
1608
1609 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1610
Tony Barbourdd4c9642015-01-09 12:55:14 -07001611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1612 XglCommandBufferObj cmdBuffer(m_device);
1613 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001614
Tony Barbourdd4c9642015-01-09 12:55:14 -07001615 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1616
1617 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1618
1619 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1620#ifdef DUMP_STATE_DOT
1621 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1622 pDSDumpDot((char*)"triTest2.dot");
1623#endif
1624 // render triangle
1625 cmdBuffer.Draw(0, 6, 0, 1);
1626
1627 // finalize recording of the command buffer
1628 cmdBuffer.EndCommandBuffer();
1629 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1630
1631 for (int i = 0; i < m_renderTargetCount; i++)
1632 RecordImage(m_renderTargets[i]);
1633
1634 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001635}
1636
Tony Barbourf43b6982014-11-25 13:18:32 -07001637TEST_F(XglRenderTest, MixTriangle)
1638{
1639 // This tests location applied to varyings. Notice that we have switched foo
1640 // and bar in the FS. The triangle should be blended with red, green and blue
1641 // corners.
1642 static const char *vertShaderText =
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=0) out vec4 bar;\n"
1647 "layout (location=1) out vec4 foo;\n"
1648 "layout (location=2) out float scale;\n"
1649 "vec2 vertices[3];\n"
1650 "void main() {\n"
1651 " vertices[0] = vec2(-1.0, -1.0);\n"
1652 " vertices[1] = vec2( 1.0, -1.0);\n"
1653 " vertices[2] = vec2( 0.0, 1.0);\n"
1654 "vec4 colors[3];\n"
1655 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1656 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1657 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1658 " foo = colors[gl_VertexID % 3];\n"
1659 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1660 " scale = 1.0;\n"
1661 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1662 "}\n";
1663
1664 static const char *fragShaderText =
1665 "#version 140\n"
1666 "#extension GL_ARB_separate_shader_objects : enable\n"
1667 "#extension GL_ARB_shading_language_420pack : enable\n"
1668 "layout (location = 1) in vec4 bar;\n"
1669 "layout (location = 0) in vec4 foo;\n"
1670 "layout (location = 2) in float scale;\n"
1671 "void main() {\n"
1672 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1673 "}\n";
1674
1675 ASSERT_NO_FATAL_FAILURE(InitState());
1676 ASSERT_NO_FATAL_FAILURE(InitViewport());
1677
1678 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1679 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1680
1681 XglPipelineObj pipelineobj(m_device);
1682 pipelineobj.AddShader(&vs);
1683 pipelineobj.AddShader(&ps);
1684
1685 XglDescriptorSetObj descriptorSet(m_device);
1686
Tony Barbourdd4c9642015-01-09 12:55:14 -07001687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1688 XglCommandBufferObj cmdBuffer(m_device);
1689 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1690
1691 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1692
1693 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1694
1695#ifdef DUMP_STATE_DOT
1696 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1697 pDSDumpDot((char*)"triTest2.dot");
1698#endif
1699 // render triangle
1700 cmdBuffer.Draw(0, 3, 0, 1);
1701
1702 // finalize recording of the command buffer
1703 cmdBuffer.EndCommandBuffer();
1704 cmdBuffer.QueueCommandBuffer(NULL, 0);
1705
1706 for (int i = 0; i < m_renderTargetCount; i++)
1707 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001708}
1709
1710TEST_F(XglRenderTest, TriVertFetchAndVertID)
1711{
1712 // This tests that attributes work in the presence of gl_VertexID
1713
1714 static const char *vertShaderText =
1715 "#version 140\n"
1716 "#extension GL_ARB_separate_shader_objects : enable\n"
1717 "#extension GL_ARB_shading_language_420pack : enable\n"
1718 //XYZ1( -1, -1, -1 )
1719 "layout (location = 0) in vec4 pos;\n"
1720 //XYZ1( 0.f, 0.f, 0.f )
1721 "layout (location = 1) in vec4 inColor;\n"
1722 "layout (location = 0) out vec4 outColor;\n"
1723 "void main() {\n"
1724 " outColor = inColor;\n"
1725 " vec4 vertices[3];"
1726 " vertices[gl_VertexID % 3] = pos;\n"
1727 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1728 "}\n";
1729
1730
1731 static const char *fragShaderText =
1732 "#version 140\n"
1733 "#extension GL_ARB_separate_shader_objects : enable\n"
1734 "#extension GL_ARB_shading_language_420pack : enable\n"
1735 "layout (location = 0) in vec4 color;\n"
1736 "void main() {\n"
1737 " gl_FragColor = color;\n"
1738 "}\n";
1739
1740 ASSERT_NO_FATAL_FAILURE(InitState());
1741 ASSERT_NO_FATAL_FAILURE(InitViewport());
1742
1743 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001744 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07001745
1746 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1747 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1748
1749 XglPipelineObj pipelineobj(m_device);
1750 pipelineobj.AddShader(&vs);
1751 pipelineobj.AddShader(&ps);
1752
1753 XglDescriptorSetObj descriptorSet(m_device);
1754 descriptorSet.AttachMemoryView(&meshBuffer);
1755
1756 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1757 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1758 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1759 };
1760
1761 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1762 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1763 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1764 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1765 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1766 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1767 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1768 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1769 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1770
1771 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1772 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1773 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1774
Tony Barbourdd4c9642015-01-09 12:55:14 -07001775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1776 XglCommandBufferObj cmdBuffer(m_device);
1777 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1778
1779 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1780
1781 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1782
1783 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1784#ifdef DUMP_STATE_DOT
1785 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1786 pDSDumpDot((char*)"triTest2.dot");
1787#endif
1788 // render triangle
1789 cmdBuffer.Draw(0, 6, 0, 1);
1790
1791 // finalize recording of the command buffer
1792 cmdBuffer.EndCommandBuffer();
1793 cmdBuffer.QueueCommandBuffer(NULL, 0);
1794
1795 for (int i = 0; i < m_renderTargetCount; i++)
1796 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001797}
1798
1799TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1800{
1801 // This tests that attributes work in the presence of gl_VertexID
1802 // and a dead attribute in position 0. Draws a triangle with yellow,
1803 // red and green corners, starting at top and going clockwise.
1804
1805 static const char *vertShaderText =
1806 "#version 140\n"
1807 "#extension GL_ARB_separate_shader_objects : enable\n"
1808 "#extension GL_ARB_shading_language_420pack : enable\n"
1809 //XYZ1( -1, -1, -1 )
1810 "layout (location = 0) in vec4 pos;\n"
1811 //XYZ1( 0.f, 0.f, 0.f )
1812 "layout (location = 1) in vec4 inColor;\n"
1813 "layout (location = 0) out vec4 outColor;\n"
1814 "void main() {\n"
1815 " outColor = inColor;\n"
1816 " vec2 vertices[3];"
1817 " vertices[0] = vec2(-1.0, -1.0);\n"
1818 " vertices[1] = vec2( 1.0, -1.0);\n"
1819 " vertices[2] = vec2( 0.0, 1.0);\n"
1820 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1821 "}\n";
1822
1823
1824 static const char *fragShaderText =
1825 "#version 140\n"
1826 "#extension GL_ARB_separate_shader_objects : enable\n"
1827 "#extension GL_ARB_shading_language_420pack : enable\n"
1828 "layout (location = 0) in vec4 color;\n"
1829 "void main() {\n"
1830 " gl_FragColor = color;\n"
1831 "}\n";
1832
1833 ASSERT_NO_FATAL_FAILURE(InitState());
1834 ASSERT_NO_FATAL_FAILURE(InitViewport());
1835
1836 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Tony Barboure6152042014-12-10 17:40:15 -07001837 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07001838
1839 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1840 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1841
1842 XglPipelineObj pipelineobj(m_device);
1843 pipelineobj.AddShader(&vs);
1844 pipelineobj.AddShader(&ps);
1845
1846 XglDescriptorSetObj descriptorSet(m_device);
1847 descriptorSet.AttachMemoryView(&meshBuffer);
1848
1849 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1850 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1851 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1852 };
1853
1854 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1855 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1856 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1857 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1858 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1859 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1860 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1861 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1862 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1863
1864 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1865 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1866 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1867
Tony Barbourdd4c9642015-01-09 12:55:14 -07001868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1869 XglCommandBufferObj cmdBuffer(m_device);
1870 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001871
Tony Barbourdd4c9642015-01-09 12:55:14 -07001872 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1873
1874 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1875
1876 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1877#ifdef DUMP_STATE_DOT
1878 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1879 pDSDumpDot((char*)"triTest2.dot");
1880#endif
1881 // render triangle
1882 cmdBuffer.Draw(0, 6, 0, 1);
1883
1884 // finalize recording of the command buffer
1885 cmdBuffer.EndCommandBuffer();
1886 cmdBuffer.QueueCommandBuffer(NULL, 0);
1887
1888 for (int i = 0; i < m_renderTargetCount; i++)
1889 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001890}
1891
1892TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001893{
1894 static const char *vertShaderText =
1895 "#version 140\n"
1896 "layout (std140) uniform bufferVals {\n"
1897 " mat4 mvp;\n"
1898 "} myBufferVals;\n"
1899 "in vec4 pos;\n"
1900 "in vec4 inColor;\n"
1901 "out vec4 outColor;\n"
1902 "void main() {\n"
1903 " outColor = inColor;\n"
1904 " gl_Position = myBufferVals.mvp * pos;\n"
1905 "}\n";
1906
1907 static const char *fragShaderText =
1908 "#version 130\n"
1909 "in vec4 color;\n"
1910 "void main() {\n"
1911 " gl_FragColor = color;\n"
1912 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001913 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001914
Tony Barbourf43b6982014-11-25 13:18:32 -07001915 glm::mat4 View = glm::lookAt(
1916 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1917 glm::vec3(0,0,0), // and looks at the origin
1918 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1919 );
1920
1921 glm::mat4 Model = glm::mat4(1.0f);
1922
1923 glm::mat4 MVP = Projection * View * Model;
1924
1925 ASSERT_NO_FATAL_FAILURE(InitState());
1926 ASSERT_NO_FATAL_FAILURE(InitViewport());
1927 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1928
1929 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1930 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1931
1932 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1933
1934 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1935 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1936 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1937
1938 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1939
1940 XglPipelineObj pipelineobj(m_device);
1941 pipelineobj.AddShader(&vs);
1942 pipelineobj.AddShader(&ps);
1943
1944 XglDescriptorSetObj descriptorSet(m_device);
1945 descriptorSet.AttachMemoryView(&MVPBuffer);
1946
1947 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1948 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1949
1950 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1951 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1952 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1953 };
1954
1955 // this is the current description of g_vbData
1956 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1957 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1958 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1959 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1960 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1961 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1962 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1963 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1964 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1965
1966 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1967 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1968 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1969
Tony Barboure4ed9942015-01-09 10:06:53 -07001970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1971 XglCommandBufferObj cmdBuffer(m_device);
1972 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001973
Tony Barboure4ed9942015-01-09 10:06:53 -07001974 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
1975 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001976
Tony Barboure4ed9942015-01-09 10:06:53 -07001977 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1978#ifdef DUMP_STATE_DOT
1979 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1980 pDSDumpDot((char*)"triTest2.dot");
1981#endif
1982 // render triangle
1983 cmdBuffer.Draw(0, 36, 0, 1);
1984
1985 // finalize recording of the command buffer
1986 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001987 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001988
1989 for (int i = 0; i < m_renderTargetCount; i++)
1990 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001991}
1992
Tony Barbourf43b6982014-11-25 13:18:32 -07001993TEST_F(XglRenderTest, VSTexture)
1994{
1995 // The expected result from this test is a green and red triangle;
1996 // one red vertex on the left, two green vertices on the right.
1997 static const char *vertShaderText =
1998 "#version 130\n"
1999 "out vec4 texColor;\n"
2000 "uniform sampler2D surface;\n"
2001 "void main() {\n"
2002 " vec2 vertices[3];"
2003 " vertices[0] = vec2(-0.5, -0.5);\n"
2004 " vertices[1] = vec2( 0.5, -0.5);\n"
2005 " vertices[2] = vec2( 0.5, 0.5);\n"
2006 " vec2 positions[3];"
2007 " positions[0] = vec2( 0.0, 0.0);\n"
2008 " positions[1] = vec2( 0.25, 0.1);\n"
2009 " positions[2] = vec2( 0.1, 0.25);\n"
2010 " vec2 samplePos = positions[gl_VertexID % 3];\n"
2011 " texColor = textureLod(surface, samplePos, 0.0);\n"
2012 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2013 "}\n";
2014
2015 static const char *fragShaderText =
2016 "#version 130\n"
2017 "in vec4 texColor;\n"
2018 "void main() {\n"
2019 " gl_FragColor = texColor;\n"
2020 "}\n";
2021
2022 ASSERT_NO_FATAL_FAILURE(InitState());
2023 ASSERT_NO_FATAL_FAILURE(InitViewport());
2024
2025 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2026 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2027 XglSamplerObj sampler(m_device);
2028 XglTextureObj texture(m_device);
2029
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002030 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002031 vs.BindShaderEntitySlotToSampler(0, &sampler);
2032
2033 XglPipelineObj pipelineobj(m_device);
2034 pipelineobj.AddShader(&vs);
2035 pipelineobj.AddShader(&ps);
2036
2037 XglDescriptorSetObj descriptorSet(m_device);
2038 descriptorSet.AttachImageView(&texture);
2039 descriptorSet.AttachSampler(&sampler);
2040
2041 m_memoryRefManager.AddMemoryRef(&texture);
2042
Tony Barbourdd4c9642015-01-09 12:55:14 -07002043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2044 XglCommandBufferObj cmdBuffer(m_device);
2045 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002046
Tony Barbourdd4c9642015-01-09 12:55:14 -07002047 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2048
2049 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2050
2051#ifdef DUMP_STATE_DOT
2052 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2053 pDSDumpDot((char*)"triTest2.dot");
2054#endif
2055 // render triangle
2056 cmdBuffer.Draw(0, 3, 0, 1);
2057
2058 // finalize recording of the command buffer
2059 cmdBuffer.EndCommandBuffer();
2060 cmdBuffer.QueueCommandBuffer(NULL, 0);
2061
2062 for (int i = 0; i < m_renderTargetCount; i++)
2063 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002064}
2065TEST_F(XglRenderTest, TexturedTriangle)
2066{
2067 // The expected result from this test is a red and green checkered triangle
2068 static const char *vertShaderText =
2069 "#version 140\n"
2070 "#extension GL_ARB_separate_shader_objects : enable\n"
2071 "#extension GL_ARB_shading_language_420pack : enable\n"
2072 "layout (location = 0) out vec2 samplePos;\n"
2073 "void main() {\n"
2074 " vec2 vertices[3];"
2075 " vertices[0] = vec2(-0.5, -0.5);\n"
2076 " vertices[1] = vec2( 0.5, -0.5);\n"
2077 " vertices[2] = vec2( 0.5, 0.5);\n"
2078 " vec2 positions[3];"
2079 " positions[0] = vec2( 0.0, 0.0);\n"
2080 " positions[1] = vec2( 1.0, 0.0);\n"
2081 " positions[2] = vec2( 1.0, 1.0);\n"
2082 " samplePos = positions[gl_VertexID % 3];\n"
2083 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2084 "}\n";
2085
2086 static const char *fragShaderText =
2087 "#version 140\n"
2088 "#extension GL_ARB_separate_shader_objects : enable\n"
2089 "#extension GL_ARB_shading_language_420pack : enable\n"
2090 "layout (location = 0) in vec2 samplePos;\n"
2091 "layout (binding = 0) uniform sampler2D surface;\n"
2092 "layout (location=0) out vec4 outColor;\n"
2093 "void main() {\n"
2094 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2095 " outColor = texColor;\n"
2096 "}\n";
2097
2098 ASSERT_NO_FATAL_FAILURE(InitState());
2099 ASSERT_NO_FATAL_FAILURE(InitViewport());
2100
2101 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2102 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2103 XglSamplerObj sampler(m_device);
2104 XglTextureObj texture(m_device);
2105
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002106 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002107 ps.BindShaderEntitySlotToSampler(0, &sampler);
2108
2109 XglPipelineObj pipelineobj(m_device);
2110 pipelineobj.AddShader(&vs);
2111 pipelineobj.AddShader(&ps);
2112
2113 XglDescriptorSetObj descriptorSet(m_device);
2114 descriptorSet.AttachImageView(&texture);
2115 descriptorSet.AttachSampler(&sampler);
2116
2117 m_memoryRefManager.AddMemoryRef(&texture);
2118
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2120 XglCommandBufferObj cmdBuffer(m_device);
2121 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2122
2123 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2124
2125 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2126
2127#ifdef DUMP_STATE_DOT
2128 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2129 pDSDumpDot((char*)"triTest2.dot");
2130#endif
2131 // render triangle
2132 cmdBuffer.Draw(0, 3, 0, 1);
2133
2134 // finalize recording of the command buffer
2135 cmdBuffer.EndCommandBuffer();
2136 cmdBuffer.QueueCommandBuffer(NULL, 0);
2137
2138 for (int i = 0; i < m_renderTargetCount; i++)
2139 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002140}
2141TEST_F(XglRenderTest, TexturedTriangleClip)
2142{
2143 // The expected result from this test is a red and green checkered triangle
2144 static const char *vertShaderText =
2145 "#version 330\n"
2146 "#extension GL_ARB_separate_shader_objects : enable\n"
2147 "#extension GL_ARB_shading_language_420pack : enable\n"
2148 "layout (location = 0) out vec2 samplePos;\n"
2149 "out gl_PerVertex {\n"
2150 " vec4 gl_Position;\n"
2151 " float gl_ClipDistance[1];\n"
2152 "};\n"
2153 "void main() {\n"
2154 " vec2 vertices[3];"
2155 " vertices[0] = vec2(-0.5, -0.5);\n"
2156 " vertices[1] = vec2( 0.5, -0.5);\n"
2157 " vertices[2] = vec2( 0.5, 0.5);\n"
2158 " vec2 positions[3];"
2159 " positions[0] = vec2( 0.0, 0.0);\n"
2160 " positions[1] = vec2( 1.0, 0.0);\n"
2161 " positions[2] = vec2( 1.0, 1.0);\n"
2162 " float dists[3];\n"
2163 " dists[0] = 1.0;\n"
2164 " dists[1] = 1.0;\n"
2165 " dists[2] = -1.0;\n"
2166 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2167 " samplePos = positions[gl_VertexID % 3];\n"
2168 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2169 "}\n";
2170
2171 static const char *fragShaderText =
2172 "#version 140\n"
2173 "#extension GL_ARB_separate_shader_objects : enable\n"
2174 "#extension GL_ARB_shading_language_420pack : enable\n"
2175 "layout (location = 0) in vec2 samplePos;\n"
2176 "layout (binding = 0) uniform sampler2D surface;\n"
2177 "layout (location=0) out vec4 outColor;\n"
2178 "void main() {\n"
2179 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2180 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2181 " outColor = texColor;\n"
2182 "}\n";
2183
2184
2185 ASSERT_NO_FATAL_FAILURE(InitState());
2186 ASSERT_NO_FATAL_FAILURE(InitViewport());
2187
2188 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2189 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2190 XglSamplerObj sampler(m_device);
2191 XglTextureObj texture(m_device);
2192
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002193 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002194 ps.BindShaderEntitySlotToSampler(0, &sampler);
2195
2196 XglPipelineObj pipelineobj(m_device);
2197 pipelineobj.AddShader(&vs);
2198 pipelineobj.AddShader(&ps);
2199
2200 XglDescriptorSetObj descriptorSet(m_device);
2201 descriptorSet.AttachImageView(&texture);
2202 descriptorSet.AttachSampler(&sampler);
2203
2204 m_memoryRefManager.AddMemoryRef(&texture);
2205
Tony Barbourdd4c9642015-01-09 12:55:14 -07002206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2207 XglCommandBufferObj cmdBuffer(m_device);
2208 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2209
2210 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2211
2212 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2213
2214#ifdef DUMP_STATE_DOT
2215 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2216 pDSDumpDot((char*)"triTest2.dot");
2217#endif
2218 // render triangle
2219 cmdBuffer.Draw(0, 3, 0, 1);
2220
2221 // finalize recording of the command buffer
2222 cmdBuffer.EndCommandBuffer();
2223 cmdBuffer.QueueCommandBuffer(NULL, 0);
2224
2225 for (int i = 0; i < m_renderTargetCount; i++)
2226 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002227}
2228TEST_F(XglRenderTest, FSTriangle)
2229{
2230 // The expected result from this test is a red and green checkered triangle
2231 static const char *vertShaderText =
2232 "#version 140\n"
2233 "#extension GL_ARB_separate_shader_objects : enable\n"
2234 "#extension GL_ARB_shading_language_420pack : enable\n"
2235 "layout (location = 0) out vec2 samplePos;\n"
2236 "void main() {\n"
2237 " vec2 vertices[3];"
2238 " vertices[0] = vec2(-0.5, -0.5);\n"
2239 " vertices[1] = vec2( 0.5, -0.5);\n"
2240 " vertices[2] = vec2( 0.5, 0.5);\n"
2241 " vec2 positions[3];"
2242 " positions[0] = vec2( 0.0, 0.0);\n"
2243 " positions[1] = vec2( 1.0, 0.0);\n"
2244 " positions[2] = vec2( 1.0, 1.0);\n"
2245 " samplePos = positions[gl_VertexID % 3];\n"
2246 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2247 "}\n";
2248
2249 static const char *fragShaderText =
2250 "#version 140\n"
2251 "#extension GL_ARB_separate_shader_objects : enable\n"
2252 "#extension GL_ARB_shading_language_420pack : enable\n"
2253 "layout (location = 0) in vec2 samplePos;\n"
2254 "layout (binding = 0) uniform sampler2D surface;\n"
2255 "layout (location=0) out vec4 outColor;\n"
2256 "void main() {\n"
2257 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2258 " outColor = texColor;\n"
2259 "}\n";
2260
2261 ASSERT_NO_FATAL_FAILURE(InitState());
2262 ASSERT_NO_FATAL_FAILURE(InitViewport());
2263
2264 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2265 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2266 XglSamplerObj sampler(m_device);
2267 XglTextureObj texture(m_device);
2268
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002269 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002270 ps.BindShaderEntitySlotToSampler(0, &sampler);
2271
2272 XglPipelineObj pipelineobj(m_device);
2273 pipelineobj.AddShader(&vs);
2274 pipelineobj.AddShader(&ps);
2275
2276 XglDescriptorSetObj descriptorSet(m_device);
2277 descriptorSet.AttachImageView(&texture);
2278 descriptorSet.AttachSampler(&sampler);
2279
2280 m_memoryRefManager.AddMemoryRef(&texture);
2281
Tony Barbourdd4c9642015-01-09 12:55:14 -07002282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2283 XglCommandBufferObj cmdBuffer(m_device);
2284 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2285
2286 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2287
2288 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2289
2290#ifdef DUMP_STATE_DOT
2291 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2292 pDSDumpDot((char*)"triTest2.dot");
2293#endif
2294 // render triangle
2295 cmdBuffer.Draw(0, 3, 0, 1);
2296
2297 // finalize recording of the command buffer
2298 cmdBuffer.EndCommandBuffer();
2299 cmdBuffer.QueueCommandBuffer(NULL, 0);
2300
2301 for (int i = 0; i < m_renderTargetCount; i++)
2302 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002303}
2304TEST_F(XglRenderTest, SamplerBindingsTriangle)
2305{
2306 // This test sets bindings on the samplers
2307 // For now we are asserting that sampler and texture pairs
2308 // march in lock step, and are set via GLSL binding. This can
2309 // and will probably change.
2310 // The sampler bindings should match the sampler and texture slot
2311 // number set up by the application.
2312 // This test will result in a blue triangle
2313 static const char *vertShaderText =
2314 "#version 140\n"
2315 "#extension GL_ARB_separate_shader_objects : enable\n"
2316 "#extension GL_ARB_shading_language_420pack : enable\n"
2317 "layout (location = 0) out vec4 samplePos;\n"
2318 "void main() {\n"
2319 " vec2 vertices[3];"
2320 " vertices[0] = vec2(-0.5, -0.5);\n"
2321 " vertices[1] = vec2( 0.5, -0.5);\n"
2322 " vertices[2] = vec2( 0.5, 0.5);\n"
2323 " vec2 positions[3];"
2324 " positions[0] = vec2( 0.0, 0.0);\n"
2325 " positions[1] = vec2( 1.0, 0.0);\n"
2326 " positions[2] = vec2( 1.0, 1.0);\n"
2327 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2328 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2329 "}\n";
2330
2331 static const char *fragShaderText =
2332 "#version 140\n"
2333 "#extension GL_ARB_separate_shader_objects : enable\n"
2334 "#extension GL_ARB_shading_language_420pack : enable\n"
2335 "layout (location = 0) in vec4 samplePos;\n"
2336 "layout (binding = 0) uniform sampler2D surface0;\n"
2337 "layout (binding = 1) uniform sampler2D surface1;\n"
2338 "layout (binding = 12) uniform sampler2D surface2;\n"
2339 "void main() {\n"
2340 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2341 "}\n";
2342
2343 ASSERT_NO_FATAL_FAILURE(InitState());
2344 ASSERT_NO_FATAL_FAILURE(InitViewport());
2345
2346 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2347 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2348
2349 XglSamplerObj sampler1(m_device);
2350 XglSamplerObj sampler2(m_device);
2351 XglSamplerObj sampler3(m_device);
2352
2353 XglTextureObj texture1(m_device); // Red
2354 texture1.ChangeColors(0xffff0000,0xffff0000);
2355 XglTextureObj texture2(m_device); // Green
2356 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2357 XglTextureObj texture3(m_device); // Blue
2358 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2359
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002360 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002361 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2362
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002363 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Tony Barbourf43b6982014-11-25 13:18:32 -07002364 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2365
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002366 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002367 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2368
2369 XglPipelineObj pipelineobj(m_device);
2370 pipelineobj.AddShader(&vs);
2371 pipelineobj.AddShader(&ps);
2372
2373 XglDescriptorSetObj descriptorSet(m_device);
2374 descriptorSet.AttachImageView(&texture1);
2375 descriptorSet.AttachSampler(&sampler1);
2376 descriptorSet.AttachImageView(&texture2);
2377 descriptorSet.AttachSampler(&sampler2);
2378 descriptorSet.AttachImageView(&texture3);
2379 descriptorSet.AttachSampler(&sampler3);
2380
2381 m_memoryRefManager.AddMemoryRef(&texture1);
2382 m_memoryRefManager.AddMemoryRef(&texture2);
2383 m_memoryRefManager.AddMemoryRef(&texture3);
2384
Tony Barbourdd4c9642015-01-09 12:55:14 -07002385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2386 XglCommandBufferObj cmdBuffer(m_device);
2387 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2388
2389 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2390
2391 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2392
2393#ifdef DUMP_STATE_DOT
2394 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2395 pDSDumpDot((char*)"triTest2.dot");
2396#endif
2397 // render triangle
2398 cmdBuffer.Draw(0, 3, 0, 1);
2399
2400 // finalize recording of the command buffer
2401 cmdBuffer.EndCommandBuffer();
2402 cmdBuffer.QueueCommandBuffer(NULL, 0);
2403
2404 for (int i = 0; i < m_renderTargetCount; i++)
2405 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002406
2407}
2408
2409TEST_F(XglRenderTest, TriangleVSUniformBlock)
2410{
2411 // The expected result from this test is a blue triangle
2412
2413 static const char *vertShaderText =
2414 "#version 140\n"
2415 "#extension GL_ARB_separate_shader_objects : enable\n"
2416 "#extension GL_ARB_shading_language_420pack : enable\n"
2417 "layout (location = 0) out vec4 outColor;\n"
2418 "layout (std140, binding = 0) uniform bufferVals {\n"
2419 " vec4 red;\n"
2420 " vec4 green;\n"
2421 " vec4 blue;\n"
2422 " vec4 white;\n"
2423 "} myBufferVals;\n"
2424 "void main() {\n"
2425 " vec2 vertices[3];"
2426 " vertices[0] = vec2(-0.5, -0.5);\n"
2427 " vertices[1] = vec2( 0.5, -0.5);\n"
2428 " vertices[2] = vec2( 0.5, 0.5);\n"
2429 " outColor = myBufferVals.blue;\n"
2430 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2431 "}\n";
2432
2433 static const char *fragShaderText =
2434 "#version 140\n"
2435 "#extension GL_ARB_separate_shader_objects : enable\n"
2436 "#extension GL_ARB_shading_language_420pack : enable\n"
2437 "layout (location = 0) in vec4 inColor;\n"
2438 "void main() {\n"
2439 " gl_FragColor = inColor;\n"
2440 "}\n";
2441
2442 ASSERT_NO_FATAL_FAILURE(InitState());
2443 ASSERT_NO_FATAL_FAILURE(InitViewport());
2444
2445 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2446 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2447
2448 // Let's populate our buffer with the following:
2449 // vec4 red;
2450 // vec4 green;
2451 // vec4 blue;
2452 // vec4 white;
2453 const int valCount = 4 * 4;
2454 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2455 0.0, 1.0, 0.0, 1.0,
2456 0.0, 0.0, 1.0, 1.0,
2457 1.0, 1.0, 1.0, 1.0 };
2458
2459 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
2460 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
2461
2462 XglPipelineObj pipelineobj(m_device);
2463 pipelineobj.AddShader(&vs);
2464 pipelineobj.AddShader(&ps);
2465
2466 XglDescriptorSetObj descriptorSet(m_device);
2467 descriptorSet.AttachMemoryView(&colorBuffer);
2468
Tony Barbourdd4c9642015-01-09 12:55:14 -07002469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2470 XglCommandBufferObj cmdBuffer(m_device);
2471 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2472
2473 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2474
2475 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2476
2477#ifdef DUMP_STATE_DOT
2478 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2479 pDSDumpDot((char*)"triTest2.dot");
2480#endif
2481 // render triangle
2482 cmdBuffer.Draw(0, 3, 0, 1);
2483
2484 // finalize recording of the command buffer
2485 cmdBuffer.EndCommandBuffer();
2486 cmdBuffer.QueueCommandBuffer(NULL, 0);
2487
2488 for (int i = 0; i < m_renderTargetCount; i++)
2489 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002490
2491}
2492
2493TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2494{
2495 // This test allows the shader to select which buffer it is
2496 // pulling from using layout binding qualifier.
2497 // There are corresponding changes in the compiler stack that
2498 // will select the buffer using binding directly.
2499 // The binding number should match the slot number set up by
2500 // the application.
2501 // The expected result from this test is a purple triangle
2502
2503 static const char *vertShaderText =
2504 "#version 140\n"
2505 "#extension GL_ARB_separate_shader_objects : enable\n"
2506 "#extension GL_ARB_shading_language_420pack : enable\n"
2507 "void main() {\n"
2508 " vec2 vertices[3];"
2509 " vertices[0] = vec2(-0.5, -0.5);\n"
2510 " vertices[1] = vec2( 0.5, -0.5);\n"
2511 " vertices[2] = vec2( 0.5, 0.5);\n"
2512 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2513 "}\n";
2514
2515 static const char *fragShaderText =
2516 "#version 140\n"
2517 "#extension GL_ARB_separate_shader_objects : enable\n"
2518 "#extension GL_ARB_shading_language_420pack : enable\n"
2519 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2520 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2521 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2522 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2523 "void main() {\n"
2524 " gl_FragColor = myBlueVal.color;\n"
2525 " gl_FragColor += myRedVal.color;\n"
2526 "}\n";
2527
2528 ASSERT_NO_FATAL_FAILURE(InitState());
2529 ASSERT_NO_FATAL_FAILURE(InitViewport());
2530
2531 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2532 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2533
2534 // We're going to create a number of uniform buffers, and then allow
2535 // the shader to select which it wants to read from with a binding
2536
2537 // Let's populate the buffers with a single color each:
2538 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2539 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2540 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2541 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2542
2543 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2544 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2545 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2546 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2547
2548 const int redCount = sizeof(redVals) / sizeof(float);
2549 const int greenCount = sizeof(greenVals) / sizeof(float);
2550 const int blueCount = sizeof(blueVals) / sizeof(float);
2551 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2552
2553 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2554 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2555
2556 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2557 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2558
2559 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2560 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2561
2562 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2563 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2564
2565 XglPipelineObj pipelineobj(m_device);
2566 pipelineobj.AddShader(&vs);
2567 pipelineobj.AddShader(&ps);
2568
2569 XglDescriptorSetObj descriptorSet(m_device);
2570 descriptorSet.AttachMemoryView(&redBuffer);
2571 descriptorSet.AttachMemoryView(&greenBuffer);
2572 descriptorSet.AttachMemoryView(&blueBuffer);
2573 descriptorSet.AttachMemoryView(&whiteBuffer);
2574
Tony Barbourdd4c9642015-01-09 12:55:14 -07002575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2576 XglCommandBufferObj cmdBuffer(m_device);
2577 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002578
Tony Barbourdd4c9642015-01-09 12:55:14 -07002579 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2580
2581 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2582
2583#ifdef DUMP_STATE_DOT
2584 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2585 pDSDumpDot((char*)"triTest2.dot");
2586#endif
2587 // render triangle
2588 cmdBuffer.Draw(0, 3, 0, 1);
2589
2590 // finalize recording of the command buffer
2591 cmdBuffer.EndCommandBuffer();
2592 cmdBuffer.QueueCommandBuffer(NULL, 0);
2593
2594 for (int i = 0; i < m_renderTargetCount; i++)
2595 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002596}
2597
2598TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2599{
2600 // This test is the same as TriangleFSUniformBlockBinding, but
2601 // it does not provide an instance name.
2602 // The expected result from this test is a purple triangle
2603
2604 static const char *vertShaderText =
2605 "#version 140\n"
2606 "#extension GL_ARB_separate_shader_objects : enable\n"
2607 "#extension GL_ARB_shading_language_420pack : enable\n"
2608 "void main() {\n"
2609 " vec2 vertices[3];"
2610 " vertices[0] = vec2(-0.5, -0.5);\n"
2611 " vertices[1] = vec2( 0.5, -0.5);\n"
2612 " vertices[2] = vec2( 0.5, 0.5);\n"
2613 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2614 "}\n";
2615
2616 static const char *fragShaderText =
2617 "#version 430\n"
2618 "#extension GL_ARB_separate_shader_objects : enable\n"
2619 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002620 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2621 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2622 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2623 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002624 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002625 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002626 " outColor = blue;\n"
2627 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002628 "}\n";
2629 ASSERT_NO_FATAL_FAILURE(InitState());
2630 ASSERT_NO_FATAL_FAILURE(InitViewport());
2631
2632 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2633 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2634
2635 // We're going to create a number of uniform buffers, and then allow
2636 // the shader to select which it wants to read from with a binding
2637
2638 // Let's populate the buffers with a single color each:
2639 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2640 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2641 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2642 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2643
2644 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2645 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2646 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2647 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2648
2649 const int redCount = sizeof(redVals) / sizeof(float);
2650 const int greenCount = sizeof(greenVals) / sizeof(float);
2651 const int blueCount = sizeof(blueVals) / sizeof(float);
2652 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2653
2654 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2655 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2656
2657 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2658 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2659
2660 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2661 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2662
2663 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002664 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002665
2666 XglPipelineObj pipelineobj(m_device);
2667 pipelineobj.AddShader(&vs);
2668 pipelineobj.AddShader(&ps);
2669
2670 XglDescriptorSetObj descriptorSet(m_device);
2671 descriptorSet.AttachMemoryView(&redBuffer);
2672 descriptorSet.AttachMemoryView(&greenBuffer);
2673 descriptorSet.AttachMemoryView(&blueBuffer);
2674 descriptorSet.AttachMemoryView(&whiteBuffer);
2675
Tony Barbourdd4c9642015-01-09 12:55:14 -07002676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2677 XglCommandBufferObj cmdBuffer(m_device);
2678 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2679
2680 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2681
2682 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2683
2684#ifdef DUMP_STATE_DOT
2685 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2686 pDSDumpDot((char*)"triTest2.dot");
2687#endif
2688 // render triangle
2689 cmdBuffer.Draw(0, 3, 0, 1);
2690
2691 // finalize recording of the command buffer
2692 cmdBuffer.EndCommandBuffer();
2693 cmdBuffer.QueueCommandBuffer(NULL, 0);
2694
2695 for (int i = 0; i < m_renderTargetCount; i++)
2696 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002697
2698}
2699
2700TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2701{
2702 static const char *vertShaderText =
2703 "#version 140\n"
2704 "#extension GL_ARB_separate_shader_objects : enable\n"
2705 "#extension GL_ARB_shading_language_420pack : enable\n"
2706 "layout (std140, binding=0) uniform bufferVals {\n"
2707 " mat4 mvp;\n"
2708 "} myBufferVals;\n"
2709 "layout (location=0) in vec4 pos;\n"
2710 "layout (location=0) out vec2 UV;\n"
2711 "void main() {\n"
2712 " vec2 positions[3];"
2713 " positions[0] = vec2( 0.0, 0.0);\n"
2714 " positions[1] = vec2( 0.25, 0.1);\n"
2715 " positions[2] = vec2( 0.1, 0.25);\n"
2716 " UV = positions[gl_VertexID % 3];\n"
2717 " gl_Position = myBufferVals.mvp * pos;\n"
2718 "}\n";
2719
2720 static const char *fragShaderText =
2721 "#version 140\n"
2722 "#extension GL_ARB_separate_shader_objects : enable\n"
2723 "#extension GL_ARB_shading_language_420pack : enable\n"
2724 "layout (binding=0) uniform sampler2D surface;\n"
2725 "layout (location=0) out vec4 outColor;\n"
2726 "layout (location=0) in vec2 UV;\n"
2727 "void main() {\n"
2728 " outColor= textureLod(surface, UV, 0.0);\n"
2729 "}\n";
2730 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2731
2732 glm::mat4 View = glm::lookAt(
2733 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2734 glm::vec3(0,0,0), // and looks at the origin
2735 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2736 );
2737
2738 glm::mat4 Model = glm::mat4(1.0f);
2739
2740 glm::mat4 MVP = Projection * View * Model;
2741
2742
2743 ASSERT_NO_FATAL_FAILURE(InitState());
2744 ASSERT_NO_FATAL_FAILURE(InitViewport());
2745 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2746
2747 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2748 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Tony Barboure6152042014-12-10 17:40:15 -07002749 meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
Tony Barbourf43b6982014-11-25 13:18:32 -07002750
2751
2752 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2753
2754 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2755 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2756 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2757 XglSamplerObj sampler(m_device);
2758 XglTextureObj texture(m_device);
2759
2760 // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2761 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002762 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002763 ps.BindShaderEntitySlotToSampler(0, &sampler);
2764
2765 XglPipelineObj pipelineobj(m_device);
2766 pipelineobj.AddShader(&vs);
2767 pipelineobj.AddShader(&ps);
2768
2769 XglDescriptorSetObj descriptorSet(m_device);
2770
2771 descriptorSet.AttachMemoryView(&mvpBuffer);
2772 descriptorSet.AttachImageView(&texture);
2773 descriptorSet.AttachSampler(&sampler);
2774
2775 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2776 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2777 m_memoryRefManager.AddMemoryRef(&texture);
2778
2779 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2780 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2781 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2782 };
2783
2784 // this is the current description of g_vbData
2785 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2786 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2787 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2788 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2789 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2790 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2791 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2792 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2793 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2794
2795 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2796 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2797 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2798
Tony Barbourdd4c9642015-01-09 12:55:14 -07002799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2800 XglCommandBufferObj cmdBuffer(m_device);
2801 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002802
Tony Barbourdd4c9642015-01-09 12:55:14 -07002803 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2804 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2805
2806 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2807#ifdef DUMP_STATE_DOT
2808 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2809 pDSDumpDot((char*)"triTest2.dot");
2810#endif
2811 // render triangle
2812 cmdBuffer.Draw(0, 36, 0, 1);
2813
2814 // finalize recording of the command buffer
2815 cmdBuffer.EndCommandBuffer();
2816 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2817
2818 for (int i = 0; i < m_renderTargetCount; i++)
2819 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002820
2821}
Cody Northropd1ce7842014-12-09 11:17:01 -07002822
2823TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2824{
2825 // This test mixes binding slots of textures and buffers, ensuring
2826 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002827 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002828 // you can modify it to move the desired result around.
2829
2830 static const char *vertShaderText =
2831 "#version 140\n"
2832 "#extension GL_ARB_separate_shader_objects : enable\n"
2833 "#extension GL_ARB_shading_language_420pack : enable\n"
2834 "void main() {\n"
2835 " vec2 vertices[3];"
2836 " vertices[0] = vec2(-0.5, -0.5);\n"
2837 " vertices[1] = vec2( 0.5, -0.5);\n"
2838 " vertices[2] = vec2( 0.5, 0.5);\n"
2839 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2840 "}\n";
2841
2842 static const char *fragShaderText =
2843 "#version 430\n"
2844 "#extension GL_ARB_separate_shader_objects : enable\n"
2845 "#extension GL_ARB_shading_language_420pack : enable\n"
2846 "layout (binding = 0) uniform sampler2D surface0;\n"
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002847 "layout (binding = 9) uniform sampler2D surface1;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002848 "layout (binding = 2) uniform sampler2D surface2;\n"
Cody Northropa0410942014-12-09 13:59:39 -07002849 "layout (binding = 4) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002850
Cody Northropa0410942014-12-09 13:59:39 -07002851
2852 "layout (std140, binding = 10) uniform redVal { vec4 red; };"
2853 "layout (std140, binding = 15) uniform greenVal { vec4 green; };"
2854 "layout (std140, binding = 13) uniform blueVal { vec4 blue; };"
2855 "layout (std140, binding = 17) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002856 "layout (location = 0) out vec4 outColor;\n"
2857 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002858 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002859 " outColor += white * vec4(0.00001);\n"
2860 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002861 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002862 "}\n";
2863 ASSERT_NO_FATAL_FAILURE(InitState());
2864 ASSERT_NO_FATAL_FAILURE(InitViewport());
2865
2866 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2867 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2868
Cody Northropd1ce7842014-12-09 11:17:01 -07002869 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2870 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2871 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2872 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2873
2874 const int redCount = sizeof(redVals) / sizeof(float);
2875 const int greenCount = sizeof(greenVals) / sizeof(float);
2876 const int blueCount = sizeof(blueVals) / sizeof(float);
2877 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2878
2879 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropa0410942014-12-09 13:59:39 -07002880 ps.BindShaderEntitySlotToMemory(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002881
2882 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropa0410942014-12-09 13:59:39 -07002883 ps.BindShaderEntitySlotToMemory(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002884
2885 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropa0410942014-12-09 13:59:39 -07002886 ps.BindShaderEntitySlotToMemory(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002887
2888 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropa0410942014-12-09 13:59:39 -07002889 ps.BindShaderEntitySlotToMemory(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002890
2891 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002892 XglTextureObj texture0(m_device); // Light Red
2893 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002894 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
Cody Northropd1ce7842014-12-09 11:17:01 -07002895 ps.BindShaderEntitySlotToSampler(0, &sampler0);
2896 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002897 XglTextureObj texture2(m_device); // Light Blue
2898 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002899 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
Cody Northropd1ce7842014-12-09 11:17:01 -07002900 ps.BindShaderEntitySlotToSampler(2, &sampler2);
2901 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002902 XglTextureObj texture4(m_device); // Light Green
2903 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002904 ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
Cody Northropd1ce7842014-12-09 11:17:01 -07002905 ps.BindShaderEntitySlotToSampler(4, &sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002906
2907 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2908 // TODO: Get back here ASAP and understand why.
2909 XglSamplerObj sampler7(m_device);
2910 XglTextureObj texture7(m_device); // Red and Blue
2911 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Courtney Goeltzenleuchter6cbffef2014-12-11 09:03:03 -07002912 ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
2913 ps.BindShaderEntitySlotToSampler(9, &sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002914
2915
2916 XglPipelineObj pipelineobj(m_device);
2917 pipelineobj.AddShader(&vs);
2918 pipelineobj.AddShader(&ps);
2919
2920 XglDescriptorSetObj descriptorSet(m_device);
2921 descriptorSet.AttachMemoryView(&redBuffer);
2922 descriptorSet.AttachMemoryView(&greenBuffer);
2923 descriptorSet.AttachMemoryView(&blueBuffer);
2924 descriptorSet.AttachMemoryView(&whiteBuffer);
2925 descriptorSet.AttachImageView(&texture0);
2926 descriptorSet.AttachSampler(&sampler0);
2927 descriptorSet.AttachImageView(&texture2);
2928 descriptorSet.AttachSampler(&sampler2);
2929 descriptorSet.AttachImageView(&texture4);
2930 descriptorSet.AttachSampler(&sampler4);
Cody Northropa0410942014-12-09 13:59:39 -07002931 descriptorSet.AttachImageView(&texture7);
2932 descriptorSet.AttachSampler(&sampler7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002933
2934 m_memoryRefManager.AddMemoryRef(&texture0);
2935 m_memoryRefManager.AddMemoryRef(&texture2);
2936 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002937 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002938
Tony Barbourdd4c9642015-01-09 12:55:14 -07002939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2940 XglCommandBufferObj cmdBuffer(m_device);
2941 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002942
Tony Barbourdd4c9642015-01-09 12:55:14 -07002943 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
2944
2945 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2946
2947#ifdef DUMP_STATE_DOT
2948 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2949 pDSDumpDot((char*)"triTest2.dot");
2950#endif
2951 // render triangle
2952 cmdBuffer.Draw(0, 3, 0, 1);
2953
2954 // finalize recording of the command buffer
2955 cmdBuffer.EndCommandBuffer();
2956 cmdBuffer.QueueCommandBuffer(NULL, 0);
2957
2958 for (int i = 0; i < m_renderTargetCount; i++)
2959 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002960
2961}
2962
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002963TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2964{
2965 // This test matches binding slots of textures and buffers, requiring
2966 // the driver to give them distinct number spaces.
2967 // The expected result from this test is a red triangle, although
2968 // you can modify it to move the desired result around.
2969
2970 static const char *vertShaderText =
2971 "#version 140\n"
2972 "#extension GL_ARB_separate_shader_objects : enable\n"
2973 "#extension GL_ARB_shading_language_420pack : enable\n"
2974 "void main() {\n"
2975 " vec2 vertices[3];"
2976 " vertices[0] = vec2(-0.5, -0.5);\n"
2977 " vertices[1] = vec2( 0.5, -0.5);\n"
2978 " vertices[2] = vec2( 0.5, 0.5);\n"
2979 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2980 "}\n";
2981
2982 static const char *fragShaderText =
2983 "#version 430\n"
2984 "#extension GL_ARB_separate_shader_objects : enable\n"
2985 "#extension GL_ARB_shading_language_420pack : enable\n"
2986 "layout (binding = 0) uniform sampler2D surface0;\n"
2987 "layout (binding = 1) uniform sampler2D surface1;\n"
2988 "layout (binding = 2) uniform sampler2D surface2;\n"
2989 "layout (binding = 3) uniform sampler2D surface3;\n"
2990 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2991 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2992 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2993 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2994 "layout (location = 0) out vec4 outColor;\n"
2995 "void main() {\n"
2996 " outColor = red;// * vec4(0.00001);\n"
2997 " outColor += white * vec4(0.00001);\n"
2998 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2999 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
3000 "}\n";
3001 ASSERT_NO_FATAL_FAILURE(InitState());
3002 ASSERT_NO_FATAL_FAILURE(InitViewport());
3003
3004 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3005 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3006
3007 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
3008 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
3009 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
3010 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
3011
3012 const int redCount = sizeof(redVals) / sizeof(float);
3013 const int greenCount = sizeof(greenVals) / sizeof(float);
3014 const int blueCount = sizeof(blueVals) / sizeof(float);
3015 const int whiteCount = sizeof(whiteVals) / sizeof(float);
3016
3017 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3018 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
3019
3020 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3021 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
3022
3023 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3024 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
3025
3026 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
3027 ps.BindShaderEntitySlotToMemory(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
3028
3029 XglSamplerObj sampler0(m_device);
3030 XglTextureObj texture0(m_device); // Light Red
3031 texture0.ChangeColors(0xff800000,0xff800000);
3032 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0);
3033 ps.BindShaderEntitySlotToSampler(0, &sampler0);
3034 XglSamplerObj sampler2(m_device);
3035 XglTextureObj texture2(m_device); // Light Blue
3036 texture2.ChangeColors(0xff000080,0xff000080);
3037 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2);
3038 ps.BindShaderEntitySlotToSampler(1, &sampler2);
3039 XglSamplerObj sampler4(m_device);
3040 XglTextureObj texture4(m_device); // Light Green
3041 texture4.ChangeColors(0xff008000,0xff008000);
3042 ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4);
3043 ps.BindShaderEntitySlotToSampler(2, &sampler4);
3044 XglSamplerObj sampler7(m_device);
3045 XglTextureObj texture7(m_device); // Red and Blue
3046 texture7.ChangeColors(0xffff00ff,0xffff00ff);
3047 ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7);
3048 ps.BindShaderEntitySlotToSampler(3, &sampler7);
3049
3050
3051 XglPipelineObj pipelineobj(m_device);
3052 pipelineobj.AddShader(&vs);
3053 pipelineobj.AddShader(&ps);
3054
3055 XglDescriptorSetObj descriptorSet(m_device);
3056 descriptorSet.AttachMemoryView(&redBuffer);
3057 descriptorSet.AttachMemoryView(&greenBuffer);
3058 descriptorSet.AttachMemoryView(&blueBuffer);
3059 descriptorSet.AttachMemoryView(&whiteBuffer);
3060 descriptorSet.AttachImageView(&texture0);
3061 descriptorSet.AttachSampler(&sampler0);
3062 descriptorSet.AttachImageView(&texture2);
3063 descriptorSet.AttachSampler(&sampler2);
3064 descriptorSet.AttachImageView(&texture4);
3065 descriptorSet.AttachSampler(&sampler4);
3066 descriptorSet.AttachImageView(&texture7);
3067 descriptorSet.AttachSampler(&sampler7);
3068
3069 m_memoryRefManager.AddMemoryRef(&texture0);
3070 m_memoryRefManager.AddMemoryRef(&texture2);
3071 m_memoryRefManager.AddMemoryRef(&texture4);
3072 m_memoryRefManager.AddMemoryRef(&texture7);
3073
Tony Barbourdd4c9642015-01-09 12:55:14 -07003074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3075 XglCommandBufferObj cmdBuffer(m_device);
3076 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003077
Tony Barbourdd4c9642015-01-09 12:55:14 -07003078 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0));
3079
3080 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3081
3082#ifdef DUMP_STATE_DOT
3083 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3084 pDSDumpDot((char*)"triTest2.dot");
3085#endif
3086 // render triangle
3087 cmdBuffer.Draw(0, 3, 0, 1);
3088
3089 // finalize recording of the command buffer
3090 cmdBuffer.EndCommandBuffer();
3091 cmdBuffer.QueueCommandBuffer(NULL, 0);
3092
3093 for (int i = 0; i < m_renderTargetCount; i++)
3094 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003095
3096}
3097
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003098int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003099 int result;
3100
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003101 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003102 XglTestFramework::InitArgs(&argc, argv);
3103
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003104 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003105
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003106 result = RUN_ALL_TESTS();
3107
3108 XglTestFramework::Finish();
3109 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003110}