blob: b9c9f7bf1a54772e69b83a0846f171a0628d3fae [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 *
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060023 * 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 Wuc6fb9af2014-08-04 11:28:43 +080028 */
29
30#ifndef INTEL_H
31#define INTEL_H
32
Chia-I Wu214dac62014-08-05 11:07:40 +080033#include <stdlib.h>
Chia-I Wu032a2e32015-01-19 11:14:00 +080034#include <stdio.h>
35#include <stdarg.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080036#include <stdbool.h>
Chia-I Wuaabb3602014-08-19 14:18:23 +080037#include <stdint.h>
Chia-I Wu214dac62014-08-05 11:07:40 +080038#include <string.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080039#include <assert.h>
40
David Pinedo329ca9e2015-11-06 12:54:48 -070041#include <vulkan/vulkan.h>
42#include <vulkan/vk_icd.h>
David Pinedoa31fe0b2015-11-24 09:00:24 -070043#include <vulkan/vk_lunarg_debug_report.h>
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080044
45#include "icd.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060046#include "icd-spv.h"
Chia-I Wu1bf06df2014-08-16 12:33:13 +080047#include "icd-format.h"
Chia-I Wu96a41bc2015-02-21 14:19:23 +080048#include "icd-instance.h"
Chia-I Wu69abeac2014-08-16 12:43:53 +080049#include "icd-utils.h"
Chia-I Wuc6fb9af2014-08-04 11:28:43 +080050
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060051#define INTEL_API_VERSION VK_API_VERSION
Chia-I Wu214dac62014-08-05 11:07:40 +080052#define INTEL_DRIVER_VERSION 0
53
54#define INTEL_GEN(gen) ((int) ((gen) * 100))
55
Chia-I Wu24693712014-11-08 11:54:47 +080056#define INTEL_MAX_VERTEX_BINDING_COUNT 33
57#define INTEL_MAX_VERTEX_ELEMENT_COUNT (INTEL_MAX_VERTEX_BINDING_COUNT + 1)
Tony Barbourfa6cac72015-01-16 14:27:35 -070058#define INTEL_MAX_RENDER_TARGETS 8
Chris Forbes948bf602015-05-08 11:01:16 +120059#define INTEL_MAX_VIEWPORTS 16
Tony Barbourfa6cac72015-01-16 14:27:35 -070060
Chia-I Wu27d8ed92015-10-27 18:53:22 +080061#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 Lobodzinski72346292015-07-02 16:49:40 -060063#define INTEL_MEMORY_HEAP_COUNT 1
64#define INTEL_MEMORY_HEAP_SIZE (2u << 30)
65#define INTEL_MEMORY_TYPE_COUNT 1
Jeremy Hayesd02809a2015-04-15 14:17:56 -060066
Chia-I Wu1c527012014-08-23 14:57:35 +080067enum intel_debug_flags {
68 INTEL_DEBUG_BATCH = 1 << 0,
Chia-I Wu93ada312014-08-23 15:02:25 +080069
70 INTEL_DEBUG_NOHW = 1 << 20,
Chia-I Wu3fb47ce2014-10-28 11:19:36 +080071 INTEL_DEBUG_NOCACHE = 1 << 21,
Chia-I Wuc45db532015-02-19 11:20:38 -070072 INTEL_DEBUG_NOHIZ = 1 << 22,
73 INTEL_DEBUG_HANG = 1 << 23,
Chia-I Wu1c527012014-08-23 14:57:35 +080074};
75
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060076struct intel_instance;
77
Chia-I Wu924c1fc2015-01-19 11:14:00 +080078struct intel_handle {
79 /* the loader expects a "void *" at the beginning */
80 void *loader_data;
81
82 uint32_t magic;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060083 const struct intel_instance *instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080084};
85
Chia-I Wu1c527012014-08-23 14:57:35 +080086extern int intel_debug;
87
Chia-I Wu924c1fc2015-01-19 11:14:00 +080088static const uint32_t intel_handle_magic = 0x494e544c;
89
90static inline void intel_handle_init(struct intel_handle *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -060091 VkDbgObjectType type,
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060092 const struct intel_instance *instance)
Chia-I Wu924c1fc2015-01-19 11:14:00 +080093{
Tony Barbourde4124d2015-07-03 10:33:54 -060094 set_loader_magic_value((void *)handle);
Chia-I Wu924c1fc2015-01-19 11:14:00 +080095
96 handle->magic = intel_handle_magic + type;
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -060097 handle->instance = instance;
Chia-I Wu924c1fc2015-01-19 11:14:00 +080098}
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 */
105static inline bool intel_handle_validate(const void *handle)
106{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600107// const uint32_t handle_type =
108// ((const struct intel_handle *) handle)->magic - intel_handle_magic;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800109
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600110 /* TODO: this does not work for extensions, needs adjusting */
111// return (handle_type <= VK_OBJECT_TYPE_END_RANGE);
112 return true;
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800113}
114
115/**
116 * Return true if \p handle is a valid intel_handle of \p type.
117 *
118 * \see intel_handle_validate().
119 */
120static inline bool intel_handle_validate_type(const void *handle,
Tony Barbourde4124d2015-07-03 10:33:54 -0600121 VkDbgObjectType type)
Chia-I Wu924c1fc2015-01-19 11:14:00 +0800122{
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 Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600129void *intel_alloc(const void *handle,
130 size_t size, size_t alignment,
Chia-I Wu1f851912015-10-27 18:04:07 +0800131 VkSystemAllocationScope scope);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800132
Courtney Goeltzenleuchter33a54d52015-06-09 07:50:24 -0600133void intel_free(const void *handle, void *ptr);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800134
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600135void intel_logv(const void *handle,
136 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600137 VkDbgObjectType obj_type, uint64_t src_object,
Courtney Goeltzenleuchter434cf3f2015-06-09 08:13:49 -0600138 size_t location, int32_t msg_code,
139 const char *format, va_list ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800140
141static inline void intel_log(const void *handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600142 VkFlags msg_flags,
Tony Barbourde4124d2015-07-03 10:33:54 -0600143 VkDbgObjectType obj_type, uint64_t src_object,
Chia-I Wu032a2e32015-01-19 11:14:00 +0800144 size_t location, int32_t msg_code,
145 const char *format, ...)
146{
147 va_list ap;
148
149 va_start(ap, format);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600150 intel_logv(handle, msg_flags, obj_type, src_object,
151 location, msg_code, format, ap);
Chia-I Wu032a2e32015-01-19 11:14:00 +0800152 va_end(ap);
153}
154
Chia-I Wuc6fb9af2014-08-04 11:28:43 +0800155#endif /* INTEL_H */