blob: 7eab599085f930eb216850c987add8b3277bb8f4 [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 Goeltzenleuchter34b81772014-10-10 18:04:39 -060070#define GLM_FORCE_RADIANS
71#include "glm/glm.hpp"
72#include <glm/gtc/matrix_transform.hpp>
73
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060074#include "xglrenderframework.h"
Courtney Goeltzenleuchter2268d1e2014-09-01 13:57:15 -060075
Courtney Goeltzenleuchterbb7014d2014-10-09 11:05:19 -060076#undef ASSERT_NO_FATAL_FAILURE
77#define ASSERT_NO_FATAL_FAILURE(x) x
78
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -060079//--------------------------------------------------------------------------------------
80// Mesh and VertexFormat Data
81//--------------------------------------------------------------------------------------
82struct Vertex
83{
84 XGL_FLOAT posX, posY, posZ, posW; // Position data
85 XGL_FLOAT r, g, b, a; // Color
86};
87
88#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
89
90static const Vertex g_vbData[] =
91{
92 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
93 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
94 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
95 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
96 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
97 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
98
99 { XYZ1( -1, -1, 1 ), XYZ1( 0.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, 0.f, 1.f ) },
102 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
103 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
104 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
105
106 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.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, 1.f ) },
109 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
110 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
111 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
112
113 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
114 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
115 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
116 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
117 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
118 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
119
120 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
121 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
122 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
123 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
124 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
125 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
126
127 { XYZ1( 1, -1, 1 ), XYZ1( 1.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, 1.f ) },
130 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
131 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
132 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
133};
134
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600135class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600136{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600137public:
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600138 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
Cody Northrop350727b2014-10-06 15:42:00 -0600139 void InitTexture();
140 void InitSampler();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600141 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600142 void DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText);
Cody Northrop4e6b4762014-10-09 21:25:22 -0600143 void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600144 void DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText);
Cody Northrop4e6b4762014-10-09 21:25:22 -0600145
146 void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Cody Northrop7a1f0462014-10-10 14:49:36 -0600147 void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600148 void DrawRotatedTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600149
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600150
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600151protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600152 XGL_IMAGE m_texture;
153 XGL_IMAGE_VIEW m_textureView;
154 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
155 XGL_GPU_MEMORY m_textureMem;
156
157 XGL_SAMPLER m_sampler;
158
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600159// XGL_APPLICATION_INFO app_info;
160// XGL_PHYSICAL_GPU objs[MAX_GPUS];
161// XGL_UINT gpu_count;
162// XGL_GPU_MEMORY m_descriptor_set_mem;
163// XGL_GPU_MEMORY m_pipe_mem;
164// XglDevice *m_device;
165// XGL_CMD_BUFFER m_cmdBuffer;
166// XGL_UINT32 m_numVertices;
167// XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
168// XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
169// XGL_GPU_MEMORY m_vtxBufferMem;
170// XGL_GPU_MEMORY m_constantBufferMem;
171// XGL_UINT32 m_numMemRefs;
172// XGL_MEMORY_REF m_memRefs[5];
173// XGL_RASTER_STATE_OBJECT m_stateRaster;
174// XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
175// XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
176// XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
177// XGL_MSAA_STATE_OBJECT m_stateMsaa;
178// XGL_DESCRIPTOR_SET m_rsrcDescSet;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600179
180 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600181
182 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
183 this->app_info.pNext = NULL;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600184 this->app_info.pAppName = (const XGL_CHAR *) "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600185 this->app_info.appVersion = 1;
186 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
187 this->app_info.engineVersion = 1;
188 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
189
Cody Northrop350727b2014-10-06 15:42:00 -0600190 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
191 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
192
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600193 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600194 }
195
196 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600197 // Clean up resources before we reset
198 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600199 }
200};
201
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600202// this function will create the vertex buffer and fill it with the mesh data
203void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride,
204 const void* vertices )
205{
206 XGL_RESULT err = XGL_SUCCESS;
207
208 assert( numVertices * vbStride > 0 );
209 m_numVertices = numVertices;
210
211 XGL_MEMORY_ALLOC_INFO alloc_info = {};
212 XGL_UINT8 *pData;
213
214 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
215 alloc_info.allocationSize = numVertices * vbStride;
216 alloc_info.alignment = 0;
217 alloc_info.heapCount = 1;
218 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
219
220 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
221 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
222
223 err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem);
224 ASSERT_XGL_SUCCESS(err);
225
226 err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData);
227 ASSERT_XGL_SUCCESS(err);
228
229 memcpy(pData, vertices, alloc_info.allocationSize);
230
231 err = xglUnmapMemory(m_vtxBufferMem);
232 ASSERT_XGL_SUCCESS(err);
233
234 // set up the memory view for the vertex buffer
235 this->m_vtxBufferView.stride = vbStride;
236 this->m_vtxBufferView.range = numVertices * vbStride;
237 this->m_vtxBufferView.offset = 0;
238 this->m_vtxBufferView.mem = m_vtxBufferMem;
239 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
240 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
241
242 // open the command buffer
243 err = xglBeginCommandBuffer( m_cmdBuffer, 0 );
244 ASSERT_XGL_SUCCESS(err);
245
246 XGL_MEMORY_STATE_TRANSITION transition = {};
247 transition.mem = m_vtxBufferMem;
248 transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER;
249 transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
250 transition.offset = 0;
251 transition.regionSize = numVertices * vbStride;
252
253 // write transition to the command buffer
254 xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition );
255 this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
256
257 // finish recording the command buffer
258 err = xglEndCommandBuffer( m_cmdBuffer );
259 ASSERT_XGL_SUCCESS(err);
260
261 // this command buffer only uses the vertex buffer memory
262 m_numMemRefs = 1;
263 m_memRefs[0].flags = 0;
264 m_memRefs[0].mem = m_vtxBufferMem;
265
266 // submit the command buffer to the universal queue
267 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
268 ASSERT_XGL_SUCCESS(err);
269}
270
Cody Northrop350727b2014-10-06 15:42:00 -0600271void XglRenderTest::InitTexture()
272{
Cody Northrop904742c2014-10-07 16:25:00 -0600273#define DEMO_TEXTURE_COUNT 1
274
275 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
276 const XGL_INT tex_width = 16;
277 const XGL_INT tex_height = 16;
278 const uint32_t tex_colors[DEMO_TEXTURE_COUNT][2] = {
279 { 0xffff0000, 0xff00ff00 },
280 };
Cody Northrop350727b2014-10-06 15:42:00 -0600281 XGL_RESULT err;
Cody Northrop904742c2014-10-07 16:25:00 -0600282 XGL_UINT i;
Cody Northrop350727b2014-10-06 15:42:00 -0600283
Cody Northrop904742c2014-10-07 16:25:00 -0600284 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
285 const XGL_SAMPLER_CREATE_INFO sampler = {
286 .sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
287 .pNext = NULL,
288 .magFilter = XGL_TEX_FILTER_NEAREST,
289 .minFilter = XGL_TEX_FILTER_NEAREST,
290 .mipMode = XGL_TEX_MIPMAP_BASE,
291 .addressU = XGL_TEX_ADDRESS_WRAP,
292 .addressV = XGL_TEX_ADDRESS_WRAP,
293 .addressW = XGL_TEX_ADDRESS_WRAP,
294 .mipLodBias = 0.0f,
295 .maxAnisotropy = 0,
296 .compareFunc = XGL_COMPARE_NEVER,
297 .minLod = 0.0f,
298 .maxLod = 0.0f,
299 .borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE,
300 };
301 const XGL_IMAGE_CREATE_INFO image = {
302 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
303 .pNext = NULL,
304 .imageType = XGL_IMAGE_2D,
305 .format = tex_format,
306 .extent = { tex_width, tex_height, 1 },
307 .mipLevels = 1,
308 .arraySize = 1,
309 .samples = 1,
310 .tiling = XGL_LINEAR_TILING,
311 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
312 .flags = 0,
313 };
314 XGL_MEMORY_ALLOC_INFO mem_alloc;
315 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
316 mem_alloc.pNext = NULL;
317 mem_alloc.allocationSize = 0;
318 mem_alloc.alignment = 0;
319 mem_alloc.flags = 0;
320 mem_alloc.heapCount = 0;
321 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
322 XGL_IMAGE_VIEW_CREATE_INFO view;
323 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
324 view.pNext = NULL;
325 view.image = XGL_NULL_HANDLE;
326 view.viewType = XGL_IMAGE_VIEW_2D;
327 view.format = image.format;
328 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
329 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
330 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
331 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
332 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
333 view.subresourceRange.baseMipLevel = 0;
334 view.subresourceRange.mipLevels = 1;
335 view.subresourceRange.baseArraySlice = 0;
336 view.subresourceRange.arraySize = 1;
337 view.minLod = 0.0f;
Cody Northrop350727b2014-10-06 15:42:00 -0600338
Cody Northrop904742c2014-10-07 16:25:00 -0600339 XGL_MEMORY_REQUIREMENTS mem_reqs;
340 XGL_SIZE mem_reqs_size;
Cody Northrop350727b2014-10-06 15:42:00 -0600341
Cody Northrop904742c2014-10-07 16:25:00 -0600342 /* create sampler */
343 err = xglCreateSampler(device(), &sampler, &m_sampler);
344 assert(!err);
345
346 /* create image */
347 err = xglCreateImage(device(), &image, &m_texture);
348 assert(!err);
349
350 err = xglGetObjectInfo(m_texture,
351 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
352 &mem_reqs_size, &mem_reqs);
353 assert(!err && mem_reqs_size == sizeof(mem_reqs));
354
355 mem_alloc.allocationSize = mem_reqs.size;
356 mem_alloc.alignment = mem_reqs.alignment;
357 mem_alloc.heapCount = mem_reqs.heapCount;
358 memcpy(mem_alloc.heaps, mem_reqs.heaps,
359 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
360
361 /* allocate memory */
362 err = xglAllocMemory(device(), &mem_alloc, &m_textureMem);
363 assert(!err);
364
365 /* bind memory */
366 err = xglBindObjectMemory(m_texture, m_textureMem, 0);
367 assert(!err);
368
369 /* create image view */
370 view.image = m_texture;
371 err = xglCreateImageView(device(), &view, &m_textureView);
372 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600373 }
374
Cody Northrop904742c2014-10-07 16:25:00 -0600375 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
376 const XGL_IMAGE_SUBRESOURCE subres = {
377 .aspect = XGL_IMAGE_ASPECT_COLOR,
378 .mipLevel = 0,
379 .arraySlice = 0,
380 };
381 XGL_SUBRESOURCE_LAYOUT layout;
382 XGL_SIZE layout_size;
383 XGL_VOID *data;
384 XGL_INT x, y;
Cody Northrop350727b2014-10-06 15:42:00 -0600385
Cody Northrop904742c2014-10-07 16:25:00 -0600386 err = xglGetImageSubresourceInfo(m_texture, &subres,
387 XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout);
388 assert(!err && layout_size == sizeof(layout));
Cody Northrop350727b2014-10-06 15:42:00 -0600389
Cody Northrop904742c2014-10-07 16:25:00 -0600390 err = xglMapMemory(m_textureMem, 0, &data);
391 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600392
Cody Northrop904742c2014-10-07 16:25:00 -0600393 for (y = 0; y < tex_height; y++) {
394 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
395 for (x = 0; x < tex_width; x++)
396 row[x] = tex_colors[i][(x & 1) ^ (y & 1)];
Cody Northrop350727b2014-10-06 15:42:00 -0600397 }
Cody Northrop904742c2014-10-07 16:25:00 -0600398
399 err = xglUnmapMemory(m_textureMem);
400 assert(!err);
Cody Northrop350727b2014-10-06 15:42:00 -0600401 }
402
Cody Northrop350727b2014-10-06 15:42:00 -0600403 m_textureViewInfo.view = m_textureView;
404}
405
406void XglRenderTest::InitSampler()
407{
408 XGL_RESULT err;
409
410 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
411 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
412 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
413 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
414 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
415 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
416 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
417 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
418 samplerCreateInfo.mipLodBias = 0.0;
419 samplerCreateInfo.maxAnisotropy = 0.0;
420 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
421 samplerCreateInfo.minLod = 0.0;
422 samplerCreateInfo.maxLod = 0.0;
423 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
424
425 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler);
426 ASSERT_XGL_SUCCESS(err);
427}
428
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600429void XglRenderTest::DrawRotatedTriangleTest()
430{
431 // TODO : This test will pass a matrix into VS to affect triangle orientation.
432}
433
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600434void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600435{
436 XGL_PIPELINE pipeline;
437 XGL_SHADER vs, ps;
438 XGL_RESULT err;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600439
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600440 ASSERT_NO_FATAL_FAILURE(InitState());
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600441 ASSERT_NO_FATAL_FAILURE(InitViewport());
442
443 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
444 vertShaderText, &vs));
445
446 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
447 fragShaderText, &ps));
448
449 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600450
451 /*
452 * Shaders are now part of the pipeline, don't need these anymore
453 */
454 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
455 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
456
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600458
Cody Northrop342912c2014-10-01 14:03:25 -0600459 const int constantCount = 4;
460 const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 };
461 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
462
463 // Create descriptor set for a uniform resource
464 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
465 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
466 descriptorInfo.slots = 1;
467
468 // create a descriptor set with a single slot
469 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
470 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
471
472 // bind memory to the descriptor set
473 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
474
475 // write the constant buffer view to the descriptor set
476 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
477 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
478 xglEndDescriptorSetUpdate( m_rsrcDescSet );
479
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600480 // Build command buffer
481 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
482 ASSERT_XGL_SUCCESS(err);
483
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600484 GenerateClearAndPrepareBufferCmds();
485 GenerateBindRenderTargetCmd();
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600486 GenerateBindStateAndPipelineCmds(&pipeline);
487
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600488// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
489// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
490
491 // render the cube
492 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
493
494 // prepare the back buffer for present
495// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
496// transitionToPresent.image = m_image;
497// transitionToPresent.oldState = m_image_state;
498// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
499// transitionToPresent.subresourceRange = srRange;
500// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
501// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
502
503 // finalize recording of the command buffer
504 err = xglEndCommandBuffer( m_cmdBuffer );
505 ASSERT_XGL_SUCCESS( err );
506
507 // this command buffer only uses the vertex buffer memory
508 m_numMemRefs = 0;
509// m_memRefs[0].flags = 0;
510// m_memRefs[0].mem = m_vtxBufferMemory;
511
512 // submit the command buffer to the universal queue
513 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
514 ASSERT_XGL_SUCCESS( err );
515
Chia-I Wuf34ac502014-08-27 14:58:05 +0800516 err = xglQueueWaitIdle( m_device->m_queue );
517 ASSERT_XGL_SUCCESS( err );
518
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600519 // Wait for work to finish before cleaning up.
520 xglDeviceWaitIdle(m_device->device());
521
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600522 RecordImage(m_renderTarget);
Chia-I Wuf070ec12014-08-30 23:58:36 +0800523
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600524}
525
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600526void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600527{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600528 XGL_PIPELINE pipeline;
529 XGL_SHADER vs, ps;
530 XGL_RESULT err;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600531
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600532 ASSERT_NO_FATAL_FAILURE(InitState());
533 ASSERT_NO_FATAL_FAILURE(InitViewport());
534
535 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
536 vertShaderText, &vs));
537
538 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
539 fragShaderText, &ps));
540
541 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
542
543 /*
544 * Shaders are now part of the pipeline, don't need these anymore
545 */
546 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
547 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
548
549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
550
551 const int constantCount = 8;
552 const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0,
553 0.0, 0.0, 1.0, 1.0 };
554
555 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
556
557 // Create descriptor set for a uniform resource
558 const int slotCount = 1;
559 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
560 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
561 descriptorInfo.slots = slotCount;
562
563 // create a descriptor set with a single slot
564 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
565 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
566
567 // bind memory to the descriptor set
568 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
569
570 // write the constant buffer view to the descriptor set
571 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
572 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
573 xglEndDescriptorSetUpdate( m_rsrcDescSet );
574
575 // Build command buffer
576 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
577 ASSERT_XGL_SUCCESS(err);
578
579 GenerateClearAndPrepareBufferCmds();
580 GenerateBindRenderTargetCmd();
581 GenerateBindStateAndPipelineCmds(&pipeline);
582
583// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
584// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
585
586 // render the cube
587 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
588
589 // prepare the back buffer for present
590// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
591// transitionToPresent.image = m_image;
592// transitionToPresent.oldState = m_image_state;
593// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
594// transitionToPresent.subresourceRange = srRange;
595// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
596// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
597
598 // finalize recording of the command buffer
599 err = xglEndCommandBuffer( m_cmdBuffer );
600 ASSERT_XGL_SUCCESS( err );
601
602 // this command buffer only uses the vertex buffer memory
603 m_numMemRefs = 0;
604// m_memRefs[0].flags = 0;
605// m_memRefs[0].mem = m_vtxBufferMemory;
606
607 // submit the command buffer to the universal queue
608 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
609 ASSERT_XGL_SUCCESS( err );
610
611 err = xglQueueWaitIdle( m_device->m_queue );
612 ASSERT_XGL_SUCCESS( err );
613
614 // Wait for work to finish before cleaning up.
615 xglDeviceWaitIdle(m_device->device());
616
617 RecordImage(m_renderTarget);
618
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600619}
620
Cody Northrop7a1f0462014-10-10 14:49:36 -0600621
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600622void XglRenderTest::DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText)
Cody Northrop7a1f0462014-10-10 14:49:36 -0600623{
624 XGL_PIPELINE pipeline;
625 XGL_SHADER vs, ps;
626 XGL_RESULT err;
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -0600627 glm::mat4 MVP;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600628 int i;
629
630 // Create identity matrix
631 glm::mat4 Model = glm::mat4(1.0f);
Cody Northrop7a1f0462014-10-10 14:49:36 -0600632
633 ASSERT_NO_FATAL_FAILURE(InitState());
634 ASSERT_NO_FATAL_FAILURE(InitViewport());
635
636 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
637 vertShaderText, &vs));
638
639 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
640 fragShaderText, &ps));
641
642 ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps));
643
644 /*
645 * Shaders are now part of the pipeline, don't need these anymore
646 */
647 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
648 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
649
650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
651
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600652 const int matrixSize = 16;
653 MVP = Model;
Cody Northrop7a1f0462014-10-10 14:49:36 -0600654
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -0600655 InitConstantBuffer(matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Cody Northrop7a1f0462014-10-10 14:49:36 -0600656
657 // Create descriptor set for a uniform resource
658 const int slotCount = 1;
659 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
660 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
661 descriptorInfo.slots = slotCount;
662
663 // create a descriptor set with a single slot
664 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
665 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
666
667 // bind memory to the descriptor set
668 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
669
670 // write the constant buffer view to the descriptor set
671 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
672 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
673 xglEndDescriptorSetUpdate( m_rsrcDescSet );
674
675 // Build command buffer
676 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
677 ASSERT_XGL_SUCCESS(err);
678
679 GenerateClearAndPrepareBufferCmds();
680 GenerateBindRenderTargetCmd();
681 GenerateBindStateAndPipelineCmds(&pipeline);
682
683// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
684// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
685
686 // render the cube
687 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
688
689 // prepare the back buffer for present
690// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
691// transitionToPresent.image = m_image;
692// transitionToPresent.oldState = m_image_state;
693// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
694// transitionToPresent.subresourceRange = srRange;
695// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
696// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
697
698 // finalize recording of the command buffer
699 err = xglEndCommandBuffer( m_cmdBuffer );
700 ASSERT_XGL_SUCCESS( err );
701
702 // this command buffer only uses the vertex buffer memory
703 m_numMemRefs = 0;
704// m_memRefs[0].flags = 0;
705// m_memRefs[0].mem = m_vtxBufferMemory;
706
707 // submit the command buffer to the universal queue
708 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
709 ASSERT_XGL_SUCCESS( err );
710
711 err = xglQueueWaitIdle( m_device->m_queue );
712 ASSERT_XGL_SUCCESS( err );
713
714 // Wait for work to finish before cleaning up.
715 xglDeviceWaitIdle(m_device->device());
716
717 RecordImage(m_renderTarget);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600718
719 for (i = 0; i < 8; i++) {
720 XGL_UINT8 *pData;
721 err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData);
722 ASSERT_XGL_SUCCESS(err);
723
724 MVP = glm::rotate(MVP, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
725 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
726
727 err = xglUnmapMemory(m_constantBufferMem);
728 ASSERT_XGL_SUCCESS(err);
729
730 // submit the command buffer to the universal queue
731 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
732 ASSERT_XGL_SUCCESS( err );
733
734 err = xglQueueWaitIdle( m_device->m_queue );
735 ASSERT_XGL_SUCCESS( err );
736
737 // Wait for work to finish before cleaning up.
738 xglDeviceWaitIdle(m_device->device());
739
740 RecordImage(m_renderTarget);
741 }
Cody Northrop7a1f0462014-10-10 14:49:36 -0600742}
743
Cody Northrop4e6b4762014-10-09 21:25:22 -0600744void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
745{
746 XGL_RESULT err;
747 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
748 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
749 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
750
751
752 // Create descriptor set for our one resource
753 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
754 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
755 descriptorInfo.slots = 1; // Vertex buffer only
756
757 // create a descriptor set with a single slot
758 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
759 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
760
761 // bind memory to the descriptor set
762 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
763
764 // write the vertex buffer view to the descriptor set
765 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
766 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView );
767 xglEndDescriptorSetUpdate( m_rsrcDescSet );
768
769 const int slots = 1;
770 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
771 slotInfo[0].shaderEntityIndex = 0;
772 slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT;
773
774 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
775 vs_stage.pNext = XGL_NULL_HANDLE;
776 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
777 vs_stage.shader.shader = vs;
778 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
779 vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots;
780 vs_stage.shader.linkConstBufferCount = 0;
781 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
782 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
783 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
784
785 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
786 ps_stage.pNext = &vs_stage;
787 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
788 ps_stage.shader.shader = ps;
789 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
790 ps_stage.shader.linkConstBufferCount = 0;
791 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
792 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
793 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
794
795 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
796 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
797 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
798 };
799
800 // this is the current description of g_vbData
801 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
802 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
803 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
804 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
805 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
806 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
807 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
808 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
809 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
810
811 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = {
812 XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType;
813 &ps_stage, // pNext;
814 1, // bindingCount
815 &vi_binding, // pVertexBindingDescriptions;
816 2, // attributeCount; // number of attributes
817 vi_attribs // pVertexAttributeDescriptions;
818 };
819
820 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
821 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
822 &vi_state, // pNext
823 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
824 XGL_FALSE, // disableVertexReuse
825 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
826 XGL_FALSE, // primitiveRestartEnable
827 0 // primitiveRestartIndex
828 };
829
830 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
831 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
832 &ia_state,
833 XGL_FALSE, // depthClipEnable
834 XGL_FALSE, // rasterizerDiscardEnable
835 1.0 // pointSize
836 };
837
838 XGL_PIPELINE_CB_STATE cb_state = {
839 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
840 &rs_state,
841 XGL_FALSE, // alphaToCoverageEnable
842 XGL_FALSE, // dualSourceBlendEnable
843 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
844 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
845 {
846 XGL_FALSE, // blendEnable
847 m_render_target_fmt, // XGL_FORMAT
848 0xF // channelWriteMask
849 }
850 }
851 };
852
853 // TODO: Should take depth buffer format from queried formats
854 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
855 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
856 &cb_state,
857 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
858 };
859
860 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
861 info.pNext = &db_state;
862 info.flags = 0;
863 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
864 ASSERT_XGL_SUCCESS(err);
865
866 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
867 ASSERT_XGL_SUCCESS(err);
868}
869
Cody Northrop7a1f0462014-10-10 14:49:36 -0600870void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
871{
872 XGL_RESULT err;
873 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
874 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
875 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
876
877
878 const int vsSlots = 1; // Uniform buffer only
879
880 // Create descriptor set for our one resource
881 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
882 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
883 descriptorInfo.slots = vsSlots;
884
885 // create a descriptor set with a single slot
886 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
887 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
888
889 // bind memory to the descriptor set
890 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
891
892
893 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
894 slotInfo[0].shaderEntityIndex = 0;
895 slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
896
897 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
898 vs_stage.pNext = XGL_NULL_HANDLE;
899 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
900 vs_stage.shader.shader = vs;
901 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
902 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
903 vs_stage.shader.linkConstBufferCount = 0;
904 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
905 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
906 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
907
908 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
909 ps_stage.pNext = &vs_stage;
910 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
911 ps_stage.shader.shader = ps;
912 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
913 ps_stage.shader.linkConstBufferCount = 0;
914 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
915 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
916 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
917
918 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
919 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
920 &ps_stage, // pNext
921 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
922 XGL_FALSE, // disableVertexReuse
923 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
924 XGL_FALSE, // primitiveRestartEnable
925 0 // primitiveRestartIndex
926 };
927
928 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
929 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
930 &ia_state,
931 XGL_FALSE, // depthClipEnable
932 XGL_FALSE, // rasterizerDiscardEnable
933 1.0 // pointSize
934 };
935
936 XGL_PIPELINE_CB_STATE cb_state = {
937 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
938 &rs_state,
939 XGL_FALSE, // alphaToCoverageEnable
940 XGL_FALSE, // dualSourceBlendEnable
941 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
942 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
943 {
944 XGL_FALSE, // blendEnable
945 m_render_target_fmt, // XGL_FORMAT
946 0xF // channelWriteMask
947 }
948 }
949 };
950
951 // TODO: Should take depth buffer format from queried formats
952 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
953 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
954 &cb_state,
955 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
956 };
957
958 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
959 info.pNext = &db_state;
960 info.flags = 0;
961 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
962 ASSERT_XGL_SUCCESS(err);
963
964 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
965 ASSERT_XGL_SUCCESS(err);
966}
967
Cody Northrop4e6b4762014-10-09 21:25:22 -0600968void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
969{
970 XGL_PIPELINE pipeline;
971 XGL_SHADER vs, ps;
972 XGL_RESULT err;
973
974 ASSERT_NO_FATAL_FAILURE(InitState());
975 ASSERT_NO_FATAL_FAILURE(InitViewport());
976 ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData));
977
978 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
979 vertShaderText, &vs));
980
981 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
982 fragShaderText, &ps));
983
984 ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps));
985
986 /*
987 * Shaders are now part of the pipeline, don't need these anymore
988 */
989 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
990 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
991
992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
993
994 // Build command buffer
995 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
996 ASSERT_XGL_SUCCESS(err);
997
998 GenerateClearAndPrepareBufferCmds();
999 GenerateBindRenderTargetCmd();
1000 GenerateBindStateAndPipelineCmds(&pipeline);
1001
1002// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1003// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1004
1005 // render the cube
Courtney Goeltzenleuchtere2a5a092014-10-10 09:52:27 -06001006 xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 );
Cody Northrop4e6b4762014-10-09 21:25:22 -06001007
1008 // prepare the back buffer for present
1009// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1010// transitionToPresent.image = m_image;
1011// transitionToPresent.oldState = m_image_state;
1012// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1013// transitionToPresent.subresourceRange = srRange;
1014// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1015// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1016
1017 // finalize recording of the command buffer
1018 err = xglEndCommandBuffer( m_cmdBuffer );
1019 ASSERT_XGL_SUCCESS( err );
1020
1021 // this command buffer only uses the vertex buffer memory
1022 m_numMemRefs = 0;
1023// m_memRefs[0].flags = 0;
1024// m_memRefs[0].mem = m_vtxBufferMemory;
1025
1026 // submit the command buffer to the universal queue
1027 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1028 ASSERT_XGL_SUCCESS( err );
1029
1030 err = xglQueueWaitIdle( m_device->m_queue );
1031 ASSERT_XGL_SUCCESS( err );
1032
1033 // Wait for work to finish before cleaning up.
1034 xglDeviceWaitIdle(m_device->device());
1035
1036 RecordImage(m_renderTarget);
1037
1038}
1039
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001040TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001041{
1042 static const char *vertShaderText =
1043 "#version 130\n"
1044 "vec2 vertices[3];\n"
1045 "void main() {\n"
1046 " vertices[0] = vec2(-1.0, -1.0);\n"
1047 " vertices[1] = vec2( 1.0, -1.0);\n"
1048 " vertices[2] = vec2( 0.0, 1.0);\n"
1049 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1050 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -06001051
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001052 static const char *fragShaderText =
1053 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001054 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -06001055 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001056 "}\n";
1057 DrawTriangleTest(vertShaderText, fragShaderText);
1058}
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001059
Courtney Goeltzenleuchterd4ee38d2014-10-10 13:59:38 -06001060TEST_F(XglRenderTest, BIL_GreenTriangle)
1061{
1062 bool saved_use_bil = XglTestFramework::m_use_bil;
1063
1064 static const char *vertShaderText =
1065 "#version 130\n"
1066 "vec2 vertices[3];\n"
1067 "void main() {\n"
1068 " vertices[0] = vec2(-1.0, -1.0);\n"
1069 " vertices[1] = vec2( 1.0, -1.0);\n"
1070 " vertices[2] = vec2( 0.0, 1.0);\n"
1071 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1072 "}\n";
1073
1074 static const char *fragShaderText =
1075 "#version 130\n"
1076 "void main() {\n"
1077 " gl_FragColor = vec4(0,1,0,1);\n"
1078 "}\n";
1079 XglTestFramework::m_use_bil = true;
1080 DrawTriangleTest(vertShaderText, fragShaderText);
1081 XglTestFramework::m_use_bil = saved_use_bil;
1082}
1083
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001084TEST_F(XglRenderTest, TriangleFragUniform)
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001085{
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001086
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001087 static const char *vertShaderText =
1088 "#version 130\n"
1089 "out vec4 color;\n"
1090 "out vec4 scale;\n"
1091 "vec2 vertices[3];\n"
1092 "void main() {\n"
1093 "vec2 vertices[3];\n"
1094 " vertices[0] = vec2(-0.5, -0.5);\n"
1095 " vertices[1] = vec2( 0.5, -0.5);\n"
1096 " vertices[2] = vec2( 0.5, 0.5);\n"
1097 "vec4 colors[3];\n"
1098 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1099 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1100 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1101 " color = colors[gl_VertexID % 3];\n"
1102 " scale = vec4(1.0, 1.0, 1.0, 1.0);\n"
1103 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1104 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001105
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001106 static const char *fragShaderText =
1107 "#version 130\n"
1108 "in vec4 color;\n"
1109 "in vec4 scale;\n"
1110 "uniform vec4 foo;\n"
1111 "void main() {\n"
1112 " gl_FragColor = color * scale + foo;\n"
1113 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001114
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001115 DrawTriangleTest(vertShaderText, fragShaderText);
1116}
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001117
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001118TEST_F(XglRenderTest, YellowTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001119{
1120 static const char *vertShaderText =
1121 "#version 130\n"
1122 "void main() {\n"
1123 " vec2 vertices[3];"
1124 " vertices[0] = vec2(-0.5, -0.5);\n"
1125 " vertices[1] = vec2( 0.5, -0.5);\n"
1126 " vertices[2] = vec2( 0.5, 0.5);\n"
1127 " vec4 colors[3];\n"
1128 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1129 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1130 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1131 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1132 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001133
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001134 static const char *fragShaderText =
1135 "#version 130\n"
1136 "void main() {\n"
1137 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
1138 "}\n";
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001139
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001140 DrawTriangleTest(vertShaderText, fragShaderText);
1141}
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001142
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001143TEST_F(XglRenderTest, RotatedTriangle) {
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001144 DrawRotatedTriangleTest();
1145}
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001146
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001147TEST_F(XglRenderTest, TriangleTwoFSUniforms)
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001148{
1149 static const char *vertShaderText =
1150 "#version 130\n"
1151 "out vec4 color;\n"
1152 "out vec4 scale;\n"
1153 "out vec2 samplePos;\n"
1154 "void main() {\n"
1155 " vec2 vertices[3];"
1156 " vertices[0] = vec2(-0.5, -0.5);\n"
1157 " vertices[1] = vec2( 0.5, -0.5);\n"
1158 " vertices[2] = vec2( 0.5, 0.5);\n"
1159 " vec4 colors[3];\n"
1160 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1161 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1162 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1163 " color = colors[gl_VertexID % 3];\n"
1164 " vec2 positions[3];"
1165 " positions[0] = vec2( 0.0, 0.0);\n"
1166 " positions[1] = vec2( 1.0, 0.0);\n"
1167 " positions[2] = vec2( 1.0, 1.0);\n"
1168 " scale = vec4(0.0, 0.0, 0.0, 0.0);\n"
1169 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1170 "}\n";
Cody Northrop4e6b4762014-10-09 21:25:22 -06001171
1172
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001173 static const char *fragShaderText =
1174 "#version 430\n"
1175 "in vec4 color;\n"
1176 "in vec4 scale;\n"
1177 "uniform vec4 foo;\n"
1178 "uniform vec4 bar;\n"
1179 "void main() {\n"
1180 // by default, with no location or blocks
1181 // the compiler will read them from buffer
1182 // in reverse order of first use in shader
1183 // The buffer contains red, followed by blue,
1184 // so foo should be blue, bar should be red
1185 " gl_FragColor = color * scale * foo * bar + foo;\n"
1186 "}\n";
Cody Northrop4e6b4762014-10-09 21:25:22 -06001187
Cody Northrop5b7d85a2014-10-09 21:26:47 -06001188 DrawTriangleTwoUniformsFS(vertShaderText, fragShaderText);
1189}
Cody Northrop4e6b4762014-10-09 21:25:22 -06001190
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001191TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001192{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -06001193 static const char *vertShaderText =
Courtney Goeltzenleuchterbb7014d2014-10-09 11:05:19 -06001194 "#version 130\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -06001195 //XYZ1( -1, -1, -1 )
1196 "in vec4 pos;\n"
1197 //XYZ1( 0.f, 0.f, 0.f )
1198 "in vec4 inColor;\n"
1199 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001200 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001201 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -06001202 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001203 "}\n";
1204
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001205
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001206 static const char *fragShaderText =
Cody Northrop0dbe84f2014-10-09 19:55:56 -06001207 "#version 430\n"
1208 "in vec4 color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001209 "void main() {\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -06001210 " gl_FragColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001211 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -06001212
Cody Northrop4e6b4762014-10-09 21:25:22 -06001213 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
Tobin Ehlis34e0e442014-10-07 14:41:29 -06001214}
1215
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -06001216TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001217{
1218 static const char *vertShaderText =
1219 "#version 130\n"
1220 "uniform mat4 mvp;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001221 "void main() {\n"
1222 " vec2 vertices[3];"
1223 " vertices[0] = vec2(-0.5, -0.5);\n"
1224 " vertices[1] = vec2( 0.5, -0.5);\n"
1225 " vertices[2] = vec2( 0.5, 0.5);\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001226 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0) * mvp;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001227 "}\n";
1228
1229 static const char *fragShaderText =
1230 "#version 430\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001231 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001232 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001233 "}\n";
1234
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001235 // Create identity matrix
1236 glm::mat4 Model = glm::mat4(1.0f);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -06001237 DrawTriangleVSUniform(vertShaderText, fragShaderText);
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001238
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -06001239// Model = glm::rotate(Model, glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f));
1240// DrawTriangleVSUniform(vertShaderText, fragShaderText, Model);
Cody Northrop7a1f0462014-10-10 14:49:36 -06001241}
1242
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001243int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06001244 int result;
1245
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001246 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06001247 XglTestFramework::InitArgs(&argc, argv);
1248
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06001249 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
1250
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06001251 result = RUN_ALL_TESTS();
1252
1253 XglTestFramework::Finish();
1254 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001255}