blob: d0ae090dfaf1476493caa97c53ffd8d26ae2401b [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) );
1062 for (int i = 0; i < bufferCount; ++i) {
1063 // Note: These are all constant buffers
1064 slotInfo[i].shaderEntityIndex = i;
1065 slotInfo[i].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1066 }
1067
1068 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1069 ps_stage.shader.descriptorSetMapping[0].descriptorCount = bufferCount;
1070
1071 ps_stage.shader.linkConstBufferCount = 0;
1072 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1073 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1074 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1075
1076 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1077 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1078 &ps_stage, // pNext
1079 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1080 XGL_FALSE, // disableVertexReuse
1081 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1082 XGL_FALSE, // primitiveRestartEnable
1083 0 // primitiveRestartIndex
1084 };
1085
1086 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1087 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1088 &ia_state,
1089 XGL_FALSE, // depthClipEnable
1090 XGL_FALSE, // rasterizerDiscardEnable
1091 1.0 // pointSize
1092 };
1093
1094 XGL_PIPELINE_CB_STATE cb_state = {
1095 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1096 &rs_state,
1097 XGL_FALSE, // alphaToCoverageEnable
1098 XGL_FALSE, // dualSourceBlendEnable
1099 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1100 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1101 {
1102 XGL_FALSE, // blendEnable
1103 m_render_target_fmt, // XGL_FORMAT
1104 0xF // channelWriteMask
1105 }
1106 }
1107 };
1108
1109 // TODO: Should take depth buffer format from queried formats
1110 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1111 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1112 &cb_state,
1113 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1114 };
1115
1116 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1117 info.pNext = &db_state;
1118 info.flags = 0;
1119 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1120 ASSERT_XGL_SUCCESS(err);
1121
1122 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1123 ASSERT_XGL_SUCCESS(err);
1124}
1125
Cody Northropc6953d02014-10-20 11:23:32 -06001126void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
1127{
1128 // based on CreatePipelineVSUniform
1129
1130 XGL_RESULT err;
1131 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1132 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1133 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1134
Cody Northrop9394e0c2014-10-23 10:21:47 -06001135 const int vsSlots = 2; // One texture, one sampler
Cody Northropc6953d02014-10-20 11:23:32 -06001136
1137 // Create descriptor set for single texture and sampler
Cody Northrop9394e0c2014-10-23 10:21:47 -06001138 XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {};
1139 vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1140 vsDescriptorInfo.slots = vsSlots;
1141 err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &m_rsrcDescSet );
Cody Northropc6953d02014-10-20 11:23:32 -06001142 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1143 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1144
Cody Northropc6953d02014-10-20 11:23:32 -06001145 // Assign the slots, note that only t0 and s0 will work as of writing this test
Cody Northrop9394e0c2014-10-23 10:21:47 -06001146 XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1147 vsSlotInfo[0].shaderEntityIndex = 0;
1148 vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1149 vsSlotInfo[1].shaderEntityIndex = 0;
1150 vsSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
Cody Northropc6953d02014-10-20 11:23:32 -06001151
1152 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1153 vs_stage.pNext = XGL_NULL_HANDLE;
1154 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1155 vs_stage.shader.shader = vs;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001156 vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo;
1157 vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots;
Cody Northropc6953d02014-10-20 11:23:32 -06001158 vs_stage.shader.linkConstBufferCount = 0;
1159 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1160 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1161 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1162
Cody Northrop9394e0c2014-10-23 10:21:47 -06001163 const int psSlots = 2; // One texture, one sampler
1164
1165 // Create descriptor set for single texture and sampler
1166 XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {};
1167 psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1168 psDescriptorInfo.slots = psSlots;
1169 err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet );
1170 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1171 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1172
1173 // Assign the slots, note that only t0 and s0 will work as of writing this test
1174 XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1175 psSlotInfo[0].shaderEntityIndex = 0;
1176 psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1177 psSlotInfo[1].shaderEntityIndex = 0;
1178 psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1179
Cody Northropc6953d02014-10-20 11:23:32 -06001180 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1181 ps_stage.pNext = &vs_stage;
1182 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1183 ps_stage.shader.shader = ps;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001184 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) psSlotInfo;
Cody Northropc6953d02014-10-20 11:23:32 -06001185 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1186 ps_stage.shader.linkConstBufferCount = 0;
1187 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1188 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1189 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1190
1191 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1192 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1193 &ps_stage, // pNext
1194 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1195 XGL_FALSE, // disableVertexReuse
1196 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1197 XGL_FALSE, // primitiveRestartEnable
1198 0 // primitiveRestartIndex
1199 };
1200
1201 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1202 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1203 &ia_state,
1204 XGL_FALSE, // depthClipEnable
1205 XGL_FALSE, // rasterizerDiscardEnable
1206 1.0 // pointSize
1207 };
1208
1209 XGL_PIPELINE_CB_STATE cb_state = {
1210 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1211 &rs_state,
1212 XGL_FALSE, // alphaToCoverageEnable
1213 XGL_FALSE, // dualSourceBlendEnable
1214 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1215 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1216 {
1217 XGL_FALSE, // blendEnable
1218 m_render_target_fmt, // XGL_FORMAT
1219 0xF // channelWriteMask
1220 }
1221 }
1222 };
1223
1224 // TODO: Should take depth buffer format from queried formats
1225 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1226 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1227 &cb_state,
1228 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1229 };
1230
1231 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1232 info.pNext = &db_state;
1233 info.flags = 0;
1234 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1235 ASSERT_XGL_SUCCESS(err);
1236
1237 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1238 ASSERT_XGL_SUCCESS(err);
1239}
1240
Cody Northropac6179b2014-10-29 12:09:45 -06001241void XglRenderTest::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps,
1242 int textureCount, int samplerCount)
1243{
1244 // based on CreatePipelineSingleTextureAndSampler
1245
1246 XGL_RESULT err;
1247 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
1248 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
1249 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
1250
1251 const int psSlots = textureCount + samplerCount;
1252
1253 // Create descriptor set for single texture and sampler
1254 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1255 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1256 descriptorInfo.slots = psSlots;
1257 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1258 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1259 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1260
1261 // Assign the slots, note that only t0 and s0 will work as of writing this test
1262 XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
1263 int slotIndex = 0;
1264 for (int i = 0; i < textureCount; ++i) {
1265 slotInfo[slotIndex].shaderEntityIndex = i;
1266 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
1267 }
1268 for (int i = 0; i < samplerCount; ++i) {
1269 slotInfo[slotIndex].shaderEntityIndex = i;
1270 slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
1271 }
1272
1273 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1274 vs_stage.pNext = XGL_NULL_HANDLE;
1275 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
1276 vs_stage.shader.shader = vs;
1277 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
1278 vs_stage.shader.linkConstBufferCount = 0;
1279 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1280 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1281 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1282
1283 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1284 ps_stage.pNext = &vs_stage;
1285 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
1286 ps_stage.shader.shader = ps;
1287 ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
1288 ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
1289 ps_stage.shader.linkConstBufferCount = 0;
1290 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
1291 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
1292 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
1293
1294 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
1295 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
1296 &ps_stage, // pNext
1297 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
1298 XGL_FALSE, // disableVertexReuse
1299 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
1300 XGL_FALSE, // primitiveRestartEnable
1301 0 // primitiveRestartIndex
1302 };
1303
1304 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
1305 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
1306 &ia_state,
1307 XGL_FALSE, // depthClipEnable
1308 XGL_FALSE, // rasterizerDiscardEnable
1309 1.0 // pointSize
1310 };
1311
1312 XGL_PIPELINE_CB_STATE cb_state = {
1313 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
1314 &rs_state,
1315 XGL_FALSE, // alphaToCoverageEnable
1316 XGL_FALSE, // dualSourceBlendEnable
1317 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
1318 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
1319 {
1320 XGL_FALSE, // blendEnable
1321 m_render_target_fmt, // XGL_FORMAT
1322 0xF // channelWriteMask
1323 }
1324 }
1325 };
1326
1327 // TODO: Should take depth buffer format from queried formats
1328 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
1329 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
1330 &cb_state,
1331 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
1332 };
1333
1334 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1335 info.pNext = &db_state;
1336 info.flags = 0;
1337 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
1338 ASSERT_XGL_SUCCESS(err);
1339
1340 err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
1341 ASSERT_XGL_SUCCESS(err);
1342}
1343
Cody Northrop722ff402014-10-20 09:22:42 -06001344void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
1345{
1346 XGL_PIPELINE pipeline;
1347 XGL_SHADER vs, ps;
1348 XGL_RESULT err;
1349
1350 ASSERT_NO_FATAL_FAILURE(InitState());
1351 ASSERT_NO_FATAL_FAILURE(InitViewport());
1352 ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData));
1353
1354 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1355 vertShaderText, &vs));
1356
1357 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1358 fragShaderText, &ps));
1359
1360 ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps));
1361
1362 /*
1363 * Shaders are now part of the pipeline, don't need these anymore
1364 */
1365 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1366 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1367
1368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1369
1370 // Build command buffer
1371 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1372 ASSERT_XGL_SUCCESS(err);
1373
1374 GenerateClearAndPrepareBufferCmds();
1375 GenerateBindRenderTargetCmd();
1376 GenerateBindStateAndPipelineCmds(&pipeline);
1377
1378// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1379// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1380
1381 // render the cube
1382 xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 );
1383
1384 // prepare the back buffer for present
1385// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1386// transitionToPresent.image = m_image;
1387// transitionToPresent.oldState = m_image_state;
1388// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1389// transitionToPresent.subresourceRange = srRange;
1390// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1391// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1392
1393 // finalize recording of the command buffer
1394 err = xglEndCommandBuffer( m_cmdBuffer );
1395 ASSERT_XGL_SUCCESS( err );
1396
1397 // this command buffer only uses the vertex buffer memory
1398 m_numMemRefs = 0;
1399// m_memRefs[0].flags = 0;
1400// m_memRefs[0].mem = m_vtxBufferMemory;
1401
1402 // submit the command buffer to the universal queue
1403 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1404 ASSERT_XGL_SUCCESS( err );
1405
1406 err = xglQueueWaitIdle( m_device->m_queue );
1407 ASSERT_XGL_SUCCESS( err );
1408
1409 // Wait for work to finish before cleaning up.
1410 xglDeviceWaitIdle(m_device->device());
1411
1412 RecordImage(m_renderTarget);
1413
1414}
1415
Cody Northropec1d3c32014-10-28 15:41:42 -06001416void XglRenderTest::DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText)
1417{
1418 // sourced from DrawTriangleFSUniformBlock
1419
1420 XGL_PIPELINE pipeline;
1421 XGL_SHADER vs, ps;
1422 XGL_RESULT err;
1423
1424 ASSERT_NO_FATAL_FAILURE(InitState());
1425 ASSERT_NO_FATAL_FAILURE(InitViewport());
1426
1427 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1428 vertShaderText, &vs));
1429
1430 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1431 fragShaderText, &ps));
1432
1433 const int bufferCount = 4;
1434 ASSERT_NO_FATAL_FAILURE(CreatePipelineFSUniformBlockBinding(&pipeline, vs, ps, bufferCount));
1435
1436 /*
1437 * Shaders are now part of the pipeline, don't need these anymore
1438 */
1439 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1440 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1441
1442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1443
1444
1445 // We're going to create a number of uniform buffers, and then allow
1446 // the shader to select which it wants to read from with a binding
1447
1448 // Let's populate the buffers with a single color each:
1449 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
1450 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
1451 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
1452 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
1453
1454 assert(4 == bufferCount); // update the following code if you want more than 4
1455
1456 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
1457 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
1458 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
1459 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
1460
1461 const int redCount = sizeof(redVals) / sizeof(float);
1462 const int greenCount = sizeof(greenVals) / sizeof(float);
1463 const int blueCount = sizeof(blueVals) / sizeof(float);
1464 const int whiteCount = sizeof(whiteVals) / sizeof(float);
1465
1466 int index = 0;
1467 InitUniformBuffer(redCount, sizeof(redVals[0]), index++, (const void *) redVals);
1468 InitUniformBuffer(greenCount, sizeof(greenVals[0]), index++, (const void *) greenVals);
1469 InitUniformBuffer(blueCount, sizeof(blueVals[0]), index++, (const void *) blueVals);
1470 InitUniformBuffer(whiteCount, sizeof(whiteVals[0]), index++, (const void *) whiteVals);
1471
1472
1473 // Create descriptor set for a uniform resource
1474 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1475 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1476 descriptorInfo.slots = bufferCount;
1477
1478 // create a descriptor set with a single slot
1479 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1480 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1481
1482 // bind memory to the descriptor set
1483 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1484
1485 // write the constant buffer view to the descriptor set
1486 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1487
1488 for(int i = 0; i < bufferCount; ++i)
1489 xglAttachMemoryViewDescriptors( m_rsrcDescSet, i, 1, &m_uniformBufferView[i] );
1490
1491 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1492
1493 // Build command buffer
1494 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1495 ASSERT_XGL_SUCCESS(err);
1496
1497 GenerateClearAndPrepareBufferCmds();
1498 GenerateBindRenderTargetCmd();
1499 GenerateBindStateAndPipelineCmds(&pipeline);
1500
1501// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1502// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1503
1504 // render the cube
1505 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1506
1507 // prepare the back buffer for present
1508// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1509// transitionToPresent.image = m_image;
1510// transitionToPresent.oldState = m_image_state;
1511// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1512// transitionToPresent.subresourceRange = srRange;
1513// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1514// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1515
1516 // finalize recording of the command buffer
1517 err = xglEndCommandBuffer( m_cmdBuffer );
1518 ASSERT_XGL_SUCCESS( err );
1519
1520 // this command buffer only uses the vertex buffer memory
1521 m_numMemRefs = 0;
1522// m_memRefs[0].flags = 0;
1523// m_memRefs[0].mem = m_vtxBufferMemory;
1524
1525 // submit the command buffer to the universal queue
1526 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1527 ASSERT_XGL_SUCCESS( err );
1528
1529 err = xglQueueWaitIdle( m_device->m_queue );
1530 ASSERT_XGL_SUCCESS( err );
1531
1532 // Wait for work to finish before cleaning up.
1533 xglDeviceWaitIdle(m_device->device());
1534
1535 RecordImage(m_renderTarget);
1536
1537}
1538
Cody Northropac6179b2014-10-29 12:09:45 -06001539void XglRenderTest::DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText,
1540 int textureCount, int samplerCount)
1541{
1542 // based on DrawTexturedTriangle
1543
1544 XGL_PIPELINE pipeline;
1545 XGL_SHADER vs, ps;
1546 XGL_RESULT err;
1547
1548 ASSERT_NO_FATAL_FAILURE(InitState());
1549 ASSERT_NO_FATAL_FAILURE(InitViewport());
1550
1551 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
1552 vertShaderText, &vs));
1553
1554 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
1555 fragShaderText, &ps));
1556
1557 ASSERT_NO_FATAL_FAILURE(CreatePipelineMultipleTexturesAndSamplers(&pipeline, vs, ps, textureCount, samplerCount));
1558
1559 /*
1560 * Shaders are now part of the pipeline, don't need these anymore
1561 */
1562 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
1563 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
1564
1565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1566
1567
1568 // Create a few texture/sampler pairs
1569 int textureColors[16];
1570 assert(textureCount < 16);
1571 textureColors[0] = 0xFF0000FF; //red
1572 textureColors[1] = 0xFF00FF00; //green
1573 textureColors[2] = 0xFFFF0000; //blue
1574
1575 ASSERT_NO_FATAL_FAILURE(InitMultipleSamplers(samplerCount));
1576 ASSERT_NO_FATAL_FAILURE(InitMultipleTextures(textureCount, textureColors));
1577
1578 // Create descriptor set for a texture and sampler resources
1579 const int slotCount = textureCount + samplerCount;
1580 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
1581 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
1582 descriptorInfo.slots = slotCount;
1583
1584 // create a descriptor set with a single slot
1585 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
1586 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
1587
1588 // bind memory to the descriptor set
1589 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
1590
1591 // write the sampler and image views to the descriptor set
1592 // ensure this matches order set in CreatePipelineSingleTextureAndSampler
1593 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
1594 int descSlot = 0;
1595 for (int i = 0; i < textureCount; ++i)
1596 xglAttachImageViewDescriptors( m_rsrcDescSet, descSlot++, 1, &m_textureViewInfo[i]);
1597 for (int i = 0; i < samplerCount; ++i)
1598 xglAttachSamplerDescriptors(m_rsrcDescSet, descSlot++, 1, &m_sampler[i]);
1599 xglEndDescriptorSetUpdate( m_rsrcDescSet );
1600
1601 // Build command buffer
1602 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1603 ASSERT_XGL_SUCCESS(err);
1604
1605 GenerateClearAndPrepareBufferCmds();
1606 GenerateBindRenderTargetCmd();
1607 GenerateBindStateAndPipelineCmds(&pipeline);
1608
1609// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
1610// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
1611
1612 // render the cube
1613 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
1614
1615 // prepare the back buffer for present
1616// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
1617// transitionToPresent.image = m_image;
1618// transitionToPresent.oldState = m_image_state;
1619// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
1620// transitionToPresent.subresourceRange = srRange;
1621// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
1622// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
1623
1624 // finalize recording of the command buffer
1625 err = xglEndCommandBuffer( m_cmdBuffer );
1626 ASSERT_XGL_SUCCESS( err );
1627
1628 // this command buffer only uses the vertex buffer memory
1629 m_numMemRefs = 0;
1630// m_memRefs[0].flags = 0;
1631// m_memRefs[0].mem = m_vtxBufferMemory;
1632
1633 // submit the command buffer to the universal queue
1634 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
1635 ASSERT_XGL_SUCCESS( err );
1636
1637 err = xglQueueWaitIdle( m_device->m_queue );
1638 ASSERT_XGL_SUCCESS( err );
1639
1640 // Wait for work to finish before cleaning up.
1641 xglDeviceWaitIdle(m_device->device());
1642
1643 RecordImage(m_renderTarget);
1644
1645}
1646
Cody Northrop722ff402014-10-20 09:22:42 -06001647TEST_F(XglRenderTest, GreenTriangle)
1648{
1649 static const char *vertShaderText =
1650 "#version 130\n"
1651 "vec2 vertices[3];\n"
1652 "void main() {\n"
1653 " vertices[0] = vec2(-1.0, -1.0);\n"
1654 " vertices[1] = vec2( 1.0, -1.0);\n"
1655 " vertices[2] = vec2( 0.0, 1.0);\n"
1656 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1657 "}\n";
1658
1659 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001660 "#version 130\n"
1661 "void main() {\n"
1662 " gl_FragColor = vec4(0,1,0,1);\n"
1663 "}\n";
Cody Northrop722ff402014-10-20 09:22:42 -06001664
Cody Northrop722ff402014-10-20 09:22:42 -06001665 XglTestFramework::m_use_bil = true;
1666 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001667}
1668
GregFef5d9cf2014-10-22 14:40:26 -06001669TEST_F(XglRenderTest, MixTriangle)
1670{
1671 // This tests location applied to varyings. Notice that we have switched foo
1672 // and bar in the FS. The triangle should be blended with red, green and blue
1673 // corners.
1674 static const char *vertShaderText =
1675 "#version 140\n"
1676 "#extension GL_ARB_separate_shader_objects : enable\n"
1677 "#extension GL_ARB_shading_language_420pack : enable\n"
1678 "layout (location=0) out vec4 bar;\n"
1679 "layout (location=1) out vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001680 "layout (location=2) out float scale;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001681 "vec2 vertices[3];\n"
1682 "void main() {\n"
1683 " vertices[0] = vec2(-1.0, -1.0);\n"
1684 " vertices[1] = vec2( 1.0, -1.0);\n"
1685 " vertices[2] = vec2( 0.0, 1.0);\n"
1686 "vec4 colors[3];\n"
1687 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1688 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1689 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1690 " foo = colors[gl_VertexID % 3];\n"
1691 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001692 " scale = 1.0;\n"
GregFef5d9cf2014-10-22 14:40:26 -06001693 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1694 "}\n";
1695
1696 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001697 "#version 140\n"
1698 "#extension GL_ARB_separate_shader_objects : enable\n"
1699 "#extension GL_ARB_shading_language_420pack : enable\n"
1700 "layout (location = 1) in vec4 bar;\n"
1701 "layout (location = 0) in vec4 foo;\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001702 "layout (location = 2) in float scale;\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001703 "void main() {\n"
Courtney Goeltzenleuchter3d88b532014-11-03 15:40:13 -07001704 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
Cody Northrop6217b822014-10-30 11:20:22 -06001705 "}\n";
GregFef5d9cf2014-10-22 14:40:26 -06001706
GregF91b2d302014-10-23 10:44:44 -06001707 XglTestFramework::m_use_bil = true;
1708 DrawTriangleTest(vertShaderText, fragShaderText);
Cody Northrop722ff402014-10-20 09:22:42 -06001709}
1710
1711TEST_F(XglRenderTest, TriangleWithVertexFetch)
1712{
1713 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001714 "#version 140\n"
1715 "#extension GL_ARB_separate_shader_objects : enable\n"
1716 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001717 //XYZ1( -1, -1, -1 )
Cody Northrop6217b822014-10-30 11:20:22 -06001718 "layout (location = 0) in vec4 pos;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001719 //XYZ1( 0.f, 0.f, 0.f )
Cody Northrop6217b822014-10-30 11:20:22 -06001720 "layout (location = 1) in vec4 inColor;\n"
1721 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001722 "void main() {\n"
1723 " outColor = inColor;\n"
1724 " gl_Position = pos;\n"
1725 "}\n";
1726
1727
1728 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001729 "#version 140\n"
1730 "#extension GL_ARB_separate_shader_objects : enable\n"
1731 "#extension GL_ARB_shading_language_420pack : enable\n"
1732 "layout (location = 0) in vec4 color;\n"
Cody Northrop722ff402014-10-20 09:22:42 -06001733 "void main() {\n"
1734 " gl_FragColor = color;\n"
1735 "}\n";
1736
Cody Northrop6217b822014-10-30 11:20:22 -06001737 XglTestFramework::m_use_bil = true;
Cody Northrop722ff402014-10-20 09:22:42 -06001738 DrawTriangleWithVertexFetch(vertShaderText, fragShaderText);
1739}
1740
Cody Northropc6953d02014-10-20 11:23:32 -06001741TEST_F(XglRenderTest, TexturedTriangle)
1742{
Cody Northrop5fa1d332014-10-20 11:51:32 -06001743 // The expected result from this test is a red and green checkered triangle
Cody Northropc6953d02014-10-20 11:23:32 -06001744 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001745 "#version 140\n"
1746 "#extension GL_ARB_separate_shader_objects : enable\n"
1747 "#extension GL_ARB_shading_language_420pack : enable\n"
1748 "layout (location = 0) out vec2 samplePos;\n"
Cody Northropc6953d02014-10-20 11:23:32 -06001749 "void main() {\n"
1750 " vec2 vertices[3];"
1751 " vertices[0] = vec2(-0.5, -0.5);\n"
1752 " vertices[1] = vec2( 0.5, -0.5);\n"
1753 " vertices[2] = vec2( 0.5, 0.5);\n"
1754 " vec2 positions[3];"
1755 " positions[0] = vec2( 0.0, 0.0);\n"
1756 " positions[1] = vec2( 1.0, 0.0);\n"
1757 " positions[2] = vec2( 1.0, 1.0);\n"
1758 " samplePos = positions[gl_VertexID % 3];\n"
1759 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1760 "}\n";
1761
1762 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001763 "#version 140\n"
1764 "#extension GL_ARB_separate_shader_objects : enable\n"
1765 "#extension GL_ARB_shading_language_420pack : enable\n"
1766 "layout (location = 0) in vec2 samplePos;\n"
1767 "layout (binding = 0) uniform sampler2D surface;\n"
Cody Northropc6953d02014-10-20 11:23:32 -06001768 "void main() {\n"
1769 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1770 " gl_FragColor = texColor;\n"
1771 "}\n";
Cody Northrop6217b822014-10-30 11:20:22 -06001772
1773 XglTestFramework::m_use_bil = true;
Cody Northropc6953d02014-10-20 11:23:32 -06001774 DrawTexturedTriangle(vertShaderText, fragShaderText);
1775}
1776
Cody Northrop9394e0c2014-10-23 10:21:47 -06001777TEST_F(XglRenderTest, VSTexture)
1778{
1779 // The expected result from this test is a green and red triangle;
1780 // one red vertex on the left, two green vertices on the right.
1781 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001782 "#version 140\n"
1783 "#extension GL_ARB_separate_shader_objects : enable\n"
1784 "#extension GL_ARB_shading_language_420pack : enable\n"
1785 "layout (location = 0) out vec4 texColor;\n"
1786 "layout (binding = 0) uniform sampler2D surface;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001787 "void main() {\n"
1788 " vec2 vertices[3];"
1789 " vertices[0] = vec2(-0.5, -0.5);\n"
1790 " vertices[1] = vec2( 0.5, -0.5);\n"
1791 " vertices[2] = vec2( 0.5, 0.5);\n"
1792 " vec2 positions[3];"
1793 " positions[0] = vec2( 0.0, 0.0);\n"
1794 " positions[1] = vec2( 0.25, 0.1);\n"
1795 " positions[2] = vec2( 0.1, 0.25);\n"
1796 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1797 " texColor = textureLod(surface, samplePos, 0.0);\n"
1798 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1799 "}\n";
1800
1801 static const char *fragShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001802 "#version 140\n"
1803 "#extension GL_ARB_separate_shader_objects : enable\n"
1804 "#extension GL_ARB_shading_language_420pack : enable\n"
1805 "layout (location = 0) in vec4 texColor;\n"
Cody Northrop9394e0c2014-10-23 10:21:47 -06001806 "void main() {\n"
1807 " gl_FragColor = texColor;\n"
1808 "}\n";
1809
Cody Northrop6217b822014-10-30 11:20:22 -06001810 XglTestFramework::m_use_bil = true;
Cody Northrop9394e0c2014-10-23 10:21:47 -06001811 DrawTexturedTriangle(vertShaderText, fragShaderText);
1812}
1813
Cody Northrop6217b822014-10-30 11:20:22 -06001814TEST_F(XglRenderTest, SamplerBindingsTriangle)
1815{
1816 // This test sets bindings on the samplers
1817 // For now we are asserting that sampler and texture pairs
1818 // march in lock step, and are set via GLSL binding. This can
1819 // and will probably change.
1820 // The sampler bindings should match the sampler and texture slot
1821 // number set up by the application.
1822 // This test will result in a blue triangle
1823 static const char *vertShaderText =
1824 "#version 140\n"
1825 "#extension GL_ARB_separate_shader_objects : enable\n"
1826 "#extension GL_ARB_shading_language_420pack : enable\n"
1827 "layout (location = 0) out vec4 samplePos;\n"
1828 "void main() {\n"
1829 " vec2 vertices[3];"
1830 " vertices[0] = vec2(-0.5, -0.5);\n"
1831 " vertices[1] = vec2( 0.5, -0.5);\n"
1832 " vertices[2] = vec2( 0.5, 0.5);\n"
1833 " vec2 positions[3];"
1834 " positions[0] = vec2( 0.0, 0.0);\n"
1835 " positions[1] = vec2( 1.0, 0.0);\n"
1836 " positions[2] = vec2( 1.0, 1.0);\n"
1837 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
1838 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1839 "}\n";
1840
1841 static const char *fragShaderText =
1842 "#version 140\n"
1843 "#extension GL_ARB_separate_shader_objects : enable\n"
1844 "#extension GL_ARB_shading_language_420pack : enable\n"
1845 "layout (location = 0) in vec4 samplePos;\n"
1846 "layout (binding = 0) uniform sampler2D surface0;\n"
1847 "layout (binding = 1) uniform sampler2D surface1;\n"
1848 "layout (binding = 2) uniform sampler2D surface2;\n"
1849 "void main() {\n"
1850 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
1851 "}\n";
1852
1853 XglTestFramework::m_use_bil = true;
1854 int textureCount = g_TextureCount;
1855 int samplerCount = g_SamplerCount;
1856 DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount);
1857}
1858
1859TEST_F(XglRenderTest, TriangleVSUniformBlock)
1860{
1861 // The expected result from this test is a blue triangle
1862
1863 static const char *vertShaderText =
1864 "#version 140\n"
1865 "#extension GL_ARB_separate_shader_objects : enable\n"
1866 "#extension GL_ARB_shading_language_420pack : enable\n"
1867 "layout (location = 0) out vec4 outColor;\n"
1868 "layout (std140, binding = 0) uniform bufferVals {\n"
1869 " vec4 red;\n"
1870 " vec4 green;\n"
1871 " vec4 blue;\n"
1872 " vec4 white;\n"
1873 "} myBufferVals;\n"
1874 "void main() {\n"
1875 " vec2 vertices[3];"
1876 " vertices[0] = vec2(-0.5, -0.5);\n"
1877 " vertices[1] = vec2( 0.5, -0.5);\n"
1878 " vertices[2] = vec2( 0.5, 0.5);\n"
1879 " outColor = myBufferVals.blue;\n"
1880 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1881 "}\n";
1882
1883 static const char *fragShaderText =
1884 "#version 140\n"
1885 "#extension GL_ARB_separate_shader_objects : enable\n"
1886 "#extension GL_ARB_shading_language_420pack : enable\n"
1887 "layout (location = 0) in vec4 inColor;\n"
1888 "void main() {\n"
1889 " gl_FragColor = inColor;\n"
1890 "}\n";
1891
1892 XglTestFramework::m_use_bil = true;
1893 DrawTriangleVSUniformBlock(vertShaderText, fragShaderText);
1894}
1895
Cody Northropec1d3c32014-10-28 15:41:42 -06001896TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
1897{
1898 // This test allows the shader to select which buffer it is
1899 // pulling from using layout binding qualifier.
1900 // There are corresponding changes in the compiler stack that
1901 // will select the buffer using binding directly.
Cody Northrop6217b822014-10-30 11:20:22 -06001902 // The binding number should match the slot number set up by
1903 // the application.
Cody Northropec1d3c32014-10-28 15:41:42 -06001904 // The expected result from this test is a purple triangle
1905
1906 static const char *vertShaderText =
Cody Northrop6217b822014-10-30 11:20:22 -06001907 "#version 140\n"
1908 "#extension GL_ARB_separate_shader_objects : enable\n"
1909 "#extension GL_ARB_shading_language_420pack : enable\n"
Cody Northropec1d3c32014-10-28 15:41:42 -06001910 "void main() {\n"
1911 " vec2 vertices[3];"
1912 " vertices[0] = vec2(-0.5, -0.5);\n"
1913 " vertices[1] = vec2( 0.5, -0.5);\n"
1914 " vertices[2] = vec2( 0.5, 0.5);\n"
1915 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1916 "}\n";
1917
1918 static const char *fragShaderText =
1919 "#version 140\n"
1920 "#extension GL_ARB_separate_shader_objects : enable\n"
1921 "#extension GL_ARB_shading_language_420pack : enable\n"
1922 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
1923 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
1924 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
1925 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
1926 "void main() {\n"
1927 " gl_FragColor = myBlueVal.color;\n"
1928 " gl_FragColor += myRedVal.color;\n"
1929 "}\n";
1930
Cody Northrop6217b822014-10-30 11:20:22 -06001931 XglTestFramework::m_use_bil = true;
Cody Northropec1d3c32014-10-28 15:41:42 -06001932 DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText);
1933}
1934
Cody Northrop722ff402014-10-20 09:22:42 -06001935int main(int argc, char **argv) {
1936 int result;
1937
1938 ::testing::InitGoogleTest(&argc, argv);
1939 XglTestFramework::InitArgs(&argc, argv);
1940
1941 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
1942
1943 result = RUN_ALL_TESTS();
1944
1945 XglTestFramework::Finish();
1946 return result;
1947}