blob: b716ee9577605b99eb7f9e2f9d8d67d2ef7a0440 [file] [log] [blame]
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08001/*
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08002 *
Courtney Goeltzenleuchter8a17da52015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Chia-I Wuc6fb9af2014-08-04 11:28:43 +08004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080022 *
23 * Authors:
24 * Chia-I Wu <olv@lunarg.com>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080025 */
26
27#ifndef INTEL_H
28#define INTEL_H
29
Chia-I Wu214dac62014-08-05 11:07:40 +080030#include <stdlib.h>
Chia-I Wu032a2e32015-01-19 11:14:00 +080031#include <stdio.h>
32#include <stdarg.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080033#include <stdbool.h>
Chia-I Wuaabb3602014-08-19 14:18:23 +080034#include <stdint.h>
Chia-I Wu214dac62014-08-05 11:07:40 +080035#include <string.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080036#include <assert.h>
37
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060038#include <vulkan.h>
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060039#include <vk_icd.h>
Tony Barbourde4124d2015-07-03 10:33:54 -060040#include <vk_debug_report_lunarg.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080041
42#include "icd.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060043#include "icd-spv.h"
Chia-I Wu1bf06df2014-08-16 12:33:13 +080044#include "icd-format.h"
Chia-I Wu96a41bc2015-02-21 14:19:23 +080045#include "icd-instance.h"
Chia-I Wu69abeac2014-08-16 12:43:53 +080046#include "icd-utils.h"
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080047
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060048#define INTEL_API_VERSION VK_API_VERSION
Chia-I Wu214dac62014-08-05 11:07:40 +080049#define INTEL_DRIVER_VERSION 0
50
51#define INTEL_GEN(gen) ((int) ((gen) * 100))
52
Chia-I Wu24693712014-11-08 11:54:47 +080053#define INTEL_MAX_VERTEX_BINDING_COUNT 33
54#define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1)
Tony Barbourfa6cac72015-01-16 14:27:35 -070055#define INTEL_MAX_RENDER_TARGETS 8
Chris Forbes948bf602015-05-08 11:01:16 +120056#define INTEL_MAX_VIEWPORTS 16
Tony Barbourfa6cac72015-01-16 14:27:35 -070057
Chia-I Wu27d8ed92015-10-27 18:53:22 +080058#define INTEL_MEMORY_PROPERTY_ALL (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |\
59 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
Mark Lobodzinski72346292015-07-02 16:49:40 -060060#define INTEL_MEMORY_HEAP_COUNT 1
61#define INTEL_MEMORY_HEAP_SIZE (2u << 30)
62#define INTEL_MEMORY_TYPE_COUNT 1
Jeremy Hayesd02809a2015-04-15 14:17:56 -060063
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
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060073struct intel_instance;
74
Chia-I Wu924c1fc2015-01-19 11:14:00 +080075struct intel_handle {
76 /* the loader expects a "void *" at the beginning */
77 void *loader_data;
78
79 uint32_t magic;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060080 const struct intel_instance *instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080081};
82
Chia-I Wu1c527012014-08-23 14:57:35 +080083extern int intel_debug;
84
Chia-I Wu924c1fc2015-01-19 11:14:00 +080085static const uint32_t intel_handle_magic = 0x494e544c;
86
87static inline void intel_handle_init(struct intel_handle *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -060088 VkDbgObjectType type,
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060089 const struct intel_instance *instance)
Chia-I Wu924c1fc2015-01-19 11:14:00 +080090{
Tony Barbourde4124d2015-07-03 10:33:54 -060091 set_loader_magic_value((void *)handle);
Chia-I Wu924c1fc2015-01-19 11:14:00 +080092
93 handle->magic = intel_handle_magic + type;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060094 handle->instance = instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080095}
96
97/**
98 * Return true if \p handle is a valid intel_handle. This assumes the first
99 * sizeof(intel_handle) bytes are readable, and they does not happen to have
100 * our magic values.
101 */
102static inline bool intel_handle_validate(const void *handle)
103{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600104// const uint32_t handle_type =
105// ((const struct intel_handle *) handle)->magic - intel_handle_magic;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800106
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600107 /* TODO: this does not work for extensions, needs adjusting */
108// return (handle_type <= VK_OBJECT_TYPE_END_RANGE);
109 return true;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800110}
111
112/**
113 * Return true if \p handle is a valid intel_handle of \p type.
114 *
115 * \see intel_handle_validate().
116 */
117static inline bool intel_handle_validate_type(const void *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -0600118 VkDbgObjectType type)
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800119{
120 const uint32_t handle_type =
121 ((const struct intel_handle *) handle)->magic - intel_handle_magic;
122
123 return (handle_type == (uint32_t) type);
124}
125
Courtney Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600126void *intel_alloc(const void *handle,
127 size_t size, size_t alignment,
Chia-I Wu1f851912015-10-27 18:04:07 +0800128 VkSystemAllocationScope scope);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800129
Courtney Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600130void intel_free(const void *handle, void *ptr);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800131
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600132void intel_logv(const void *handle,
133 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600134 VkDbgObjectType obj_type, uint64_t src_object,
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600135 size_t location, int32_t msg_code,
136 const char *format, va_list ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800137
138static inline void intel_log(const void *handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600139 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600140 VkDbgObjectType obj_type, uint64_t src_object,
Chia-I Wu032a2e32015-01-19 11:14:00 +0800141 size_t location, int32_t msg_code,
142 const char *format, ...)
143{
144 va_list ap;
145
146 va_start(ap, format);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600147 intel_logv(handle, msg_flags, obj_type, src_object,
148 location, msg_code, format, ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800149 va_end(ap);
150}
151
Chia-I Wuc6fb9af2014-08-04 11:28:43 +0800152#endif /* INTEL_H */