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