blob: 81f1430aaceea4e2933d4f8af23d48fcd29b3679 [file] [log] [blame]
Chia-I Wu214dac62014-08-05 11:07:40 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu214dac62014-08-05 11:07:40 +08003 *
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 Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu214dac62014-08-05 11:07:40 +080026 */
27
28#include <stdio.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <fcntl.h>
32#include <unistd.h>
33
34#include "genhw/genhw.h"
Chia-I Wud8965932014-10-13 13:32:37 +080035#include "kmd/winsys.h"
Chia-I Wuec841722014-08-25 22:36:01 +080036#include "queue.h"
Chia-I Wu214dac62014-08-05 11:07:40 +080037#include "gpu.h"
Chia-I Wu032a2e32015-01-19 11:14:00 +080038#include "instance.h"
Chia-I Wu41858c82015-04-04 16:39:25 +080039#include "wsi.h"
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060040#include "vk_debug_report_lunarg.h"
41#include "vk_debug_marker_lunarg.h"
Chia-I Wu1db76e02014-09-15 14:21:14 +080042
Chia-I Wuf07865e2014-09-15 13:52:21 +080043static int gpu_open_primary_node(struct intel_gpu *gpu)
44{
Chia-I Wu41858c82015-04-04 16:39:25 +080045 if (gpu->primary_fd_internal < 0)
46 gpu->primary_fd_internal = open(gpu->primary_node, O_RDWR);
47
Chia-I Wuf07865e2014-09-15 13:52:21 +080048 return gpu->primary_fd_internal;
49}
50
51static void gpu_close_primary_node(struct intel_gpu *gpu)
52{
Chia-I Wu41858c82015-04-04 16:39:25 +080053 if (gpu->primary_fd_internal >= 0) {
54 close(gpu->primary_fd_internal);
Chia-I Wuf07865e2014-09-15 13:52:21 +080055 gpu->primary_fd_internal = -1;
Chia-I Wu41858c82015-04-04 16:39:25 +080056 }
Chia-I Wuf07865e2014-09-15 13:52:21 +080057}
58
59static int gpu_open_render_node(struct intel_gpu *gpu)
60{
61 if (gpu->render_fd_internal < 0 && gpu->render_node) {
62 gpu->render_fd_internal = open(gpu->render_node, O_RDWR);
63 if (gpu->render_fd_internal < 0) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060064 intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0, VK_NULL_HANDLE, 0,
Chia-I Wuf07865e2014-09-15 13:52:21 +080065 0, "failed to open %s", gpu->render_node);
66 }
67 }
68
69 return gpu->render_fd_internal;
70}
71
72static void gpu_close_render_node(struct intel_gpu *gpu)
73{
74 if (gpu->render_fd_internal >= 0) {
75 close(gpu->render_fd_internal);
76 gpu->render_fd_internal = -1;
77 }
78}
79
Chia-I Wu214dac62014-08-05 11:07:40 +080080static const char *gpu_get_name(const struct intel_gpu *gpu)
81{
82 const char *name = NULL;
83
84 if (gen_is_hsw(gpu->devid)) {
85 if (gen_is_desktop(gpu->devid))
86 name = "Intel(R) Haswell Desktop";
87 else if (gen_is_mobile(gpu->devid))
88 name = "Intel(R) Haswell Mobile";
89 else if (gen_is_server(gpu->devid))
90 name = "Intel(R) Haswell Server";
91 }
92 else if (gen_is_ivb(gpu->devid)) {
93 if (gen_is_desktop(gpu->devid))
94 name = "Intel(R) Ivybridge Desktop";
95 else if (gen_is_mobile(gpu->devid))
96 name = "Intel(R) Ivybridge Mobile";
97 else if (gen_is_server(gpu->devid))
98 name = "Intel(R) Ivybridge Server";
99 }
100 else if (gen_is_snb(gpu->devid)) {
101 if (gen_is_desktop(gpu->devid))
102 name = "Intel(R) Sandybridge Desktop";
103 else if (gen_is_mobile(gpu->devid))
104 name = "Intel(R) Sandybridge Mobile";
105 else if (gen_is_server(gpu->devid))
106 name = "Intel(R) Sandybridge Server";
107 }
108
109 if (!name)
110 name = "Unknown Intel Chipset";
111
112 return name;
113}
114
Chia-I Wud71ff552015-02-20 12:50:12 -0700115void intel_gpu_destroy(struct intel_gpu *gpu)
Chia-I Wu214dac62014-08-05 11:07:40 +0800116{
Chia-I Wu8635e912015-04-09 14:13:57 +0800117 intel_wsi_gpu_cleanup(gpu);
Chia-I Wud71ff552015-02-20 12:50:12 -0700118
Chia-I Wu41858c82015-04-04 16:39:25 +0800119 intel_gpu_cleanup_winsys(gpu);
Chia-I Wud71ff552015-02-20 12:50:12 -0700120
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800121 intel_free(gpu, gpu->primary_node);
122 intel_free(gpu, gpu);
Chia-I Wud71ff552015-02-20 12:50:12 -0700123}
124
125static int devid_to_gen(int devid)
126{
127 int gen;
128
129 if (gen_is_hsw(devid))
130 gen = INTEL_GEN(7.5);
131 else if (gen_is_ivb(devid))
132 gen = INTEL_GEN(7);
133 else if (gen_is_snb(devid))
134 gen = INTEL_GEN(6);
135 else
136 gen = -1;
137
138#ifdef INTEL_GEN_SPECIALIZED
139 if (gen != INTEL_GEN(INTEL_GEN_SPECIALIZED))
140 gen = -1;
141#endif
142
143 return gen;
144}
145
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600146VkResult intel_gpu_create(const struct intel_instance *instance, int devid,
Chia-I Wud71ff552015-02-20 12:50:12 -0700147 const char *primary_node, const char *render_node,
148 struct intel_gpu **gpu_ret)
149{
150 const int gen = devid_to_gen(devid);
Chia-I Wuf07865e2014-09-15 13:52:21 +0800151 size_t primary_len, render_len;
Chia-I Wud71ff552015-02-20 12:50:12 -0700152 struct intel_gpu *gpu;
153
154 if (gen < 0) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600155 intel_log(instance, VK_DBG_REPORT_WARN_BIT, 0,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156 VK_NULL_HANDLE, 0, 0, "unsupported device id 0x%04x", devid);
157 return VK_ERROR_INITIALIZATION_FAILED;
Chia-I Wud71ff552015-02-20 12:50:12 -0700158 }
Chia-I Wu214dac62014-08-05 11:07:40 +0800159
Tony Barbour8205d902015-04-16 15:59:00 -0600160 gpu = intel_alloc(instance, sizeof(*gpu), 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
Chia-I Wu214dac62014-08-05 11:07:40 +0800161 if (!gpu)
Tony Barbour8205d902015-04-16 15:59:00 -0600162 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu214dac62014-08-05 11:07:40 +0800163
164 memset(gpu, 0, sizeof(*gpu));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600165 /* there is no VK_DBG_OBJECT_GPU */
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -0600166 intel_handle_init(&gpu->handle, VK_OBJECT_TYPE_PHYSICAL_DEVICE, instance);
Chia-I Wu214dac62014-08-05 11:07:40 +0800167
Chia-I Wu214dac62014-08-05 11:07:40 +0800168 gpu->devid = devid;
169
Chia-I Wuf07865e2014-09-15 13:52:21 +0800170 primary_len = strlen(primary_node);
171 render_len = (render_node) ? strlen(render_node) : 0;
172
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800173 gpu->primary_node = intel_alloc(gpu, primary_len + 1 +
Tony Barbour8205d902015-04-16 15:59:00 -0600174 ((render_len) ? (render_len + 1) : 0), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wuf07865e2014-09-15 13:52:21 +0800175 if (!gpu->primary_node) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800176 intel_free(instance, gpu);
Tony Barbour8205d902015-04-16 15:59:00 -0600177 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu214dac62014-08-05 11:07:40 +0800178 }
Chia-I Wuf07865e2014-09-15 13:52:21 +0800179
180 memcpy(gpu->primary_node, primary_node, primary_len + 1);
181
182 if (render_node) {
183 gpu->render_node = gpu->primary_node + primary_len + 1;
184 memcpy(gpu->render_node, render_node, render_len + 1);
BogDan Vatra80f80612015-04-30 19:28:26 +0300185 } else {
186 gpu->render_node = gpu->primary_node;
Chia-I Wuf07865e2014-09-15 13:52:21 +0800187 }
Chia-I Wu214dac62014-08-05 11:07:40 +0800188
189 gpu->gen_opaque = gen;
190
Chia-I Wu960f1952014-08-28 23:27:10 +0800191 switch (intel_gpu_gen(gpu)) {
192 case INTEL_GEN(7.5):
193 gpu->gt = gen_get_hsw_gt(devid);
194 break;
195 case INTEL_GEN(7):
196 gpu->gt = gen_get_ivb_gt(devid);
197 break;
198 case INTEL_GEN(6):
199 gpu->gt = gen_get_snb_gt(devid);
200 break;
201 }
202
Mike Stroyan9fca7122015-02-09 13:08:26 -0700203 /* 150K dwords */
204 gpu->max_batch_buffer_size = sizeof(uint32_t) * 150*1024;
Chia-I Wud6109bb2014-08-21 09:12:19 +0800205
206 /* the winsys is prepared for one reloc every two dwords, then minus 2 */
207 gpu->batch_buffer_reloc_count =
208 gpu->max_batch_buffer_size / sizeof(uint32_t) / 2 - 2;
Chia-I Wu214dac62014-08-05 11:07:40 +0800209
Chia-I Wuf07865e2014-09-15 13:52:21 +0800210 gpu->primary_fd_internal = -1;
211 gpu->render_fd_internal = -1;
212
Chia-I Wu214dac62014-08-05 11:07:40 +0800213 *gpu_ret = gpu;
214
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215 return VK_SUCCESS;
Chia-I Wu214dac62014-08-05 11:07:40 +0800216}
217
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600218void intel_gpu_get_limits(VkPhysicalDeviceLimits *pLimits)
219{
220 // TODO: fill out more limits
221 memset(pLimits, 0, sizeof(*pLimits));
222
223 // no size limit, but no bounded buffer could exceed 2GB
224 pLimits->maxBoundDescriptorSets = 1;
225 pLimits->maxComputeWorkGroupInvocations = 512;
226
227 // incremented every 80ns
228 pLimits->timestampFrequency = 1000 * 1000 * 1000 / 80;
229
230 // hardware is limited to 16 viewports
231 pLimits->maxViewports = INTEL_MAX_VIEWPORTS;
232 pLimits->maxColorAttachments = INTEL_MAX_RENDER_TARGETS;
233
234 // ?
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600235 pLimits->maxImageDimension1D = 8192;
236 pLimits->maxImageDimension2D = 8192;
237 pLimits->maxImageDimension3D = 8192;
238 pLimits->maxImageDimensionCube = 8192;
239 pLimits->maxImageArrayLayers = 2048;
240 pLimits->maxTexelBufferSize = 128 * 1024 * 1024; // 128M texels hard limit
Courtney Goeltzenleuchterd6633e22015-10-22 15:47:21 -0600241 pLimits->maxUniformBufferRange = 64 * 1024; // not hard limit
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600242
243 /* HW has two per-stage resource tables:
244 * - samplers, 16 per stage on IVB; blocks of 16 on HSW+ via shader hack, as the
245 * table base ptr used by the sampler hw is under shader sw control.
246 *
247 * - binding table entries, 250 total on all gens, shared between
248 * textures, RT, images, SSBO, UBO, ...
249 * the top few indices (250-255) are used for 'stateless' access with various cache
250 * options, and for SLM access.
251 */
252 pLimits->maxPerStageDescriptorSamplers = 16; // technically more on HSW+..
253 pLimits->maxDescriptorSetSamplers = 16;
254
255 pLimits->maxPerStageDescriptorUniformBuffers = 128;
256 pLimits->maxDescriptorSetUniformBuffers = 128;
257
258 pLimits->maxPerStageDescriptorSampledImages = 128;
259 pLimits->maxDescriptorSetSampledImages = 128;
260
261 // storage images and buffers not implemented; left at zero
Courtney Goeltzenleuchterd3a8d362015-10-23 10:37:02 -0600262
263 // required to support at least two queue priorities
264 pLimits->discreteQueuePriorities = 2;
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600265}
266
Chia-I Wu214dac62014-08-05 11:07:40 +0800267void intel_gpu_get_props(const struct intel_gpu *gpu,
Tony Barbour8205d902015-04-16 15:59:00 -0600268 VkPhysicalDeviceProperties *props)
Chia-I Wu214dac62014-08-05 11:07:40 +0800269{
270 const char *name;
271 size_t name_len;
272
Chia-I Wu214dac62014-08-05 11:07:40 +0800273 props->apiVersion = INTEL_API_VERSION;
274 props->driverVersion = INTEL_DRIVER_VERSION;
275
276 props->vendorId = 0x8086;
277 props->deviceId = gpu->devid;
278
Tony Barbour8205d902015-04-16 15:59:00 -0600279 props->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
Chia-I Wu214dac62014-08-05 11:07:40 +0800280
281 /* copy GPU name */
282 name = gpu_get_name(gpu);
283 name_len = strlen(name);
Tony Barbour8205d902015-04-16 15:59:00 -0600284 if (name_len > sizeof(props->deviceName) - 1)
285 name_len = sizeof(props->deviceName) - 1;
286 memcpy(props->deviceName, name, name_len);
287 props->deviceName[name_len] = '\0';
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600288
289 intel_gpu_get_limits(&props->limits);
290
291 intel_gpu_get_sparse_properties(&props->sparseProperties);
Chia-I Wu214dac62014-08-05 11:07:40 +0800292}
293
Chia-I Wu214dac62014-08-05 11:07:40 +0800294void intel_gpu_get_queue_props(const struct intel_gpu *gpu,
295 enum intel_gpu_engine_type engine,
Cody Northropef72e2a2015-08-03 17:04:53 -0600296 VkQueueFamilyProperties *props)
Chia-I Wu214dac62014-08-05 11:07:40 +0800297{
Chia-I Wu214dac62014-08-05 11:07:40 +0800298 switch (engine) {
299 case INTEL_GPU_ENGINE_3D:
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500300 props->queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
Chia-I Wu214dac62014-08-05 11:07:40 +0800301 props->queueCount = 1;
Courtney Goeltzenleuchter68535a62015-10-19 16:03:32 -0600302 props->timestampValidBits = 0;
Chia-I Wu214dac62014-08-05 11:07:40 +0800303 break;
304 default:
305 assert(!"unknown engine type");
306 return;
307 }
308}
309
310void intel_gpu_get_memory_props(const struct intel_gpu *gpu,
Tony Barbour8205d902015-04-16 15:59:00 -0600311 VkPhysicalDeviceMemoryProperties *props)
Chia-I Wu214dac62014-08-05 11:07:40 +0800312{
Mark Lobodzinski72346292015-07-02 16:49:40 -0600313 memset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties));
314 props->memoryTypeCount = INTEL_MEMORY_TYPE_COUNT;
315 props->memoryHeapCount = INTEL_MEMORY_HEAP_COUNT;
316
317 // For now, Intel will support one memory type
318 for (uint32_t i = 0; i < props->memoryTypeCount; i++) {
319 assert(props->memoryTypeCount == 1);
320 props->memoryTypes[i].propertyFlags = INTEL_MEMORY_PROPERTY_ALL;
321 props->memoryTypes[i].heapIndex = i;
322 }
323
324 // For now, Intel will support a single heap with all available memory
325 for (uint32_t i = 0; i < props->memoryHeapCount; i++) {
326 assert(props->memoryHeapCount == 1);
327 props->memoryHeaps[0].size = INTEL_MEMORY_HEAP_SIZE;
328 }
Chia-I Wu214dac62014-08-05 11:07:40 +0800329}
330
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800331int intel_gpu_get_max_threads(const struct intel_gpu *gpu,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600332 VkShaderStageFlagBits stage)
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800333{
334 switch (intel_gpu_gen(gpu)) {
335 case INTEL_GEN(7.5):
336 switch (stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600337 case VK_SHADER_STAGE_VERTEX_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800338 return (gpu->gt >= 2) ? 280 : 70;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600339 case VK_SHADER_STAGE_GEOMETRY_BIT:
Cody Northrop293d4502015-05-05 09:38:03 -0600340 /* values from ilo_gpe_init_gs_cso_gen7 */
341 return (gpu->gt >= 2) ? 256 : 70;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600342 case VK_SHADER_STAGE_FRAGMENT_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800343 return (gpu->gt == 3) ? 408 :
344 (gpu->gt == 2) ? 204 : 102;
345 default:
346 break;
347 }
348 break;
349 case INTEL_GEN(7):
350 switch (stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600351 case VK_SHADER_STAGE_VERTEX_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800352 return (gpu->gt == 2) ? 128 : 36;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600353 case VK_SHADER_STAGE_GEOMETRY_BIT:
Cody Northrop293d4502015-05-05 09:38:03 -0600354 /* values from ilo_gpe_init_gs_cso_gen7 */
355 return (gpu->gt == 2) ? 128 : 36;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600356 case VK_SHADER_STAGE_FRAGMENT_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800357 return (gpu->gt == 2) ? 172 : 48;
358 default:
359 break;
360 }
361 break;
362 case INTEL_GEN(6):
363 switch (stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600364 case VK_SHADER_STAGE_VERTEX_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800365 return (gpu->gt == 2) ? 60 : 24;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600366 case VK_SHADER_STAGE_GEOMETRY_BIT:
Cody Northrop293d4502015-05-05 09:38:03 -0600367 /* values from ilo_gpe_init_gs_cso_gen6 */
368 return (gpu->gt == 2) ? 28 : 21;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600369 case VK_SHADER_STAGE_FRAGMENT_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800370 return (gpu->gt == 2) ? 80 : 40;
371 default:
372 break;
373 }
374 break;
375 default:
376 break;
377 }
378
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600379 intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0, VK_NULL_HANDLE,
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800380 0, 0, "unknown Gen or shader stage");
381
382 switch (stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600383 case VK_SHADER_STAGE_VERTEX_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800384 return 1;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600385 case VK_SHADER_STAGE_GEOMETRY_BIT:
Cody Northrop293d4502015-05-05 09:38:03 -0600386 return 1;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600387 case VK_SHADER_STAGE_FRAGMENT_BIT:
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800388 return 4;
389 default:
390 return 1;
391 }
392}
393
Chia-I Wu41858c82015-04-04 16:39:25 +0800394int intel_gpu_get_primary_fd(struct intel_gpu *gpu)
Chia-I Wu1db76e02014-09-15 14:21:14 +0800395{
Chia-I Wu41858c82015-04-04 16:39:25 +0800396 return gpu_open_primary_node(gpu);
Chia-I Wu1db76e02014-09-15 14:21:14 +0800397}
398
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600399VkResult intel_gpu_init_winsys(struct intel_gpu *gpu)
Chia-I Wu214dac62014-08-05 11:07:40 +0800400{
Chia-I Wud8965932014-10-13 13:32:37 +0800401 int fd;
Chia-I Wu214dac62014-08-05 11:07:40 +0800402
Chia-I Wud8965932014-10-13 13:32:37 +0800403 assert(!gpu->winsys);
404
Chia-I Wu41858c82015-04-04 16:39:25 +0800405 fd = gpu_open_render_node(gpu);
Chia-I Wud8965932014-10-13 13:32:37 +0800406 if (fd < 0)
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600407 return VK_ERROR_INITIALIZATION_FAILED;
Chia-I Wud8965932014-10-13 13:32:37 +0800408
Courtney Goeltzenleuchter9ecf6852015-06-09 08:22:48 -0600409 gpu->winsys = intel_winsys_create_for_fd(gpu->handle.instance->icd, fd);
Chia-I Wud8965932014-10-13 13:32:37 +0800410 if (!gpu->winsys) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600411 intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412 VK_NULL_HANDLE, 0, 0, "failed to create GPU winsys");
Chia-I Wu41858c82015-04-04 16:39:25 +0800413 gpu_close_render_node(gpu);
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600414 return VK_ERROR_INITIALIZATION_FAILED;
Chia-I Wud8965932014-10-13 13:32:37 +0800415 }
416
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 return VK_SUCCESS;
Chia-I Wu214dac62014-08-05 11:07:40 +0800418}
419
Chia-I Wu41858c82015-04-04 16:39:25 +0800420void intel_gpu_cleanup_winsys(struct intel_gpu *gpu)
Chia-I Wu214dac62014-08-05 11:07:40 +0800421{
Chia-I Wud8965932014-10-13 13:32:37 +0800422 if (gpu->winsys) {
423 intel_winsys_destroy(gpu->winsys);
424 gpu->winsys = NULL;
425 }
426
Chia-I Wuf07865e2014-09-15 13:52:21 +0800427 gpu_close_primary_node(gpu);
428 gpu_close_render_node(gpu);
Chia-I Wu214dac62014-08-05 11:07:40 +0800429}
430
Courtney Goeltzenleuchter95b73722015-06-08 18:08:35 -0600431enum intel_phy_dev_ext_type intel_gpu_lookup_phy_dev_extension(
432 const struct intel_gpu *gpu,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600433 const char *ext)
Chia-I Wu214dac62014-08-05 11:07:40 +0800434{
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600435 uint32_t type;
436 uint32_t array_size = ARRAY_SIZE(intel_phy_dev_gpu_exts);
Chia-I Wu1db76e02014-09-15 14:21:14 +0800437
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600438 for (type = 0; type < array_size; type++) {
Courtney Goeltzenleuchter95b73722015-06-08 18:08:35 -0600439 if (compare_vk_extension_properties(&intel_phy_dev_gpu_exts[type], ext))
Chia-I Wu1db76e02014-09-15 14:21:14 +0800440 break;
441 }
442
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600443 assert(type < array_size || type == INTEL_PHY_DEV_EXT_INVALID);
Chia-I Wu1db76e02014-09-15 14:21:14 +0800444
445 return type;
Chia-I Wu214dac62014-08-05 11:07:40 +0800446}
Chia-I Wubec90a02014-08-06 12:33:03 +0800447
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600448ICD_EXPORT void VKAPI vkGetPhysicalDeviceProperties(
Tony Barbour426b9052015-06-24 16:06:58 -0600449 VkPhysicalDevice gpu_,
450 VkPhysicalDeviceProperties* pProperties)
Chia-I Wubec90a02014-08-06 12:33:03 +0800451{
Chia-I Wu41858c82015-04-04 16:39:25 +0800452 struct intel_gpu *gpu = intel_gpu(gpu_);
Chia-I Wubec90a02014-08-06 12:33:03 +0800453
Tony Barbour426b9052015-06-24 16:06:58 -0600454 intel_gpu_get_props(gpu, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -0600455}
Chia-I Wubec90a02014-08-06 12:33:03 +0800456
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600457ICD_EXPORT void VKAPI vkGetPhysicalDeviceQueueFamilyProperties(
Tony Barbour426b9052015-06-24 16:06:58 -0600458 VkPhysicalDevice gpu_,
Cody Northropef72e2a2015-08-03 17:04:53 -0600459 uint32_t* pCount,
460 VkQueueFamilyProperties* pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -0600461{
462 struct intel_gpu *gpu = intel_gpu(gpu_);
463 int engine;
464
Cody Northropef72e2a2015-08-03 17:04:53 -0600465 if (pProperties == NULL) {
466 *pCount = INTEL_GPU_ENGINE_COUNT;
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600467 return;
Cody Northropef72e2a2015-08-03 17:04:53 -0600468 }
469
Cody Northropef72e2a2015-08-03 17:04:53 -0600470 for (engine = 0; engine < *pCount; engine++) {
Tony Barbour426b9052015-06-24 16:06:58 -0600471 intel_gpu_get_queue_props(gpu, engine, pProperties);
472 pProperties++;
473 }
Tony Barbour426b9052015-06-24 16:06:58 -0600474}
475
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600476ICD_EXPORT void VKAPI vkGetPhysicalDeviceMemoryProperties(
Tony Barbour426b9052015-06-24 16:06:58 -0600477 VkPhysicalDevice gpu_,
478 VkPhysicalDeviceMemoryProperties* pProperties)
479{
480 struct intel_gpu *gpu = intel_gpu(gpu_);
481
482 intel_gpu_get_memory_props(gpu, pProperties);
Chia-I Wubec90a02014-08-06 12:33:03 +0800483}
484
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600485ICD_EXPORT void VKAPI vkGetPhysicalDeviceFeatures(
Chris Forbesd7576302015-06-21 22:55:02 +1200486 VkPhysicalDevice physicalDevice,
487 VkPhysicalDeviceFeatures* pFeatures)
488{
Chris Forbesd7576302015-06-21 22:55:02 +1200489 /* TODO: fill out features */
490 memset(pFeatures, 0, sizeof(*pFeatures));
Chris Forbesd7576302015-06-21 22:55:02 +1200491}
492
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600493void intel_gpu_get_sparse_properties(VkPhysicalDeviceSparseProperties *pProps)
Chris Forbesd7576302015-06-21 22:55:02 +1200494{
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600495 memset(pProps, 0, sizeof(*pProps));
Chris Forbesd7576302015-06-21 22:55:02 +1200496}
497
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600498ICD_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600499 VkPhysicalDevice physicalDevice,
500 const char* pLayerName,
501 uint32_t* pCount,
502 VkExtensionProperties* pProperties)
Chia-I Wubec90a02014-08-06 12:33:03 +0800503{
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600504 uint32_t copy_size;
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600505 uint32_t extension_count = ARRAY_SIZE(intel_phy_dev_gpu_exts);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600506
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600507 if (pProperties == NULL) {
508 *pCount = INTEL_PHY_DEV_EXT_COUNT;
509 return VK_SUCCESS;
510 }
511
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600512 copy_size = *pCount < extension_count ? *pCount : extension_count;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600513 memcpy(pProperties, intel_phy_dev_gpu_exts, copy_size * sizeof(VkExtensionProperties));
514 *pCount = copy_size;
Courtney Goeltzenleuchterb4269252015-07-11 10:08:36 -0600515 if (copy_size < extension_count) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600516 return VK_INCOMPLETE;
517 }
518
Tony Barbour426b9052015-06-24 16:06:58 -0600519 return VK_SUCCESS;
520}
Chia-I Wubec90a02014-08-06 12:33:03 +0800521
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600522ICD_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600523 VkPhysicalDevice physicalDevice,
524 uint32_t* pCount,
525 VkLayerProperties* pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -0600526{
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600527 *pCount = 0;
Tobin Ehlis0ef6ec52015-04-16 12:51:37 -0600528 return VK_SUCCESS;
Chia-I Wubec90a02014-08-06 12:33:03 +0800529}
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600530
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600531ICD_EXPORT void VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600532 VkPhysicalDevice physicalDevice,
533 VkFormat format,
534 VkImageType type,
535 uint32_t samples,
536 VkImageUsageFlags usage,
537 VkImageTiling tiling,
538 uint32_t* pNumProperties,
539 VkSparseImageFormatProperties* pProperties)
540{
541 *pNumProperties = 0;
Mark Lobodzinski83d4e6a2015-07-03 15:58:09 -0600542}
543