blob: 4fb47e14fc9ac3734fce380d5471f0ae4411a10a [file] [log] [blame]
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08001/*
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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080026 */
27
28#ifndef INTEL_H
29#define INTEL_H
30
Chia-I Wu214dac62014-08-05 11:07:40 +080031#include <stdlib.h>
Chia-I Wu032a2e32015-01-19 11:14:00 +080032#include <stdio.h>
33#include <stdarg.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080034#include <stdbool.h>
Chia-I Wuaabb3602014-08-19 14:18:23 +080035#include <stdint.h>
Chia-I Wu214dac62014-08-05 11:07:40 +080036#include <string.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080037#include <assert.h>
38
39#include <xgl.h>
40#include <xglDbg.h>
Chia-I Wub8dceae2014-09-23 10:37:23 +080041#include <xglWsiX11Ext.h>
Chia-I Wu924c1fc2015-01-19 11:14:00 +080042#include <xglIcd.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080043
44#include "icd.h"
Chia-I Wu900364b2015-01-03 13:55:22 +080045#include "icd-alloc.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080046#include "icd-bil.h"
Chia-I Wu1bf06df2014-08-16 12:33:13 +080047#include "icd-format.h"
Chia-I Wu96a41bc2015-02-21 14:19:23 +080048#include "icd-instance.h"
Chia-I Wu8e270b52015-01-03 14:47:32 +080049#include "icd-log.h"
Chia-I Wu69abeac2014-08-16 12:43:53 +080050#include "icd-utils.h"
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080051
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -070052#define INTEL_API_VERSION XGL_API_VERSION
Chia-I Wu214dac62014-08-05 11:07:40 +080053#define INTEL_DRIVER_VERSION 0
54
55#define INTEL_GEN(gen) ((int) ((gen) * 100))
56
Chia-I Wu24693712014-11-08 11:54:47 +080057#define INTEL_MAX_VERTEX_BINDING_COUNT 33
58#define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1)
Tony Barbourfa6cac72015-01-16 14:27:35 -070059#define INTEL_MAX_RENDER_TARGETS 8
60
Chia-I Wu1c527012014-08-23 14:57:35 +080061enum intel_debug_flags {
62 INTEL_DEBUG_BATCH = 1 << 0,
Chia-I Wu93ada312014-08-23 15:02:25 +080063
64 INTEL_DEBUG_NOHW = 1 << 20,
Chia-I Wu3fb47ce2014-10-28 11:19:36 +080065 INTEL_DEBUG_NOCACHE = 1 << 21,
Chia-I Wuc45db532015-02-19 11:20:38 -070066 INTEL_DEBUG_NOHIZ = 1 << 22,
67 INTEL_DEBUG_HANG = 1 << 23,
Chia-I Wu1c527012014-08-23 14:57:35 +080068};
69
Chia-I Wu924c1fc2015-01-19 11:14:00 +080070struct intel_handle {
71 /* the loader expects a "void *" at the beginning */
72 void *loader_data;
73
74 uint32_t magic;
Chia-I Wu032a2e32015-01-19 11:14:00 +080075 const struct icd_instance *icd;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080076};
77
Chia-I Wu1c527012014-08-23 14:57:35 +080078extern int intel_debug;
79
Chia-I Wu924c1fc2015-01-19 11:14:00 +080080static const uint32_t intel_handle_magic = 0x494e544c;
81
82static inline void intel_handle_init(struct intel_handle *handle,
Chia-I Wu032a2e32015-01-19 11:14:00 +080083 XGL_DBG_OBJECT_TYPE type,
84 const struct icd_instance *icd)
Chia-I Wu924c1fc2015-01-19 11:14:00 +080085{
86 set_loader_magic_value(handle);
87
88 handle->magic = intel_handle_magic + type;
Chia-I Wu032a2e32015-01-19 11:14:00 +080089 handle->icd = icd;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080090}
91
92/**
93 * Return true if \p handle is a valid intel_handle. This assumes the first
94 * sizeof(intel_handle) bytes are readable, and they does not happen to have
95 * our magic values.
96 */
97static inline bool intel_handle_validate(const void *handle)
98{
99 const uint32_t handle_type =
100 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
101
102 return (handle_type <= XGL_DBG_OBJECT_TYPE_END_RANGE);
103}
104
105/**
106 * Return true if \p handle is a valid intel_handle of \p type.
107 *
108 * \see intel_handle_validate().
109 */
110static inline bool intel_handle_validate_type(const void *handle,
111 XGL_DBG_OBJECT_TYPE type)
112{
113 const uint32_t handle_type =
114 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
115
116 return (handle_type == (uint32_t) type);
117}
118
Chia-I Wu032a2e32015-01-19 11:14:00 +0800119static inline void *intel_alloc(const void *handle,
120 size_t size, size_t alignment,
121 XGL_SYSTEM_ALLOC_TYPE type)
122{
123 assert(intel_handle_validate(handle));
124 return icd_instance_alloc(((const struct intel_handle *) handle)->icd,
125 size, alignment, type);
126}
127
128static inline void intel_free(const void *handle, void *ptr)
129{
130 assert(intel_handle_validate(handle));
131 icd_instance_free(((const struct intel_handle *) handle)->icd, ptr);
132}
133
134static inline void intel_logv(const void *handle,
135 XGL_DBG_MSG_TYPE msg_type,
136 XGL_VALIDATION_LEVEL validation_level,
137 XGL_BASE_OBJECT src_object,
138 size_t location, int32_t msg_code,
139 const char *format, va_list ap)
140{
141 char msg[256];
142 int ret;
143
144 ret = vsnprintf(msg, sizeof(msg), format, ap);
145 if (ret >= sizeof(msg) || ret < 0)
146 msg[sizeof(msg) - 1] = '\0';
147
148 assert(intel_handle_validate(handle));
149 icd_instance_log(((const struct intel_handle *) handle)->icd,
150 msg_type, validation_level, src_object, location, msg_code, msg);
151}
152
153static inline void intel_log(const void *handle,
154 XGL_DBG_MSG_TYPE msg_type,
155 XGL_VALIDATION_LEVEL validation_level,
156 XGL_BASE_OBJECT src_object,
157 size_t location, int32_t msg_code,
158 const char *format, ...)
159{
160 va_list ap;
161
162 va_start(ap, format);
163 intel_logv(handle, msg_type, validation_level, src_object,
164 location, msg_code, format, ap);
165 va_end(ap);
166}
167
Chia-I Wuc6fb9af2014-08-04 11:28:43 +0800168#endif /* INTEL_H */