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