blob: de7bcbdfcec0c0b2f3ad5705436a4b2094e3b3dc [file] [log] [blame]
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08003 *
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
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include <vulkan.h>
40#include <vkDbg.h>
41#include <vkWsiX11Ext.h>
42#include <vkIcd.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080043
44#include "icd.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060045#include "icd-spv.h"
Chia-I Wu1bf06df2014-08-16 12:33:13 +080046#include "icd-format.h"
Chia-I Wu96a41bc2015-02-21 14:19:23 +080047#include "icd-instance.h"
Chia-I Wu69abeac2014-08-16 12:43:53 +080048#include "icd-utils.h"
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080049
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050#define INTEL_API_VERSION VK_API_VERSION
Chia-I Wu214dac62014-08-05 11:07:40 +080051#define INTEL_DRIVER_VERSION 0
52
53#define INTEL_GEN(gen) ((int) ((gen) * 100))
54
Chia-I Wu24693712014-11-08 11:54:47 +080055#define INTEL_MAX_VERTEX_BINDING_COUNT 33
56#define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1)
Tony Barbourfa6cac72015-01-16 14:27:35 -070057#define INTEL_MAX_RENDER_TARGETS 8
58
Jeremy Hayesd02809a2015-04-15 14:17:56 -060059#define INTEL_MEMORY_PROPERTY_ALL (VK_MEMORY_PROPERTY_GPU_ONLY | VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT |\
60 VK_MEMORY_PROPERTY_CPU_GPU_COHERENT_BIT | VK_MEMORY_PROPERTY_CPU_UNCACHED_BIT |\
61 VK_MEMORY_PROPERTY_CPU_WRITE_COMBINED_BIT | VK_MEMORY_PROPERTY_PREFER_CPU_LOCAL |\
62 VK_MEMORY_PROPERTY_SHAREABLE_BIT)
63
Chia-I Wu1c527012014-08-23 14:57:35 +080064enum intel_debug_flags {
65 INTEL_DEBUG_BATCH = 1 << 0,
Chia-I Wu93ada312014-08-23 15:02:25 +080066
67 INTEL_DEBUG_NOHW = 1 << 20,
Chia-I Wu3fb47ce2014-10-28 11:19:36 +080068 INTEL_DEBUG_NOCACHE = 1 << 21,
Chia-I Wuc45db532015-02-19 11:20:38 -070069 INTEL_DEBUG_NOHIZ = 1 << 22,
70 INTEL_DEBUG_HANG = 1 << 23,
Chia-I Wu1c527012014-08-23 14:57:35 +080071};
72
Chia-I Wu924c1fc2015-01-19 11:14:00 +080073struct intel_handle {
74 /* the loader expects a "void *" at the beginning */
75 void *loader_data;
76
77 uint32_t magic;
Chia-I Wu032a2e32015-01-19 11:14:00 +080078 const struct icd_instance *icd;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080079};
80
Chia-I Wu1c527012014-08-23 14:57:35 +080081extern int intel_debug;
82
Chia-I Wu924c1fc2015-01-19 11:14:00 +080083static const uint32_t intel_handle_magic = 0x494e544c;
84
85static inline void intel_handle_init(struct intel_handle *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060086 VK_DBG_OBJECT_TYPE type,
Chia-I Wu032a2e32015-01-19 11:14:00 +080087 const struct icd_instance *icd)
Chia-I Wu924c1fc2015-01-19 11:14:00 +080088{
89 set_loader_magic_value(handle);
90
91 handle->magic = intel_handle_magic + type;
Chia-I Wu032a2e32015-01-19 11:14:00 +080092 handle->icd = icd;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080093}
94
95/**
96 * Return true if \p handle is a valid intel_handle. This assumes the first
97 * sizeof(intel_handle) bytes are readable, and they does not happen to have
98 * our magic values.
99 */
100static inline bool intel_handle_validate(const void *handle)
101{
102 const uint32_t handle_type =
103 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
104
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600105 return (handle_type <= VK_DBG_OBJECT_TYPE_END_RANGE);
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800106}
107
108/**
109 * Return true if \p handle is a valid intel_handle of \p type.
110 *
111 * \see intel_handle_validate().
112 */
113static inline bool intel_handle_validate_type(const void *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 VK_DBG_OBJECT_TYPE type)
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800115{
116 const uint32_t handle_type =
117 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
118
119 return (handle_type == (uint32_t) type);
120}
121
Chia-I Wu032a2e32015-01-19 11:14:00 +0800122static inline void *intel_alloc(const void *handle,
123 size_t size, size_t alignment,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600124 VkSystemAllocType type)
Chia-I Wu032a2e32015-01-19 11:14:00 +0800125{
126 assert(intel_handle_validate(handle));
127 return icd_instance_alloc(((const struct intel_handle *) handle)->icd,
128 size, alignment, type);
129}
130
131static inline void intel_free(const void *handle, void *ptr)
132{
133 assert(intel_handle_validate(handle));
134 icd_instance_free(((const struct intel_handle *) handle)->icd, ptr);
135}
136
137static inline void intel_logv(const void *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600138 VK_DBG_MSG_TYPE msg_type,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 VkValidationLevel validation_level,
140 VkBaseObject src_object,
Chia-I Wu032a2e32015-01-19 11:14:00 +0800141 size_t location, int32_t msg_code,
142 const char *format, va_list ap)
143{
144 char msg[256];
145 int ret;
146
147 ret = vsnprintf(msg, sizeof(msg), format, ap);
148 if (ret >= sizeof(msg) || ret < 0)
149 msg[sizeof(msg) - 1] = '\0';
150
151 assert(intel_handle_validate(handle));
152 icd_instance_log(((const struct intel_handle *) handle)->icd,
153 msg_type, validation_level, src_object, location, msg_code, msg);
154}
155
156static inline void intel_log(const void *handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600157 VK_DBG_MSG_TYPE msg_type,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600158 VkValidationLevel validation_level,
159 VkBaseObject src_object,
Chia-I Wu032a2e32015-01-19 11:14:00 +0800160 size_t location, int32_t msg_code,
161 const char *format, ...)
162{
163 va_list ap;
164
165 va_start(ap, format);
166 intel_logv(handle, msg_type, validation_level, src_object,
167 location, msg_code, format, ap);
168 va_end(ap);
169}
170
Chia-I Wuc6fb9af2014-08-04 11:28:43 +0800171#endif /* INTEL_H */