blob: f917a99bdf6be06221d125ad9659489ef9a700a7 [file] [log] [blame]
Cody Northrop722ff402014-10-20 09:22:42 -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
53// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
59#include <iostream>
60#include <fstream>
61using namespace std;
62
63#include <xgl.h>
64#include "gtest-1.7.0/include/gtest/gtest.h"
65
66#include "xgldevice.h"
67#include "xglimage.h"
68#include "icd-bil.h"
69
70#define GLM_FORCE_RADIANS
71#include "glm/glm.hpp"
72#include <glm/gtc/matrix_transform.hpp>
73
74#include "xglrenderframework.h"
75
76#undef ASSERT_NO_FATAL_FAILURE
77#define ASSERT_NO_FATAL_FAILURE(x) x
78
79//--------------------------------------------------------------------------------------
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
Cody Northropac6179b2014-10-29 12:09:45 -0600135// These values are used in a few places
136static const int g_UniformBufferCount = 16;
137static const int g_SamplerCount = 3;
138static const int g_TextureCount = 3;
Cody Northropec1d3c32014-10-28 15:41:42 -0600139
Cody Northrop722ff402014-10-20 09:22:42 -0600140class XglRenderTest : public XglRenderFramework
141{
142public:
143 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
Cody Northropac6179b2014-10-29 12:09:45 -0600144 void InitTexture(int textureSlot = 0, int* color = 0);
145 void InitMultipleTextures(int textureCount, int* colors);
146 void InitSampler(int samplerSlot = 0);
147 void InitMultipleSamplers(int samplerCount);
Cody Northropec1d3c32014-10-28 15:41:42 -0600148 void InitUniformBuffer(int constantCount, int constantSize, int constantIndex, const void* data);
Cody Northrop722ff402014-10-20 09:22:42 -0600149 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -0600150 void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText);
Cody Northropec1d3c32014-10-28 15:41:42 -0600151 void DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText);
Cody Northrop0fdf64e2014-10-20 11:51:06 -0600152 void DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText);
Cody Northropc6953d02014-10-20 11:23:32 -0600153 void DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText);
Cody Northrop9394e0c2014-10-23 10:21:47 -0600154 void DrawVSTexture(const char *vertShaderText, const char *fragShaderText);
Cody Northropac6179b2014-10-29 12:09:45 -0600155 void DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText, int textureCount, int samplerCount);
Cody Northrop722ff402014-10-20 09:22:42 -0600156
Cody Northrop0fdf64e2014-10-20 11:51:06 -0600157
Cody Northrop722ff402014-10-20 09:22:42 -0600158 void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Cody Northropec1d3c32014-10-28 15:41:42 -0600159 void CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, int bufferCount);
Cody Northrop722ff402014-10-20 09:22:42 -0600160 void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Cody Northropc6953d02014-10-20 11:23:32 -0600161 void CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
Cody Northropac6179b2014-10-29 12:09:45 -0600162 void CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, int textureCount, int samplerCount);
Cody Northrop722ff402014-10-20 09:22:42 -0600163
164protected:
Cody Northropac6179b2014-10-29 12:09:45 -0600165 XGL_IMAGE m_texture[g_TextureCount];
166 XGL_IMAGE_VIEW m_textureView[g_TextureCount];
167 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo[g_TextureCount];
168 XGL_GPU_MEMORY m_textureMem[g_TextureCount];
Cody Northrop722ff402014-10-20 09:22:42 -0600169
Cody Northrop722ff402014-10-20 09:22:42 -0600170
Cody Northropac6179b2014-10-29 12:09:45 -0600171 XGL_SAMPLER m_sampler[g_SamplerCount];
172
173 XGL_GPU_MEMORY m_uniformBufferMem[g_UniformBufferCount];
174 XGL_MEMORY_VIEW_ATTACH_INFO m_uniformBufferView[g_UniformBufferCount];
Cody Northropec1d3c32014-10-28 15:41:42 -0600175
176
177
Cody Northrop722ff402014-10-20 09:22:42 -0600178// XGL_APPLICATION_INFO app_info;
179// XGL_PHYSICAL_GPU objs[MAX_GPUS];
180// XGL_UINT gpu_count;
181// XGL_GPU_MEMORY m_descriptor_set_mem;
182// XGL_GPU_MEMORY m_pipe_mem;
183// XglDevice *m_device;
184// XGL_CMD_BUFFER m_cmdBuffer;
185// XGL_UINT32 m_numVertices;
186// XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
187// XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
188// XGL_GPU_MEMORY m_vtxBufferMem;
189// XGL_GPU_MEMORY m_constantBufferMem;
190// XGL_UINT32 m_numMemRefs;
191// XGL_MEMORY_REF m_memRefs[5];
192// XGL_RASTER_STATE_OBJECT m_stateRaster;
193// XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
194// XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
195// XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
196// XGL_MSAA_STATE_OBJECT m_stateMsaa;
197// XGL_DESCRIPTOR_SET m_rsrcDescSet;
198
199 virtual void SetUp() {
200
201 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
202 this->app_info.pNext = NULL;
Cody Northropaa853252014-10-20 09:25:17 -0600203 this->app_info.pAppName = (const XGL_CHAR *) "compiler render_tests";
Cody Northrop722ff402014-10-20 09:22:42 -0600204 this->app_info.appVersion = 1;
205 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
206 this->app_info.engineVersion = 1;
207 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
208
Cody Northropac6179b2014-10-29 12:09:45 -0600209 for (int i = 0; i < g_TextureCount; ++i) {
210 m_textureViewInfo[i].sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
211 }
Cody Northrop722ff402014-10-20 09:22:42 -0600212
213 InitFramework();
214 }
215
216 virtual void TearDown() {
217 // Clean up resources before we reset
218 ShutdownFramework();
219 }
220};
221
222// this function will create the vertex buffer and fill it with the mesh data
223void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride,
224 const void* vertices )
225{
226 XGL_RESULT err = XGL_SUCCESS;
227
228 assert( numVertices * vbStride > 0 );
229 m_numVertices = numVertices;
230
231 XGL_MEMORY_ALLOC_INFO alloc_info = {};
232 XGL_UINT8 *pData;
233
234 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
235 alloc_info.allocationSize = numVertices * vbStride;
236 alloc_info.alignment = 0;
237 alloc_info.heapCount = 1;
238 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
239
240 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
241 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
242
243 err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem);
244 ASSERT_XGL_SUCCESS(err);
245
246 err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData);
247 ASSERT_XGL_SUCCESS(err);
248
249 memcpy(pData, vertices, alloc_info.allocationSize);
250
251 err = xglUnmapMemory(m_vtxBufferMem);
252 ASSERT_XGL_SUCCESS(err);
253
254 // set up the memory view for the vertex buffer
255 this->m_vtxBufferView.stride = vbStride;
256 this->m_vtxBufferView.range = numVertices * vbStride;
257 this->m_vtxBufferView.offset = 0;
258 this->m_vtxBufferView.mem = m_vtxBufferMem;
259 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
260 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
261
262 // open the command buffer
263 err = xglBeginCommandBuffer( m_cmdBuffer, 0 );
264 ASSERT_XGL_SUCCESS(err);
265
266 XGL_MEMORY_STATE_TRANSITION transition = {};
267 transition.mem = m_vtxBufferMem;
268 transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER;
269 transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
270 transition.offset = 0;
271 transition.regionSize = numVertices * vbStride;
272
273 // write transition to the command buffer
274 xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition );
275 this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
276
277 // finish recording the command buffer
278 err = xglEndCommandBuffer( m_cmdBuffer );
279 ASSERT_XGL_SUCCESS(err);
280
281 // this command buffer only uses the vertex buffer memory
282 m_numMemRefs = 1;
283 m_memRefs[0].flags = 0;
284 m_memRefs[0].mem = m_vtxBufferMem;
285
286 // submit the command buffer to the universal queue
287 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
288 ASSERT_XGL_SUCCESS(err);
289}
290
Cody Northropac6179b2014-10-29 12:09:45 -0600291void XglRenderTest::InitTexture(int textureSlot, int* color)
Cody Northrop722ff402014-10-20 09:22:42 -0600292{
293#define DEMO_TEXTURE_COUNT 1
294
Cody Northropac6179b2014-10-29 12:09:45 -0600295 const XGL_FORMAT tex_format = { XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM };
Cody Northrop722ff402014-10-20 09:22:42 -0600296 const XGL_INT tex_width = 16;
297 const XGL_INT tex_height = 16;
Cody Northropac6179b2014-10-29 12:09:45 -0600298 uint32_t tex_colors[DEMO_TEXTURE_COUNT][2];
299
300 // assign the texture color with parameter
301 assert(1 == DEMO_TEXTURE_COUNT);
302 if (color != NULL) {
303 tex_colors[0][0] = *color;
304 tex_colors[0][1] = *color;
305 } else {
Cody Northrop6217b822014-10-30 11:20:22 -0600306 tex_colors[0][0] = 0xff0000ff;
Cody Northropac6179b2014-10-29 12:09:45 -0600307 tex_colors[0][1] = 0xff00ff00;
308 }
309
Cody Northrop722ff402014-10-20 09:22:42 -0600310 XGL_RESULT err;
311 XGL_UINT i;
312
313 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
Cody Northrop722ff402014-10-20 09:22:42 -0600314 const XGL_IMAGE_CREATE_INFO image = {
315 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
316 .pNext = NULL,
317 .imageType = XGL_IMAGE_2D,
318 .format = tex_format,
319 .extent = { tex_width, tex_height, 1 },
320 .mipLevels = 1,
321 .arraySize = 1,
322 .samples = 1,
323 .tiling = XGL_LINEAR_TILING,
324 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
325 .flags = 0,
326 };
327 XGL_MEMORY_ALLOC_INFO mem_alloc;
328 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
329 mem_alloc.pNext = NULL;
330 mem_alloc.allocationSize = 0;
331 mem_alloc.alignment = 0;
332 mem_alloc.flags = 0;
333 mem_alloc.heapCount = 0;
334 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
335 XGL_IMAGE_VIEW_CREATE_INFO view;
336 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
337 view.pNext = NULL;
338 view.image = XGL_NULL_HANDLE;
339 view.viewType = XGL_IMAGE_VIEW_2D;
340 view.format = image.format;
341 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
342 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
343 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
344 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
345 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
346 view.subresourceRange.baseMipLevel = 0;
347 view.subresourceRange.mipLevels = 1;
348 view.subresourceRange.baseArraySlice = 0;
349 view.subresourceRange.arraySize = 1;
350 view.minLod = 0.0f;
351
352 XGL_MEMORY_REQUIREMENTS mem_reqs;
353 XGL_SIZE mem_reqs_size;
354
Cody Northrop722ff402014-10-20 09:22:42 -0600355 /* create image */
Cody Northropac6179b2014-10-29 12:09:45 -0600356 err = xglCreateImage(device(), &image, &m_texture[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600357 assert(!err);
358
Cody Northropac6179b2014-10-29 12:09:45 -0600359 err = xglGetObjectInfo(m_texture[textureSlot],
Cody Northrop722ff402014-10-20 09:22:42 -0600360 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
361 &mem_reqs_size, &mem_reqs);
362 assert(!err && mem_reqs_size == sizeof(mem_reqs));
363
364 mem_alloc.allocationSize = mem_reqs.size;
365 mem_alloc.alignment = mem_reqs.alignment;
366 mem_alloc.heapCount = mem_reqs.heapCount;
367 memcpy(mem_alloc.heaps, mem_reqs.heaps,
368 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
369
370 /* allocate memory */
Cody Northropac6179b2014-10-29 12:09:45 -0600371 err = xglAllocMemory(device(), &mem_alloc, &m_textureMem[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600372 assert(!err);
373
374 /* bind memory */
Cody Northropac6179b2014-10-29 12:09:45 -0600375 err = xglBindObjectMemory(m_texture[textureSlot], m_textureMem[textureSlot], 0);
Cody Northrop722ff402014-10-20 09:22:42 -0600376 assert(!err);
377
378 /* create image view */
Cody Northropac6179b2014-10-29 12:09:45 -0600379 view.image = m_texture[textureSlot];
380 err = xglCreateImageView(device(), &view, &m_textureView[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600381 assert(!err);
382 }
383
384 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
385 const XGL_IMAGE_SUBRESOURCE subres = {
386 .aspect = XGL_IMAGE_ASPECT_COLOR,
387 .mipLevel = 0,
388 .arraySlice = 0,
389 };
390 XGL_SUBRESOURCE_LAYOUT layout;
391 XGL_SIZE layout_size;
392 XGL_VOID *data;
393 XGL_INT x, y;
394
Cody Northropac6179b2014-10-29 12:09:45 -0600395 err = xglGetImageSubresourceInfo(m_texture[textureSlot], &subres,
Cody Northrop722ff402014-10-20 09:22:42 -0600396 XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout);
397 assert(!err && layout_size == sizeof(layout));
398
Cody Northropac6179b2014-10-29 12:09:45 -0600399 err = xglMapMemory(m_textureMem[textureSlot], 0, &data);
Cody Northrop722ff402014-10-20 09:22:42 -0600400 assert(!err);
401
402 for (y = 0; y < tex_height; y++) {
403 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
404 for (x = 0; x < tex_width; x++)
405 row[x] = tex_colors[i][(x & 1) ^ (y & 1)];
406 }
407
Cody Northropac6179b2014-10-29 12:09:45 -0600408 err = xglUnmapMemory(m_textureMem[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600409 assert(!err);
410 }
411
Cody Northropac6179b2014-10-29 12:09:45 -0600412 m_textureViewInfo[textureSlot].view = m_textureView[textureSlot];
Cody Northrop722ff402014-10-20 09:22:42 -0600413}
414
Cody Northropac6179b2014-10-29 12:09:45 -0600415
416void XglRenderTest::InitMultipleTextures(int textureCount, int* colors)
417{
418
419 for (int i = 0; i < textureCount; ++i)
420 InitTexture(i, &colors[i]);
421}
422
423
424void XglRenderTest::InitMultipleSamplers(const int samplerCount)
425{
426 XGL_RESULT err;
427
428 for (int i = 0; i < samplerCount; ++i) {
429
430 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
431 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
432 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
433 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
434 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
435 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
436 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
437 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
438 samplerCreateInfo.mipLodBias = 0.0;
439 samplerCreateInfo.maxAnisotropy = 0.0;
440 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
441 samplerCreateInfo.minLod = 0.0;
442 samplerCreateInfo.maxLod = 0.0;
443 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
444
445 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[i]);
446 ASSERT_XGL_SUCCESS(err);
447 }
448}
449
450void XglRenderTest::InitSampler(int samplerSlot)
Cody Northrop722ff402014-10-20 09:22:42 -0600451{
452 XGL_RESULT err;
453
454 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
455 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
456 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
457 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
458 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
459 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
460 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
461 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
462 samplerCreateInfo.mipLodBias = 0.0;
463 samplerCreateInfo.maxAnisotropy = 0.0;
464 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
465 samplerCreateInfo.minLod = 0.0;
466 samplerCreateInfo.maxLod = 0.0;
467 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
468
Cody Northropac6179b2014-10-29 12:09:45 -0600469 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[samplerSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600470 ASSERT_XGL_SUCCESS(err);
471}
472
Cody Northropac6179b2014-10-29 12:09:45 -0600473
Cody Northropec1d3c32014-10-28 15:41:42 -0600474void XglRenderTest::InitUniformBuffer(int constantCount, int constantSize,
475 int constantIndex, const void* data)
Cody Northrop722ff402014-10-20 09:22:42 -0600476{
Cody Northropec1d3c32014-10-28 15:41:42 -0600477 // based on XglRenderFramework::InitConstantBuffer
478 // mainly add an index when selecting which buffer you are creating
479
480 XGL_RESULT err = XGL_SUCCESS;
481
482 XGL_MEMORY_ALLOC_INFO alloc_info = {};
483 XGL_UINT8 *pData;
484
485 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
486 alloc_info.allocationSize = constantCount * constantSize;
487 alloc_info.alignment = 0;
488 alloc_info.heapCount = 1;
489 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
490
491 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
492 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
493
494 err = xglAllocMemory(device(), &alloc_info, &m_uniformBufferMem[constantIndex]);
495 ASSERT_XGL_SUCCESS(err);
496
497 err = xglMapMemory(m_uniformBufferMem[constantIndex], 0, (XGL_VOID **) &pData);
498 ASSERT_XGL_SUCCESS(err);
499
500 memcpy(pData, data, alloc_info.allocationSize);
501
502 err = xglUnmapMemory(m_uniformBufferMem[constantIndex]);
503 ASSERT_XGL_SUCCESS(err);
504
505 // set up the memory view for the constant buffer
506 this->m_uniformBufferView[constantIndex].stride = 16;
507 this->m_uniformBufferView[constantIndex].range = alloc_info.allocationSize;
508 this->m_uniformBufferView[constantIndex].offset = 0;
509 this->m_uniformBufferView[constantIndex].mem = m_uniformBufferMem[constantIndex];
510 this->m_uniformBufferView[constantIndex].format.channelFormat = XGL_CH_FMT_R32G32B32A32;
511 this->m_uniformBufferView[constantIndex].format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop722ff402014-10-20 09:22:42 -0600512}
513
514void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
515{
516 XGL_PIPELINE pipeline;
517 XGL_SHADER vs, ps;
518 XGL_RESULT err;
519
520 ASSERT_NO_FATAL_FAILURE(InitState());
521 ASSERT_NO_FATAL_FAILURE(InitViewport());
522
523 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
524 vertShaderText, &vs));
525
526 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
527 fragShaderText, &ps));
528
529 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
530
531 /*
532 * Shaders are now part of the pipeline, don't need these anymore
533 */
534 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
535 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
536
537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
538
539 const int constantCount = 4;
540 const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 };
541 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
542
543 // Create descriptor set for a uniform resource
544 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
545 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
546 descriptorInfo.slots = 1;
547
548 // create a descriptor set with a single slot
549 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
550 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
551
552 // bind memory to the descriptor set
553 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
554
555 // write the constant buffer view to the descriptor set
556 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
557 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
558 xglEndDescriptorSetUpdate( m_rsrcDescSet );
559
560 // Build command buffer
561 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
562 ASSERT_XGL_SUCCESS(err);
563
564 GenerateClearAndPrepareBufferCmds();
565 GenerateBindRenderTargetCmd();
566 GenerateBindStateAndPipelineCmds(&pipeline);
567
568// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
569// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
570
571 // render the cube
572 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
573
574 // prepare the back buffer for present
575// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
576// transitionToPresent.image = m_image;
577// transitionToPresent.oldState = m_image_state;
578// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
579// transitionToPresent.subresourceRange = srRange;
580// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
581// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
582
583 // finalize recording of the command buffer
584 err = xglEndCommandBuffer( m_cmdBuffer );
585 ASSERT_XGL_SUCCESS( err );
586
587 // this command buffer only uses the vertex buffer memory
588 m_numMemRefs = 0;
589// m_memRefs[0].flags = 0;
590// m_memRefs[0].mem = m_vtxBufferMemory;
591
592 // submit the command buffer to the universal queue
593 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
594 ASSERT_XGL_SUCCESS( err );
595
596 err = xglQueueWaitIdle( m_device->m_queue );
597 ASSERT_XGL_SUCCESS( err );
598
599 // Wait for work to finish before cleaning up.
600 xglDeviceWaitIdle(m_device->device());
601
602 RecordImage(m_renderTarget);
603
604}
605
Cody Northropc6953d02014-10-20 11:23:32 -0600606void XglRenderTest::DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText)
607{
608
609 // based on DrawTriangleTwoUniformsFS
610
611 XGL_PIPELINE pipeline;
612 XGL_SHADER vs, ps;
613 XGL_RESULT err;
614
615 ASSERT_NO_FATAL_FAILURE(InitState());
616 ASSERT_NO_FATAL_FAILURE(InitViewport());
617
618 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
619 vertShaderText, &vs));
620
621 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
622 fragShaderText, &ps));
623
624 ASSERT_NO_FATAL_FAILURE(CreatePipelineSingleTextureAndSampler(&pipeline, vs, ps));
625
626 /*
627 * Shaders are now part of the pipeline, don't need these anymore
628 */
629 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
630 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
631
632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
633
634
635 // Enable our single sampler
636 ASSERT_NO_FATAL_FAILURE(InitSampler());
637
638 // Enable our single texture
639 ASSERT_NO_FATAL_FAILURE(InitTexture());
640
641 // Create descriptor set for a texture and sampler resources
Cody Northrop5fa1d332014-10-20 11:51:32 -0600642 const int slotCount = 2;
Cody Northropc6953d02014-10-20 11:23:32 -0600643 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
644 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
645 descriptorInfo.slots = slotCount;
646
647 // create a descriptor set with a single slot
648 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
649 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
650
651 // bind memory to the descriptor set
652 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
653
654 // write the sampler and image views to the descriptor set
655 // ensure this matches order set in CreatePipelineSingleTextureAndSampler
656 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
Cody Northropac6179b2014-10-29 12:09:45 -0600657 xglAttachImageViewDescriptors( m_rsrcDescSet, 0, 1, &m_textureViewInfo[0] );
658 xglAttachSamplerDescriptors(m_rsrcDescSet, 1, 1, &m_sampler[0]);
Cody Northropc6953d02014-10-20 11:23:32 -0600659 xglEndDescriptorSetUpdate( m_rsrcDescSet );
660
661 // Build command buffer
662 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
663 ASSERT_XGL_SUCCESS(err);
664
665 GenerateClearAndPrepareBufferCmds();
666 GenerateBindRenderTargetCmd();
667 GenerateBindStateAndPipelineCmds(&pipeline);
668
669// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
670// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
671
672 // render the cube
673 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
674
675 // prepare the back buffer for present
676// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
677// transitionToPresent.image = m_image;
678// transitionToPresent.oldState = m_image_state;
679// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
680// transitionToPresent.subresourceRange = srRange;
681// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
682// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
683
684 // finalize recording of the command buffer
685 err = xglEndCommandBuffer( m_cmdBuffer );
686 ASSERT_XGL_SUCCESS( err );
687
688 // this command buffer only uses the vertex buffer memory
689 m_numMemRefs = 0;
690// m_memRefs[0].flags = 0;
691// m_memRefs[0].mem = m_vtxBufferMemory;
692
693 // submit the command buffer to the universal queue
694 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
695 ASSERT_XGL_SUCCESS( err );
696
697 err = xglQueueWaitIdle( m_device->m_queue );
698 ASSERT_XGL_SUCCESS( err );
699
700 // Wait for work to finish before cleaning up.
701 xglDeviceWaitIdle(m_device->device());
702
703 RecordImage(m_renderTarget);
704
705}
Cody Northrop722ff402014-10-20 09:22:42 -0600706
Cody Northrop0fdf64e2014-10-20 11:51:06 -0600707void XglRenderTest::DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText)
708{
709 // sourced from DrawTriangleVSUniform
710 XGL_PIPELINE pipeline;
711 XGL_SHADER vs, ps;
712 XGL_RESULT err;
713
714 ASSERT_NO_FATAL_FAILURE(InitState());
715 ASSERT_NO_FATAL_FAILURE(InitViewport());
716
717 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
718 vertShaderText, &vs));
719
720 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
721 fragShaderText, &ps));
722
723 ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps));
724
725 /*
726 * Shaders are now part of the pipeline, don't need these anymore
727 */
728 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
729 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
730
731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
732
733 // Let's populate our buffer with the following:
734 // vec4 red;
735 // vec4 green;
736 // vec4 blue;
737 // vec4 white;
738 const int valCount = 4 * 4;
739 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
740 0.0, 1.0, 0.0, 1.0,
741 0.0, 0.0, 1.0, 1.0,
742 1.0, 1.0, 1.0, 1.0 };
743
744 InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
745
746 // Create descriptor set for a uniform resource
747 const int slotCount = 1;
748 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
749 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
750 descriptorInfo.slots = slotCount;
751
752 // create a descriptor set with a single slot
753 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
754 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
755
756 // bind memory to the descriptor set
757 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
758
759 // write the constant buffer view to the descriptor set
760 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
761 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
762 xglEndDescriptorSetUpdate( m_rsrcDescSet );
763
764 // Build command buffer
765 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
766 ASSERT_XGL_SUCCESS(err);
767
768 GenerateClearAndPrepareBufferCmds();
769 GenerateBindRenderTargetCmd();
770 GenerateBindStateAndPipelineCmds(&pipeline);
771
772// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
773// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
774
775 // render the cube
776 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
777
778 // prepare the back buffer for present
779// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
780// transitionToPresent.image = m_image;
781// transitionToPresent.oldState = m_image_state;
782// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
783// transitionToPresent.subresourceRange = srRange;
784// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
785// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
786
787 // finalize recording of the command buffer
788 err = xglEndCommandBuffer( m_cmdBuffer );
789 ASSERT_XGL_SUCCESS( err );
790
791 // this command buffer only uses the vertex buffer memory
792 m_numMemRefs = 0;
793// m_memRefs[0].flags = 0;
794// m_memRefs[0].mem = m_vtxBufferMemory;
795
796 // submit the command buffer to the universal queue
797 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
798 ASSERT_XGL_SUCCESS( err );
799
800 err = xglQueueWaitIdle( m_device->m_queue );
801 ASSERT_XGL_SUCCESS( err );
802
803 // Wait for work to finish before cleaning up.
804 xglDeviceWaitIdle(m_device->device());
805
806 RecordImage(m_renderTarget);
807}
808
Cody Northrop722ff402014-10-20 09:22:42 -0600809void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
810{
811 XGL_RESULT err;
812 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
813 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
814 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
815
816
817 // Create descriptor set for our one resource
818 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
819 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
820 descriptorInfo.slots = 1; // Vertex buffer only
821
822 // create a descriptor set with a single slot
823 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
824 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
825
826 // bind memory to the descriptor set
827 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
828
829 // write the vertex buffer view to the descriptor set
830 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
831 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView );
832 xglEndDescriptorSetUpdate( m_rsrcDescSet );
833
834 const int slots = 1;
835 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
836 slotInfo[0].shaderEntityIndex = 0;
837 slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT;
838
839 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
840 vs_stage.pNext = XGL_NULL_HANDLE;
841 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
842 vs_stage.shader.shader = vs;
843 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
844 vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots;
845 vs_stage.shader.linkConstBufferCount = 0;
846 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
847 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
848 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
849
850 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
851 ps_stage.pNext = &vs_stage;
852 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
853 ps_stage.shader.shader = ps;
854 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
855 ps_stage.shader.linkConstBufferCount = 0;
856 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
857 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
858 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
859
860 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
861 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
862 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
863 };
864
865 // this is the current description of g_vbData
866 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
867 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
868 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
869 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
870 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
871 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
872 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
873 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
874 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
875
876 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = {
877 XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType;
878 &ps_stage, // pNext;
879 1, // bindingCount
880 &vi_binding, // pVertexBindingDescriptions;
881 2, // attributeCount; // number of attributes
882 vi_attribs // pVertexAttributeDescriptions;
883 };
884
885 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
886 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
887 &vi_state, // pNext
888 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
889 XGL_FALSE, // disableVertexReuse
890 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
891 XGL_FALSE, // primitiveRestartEnable
892 0 // primitiveRestartIndex
893 };
894
895 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
896 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
897 &ia_state,
898 XGL_FALSE, // depthClipEnable
899 XGL_FALSE, // rasterizerDiscardEnable
900 1.0 // pointSize
901 };
902
903 XGL_PIPELINE_CB_STATE cb_state = {
904 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
905 &rs_state,
906 XGL_FALSE, // alphaToCoverageEnable
907 XGL_FALSE, // dualSourceBlendEnable
908 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
909 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
910 {
911 XGL_FALSE, // blendEnable
912 m_render_target_fmt, // XGL_FORMAT
913 0xF // channelWriteMask
914 }
915 }
916 };
917
918 // TODO: Should take depth buffer format from queried formats
919 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
920 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
921 &cb_state,
922 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
923 };
924
925 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
926 info.pNext = &db_state;
927 info.flags = 0;
928 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
929 ASSERT_XGL_SUCCESS(err);
930
931 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
932 ASSERT_XGL_SUCCESS(err);
933}
934
935void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
936{
937 XGL_RESULT err;
938 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
939 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
940 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
941
942
943 const int vsSlots = 1; // Uniform buffer only
944
945 // Create descriptor set for our one resource
946 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
947 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
948 descriptorInfo.slots = vsSlots;
949
950 // create a descriptor set with a single slot
951 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
952 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
953
954 // bind memory to the descriptor set
955 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
956
957
958 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
959 slotInfo[0].shaderEntityIndex = 0;
960 slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
961
962 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
963 vs_stage.pNext = XGL_NULL_HANDLE;
964 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
965 vs_stage.shader.shader = vs;
966 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
967 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
968 vs_stage.shader.linkConstBufferCount = 0;
969 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
970 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
971 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
972
973 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
974 ps_stage.pNext = &vs_stage;
975 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
976 ps_stage.shader.shader = ps;
977 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
978 ps_stage.shader.linkConstBufferCount = 0;
979 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
980 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
981 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
982
983 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
984 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
985 &ps_stage, // pNext
986 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
987 XGL_FALSE, // disableVertexReuse
988 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
989 XGL_FALSE, // primitiveRestartEnable
990 0 // primitiveRestartIndex
991 };
992
993 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
994 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
995 &ia_state,
996 XGL_FALSE, // depthClipEnable
997 XGL_FALSE, // rasterizerDiscardEnable
998 1.0 // pointSize
999 };
1000
1001 XGL_PIPELINE_CB_STATE cb_state = {
1002 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1003 &rs_state,
1004 XGL_FALSE, // alphaToCoverageEnable
1005 XGL_FALSE, // dualSourceBlendEnable
1006 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1007 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1008 {
1009 XGL_FALSE, // blendEnable
1010 m_render_target_fmt, // XGL_FORMAT
1011 0xF // channelWriteMask
1012 }
1013 }
1014 };
1015
1016 // TODO: Should take depth buffer format from queried formats
1017 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1018 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1019 &cb_state,
1020 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1021 };
1022
1023 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1024 info.pNext = &db_state;
1025 info.flags = 0;
1026 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1027 ASSERT_XGL_SUCCESS(err);
1028
1029 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1030 ASSERT_XGL_SUCCESS(err);
1031}
1032
Cody Northropec1d3c32014-10-28 15:41:42 -06001033void XglRenderTest::CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, const int bufferCount)
1034{
1035 // based on CreateDefaultPipeline
1036 // only difference is number of constant buffers
1037
1038 XGL_RESULT err;
1039 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1040 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1041 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1042
1043 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1044 vs_stage.pNext = XGL_NULL_HANDLE;
1045 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1046 vs_stage.shader.shader = vs;
1047 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
1048 vs_stage.shader.linkConstBufferCount = 0;
1049 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1050 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1051 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1052
1053 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1054 ps_stage.pNext = &vs_stage;
1055 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1056 ps_stage.shader.shader = ps;
1057
1058// const int slots = 4;
1059// assert (slots == bufferCount); // update as needed
1060
1061 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( bufferCount * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
Cody Northrop929838b2014-11-05 17:08:33 -07001062 for (int i = 0; i < bufferCount - 1; ++i) {
Cody Northropec1d3c32014-10-28 15:41:42 -06001063 // Note: These are all constant buffers
1064 slotInfo[i].shaderEntityIndex = i;
1065 slotInfo[i].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1066 }
1067
Cody Northrop929838b2014-11-05 17:08:33 -07001068 slotInfo[bufferCount - 1].shaderEntityIndex = 18;
1069 slotInfo[bufferCount - 1].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1070
Cody Northropec1d3c32014-10-28 15:41:42 -06001071 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1072 ps_stage.shader.descriptorSetMapping[0].descriptorCount = bufferCount;
1073
1074 ps_stage.shader.linkConstBufferCount = 0;
1075 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1076 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1077 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1078
1079 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1080 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1081 &ps_stage, // pNext
1082 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1083 XGL_FALSE, // disableVertexReuse
1084 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1085 XGL_FALSE, // primitiveRestartEnable
1086 0 // primitiveRestartIndex
1087 };
1088
1089 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1090 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1091 &ia_state,
1092 XGL_FALSE, // depthClipEnable
1093 XGL_FALSE, // rasterizerDiscardEnable
1094 1.0 // pointSize
1095 };
1096
1097 XGL_PIPELINE_CB_STATE cb_state = {
1098 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1099 &rs_state,
1100 XGL_FALSE, // alphaToCoverageEnable
1101 XGL_FALSE, // dualSourceBlendEnable
1102 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1103 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1104 {
1105 XGL_FALSE, // blendEnable
1106 m_render_target_fmt, // XGL_FORMAT
1107 0xF // channelWriteMask
1108 }
1109 }
1110 };
1111
1112 // TODO: Should take depth buffer format from queried formats
1113 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1114 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1115 &cb_state,
1116 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1117 };
1118
1119 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1120 info.pNext = &db_state;
1121 info.flags = 0;
1122 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1123 ASSERT_XGL_SUCCESS(err);
1124
1125 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1126 ASSERT_XGL_SUCCESS(err);
1127}
1128
Cody Northropc6953d02014-10-20 11:23:32 -06001129void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
1130{
1131 // based on CreatePipelineVSUniform
1132
1133 XGL_RESULT err;
1134 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1135 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1136 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1137
Cody Northrop9394e0c2014-10-23 10:21:47 -06001138 const int vsSlots = 2; // One texture, one sampler
Cody Northropc6953d02014-10-20 11:23:32 -06001139
1140 // Create descriptor set for single texture and sampler
Cody Northrop9394e0c2014-10-23 10:21:47 -06001141 XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {};
1142 vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1143 vsDescriptorInfo.slots = vsSlots;
1144 err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &m_rsrcDescSet );
Cody Northropc6953d02014-10-20 11:23:32 -06001145 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1146 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1147
Cody Northropc6953d02014-10-20 11:23:32 -06001148 // Assign the slots, note that only t0 and s0 will work as of writing this test
Cody Northrop9394e0c2014-10-23 10:21:47 -06001149 XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1150 vsSlotInfo[0].shaderEntityIndex = 0;
1151 vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1152 vsSlotInfo[1].shaderEntityIndex = 0;
1153 vsSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
Cody Northropc6953d02014-10-20 11:23:32 -06001154
1155 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1156 vs_stage.pNext = XGL_NULL_HANDLE;
1157 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1158 vs_stage.shader.shader = vs;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001159 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo;
1160 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
Cody Northropc6953d02014-10-20 11:23:32 -06001161 vs_stage.shader.linkConstBufferCount = 0;
1162 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1163 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1164 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1165
Cody Northrop9394e0c2014-10-23 10:21:47 -06001166 const int psSlots = 2; // One texture, one sampler
1167
1168 // Create descriptor set for single texture and sampler
1169 XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {};
1170 psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1171 psDescriptorInfo.slots = psSlots;
1172 err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet );
1173 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1174 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1175
1176 // Assign the slots, note that only t0 and s0 will work as of writing this test
1177 XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1178 psSlotInfo[0].shaderEntityIndex = 0;
1179 psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1180 psSlotInfo[1].shaderEntityIndex = 0;
1181 psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1182
Cody Northropc6953d02014-10-20 11:23:32 -06001183 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1184 ps_stage.pNext = &vs_stage;
1185 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1186 ps_stage.shader.shader = ps;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001187 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) psSlotInfo;
Cody Northropc6953d02014-10-20 11:23:32 -06001188 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1189 ps_stage.shader.linkConstBufferCount = 0;
1190 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1191 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1192 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1193
1194 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1195 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1196 &ps_stage, // pNext
1197 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1198 XGL_FALSE, // disableVertexReuse
1199 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1200 XGL_FALSE, // primitiveRestartEnable
1201 0 // primitiveRestartIndex
1202 };
1203
1204 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1205 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1206 &ia_state,
1207 XGL_FALSE, // depthClipEnable
1208 XGL_FALSE, // rasterizerDiscardEnable
1209 1.0 // pointSize
1210 };
1211
1212 XGL_PIPELINE_CB_STATE cb_state = {
1213 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1214 &rs_state,
1215 XGL_FALSE, // alphaToCoverageEnable
1216 XGL_FALSE, // dualSourceBlendEnable
1217 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1218 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1219 {
1220 XGL_FALSE, // blendEnable
1221 m_render_target_fmt, // XGL_FORMAT
1222 0xF // channelWriteMask
1223 }
1224 }
1225 };
1226
1227 // TODO: Should take depth buffer format from queried formats
1228 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1229 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1230 &cb_state,
1231 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1232 };
1233
1234 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1235 info.pNext = &db_state;
1236 info.flags = 0;
1237 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1238 ASSERT_XGL_SUCCESS(err);
1239
1240 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1241 ASSERT_XGL_SUCCESS(err);
1242}
1243
Cody Northropac6179b2014-10-29 12:09:45 -06001244void XglRenderTest::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps,
1245 int textureCount, int samplerCount)
1246{
1247 // based on CreatePipelineSingleTextureAndSampler
1248
1249 XGL_RESULT err;
1250 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1251 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1252 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1253
1254 const int psSlots = textureCount + samplerCount;
1255
1256 // Create descriptor set for single texture and sampler
1257 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1258 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1259 descriptorInfo.slots = psSlots;
1260 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1261 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1262 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1263
1264 // Assign the slots, note that only t0 and s0 will work as of writing this test
1265 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1266 int slotIndex = 0;
Cody Northrop929838b2014-11-05 17:08:33 -07001267 for (int i = 0; i < textureCount - 1; ++i) {
Cody Northropac6179b2014-10-29 12:09:45 -06001268 slotInfo[slotIndex].shaderEntityIndex = i;
1269 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1270 }
Cody Northrop929838b2014-11-05 17:08:33 -07001271 slotInfo[slotIndex].shaderEntityIndex = 12;
1272 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1273 for (int i = 0; i < samplerCount - 1; ++i) {
Cody Northropac6179b2014-10-29 12:09:45 -06001274 slotInfo[slotIndex].shaderEntityIndex = i;
1275 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1276 }
1277
Cody Northrop929838b2014-11-05 17:08:33 -07001278 slotInfo[slotIndex].shaderEntityIndex = 12;
1279 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1280
Cody Northropac6179b2014-10-29 12:09:45 -06001281 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1282 vs_stage.pNext = XGL_NULL_HANDLE;
1283 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1284 vs_stage.shader.shader = vs;
1285 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
1286 vs_stage.shader.linkConstBufferCount = 0;
1287 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1288 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1289 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1290
1291 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1292 ps_stage.pNext = &vs_stage;
1293 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1294 ps_stage.shader.shader = ps;
1295 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1296 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1297 ps_stage.shader.linkConstBufferCount = 0;
1298 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1299 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1300 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1301
1302 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1303 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1304 &ps_stage, // pNext
1305 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1306 XGL_FALSE, // disableVertexReuse
1307 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1308 XGL_FALSE, // primitiveRestartEnable
1309 0 // primitiveRestartIndex
1310 };
1311
1312 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1313 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1314 &ia_state,
1315 XGL_FALSE, // depthClipEnable
1316 XGL_FALSE, // rasterizerDiscardEnable
1317 1.0 // pointSize
1318 };
1319
1320 XGL_PIPELINE_CB_STATE cb_state = {
1321 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1322 &rs_state,
1323 XGL_FALSE, // alphaToCoverageEnable
1324 XGL_FALSE, // dualSourceBlendEnable
1325 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1326 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1327 {
1328 XGL_FALSE, // blendEnable
1329 m_render_target_fmt, // XGL_FORMAT
1330 0xF // channelWriteMask
1331 }
1332 }
1333 };
1334
1335 // TODO: Should take depth buffer format from queried formats
1336 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1337 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1338 &cb_state,
1339 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1340 };
1341
1342 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1343 info.pNext = &db_state;
1344 info.flags = 0;
1345 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1346 ASSERT_XGL_SUCCESS(err);
1347
1348 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1349 ASSERT_XGL_SUCCESS(err);
1350}
1351
Cody Northrop722ff402014-10-20 09:22:42 -06001352void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
1353{
1354 XGL_PIPELINE pipeline;
1355 XGL_SHADER vs, ps;
1356 XGL_RESULT err;
1357
1358 ASSERT_NO_FATAL_FAILURE(InitState());
1359 ASSERT_NO_FATAL_FAILURE(InitViewport());
1360 ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData));
1361
1362 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1363 vertShaderText, &vs));
1364
1365 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1366 fragShaderText, &ps));
1367
1368 ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps));
1369
1370 /*
1371 * Shaders are now part of the pipeline, don't need these anymore
1372 */
1373 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1374 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1375
1376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1377
1378 // Build command buffer
1379 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1380 ASSERT_XGL_SUCCESS(err);
1381
1382 GenerateClearAndPrepareBufferCmds();
1383 GenerateBindRenderTargetCmd();
1384 GenerateBindStateAndPipelineCmds(&pipeline);
1385
1386// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1387// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1388
1389 // render the cube
1390 xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 );
1391
1392 // prepare the back buffer for present
1393// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1394// transitionToPresent.image = m_image;
1395// transitionToPresent.oldState = m_image_state;
1396// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1397// transitionToPresent.subresourceRange = srRange;
1398// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1399// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1400
1401 // finalize recording of the command buffer
1402 err = xglEndCommandBuffer( m_cmdBuffer );
1403 ASSERT_XGL_SUCCESS( err );
1404
1405 // this command buffer only uses the vertex buffer memory
1406 m_numMemRefs = 0;
1407// m_memRefs[0].flags = 0;
1408// m_memRefs[0].mem = m_vtxBufferMemory;
1409
1410 // submit the command buffer to the universal queue
1411 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1412 ASSERT_XGL_SUCCESS( err );
1413
1414 err = xglQueueWaitIdle( m_device->m_queue );
1415 ASSERT_XGL_SUCCESS( err );
1416
1417 // Wait for work to finish before cleaning up.
1418 xglDeviceWaitIdle(m_device->device());
1419
1420 RecordImage(m_renderTarget);
1421
1422}
1423
Cody Northropec1d3c32014-10-28 15:41:42 -06001424void XglRenderTest::DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText)
1425{
1426 // sourced from DrawTriangleFSUniformBlock
1427
1428 XGL_PIPELINE pipeline;
1429 XGL_SHADER vs, ps;
1430 XGL_RESULT err;
1431
1432 ASSERT_NO_FATAL_FAILURE(InitState());
1433 ASSERT_NO_FATAL_FAILURE(InitViewport());
1434
1435 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1436 vertShaderText, &vs));
1437
1438 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1439 fragShaderText, &ps));
1440
1441 const int bufferCount = 4;
1442 ASSERT_NO_FATAL_FAILURE(CreatePipelineFSUniformBlockBinding(&pipeline, vs, ps, bufferCount));
1443
1444 /*
1445 * Shaders are now part of the pipeline, don't need these anymore
1446 */
1447 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1448 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1449
1450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1451
1452
1453 // We're going to create a number of uniform buffers, and then allow
1454 // the shader to select which it wants to read from with a binding
1455
1456 // Let's populate the buffers with a single color each:
1457 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
1458 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
1459 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
1460 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
1461
1462 assert(4 == bufferCount); // update the following code if you want more than 4
1463
1464 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
1465 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
1466 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
1467 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
1468
1469 const int redCount = sizeof(redVals) / sizeof(float);
1470 const int greenCount = sizeof(greenVals) / sizeof(float);
1471 const int blueCount = sizeof(blueVals) / sizeof(float);
1472 const int whiteCount = sizeof(whiteVals) / sizeof(float);
1473
1474 int index = 0;
1475 InitUniformBuffer(redCount, sizeof(redVals[0]), index++, (const void *) redVals);
1476 InitUniformBuffer(greenCount, sizeof(greenVals[0]), index++, (const void *) greenVals);
1477 InitUniformBuffer(blueCount, sizeof(blueVals[0]), index++, (const void *) blueVals);
1478 InitUniformBuffer(whiteCount, sizeof(whiteVals[0]), index++, (const void *) whiteVals);
1479
1480
1481 // Create descriptor set for a uniform resource
1482 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1483 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1484 descriptorInfo.slots = bufferCount;
1485
1486 // create a descriptor set with a single slot
1487 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1488 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1489
1490 // bind memory to the descriptor set
1491 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1492
1493 // write the constant buffer view to the descriptor set
1494 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1495
1496 for(int i = 0; i < bufferCount; ++i)
1497 xglAttachMemoryViewDescriptors( m_rsrcDescSet, i, 1, &m_uniformBufferView[i] );
1498
1499 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1500
1501 // Build command buffer
1502 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1503 ASSERT_XGL_SUCCESS(err);
1504
1505 GenerateClearAndPrepareBufferCmds();
1506 GenerateBindRenderTargetCmd();
1507 GenerateBindStateAndPipelineCmds(&pipeline);
1508
1509// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1510// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1511
1512 // render the cube
1513 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1514
1515 // prepare the back buffer for present
1516// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1517// transitionToPresent.image = m_image;
1518// transitionToPresent.oldState = m_image_state;
1519// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1520// transitionToPresent.subresourceRange = srRange;
1521// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1522// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1523
1524 // finalize recording of the command buffer
1525 err = xglEndCommandBuffer( m_cmdBuffer );
1526 ASSERT_XGL_SUCCESS( err );
1527
1528 // this command buffer only uses the vertex buffer memory
1529 m_numMemRefs = 0;
1530// m_memRefs[0].flags = 0;
1531// m_memRefs[0].mem = m_vtxBufferMemory;
1532
1533 // submit the command buffer to the universal queue
1534 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1535 ASSERT_XGL_SUCCESS( err );
1536
1537 err = xglQueueWaitIdle( m_device->m_queue );
1538 ASSERT_XGL_SUCCESS( err );
1539
1540 // Wait for work to finish before cleaning up.
1541 xglDeviceWaitIdle(m_device->device());
1542
1543 RecordImage(m_renderTarget);
1544
1545}
1546
Cody Northropac6179b2014-10-29 12:09:45 -06001547void XglRenderTest::DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText,
1548 int textureCount, int samplerCount)
1549{
1550 // based on DrawTexturedTriangle
1551
1552 XGL_PIPELINE pipeline;
1553 XGL_SHADER vs, ps;
1554 XGL_RESULT err;
1555
1556 ASSERT_NO_FATAL_FAILURE(InitState());
1557 ASSERT_NO_FATAL_FAILURE(InitViewport());
1558
1559 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1560 vertShaderText, &vs));
1561
1562 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1563 fragShaderText, &ps));
1564
1565 ASSERT_NO_FATAL_FAILURE(CreatePipelineMultipleTexturesAndSamplers(&pipeline, vs, ps, textureCount, samplerCount));
1566
1567 /*
1568 * Shaders are now part of the pipeline, don't need these anymore
1569 */
1570 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1571 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1572
1573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1574
1575
1576 // Create a few texture/sampler pairs
1577 int textureColors[16];
1578 assert(textureCount < 16);
1579 textureColors[0] = 0xFF0000FF; //red
1580 textureColors[1] = 0xFF00FF00; //green
1581 textureColors[2] = 0xFFFF0000; //blue
1582
1583 ASSERT_NO_FATAL_FAILURE(InitMultipleSamplers(samplerCount));
1584 ASSERT_NO_FATAL_FAILURE(InitMultipleTextures(textureCount, textureColors));
1585
1586 // Create descriptor set for a texture and sampler resources
1587 const int slotCount = textureCount + samplerCount;
1588 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1589 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1590 descriptorInfo.slots = slotCount;
1591
1592 // create a descriptor set with a single slot
1593 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1594 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1595
1596 // bind memory to the descriptor set
1597 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1598
1599 // write the sampler and image views to the descriptor set
1600 // ensure this matches order set in CreatePipelineSingleTextureAndSampler
1601 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1602 int descSlot = 0;
1603 for (int i = 0; i < textureCount; ++i)
1604 xglAttachImageViewDescriptors( m_rsrcDescSet, descSlot++, 1, &m_textureViewInfo[i]);
1605 for (int i = 0; i < samplerCount; ++i)
1606 xglAttachSamplerDescriptors(m_rsrcDescSet, descSlot++, 1, &m_sampler[i]);
1607 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1608
1609 // Build command buffer
1610 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1611 ASSERT_XGL_SUCCESS(err);
1612
1613 GenerateClearAndPrepareBufferCmds();
1614 GenerateBindRenderTargetCmd();
1615 GenerateBindStateAndPipelineCmds(&pipeline);
1616
1617// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1618// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1619
1620 // render the cube
1621 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1622
1623 // prepare the back buffer for present
1624// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1625// transitionToPresent.image = m_image;
1626// transitionToPresent.oldState = m_image_state;
1627// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1628// transitionToPresent.subresourceRange = srRange;
1629// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1630// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1631
1632 // finalize recording of the command buffer
1633 err = xglEndCommandBuffer( m_cmdBuffer );
1634 ASSERT_XGL_SUCCESS( err );
1635
1636 // this command buffer only uses the vertex buffer memory
1637 m_numMemRefs = 0;
1638// m_memRefs[0].flags = 0;
1639// m_memRefs[0].mem = m_vtxBufferMemory;
1640
1641 // submit the command buffer to the universal queue
1642 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1643 ASSERT_XGL_SUCCESS( err );
1644
1645 err = xglQueueWaitIdle( m_device->m_queue );
1646 ASSERT_XGL_SUCCESS( err );
1647
1648 // Wait for work to finish before cleaning up.
1649 xglDeviceWaitIdle(m_device->device());
1650
1651 RecordImage(m_renderTarget);
1652
1653}
1654
Cody Northrop722ff402014-10-20 09:22:42 -06001655TEST_F(XglRenderTest, GreenTriangle)
1656{
1657 static const char *vertShaderText =
1658 "#version 130\n"
1659 "vec2 vertices[3];\n"
1660 "void main() {\n"
1661 " vertices[0] = vec2(-1.0, -1.0);\n"
1662 " vertices[1] = vec2( 1.0, -1.0);\n"
1663 " vertices[2] = vec2( 0.0, 1.0);\n"
1664 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1665 "}\n";
1666
1667 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001668 "#version 130\n"
1669 "void main() {\n"
1670 " gl_FragColor = vec4(0,1,0,1);\n"
1671 "}\n";
Cody Northrop722ff402014-10-20 09:22:42 -06001672
Cody Northrop722ff402014-10-20 09:22:42 -06001673 XglTestFramework::m_use_bil = true;
1674 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001675}
1676
GregFef5d9cf2014-10-22 14:40:26 -06001677TEST_F(XglRenderTest, MixTriangle)
1678{
1679 // This tests location applied to varyings. Notice that we have switched foo
1680 // and bar in the FS. The triangle should be blended with red, green and blue
1681 // corners.
1682 static const char *vertShaderText =
1683 "#version 140\n"
1684 "#extension GL_ARB_separate_shader_objects : enable\n"
1685 "#extension GL_ARB_shading_language_420pack : enable\n"
1686 "layout (location=0) out vec4 bar;\n"
1687 "layout (location=1) out vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001688 "layout (location=2) out float scale;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001689 "vec2 vertices[3];\n"
1690 "void main() {\n"
1691 " vertices[0] = vec2(-1.0, -1.0);\n"
1692 " vertices[1] = vec2( 1.0, -1.0);\n"
1693 " vertices[2] = vec2( 0.0, 1.0);\n"
1694 "vec4 colors[3];\n"
1695 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1696 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1697 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1698 " foo = colors[gl_VertexID % 3];\n"
1699 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001700 " scale = 1.0;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001701 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1702 "}\n";
1703
1704 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001705 "#version 140\n"
1706 "#extension GL_ARB_separate_shader_objects : enable\n"
1707 "#extension GL_ARB_shading_language_420pack : enable\n"
1708 "layout (location = 1) in vec4 bar;\n"
1709 "layout (location = 0) in vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001710 "layout (location = 2) in float scale;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001711 "void main() {\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001712 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001713 "}\n";
GregFef5d9cf2014-10-22 14:40:26 -06001714
GregF91b2d302014-10-23 10:44:44 -06001715 XglTestFramework::m_use_bil = true;
1716 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001717}
1718
1719TEST_F(XglRenderTest, TriangleWithVertexFetch)
1720{
1721 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001722 "#version 140\n"
1723 "#extension GL_ARB_separate_shader_objects : enable\n"
1724 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001725 //XYZ1( 0.f, 0.f, 0.f )
Cody Northrop6217b822014-10-30 11:20:22 -06001726 "layout (location = 1) in vec4 inColor;\n"
GregF781f8562014-11-04 13:42:39 -07001727 //XYZ1( -1, -1, -1 )
1728 "layout (location = 0) in vec4 pos;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001729 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001730 "void main() {\n"
1731 " outColor = inColor;\n"
1732 " gl_Position = pos;\n"
1733 "}\n";
1734
1735
1736 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001737 "#version 140\n"
1738 "#extension GL_ARB_separate_shader_objects : enable\n"
1739 "#extension GL_ARB_shading_language_420pack : enable\n"
1740 "layout (location = 0) in vec4 color;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001741 "void main() {\n"
1742 " gl_FragColor = color;\n"
1743 "}\n";
1744
Cody Northrop6217b822014-10-30 11:20:22 -06001745 XglTestFramework::m_use_bil = true;
Cody Northrop722ff402014-10-20 09:22:42 -06001746 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1747}
1748
GregF1ce3a832014-10-30 16:46:12 -06001749TEST_F(XglRenderTest, TriVertFetchAndVertID)
1750{
1751 // This tests that attributes work in the presence of gl_VertexID
1752
1753 static const char *vertShaderText =
1754 "#version 140\n"
1755 "#extension GL_ARB_separate_shader_objects : enable\n"
1756 "#extension GL_ARB_shading_language_420pack : enable\n"
1757 //XYZ1( -1, -1, -1 )
1758 "layout (location = 0) in vec4 pos;\n"
1759 //XYZ1( 0.f, 0.f, 0.f )
1760 "layout (location = 1) in vec4 inColor;\n"
1761 "layout (location = 0) out vec4 outColor;\n"
1762 "void main() {\n"
1763 " outColor = inColor;\n"
1764 " vec4 vertices[3];"
1765 " vertices[gl_VertexID % 3] = pos;\n"
1766 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1767 "}\n";
1768
1769
1770 static const char *fragShaderText =
1771 "#version 140\n"
1772 "#extension GL_ARB_separate_shader_objects : enable\n"
1773 "#extension GL_ARB_shading_language_420pack : enable\n"
1774 "layout (location = 0) in vec4 color;\n"
1775 "void main() {\n"
1776 " gl_FragColor = color;\n"
1777 "}\n";
1778
1779 XglTestFramework::m_use_bil = true;
1780 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1781}
1782
GregF31deb632014-10-31 17:36:18 -06001783TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1784{
1785 // This tests that attributes work in the presence of gl_VertexID
GregF8e5eb2b2014-11-04 14:20:50 -07001786 // and a dead attribute in position 0. Draws a triangle with yellow,
1787 // red and green corners, starting at top and going clockwise.
GregF31deb632014-10-31 17:36:18 -06001788
1789 static const char *vertShaderText =
1790 "#version 140\n"
1791 "#extension GL_ARB_separate_shader_objects : enable\n"
1792 "#extension GL_ARB_shading_language_420pack : enable\n"
1793 //XYZ1( -1, -1, -1 )
1794 "layout (location = 0) in vec4 pos;\n"
1795 //XYZ1( 0.f, 0.f, 0.f )
1796 "layout (location = 1) in vec4 inColor;\n"
1797 "layout (location = 0) out vec4 outColor;\n"
1798 "void main() {\n"
GregF8e5eb2b2014-11-04 14:20:50 -07001799 " outColor = inColor;\n"
1800 " vec2 vertices[3];"
1801 " vertices[0] = vec2(-1.0, -1.0);\n"
1802 " vertices[1] = vec2( 1.0, -1.0);\n"
1803 " vertices[2] = vec2( 0.0, 1.0);\n"
1804 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
GregF31deb632014-10-31 17:36:18 -06001805 "}\n";
1806
1807
1808 static const char *fragShaderText =
1809 "#version 140\n"
1810 "#extension GL_ARB_separate_shader_objects : enable\n"
1811 "#extension GL_ARB_shading_language_420pack : enable\n"
1812 "layout (location = 0) in vec4 color;\n"
1813 "void main() {\n"
1814 " gl_FragColor = color;\n"
1815 "}\n";
1816
1817 XglTestFramework::m_use_bil = true;
1818 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1819}
1820
Cody Northropc6953d02014-10-20 11:23:32 -06001821TEST_F(XglRenderTest, TexturedTriangle)
1822{
Cody Northrop5fa1d332014-10-20 11:51:32 -06001823 // The expected result from this test is a red and green checkered triangle
Cody Northropc6953d02014-10-20 11:23:32 -06001824 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001825 "#version 140\n"
1826 "#extension GL_ARB_separate_shader_objects : enable\n"
1827 "#extension GL_ARB_shading_language_420pack : enable\n"
1828 "layout (location = 0) out vec2 samplePos;\n"
Cody Northropc6953d02014-10-20 11:23:32 -06001829 "void main() {\n"
1830 " vec2 vertices[3];"
1831 " vertices[0] = vec2(-0.5, -0.5);\n"
1832 " vertices[1] = vec2( 0.5, -0.5);\n"
1833 " vertices[2] = vec2( 0.5, 0.5);\n"
1834 " vec2 positions[3];"
1835 " positions[0] = vec2( 0.0, 0.0);\n"
1836 " positions[1] = vec2( 1.0, 0.0);\n"
1837 " positions[2] = vec2( 1.0, 1.0);\n"
1838 " samplePos = positions[gl_VertexID % 3];\n"
1839 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1840 "}\n";
1841
1842 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001843 "#version 140\n"
1844 "#extension GL_ARB_separate_shader_objects : enable\n"
1845 "#extension GL_ARB_shading_language_420pack : enable\n"
1846 "layout (location = 0) in vec2 samplePos;\n"
1847 "layout (binding = 0) uniform sampler2D surface;\n"
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001848 "layout (location=0) out vec4 outColor;\n"
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001849 "void main() {\n"
1850 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1851 " outColor = texColor;\n"
1852 "}\n";
GregFea15e542014-11-03 16:52:56 -07001853
1854 XglTestFramework::m_use_bil = true;
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001855 DrawTexturedTriangle(vertShaderText, fragShaderText);
1856}
1857
GregFe636c1a2014-11-07 13:29:23 -07001858TEST_F(XglRenderTest, TexturedTriangleClip)
GregFef017512014-11-06 14:53:03 -07001859{
1860 // The expected result from this test is a red and green checkered triangle
1861 static const char *vertShaderText =
GregFe636c1a2014-11-07 13:29:23 -07001862 "#version 330\n"
GregFef017512014-11-06 14:53:03 -07001863 "#extension GL_ARB_separate_shader_objects : enable\n"
1864 "#extension GL_ARB_shading_language_420pack : enable\n"
1865 "layout (location = 0) out vec2 samplePos;\n"
GregFe636c1a2014-11-07 13:29:23 -07001866 "out gl_PerVertex {\n"
1867 " vec4 gl_Position;\n"
1868 " float gl_ClipDistance[1];\n"
1869 "};\n"
GregFef017512014-11-06 14:53:03 -07001870 "void main() {\n"
1871 " vec2 vertices[3];"
1872 " vertices[0] = vec2(-0.5, -0.5);\n"
1873 " vertices[1] = vec2( 0.5, -0.5);\n"
1874 " vertices[2] = vec2( 0.5, 0.5);\n"
1875 " vec2 positions[3];"
1876 " positions[0] = vec2( 0.0, 0.0);\n"
1877 " positions[1] = vec2( 1.0, 0.0);\n"
1878 " positions[2] = vec2( 1.0, 1.0);\n"
GregFe636c1a2014-11-07 13:29:23 -07001879 " float dists[3];\n"
1880 " dists[0] = 1.0;\n"
1881 " dists[1] = 1.0;\n"
1882 " dists[2] = -1.0;\n"
1883 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
GregFef017512014-11-06 14:53:03 -07001884 " samplePos = positions[gl_VertexID % 3];\n"
1885 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1886 "}\n";
1887
1888 static const char *fragShaderText =
1889 "#version 140\n"
1890 "#extension GL_ARB_separate_shader_objects : enable\n"
1891 "#extension GL_ARB_shading_language_420pack : enable\n"
1892 "layout (location = 0) in vec2 samplePos;\n"
1893 "layout (binding = 0) uniform sampler2D surface;\n"
1894 "layout (location=0) out vec4 outColor;\n"
1895 "void main() {\n"
1896 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1897 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1898 " outColor = texColor;\n"
1899 "}\n";
1900
GregFe636c1a2014-11-07 13:29:23 -07001901 XglTestFramework::m_use_bil = false;
GregFef017512014-11-06 14:53:03 -07001902 DrawTexturedTriangle(vertShaderText, fragShaderText);
1903}
1904
Cody Northrop9394e0c2014-10-23 10:21:47 -06001905TEST_F(XglRenderTest, VSTexture)
1906{
1907 // The expected result from this test is a green and red triangle;
1908 // one red vertex on the left, two green vertices on the right.
1909 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001910 "#version 140\n"
1911 "#extension GL_ARB_separate_shader_objects : enable\n"
1912 "#extension GL_ARB_shading_language_420pack : enable\n"
1913 "layout (location = 0) out vec4 texColor;\n"
1914 "layout (binding = 0) uniform sampler2D surface;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001915 "void main() {\n"
1916 " vec2 vertices[3];"
1917 " vertices[0] = vec2(-0.5, -0.5);\n"
1918 " vertices[1] = vec2( 0.5, -0.5);\n"
1919 " vertices[2] = vec2( 0.5, 0.5);\n"
1920 " vec2 positions[3];"
1921 " positions[0] = vec2( 0.0, 0.0);\n"
1922 " positions[1] = vec2( 0.25, 0.1);\n"
1923 " positions[2] = vec2( 0.1, 0.25);\n"
1924 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1925 " texColor = textureLod(surface, samplePos, 0.0);\n"
1926 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1927 "}\n";
1928
1929 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001930 "#version 140\n"
1931 "#extension GL_ARB_separate_shader_objects : enable\n"
1932 "#extension GL_ARB_shading_language_420pack : enable\n"
1933 "layout (location = 0) in vec4 texColor;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001934 "void main() {\n"
1935 " gl_FragColor = texColor;\n"
1936 "}\n";
1937
Cody Northrop6217b822014-10-30 11:20:22 -06001938 XglTestFramework::m_use_bil = true;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001939 DrawTexturedTriangle(vertShaderText, fragShaderText);
1940}
1941
Cody Northrop6217b822014-10-30 11:20:22 -06001942TEST_F(XglRenderTest, SamplerBindingsTriangle)
1943{
1944 // This test sets bindings on the samplers
1945 // For now we are asserting that sampler and texture pairs
1946 // march in lock step, and are set via GLSL binding. This can
1947 // and will probably change.
1948 // The sampler bindings should match the sampler and texture slot
1949 // number set up by the application.
1950 // This test will result in a blue triangle
1951 static const char *vertShaderText =
1952 "#version 140\n"
1953 "#extension GL_ARB_separate_shader_objects : enable\n"
1954 "#extension GL_ARB_shading_language_420pack : enable\n"
1955 "layout (location = 0) out vec4 samplePos;\n"
1956 "void main() {\n"
1957 " vec2 vertices[3];"
1958 " vertices[0] = vec2(-0.5, -0.5);\n"
1959 " vertices[1] = vec2( 0.5, -0.5);\n"
1960 " vertices[2] = vec2( 0.5, 0.5);\n"
1961 " vec2 positions[3];"
1962 " positions[0] = vec2( 0.0, 0.0);\n"
1963 " positions[1] = vec2( 1.0, 0.0);\n"
1964 " positions[2] = vec2( 1.0, 1.0);\n"
1965 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
1966 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1967 "}\n";
1968
1969 static const char *fragShaderText =
1970 "#version 140\n"
1971 "#extension GL_ARB_separate_shader_objects : enable\n"
1972 "#extension GL_ARB_shading_language_420pack : enable\n"
1973 "layout (location = 0) in vec4 samplePos;\n"
1974 "layout (binding = 0) uniform sampler2D surface0;\n"
1975 "layout (binding = 1) uniform sampler2D surface1;\n"
Cody Northrop929838b2014-11-05 17:08:33 -07001976 "layout (binding = 12) uniform sampler2D surface2;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001977 "void main() {\n"
1978 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
1979 "}\n";
1980
1981 XglTestFramework::m_use_bil = true;
1982 int textureCount = g_TextureCount;
1983 int samplerCount = g_SamplerCount;
1984 DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount);
1985}
1986
1987TEST_F(XglRenderTest, TriangleVSUniformBlock)
1988{
1989 // The expected result from this test is a blue triangle
1990
1991 static const char *vertShaderText =
1992 "#version 140\n"
1993 "#extension GL_ARB_separate_shader_objects : enable\n"
1994 "#extension GL_ARB_shading_language_420pack : enable\n"
1995 "layout (location = 0) out vec4 outColor;\n"
1996 "layout (std140, binding = 0) uniform bufferVals {\n"
1997 " vec4 red;\n"
1998 " vec4 green;\n"
1999 " vec4 blue;\n"
2000 " vec4 white;\n"
2001 "} myBufferVals;\n"
2002 "void main() {\n"
2003 " vec2 vertices[3];"
2004 " vertices[0] = vec2(-0.5, -0.5);\n"
2005 " vertices[1] = vec2( 0.5, -0.5);\n"
2006 " vertices[2] = vec2( 0.5, 0.5);\n"
2007 " outColor = myBufferVals.blue;\n"
2008 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2009 "}\n";
2010
2011 static const char *fragShaderText =
2012 "#version 140\n"
2013 "#extension GL_ARB_separate_shader_objects : enable\n"
2014 "#extension GL_ARB_shading_language_420pack : enable\n"
2015 "layout (location = 0) in vec4 inColor;\n"
2016 "void main() {\n"
2017 " gl_FragColor = inColor;\n"
2018 "}\n";
2019
2020 XglTestFramework::m_use_bil = true;
2021 DrawTriangleVSUniformBlock(vertShaderText, fragShaderText);
2022}
2023
Cody Northropec1d3c32014-10-28 15:41:42 -06002024TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2025{
2026 // This test allows the shader to select which buffer it is
2027 // pulling from using layout binding qualifier.
2028 // There are corresponding changes in the compiler stack that
2029 // will select the buffer using binding directly.
Cody Northrop6217b822014-10-30 11:20:22 -06002030 // The binding number should match the slot number set up by
2031 // the application.
Cody Northropec1d3c32014-10-28 15:41:42 -06002032 // The expected result from this test is a purple triangle
2033
2034 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06002035 "#version 140\n"
2036 "#extension GL_ARB_separate_shader_objects : enable\n"
2037 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northropec1d3c32014-10-28 15:41:42 -06002038 "void main() {\n"
2039 " vec2 vertices[3];"
2040 " vertices[0] = vec2(-0.5, -0.5);\n"
2041 " vertices[1] = vec2( 0.5, -0.5);\n"
2042 " vertices[2] = vec2( 0.5, 0.5);\n"
2043 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2044 "}\n";
2045
2046 static const char *fragShaderText =
2047 "#version 140\n"
2048 "#extension GL_ARB_separate_shader_objects : enable\n"
2049 "#extension GL_ARB_shading_language_420pack : enable\n"
2050 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2051 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2052 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Cody Northrop929838b2014-11-05 17:08:33 -07002053 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Cody Northropec1d3c32014-10-28 15:41:42 -06002054 "void main() {\n"
2055 " gl_FragColor = myBlueVal.color;\n"
2056 " gl_FragColor += myRedVal.color;\n"
2057 "}\n";
2058
Cody Northrop6217b822014-10-30 11:20:22 -06002059 XglTestFramework::m_use_bil = true;
Cody Northropec1d3c32014-10-28 15:41:42 -06002060 DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText);
2061}
2062
Cody Northrop929838b2014-11-05 17:08:33 -07002063TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2064{
2065 // This test is the same as TriangleFSUniformBlockBinding, but
2066 // it does not provide an instance name.
2067 // The expected result from this test is a purple triangle
2068
2069 static const char *vertShaderText =
2070 "#version 140\n"
2071 "#extension GL_ARB_separate_shader_objects : enable\n"
2072 "#extension GL_ARB_shading_language_420pack : enable\n"
2073 "void main() {\n"
2074 " vec2 vertices[3];"
2075 " vertices[0] = vec2(-0.5, -0.5);\n"
2076 " vertices[1] = vec2( 0.5, -0.5);\n"
2077 " vertices[2] = vec2( 0.5, 0.5);\n"
2078 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2079 "}\n";
2080
2081 static const char *fragShaderText =
2082 "#version 430\n"
2083 "#extension GL_ARB_separate_shader_objects : enable\n"
2084 "#extension GL_ARB_shading_language_420pack : enable\n"
2085 "layout (location = 0) uniform vec4 foo;\n"
2086 "layout (location = 1) uniform vec4 bar;\n"
2087 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2088 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2089 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2090 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
2091 "void main() {\n"
2092 " gl_FragColor = blue;\n"
2093 " gl_FragColor += red;\n"
2094 "}\n";
2095
2096 XglTestFramework::m_use_bil = true;
2097 DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText);
2098}
2099
Cody Northrop722ff402014-10-20 09:22:42 -06002100int main(int argc, char **argv) {
2101 int result;
2102
2103 ::testing::InitGoogleTest(&argc, argv);
2104 XglTestFramework::InitArgs(&argc, argv);
2105
2106 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2107
2108 result = RUN_ALL_TESTS();
2109
2110 XglTestFramework::Finish();
2111 return result;
2112}