Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 1 | /* |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | 8a17da5 | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 4 | * |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 22 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 24 | * Author: Chia-I Wu <olv@lunarg.com> |
| 25 | * Author: Jeremy Hayes <jeremy@lunarg.com> |
| 26 | * Author: Jon Ashburn <jon@lunarg.com> |
| 27 | * |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #ifndef INTEL_H |
| 31 | #define INTEL_H |
| 32 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 33 | #include <stdlib.h> |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 34 | #include <stdio.h> |
| 35 | #include <stdarg.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 36 | #include <stdbool.h> |
Chia-I Wu | aabb360 | 2014-08-19 14:18:23 +0800 | [diff] [blame] | 37 | #include <stdint.h> |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 38 | #include <string.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 39 | #include <assert.h> |
| 40 | |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 41 | #include <vulkan/vulkan.h> |
| 42 | #include <vulkan/vk_icd.h> |
David Pinedo | a31fe0b | 2015-11-24 09:00:24 -0700 | [diff] [blame] | 43 | #include <vulkan/vk_lunarg_debug_report.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 44 | |
| 45 | #include "icd.h" |
Cody Northrop | d4e020a | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 46 | #include "icd-spv.h" |
Chia-I Wu | 1bf06df | 2014-08-16 12:33:13 +0800 | [diff] [blame] | 47 | #include "icd-format.h" |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 48 | #include "icd-instance.h" |
Chia-I Wu | 69abeac | 2014-08-16 12:43:53 +0800 | [diff] [blame] | 49 | #include "icd-utils.h" |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 50 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 51 | #define INTEL_API_VERSION VK_API_VERSION |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 52 | #define INTEL_DRIVER_VERSION 0 |
| 53 | |
| 54 | #define INTEL_GEN(gen) ((int) ((gen) * 100)) |
| 55 | |
Chia-I Wu | 2469371 | 2014-11-08 11:54:47 +0800 | [diff] [blame] | 56 | #define INTEL_MAX_VERTEX_BINDING_COUNT 33 |
| 57 | #define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 58 | #define INTEL_MAX_RENDER_TARGETS 8 |
Chris Forbes | 948bf60 | 2015-05-08 11:01:16 +1200 | [diff] [blame] | 59 | #define INTEL_MAX_VIEWPORTS 16 |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 60 | |
Chia-I Wu | 27d8ed9 | 2015-10-27 18:53:22 +0800 | [diff] [blame] | 61 | #define INTEL_MEMORY_PROPERTY_ALL (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |\ |
| 62 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT) |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 63 | #define INTEL_MEMORY_HEAP_COUNT 1 |
| 64 | #define INTEL_MEMORY_HEAP_SIZE (2u << 30) |
| 65 | #define INTEL_MEMORY_TYPE_COUNT 1 |
Jeremy Hayes | d02809a | 2015-04-15 14:17:56 -0600 | [diff] [blame] | 66 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 67 | enum intel_debug_flags { |
| 68 | INTEL_DEBUG_BATCH = 1 << 0, |
Chia-I Wu | 93ada31 | 2014-08-23 15:02:25 +0800 | [diff] [blame] | 69 | |
| 70 | INTEL_DEBUG_NOHW = 1 << 20, |
Chia-I Wu | 3fb47ce | 2014-10-28 11:19:36 +0800 | [diff] [blame] | 71 | INTEL_DEBUG_NOCACHE = 1 << 21, |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 72 | INTEL_DEBUG_NOHIZ = 1 << 22, |
| 73 | INTEL_DEBUG_HANG = 1 << 23, |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 74 | }; |
| 75 | |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 76 | struct intel_instance; |
| 77 | |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 78 | struct intel_handle { |
| 79 | /* the loader expects a "void *" at the beginning */ |
| 80 | void *loader_data; |
| 81 | |
| 82 | uint32_t magic; |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 83 | const struct intel_instance *instance; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 84 | }; |
| 85 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 86 | extern int intel_debug; |
| 87 | |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 88 | static const uint32_t intel_handle_magic = 0x494e544c; |
| 89 | |
| 90 | static inline void intel_handle_init(struct intel_handle *handle, |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 91 | VkDbgObjectType type, |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 92 | const struct intel_instance *instance) |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 93 | { |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 94 | set_loader_magic_value((void *)handle); |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 95 | |
| 96 | handle->magic = intel_handle_magic + type; |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 97 | handle->instance = instance; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Return true if \p handle is a valid intel_handle. This assumes the first |
| 102 | * sizeof(intel_handle) bytes are readable, and they does not happen to have |
| 103 | * our magic values. |
| 104 | */ |
| 105 | static inline bool intel_handle_validate(const void *handle) |
| 106 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 107 | // const uint32_t handle_type = |
| 108 | // ((const struct intel_handle *) handle)->magic - intel_handle_magic; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 109 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 110 | /* TODO: this does not work for extensions, needs adjusting */ |
| 111 | // return (handle_type <= VK_OBJECT_TYPE_END_RANGE); |
| 112 | return true; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Return true if \p handle is a valid intel_handle of \p type. |
| 117 | * |
| 118 | * \see intel_handle_validate(). |
| 119 | */ |
| 120 | static inline bool intel_handle_validate_type(const void *handle, |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 121 | VkDbgObjectType type) |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 122 | { |
| 123 | const uint32_t handle_type = |
| 124 | ((const struct intel_handle *) handle)->magic - intel_handle_magic; |
| 125 | |
| 126 | return (handle_type == (uint32_t) type); |
| 127 | } |
| 128 | |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 129 | void *intel_alloc(const void *handle, |
| 130 | size_t size, size_t alignment, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 131 | VkSystemAllocationScope scope); |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 132 | |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 133 | void intel_free(const void *handle, void *ptr); |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 134 | |
Courtney Goeltzenleuchter | 434cf3f | 2015-06-09 08:13:49 -0600 | [diff] [blame] | 135 | void intel_logv(const void *handle, |
| 136 | VkFlags msg_flags, |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 137 | VkDbgObjectType obj_type, uint64_t src_object, |
Courtney Goeltzenleuchter | 434cf3f | 2015-06-09 08:13:49 -0600 | [diff] [blame] | 138 | size_t location, int32_t msg_code, |
| 139 | const char *format, va_list ap); |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 140 | |
| 141 | static inline void intel_log(const void *handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 142 | VkFlags msg_flags, |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 143 | VkDbgObjectType obj_type, uint64_t src_object, |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 144 | size_t location, int32_t msg_code, |
| 145 | const char *format, ...) |
| 146 | { |
| 147 | va_list ap; |
| 148 | |
| 149 | va_start(ap, format); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 150 | intel_logv(handle, msg_flags, obj_type, src_object, |
| 151 | location, msg_code, format, ap); |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 152 | va_end(ap); |
| 153 | } |
| 154 | |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 155 | #endif /* INTEL_H */ |