blob: d82951e633a8b95d739f3ad9cb709d77c780be22 [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>
64#include "gtest-1.7.0/include/gtest/gtest.h"
65
66#include "xgldevice.h"
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -060067#include "xglimage.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080068#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060069
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060070#include "xglrenderframework.h"
Courtney Goeltzenleuchter2268d1e2014-09-01 13:57:15 -060071
Courtney Goeltzenleuchterbb7014d2014-10-09 11:05:19 -060072#undef ASSERT_NO_FATAL_FAILURE
73#define ASSERT_NO_FATAL_FAILURE(x) x
74
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -060075//--------------------------------------------------------------------------------------
76// Mesh and VertexFormat Data
77//--------------------------------------------------------------------------------------
78struct Vertex
79{
80 XGL_FLOAT posX, posY, posZ, posW; // Position data
81 XGL_FLOAT r, g, b, a; // Color
82};
83
84#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
85
86static const Vertex g_vbData[] =
87{
88 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
89 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
90 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
91 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
92 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
93 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
94
95 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
96 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
97 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
98 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
99 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
100 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
101
102 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
103 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
104 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
105 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
106 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
107 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
108
109 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
110 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
111 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
112 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
113 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
114 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
115
116 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
117 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
118 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
119 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
120 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
121 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
122
123 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
124 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
125 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
126 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
127 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
128 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
129};
130
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600131class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600132{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600133public:
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600134 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
Cody Northrop350727b2014-10-06 15:42:00 -0600135 void InitTexture();
136 void InitSampler();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600137 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600138 void DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText);
Cody Northrop4e6b4762014-10-09 21:25:22 -0600139 void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText);
140
141 void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600142 void DrawRotatedTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600143
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600144
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600145protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600146 XGL_IMAGE m_texture;
147 XGL_IMAGE_VIEW m_textureView;
148 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
149 XGL_GPU_MEMORY m_textureMem;
150
151 XGL_SAMPLER m_sampler;
152
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600153// XGL_APPLICATION_INFO app_info;
154// XGL_PHYSICAL_GPU objs[MAX_GPUS];
155// XGL_UINT gpu_count;
156// XGL_GPU_MEMORY m_descriptor_set_mem;
157// XGL_GPU_MEMORY m_pipe_mem;
158// XglDevice *m_device;
159// XGL_CMD_BUFFER m_cmdBuffer;
160// XGL_UINT32 m_numVertices;
161// XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
162// XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
163// XGL_GPU_MEMORY m_vtxBufferMem;
164// XGL_GPU_MEMORY m_constantBufferMem;
165// XGL_UINT32 m_numMemRefs;
166// XGL_MEMORY_REF m_memRefs[5];
167// XGL_RASTER_STATE_OBJECT m_stateRaster;
168// XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
169// XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
170// XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
171// XGL_MSAA_STATE_OBJECT m_stateMsaa;
172// XGL_DESCRIPTOR_SET m_rsrcDescSet;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600173
174 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600175
176 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
177 this->app_info.pNext = NULL;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600178 this->app_info.pAppName = (const XGL_CHAR *) "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600179 this->app_info.appVersion = 1;
180 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
181 this->app_info.engineVersion = 1;
182 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
183
Cody Northrop350727b2014-10-06 15:42:00 -0600184 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
185 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
186
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600187 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600188 }
189
190 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600191 // Clean up resources before we reset
192 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600193 }
194};
195
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600196// this function will create the vertex buffer and fill it with the mesh data
197void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride,
198 const void* vertices )
199{
200 XGL_RESULT err = XGL_SUCCESS;
201
202 assert( numVertices * vbStride > 0 );
203 m_numVertices = numVertices;
204
205 XGL_MEMORY_ALLOC_INFO alloc_info = {};
206 XGL_UINT8 *pData;
207
208 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
209 alloc_info.allocationSize = numVertices * vbStride;
210 alloc_info.alignment = 0;
211 alloc_info.heapCount = 1;
212 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
213
214 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
215 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
216
217 err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem);
218 ASSERT_XGL_SUCCESS(err);
219
220 err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData);
221 ASSERT_XGL_SUCCESS(err);
222
223 memcpy(pData, vertices, alloc_info.allocationSize);
224
225 err = xglUnmapMemory(m_vtxBufferMem);
226 ASSERT_XGL_SUCCESS(err);
227
228 // set up the memory view for the vertex buffer
229 this->m_vtxBufferView.stride = vbStride;
230 this->m_vtxBufferView.range = numVertices * vbStride;
231 this->m_vtxBufferView.offset = 0;
232 this->m_vtxBufferView.mem = m_vtxBufferMem;
233 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
234 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
235
236 // open the command buffer
237 err = xglBeginCommandBuffer( m_cmdBuffer, 0 );
238 ASSERT_XGL_SUCCESS(err);
239
240 XGL_MEMORY_STATE_TRANSITION transition = {};
241 transition.mem = m_vtxBufferMem;
242 transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER;
243 transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
244 transition.offset = 0;
245 transition.regionSize = numVertices * vbStride;
246
247 // write transition to the command buffer
248 xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition );
249 this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
250
251 // finish recording the command buffer
252 err = xglEndCommandBuffer( m_cmdBuffer );
253 ASSERT_XGL_SUCCESS(err);
254
255 // this command buffer only uses the vertex buffer memory
256 m_numMemRefs = 1;
257 m_memRefs[0].flags = 0;
258 m_memRefs[0].mem = m_vtxBufferMem;
259
260 // submit the command buffer to the universal queue
261 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
262 ASSERT_XGL_SUCCESS(err);
263}
264
Cody Northrop350727b2014-10-06 15:42:00 -0600265void XglRenderTest::InitTexture()
266{
Cody Northrop904742c2014-10-07 16:25:00 -0600267#define DEMO_TEXTURE_COUNT 1
268
269 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
270 const XGL_INT tex_width = 16;
271 const XGL_INT tex_height = 16;
272 const uint32_t tex_colors[DEMO_TEXTURE_COUNT][2] = {
273 { 0xffff0000, 0xff00ff00 },
274 };
Cody Northrop350727b2014-10-06 15:42:00 -0600275 XGL_RESULT err;
Cody Northrop904742c2014-10-07 16:25:00 -0600276 XGL_UINT i;
Cody Northrop350727b2014-10-06 15:42:00 -0600277
Cody Northrop904742c2014-10-07 16:25:00 -0600278 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
279 const XGL_SAMPLER_CREATE_INFO sampler = {
280 .sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
281 .pNext = NULL,
282 .magFilter = XGL_TEX_FILTER_NEAREST,
283 .minFilter = XGL_TEX_FILTER_NEAREST,
284 .mipMode = XGL_TEX_MIPMAP_BASE,
285 .addressU = XGL_TEX_ADDRESS_WRAP,
286 .addressV = XGL_TEX_ADDRESS_WRAP,
287 .addressW = XGL_TEX_ADDRESS_WRAP,
288 .mipLodBias = 0.0f,
289 .maxAnisotropy = 0,
290 .compareFunc = XGL_COMPARE_NEVER,
291 .minLod = 0.0f,
292 .maxLod = 0.0f,
293 .borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE,
294 };
295 const XGL_IMAGE_CREATE_INFO image = {
296 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
297 .pNext = NULL,
298 .imageType = XGL_IMAGE_2D,
299 .format = tex_format,
300 .extent = { tex_width, tex_height, 1 },
301 .mipLevels = 1,
302 .arraySize = 1,
303 .samples = 1,
304 .tiling = XGL_LINEAR_TILING,
305 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
306 .flags = 0,
307 };
308 XGL_MEMORY_ALLOC_INFO mem_alloc;
309 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
310 mem_alloc.pNext = NULL;
311 mem_alloc.allocationSize = 0;
312 mem_alloc.alignment = 0;
313 mem_alloc.flags = 0;
314 mem_alloc.heapCount = 0;
315 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
316 XGL_IMAGE_VIEW_CREATE_INFO view;
317 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
318 view.pNext = NULL;
319 view.image = XGL_NULL_HANDLE;
320 view.viewType = XGL_IMAGE_VIEW_2D;
321 view.format = image.format;
322 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
323 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
324 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
325 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
326 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
327 view.subresourceRange.baseMipLevel = 0;
328 view.subresourceRange.mipLevels = 1;
329 view.subresourceRange.baseArraySlice = 0;
330 view.subresourceRange.arraySize = 1;
331 view.minLod = 0.0f;
Cody Northrop350727b2014-10-06 15:42:00 -0600332
Cody Northrop904742c2014-10-07 16:25:00 -0600333 XGL_MEMORY_REQUIREMENTS mem_reqs;
334 XGL_SIZE mem_reqs_size;
Cody Northrop350727b2014-10-06 15:42:00 -0600335
Cody Northrop904742c2014-10-07 16:25:00 -0600336 /* create sampler */
337 err = xglCreateSampler(device(), &sampler, &m_sampler);
338 assert(!err);
339
340 /* create image */
341 err = xglCreateImage(device(), &image, &m_texture);
342 assert(!err);
343
344 err = xglGetObjectInfo(m_texture,
345 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
346 &mem_reqs_size, &mem_reqs);
347 assert(!err && mem_reqs_size == sizeof(mem_reqs));
348
349 mem_alloc.allocationSize = mem_reqs.size;
350 mem_alloc.alignment = mem_reqs.alignment;
351 mem_alloc.heapCount = mem_reqs.heapCount;
352 memcpy(mem_alloc.heaps, mem_reqs.heaps,
353 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
354
355 /* allocate memory */
356 err = xglAllocMemory(device(), &mem_alloc, &m_textureMem);
357 assert(!err);
358
359 /* bind memory */
360 err = xglBindObjectMemory(m_texture, m_textureMem, 0);
361 assert(!err);
362
363 /* create image view */
364 view.image = m_texture;
365 err = xglCreateImageView(device(), &view, &m_textureView);
366 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600367 }
368
Cody Northrop904742c2014-10-07 16:25:00 -0600369 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
370 const XGL_IMAGE_SUBRESOURCE subres = {
371 .aspect = XGL_IMAGE_ASPECT_COLOR,
372 .mipLevel = 0,
373 .arraySlice = 0,
374 };
375 XGL_SUBRESOURCE_LAYOUT layout;
376 XGL_SIZE layout_size;
377 XGL_VOID *data;
378 XGL_INT x, y;
Cody Northrop350727b2014-10-06 15:42:00 -0600379
Cody Northrop904742c2014-10-07 16:25:00 -0600380 err = xglGetImageSubresourceInfo(m_texture, &subres,
381 XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout);
382 assert(!err && layout_size == sizeof(layout));
Cody Northrop350727b2014-10-06 15:42:00 -0600383
Cody Northrop904742c2014-10-07 16:25:00 -0600384 err = xglMapMemory(m_textureMem, 0, &data);
385 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600386
Cody Northrop904742c2014-10-07 16:25:00 -0600387 for (y = 0; y < tex_height; y++) {
388 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
389 for (x = 0; x < tex_width; x++)
390 row[x] = tex_colors[i][(x & 1) ^ (y & 1)];
Cody Northrop350727b2014-10-06 15:42:00 -0600391 }
Cody Northrop904742c2014-10-07 16:25:00 -0600392
393 err = xglUnmapMemory(m_textureMem);
394 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600395 }
396
Cody Northrop350727b2014-10-06 15:42:00 -0600397 m_textureViewInfo.view = m_textureView;
398}
399
400void XglRenderTest::InitSampler()
401{
402 XGL_RESULT err;
403
404 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
405 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
406 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
407 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
408 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
409 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
410 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
411 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
412 samplerCreateInfo.mipLodBias = 0.0;
413 samplerCreateInfo.maxAnisotropy = 0.0;
414 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
415 samplerCreateInfo.minLod = 0.0;
416 samplerCreateInfo.maxLod = 0.0;
417 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
418
419 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler);
420 ASSERT_XGL_SUCCESS(err);
421}
422
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600423void XglRenderTest::DrawRotatedTriangleTest()
424{
425 // TODO : This test will pass a matrix into VS to affect triangle orientation.
426}
427
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600428void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600429{
430 XGL_PIPELINE pipeline;
431 XGL_SHADER vs, ps;
432 XGL_RESULT err;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600433
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600434 ASSERT_NO_FATAL_FAILURE(InitState());
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600435 ASSERT_NO_FATAL_FAILURE(InitViewport());
436
437 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
438 vertShaderText, &vs));
439
440 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
441 fragShaderText, &ps));
442
443 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600444
445 /*
446 * Shaders are now part of the pipeline, don't need these anymore
447 */
448 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
449 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
450
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600452
Cody Northrop342912c2014-10-01 14:03:25 -0600453 const int constantCount = 4;
454 const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 };
455 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
456
457 // Create descriptor set for a uniform resource
458 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
459 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
460 descriptorInfo.slots = 1;
461
462 // create a descriptor set with a single slot
463 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
464 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
465
466 // bind memory to the descriptor set
467 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
468
469 // write the constant buffer view to the descriptor set
470 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
471 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
472 xglEndDescriptorSetUpdate( m_rsrcDescSet );
473
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600474 // Build command buffer
475 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
476 ASSERT_XGL_SUCCESS(err);
477
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600478 GenerateClearAndPrepareBufferCmds();
479 GenerateBindRenderTargetCmd();
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600480 GenerateBindStateAndPipelineCmds(&pipeline);
481
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600482// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
483// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
484
485 // render the cube
486 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
487
488 // prepare the back buffer for present
489// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
490// transitionToPresent.image = m_image;
491// transitionToPresent.oldState = m_image_state;
492// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
493// transitionToPresent.subresourceRange = srRange;
494// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
495// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
496
497 // finalize recording of the command buffer
498 err = xglEndCommandBuffer( m_cmdBuffer );
499 ASSERT_XGL_SUCCESS( err );
500
501 // this command buffer only uses the vertex buffer memory
502 m_numMemRefs = 0;
503// m_memRefs[0].flags = 0;
504// m_memRefs[0].mem = m_vtxBufferMemory;
505
506 // submit the command buffer to the universal queue
507 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
508 ASSERT_XGL_SUCCESS( err );
509
Chia-I Wuf34ac502014-08-27 14:58:05 +0800510 err = xglQueueWaitIdle( m_device->m_queue );
511 ASSERT_XGL_SUCCESS( err );
512
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600513 // Wait for work to finish before cleaning up.
514 xglDeviceWaitIdle(m_device->device());
515
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600516 RecordImage(m_renderTarget);
Chia-I Wuf070ec12014-08-30 23:58:36 +0800517
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600518}
519
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600520void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600521{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600522 XGL_PIPELINE pipeline;
523 XGL_SHADER vs, ps;
524 XGL_RESULT err;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600525
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600526 ASSERT_NO_FATAL_FAILURE(InitState());
527 ASSERT_NO_FATAL_FAILURE(InitViewport());
528
529 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
530 vertShaderText, &vs));
531
532 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
533 fragShaderText, &ps));
534
535 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
536
537 /*
538 * Shaders are now part of the pipeline, don't need these anymore
539 */
540 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
541 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
542
543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
544
545 const int constantCount = 8;
546 const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0,
547 0.0, 0.0, 1.0, 1.0 };
548
549 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
550
551 // Create descriptor set for a uniform resource
552 const int slotCount = 1;
553 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
554 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
555 descriptorInfo.slots = slotCount;
556
557 // create a descriptor set with a single slot
558 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
559 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
560
561 // bind memory to the descriptor set
562 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
563
564 // write the constant buffer view to the descriptor set
565 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
566 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
567 xglEndDescriptorSetUpdate( m_rsrcDescSet );
568
569 // Build command buffer
570 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
571 ASSERT_XGL_SUCCESS(err);
572
573 GenerateClearAndPrepareBufferCmds();
574 GenerateBindRenderTargetCmd();
575 GenerateBindStateAndPipelineCmds(&pipeline);
576
577// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
578// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
579
580 // render the cube
581 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
582
583 // prepare the back buffer for present
584// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
585// transitionToPresent.image = m_image;
586// transitionToPresent.oldState = m_image_state;
587// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
588// transitionToPresent.subresourceRange = srRange;
589// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
590// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
591
592 // finalize recording of the command buffer
593 err = xglEndCommandBuffer( m_cmdBuffer );
594 ASSERT_XGL_SUCCESS( err );
595
596 // this command buffer only uses the vertex buffer memory
597 m_numMemRefs = 0;
598// m_memRefs[0].flags = 0;
599// m_memRefs[0].mem = m_vtxBufferMemory;
600
601 // submit the command buffer to the universal queue
602 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
603 ASSERT_XGL_SUCCESS( err );
604
605 err = xglQueueWaitIdle( m_device->m_queue );
606 ASSERT_XGL_SUCCESS( err );
607
608 // Wait for work to finish before cleaning up.
609 xglDeviceWaitIdle(m_device->device());
610
611 RecordImage(m_renderTarget);
612
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600613}
614
Cody Northrop4e6b4762014-10-09 21:25:22 -0600615void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
616{
617 XGL_RESULT err;
618 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
619 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
620 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
621
622
623 // Create descriptor set for our one resource
624 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
625 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
626 descriptorInfo.slots = 1; // Vertex buffer only
627
628 // create a descriptor set with a single slot
629 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
630 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
631
632 // bind memory to the descriptor set
633 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
634
635 // write the vertex buffer view to the descriptor set
636 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
637 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView );
638 xglEndDescriptorSetUpdate( m_rsrcDescSet );
639
640 const int slots = 1;
641 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
642 slotInfo[0].shaderEntityIndex = 0;
643 slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT;
644
645 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
646 vs_stage.pNext = XGL_NULL_HANDLE;
647 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
648 vs_stage.shader.shader = vs;
649 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
650 vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots;
651 vs_stage.shader.linkConstBufferCount = 0;
652 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
653 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
654 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
655
656 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
657 ps_stage.pNext = &vs_stage;
658 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
659 ps_stage.shader.shader = ps;
660 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
661 ps_stage.shader.linkConstBufferCount = 0;
662 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
663 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
664 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
665
666 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
667 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
668 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
669 };
670
671 // this is the current description of g_vbData
672 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
673 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
674 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
675 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
676 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
677 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
678 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
679 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
680 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
681
682 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = {
683 XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType;
684 &ps_stage, // pNext;
685 1, // bindingCount
686 &vi_binding, // pVertexBindingDescriptions;
687 2, // attributeCount; // number of attributes
688 vi_attribs // pVertexAttributeDescriptions;
689 };
690
691 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
692 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
693 &vi_state, // pNext
694 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
695 XGL_FALSE, // disableVertexReuse
696 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
697 XGL_FALSE, // primitiveRestartEnable
698 0 // primitiveRestartIndex
699 };
700
701 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
702 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
703 &ia_state,
704 XGL_FALSE, // depthClipEnable
705 XGL_FALSE, // rasterizerDiscardEnable
706 1.0 // pointSize
707 };
708
709 XGL_PIPELINE_CB_STATE cb_state = {
710 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
711 &rs_state,
712 XGL_FALSE, // alphaToCoverageEnable
713 XGL_FALSE, // dualSourceBlendEnable
714 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
715 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
716 {
717 XGL_FALSE, // blendEnable
718 m_render_target_fmt, // XGL_FORMAT
719 0xF // channelWriteMask
720 }
721 }
722 };
723
724 // TODO: Should take depth buffer format from queried formats
725 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
726 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
727 &cb_state,
728 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
729 };
730
731 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
732 info.pNext = &db_state;
733 info.flags = 0;
734 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
735 ASSERT_XGL_SUCCESS(err);
736
737 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
738 ASSERT_XGL_SUCCESS(err);
739}
740
741void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
742{
743 XGL_PIPELINE pipeline;
744 XGL_SHADER vs, ps;
745 XGL_RESULT err;
746
747 ASSERT_NO_FATAL_FAILURE(InitState());
748 ASSERT_NO_FATAL_FAILURE(InitViewport());
749 ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData));
750
751 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
752 vertShaderText, &vs));
753
754 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
755 fragShaderText, &ps));
756
757 ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps));
758
759 /*
760 * Shaders are now part of the pipeline, don't need these anymore
761 */
762 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
763 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
764
765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
766
767 // Build command buffer
768 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
769 ASSERT_XGL_SUCCESS(err);
770
771 GenerateClearAndPrepareBufferCmds();
772 GenerateBindRenderTargetCmd();
773 GenerateBindStateAndPipelineCmds(&pipeline);
774
775// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
776// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
777
778 // render the cube
Courtney Goeltzenleuchtere2a5a092014-10-10 09:52:27 -0600779 xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 );
Cody Northrop4e6b4762014-10-09 21:25:22 -0600780
781 // prepare the back buffer for present
782// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
783// transitionToPresent.image = m_image;
784// transitionToPresent.oldState = m_image_state;
785// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
786// transitionToPresent.subresourceRange = srRange;
787// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
788// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
789
790 // finalize recording of the command buffer
791 err = xglEndCommandBuffer( m_cmdBuffer );
792 ASSERT_XGL_SUCCESS( err );
793
794 // this command buffer only uses the vertex buffer memory
795 m_numMemRefs = 0;
796// m_memRefs[0].flags = 0;
797// m_memRefs[0].mem = m_vtxBufferMemory;
798
799 // submit the command buffer to the universal queue
800 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
801 ASSERT_XGL_SUCCESS( err );
802
803 err = xglQueueWaitIdle( m_device->m_queue );
804 ASSERT_XGL_SUCCESS( err );
805
806 // Wait for work to finish before cleaning up.
807 xglDeviceWaitIdle(m_device->device());
808
809 RecordImage(m_renderTarget);
810
811}
812
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600813TEST_F(XglRenderTest, TestDrawTriangle1)
814{
815 static const char *vertShaderText =
816 "#version 130\n"
817 "vec2 vertices[3];\n"
818 "void main() {\n"
819 " vertices[0] = vec2(-1.0, -1.0);\n"
820 " vertices[1] = vec2( 1.0, -1.0);\n"
821 " vertices[2] = vec2( 0.0, 1.0);\n"
822 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
823 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600824
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600825 static const char *fragShaderText =
826 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600827 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600828 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600829 "}\n";
830 DrawTriangleTest(vertShaderText, fragShaderText);
831}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600832
Courtney Goeltzenleuchterd4ee38d2014-10-10 13:59:38 -0600833TEST_F(XglRenderTest, BIL_GreenTriangle)
834{
835 bool saved_use_bil = XglTestFramework::m_use_bil;
836
837 static const char *vertShaderText =
838 "#version 130\n"
839 "vec2 vertices[3];\n"
840 "void main() {\n"
841 " vertices[0] = vec2(-1.0, -1.0);\n"
842 " vertices[1] = vec2( 1.0, -1.0);\n"
843 " vertices[2] = vec2( 0.0, 1.0);\n"
844 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
845 "}\n";
846
847 static const char *fragShaderText =
848 "#version 130\n"
849 "void main() {\n"
850 " gl_FragColor = vec4(0,1,0,1);\n"
851 "}\n";
852 XglTestFramework::m_use_bil = true;
853 DrawTriangleTest(vertShaderText, fragShaderText);
854 XglTestFramework::m_use_bil = saved_use_bil;
855}
856
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600857TEST_F(XglRenderTest, TestDrawTriangle2)
858{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600859
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600860 static const char *vertShaderText =
861 "#version 130\n"
862 "out vec4 color;\n"
863 "out vec4 scale;\n"
864 "vec2 vertices[3];\n"
865 "void main() {\n"
866 "vec2 vertices[3];\n"
867 " vertices[0] = vec2(-0.5, -0.5);\n"
868 " vertices[1] = vec2( 0.5, -0.5);\n"
869 " vertices[2] = vec2( 0.5, 0.5);\n"
870 "vec4 colors[3];\n"
871 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
872 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
873 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
874 " color = colors[gl_VertexID % 3];\n"
875 " scale = vec4(1.0, 1.0, 1.0, 1.0);\n"
876 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
877 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600878
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600879 static const char *fragShaderText =
880 "#version 130\n"
881 "in vec4 color;\n"
882 "in vec4 scale;\n"
883 "uniform vec4 foo;\n"
884 "void main() {\n"
885 " gl_FragColor = color * scale + foo;\n"
886 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600887
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600888 DrawTriangleTest(vertShaderText, fragShaderText);
889}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600890
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600891TEST_F(XglRenderTest, TestDrawTriangle3)
892{
893 static const char *vertShaderText =
894 "#version 130\n"
895 "void main() {\n"
896 " vec2 vertices[3];"
897 " vertices[0] = vec2(-0.5, -0.5);\n"
898 " vertices[1] = vec2( 0.5, -0.5);\n"
899 " vertices[2] = vec2( 0.5, 0.5);\n"
900 " vec4 colors[3];\n"
901 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
902 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
903 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
904 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
905 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600906
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600907 static const char *fragShaderText =
908 "#version 130\n"
909 "void main() {\n"
910 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
911 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600912
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600913 DrawTriangleTest(vertShaderText, fragShaderText);
914}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600915
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600916TEST_F(XglRenderTest, TestDrawRotatedTriangle) {
917 DrawRotatedTriangleTest();
918}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600919
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600920TEST_F(XglRenderTest, TestDrawTriangleTwoFSUniforms)
921{
922 static const char *vertShaderText =
923 "#version 130\n"
924 "out vec4 color;\n"
925 "out vec4 scale;\n"
926 "out vec2 samplePos;\n"
927 "void main() {\n"
928 " vec2 vertices[3];"
929 " vertices[0] = vec2(-0.5, -0.5);\n"
930 " vertices[1] = vec2( 0.5, -0.5);\n"
931 " vertices[2] = vec2( 0.5, 0.5);\n"
932 " vec4 colors[3];\n"
933 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
934 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
935 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
936 " color = colors[gl_VertexID % 3];\n"
937 " vec2 positions[3];"
938 " positions[0] = vec2( 0.0, 0.0);\n"
939 " positions[1] = vec2( 1.0, 0.0);\n"
940 " positions[2] = vec2( 1.0, 1.0);\n"
941 " scale = vec4(0.0, 0.0, 0.0, 0.0);\n"
942 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
943 "}\n";
Cody Northrop4e6b4762014-10-09 21:25:22 -0600944
945
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600946 static const char *fragShaderText =
947 "#version 430\n"
948 "in vec4 color;\n"
949 "in vec4 scale;\n"
950 "uniform vec4 foo;\n"
951 "uniform vec4 bar;\n"
952 "void main() {\n"
953 // by default, with no location or blocks
954 // the compiler will read them from buffer
955 // in reverse order of first use in shader
956 // The buffer contains red, followed by blue,
957 // so foo should be blue, bar should be red
958 " gl_FragColor = color * scale * foo * bar + foo;\n"
959 "}\n";
Cody Northrop4e6b4762014-10-09 21:25:22 -0600960
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600961 DrawTriangleTwoUniformsFS(vertShaderText, fragShaderText);
962}
Cody Northrop4e6b4762014-10-09 21:25:22 -0600963
964TEST_F(XglRenderTest, TestDrawTriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600965{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600966 static const char *vertShaderText =
Courtney Goeltzenleuchterbb7014d2014-10-09 11:05:19 -0600967 "#version 130\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600968 //XYZ1( -1, -1, -1 )
969 "in vec4 pos;\n"
970 //XYZ1( 0.f, 0.f, 0.f )
971 "in vec4 inColor;\n"
972 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600973 "void main() {\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600974 " outColor = inColor;\n"
975 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600976 "}\n";
977
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600978
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600979 static const char *fragShaderText =
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600980 "#version 430\n"
981 "in vec4 color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600982 "void main() {\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600983 " gl_FragColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600984 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600985
Cody Northrop4e6b4762014-10-09 21:25:22 -0600986 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600987}
988
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600989int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600990 int result;
991
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600992 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600993 XglTestFramework::InitArgs(&argc, argv);
994
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -0600995 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
996
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600997 result = RUN_ALL_TESTS();
998
999 XglTestFramework::Finish();
1000 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001001}