blob: 97db2730debaf89f9bf0cb51359a31401689d472 [file] [log] [blame]
Courtney Goeltzenleuchterb202efc2014-08-06 16:11:26 -06001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef COMMON_H
26#define COMMON_H
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <stdbool.h>
31#include <string.h>
32
33#include <xgl.h>
34
35#define ERR(err) printf("%s:%d: failed with %s\n", \
36 __FILE__, __LINE__, xgl_result_string(err));
37
38#define ERR_EXIT(err) do { ERR(err); exit(-1); } while (0)
39
40#define ERR_MSG(msg) printf("%s:%d: failed with %s\n", \
41 __FILE__, __LINE__, msg);
42
43#define ERR_MSG_EXIT(err) do { ERR_MSG(err); exit(-1); } while (0)
44
45#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
46
47#define MAX_GPUS 8
48
49struct app_dev {
50 struct app_gpu *gpu; /* point back to the GPU */
51
52 XGL_DEVICE obj;
53
54 XGL_UINT heap_count;
55 XGL_MEMORY_HEAP_PROPERTIES *heap_props;
56
57 XGL_FORMAT_PROPERTIES format_props[XGL_MAX_CH_FMT][XGL_MAX_NUM_FMT];
58};
59
60struct app_gpu {
61 XGL_UINT id;
62 XGL_PHYSICAL_GPU obj;
63
64 XGL_PHYSICAL_GPU_PROPERTIES props;
65 XGL_PHYSICAL_GPU_PERFORMANCE perf;
66
67 XGL_UINT queue_count;
68 XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props;
69
70 XGL_PHYSICAL_GPU_MEMORY_PROPERTIES memory_props;
71
72 XGL_UINT extension_count;
73 const XGL_CHAR **extensions;
74
75 struct app_dev dev;
76};
77
78static const char *xgl_result_string(XGL_RESULT err)
79{
80 switch (err) {
81#define STR(r) case r: return #r
82 STR(XGL_SUCCESS);
83 STR(XGL_UNSUPPORTED);
84 STR(XGL_NOT_READY);
85 STR(XGL_TIMEOUT);
86 STR(XGL_EVENT_SET);
87 STR(XGL_EVENT_RESET);
88 STR(XGL_ERROR_UNKNOWN);
89 STR(XGL_ERROR_UNAVAILABLE);
90 STR(XGL_ERROR_INITIALIZATION_FAILED);
91 STR(XGL_ERROR_OUT_OF_MEMORY);
92 STR(XGL_ERROR_OUT_OF_GPU_MEMORY);
93 STR(XGL_ERROR_DEVICE_ALREADY_CREATED);
94 STR(XGL_ERROR_DEVICE_LOST);
95 STR(XGL_ERROR_INVALID_POINTER);
96 STR(XGL_ERROR_INVALID_VALUE);
97 STR(XGL_ERROR_INVALID_HANDLE);
98 STR(XGL_ERROR_INVALID_ORDINAL);
99 STR(XGL_ERROR_INVALID_MEMORY_SIZE);
100 STR(XGL_ERROR_INVALID_EXTENSION);
101 STR(XGL_ERROR_INVALID_FLAGS);
102 STR(XGL_ERROR_INVALID_ALIGNMENT);
103 STR(XGL_ERROR_INVALID_FORMAT);
104 STR(XGL_ERROR_INVALID_IMAGE);
105 STR(XGL_ERROR_INVALID_DESCRIPTOR_SET_DATA);
106 STR(XGL_ERROR_INVALID_QUEUE_TYPE);
107 STR(XGL_ERROR_INVALID_OBJECT_TYPE);
108 STR(XGL_ERROR_UNSUPPORTED_SHADER_IL_VERSION);
109 STR(XGL_ERROR_BAD_SHADER_CODE);
110 STR(XGL_ERROR_BAD_PIPELINE_DATA);
111 STR(XGL_ERROR_TOO_MANY_MEMORY_REFERENCES);
112 STR(XGL_ERROR_NOT_MAPPABLE);
113 STR(XGL_ERROR_MEMORY_MAP_FAILED);
114 STR(XGL_ERROR_MEMORY_UNMAP_FAILED);
115 STR(XGL_ERROR_INCOMPATIBLE_DEVICE);
116 STR(XGL_ERROR_INCOMPATIBLE_DRIVER);
117 STR(XGL_ERROR_INCOMPLETE_COMMAND_BUFFER);
118 STR(XGL_ERROR_BUILDING_COMMAND_BUFFER);
119 STR(XGL_ERROR_MEMORY_NOT_BOUND);
120 STR(XGL_ERROR_INCOMPATIBLE_QUEUE);
121 STR(XGL_ERROR_NOT_SHAREABLE);
122#undef STR
123 default: return "UNKNOWN_RESULT";
124 }
125}
126
127void app_dev_init_formats(struct app_dev *dev);
128void app_dev_init(struct app_dev *dev, struct app_gpu *gpu);
129void app_dev_destroy(struct app_dev *dev);
130void app_gpu_init_extensions(struct app_gpu *gpu);
131void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj);
132void app_gpu_destroy(struct app_gpu *gpu);
133
134#endif // COMMON_H