blob: 82d5f33ccee3a7bc1ba03229f5c4d9e782b812cd [file] [log] [blame]
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -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
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060030
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
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060054// Verify XGL driver initialization
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060055
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060056#include <stdlib.h>
57#include <stdio.h>
58#include <stdbool.h>
59#include <string.h>
60
61#include <xgl.h>
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060062#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060063
Chia-I Wu3b78d312014-12-29 15:39:23 +080064#include "xgltestbinding.h"
65#include "test_common.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080066#include "icd-bil.h"
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060067
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060068class XglTest : public ::testing::Test {
69public:
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -060070 void CreateImageTest();
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -060071 void CreateCommandBufferTest();
72 void CreatePipelineTest();
73 void CreateShaderTest();
74 void CreateShader(XGL_SHADER *pshader);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060075
Chia-I Wu3b78d312014-12-29 15:39:23 +080076 XGL_DEVICE device() {return m_device->obj();}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060077
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060078protected:
79 XGL_APPLICATION_INFO app_info;
Chia-I Wu9c877b22014-12-28 14:37:25 +080080 XGL_PHYSICAL_GPU objs[XGL_MAX_PHYSICAL_GPUS];
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060081 XGL_UINT gpu_count;
Chia-I Wu3b78d312014-12-29 15:39:23 +080082
83 XGL_UINT m_device_id;
84 xgl_testing::Device *m_device;
85 XGL_PHYSICAL_GPU_PROPERTIES props;
86 XGL_PHYSICAL_GPU_QUEUE_PROPERTIES queue_props;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060087
88 virtual void SetUp() {
89 XGL_RESULT err;
90
91 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
92 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080093 this->app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060094 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080095 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060096 this->app_info.engineVersion = 1;
97 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
98
99 err = xglInitAndEnumerateGpus(&app_info, NULL,
Chia-I Wu9c877b22014-12-28 14:37:25 +0800100 XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600101 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700102 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600103
Chia-I Wu3b78d312014-12-29 15:39:23 +0800104 m_device_id = 0;
105 this->m_device = new xgl_testing::Device(objs[m_device_id]);
106 this->m_device->init();
107
108 props = m_device->gpu().properties();
109 queue_props = m_device->gpu().queue_properties()[0];
110
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600111 }
112
113 virtual void TearDown() {
114 xglInitAndEnumerateGpus(&this->app_info, NULL, 0, &gpu_count, NULL);
115 }
116};
117
118TEST(Initialization, xglInitAndEnumerateGpus) {
119 XGL_APPLICATION_INFO app_info = {};
Chia-I Wu9c877b22014-12-28 14:37:25 +0800120 XGL_PHYSICAL_GPU objs[XGL_MAX_PHYSICAL_GPUS];
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600121 XGL_UINT gpu_count;
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600122 XGL_RESULT err;
Chia-I Wu9c877b22014-12-28 14:37:25 +0800123 xgl_testing::PhysicalGpu *gpu;
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600124 XGL_CHAR *layers[16];
125 XGL_SIZE layer_count;
126 XGL_CHAR layer_buf[16][256];
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600127
128 app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
129 app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800130 app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600131 app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800132 app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600133 app_info.engineVersion = 1;
134 app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600135
136 err = xglInitAndEnumerateGpus(&app_info, NULL,
Chia-I Wu9c877b22014-12-28 14:37:25 +0800137 XGL_MAX_PHYSICAL_GPUS, &gpu_count, objs);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600138 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700139 ASSERT_GE(gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600140
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600141 for (int i = 0; i < 16; i++)
142 layers[i] = &layer_buf[i][0];
Mark Lobodzinski953a1692015-01-09 15:12:03 -0600143 err = xglEnumerateLayers(objs[0], 16, 256, &layer_count, (XGL_CHAR * const *) layers, NULL);
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600144 ASSERT_XGL_SUCCESS(err);
145 for (int i = 0; i < layer_count; i++) {
146 printf("Enumerated layers: %s ", layers[i]);
147 }
148 printf("\n");
149
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600150 // TODO: Iterate over all GPUs
Chia-I Wu9c877b22014-12-28 14:37:25 +0800151 gpu = new xgl_testing::PhysicalGpu(objs[0]);
Chia-I Wub7cf4452014-12-16 00:04:02 +0800152 delete gpu;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600153
154 // TODO: Verify destroy functions
155}
156
157TEST_F(XglTest, AllocMemory) {
158 XGL_RESULT err;
159 XGL_MEMORY_ALLOC_INFO alloc_info = {};
160 XGL_GPU_MEMORY gpu_mem;
161 XGL_UINT8 *pData;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700162 XGL_UINT localHeap[1] = {0};
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600163
164 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
165 alloc_info.allocationSize = 1024 * 1024; // 1MB
166 alloc_info.alignment = 0;
Jon Ashburn542cd092015-01-20 13:55:32 -0700167 alloc_info.memProps = XGL_MEMORY_PROPERTY_SHAREABLE_BIT |
168 XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600169 alloc_info.heapCount = 1;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700170 alloc_info.pHeaps = localHeap;
171
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600172
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600173 // TODO: Try variety of memory priorities
174 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
175
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600176 err = xglAllocMemory(device(), &alloc_info, &gpu_mem);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600177 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600178
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600179 err = xglMapMemory(gpu_mem, 0, (XGL_VOID **) &pData);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600180 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600181
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600182 memset(pData, 0x55, alloc_info.allocationSize);
183 EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write";
184
185 err = xglUnmapMemory(gpu_mem);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600186 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600187
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600188 err = xglFreeMemory(gpu_mem);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600189 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600190}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600191
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600192TEST_F(XglTest, Event) {
193 XGL_EVENT_CREATE_INFO event_info;
194 XGL_EVENT event;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600195 XGL_MEMORY_REQUIREMENTS mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800196 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600197 XGL_RESULT err;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600198
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600199 // typedef struct _XGL_EVENT_CREATE_INFO
200 // {
201 // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO
202 // const XGL_VOID* pNext; // Pointer to next structure
203 // XGL_FLAGS flags; // Reserved
204 // } XGL_EVENT_CREATE_INFO;
205 memset(&event_info, 0, sizeof(event_info));
206 event_info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600207
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600208 err = xglCreateEvent(device(), &event_info, &event);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600209 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600210
211 err = xglGetObjectInfo(event, XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
212 &data_size, &mem_req);
213 ASSERT_XGL_SUCCESS(err);
214
215 // XGL_RESULT XGLAPI xglAllocMemory(
216 // XGL_DEVICE device,
217 // const XGL_MEMORY_ALLOC_INFO* pAllocInfo,
218 // XGL_GPU_MEMORY* pMem);
219 XGL_MEMORY_ALLOC_INFO mem_info;
220 XGL_GPU_MEMORY event_mem;
221
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600222 ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect events to require memory";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600223
Tony Barbourfa6cac72015-01-16 14:27:35 -0700224 XGL_UINT heapInfo[mem_req.heapCount];
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600225 memset(&mem_info, 0, sizeof(mem_info));
226 mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
227 mem_info.allocationSize = mem_req.size;
228 mem_info.alignment = mem_req.alignment;
Jon Ashburn542cd092015-01-20 13:55:32 -0700229 mem_info.memProps = XGL_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600230 mem_info.heapCount = mem_req.heapCount;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700231 mem_info.pHeaps = heapInfo;
232 memcpy(heapInfo, mem_req.pHeaps, sizeof(XGL_UINT)*mem_info.heapCount);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600233 mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
234 mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600235 err = xglAllocMemory(device(), &mem_info, &event_mem);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600236 ASSERT_XGL_SUCCESS(err);
237
Jon Ashburned62b412015-01-15 10:39:19 -0700238 err = xglBindObjectMemory(event, 0, event_mem, 0);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600239 ASSERT_XGL_SUCCESS(err);
240
241 err = xglResetEvent(event);
242 ASSERT_XGL_SUCCESS(err);
243
244 err = xglGetEventStatus(event);
245 ASSERT_EQ(XGL_EVENT_RESET, err);
246
247 err = xglSetEvent(event);
248 ASSERT_XGL_SUCCESS(err);
249
250 err = xglGetEventStatus(event);
251 ASSERT_EQ(XGL_EVENT_SET, err);
252
253 // TODO: Test actual synchronization with command buffer event.
254
255 // All done with event memory, clean up
Jon Ashburned62b412015-01-15 10:39:19 -0700256 err = xglBindObjectMemory(event, 0, XGL_NULL_HANDLE, 0);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600257 ASSERT_XGL_SUCCESS(err);
258
259 err = xglDestroyObject(event);
260 ASSERT_XGL_SUCCESS(err);
261}
262
263TEST_F(XglTest, Fence) {
264 XGL_RESULT err;
265 XGL_FENCE_CREATE_INFO fence_info;
266 XGL_FENCE fence;
267
268 memset(&fence_info, 0, sizeof(fence_info));
269
270 // typedef struct _XGL_FENCE_CREATE_INFO
271 // {
272 // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO
273 // const XGL_VOID* pNext; // Pointer to next structure
274 // XGL_FLAGS flags; // Reserved
275 fence_info.sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO;
276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277 err = xglCreateFence(device(), &fence_info, &fence);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600278 ASSERT_XGL_SUCCESS(err);
279
280 err = xglGetFenceStatus(fence);
281 // We've not submitted this fence on a command buffer so should get
282 // XGL_ERROR_UNAVAILABLE
283 EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err);
284
285 // Test glxWaitForFences
286 // XGL_RESULT XGLAPI xglWaitForFences(
287 // XGL_DEVICE device,
288 // XGL_UINT fenceCount,
289 // const XGL_FENCE* pFences,
290 // XGL_BOOL waitAll,
291 // XGL_UINT64 timeout);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600292 err = xglWaitForFences(device(), 1, &fence, XGL_TRUE, 0);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600293 EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err);
294
295 // TODO: Attached to command buffer and test GetFenceStatus
296 // TODO: Add some commands and submit the command buffer
297
298 err = xglDestroyObject(fence);
299 ASSERT_XGL_SUCCESS(err);
300
301}
302
303#define MAX_QUERY_SLOTS 10
304
305TEST_F(XglTest, Query) {
306 XGL_QUERY_POOL_CREATE_INFO query_info;
307 XGL_QUERY_POOL query_pool;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800308 size_t data_size;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600309 XGL_MEMORY_REQUIREMENTS mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800310 size_t query_result_size;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600311 XGL_UINT *query_result_data;
312 XGL_RESULT err;
313
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600314 // typedef enum _XGL_QUERY_TYPE
315 // {
316 // XGL_QUERY_OCCLUSION = 0x00000000,
317 // XGL_QUERY_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600318
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600319 // XGL_QUERY_TYPE_BEGIN_RANGE = XGL_QUERY_OCCLUSION,
320 // XGL_QUERY_TYPE_END_RANGE = XGL_QUERY_PIPELINE_STATISTICS,
321 // XGL_NUM_QUERY_TYPE = (XGL_QUERY_TYPE_END_RANGE - XGL_QUERY_TYPE_BEGIN_RANGE + 1),
322 // XGL_MAX_ENUM(_XGL_QUERY_TYPE)
323 // } XGL_QUERY_TYPE;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600324
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600325 // typedef struct _XGL_QUERY_POOL_CREATE_INFO
326 // {
327 // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
328 // const XGL_VOID* pNext; // Pointer to next structure
329 // XGL_QUERY_TYPE queryType;
330 // XGL_UINT slots;
331 // } XGL_QUERY_POOL_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600332
333 memset(&query_info, 0, sizeof(query_info));
334 query_info.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
335 query_info.queryType = XGL_QUERY_OCCLUSION;
336 query_info.slots = MAX_QUERY_SLOTS;
337
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600338 // XGL_RESULT XGLAPI xglCreateQueryPool(
339 // XGL_DEVICE device,
340 // const XGL_QUERY_POOL_CREATE_INFO* pCreateInfo,
341 // XGL_QUERY_POOL* pQueryPool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600342
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600343 err = xglCreateQueryPool(device(), &query_info, &query_pool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600344 ASSERT_XGL_SUCCESS(err);
345
Jon Ashburnb8e43892014-09-25 14:36:58 -0600346 data_size = sizeof(mem_req);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600347 err = xglGetObjectInfo(query_pool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
348 &data_size, &mem_req);
349 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600350 ASSERT_NE(0, data_size) << "Invalid data_size";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600351
352 // XGL_RESULT XGLAPI xglAllocMemory(
353 // XGL_DEVICE device,
354 // const XGL_MEMORY_ALLOC_INFO* pAllocInfo,
355 // XGL_GPU_MEMORY* pMem);
356 XGL_MEMORY_ALLOC_INFO mem_info;
357 XGL_GPU_MEMORY query_mem;
358
Tony Barbourfa6cac72015-01-16 14:27:35 -0700359 XGL_UINT heapInfo[mem_req.heapCount];
360
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600361 memset(&mem_info, 0, sizeof(mem_info));
362 mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
363 // TODO: Is a simple multiple all that's needed here?
364 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
365 mem_info.alignment = mem_req.alignment;
366 mem_info.heapCount = mem_req.heapCount;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700367 mem_info.pHeaps = heapInfo;
368 memcpy(heapInfo, mem_req.pHeaps, sizeof(XGL_UINT)*mem_info.heapCount);
Jon Ashburn542cd092015-01-20 13:55:32 -0700369 mem_info.memProps = XGL_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600370 mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
371
372 // TODO: are the flags right?
373 // TODO: Should this be pinned? Or maybe a separate test with pinned.
374 mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600375 err = xglAllocMemory(device(), &mem_info, &query_mem);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600376 ASSERT_XGL_SUCCESS(err);
377
Jon Ashburned62b412015-01-15 10:39:19 -0700378 err = xglBindObjectMemory(query_pool, 0, query_mem, 0);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600379 ASSERT_XGL_SUCCESS(err);
380
381 // TODO: Test actual synchronization with command buffer event.
382 // TODO: Create command buffer
383 // TODO: xglCmdResetQueryPool
384 // TODO: xglCmdBeginQuery
385 // TODO: commands
386 // TOOD: xglCmdEndQuery
387
388 err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
389 &query_result_size, XGL_NULL_HANDLE);
390 ASSERT_XGL_SUCCESS(err);
391
392 if (query_result_size > 0) {
393 query_result_data = new XGL_UINT [query_result_size];
394 err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
395 &query_result_size, query_result_data);
396 ASSERT_XGL_SUCCESS(err);
397
398 // TODO: Test Query result data.
399
400 }
401
402 // All done with QueryPool memory, clean up
Jon Ashburned62b412015-01-15 10:39:19 -0700403 err = xglBindObjectMemory(query_pool, 0, XGL_NULL_HANDLE, 0);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600404 ASSERT_XGL_SUCCESS(err);
405
406 err = xglDestroyObject(query_pool);
407 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600408}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600409
Chia-I Wu3b78d312014-12-29 15:39:23 +0800410void getQueue(xgl_testing::Device *device, XGL_QUEUE_TYPE qtype, const char *qname)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600411{
412 int que_idx;
413 XGL_RESULT err;
414 XGL_QUEUE queue;
415
Chia-I Wu3b78d312014-12-29 15:39:23 +0800416 const XGL_PHYSICAL_GPU_QUEUE_PROPERTIES props = device->gpu().queue_properties()[0];
417 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
418 err = xglGetDeviceQueue(device->obj(), qtype, que_idx, &queue);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600419 ASSERT_EQ(XGL_SUCCESS, err) << "xglGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << xgl_result_string(err);
420 }
421}
422
423TEST_F(XglTest, Queue)
424{
425 XGL_UINT que_idx;
426
Chia-I Wu3b78d312014-12-29 15:39:23 +0800427 ASSERT_NE(0, queue_props.queueCount) << "No heaps available for GPU #" << m_device_id << ": " << props.gpuName;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600428
429// XGL_RESULT XGLAPI xglGetDeviceQueue(
430// XGL_DEVICE device,
431// XGL_QUEUE_TYPE queueType,
432// XGL_UINT queueIndex,
433// XGL_QUEUE* pQueue);
434 /*
435 * queue handles are retrieved from the device by calling
436 * xglGetDeviceQueue() with a queue type and a requested logical
437 * queue ID. The logical queue ID is a sequential number starting
438 * from zero and referencing up to the number of queues requested
439 * at device creation. Each queue type has its own sequence of IDs
440 * starting at zero.
441 */
442
Chia-I Wu3b78d312014-12-29 15:39:23 +0800443 for (que_idx = 0; que_idx < queue_props.queueCount; que_idx++) {
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600444
445// typedef enum _XGL_QUEUE_FLAGS
446// {
447// XGL_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations
448// XGL_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations
449// XGL_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations
450// XGL_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue
451// } XGL_QUEUE_FLAGS;
452
453// typedef enum _XGL_QUEUE_TYPE
454// {
455// XGL_QUEUE_TYPE_GRAPHICS = 0x1,
456// XGL_QUEUE_TYPE_COMPUTE = 0x2,
457// XGL_QUEUE_TYPE_DMA = 0x3,
458// XGL_MAX_ENUM(_XGL_QUEUE_TYPE)
459// } XGL_QUEUE_TYPE;
460
Chia-I Wu3b78d312014-12-29 15:39:23 +0800461 if (queue_props.queueFlags & XGL_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600462 getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "Graphics");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600463 }
464
Chia-I Wu3b78d312014-12-29 15:39:23 +0800465 if (queue_props.queueFlags & XGL_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600466 getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "Compute");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600467 }
468
Chia-I Wu3b78d312014-12-29 15:39:23 +0800469 if (queue_props.queueFlags & XGL_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600470 getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "DMA");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600471 }
472
473 // TODO: What do we do about EXTENDED_BIT?
474
475 /* Guide: pg 34:
476 * The queue objects cannot be destroyed explicitly by an application
477 * and are automatically destroyed when the associated device is destroyed.
478 * Once the device is destroyed, attempting to use a queue results in
479 * undefined behavior.
480 */
481 }
482}
483
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600484void XglTest::CreateImageTest()
485{
486 XGL_RESULT err;
487 XGL_IMAGE image;
488 XGL_UINT w, h, mipCount;
489 XGL_SIZE size;
490 XGL_FORMAT fmt;
491 XGL_FORMAT_PROPERTIES image_fmt;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800492 size_t data_size;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600493
494 w =512;
495 h = 256;
496 mipCount = 0;
497
498 XGL_UINT _w = w;
499 XGL_UINT _h = h;
500 while( ( _w > 0 ) || ( _h > 0 ) )
501 {
502 _w >>= 1;
503 _h >>= 1;
504 mipCount++;
505 }
506
507 fmt.channelFormat = XGL_CH_FMT_R8G8B8A8;
508 fmt.numericFormat = XGL_NUM_FMT_UINT;
509 // TODO: Pick known good format rather than just expect common format
510 /*
511 * XXX: What should happen if given NULL HANDLE for the pData argument?
512 * We're not requesting XGL_INFO_TYPE_MEMORY_REQUIREMENTS so there is
513 * an expectation that pData is a valid pointer.
514 * However, why include a returned size value? That implies that the
515 * amount of data may vary and that doesn't work well for using a
516 * fixed structure.
517 */
518
Jon Ashburnb8e43892014-09-25 14:36:58 -0600519 size = sizeof(image_fmt);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600520 err = xglGetFormatInfo(device(), fmt,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600521 XGL_INFO_TYPE_FORMAT_PROPERTIES,
522 &size, &image_fmt);
523 ASSERT_XGL_SUCCESS(err);
524
525// typedef struct _XGL_IMAGE_CREATE_INFO
526// {
527// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO
528// const XGL_VOID* pNext; // Pointer to next structure.
529// XGL_IMAGE_TYPE imageType;
530// XGL_FORMAT format;
531// XGL_EXTENT3D extent;
532// XGL_UINT mipLevels;
533// XGL_UINT arraySize;
534// XGL_UINT samples;
535// XGL_IMAGE_TILING tiling;
536// XGL_FLAGS usage; // XGL_IMAGE_USAGE_FLAGS
537// XGL_FLAGS flags; // XGL_IMAGE_CREATE_FLAGS
538// } XGL_IMAGE_CREATE_INFO;
539
540
541 XGL_IMAGE_CREATE_INFO imageCreateInfo = {};
542 imageCreateInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
543 imageCreateInfo.imageType = XGL_IMAGE_2D;
544 imageCreateInfo.format = fmt;
545 imageCreateInfo.arraySize = 1;
546 imageCreateInfo.extent.width = w;
547 imageCreateInfo.extent.height = h;
548 imageCreateInfo.extent.depth = 1;
549 imageCreateInfo.mipLevels = mipCount;
550 imageCreateInfo.samples = 1;
551 imageCreateInfo.tiling = XGL_LINEAR_TILING;
552
553// Image usage flags
554// typedef enum _XGL_IMAGE_USAGE_FLAGS
555// {
556// XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001,
557// XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002,
558// XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004,
559// XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008,
560// } XGL_IMAGE_USAGE_FLAGS;
561 imageCreateInfo.usage = XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
562
563// XGL_RESULT XGLAPI xglCreateImage(
564// XGL_DEVICE device,
565// const XGL_IMAGE_CREATE_INFO* pCreateInfo,
566// XGL_IMAGE* pImage);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600567 err = xglCreateImage(device(), &imageCreateInfo, &image);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600568 ASSERT_XGL_SUCCESS(err);
569
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600570 // Verify image resources
571// XGL_RESULT XGLAPI xglGetImageSubresourceInfo(
572// XGL_IMAGE image,
573// const XGL_IMAGE_SUBRESOURCE* pSubresource,
574// XGL_SUBRESOURCE_INFO_TYPE infoType,
575// XGL_SIZE* pDataSize,
576// XGL_VOID* pData);
577// typedef struct _XGL_SUBRESOURCE_LAYOUT
578// {
579// XGL_GPU_SIZE offset; // Specified in bytes
580// XGL_GPU_SIZE size; // Specified in bytes
581// XGL_GPU_SIZE rowPitch; // Specified in bytes
582// XGL_GPU_SIZE depthPitch; // Specified in bytes
583// } XGL_SUBRESOURCE_LAYOUT;
584
585// typedef struct _XGL_IMAGE_SUBRESOURCE
586// {
587// XGL_IMAGE_ASPECT aspect;
588// XGL_UINT mipLevel;
589// XGL_UINT arraySlice;
590// } XGL_IMAGE_SUBRESOURCE;
591// typedef enum _XGL_SUBRESOURCE_INFO_TYPE
592// {
593// // Info type for xglGetImageSubresourceInfo()
594// XGL_INFO_TYPE_SUBRESOURCE_LAYOUT = 0x00000000,
595
596// XGL_MAX_ENUM(_XGL_SUBRESOURCE_INFO_TYPE)
597// } XGL_SUBRESOURCE_INFO_TYPE;
598 XGL_IMAGE_SUBRESOURCE subresource = {};
599 subresource.aspect = XGL_IMAGE_ASPECT_COLOR;
600 subresource.arraySlice = 0;
601
602 _w = w;
603 _h = h;
604 while( ( _w > 0 ) || ( _h > 0 ) )
605 {
606 XGL_SUBRESOURCE_LAYOUT layout = {};
Jon Ashburnb8e43892014-09-25 14:36:58 -0600607 data_size = sizeof(layout);
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600608 err = xglGetImageSubresourceInfo(image, &subresource, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT,
609 &data_size, &layout);
610 ASSERT_XGL_SUCCESS(err);
611 ASSERT_EQ(sizeof(XGL_SUBRESOURCE_LAYOUT), data_size) << "Invalid structure (XGL_SUBRESOURCE_LAYOUT) size";
612
613 // TODO: 4 should be replaced with pixel size for given format
614 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
615 _w >>= 1;
616 _h >>= 1;
617
618 subresource.mipLevel++;
619 }
620
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700621 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc = {
622 .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO,
623 .pNext = NULL,
624
625 };
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600626 XGL_MEMORY_REQUIREMENTS mem_req;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700627 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
628 XGL_SIZE img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
Jon Ashburnb8e43892014-09-25 14:36:58 -0600629 data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600630 err = xglGetObjectInfo(image, XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
631 &data_size, &mem_req);
632 ASSERT_XGL_SUCCESS(err);
633 ASSERT_EQ(data_size, sizeof(mem_req));
634 ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory";
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700635 err = xglGetObjectInfo(image, XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
636 &img_reqs_size, &img_reqs);
637 ASSERT_XGL_SUCCESS(err);
638 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
639 img_alloc.usage = img_reqs.usage;
640 img_alloc.formatClass = img_reqs.formatClass;
641 img_alloc.samples = img_reqs.samples;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600642 // XGL_RESULT XGLAPI xglAllocMemory(
643 // XGL_DEVICE device,
644 // const XGL_MEMORY_ALLOC_INFO* pAllocInfo,
645 // XGL_GPU_MEMORY* pMem);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700646 XGL_MEMORY_ALLOC_INFO mem_info = {};
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600647 XGL_GPU_MEMORY image_mem;
648
Tony Barbourfa6cac72015-01-16 14:27:35 -0700649 XGL_UINT heapInfo[mem_req.heapCount];
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600650 mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700651 mem_info.pNext = &img_alloc;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600652 mem_info.allocationSize = mem_req.size;
653 mem_info.alignment = mem_req.alignment;
654 mem_info.heapCount = mem_req.heapCount;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700655 mem_info.pHeaps = heapInfo;
656 memcpy(heapInfo, mem_req.pHeaps, sizeof(XGL_UINT)*mem_info.heapCount);
Jon Ashburn542cd092015-01-20 13:55:32 -0700657 mem_info.memProps = XGL_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600658 mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
659 mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600660 err = xglAllocMemory(device(), &mem_info, &image_mem);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600661 ASSERT_XGL_SUCCESS(err);
662
Jon Ashburned62b412015-01-15 10:39:19 -0700663 err = xglBindObjectMemory(image, 0, image_mem, 0);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600664 ASSERT_XGL_SUCCESS(err);
665
666// typedef struct _XGL_IMAGE_VIEW_CREATE_INFO
667// {
668// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
669// const XGL_VOID* pNext; // Pointer to next structure
670// XGL_IMAGE image;
671// XGL_IMAGE_VIEW_TYPE viewType;
672// XGL_FORMAT format;
673// XGL_CHANNEL_MAPPING channels;
674// XGL_IMAGE_SUBRESOURCE_RANGE subresourceRange;
675// XGL_FLOAT minLod;
676// } XGL_IMAGE_VIEW_CREATE_INFO;
677 XGL_IMAGE_VIEW_CREATE_INFO viewInfo = {};
678 XGL_IMAGE_VIEW view;
679 viewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
680 viewInfo.image = image;
681 viewInfo.viewType = XGL_IMAGE_VIEW_2D;
682 viewInfo.format = fmt;
683
684 viewInfo.channels.r = XGL_CHANNEL_SWIZZLE_R;
685 viewInfo.channels.g = XGL_CHANNEL_SWIZZLE_G;
686 viewInfo.channels.b = XGL_CHANNEL_SWIZZLE_B;
687 viewInfo.channels.a = XGL_CHANNEL_SWIZZLE_A;
688
689 viewInfo.subresourceRange.baseArraySlice = 0;
690 viewInfo.subresourceRange.arraySize = 1;
691 viewInfo.subresourceRange.baseMipLevel = 0;
692 viewInfo.subresourceRange.mipLevels = 1;
693 viewInfo.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
694
695// XGL_RESULT XGLAPI xglCreateImageView(
696// XGL_DEVICE device,
697// const XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo,
698// XGL_IMAGE_VIEW* pView);
699
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600700 err = xglCreateImageView(device(), &viewInfo, &view);
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600701 ASSERT_XGL_SUCCESS(err) << "xglCreateImageView failed";
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600702
703 // TODO: Test image memory.
704
705 // All done with image memory, clean up
Jon Ashburned62b412015-01-15 10:39:19 -0700706 ASSERT_XGL_SUCCESS(xglBindObjectMemory(image, 0, XGL_NULL_HANDLE, 0));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600707
708 ASSERT_XGL_SUCCESS(xglFreeMemory(image_mem));
709
710 ASSERT_XGL_SUCCESS(xglDestroyObject(image));
711}
712
713TEST_F(XglTest, CreateImage) {
714 CreateImageTest();
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600715}
716
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600717void XglTest::CreateCommandBufferTest()
718{
719 XGL_RESULT err;
720 XGL_CMD_BUFFER_CREATE_INFO info = {};
721 XGL_CMD_BUFFER cmdBuffer;
722
723// typedef struct _XGL_CMD_BUFFER_CREATE_INFO
724// {
725// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
726// const XGL_VOID* pNext;
727// XGL_QUEUE_TYPE queueType;
728// XGL_FLAGS flags;
729// } XGL_CMD_BUFFER_CREATE_INFO;
730
731 info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
732 info.queueType = XGL_QUEUE_TYPE_GRAPHICS;
733 err = xglCreateCommandBuffer(device(), &info, &cmdBuffer);
734 ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed";
735
736 ASSERT_XGL_SUCCESS(xglDestroyObject(cmdBuffer));
737}
738
739TEST_F(XglTest, TestComandBuffer) {
740 CreateCommandBufferTest();
741}
742
743void XglTest::CreateShader(XGL_SHADER *pshader)
744{
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600745 void *code;
746 uint32_t codeSize;
Chia-I Wu4115c892014-08-28 11:56:29 +0800747 struct icd_bil_header *pBIL;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600748 XGL_RESULT err;
749
Chia-I Wu4115c892014-08-28 11:56:29 +0800750 codeSize = sizeof(struct icd_bil_header) + 100;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600751 code = malloc(codeSize);
752 ASSERT_TRUE(NULL != code) << "malloc failed!";
753
754 memset(code, 0, codeSize);
755
756 // Indicate that this is BIL data.
Chia-I Wu4115c892014-08-28 11:56:29 +0800757 pBIL = (struct icd_bil_header *) code;
758 pBIL->magic = ICD_BIL_MAGIC;
759 pBIL->version = ICD_BIL_VERSION;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600760
761// typedef struct _XGL_SHADER_CREATE_INFO
762// {
763// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO
764// const XGL_VOID* pNext; // Pointer to next structure
765// XGL_SIZE codeSize; // Specified in bytes
766// const XGL_VOID* pCode;
767// XGL_FLAGS flags; // Reserved
768// } XGL_SHADER_CREATE_INFO;
769
770 XGL_SHADER_CREATE_INFO createInfo;
771 XGL_SHADER shader;
772
773 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
774 createInfo.pNext = NULL;
775 createInfo.pCode = code;
776 createInfo.codeSize = codeSize;
777 createInfo.flags = 0;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600778 err = xglCreateShader(device(), &createInfo, &shader);
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600779 ASSERT_XGL_SUCCESS(err);
780
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600781 *pshader = shader;
782}
783
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600784int main(int argc, char **argv) {
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600785 ::testing::InitGoogleTest(&argc, argv);
Chia-I Wu1c9869e2014-12-28 14:27:28 +0800786 xgl_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600787 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600788}