blob: 37aac3c8e786968c8633b5a876e13f50a439426e [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>
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060040#include <vk_icd.h>
Tony Barbourde4124d2015-07-03 10:33:54 -060041#include <vk_debug_report_lunarg.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080042
43#include "icd.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060044#include "icd-spv.h"
Chia-I Wu1bf06df2014-08-16 12:33:13 +080045#include "icd-format.h"
Chia-I Wu96a41bc2015-02-21 14:19:23 +080046#include "icd-instance.h"
Chia-I Wu69abeac2014-08-16 12:43:53 +080047#include "icd-utils.h"
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080048
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060049#define INTEL_API_VERSION VK_API_VERSION
Chia-I Wu214dac62014-08-05 11:07:40 +080050#define INTEL_DRIVER_VERSION 0
51
52#define INTEL_GEN(gen) ((int) ((gen) * 100))
53
Chia-I Wu24693712014-11-08 11:54:47 +080054#define INTEL_MAX_VERTEX_BINDING_COUNT 33
55#define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1)
Tony Barbourfa6cac72015-01-16 14:27:35 -070056#define INTEL_MAX_RENDER_TARGETS 8
Chris Forbes948bf602015-05-08 11:01:16 +120057#define INTEL_MAX_VIEWPORTS 16
Tony Barbourfa6cac72015-01-16 14:27:35 -070058
Tony Barbour8205d902015-04-16 15:59:00 -060059#define INTEL_MEMORY_PROPERTY_ALL (VK_MEMORY_PROPERTY_DEVICE_ONLY | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |\
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -060060 VK_MEMORY_PROPERTY_HOST_NON_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT |\
Mark Lobodzinski99d272a2015-07-02 17:09:57 -060061 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT)
Mark Lobodzinski72346292015-07-02 16:49:40 -060062#define INTEL_MEMORY_HEAP_COUNT 1
63#define INTEL_MEMORY_HEAP_SIZE (2u << 30)
64#define INTEL_MEMORY_TYPE_COUNT 1
Jeremy Hayesd02809a2015-04-15 14:17:56 -060065
Chia-I Wu1c527012014-08-23 14:57:35 +080066enum intel_debug_flags {
67 INTEL_DEBUG_BATCH = 1 << 0,
Chia-I Wu93ada312014-08-23 15:02:25 +080068
69 INTEL_DEBUG_NOHW = 1 << 20,
Chia-I Wu3fb47ce2014-10-28 11:19:36 +080070 INTEL_DEBUG_NOCACHE = 1 << 21,
Chia-I Wuc45db532015-02-19 11:20:38 -070071 INTEL_DEBUG_NOHIZ = 1 << 22,
72 INTEL_DEBUG_HANG = 1 << 23,
Chia-I Wu1c527012014-08-23 14:57:35 +080073};
74
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060075struct intel_instance;
76
Chia-I Wu924c1fc2015-01-19 11:14:00 +080077struct intel_handle {
78 /* the loader expects a "void *" at the beginning */
79 void *loader_data;
80
81 uint32_t magic;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060082 const struct intel_instance *instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080083};
84
Chia-I Wu1c527012014-08-23 14:57:35 +080085extern int intel_debug;
86
Chia-I Wu924c1fc2015-01-19 11:14:00 +080087static const uint32_t intel_handle_magic = 0x494e544c;
88
89static inline void intel_handle_init(struct intel_handle *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -060090 VkDbgObjectType type,
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060091 const struct intel_instance *instance)
Chia-I Wu924c1fc2015-01-19 11:14:00 +080092{
Tony Barbourde4124d2015-07-03 10:33:54 -060093 set_loader_magic_value((void *)handle);
Chia-I Wu924c1fc2015-01-19 11:14:00 +080094
95 handle->magic = intel_handle_magic + type;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060096 handle->instance = instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080097}
98
99/**
100 * Return true if \p handle is a valid intel_handle. This assumes the first
101 * sizeof(intel_handle) bytes are readable, and they does not happen to have
102 * our magic values.
103 */
104static inline bool intel_handle_validate(const void *handle)
105{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600106// const uint32_t handle_type =
107// ((const struct intel_handle *) handle)->magic - intel_handle_magic;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800108
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600109 /* TODO: this does not work for extensions, needs adjusting */
110// return (handle_type <= VK_OBJECT_TYPE_END_RANGE);
111 return true;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800112}
113
114/**
115 * Return true if \p handle is a valid intel_handle of \p type.
116 *
117 * \see intel_handle_validate().
118 */
119static inline bool intel_handle_validate_type(const void *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -0600120 VkDbgObjectType type)
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800121{
122 const uint32_t handle_type =
123 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
124
125 return (handle_type == (uint32_t) type);
126}
127
Courtney Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600128void *intel_alloc(const void *handle,
129 size_t size, size_t alignment,
130 VkSystemAllocType type);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800131
Courtney Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600132void intel_free(const void *handle, void *ptr);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800133
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600134void intel_logv(const void *handle,
135 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600136 VkDbgObjectType obj_type, uint64_t src_object,
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600137 size_t location, int32_t msg_code,
138 const char *format, va_list ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800139
140static inline void intel_log(const void *handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600141 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600142 VkDbgObjectType obj_type, uint64_t src_object,
Chia-I Wu032a2e32015-01-19 11:14:00 +0800143 size_t location, int32_t msg_code,
144 const char *format, ...)
145{
146 va_list ap;
147
148 va_start(ap, format);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600149 intel_logv(handle, msg_flags, obj_type, src_object,
150 location, msg_code, format, ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800151 va_end(ap);
152}
153
Chia-I Wuc6fb9af2014-08-04 11:28:43 +0800154#endif /* INTEL_H */