blob: 1a36e0f10e6208f8585eaa1d57cd9d47ab93f78c [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;
Cody Northrop722ff402014-10-20 09:22:42 -0600261}
262
Cody Northropac6179b2014-10-29 12:09:45 -0600263void XglRenderTest::InitTexture(int textureSlot, int* color)
Cody Northrop722ff402014-10-20 09:22:42 -0600264{
265#define DEMO_TEXTURE_COUNT 1
266
Cody Northropac6179b2014-10-29 12:09:45 -0600267 const XGL_FORMAT tex_format = { XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM };
Cody Northrop722ff402014-10-20 09:22:42 -0600268 const XGL_INT tex_width = 16;
269 const XGL_INT tex_height = 16;
Cody Northropac6179b2014-10-29 12:09:45 -0600270 uint32_t tex_colors[DEMO_TEXTURE_COUNT][2];
271
272 // assign the texture color with parameter
273 assert(1 == DEMO_TEXTURE_COUNT);
274 if (color != NULL) {
275 tex_colors[0][0] = *color;
276 tex_colors[0][1] = *color;
277 } else {
Cody Northrop6217b822014-10-30 11:20:22 -0600278 tex_colors[0][0] = 0xff0000ff;
Cody Northropac6179b2014-10-29 12:09:45 -0600279 tex_colors[0][1] = 0xff00ff00;
280 }
281
Cody Northrop722ff402014-10-20 09:22:42 -0600282 XGL_RESULT err;
283 XGL_UINT i;
284
285 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
Cody Northrop722ff402014-10-20 09:22:42 -0600286 const XGL_IMAGE_CREATE_INFO image = {
287 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
288 .pNext = NULL,
289 .imageType = XGL_IMAGE_2D,
290 .format = tex_format,
291 .extent = { tex_width, tex_height, 1 },
292 .mipLevels = 1,
293 .arraySize = 1,
294 .samples = 1,
295 .tiling = XGL_LINEAR_TILING,
296 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
297 .flags = 0,
298 };
299 XGL_MEMORY_ALLOC_INFO mem_alloc;
300 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
301 mem_alloc.pNext = NULL;
302 mem_alloc.allocationSize = 0;
303 mem_alloc.alignment = 0;
304 mem_alloc.flags = 0;
305 mem_alloc.heapCount = 0;
306 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
307 XGL_IMAGE_VIEW_CREATE_INFO view;
308 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
309 view.pNext = NULL;
310 view.image = XGL_NULL_HANDLE;
311 view.viewType = XGL_IMAGE_VIEW_2D;
312 view.format = image.format;
313 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
314 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
315 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
316 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
317 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
318 view.subresourceRange.baseMipLevel = 0;
319 view.subresourceRange.mipLevels = 1;
320 view.subresourceRange.baseArraySlice = 0;
321 view.subresourceRange.arraySize = 1;
322 view.minLod = 0.0f;
323
324 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700325 XGL_SIZE mem_reqs_size= sizeof(XGL_MEMORY_REQUIREMENTS);
Cody Northrop722ff402014-10-20 09:22:42 -0600326
Cody Northrop722ff402014-10-20 09:22:42 -0600327 /* create image */
Cody Northropac6179b2014-10-29 12:09:45 -0600328 err = xglCreateImage(device(), &image, &m_texture[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600329 assert(!err);
330
Cody Northropac6179b2014-10-29 12:09:45 -0600331 err = xglGetObjectInfo(m_texture[textureSlot],
Cody Northrop722ff402014-10-20 09:22:42 -0600332 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
333 &mem_reqs_size, &mem_reqs);
334 assert(!err && mem_reqs_size == sizeof(mem_reqs));
335
336 mem_alloc.allocationSize = mem_reqs.size;
337 mem_alloc.alignment = mem_reqs.alignment;
338 mem_alloc.heapCount = mem_reqs.heapCount;
339 memcpy(mem_alloc.heaps, mem_reqs.heaps,
340 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
341
342 /* allocate memory */
Cody Northropac6179b2014-10-29 12:09:45 -0600343 err = xglAllocMemory(device(), &mem_alloc, &m_textureMem[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600344 assert(!err);
345
346 /* bind memory */
Cody Northropac6179b2014-10-29 12:09:45 -0600347 err = xglBindObjectMemory(m_texture[textureSlot], m_textureMem[textureSlot], 0);
Cody Northrop722ff402014-10-20 09:22:42 -0600348 assert(!err);
349
350 /* create image view */
Cody Northropac6179b2014-10-29 12:09:45 -0600351 view.image = m_texture[textureSlot];
352 err = xglCreateImageView(device(), &view, &m_textureView[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600353 assert(!err);
354 }
355
356 for (i = 0; i < DEMO_TEXTURE_COUNT; i++) {
357 const XGL_IMAGE_SUBRESOURCE subres = {
358 .aspect = XGL_IMAGE_ASPECT_COLOR,
359 .mipLevel = 0,
360 .arraySlice = 0,
361 };
362 XGL_SUBRESOURCE_LAYOUT layout;
Jon Ashburn6317c492014-11-21 11:33:20 -0700363 XGL_SIZE layout_size = sizeof(layout);
Cody Northrop722ff402014-10-20 09:22:42 -0600364 XGL_VOID *data;
365 XGL_INT x, y;
366
Cody Northropac6179b2014-10-29 12:09:45 -0600367 err = xglGetImageSubresourceInfo(m_texture[textureSlot], &subres,
Cody Northrop722ff402014-10-20 09:22:42 -0600368 XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout);
369 assert(!err && layout_size == sizeof(layout));
370
Cody Northropac6179b2014-10-29 12:09:45 -0600371 err = xglMapMemory(m_textureMem[textureSlot], 0, &data);
Cody Northrop722ff402014-10-20 09:22:42 -0600372 assert(!err);
373
374 for (y = 0; y < tex_height; y++) {
375 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
376 for (x = 0; x < tex_width; x++)
377 row[x] = tex_colors[i][(x & 1) ^ (y & 1)];
378 }
379
Cody Northropac6179b2014-10-29 12:09:45 -0600380 err = xglUnmapMemory(m_textureMem[textureSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600381 assert(!err);
382 }
383
Cody Northropac6179b2014-10-29 12:09:45 -0600384 m_textureViewInfo[textureSlot].view = m_textureView[textureSlot];
Cody Northrop722ff402014-10-20 09:22:42 -0600385}
386
Cody Northropac6179b2014-10-29 12:09:45 -0600387
388void XglRenderTest::InitMultipleTextures(int textureCount, int* colors)
389{
390
391 for (int i = 0; i < textureCount; ++i)
392 InitTexture(i, &colors[i]);
393}
394
395
396void XglRenderTest::InitMultipleSamplers(const int samplerCount)
397{
398 XGL_RESULT err;
399
400 for (int i = 0; i < samplerCount; ++i) {
401
402 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
403 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
404 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
405 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
406 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
407 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
408 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
409 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
410 samplerCreateInfo.mipLodBias = 0.0;
411 samplerCreateInfo.maxAnisotropy = 0.0;
412 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
413 samplerCreateInfo.minLod = 0.0;
414 samplerCreateInfo.maxLod = 0.0;
415 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
416
417 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[i]);
418 ASSERT_XGL_SUCCESS(err);
419 }
420}
421
422void XglRenderTest::InitSampler(int samplerSlot)
Cody Northrop722ff402014-10-20 09:22:42 -0600423{
424 XGL_RESULT err;
425
426 XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {};
427 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
428 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
429 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
430 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
431 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
432 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
433 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
434 samplerCreateInfo.mipLodBias = 0.0;
435 samplerCreateInfo.maxAnisotropy = 0.0;
436 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
437 samplerCreateInfo.minLod = 0.0;
438 samplerCreateInfo.maxLod = 0.0;
439 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
440
Cody Northropac6179b2014-10-29 12:09:45 -0600441 err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[samplerSlot]);
Cody Northrop722ff402014-10-20 09:22:42 -0600442 ASSERT_XGL_SUCCESS(err);
443}
444
Cody Northropac6179b2014-10-29 12:09:45 -0600445
Cody Northropec1d3c32014-10-28 15:41:42 -0600446void XglRenderTest::InitUniformBuffer(int constantCount, int constantSize,
447 int constantIndex, const void* data)
Cody Northrop722ff402014-10-20 09:22:42 -0600448{
Cody Northropec1d3c32014-10-28 15:41:42 -0600449 // based on XglRenderFramework::InitConstantBuffer
450 // mainly add an index when selecting which buffer you are creating
451
452 XGL_RESULT err = XGL_SUCCESS;
453
454 XGL_MEMORY_ALLOC_INFO alloc_info = {};
455 XGL_UINT8 *pData;
456
457 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
458 alloc_info.allocationSize = constantCount * constantSize;
459 alloc_info.alignment = 0;
460 alloc_info.heapCount = 1;
461 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
462
463 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
464 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
465
466 err = xglAllocMemory(device(), &alloc_info, &m_uniformBufferMem[constantIndex]);
467 ASSERT_XGL_SUCCESS(err);
468
469 err = xglMapMemory(m_uniformBufferMem[constantIndex], 0, (XGL_VOID **) &pData);
470 ASSERT_XGL_SUCCESS(err);
471
472 memcpy(pData, data, alloc_info.allocationSize);
473
474 err = xglUnmapMemory(m_uniformBufferMem[constantIndex]);
475 ASSERT_XGL_SUCCESS(err);
476
477 // set up the memory view for the constant buffer
478 this->m_uniformBufferView[constantIndex].stride = 16;
479 this->m_uniformBufferView[constantIndex].range = alloc_info.allocationSize;
480 this->m_uniformBufferView[constantIndex].offset = 0;
481 this->m_uniformBufferView[constantIndex].mem = m_uniformBufferMem[constantIndex];
482 this->m_uniformBufferView[constantIndex].format.channelFormat = XGL_CH_FMT_R32G32B32A32;
483 this->m_uniformBufferView[constantIndex].format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop722ff402014-10-20 09:22:42 -0600484}
485
486void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
487{
488 XGL_PIPELINE pipeline;
489 XGL_SHADER vs, ps;
490 XGL_RESULT err;
491
492 ASSERT_NO_FATAL_FAILURE(InitState());
493 ASSERT_NO_FATAL_FAILURE(InitViewport());
494
495 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
496 vertShaderText, &vs));
497
498 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
499 fragShaderText, &ps));
500
501 ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps));
502
503 /*
504 * Shaders are now part of the pipeline, don't need these anymore
505 */
506 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
507 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
508
509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
510
511 const int constantCount = 4;
512 const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 };
513 InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
514
515 // Create descriptor set for a uniform resource
516 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
517 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
518 descriptorInfo.slots = 1;
519
520 // create a descriptor set with a single slot
521 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
522 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
523
524 // bind memory to the descriptor set
525 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
526
527 // write the constant buffer view to the descriptor set
528 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
529 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
530 xglEndDescriptorSetUpdate( m_rsrcDescSet );
531
532 // Build command buffer
533 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
534 ASSERT_XGL_SUCCESS(err);
535
536 GenerateClearAndPrepareBufferCmds();
537 GenerateBindRenderTargetCmd();
538 GenerateBindStateAndPipelineCmds(&pipeline);
539
540// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
541// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
542
543 // render the cube
544 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
545
546 // prepare the back buffer for present
547// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
548// transitionToPresent.image = m_image;
549// transitionToPresent.oldState = m_image_state;
550// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
551// transitionToPresent.subresourceRange = srRange;
552// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
553// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
554
555 // finalize recording of the command buffer
556 err = xglEndCommandBuffer( m_cmdBuffer );
557 ASSERT_XGL_SUCCESS( err );
558
559 // this command buffer only uses the vertex buffer memory
560 m_numMemRefs = 0;
561// m_memRefs[0].flags = 0;
562// m_memRefs[0].mem = m_vtxBufferMemory;
563
564 // submit the command buffer to the universal queue
565 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
566 ASSERT_XGL_SUCCESS( err );
567
568 err = xglQueueWaitIdle( m_device->m_queue );
569 ASSERT_XGL_SUCCESS( err );
570
571 // Wait for work to finish before cleaning up.
572 xglDeviceWaitIdle(m_device->device());
573
574 RecordImage(m_renderTarget);
575
576}
577
Cody Northropc6953d02014-10-20 11:23:32 -0600578void XglRenderTest::DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText)
579{
580
581 // based on DrawTriangleTwoUniformsFS
582
583 XGL_PIPELINE pipeline;
584 XGL_SHADER vs, ps;
585 XGL_RESULT err;
586
587 ASSERT_NO_FATAL_FAILURE(InitState());
588 ASSERT_NO_FATAL_FAILURE(InitViewport());
589
590 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
591 vertShaderText, &vs));
592
593 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
594 fragShaderText, &ps));
595
596 ASSERT_NO_FATAL_FAILURE(CreatePipelineSingleTextureAndSampler(&pipeline, vs, ps));
597
598 /*
599 * Shaders are now part of the pipeline, don't need these anymore
600 */
601 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
602 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
603
604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
605
606
607 // Enable our single sampler
608 ASSERT_NO_FATAL_FAILURE(InitSampler());
609
610 // Enable our single texture
611 ASSERT_NO_FATAL_FAILURE(InitTexture());
612
613 // Create descriptor set for a texture and sampler resources
Cody Northrop5fa1d332014-10-20 11:51:32 -0600614 const int slotCount = 2;
Cody Northropc6953d02014-10-20 11:23:32 -0600615 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
616 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
617 descriptorInfo.slots = slotCount;
618
619 // create a descriptor set with a single slot
620 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
621 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
622
623 // bind memory to the descriptor set
624 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
625
626 // write the sampler and image views to the descriptor set
627 // ensure this matches order set in CreatePipelineSingleTextureAndSampler
628 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
Cody Northropac6179b2014-10-29 12:09:45 -0600629 xglAttachImageViewDescriptors( m_rsrcDescSet, 0, 1, &m_textureViewInfo[0] );
630 xglAttachSamplerDescriptors(m_rsrcDescSet, 1, 1, &m_sampler[0]);
Cody Northropc6953d02014-10-20 11:23:32 -0600631 xglEndDescriptorSetUpdate( m_rsrcDescSet );
632
633 // Build command buffer
634 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
635 ASSERT_XGL_SUCCESS(err);
636
637 GenerateClearAndPrepareBufferCmds();
638 GenerateBindRenderTargetCmd();
639 GenerateBindStateAndPipelineCmds(&pipeline);
640
641// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
642// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
643
644 // render the cube
645 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
646
647 // prepare the back buffer for present
648// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
649// transitionToPresent.image = m_image;
650// transitionToPresent.oldState = m_image_state;
651// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
652// transitionToPresent.subresourceRange = srRange;
653// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
654// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
655
656 // finalize recording of the command buffer
657 err = xglEndCommandBuffer( m_cmdBuffer );
658 ASSERT_XGL_SUCCESS( err );
659
660 // this command buffer only uses the vertex buffer memory
661 m_numMemRefs = 0;
662// m_memRefs[0].flags = 0;
663// m_memRefs[0].mem = m_vtxBufferMemory;
664
665 // submit the command buffer to the universal queue
666 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
667 ASSERT_XGL_SUCCESS( err );
668
669 err = xglQueueWaitIdle( m_device->m_queue );
670 ASSERT_XGL_SUCCESS( err );
671
672 // Wait for work to finish before cleaning up.
673 xglDeviceWaitIdle(m_device->device());
674
675 RecordImage(m_renderTarget);
676
677}
Cody Northrop722ff402014-10-20 09:22:42 -0600678
Cody Northrop0fdf64e2014-10-20 11:51:06 -0600679void XglRenderTest::DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText)
680{
681 // sourced from DrawTriangleVSUniform
682 XGL_PIPELINE pipeline;
683 XGL_SHADER vs, ps;
684 XGL_RESULT err;
685
686 ASSERT_NO_FATAL_FAILURE(InitState());
687 ASSERT_NO_FATAL_FAILURE(InitViewport());
688
689 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
690 vertShaderText, &vs));
691
692 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
693 fragShaderText, &ps));
694
695 ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps));
696
697 /*
698 * Shaders are now part of the pipeline, don't need these anymore
699 */
700 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
701 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
702
703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
704
705 // Let's populate our buffer with the following:
706 // vec4 red;
707 // vec4 green;
708 // vec4 blue;
709 // vec4 white;
710 const int valCount = 4 * 4;
711 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
712 0.0, 1.0, 0.0, 1.0,
713 0.0, 0.0, 1.0, 1.0,
714 1.0, 1.0, 1.0, 1.0 };
715
716 InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
717
718 // Create descriptor set for a uniform resource
719 const int slotCount = 1;
720 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
721 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
722 descriptorInfo.slots = slotCount;
723
724 // create a descriptor set with a single slot
725 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
726 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
727
728 // bind memory to the descriptor set
729 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
730
731 // write the constant buffer view to the descriptor set
732 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
733 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
734 xglEndDescriptorSetUpdate( m_rsrcDescSet );
735
736 // Build command buffer
737 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
738 ASSERT_XGL_SUCCESS(err);
739
740 GenerateClearAndPrepareBufferCmds();
741 GenerateBindRenderTargetCmd();
742 GenerateBindStateAndPipelineCmds(&pipeline);
743
744// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
745// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
746
747 // render the cube
748 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
749
750 // prepare the back buffer for present
751// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
752// transitionToPresent.image = m_image;
753// transitionToPresent.oldState = m_image_state;
754// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
755// transitionToPresent.subresourceRange = srRange;
756// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
757// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
758
759 // finalize recording of the command buffer
760 err = xglEndCommandBuffer( m_cmdBuffer );
761 ASSERT_XGL_SUCCESS( err );
762
763 // this command buffer only uses the vertex buffer memory
764 m_numMemRefs = 0;
765// m_memRefs[0].flags = 0;
766// m_memRefs[0].mem = m_vtxBufferMemory;
767
768 // submit the command buffer to the universal queue
769 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
770 ASSERT_XGL_SUCCESS( err );
771
772 err = xglQueueWaitIdle( m_device->m_queue );
773 ASSERT_XGL_SUCCESS( err );
774
775 // Wait for work to finish before cleaning up.
776 xglDeviceWaitIdle(m_device->device());
777
778 RecordImage(m_renderTarget);
779}
780
Cody Northrop722ff402014-10-20 09:22:42 -0600781void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
782{
783 XGL_RESULT err;
784 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
785 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
786 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
787
788
789 // Create descriptor set for our one resource
790 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
791 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
792 descriptorInfo.slots = 1; // Vertex buffer only
793
794 // create a descriptor set with a single slot
795 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
796 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
797
798 // bind memory to the descriptor set
799 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
800
Jon Ashburn3a8c3562014-11-19 09:23:30 -0700801 memset(&vs_stage, 0, sizeof(vs_stage));
Cody Northrop722ff402014-10-20 09:22:42 -0600802 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
803 vs_stage.pNext = XGL_NULL_HANDLE;
804 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
805 vs_stage.shader.shader = vs;
Chia-I Wu3b04af52014-11-08 10:48:20 +0800806 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
Cody Northrop722ff402014-10-20 09:22:42 -0600807 vs_stage.shader.linkConstBufferCount = 0;
808 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
809 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
810 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
811
Jon Ashburn3a8c3562014-11-19 09:23:30 -0700812 memset(&ps_stage, 0, sizeof(ps_stage));
Cody Northrop722ff402014-10-20 09:22:42 -0600813 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
814 ps_stage.pNext = &vs_stage;
815 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
816 ps_stage.shader.shader = ps;
817 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
818 ps_stage.shader.linkConstBufferCount = 0;
819 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
820 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
821 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
822
823 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
824 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
825 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
826 };
827
828 // this is the current description of g_vbData
829 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
830 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
831 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
832 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
833 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
834 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
835 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
836 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
837 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
838
839 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = {
840 XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType;
841 &ps_stage, // pNext;
842 1, // bindingCount
843 &vi_binding, // pVertexBindingDescriptions;
844 2, // attributeCount; // number of attributes
845 vi_attribs // pVertexAttributeDescriptions;
846 };
847
848 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
849 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
850 &vi_state, // pNext
851 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
852 XGL_FALSE, // disableVertexReuse
853 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
854 XGL_FALSE, // primitiveRestartEnable
855 0 // primitiveRestartIndex
856 };
857
858 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
859 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
860 &ia_state,
861 XGL_FALSE, // depthClipEnable
862 XGL_FALSE, // rasterizerDiscardEnable
863 1.0 // pointSize
864 };
865
866 XGL_PIPELINE_CB_STATE cb_state = {
867 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
868 &rs_state,
869 XGL_FALSE, // alphaToCoverageEnable
870 XGL_FALSE, // dualSourceBlendEnable
871 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
872 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
873 {
874 XGL_FALSE, // blendEnable
875 m_render_target_fmt, // XGL_FORMAT
876 0xF // channelWriteMask
877 }
878 }
879 };
880
881 // TODO: Should take depth buffer format from queried formats
882 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
883 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
884 &cb_state,
885 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
886 };
887
888 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
889 info.pNext = &db_state;
890 info.flags = 0;
891 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
892 ASSERT_XGL_SUCCESS(err);
893
894 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
895 ASSERT_XGL_SUCCESS(err);
896}
897
898void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
899{
900 XGL_RESULT err;
901 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
902 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
903 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
904
905
906 const int vsSlots = 1; // Uniform buffer only
907
908 // Create descriptor set for our one resource
909 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
910 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
911 descriptorInfo.slots = vsSlots;
912
913 // create a descriptor set with a single slot
914 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
915 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
916
917 // bind memory to the descriptor set
918 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
919
920
921 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
922 slotInfo[0].shaderEntityIndex = 0;
923 slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
924
Jon Ashburn3a8c3562014-11-19 09:23:30 -0700925 memset(&vs_stage, 0, sizeof(vs_stage));
Cody Northrop722ff402014-10-20 09:22:42 -0600926 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
927 vs_stage.pNext = XGL_NULL_HANDLE;
928 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
929 vs_stage.shader.shader = vs;
930 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
931 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
932 vs_stage.shader.linkConstBufferCount = 0;
933 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
934 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
935 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
936
Jon Ashburn3a8c3562014-11-19 09:23:30 -0700937 memset(&ps_stage, 0, sizeof(ps_stage));
Cody Northrop722ff402014-10-20 09:22:42 -0600938 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
939 ps_stage.pNext = &vs_stage;
940 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
941 ps_stage.shader.shader = ps;
942 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
943 ps_stage.shader.linkConstBufferCount = 0;
944 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
945 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
946 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
947
948 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
949 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
950 &ps_stage, // pNext
951 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
952 XGL_FALSE, // disableVertexReuse
953 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
954 XGL_FALSE, // primitiveRestartEnable
955 0 // primitiveRestartIndex
956 };
957
958 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
959 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
960 &ia_state,
961 XGL_FALSE, // depthClipEnable
962 XGL_FALSE, // rasterizerDiscardEnable
963 1.0 // pointSize
964 };
965
966 XGL_PIPELINE_CB_STATE cb_state = {
967 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
968 &rs_state,
969 XGL_FALSE, // alphaToCoverageEnable
970 XGL_FALSE, // dualSourceBlendEnable
971 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
972 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
973 {
974 XGL_FALSE, // blendEnable
975 m_render_target_fmt, // XGL_FORMAT
976 0xF // channelWriteMask
977 }
978 }
979 };
980
981 // TODO: Should take depth buffer format from queried formats
982 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
983 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
984 &cb_state,
985 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
986 };
987
988 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
989 info.pNext = &db_state;
990 info.flags = 0;
991 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
992 ASSERT_XGL_SUCCESS(err);
993
994 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
995 ASSERT_XGL_SUCCESS(err);
996}
997
Cody Northropec1d3c32014-10-28 15:41:42 -0600998void XglRenderTest::CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, const int bufferCount)
999{
1000 // based on CreateDefaultPipeline
1001 // only difference is number of constant buffers
1002
1003 XGL_RESULT err;
1004 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1005 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1006 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1007
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001008 memset(&vs_stage, 0, sizeof(vs_stage));
Cody Northropec1d3c32014-10-28 15:41:42 -06001009 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1010 vs_stage.pNext = XGL_NULL_HANDLE;
1011 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1012 vs_stage.shader.shader = vs;
1013 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
1014 vs_stage.shader.linkConstBufferCount = 0;
1015 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1016 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1017 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1018
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001019 memset(&ps_stage, 0, sizeof(ps_stage));
Cody Northropec1d3c32014-10-28 15:41:42 -06001020 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1021 ps_stage.pNext = &vs_stage;
1022 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1023 ps_stage.shader.shader = ps;
1024
1025// const int slots = 4;
1026// assert (slots == bufferCount); // update as needed
1027
1028 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( bufferCount * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
Cody Northrop929838b2014-11-05 17:08:33 -07001029 for (int i = 0; i < bufferCount - 1; ++i) {
Cody Northropec1d3c32014-10-28 15:41:42 -06001030 // Note: These are all constant buffers
1031 slotInfo[i].shaderEntityIndex = i;
1032 slotInfo[i].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1033 }
1034
Cody Northrop929838b2014-11-05 17:08:33 -07001035 slotInfo[bufferCount - 1].shaderEntityIndex = 18;
1036 slotInfo[bufferCount - 1].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1037
Cody Northropec1d3c32014-10-28 15:41:42 -06001038 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1039 ps_stage.shader.descriptorSetMapping[0].descriptorCount = bufferCount;
1040
1041 ps_stage.shader.linkConstBufferCount = 0;
1042 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1043 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1044 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1045
1046 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1047 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1048 &ps_stage, // pNext
1049 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1050 XGL_FALSE, // disableVertexReuse
1051 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1052 XGL_FALSE, // primitiveRestartEnable
1053 0 // primitiveRestartIndex
1054 };
1055
1056 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1057 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1058 &ia_state,
1059 XGL_FALSE, // depthClipEnable
1060 XGL_FALSE, // rasterizerDiscardEnable
1061 1.0 // pointSize
1062 };
1063
1064 XGL_PIPELINE_CB_STATE cb_state = {
1065 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1066 &rs_state,
1067 XGL_FALSE, // alphaToCoverageEnable
1068 XGL_FALSE, // dualSourceBlendEnable
1069 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1070 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1071 {
1072 XGL_FALSE, // blendEnable
1073 m_render_target_fmt, // XGL_FORMAT
1074 0xF // channelWriteMask
1075 }
1076 }
1077 };
1078
1079 // TODO: Should take depth buffer format from queried formats
1080 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1081 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1082 &cb_state,
1083 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1084 };
1085
1086 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1087 info.pNext = &db_state;
1088 info.flags = 0;
1089 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1090 ASSERT_XGL_SUCCESS(err);
1091
1092 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1093 ASSERT_XGL_SUCCESS(err);
1094}
1095
Cody Northropc6953d02014-10-20 11:23:32 -06001096void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
1097{
1098 // based on CreatePipelineVSUniform
1099
1100 XGL_RESULT err;
1101 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1102 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1103 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1104
Cody Northrop9394e0c2014-10-23 10:21:47 -06001105 const int vsSlots = 2; // One texture, one sampler
Cody Northropc6953d02014-10-20 11:23:32 -06001106
1107 // Create descriptor set for single texture and sampler
Cody Northrop9394e0c2014-10-23 10:21:47 -06001108 XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {};
1109 vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1110 vsDescriptorInfo.slots = vsSlots;
1111 err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &m_rsrcDescSet );
Cody Northropc6953d02014-10-20 11:23:32 -06001112 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1113 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1114
Cody Northropc6953d02014-10-20 11:23:32 -06001115 // Assign the slots, note that only t0 and s0 will work as of writing this test
Cody Northrop9394e0c2014-10-23 10:21:47 -06001116 XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1117 vsSlotInfo[0].shaderEntityIndex = 0;
1118 vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1119 vsSlotInfo[1].shaderEntityIndex = 0;
1120 vsSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
Cody Northropc6953d02014-10-20 11:23:32 -06001121
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001122 memset(&vs_stage, 0, sizeof(vs_stage));
Cody Northropc6953d02014-10-20 11:23:32 -06001123 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1124 vs_stage.pNext = XGL_NULL_HANDLE;
1125 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1126 vs_stage.shader.shader = vs;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001127 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo;
1128 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
Cody Northropc6953d02014-10-20 11:23:32 -06001129 vs_stage.shader.linkConstBufferCount = 0;
1130 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1131 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1132 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1133
Cody Northrop9394e0c2014-10-23 10:21:47 -06001134 const int psSlots = 2; // One texture, one sampler
1135
1136 // Create descriptor set for single texture and sampler
1137 XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {};
1138 psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1139 psDescriptorInfo.slots = psSlots;
1140 err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet );
1141 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1142 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1143
1144 // Assign the slots, note that only t0 and s0 will work as of writing this test
1145 XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1146 psSlotInfo[0].shaderEntityIndex = 0;
1147 psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1148 psSlotInfo[1].shaderEntityIndex = 0;
1149 psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1150
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001151 memset(&ps_stage, 0, sizeof(ps_stage));
Cody Northropc6953d02014-10-20 11:23:32 -06001152 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1153 ps_stage.pNext = &vs_stage;
1154 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1155 ps_stage.shader.shader = ps;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001156 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) psSlotInfo;
Cody Northropc6953d02014-10-20 11:23:32 -06001157 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1158 ps_stage.shader.linkConstBufferCount = 0;
1159 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1160 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1161 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1162
1163 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1164 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1165 &ps_stage, // pNext
1166 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1167 XGL_FALSE, // disableVertexReuse
1168 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1169 XGL_FALSE, // primitiveRestartEnable
1170 0 // primitiveRestartIndex
1171 };
1172
1173 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1174 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1175 &ia_state,
1176 XGL_FALSE, // depthClipEnable
1177 XGL_FALSE, // rasterizerDiscardEnable
1178 1.0 // pointSize
1179 };
1180
1181 XGL_PIPELINE_CB_STATE cb_state = {
1182 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1183 &rs_state,
1184 XGL_FALSE, // alphaToCoverageEnable
1185 XGL_FALSE, // dualSourceBlendEnable
1186 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1187 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1188 {
1189 XGL_FALSE, // blendEnable
1190 m_render_target_fmt, // XGL_FORMAT
1191 0xF // channelWriteMask
1192 }
1193 }
1194 };
1195
1196 // TODO: Should take depth buffer format from queried formats
1197 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1198 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1199 &cb_state,
1200 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1201 };
1202
1203 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1204 info.pNext = &db_state;
1205 info.flags = 0;
1206 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1207 ASSERT_XGL_SUCCESS(err);
1208
1209 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1210 ASSERT_XGL_SUCCESS(err);
1211}
1212
Cody Northropac6179b2014-10-29 12:09:45 -06001213void XglRenderTest::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps,
1214 int textureCount, int samplerCount)
1215{
1216 // based on CreatePipelineSingleTextureAndSampler
1217
1218 XGL_RESULT err;
1219 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1220 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1221 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1222
1223 const int psSlots = textureCount + samplerCount;
1224
1225 // Create descriptor set for single texture and sampler
1226 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1227 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1228 descriptorInfo.slots = psSlots;
1229 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1230 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1231 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1232
1233 // Assign the slots, note that only t0 and s0 will work as of writing this test
1234 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1235 int slotIndex = 0;
Cody Northrop929838b2014-11-05 17:08:33 -07001236 for (int i = 0; i < textureCount - 1; ++i) {
Cody Northropac6179b2014-10-29 12:09:45 -06001237 slotInfo[slotIndex].shaderEntityIndex = i;
1238 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1239 }
Cody Northrop929838b2014-11-05 17:08:33 -07001240 slotInfo[slotIndex].shaderEntityIndex = 12;
1241 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1242 for (int i = 0; i < samplerCount - 1; ++i) {
Cody Northropac6179b2014-10-29 12:09:45 -06001243 slotInfo[slotIndex].shaderEntityIndex = i;
1244 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1245 }
1246
Cody Northrop929838b2014-11-05 17:08:33 -07001247 slotInfo[slotIndex].shaderEntityIndex = 12;
1248 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1249
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001250 memset(&vs_stage, 0, sizeof(vs_stage));
Cody Northropac6179b2014-10-29 12:09:45 -06001251 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1252 vs_stage.pNext = XGL_NULL_HANDLE;
1253 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1254 vs_stage.shader.shader = vs;
1255 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
1256 vs_stage.shader.linkConstBufferCount = 0;
1257 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1258 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1259 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1260
Jon Ashburn3a8c3562014-11-19 09:23:30 -07001261 memset(&ps_stage, 0, sizeof(ps_stage));
Cody Northropac6179b2014-10-29 12:09:45 -06001262 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1263 ps_stage.pNext = &vs_stage;
1264 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1265 ps_stage.shader.shader = ps;
1266 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1267 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1268 ps_stage.shader.linkConstBufferCount = 0;
1269 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1270 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1271 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1272
1273 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1274 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1275 &ps_stage, // pNext
1276 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1277 XGL_FALSE, // disableVertexReuse
1278 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1279 XGL_FALSE, // primitiveRestartEnable
1280 0 // primitiveRestartIndex
1281 };
1282
1283 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1284 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1285 &ia_state,
1286 XGL_FALSE, // depthClipEnable
1287 XGL_FALSE, // rasterizerDiscardEnable
1288 1.0 // pointSize
1289 };
1290
1291 XGL_PIPELINE_CB_STATE cb_state = {
1292 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1293 &rs_state,
1294 XGL_FALSE, // alphaToCoverageEnable
1295 XGL_FALSE, // dualSourceBlendEnable
1296 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1297 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1298 {
1299 XGL_FALSE, // blendEnable
1300 m_render_target_fmt, // XGL_FORMAT
1301 0xF // channelWriteMask
1302 }
1303 }
1304 };
1305
1306 // TODO: Should take depth buffer format from queried formats
1307 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1308 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1309 &cb_state,
1310 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1311 };
1312
1313 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1314 info.pNext = &db_state;
1315 info.flags = 0;
1316 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1317 ASSERT_XGL_SUCCESS(err);
1318
1319 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1320 ASSERT_XGL_SUCCESS(err);
1321}
1322
Cody Northrop722ff402014-10-20 09:22:42 -06001323void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
1324{
1325 XGL_PIPELINE pipeline;
1326 XGL_SHADER vs, ps;
1327 XGL_RESULT err;
1328
1329 ASSERT_NO_FATAL_FAILURE(InitState());
1330 ASSERT_NO_FATAL_FAILURE(InitViewport());
1331 ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData));
1332
1333 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1334 vertShaderText, &vs));
1335
1336 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1337 fragShaderText, &ps));
1338
1339 ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps));
1340
1341 /*
1342 * Shaders are now part of the pipeline, don't need these anymore
1343 */
1344 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1345 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1346
1347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1348
1349 // Build command buffer
1350 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1351 ASSERT_XGL_SUCCESS(err);
1352
1353 GenerateClearAndPrepareBufferCmds();
1354 GenerateBindRenderTargetCmd();
1355 GenerateBindStateAndPipelineCmds(&pipeline);
1356
1357// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1358// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1359
1360 // render the cube
1361 xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 );
1362
1363 // prepare the back buffer for present
1364// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1365// transitionToPresent.image = m_image;
1366// transitionToPresent.oldState = m_image_state;
1367// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1368// transitionToPresent.subresourceRange = srRange;
1369// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1370// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1371
1372 // finalize recording of the command buffer
1373 err = xglEndCommandBuffer( m_cmdBuffer );
1374 ASSERT_XGL_SUCCESS( err );
1375
1376 // this command buffer only uses the vertex buffer memory
1377 m_numMemRefs = 0;
1378// m_memRefs[0].flags = 0;
1379// m_memRefs[0].mem = m_vtxBufferMemory;
1380
1381 // submit the command buffer to the universal queue
1382 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1383 ASSERT_XGL_SUCCESS( err );
1384
1385 err = xglQueueWaitIdle( m_device->m_queue );
1386 ASSERT_XGL_SUCCESS( err );
1387
1388 // Wait for work to finish before cleaning up.
1389 xglDeviceWaitIdle(m_device->device());
1390
1391 RecordImage(m_renderTarget);
1392
1393}
1394
Cody Northropec1d3c32014-10-28 15:41:42 -06001395void XglRenderTest::DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText)
1396{
1397 // sourced from DrawTriangleFSUniformBlock
1398
1399 XGL_PIPELINE pipeline;
1400 XGL_SHADER vs, ps;
1401 XGL_RESULT err;
1402
1403 ASSERT_NO_FATAL_FAILURE(InitState());
1404 ASSERT_NO_FATAL_FAILURE(InitViewport());
1405
1406 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1407 vertShaderText, &vs));
1408
1409 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1410 fragShaderText, &ps));
1411
1412 const int bufferCount = 4;
1413 ASSERT_NO_FATAL_FAILURE(CreatePipelineFSUniformBlockBinding(&pipeline, vs, ps, bufferCount));
1414
1415 /*
1416 * Shaders are now part of the pipeline, don't need these anymore
1417 */
1418 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1419 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1420
1421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1422
1423
1424 // We're going to create a number of uniform buffers, and then allow
1425 // the shader to select which it wants to read from with a binding
1426
1427 // Let's populate the buffers with a single color each:
1428 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
1429 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
1430 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
1431 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
1432
1433 assert(4 == bufferCount); // update the following code if you want more than 4
1434
1435 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
1436 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
1437 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
1438 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
1439
1440 const int redCount = sizeof(redVals) / sizeof(float);
1441 const int greenCount = sizeof(greenVals) / sizeof(float);
1442 const int blueCount = sizeof(blueVals) / sizeof(float);
1443 const int whiteCount = sizeof(whiteVals) / sizeof(float);
1444
1445 int index = 0;
1446 InitUniformBuffer(redCount, sizeof(redVals[0]), index++, (const void *) redVals);
1447 InitUniformBuffer(greenCount, sizeof(greenVals[0]), index++, (const void *) greenVals);
1448 InitUniformBuffer(blueCount, sizeof(blueVals[0]), index++, (const void *) blueVals);
1449 InitUniformBuffer(whiteCount, sizeof(whiteVals[0]), index++, (const void *) whiteVals);
1450
1451
1452 // Create descriptor set for a uniform resource
1453 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1454 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1455 descriptorInfo.slots = bufferCount;
1456
1457 // create a descriptor set with a single slot
1458 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1459 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1460
1461 // bind memory to the descriptor set
1462 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1463
1464 // write the constant buffer view to the descriptor set
1465 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1466
1467 for(int i = 0; i < bufferCount; ++i)
1468 xglAttachMemoryViewDescriptors( m_rsrcDescSet, i, 1, &m_uniformBufferView[i] );
1469
1470 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1471
1472 // Build command buffer
1473 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1474 ASSERT_XGL_SUCCESS(err);
1475
1476 GenerateClearAndPrepareBufferCmds();
1477 GenerateBindRenderTargetCmd();
1478 GenerateBindStateAndPipelineCmds(&pipeline);
1479
1480// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1481// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1482
1483 // render the cube
1484 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1485
1486 // prepare the back buffer for present
1487// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1488// transitionToPresent.image = m_image;
1489// transitionToPresent.oldState = m_image_state;
1490// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1491// transitionToPresent.subresourceRange = srRange;
1492// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1493// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1494
1495 // finalize recording of the command buffer
1496 err = xglEndCommandBuffer( m_cmdBuffer );
1497 ASSERT_XGL_SUCCESS( err );
1498
1499 // this command buffer only uses the vertex buffer memory
1500 m_numMemRefs = 0;
1501// m_memRefs[0].flags = 0;
1502// m_memRefs[0].mem = m_vtxBufferMemory;
1503
1504 // submit the command buffer to the universal queue
1505 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1506 ASSERT_XGL_SUCCESS( err );
1507
1508 err = xglQueueWaitIdle( m_device->m_queue );
1509 ASSERT_XGL_SUCCESS( err );
1510
1511 // Wait for work to finish before cleaning up.
1512 xglDeviceWaitIdle(m_device->device());
1513
1514 RecordImage(m_renderTarget);
1515
1516}
1517
Cody Northropac6179b2014-10-29 12:09:45 -06001518void XglRenderTest::DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText,
1519 int textureCount, int samplerCount)
1520{
1521 // based on DrawTexturedTriangle
1522
1523 XGL_PIPELINE pipeline;
1524 XGL_SHADER vs, ps;
1525 XGL_RESULT err;
1526
1527 ASSERT_NO_FATAL_FAILURE(InitState());
1528 ASSERT_NO_FATAL_FAILURE(InitViewport());
1529
1530 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1531 vertShaderText, &vs));
1532
1533 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1534 fragShaderText, &ps));
1535
1536 ASSERT_NO_FATAL_FAILURE(CreatePipelineMultipleTexturesAndSamplers(&pipeline, vs, ps, textureCount, samplerCount));
1537
1538 /*
1539 * Shaders are now part of the pipeline, don't need these anymore
1540 */
1541 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1542 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1543
1544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1545
1546
1547 // Create a few texture/sampler pairs
1548 int textureColors[16];
1549 assert(textureCount < 16);
1550 textureColors[0] = 0xFF0000FF; //red
1551 textureColors[1] = 0xFF00FF00; //green
1552 textureColors[2] = 0xFFFF0000; //blue
1553
1554 ASSERT_NO_FATAL_FAILURE(InitMultipleSamplers(samplerCount));
1555 ASSERT_NO_FATAL_FAILURE(InitMultipleTextures(textureCount, textureColors));
1556
1557 // Create descriptor set for a texture and sampler resources
1558 const int slotCount = textureCount + samplerCount;
1559 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1560 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1561 descriptorInfo.slots = slotCount;
1562
1563 // create a descriptor set with a single slot
1564 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1565 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1566
1567 // bind memory to the descriptor set
1568 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1569
1570 // write the sampler and image views to the descriptor set
1571 // ensure this matches order set in CreatePipelineSingleTextureAndSampler
1572 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1573 int descSlot = 0;
1574 for (int i = 0; i < textureCount; ++i)
1575 xglAttachImageViewDescriptors( m_rsrcDescSet, descSlot++, 1, &m_textureViewInfo[i]);
1576 for (int i = 0; i < samplerCount; ++i)
1577 xglAttachSamplerDescriptors(m_rsrcDescSet, descSlot++, 1, &m_sampler[i]);
1578 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1579
1580 // Build command buffer
1581 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1582 ASSERT_XGL_SUCCESS(err);
1583
1584 GenerateClearAndPrepareBufferCmds();
1585 GenerateBindRenderTargetCmd();
1586 GenerateBindStateAndPipelineCmds(&pipeline);
1587
1588// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1589// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1590
1591 // render the cube
1592 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1593
1594 // prepare the back buffer for present
1595// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1596// transitionToPresent.image = m_image;
1597// transitionToPresent.oldState = m_image_state;
1598// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1599// transitionToPresent.subresourceRange = srRange;
1600// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1601// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1602
1603 // finalize recording of the command buffer
1604 err = xglEndCommandBuffer( m_cmdBuffer );
1605 ASSERT_XGL_SUCCESS( err );
1606
1607 // this command buffer only uses the vertex buffer memory
1608 m_numMemRefs = 0;
1609// m_memRefs[0].flags = 0;
1610// m_memRefs[0].mem = m_vtxBufferMemory;
1611
1612 // submit the command buffer to the universal queue
1613 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1614 ASSERT_XGL_SUCCESS( err );
1615
1616 err = xglQueueWaitIdle( m_device->m_queue );
1617 ASSERT_XGL_SUCCESS( err );
1618
1619 // Wait for work to finish before cleaning up.
1620 xglDeviceWaitIdle(m_device->device());
1621
1622 RecordImage(m_renderTarget);
1623
1624}
1625
Cody Northrop722ff402014-10-20 09:22:42 -06001626TEST_F(XglRenderTest, GreenTriangle)
1627{
1628 static const char *vertShaderText =
1629 "#version 130\n"
1630 "vec2 vertices[3];\n"
1631 "void main() {\n"
1632 " vertices[0] = vec2(-1.0, -1.0);\n"
1633 " vertices[1] = vec2( 1.0, -1.0);\n"
1634 " vertices[2] = vec2( 0.0, 1.0);\n"
1635 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1636 "}\n";
1637
1638 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001639 "#version 130\n"
1640 "void main() {\n"
1641 " gl_FragColor = vec4(0,1,0,1);\n"
1642 "}\n";
Cody Northrop722ff402014-10-20 09:22:42 -06001643
Cody Northrop722ff402014-10-20 09:22:42 -06001644 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001645}
1646
GregFef5d9cf2014-10-22 14:40:26 -06001647TEST_F(XglRenderTest, MixTriangle)
1648{
1649 // This tests location applied to varyings. Notice that we have switched foo
1650 // and bar in the FS. The triangle should be blended with red, green and blue
1651 // corners.
1652 static const char *vertShaderText =
1653 "#version 140\n"
1654 "#extension GL_ARB_separate_shader_objects : enable\n"
1655 "#extension GL_ARB_shading_language_420pack : enable\n"
1656 "layout (location=0) out vec4 bar;\n"
1657 "layout (location=1) out vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001658 "layout (location=2) out float scale;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001659 "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 "vec4 colors[3];\n"
1665 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1666 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1667 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1668 " foo = colors[gl_VertexID % 3];\n"
1669 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001670 " scale = 1.0;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001671 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1672 "}\n";
1673
1674 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001675 "#version 140\n"
1676 "#extension GL_ARB_separate_shader_objects : enable\n"
1677 "#extension GL_ARB_shading_language_420pack : enable\n"
1678 "layout (location = 1) in vec4 bar;\n"
1679 "layout (location = 0) in vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001680 "layout (location = 2) in float scale;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001681 "void main() {\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001682 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001683 "}\n";
GregFef5d9cf2014-10-22 14:40:26 -06001684
GregF91b2d302014-10-23 10:44:44 -06001685 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001686}
1687
1688TEST_F(XglRenderTest, TriangleWithVertexFetch)
1689{
1690 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001691 "#version 140\n"
1692 "#extension GL_ARB_separate_shader_objects : enable\n"
1693 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001694 //XYZ1( 0.f, 0.f, 0.f )
Cody Northrop6217b822014-10-30 11:20:22 -06001695 "layout (location = 1) in vec4 inColor;\n"
GregF781f8562014-11-04 13:42:39 -07001696 //XYZ1( -1, -1, -1 )
1697 "layout (location = 0) in vec4 pos;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001698 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001699 "void main() {\n"
1700 " outColor = inColor;\n"
1701 " gl_Position = pos;\n"
1702 "}\n";
1703
1704
1705 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001706 "#version 140\n"
1707 "#extension GL_ARB_separate_shader_objects : enable\n"
1708 "#extension GL_ARB_shading_language_420pack : enable\n"
1709 "layout (location = 0) in vec4 color;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001710 "void main() {\n"
1711 " gl_FragColor = color;\n"
1712 "}\n";
1713
1714 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1715}
1716
GregF1ce3a832014-10-30 16:46:12 -06001717TEST_F(XglRenderTest, TriVertFetchAndVertID)
1718{
1719 // This tests that attributes work in the presence of gl_VertexID
1720
1721 static const char *vertShaderText =
1722 "#version 140\n"
1723 "#extension GL_ARB_separate_shader_objects : enable\n"
1724 "#extension GL_ARB_shading_language_420pack : enable\n"
1725 //XYZ1( -1, -1, -1 )
1726 "layout (location = 0) in vec4 pos;\n"
1727 //XYZ1( 0.f, 0.f, 0.f )
1728 "layout (location = 1) in vec4 inColor;\n"
1729 "layout (location = 0) out vec4 outColor;\n"
1730 "void main() {\n"
1731 " outColor = inColor;\n"
1732 " vec4 vertices[3];"
1733 " vertices[gl_VertexID % 3] = pos;\n"
1734 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1735 "}\n";
1736
1737
1738 static const char *fragShaderText =
1739 "#version 140\n"
1740 "#extension GL_ARB_separate_shader_objects : enable\n"
1741 "#extension GL_ARB_shading_language_420pack : enable\n"
1742 "layout (location = 0) in vec4 color;\n"
1743 "void main() {\n"
1744 " gl_FragColor = color;\n"
1745 "}\n";
1746
GregF1ce3a832014-10-30 16:46:12 -06001747 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1748}
1749
GregF31deb632014-10-31 17:36:18 -06001750TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1751{
1752 // This tests that attributes work in the presence of gl_VertexID
GregF8e5eb2b2014-11-04 14:20:50 -07001753 // and a dead attribute in position 0. Draws a triangle with yellow,
1754 // red and green corners, starting at top and going clockwise.
GregF31deb632014-10-31 17:36:18 -06001755
1756 static const char *vertShaderText =
1757 "#version 140\n"
1758 "#extension GL_ARB_separate_shader_objects : enable\n"
1759 "#extension GL_ARB_shading_language_420pack : enable\n"
1760 //XYZ1( -1, -1, -1 )
1761 "layout (location = 0) in vec4 pos;\n"
1762 //XYZ1( 0.f, 0.f, 0.f )
1763 "layout (location = 1) in vec4 inColor;\n"
1764 "layout (location = 0) out vec4 outColor;\n"
1765 "void main() {\n"
GregF8e5eb2b2014-11-04 14:20:50 -07001766 " outColor = inColor;\n"
1767 " vec2 vertices[3];"
1768 " vertices[0] = vec2(-1.0, -1.0);\n"
1769 " vertices[1] = vec2( 1.0, -1.0);\n"
1770 " vertices[2] = vec2( 0.0, 1.0);\n"
1771 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
GregF31deb632014-10-31 17:36:18 -06001772 "}\n";
1773
1774
1775 static const char *fragShaderText =
1776 "#version 140\n"
1777 "#extension GL_ARB_separate_shader_objects : enable\n"
1778 "#extension GL_ARB_shading_language_420pack : enable\n"
1779 "layout (location = 0) in vec4 color;\n"
1780 "void main() {\n"
1781 " gl_FragColor = color;\n"
1782 "}\n";
1783
GregF31deb632014-10-31 17:36:18 -06001784 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1785}
1786
Cody Northropc6953d02014-10-20 11:23:32 -06001787TEST_F(XglRenderTest, TexturedTriangle)
1788{
Cody Northrop5fa1d332014-10-20 11:51:32 -06001789 // The expected result from this test is a red and green checkered triangle
Cody Northropc6953d02014-10-20 11:23:32 -06001790 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001791 "#version 140\n"
1792 "#extension GL_ARB_separate_shader_objects : enable\n"
1793 "#extension GL_ARB_shading_language_420pack : enable\n"
1794 "layout (location = 0) out vec2 samplePos;\n"
Cody Northropc6953d02014-10-20 11:23:32 -06001795 "void main() {\n"
1796 " vec2 vertices[3];"
1797 " vertices[0] = vec2(-0.5, -0.5);\n"
1798 " vertices[1] = vec2( 0.5, -0.5);\n"
1799 " vertices[2] = vec2( 0.5, 0.5);\n"
1800 " vec2 positions[3];"
1801 " positions[0] = vec2( 0.0, 0.0);\n"
1802 " positions[1] = vec2( 1.0, 0.0);\n"
1803 " positions[2] = vec2( 1.0, 1.0);\n"
1804 " samplePos = positions[gl_VertexID % 3];\n"
1805 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1806 "}\n";
1807
1808 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001809 "#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 vec2 samplePos;\n"
1813 "layout (binding = 0) uniform sampler2D surface;\n"
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001814 "layout (location=0) out vec4 outColor;\n"
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001815 "void main() {\n"
1816 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1817 " outColor = texColor;\n"
1818 "}\n";
GregFea15e542014-11-03 16:52:56 -07001819
Courtney Goeltzenleuchter75a4d102014-11-03 15:44:32 -07001820 DrawTexturedTriangle(vertShaderText, fragShaderText);
1821}
1822
GregFe636c1a2014-11-07 13:29:23 -07001823TEST_F(XglRenderTest, TexturedTriangleClip)
GregFef017512014-11-06 14:53:03 -07001824{
1825 // The expected result from this test is a red and green checkered triangle
1826 static const char *vertShaderText =
GregFe636c1a2014-11-07 13:29:23 -07001827 "#version 330\n"
GregFef017512014-11-06 14:53:03 -07001828 "#extension GL_ARB_separate_shader_objects : enable\n"
1829 "#extension GL_ARB_shading_language_420pack : enable\n"
1830 "layout (location = 0) out vec2 samplePos;\n"
GregFe636c1a2014-11-07 13:29:23 -07001831 "out gl_PerVertex {\n"
1832 " vec4 gl_Position;\n"
1833 " float gl_ClipDistance[1];\n"
1834 "};\n"
GregFef017512014-11-06 14:53:03 -07001835 "void main() {\n"
1836 " vec2 vertices[3];"
1837 " vertices[0] = vec2(-0.5, -0.5);\n"
1838 " vertices[1] = vec2( 0.5, -0.5);\n"
1839 " vertices[2] = vec2( 0.5, 0.5);\n"
1840 " vec2 positions[3];"
1841 " positions[0] = vec2( 0.0, 0.0);\n"
1842 " positions[1] = vec2( 1.0, 0.0);\n"
1843 " positions[2] = vec2( 1.0, 1.0);\n"
GregFe636c1a2014-11-07 13:29:23 -07001844 " float dists[3];\n"
1845 " dists[0] = 1.0;\n"
1846 " dists[1] = 1.0;\n"
1847 " dists[2] = -1.0;\n"
1848 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
GregFef017512014-11-06 14:53:03 -07001849 " samplePos = positions[gl_VertexID % 3];\n"
1850 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1851 "}\n";
1852
1853 static const char *fragShaderText =
1854 "#version 140\n"
1855 "#extension GL_ARB_separate_shader_objects : enable\n"
1856 "#extension GL_ARB_shading_language_420pack : enable\n"
1857 "layout (location = 0) in vec2 samplePos;\n"
1858 "layout (binding = 0) uniform sampler2D surface;\n"
1859 "layout (location=0) out vec4 outColor;\n"
1860 "void main() {\n"
1861 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1862 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1863 " outColor = texColor;\n"
1864 "}\n";
1865
Cody Northrop5b03f012014-11-17 11:50:25 -07001866 bool backupBIL = XglTestFramework::m_use_bil;
1867 if (XglTestFramework::m_use_bil) {
1868 XglTestFramework::m_use_bil = false;
1869 printf("Forcing GLSL for TexturedTriangleClip\n");
1870 }
1871
GregFef017512014-11-06 14:53:03 -07001872 DrawTexturedTriangle(vertShaderText, fragShaderText);
Cody Northrop5b03f012014-11-17 11:50:25 -07001873
1874 XglTestFramework::m_use_bil = backupBIL;
GregFef017512014-11-06 14:53:03 -07001875}
1876
Cody Northrop9394e0c2014-10-23 10:21:47 -06001877TEST_F(XglRenderTest, VSTexture)
1878{
1879 // The expected result from this test is a green and red triangle;
1880 // one red vertex on the left, two green vertices on the right.
1881 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001882 "#version 140\n"
1883 "#extension GL_ARB_separate_shader_objects : enable\n"
1884 "#extension GL_ARB_shading_language_420pack : enable\n"
1885 "layout (location = 0) out vec4 texColor;\n"
1886 "layout (binding = 0) uniform sampler2D surface;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001887 "void main() {\n"
1888 " vec2 vertices[3];"
1889 " vertices[0] = vec2(-0.5, -0.5);\n"
1890 " vertices[1] = vec2( 0.5, -0.5);\n"
1891 " vertices[2] = vec2( 0.5, 0.5);\n"
1892 " vec2 positions[3];"
1893 " positions[0] = vec2( 0.0, 0.0);\n"
1894 " positions[1] = vec2( 0.25, 0.1);\n"
1895 " positions[2] = vec2( 0.1, 0.25);\n"
1896 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1897 " texColor = textureLod(surface, samplePos, 0.0);\n"
1898 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1899 "}\n";
1900
1901 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001902 "#version 140\n"
1903 "#extension GL_ARB_separate_shader_objects : enable\n"
1904 "#extension GL_ARB_shading_language_420pack : enable\n"
1905 "layout (location = 0) in vec4 texColor;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001906 "void main() {\n"
1907 " gl_FragColor = texColor;\n"
1908 "}\n";
1909
1910 DrawTexturedTriangle(vertShaderText, fragShaderText);
1911}
1912
Cody Northrop6217b822014-10-30 11:20:22 -06001913TEST_F(XglRenderTest, SamplerBindingsTriangle)
1914{
1915 // This test sets bindings on the samplers
1916 // For now we are asserting that sampler and texture pairs
1917 // march in lock step, and are set via GLSL binding. This can
1918 // and will probably change.
1919 // The sampler bindings should match the sampler and texture slot
1920 // number set up by the application.
1921 // This test will result in a blue triangle
1922 static const char *vertShaderText =
1923 "#version 140\n"
1924 "#extension GL_ARB_separate_shader_objects : enable\n"
1925 "#extension GL_ARB_shading_language_420pack : enable\n"
1926 "layout (location = 0) out vec4 samplePos;\n"
1927 "void main() {\n"
1928 " vec2 vertices[3];"
1929 " vertices[0] = vec2(-0.5, -0.5);\n"
1930 " vertices[1] = vec2( 0.5, -0.5);\n"
1931 " vertices[2] = vec2( 0.5, 0.5);\n"
1932 " vec2 positions[3];"
1933 " positions[0] = vec2( 0.0, 0.0);\n"
1934 " positions[1] = vec2( 1.0, 0.0);\n"
1935 " positions[2] = vec2( 1.0, 1.0);\n"
1936 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
1937 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1938 "}\n";
1939
1940 static const char *fragShaderText =
1941 "#version 140\n"
1942 "#extension GL_ARB_separate_shader_objects : enable\n"
1943 "#extension GL_ARB_shading_language_420pack : enable\n"
1944 "layout (location = 0) in vec4 samplePos;\n"
1945 "layout (binding = 0) uniform sampler2D surface0;\n"
1946 "layout (binding = 1) uniform sampler2D surface1;\n"
Cody Northrop929838b2014-11-05 17:08:33 -07001947 "layout (binding = 12) uniform sampler2D surface2;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001948 "void main() {\n"
1949 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
1950 "}\n";
1951
Cody Northrop6217b822014-10-30 11:20:22 -06001952 int textureCount = g_TextureCount;
1953 int samplerCount = g_SamplerCount;
1954 DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount);
1955}
1956
1957TEST_F(XglRenderTest, TriangleVSUniformBlock)
1958{
1959 // The expected result from this test is a blue triangle
1960
1961 static const char *vertShaderText =
1962 "#version 140\n"
1963 "#extension GL_ARB_separate_shader_objects : enable\n"
1964 "#extension GL_ARB_shading_language_420pack : enable\n"
1965 "layout (location = 0) out vec4 outColor;\n"
1966 "layout (std140, binding = 0) uniform bufferVals {\n"
1967 " vec4 red;\n"
1968 " vec4 green;\n"
1969 " vec4 blue;\n"
1970 " vec4 white;\n"
1971 "} myBufferVals;\n"
1972 "void main() {\n"
1973 " vec2 vertices[3];"
1974 " vertices[0] = vec2(-0.5, -0.5);\n"
1975 " vertices[1] = vec2( 0.5, -0.5);\n"
1976 " vertices[2] = vec2( 0.5, 0.5);\n"
1977 " outColor = myBufferVals.blue;\n"
1978 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1979 "}\n";
1980
1981 static const char *fragShaderText =
1982 "#version 140\n"
1983 "#extension GL_ARB_separate_shader_objects : enable\n"
1984 "#extension GL_ARB_shading_language_420pack : enable\n"
1985 "layout (location = 0) in vec4 inColor;\n"
1986 "void main() {\n"
1987 " gl_FragColor = inColor;\n"
1988 "}\n";
1989
Cody Northrop6217b822014-10-30 11:20:22 -06001990 DrawTriangleVSUniformBlock(vertShaderText, fragShaderText);
1991}
1992
Cody Northropec1d3c32014-10-28 15:41:42 -06001993TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
1994{
1995 // This test allows the shader to select which buffer it is
1996 // pulling from using layout binding qualifier.
1997 // There are corresponding changes in the compiler stack that
1998 // will select the buffer using binding directly.
Cody Northrop6217b822014-10-30 11:20:22 -06001999 // The binding number should match the slot number set up by
2000 // the application.
Cody Northropec1d3c32014-10-28 15:41:42 -06002001 // The expected result from this test is a purple triangle
2002
2003 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06002004 "#version 140\n"
2005 "#extension GL_ARB_separate_shader_objects : enable\n"
2006 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northropec1d3c32014-10-28 15:41:42 -06002007 "void main() {\n"
2008 " vec2 vertices[3];"
2009 " vertices[0] = vec2(-0.5, -0.5);\n"
2010 " vertices[1] = vec2( 0.5, -0.5);\n"
2011 " vertices[2] = vec2( 0.5, 0.5);\n"
2012 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2013 "}\n";
2014
2015 static const char *fragShaderText =
2016 "#version 140\n"
2017 "#extension GL_ARB_separate_shader_objects : enable\n"
2018 "#extension GL_ARB_shading_language_420pack : enable\n"
2019 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2020 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2021 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Cody Northrop929838b2014-11-05 17:08:33 -07002022 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Cody Northropec1d3c32014-10-28 15:41:42 -06002023 "void main() {\n"
2024 " gl_FragColor = myBlueVal.color;\n"
2025 " gl_FragColor += myRedVal.color;\n"
2026 "}\n";
2027
2028 DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText);
2029}
2030
Cody Northrop929838b2014-11-05 17:08:33 -07002031TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2032{
2033 // This test is the same as TriangleFSUniformBlockBinding, but
2034 // it does not provide an instance name.
2035 // The expected result from this test is a purple triangle
2036
2037 static const char *vertShaderText =
2038 "#version 140\n"
2039 "#extension GL_ARB_separate_shader_objects : enable\n"
2040 "#extension GL_ARB_shading_language_420pack : enable\n"
2041 "void main() {\n"
2042 " vec2 vertices[3];"
2043 " vertices[0] = vec2(-0.5, -0.5);\n"
2044 " vertices[1] = vec2( 0.5, -0.5);\n"
2045 " vertices[2] = vec2( 0.5, 0.5);\n"
2046 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2047 "}\n";
2048
2049 static const char *fragShaderText =
2050 "#version 430\n"
2051 "#extension GL_ARB_separate_shader_objects : enable\n"
2052 "#extension GL_ARB_shading_language_420pack : enable\n"
2053 "layout (location = 0) uniform vec4 foo;\n"
2054 "layout (location = 1) uniform vec4 bar;\n"
2055 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2056 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2057 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2058 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
2059 "void main() {\n"
2060 " gl_FragColor = blue;\n"
2061 " gl_FragColor += red;\n"
2062 "}\n";
2063
Cody Northrop929838b2014-11-05 17:08:33 -07002064 DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText);
2065}
2066
Cody Northrop722ff402014-10-20 09:22:42 -06002067int main(int argc, char **argv) {
2068 int result;
2069
2070 ::testing::InitGoogleTest(&argc, argv);
2071 XglTestFramework::InitArgs(&argc, argv);
2072
2073 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2074
2075 result = RUN_ALL_TESTS();
2076
2077 XglTestFramework::Finish();
2078 return result;
2079}