Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 2 | * Vulkan |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef INTEL_H |
| 29 | #define INTEL_H |
| 30 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 31 | #include <stdlib.h> |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <stdarg.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 34 | #include <stdbool.h> |
Chia-I Wu | aabb360 | 2014-08-19 14:18:23 +0800 | [diff] [blame] | 35 | #include <stdint.h> |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 36 | #include <string.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 37 | #include <assert.h> |
| 38 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 39 | #include <vulkan.h> |
| 40 | #include <vkDbg.h> |
| 41 | #include <vkWsiX11Ext.h> |
| 42 | #include <vkIcd.h> |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 43 | |
| 44 | #include "icd.h" |
Cody Northrop | d4e020a | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 45 | #include "icd-spv.h" |
Chia-I Wu | 1bf06df | 2014-08-16 12:33:13 +0800 | [diff] [blame] | 46 | #include "icd-format.h" |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 47 | #include "icd-instance.h" |
Chia-I Wu | 69abeac | 2014-08-16 12:43:53 +0800 | [diff] [blame] | 48 | #include "icd-utils.h" |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 49 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 50 | #define INTEL_API_VERSION VK_API_VERSION |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 51 | #define INTEL_DRIVER_VERSION 0 |
| 52 | |
| 53 | #define INTEL_GEN(gen) ((int) ((gen) * 100)) |
| 54 | |
Chia-I Wu | 2469371 | 2014-11-08 11:54:47 +0800 | [diff] [blame] | 55 | #define INTEL_MAX_VERTEX_BINDING_COUNT 33 |
| 56 | #define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 57 | #define INTEL_MAX_RENDER_TARGETS 8 |
| 58 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 59 | enum intel_debug_flags { |
| 60 | INTEL_DEBUG_BATCH = 1 << 0, |
Chia-I Wu | 93ada31 | 2014-08-23 15:02:25 +0800 | [diff] [blame] | 61 | |
| 62 | INTEL_DEBUG_NOHW = 1 << 20, |
Chia-I Wu | 3fb47ce | 2014-10-28 11:19:36 +0800 | [diff] [blame] | 63 | INTEL_DEBUG_NOCACHE = 1 << 21, |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 64 | INTEL_DEBUG_NOHIZ = 1 << 22, |
| 65 | INTEL_DEBUG_HANG = 1 << 23, |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 66 | }; |
| 67 | |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 68 | struct intel_handle { |
| 69 | /* the loader expects a "void *" at the beginning */ |
| 70 | void *loader_data; |
| 71 | |
| 72 | uint32_t magic; |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 73 | const struct icd_instance *icd; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 74 | }; |
| 75 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 76 | extern int intel_debug; |
| 77 | |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 78 | static const uint32_t intel_handle_magic = 0x494e544c; |
| 79 | |
| 80 | static inline void intel_handle_init(struct intel_handle *handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 81 | VK_DBG_OBJECT_TYPE type, |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 82 | const struct icd_instance *icd) |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 83 | { |
| 84 | set_loader_magic_value(handle); |
| 85 | |
| 86 | handle->magic = intel_handle_magic + type; |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 87 | handle->icd = icd; |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Return true if \p handle is a valid intel_handle. This assumes the first |
| 92 | * sizeof(intel_handle) bytes are readable, and they does not happen to have |
| 93 | * our magic values. |
| 94 | */ |
| 95 | static inline bool intel_handle_validate(const void *handle) |
| 96 | { |
| 97 | const uint32_t handle_type = |
| 98 | ((const struct intel_handle *) handle)->magic - intel_handle_magic; |
| 99 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 100 | return (handle_type <= VK_DBG_OBJECT_TYPE_END_RANGE); |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Return true if \p handle is a valid intel_handle of \p type. |
| 105 | * |
| 106 | * \see intel_handle_validate(). |
| 107 | */ |
| 108 | static inline bool intel_handle_validate_type(const void *handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 109 | VK_DBG_OBJECT_TYPE type) |
Chia-I Wu | 924c1fc | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 110 | { |
| 111 | const uint32_t handle_type = |
| 112 | ((const struct intel_handle *) handle)->magic - intel_handle_magic; |
| 113 | |
| 114 | return (handle_type == (uint32_t) type); |
| 115 | } |
| 116 | |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 117 | static inline void *intel_alloc(const void *handle, |
| 118 | size_t size, size_t alignment, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 119 | VK_SYSTEM_ALLOC_TYPE type) |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 120 | { |
| 121 | assert(intel_handle_validate(handle)); |
| 122 | return icd_instance_alloc(((const struct intel_handle *) handle)->icd, |
| 123 | size, alignment, type); |
| 124 | } |
| 125 | |
| 126 | static inline void intel_free(const void *handle, void *ptr) |
| 127 | { |
| 128 | assert(intel_handle_validate(handle)); |
| 129 | icd_instance_free(((const struct intel_handle *) handle)->icd, ptr); |
| 130 | } |
| 131 | |
| 132 | static inline void intel_logv(const void *handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 133 | VK_DBG_MSG_TYPE msg_type, |
| 134 | VK_VALIDATION_LEVEL validation_level, |
| 135 | VK_BASE_OBJECT src_object, |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 136 | size_t location, int32_t msg_code, |
| 137 | const char *format, va_list ap) |
| 138 | { |
| 139 | char msg[256]; |
| 140 | int ret; |
| 141 | |
| 142 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
| 143 | if (ret >= sizeof(msg) || ret < 0) |
| 144 | msg[sizeof(msg) - 1] = '\0'; |
| 145 | |
| 146 | assert(intel_handle_validate(handle)); |
| 147 | icd_instance_log(((const struct intel_handle *) handle)->icd, |
| 148 | msg_type, validation_level, src_object, location, msg_code, msg); |
| 149 | } |
| 150 | |
| 151 | static inline void intel_log(const void *handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 152 | VK_DBG_MSG_TYPE msg_type, |
| 153 | VK_VALIDATION_LEVEL validation_level, |
| 154 | VK_BASE_OBJECT src_object, |
Chia-I Wu | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 155 | size_t location, int32_t msg_code, |
| 156 | const char *format, ...) |
| 157 | { |
| 158 | va_list ap; |
| 159 | |
| 160 | va_start(ap, format); |
| 161 | intel_logv(handle, msg_type, validation_level, src_object, |
| 162 | location, msg_code, format, ap); |
| 163 | va_end(ap); |
| 164 | } |
| 165 | |
Chia-I Wu | c6fb9af | 2014-08-04 11:28:43 +0800 | [diff] [blame] | 166 | #endif /* INTEL_H */ |