2015-05-08 22:32:37 -07:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
|
*
|
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
*
|
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
|
* Software.
|
|
|
|
|
|
*
|
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2021-10-30 17:02:41 -05:00
|
|
|
|
#include <inttypes.h>
|
2015-05-08 22:32:37 -07:00
|
|
|
|
#include <stdbool.h>
|
2024-07-21 11:33:02 +03:00
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
#include "drm-uapi/drm_fourcc.h"
|
|
|
|
|
|
#include "drm-uapi/drm.h"
|
|
|
|
|
|
#include <xf86drm.h>
|
2019-01-08 12:45:38 +00:00
|
|
|
|
|
2024-07-21 11:33:02 +03:00
|
|
|
|
#include "anv_private.h"
|
|
|
|
|
|
#include "anv_measure.h"
|
2024-08-08 14:42:07 +03:00
|
|
|
|
#include "anv_shader.h"
|
2025-02-07 04:55:18 -08:00
|
|
|
|
#include "anv_slab_bo.h"
|
2024-07-21 11:33:02 +03:00
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
|
#include "util/os_file.h"
|
|
|
|
|
|
#include "util/os_misc.h"
|
|
|
|
|
|
#include "util/u_atomic.h"
|
|
|
|
|
|
#include "util/u_string.h"
|
|
|
|
|
|
#include "vk_common_entrypoints.h"
|
|
|
|
|
|
#include "vk_util.h"
|
|
|
|
|
|
#include "vk_deferred_operation.h"
|
|
|
|
|
|
#include "vk_drm_syncobj.h"
|
|
|
|
|
|
#include "common/intel_aux_map.h"
|
|
|
|
|
|
#include "common/intel_common.h"
|
|
|
|
|
|
#include "common/intel_debug_identifier.h"
|
2019-01-08 12:45:38 +00:00
|
|
|
|
|
2024-07-21 11:33:02 +03:00
|
|
|
|
#include "i915/anv_device.h"
|
|
|
|
|
|
#include "xe/anv_device.h"
|
2017-01-25 12:12:20 -08:00
|
|
|
|
|
2024-11-04 13:46:26 -08:00
|
|
|
|
#include "genxml/gen70_pack.h"
|
2024-07-21 11:33:02 +03:00
|
|
|
|
#include "genxml/genX_bits.h"
|
2026-01-16 11:39:43 +01:00
|
|
|
|
#include "wsi_common_private.h"
|
2017-09-21 13:54:55 -07:00
|
|
|
|
|
2025-06-17 22:24:10 +03:00
|
|
|
|
const struct gfx8_border_color anv_default_border_colors[] = {
|
|
|
|
|
|
[VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } },
|
|
|
|
|
|
[VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } },
|
|
|
|
|
|
[VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } },
|
|
|
|
|
|
[VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } },
|
|
|
|
|
|
[VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } },
|
|
|
|
|
|
[VK_BORDER_COLOR_INT_OPAQUE_WHITE] = { .uint32 = { 1, 1, 1, 1 } },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2015-05-29 16:06:06 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_device_init_border_colors(struct anv_device *device)
|
|
|
|
|
|
{
|
2022-12-16 13:07:28 +02:00
|
|
|
|
device->border_colors =
|
|
|
|
|
|
anv_state_pool_emit_data(&device->dynamic_state_pool,
|
2025-06-17 22:24:10 +03:00
|
|
|
|
sizeof(anv_default_border_colors),
|
|
|
|
|
|
64, anv_default_border_colors);
|
2015-05-29 16:06:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 17:28:09 -05:00
|
|
|
|
static VkResult
|
2017-02-27 16:34:13 -08:00
|
|
|
|
anv_device_init_trivial_batch(struct anv_device *device)
|
|
|
|
|
|
{
|
2020-06-17 15:37:33 +03:00
|
|
|
|
VkResult result = anv_device_alloc_bo(device, "trivial-batch", 4096,
|
2025-02-19 09:24:37 -08:00
|
|
|
|
ANV_BO_ALLOC_BATCH_BUFFER_INTERNAL_FLAGS,
|
2019-12-02 15:22:38 -06:00
|
|
|
|
0 /* explicit_address */,
|
2019-10-28 17:28:09 -05:00
|
|
|
|
&device->trivial_batch_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->trivial_batch_bo, result);
|
2019-10-28 17:28:09 -05:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
2017-02-27 16:34:13 -08:00
|
|
|
|
|
|
|
|
|
|
struct anv_batch batch = {
|
2019-10-28 17:28:09 -05:00
|
|
|
|
.start = device->trivial_batch_bo->map,
|
|
|
|
|
|
.next = device->trivial_batch_bo->map,
|
|
|
|
|
|
.end = device->trivial_batch_bo->map + 4096,
|
2017-02-27 16:34:13 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-29 15:16:59 -07:00
|
|
|
|
anv_batch_emit(&batch, GFX7_MI_BATCH_BUFFER_END, bbe);
|
|
|
|
|
|
anv_batch_emit(&batch, GFX7_MI_NOOP, noop);
|
2017-02-27 16:34:13 -08:00
|
|
|
|
|
2019-10-28 17:28:09 -05:00
|
|
|
|
return VK_SUCCESS;
|
2017-02-27 16:34:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-23 23:27:17 +00:00
|
|
|
|
static bool
|
2021-03-03 13:49:18 -08:00
|
|
|
|
get_bo_from_pool(struct intel_batch_decode_bo *ret,
|
2019-02-23 23:27:17 +00:00
|
|
|
|
struct anv_block_pool *pool,
|
|
|
|
|
|
uint64_t address)
|
|
|
|
|
|
{
|
2019-10-25 16:42:47 -05:00
|
|
|
|
anv_block_pool_foreach_bo(bo, pool) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
uint64_t bo_address = intel_48b_address(bo->offset);
|
2019-10-25 16:42:47 -05:00
|
|
|
|
if (address >= bo_address && address < (bo_address + bo->size)) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
*ret = (struct intel_batch_decode_bo) {
|
2019-02-23 23:27:17 +00:00
|
|
|
|
.addr = bo_address,
|
2019-10-25 16:42:47 -05:00
|
|
|
|
.size = bo->size,
|
|
|
|
|
|
.map = bo->map,
|
2019-02-23 23:27:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-06 14:22:13 -07:00
|
|
|
|
/* Shader heap: find the backing BO for a GPU VA */
|
|
|
|
|
|
static bool
|
|
|
|
|
|
get_bo_from_shader_heap(struct intel_batch_decode_bo *ret,
|
|
|
|
|
|
const struct anv_device *device,
|
|
|
|
|
|
uint64_t address)
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
BITSET_FOREACH_SET(i, device->shader_heap.allocated_bos, ANV_SHADER_HEAP_MAX_BOS) {
|
|
|
|
|
|
struct anv_bo *bo = device->shader_heap.bos[i].bo;
|
|
|
|
|
|
|
|
|
|
|
|
/* Match the 48b-addressing convention used elsewhere */
|
|
|
|
|
|
uint64_t base = intel_48b_address(bo->offset);
|
|
|
|
|
|
uint64_t size = bo->size;
|
|
|
|
|
|
|
|
|
|
|
|
if (address >= base && address < base + size) {
|
|
|
|
|
|
*ret = (struct intel_batch_decode_bo) {
|
|
|
|
|
|
.addr = base,
|
|
|
|
|
|
.size = size,
|
|
|
|
|
|
.map = bo->map,
|
|
|
|
|
|
};
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-23 23:27:17 +00:00
|
|
|
|
/* Finding a buffer for batch decoding */
|
2021-03-03 13:49:18 -08:00
|
|
|
|
static struct intel_batch_decode_bo
|
2018-08-28 11:41:42 +01:00
|
|
|
|
decode_get_bo(void *v_batch, bool ppgtt, uint64_t address)
|
2019-02-23 23:27:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct anv_device *device = v_batch;
|
2021-03-03 13:49:18 -08:00
|
|
|
|
struct intel_batch_decode_bo ret_bo = {};
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
2018-08-28 11:41:42 +01:00
|
|
|
|
assert(ppgtt);
|
|
|
|
|
|
|
2019-02-23 23:27:17 +00:00
|
|
|
|
if (get_bo_from_pool(&ret_bo, &device->dynamic_state_pool.block_pool, address))
|
|
|
|
|
|
return ret_bo;
|
2025-08-06 14:22:13 -07:00
|
|
|
|
if (get_bo_from_shader_heap(&ret_bo, device, address))
|
2019-02-23 23:27:17 +00:00
|
|
|
|
return ret_bo;
|
|
|
|
|
|
if (get_bo_from_pool(&ret_bo, &device->binding_table_pool.block_pool, address))
|
|
|
|
|
|
return ret_bo;
|
2022-11-14 15:54:01 +02:00
|
|
|
|
if (get_bo_from_pool(&ret_bo, &device->scratch_surface_state_pool.block_pool, address))
|
2022-10-24 14:12:28 +03:00
|
|
|
|
return ret_bo;
|
2023-02-22 09:00:35 +02:00
|
|
|
|
if (device->physical->indirect_descriptors &&
|
|
|
|
|
|
get_bo_from_pool(&ret_bo, &device->bindless_surface_state_pool.block_pool, address))
|
2019-02-23 23:27:17 +00:00
|
|
|
|
return ret_bo;
|
2022-11-14 15:54:01 +02:00
|
|
|
|
if (get_bo_from_pool(&ret_bo, &device->internal_surface_state_pool.block_pool, address))
|
|
|
|
|
|
return ret_bo;
|
2023-10-11 23:48:01 +03:00
|
|
|
|
if (device->physical->indirect_descriptors &&
|
|
|
|
|
|
get_bo_from_pool(&ret_bo, &device->indirect_push_descriptor_pool.block_pool, address))
|
2023-02-22 09:00:35 +02:00
|
|
|
|
return ret_bo;
|
2023-10-24 22:31:11 +03:00
|
|
|
|
if (device->info->has_aux_map &&
|
|
|
|
|
|
get_bo_from_pool(&ret_bo, &device->aux_tt_pool.block_pool, address))
|
|
|
|
|
|
return ret_bo;
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
|
|
|
|
|
if (!device->cmd_buffer_being_decoded)
|
2021-03-03 13:49:18 -08:00
|
|
|
|
return (struct intel_batch_decode_bo) { };
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
2023-06-27 16:54:04 +03:00
|
|
|
|
struct anv_batch_bo **bbo;
|
|
|
|
|
|
u_vector_foreach(bbo, &device->cmd_buffer_being_decoded->seen_bbos) {
|
2026-02-26 17:33:12 +02:00
|
|
|
|
struct anv_bo *bo = (*bbo)->bo;
|
2019-02-23 23:27:17 +00:00
|
|
|
|
/* The decoder zeroes out the top 16 bits, so we need to as well */
|
2026-02-26 17:33:12 +02:00
|
|
|
|
uint64_t bo_address = bo->offset & (~0ull >> 16);
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
2026-02-26 17:33:12 +02:00
|
|
|
|
if (address >= bo_address &&
|
|
|
|
|
|
address < (bo_address + bo->size)) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
return (struct intel_batch_decode_bo) {
|
2019-02-23 23:27:17 +00:00
|
|
|
|
.addr = bo_address,
|
2026-02-26 17:33:12 +02:00
|
|
|
|
.size = bo->size,
|
|
|
|
|
|
.map = bo->map,
|
2019-02-23 23:27:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2026-02-26 17:33:12 +02:00
|
|
|
|
}
|
2023-06-27 16:54:04 +03:00
|
|
|
|
|
2026-02-26 17:33:12 +02:00
|
|
|
|
u_vector_foreach(bbo, &device->cmd_buffer_being_decoded->seen_bbos) {
|
2023-06-27 16:54:04 +03:00
|
|
|
|
uint32_t dep_words = (*bbo)->relocs.dep_words;
|
|
|
|
|
|
BITSET_WORD *deps = (*bbo)->relocs.deps;
|
|
|
|
|
|
for (uint32_t w = 0; w < dep_words; w++) {
|
|
|
|
|
|
BITSET_WORD mask = deps[w];
|
|
|
|
|
|
while (mask) {
|
|
|
|
|
|
int i = u_bit_scan(&mask);
|
|
|
|
|
|
uint32_t gem_handle = w * BITSET_WORDBITS + i;
|
|
|
|
|
|
struct anv_bo *bo = anv_device_lookup_bo(device, gem_handle);
|
|
|
|
|
|
assert(bo->refcount > 0);
|
2026-02-26 17:33:12 +02:00
|
|
|
|
uint64_t bo_address = bo->offset & (~0ull >> 16);
|
2023-06-27 16:54:04 +03:00
|
|
|
|
if (address >= bo_address && address < bo_address + bo->size) {
|
|
|
|
|
|
return (struct intel_batch_decode_bo) {
|
|
|
|
|
|
.addr = bo_address,
|
|
|
|
|
|
.size = bo->size,
|
|
|
|
|
|
.map = bo->map,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-02-23 23:27:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
return (struct intel_batch_decode_bo) { };
|
2019-02-23 23:27:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
struct intel_aux_map_buffer {
|
|
|
|
|
|
struct intel_buffer base;
|
2018-04-01 13:57:13 -07:00
|
|
|
|
struct anv_state state;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
static struct intel_buffer *
|
|
|
|
|
|
intel_aux_map_buffer_alloc(void *driver_ctx, uint32_t size)
|
2018-04-01 13:57:13 -07:00
|
|
|
|
{
|
2021-03-03 13:49:18 -08:00
|
|
|
|
struct intel_aux_map_buffer *buf = malloc(sizeof(struct intel_aux_map_buffer));
|
2018-04-01 13:57:13 -07:00
|
|
|
|
if (!buf)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_device *device = (struct anv_device*)driver_ctx;
|
|
|
|
|
|
|
2023-10-24 22:31:11 +03:00
|
|
|
|
struct anv_state_pool *pool = &device->aux_tt_pool;
|
2018-04-01 13:57:13 -07:00
|
|
|
|
buf->state = anv_state_pool_alloc(pool, size, size);
|
|
|
|
|
|
|
|
|
|
|
|
buf->base.gpu = pool->block_pool.bo->offset + buf->state.offset;
|
|
|
|
|
|
buf->base.gpu_end = buf->base.gpu + buf->state.alloc_size;
|
|
|
|
|
|
buf->base.map = buf->state.map;
|
|
|
|
|
|
buf->base.driver_bo = &buf->state;
|
|
|
|
|
|
return &buf->base;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-03 13:49:18 -08:00
|
|
|
|
intel_aux_map_buffer_free(void *driver_ctx, struct intel_buffer *buffer)
|
2018-04-01 13:57:13 -07:00
|
|
|
|
{
|
2021-03-03 13:49:18 -08:00
|
|
|
|
struct intel_aux_map_buffer *buf = (struct intel_aux_map_buffer*)buffer;
|
2018-04-01 13:57:13 -07:00
|
|
|
|
struct anv_device *device = (struct anv_device*)driver_ctx;
|
2023-10-24 22:31:11 +03:00
|
|
|
|
struct anv_state_pool *pool = &device->aux_tt_pool;
|
2018-04-01 13:57:13 -07:00
|
|
|
|
anv_state_pool_free(pool, buf->state);
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 13:22:19 -07:00
|
|
|
|
static struct intel_mapped_pinned_buffer_alloc aux_map_allocator = {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
.alloc = intel_aux_map_buffer_alloc,
|
|
|
|
|
|
.free = intel_aux_map_buffer_free,
|
2018-04-01 13:57:13 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-02-09 08:44:04 -08:00
|
|
|
|
static VkResult
|
|
|
|
|
|
anv_device_setup_context_or_vm(struct anv_device *device,
|
|
|
|
|
|
const VkDeviceCreateInfo *pCreateInfo,
|
|
|
|
|
|
const uint32_t num_queues)
|
|
|
|
|
|
{
|
2023-02-09 08:57:11 -08:00
|
|
|
|
switch (device->info->kmd_type) {
|
2023-02-09 08:44:04 -08:00
|
|
|
|
case INTEL_KMD_TYPE_I915:
|
|
|
|
|
|
return anv_i915_device_setup_context(device, pCreateInfo, num_queues);
|
|
|
|
|
|
case INTEL_KMD_TYPE_XE:
|
|
|
|
|
|
return anv_xe_device_setup_vm(device);
|
|
|
|
|
|
default:
|
2025-07-23 09:17:35 +02:00
|
|
|
|
UNREACHABLE("Missing");
|
2023-02-09 08:44:04 -08:00
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
anv_device_destroy_context_or_vm(struct anv_device *device)
|
|
|
|
|
|
{
|
2023-02-09 08:57:11 -08:00
|
|
|
|
switch (device->info->kmd_type) {
|
2023-02-09 08:44:04 -08:00
|
|
|
|
case INTEL_KMD_TYPE_I915:
|
2023-06-09 14:22:58 -07:00
|
|
|
|
if (device->physical->has_vm_control)
|
|
|
|
|
|
return anv_i915_device_destroy_vm(device);
|
|
|
|
|
|
else
|
|
|
|
|
|
return intel_gem_destroy_context(device->fd, device->context_id);
|
2023-02-09 08:44:04 -08:00
|
|
|
|
case INTEL_KMD_TYPE_XE:
|
|
|
|
|
|
return anv_xe_device_destroy_vm(device);
|
|
|
|
|
|
default:
|
2025-07-23 09:17:35 +02:00
|
|
|
|
UNREACHABLE("Missing");
|
2023-02-09 08:44:04 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
static VkResult
|
2023-09-29 11:17:32 -07:00
|
|
|
|
anv_device_init_trtt(struct anv_device *device)
|
|
|
|
|
|
{
|
2024-06-19 10:55:03 +03:00
|
|
|
|
if (device->physical->sparse_type != ANV_SPARSE_TYPE_TRTT ||
|
|
|
|
|
|
!device->vk.enabled_features.sparseBinding)
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
2023-09-29 11:17:32 -07:00
|
|
|
|
struct anv_trtt *trtt = &device->trtt;
|
|
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
VkResult result =
|
|
|
|
|
|
vk_sync_create(&device->vk,
|
|
|
|
|
|
&device->physical->sync_syncobj_type,
|
|
|
|
|
|
VK_SYNC_IS_TIMELINE,
|
|
|
|
|
|
0 /* initial_value */,
|
|
|
|
|
|
&trtt->timeline);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
2024-05-06 10:42:46 +03:00
|
|
|
|
simple_mtx_init(&trtt->mutex, mtx_plain);
|
2023-09-29 11:17:32 -07:00
|
|
|
|
|
2023-10-25 16:32:02 -07:00
|
|
|
|
list_inithead(&trtt->in_flight_batches);
|
2024-04-29 11:37:03 +03:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2023-09-29 11:17:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_device_finish_trtt(struct anv_device *device)
|
|
|
|
|
|
{
|
2024-06-19 10:55:03 +03:00
|
|
|
|
if (device->physical->sparse_type != ANV_SPARSE_TYPE_TRTT ||
|
|
|
|
|
|
!device->vk.enabled_features.sparseBinding)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-09-29 11:17:32 -07:00
|
|
|
|
struct anv_trtt *trtt = &device->trtt;
|
|
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
anv_sparse_trtt_garbage_collect_batches(device, true);
|
2023-10-25 16:32:02 -07:00
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
vk_sync_destroy(&device->vk, trtt->timeline);
|
2023-10-25 16:32:02 -07:00
|
|
|
|
|
2024-05-06 10:42:46 +03:00
|
|
|
|
simple_mtx_destroy(&trtt->mutex);
|
2023-09-29 11:17:32 -07:00
|
|
|
|
|
|
|
|
|
|
vk_free(&device->vk.alloc, trtt->l3_mirror);
|
|
|
|
|
|
vk_free(&device->vk.alloc, trtt->l2_mirror);
|
|
|
|
|
|
|
2025-02-17 10:07:04 +00:00
|
|
|
|
for (int i = 0; i < trtt->num_page_table_bos; i++) {
|
|
|
|
|
|
struct anv_bo *bo = trtt->page_table_bos[i];
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, bo);
|
2023-09-29 11:17:32 -07:00
|
|
|
|
anv_device_release_bo(device, trtt->page_table_bos[i]);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
2023-09-29 11:17:32 -07:00
|
|
|
|
|
|
|
|
|
|
vk_free(&device->vk.alloc, trtt->page_table_bos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-22 13:21:00 +03:00
|
|
|
|
static void
|
|
|
|
|
|
anv_device_init_descriptors_view(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!device->info->has_lsc)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_physical_device *pdevice = device->physical;
|
|
|
|
|
|
|
|
|
|
|
|
/* For descriptor buffers */
|
|
|
|
|
|
{
|
|
|
|
|
|
device->descriptor_buffer_view_state =
|
|
|
|
|
|
anv_state_pool_alloc(&device->scratch_surface_state_pool,
|
|
|
|
|
|
device->isl_dev.ss.size, 64);
|
|
|
|
|
|
|
|
|
|
|
|
const uint64_t size = pdevice->va.dynamic_visible_pool.size +
|
|
|
|
|
|
pdevice->va.push_descriptor_buffer_pool.size;
|
|
|
|
|
|
assert(size <= 4ull * 1024 * 1024 * 1024);
|
|
|
|
|
|
|
|
|
|
|
|
isl_buffer_fill_state(&device->isl_dev,
|
|
|
|
|
|
device->descriptor_buffer_view_state.map,
|
|
|
|
|
|
.address = pdevice->va.dynamic_visible_pool.addr,
|
|
|
|
|
|
.size_B = size,
|
|
|
|
|
|
.mocs = anv_mocs(device, NULL, ISL_SURF_USAGE_CONSTANT_BUFFER_BIT),
|
|
|
|
|
|
.format = ISL_FORMAT_RAW,
|
|
|
|
|
|
.swizzle = ISL_SWIZZLE_IDENTITY,
|
|
|
|
|
|
.stride_B = 1,
|
|
|
|
|
|
.is_scratch = false,
|
|
|
|
|
|
.usage = ISL_SURF_USAGE_CONSTANT_BUFFER_BIT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* For descriptors */
|
|
|
|
|
|
{
|
|
|
|
|
|
device->descriptor_view_state =
|
|
|
|
|
|
anv_state_pool_alloc(&device->scratch_surface_state_pool,
|
|
|
|
|
|
device->isl_dev.ss.size, 64);
|
|
|
|
|
|
|
|
|
|
|
|
const uint64_t size =
|
|
|
|
|
|
pdevice->va.internal_surface_state_pool.size +
|
|
|
|
|
|
pdevice->va.bindless_surface_state_pool.size;
|
|
|
|
|
|
|
|
|
|
|
|
isl_buffer_fill_state(&device->isl_dev,
|
|
|
|
|
|
device->descriptor_view_state.map,
|
|
|
|
|
|
.address = pdevice->va.internal_surface_state_pool.addr,
|
|
|
|
|
|
.size_B = size,
|
|
|
|
|
|
.mocs = anv_mocs(device, NULL, ISL_SURF_USAGE_CONSTANT_BUFFER_BIT),
|
|
|
|
|
|
.format = ISL_FORMAT_RAW,
|
|
|
|
|
|
.swizzle = ISL_SWIZZLE_IDENTITY,
|
|
|
|
|
|
.stride_B = 1,
|
|
|
|
|
|
.is_scratch = false,
|
|
|
|
|
|
.usage = ISL_SURF_USAGE_CONSTANT_BUFFER_BIT);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_device_finish_descriptors_view(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!device->info->has_lsc)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
anv_state_pool_free(&device->scratch_surface_state_pool,
|
|
|
|
|
|
device->descriptor_buffer_view_state);
|
|
|
|
|
|
anv_state_pool_free(&device->scratch_surface_state_pool,
|
|
|
|
|
|
device->descriptor_view_state);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 16:12:29 -08:00
|
|
|
|
static VkResult
|
|
|
|
|
|
anv_device_bind_null_va(struct anv_device *device,
|
|
|
|
|
|
struct anv_va_range *range,
|
|
|
|
|
|
enum anv_vm_bind_op op)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct anv_vm_bind bind = {
|
|
|
|
|
|
.address = range->addr,
|
|
|
|
|
|
.size = range->size,
|
|
|
|
|
|
.op = op,
|
|
|
|
|
|
};
|
|
|
|
|
|
struct anv_sparse_submission submit = {
|
|
|
|
|
|
.binds = &bind,
|
|
|
|
|
|
.binds_len = 1,
|
|
|
|
|
|
.binds_capacity = 1,
|
|
|
|
|
|
};
|
|
|
|
|
|
return device->kmd_backend->vm_bind(device, &submit,
|
|
|
|
|
|
ANV_VM_BIND_FLAG_SIGNAL_BIND_TIMELINE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-30 13:25:50 -07:00
|
|
|
|
static VkResult
|
|
|
|
|
|
anv_device_init_vma_heaps(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pthread_mutex_init(&device->vma_mutex, NULL) != 0)
|
|
|
|
|
|
return vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
|
|
|
|
|
|
|
|
|
|
|
|
/* keep the page with address zero out of the allocator */
|
|
|
|
|
|
util_vma_heap_init(&device->vma_lo,
|
|
|
|
|
|
device->physical->va.low_heap.addr,
|
|
|
|
|
|
device->physical->va.low_heap.size);
|
|
|
|
|
|
|
|
|
|
|
|
util_vma_heap_init(&device->vma_hi,
|
|
|
|
|
|
device->physical->va.high_heap.addr,
|
|
|
|
|
|
device->physical->va.high_heap.size);
|
|
|
|
|
|
|
2026-02-06 16:12:29 -08:00
|
|
|
|
/* Reduce the usable size of the null initialized heap by enough pages so
|
|
|
|
|
|
* that no batch buffers get placed where the CS could end up prefetching
|
|
|
|
|
|
* beyond the limit of the null pages.
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned max_prefetch = intel_device_info_get_max_engine_prefetch(device->info);
|
|
|
|
|
|
max_prefetch = align(max_prefetch, device->info->mem_alignment);
|
|
|
|
|
|
util_vma_heap_init(&device->vma_null_initialized,
|
|
|
|
|
|
device->physical->va.null_initialized_heap.addr,
|
|
|
|
|
|
device->physical->va.null_initialized_heap.size - max_prefetch);
|
|
|
|
|
|
|
2025-06-30 13:25:50 -07:00
|
|
|
|
if (device->physical->indirect_descriptors) {
|
|
|
|
|
|
util_vma_heap_init(&device->vma_desc,
|
|
|
|
|
|
device->physical->va.indirect_descriptor_pool.addr,
|
|
|
|
|
|
device->physical->va.indirect_descriptor_pool.size);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
util_vma_heap_init(&device->vma_desc,
|
|
|
|
|
|
device->physical->va.bindless_surface_state_pool.addr,
|
|
|
|
|
|
device->physical->va.bindless_surface_state_pool.size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Always initialized because the the memory types point to this and they
|
|
|
|
|
|
* are on the physical device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
util_vma_heap_init(&device->vma_dynamic_visible,
|
|
|
|
|
|
device->physical->va.dynamic_visible_pool.addr,
|
|
|
|
|
|
device->physical->va.dynamic_visible_pool.size);
|
|
|
|
|
|
util_vma_heap_init(&device->vma_trtt,
|
|
|
|
|
|
device->physical->va.trtt.addr,
|
|
|
|
|
|
device->physical->va.trtt.size);
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_device_finish_vma_heaps(struct anv_device *device)
|
|
|
|
|
|
{
|
2026-02-06 16:12:29 -08:00
|
|
|
|
util_vma_heap_finish(&device->vma_null_initialized);
|
2025-06-30 13:25:50 -07:00
|
|
|
|
util_vma_heap_finish(&device->vma_trtt);
|
|
|
|
|
|
util_vma_heap_finish(&device->vma_dynamic_visible);
|
|
|
|
|
|
util_vma_heap_finish(&device->vma_desc);
|
|
|
|
|
|
util_vma_heap_finish(&device->vma_hi);
|
|
|
|
|
|
util_vma_heap_finish(&device->vma_lo);
|
|
|
|
|
|
pthread_mutex_destroy(&device->vma_mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-17 12:25:06 -07:00
|
|
|
|
static VkResult
|
|
|
|
|
|
anv_state_pools_init(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
/* Because scratch is also relative to General State Base Address, we leave
|
|
|
|
|
|
* the base address 0 and start the pool memory at an offset. This way we
|
|
|
|
|
|
* get the correct offsets in the anv_states that get allocated from it.
|
|
|
|
|
|
*/
|
|
|
|
|
|
result = anv_state_pool_init(&device->general_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "general pool",
|
|
|
|
|
|
.base_address = 0,
|
|
|
|
|
|
.start_offset = device->physical->va.general_state_pool.addr,
|
|
|
|
|
|
.block_size = 16384,
|
|
|
|
|
|
.max_size = device->physical->va.general_state_pool.size
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_batch_bo_pool;
|
|
|
|
|
|
|
|
|
|
|
|
result = anv_state_pool_init(&device->dynamic_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "dynamic pool",
|
|
|
|
|
|
.base_address = device->physical->va.dynamic_state_pool.addr,
|
|
|
|
|
|
.block_size = 16384,
|
|
|
|
|
|
.max_size = device->physical->va.dynamic_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_general_state_pool;
|
|
|
|
|
|
|
|
|
|
|
|
/* The border color pointer is limited to 24 bits, so we need to make
|
|
|
|
|
|
* sure that any such color used at any point in the program doesn't
|
|
|
|
|
|
* exceed that limit.
|
|
|
|
|
|
* We achieve that by reserving all the custom border colors we support
|
|
|
|
|
|
* right off the bat, so they are close to the base address.
|
|
|
|
|
|
*/
|
|
|
|
|
|
result = anv_state_reserved_array_pool_init(&device->custom_border_colors,
|
|
|
|
|
|
&device->dynamic_state_pool,
|
|
|
|
|
|
MAX_CUSTOM_BORDER_COLORS,
|
|
|
|
|
|
sizeof(struct gfx8_border_color), 64);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_dynamic_state_pool;
|
|
|
|
|
|
|
|
|
|
|
|
result = anv_shader_heap_init(&device->shader_heap, device,
|
|
|
|
|
|
device->physical->va.shader_heap,
|
|
|
|
|
|
21 /* 2MiB */, 27 /* 64MiB */);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_custom_border_color_pool;
|
|
|
|
|
|
|
|
|
|
|
|
if (device->info->verx10 >= 125) {
|
|
|
|
|
|
/* Put the scratch surface states at the beginning of the internal
|
|
|
|
|
|
* surface state pool.
|
|
|
|
|
|
*/
|
|
|
|
|
|
result = anv_state_pool_init(&device->scratch_surface_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "scratch surface state pool",
|
|
|
|
|
|
.base_address = device->physical->va.scratch_surface_state_pool.addr,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.scratch_surface_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_shader_vma_heap;
|
|
|
|
|
|
|
|
|
|
|
|
result = anv_state_pool_init(&device->internal_surface_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "internal surface state pool",
|
|
|
|
|
|
.base_address = device->physical->va.internal_surface_state_pool.addr,
|
|
|
|
|
|
.start_offset = device->physical->va.scratch_surface_state_pool.size,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.internal_surface_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
result = anv_state_pool_init(&device->internal_surface_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "internal surface state pool",
|
|
|
|
|
|
.base_address = device->physical->va.internal_surface_state_pool.addr,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.internal_surface_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_scratch_surface_state_pool;
|
|
|
|
|
|
|
|
|
|
|
|
if (device->physical->indirect_descriptors) {
|
|
|
|
|
|
result = anv_state_pool_init(&device->bindless_surface_state_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "bindless surface state pool",
|
|
|
|
|
|
.base_address = device->physical->va.bindless_surface_state_pool.addr,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.bindless_surface_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_internal_surface_state_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (device->info->verx10 >= 125) {
|
|
|
|
|
|
/* We're using 3DSTATE_BINDING_TABLE_POOL_ALLOC to give the binding
|
|
|
|
|
|
* table its own base address separately from surface state base.
|
|
|
|
|
|
*/
|
|
|
|
|
|
result = anv_state_pool_init(&device->binding_table_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "binding table pool",
|
|
|
|
|
|
.base_address = device->physical->va.binding_table_pool.addr,
|
|
|
|
|
|
.block_size = device->physical->instance->binding_table_block_size,
|
|
|
|
|
|
.max_size = device->physical->va.binding_table_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* The binding table should be in front of the surface states in virtual
|
|
|
|
|
|
* address space so that all surface states can be express as relative
|
|
|
|
|
|
* offsets from the binding table location.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(device->physical->va.binding_table_pool.addr <
|
|
|
|
|
|
device->physical->va.internal_surface_state_pool.addr);
|
|
|
|
|
|
int64_t bt_pool_offset = (int64_t)device->physical->va.binding_table_pool.addr -
|
|
|
|
|
|
(int64_t)device->physical->va.internal_surface_state_pool.addr;
|
|
|
|
|
|
assert(INT32_MIN < bt_pool_offset && bt_pool_offset < 0);
|
|
|
|
|
|
result = anv_state_pool_init(&device->binding_table_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "binding table pool",
|
|
|
|
|
|
.base_address = device->physical->va.internal_surface_state_pool.addr,
|
|
|
|
|
|
.start_offset = bt_pool_offset,
|
|
|
|
|
|
.block_size = 64 * 1024,
|
|
|
|
|
|
.max_size = device->physical->va.internal_surface_state_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_bindless_surface_state_pool;
|
|
|
|
|
|
|
|
|
|
|
|
if (device->physical->indirect_descriptors) {
|
|
|
|
|
|
result = anv_state_pool_init(&device->indirect_push_descriptor_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "indirect push descriptor pool",
|
|
|
|
|
|
.base_address = device->physical->va.indirect_push_descriptor_pool.addr,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.indirect_push_descriptor_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_binding_table_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (device->vk.enabled_extensions.EXT_descriptor_buffer &&
|
|
|
|
|
|
device->info->verx10 >= 125) {
|
|
|
|
|
|
/* On Gfx12.5+ because of the bindless stages (Mesh, Task, RT), the only
|
|
|
|
|
|
* way we can wire push descriptors is through the bindless heap. This
|
|
|
|
|
|
* state pool is a 1Gb carve out of the 4Gb HW heap.
|
|
|
|
|
|
*/
|
|
|
|
|
|
result = anv_state_pool_init(&device->push_descriptor_buffer_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "push descriptor buffer state pool",
|
|
|
|
|
|
.base_address = device->physical->va.push_descriptor_buffer_pool.addr,
|
|
|
|
|
|
.block_size = 4096,
|
|
|
|
|
|
.max_size = device->physical->va.push_descriptor_buffer_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_indirect_push_descriptor_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (device->info->has_aux_map) {
|
|
|
|
|
|
result = anv_state_pool_init(&device->aux_tt_pool, device,
|
|
|
|
|
|
&(struct anv_state_pool_params) {
|
|
|
|
|
|
.name = "aux-tt pool",
|
|
|
|
|
|
.base_address = device->physical->va.aux_tt_pool.addr,
|
|
|
|
|
|
.block_size = 16384,
|
|
|
|
|
|
.max_size = device->physical->va.aux_tt_pool.size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_push_descriptor_buffer_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
fail_push_descriptor_buffer_pool:
|
|
|
|
|
|
if (device->vk.enabled_extensions.EXT_descriptor_buffer &&
|
|
|
|
|
|
device->info->verx10 >= 125)
|
|
|
|
|
|
anv_state_pool_finish(&device->push_descriptor_buffer_pool);
|
|
|
|
|
|
fail_indirect_push_descriptor_pool:
|
|
|
|
|
|
if (device->physical->indirect_descriptors)
|
|
|
|
|
|
anv_state_pool_finish(&device->indirect_push_descriptor_pool);
|
|
|
|
|
|
fail_binding_table_pool:
|
|
|
|
|
|
anv_state_pool_finish(&device->binding_table_pool);
|
|
|
|
|
|
fail_bindless_surface_state_pool:
|
|
|
|
|
|
if (device->physical->indirect_descriptors)
|
|
|
|
|
|
anv_state_pool_finish(&device->bindless_surface_state_pool);
|
|
|
|
|
|
fail_internal_surface_state_pool:
|
|
|
|
|
|
anv_state_pool_finish(&device->internal_surface_state_pool);
|
|
|
|
|
|
fail_scratch_surface_state_pool:
|
|
|
|
|
|
if (device->info->verx10 >= 125)
|
|
|
|
|
|
anv_state_pool_finish(&device->scratch_surface_state_pool);
|
|
|
|
|
|
fail_shader_vma_heap:
|
|
|
|
|
|
anv_shader_heap_finish(&device->shader_heap);
|
|
|
|
|
|
fail_custom_border_color_pool:
|
|
|
|
|
|
anv_state_reserved_array_pool_finish(&device->custom_border_colors);
|
|
|
|
|
|
fail_dynamic_state_pool:
|
|
|
|
|
|
anv_state_pool_finish(&device->dynamic_state_pool);
|
|
|
|
|
|
fail_general_state_pool:
|
|
|
|
|
|
anv_state_pool_finish(&device->general_state_pool);
|
|
|
|
|
|
fail_batch_bo_pool:
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_state_pools_finish(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
anv_state_reserved_array_pool_finish(&device->custom_border_colors);
|
|
|
|
|
|
if (device->info->has_aux_map)
|
|
|
|
|
|
anv_state_pool_finish(&device->aux_tt_pool);
|
|
|
|
|
|
if (device->vk.enabled_extensions.EXT_descriptor_buffer &&
|
|
|
|
|
|
device->info->verx10 >= 125)
|
|
|
|
|
|
anv_state_pool_finish(&device->push_descriptor_buffer_pool);
|
|
|
|
|
|
if (device->physical->indirect_descriptors)
|
|
|
|
|
|
anv_state_pool_finish(&device->indirect_push_descriptor_pool);
|
|
|
|
|
|
anv_state_pool_finish(&device->binding_table_pool);
|
|
|
|
|
|
if (device->info->verx10 >= 125)
|
|
|
|
|
|
anv_state_pool_finish(&device->scratch_surface_state_pool);
|
|
|
|
|
|
anv_state_pool_finish(&device->internal_surface_state_pool);
|
|
|
|
|
|
if (device->physical->indirect_descriptors)
|
|
|
|
|
|
anv_state_pool_finish(&device->bindless_surface_state_pool);
|
|
|
|
|
|
|
|
|
|
|
|
anv_shader_heap_finish(&device->shader_heap);
|
|
|
|
|
|
anv_state_pool_finish(&device->dynamic_state_pool);
|
|
|
|
|
|
anv_state_pool_finish(&device->general_state_pool);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-05-17 16:33:48 -07:00
|
|
|
|
VkResult anv_CreateDevice(
|
2015-07-09 18:20:10 -07:00
|
|
|
|
VkPhysicalDevice physicalDevice,
|
2015-05-08 22:32:37 -07:00
|
|
|
|
const VkDeviceCreateInfo* pCreateInfo,
|
2015-12-02 03:28:27 -08:00
|
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDevice* pDevice)
|
|
|
|
|
|
{
|
2025-06-03 18:49:55 +00:00
|
|
|
|
anv_wait_for_attach();
|
2015-07-09 18:20:10 -07:00
|
|
|
|
ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
|
2016-01-03 22:43:47 -08:00
|
|
|
|
VkResult result;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
struct anv_device *device;
|
2026-01-21 13:31:39 -08:00
|
|
|
|
bool device_has_compute_queue = false;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
|
|
|
|
|
|
|
2018-02-06 10:37:16 +01:00
|
|
|
|
/* Check requested queues and fail if we are requested to create any
|
|
|
|
|
|
* queues with flags we don't support.
|
|
|
|
|
|
*/
|
2026-01-21 13:31:39 -08:00
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
|
2026-01-26 17:54:21 +02:00
|
|
|
|
if (pCreateInfo->pQueueCreateInfos[i].flags & ~(VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT |
|
|
|
|
|
|
VK_DEVICE_QUEUE_CREATE_INTERNALLY_SYNCHRONIZED_BIT_KHR))
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(physical_device, VK_ERROR_INITIALIZATION_FAILED);
|
2024-11-04 10:30:41 +02:00
|
|
|
|
|
2026-01-21 13:31:39 -08:00
|
|
|
|
const struct anv_queue_family *family =
|
|
|
|
|
|
&physical_device->queue.families[pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex];
|
|
|
|
|
|
device_has_compute_queue |= family->engine_class == INTEL_ENGINE_CLASS_COMPUTE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-06 13:14:20 +02:00
|
|
|
|
device = vk_zalloc2(&physical_device->instance->vk.alloc, pAllocator,
|
2015-12-02 03:28:27 -08:00
|
|
|
|
sizeof(*device), 8,
|
2016-01-18 14:04:13 -08:00
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
if (!device)
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(physical_device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2021-01-23 04:57:21 -06:00
|
|
|
|
struct vk_device_dispatch_table dispatch_table;
|
2022-08-23 10:06:11 +03:00
|
|
|
|
|
|
|
|
|
|
bool override_initial_entrypoints = true;
|
|
|
|
|
|
if (physical_device->instance->vk.app_info.app_name &&
|
|
|
|
|
|
!strcmp(physical_device->instance->vk.app_info.app_name, "HITMAN3.exe")) {
|
2023-12-29 11:05:48 +02:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_hitman3_device_entrypoints,
|
|
|
|
|
|
true);
|
2022-08-23 10:06:11 +03:00
|
|
|
|
override_initial_entrypoints = false;
|
|
|
|
|
|
}
|
2022-11-03 01:41:53 +02:00
|
|
|
|
if (physical_device->info.ver < 12 &&
|
|
|
|
|
|
physical_device->instance->vk.app_info.app_name &&
|
|
|
|
|
|
!strcmp(physical_device->instance->vk.app_info.app_name, "DOOM 64")) {
|
2023-12-29 11:05:48 +02:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_doom64_device_entrypoints,
|
|
|
|
|
|
true);
|
2022-11-03 01:41:53 +02:00
|
|
|
|
override_initial_entrypoints = false;
|
|
|
|
|
|
}
|
2025-11-12 09:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
if (physical_device->info.ver < 12 &&
|
|
|
|
|
|
physical_device->instance->vk.app_info.app_name &&
|
|
|
|
|
|
!strcmp(physical_device->instance->vk.app_info.app_name, "GeeXLab")) {
|
|
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_furmark_device_entrypoints,
|
|
|
|
|
|
true);
|
|
|
|
|
|
override_initial_entrypoints = false;
|
|
|
|
|
|
}
|
2024-01-30 10:52:43 -08:00
|
|
|
|
#if DETECT_OS_ANDROID
|
2023-12-29 11:05:48 +02:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_android_device_entrypoints,
|
|
|
|
|
|
true);
|
2023-05-03 07:13:07 +03:00
|
|
|
|
override_initial_entrypoints = false;
|
|
|
|
|
|
#endif
|
2023-12-28 12:27:05 +02:00
|
|
|
|
if (physical_device->instance->vk.trace_mode & VK_TRACE_MODE_RMV) {
|
|
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_rmv_device_entrypoints,
|
|
|
|
|
|
true);
|
|
|
|
|
|
override_initial_entrypoints = false;
|
|
|
|
|
|
}
|
2021-01-23 04:57:21 -06:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
2022-08-23 10:06:11 +03:00
|
|
|
|
anv_genX(&physical_device->info, device_entrypoints),
|
|
|
|
|
|
override_initial_entrypoints);
|
2021-01-23 04:57:21 -06:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&anv_device_entrypoints, false);
|
2021-10-06 11:21:55 -05:00
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
|
|
&wsi_device_entrypoints, false);
|
2021-01-23 04:57:21 -06:00
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
|
|
2021-01-23 04:57:21 -06:00
|
|
|
|
result = vk_device_init(&device->vk, &physical_device->vk,
|
2021-01-29 12:30:34 -06:00
|
|
|
|
&dispatch_table, pCreateInfo, pAllocator);
|
2021-09-24 16:04:51 -05:00
|
|
|
|
if (result != VK_SUCCESS)
|
2021-01-24 09:26:24 -06:00
|
|
|
|
goto fail_alloc;
|
2020-04-21 12:42:59 -05:00
|
|
|
|
|
2024-08-08 14:42:07 +03:00
|
|
|
|
device->vk.shader_ops = &anv_device_shader_ops;
|
|
|
|
|
|
|
2025-04-23 09:00:50 +03:00
|
|
|
|
if (INTEL_DEBUG(DEBUG_BATCH) || INTEL_DEBUG(DEBUG_BATCH_STATS)) {
|
2023-01-30 14:46:26 -08:00
|
|
|
|
for (unsigned i = 0; i < physical_device->queue.family_count; i++) {
|
|
|
|
|
|
struct intel_batch_decode_ctx *decoder = &device->decoder[i];
|
|
|
|
|
|
|
2023-08-01 23:16:43 +03:00
|
|
|
|
const unsigned decode_flags = INTEL_BATCH_DECODE_DEFAULT_FLAGS;
|
2023-01-30 14:46:26 -08:00
|
|
|
|
|
2024-01-25 12:36:06 -08:00
|
|
|
|
intel_batch_decode_ctx_init_brw(decoder,
|
|
|
|
|
|
&physical_device->compiler->isa,
|
|
|
|
|
|
&physical_device->info,
|
|
|
|
|
|
stderr, decode_flags, NULL,
|
|
|
|
|
|
decode_get_bo, NULL, device);
|
2023-06-07 00:37:03 +03:00
|
|
|
|
intel_batch_stats_reset(decoder);
|
2023-01-30 14:46:26 -08:00
|
|
|
|
|
|
|
|
|
|
decoder->engine = physical_device->queue.families[i].engine_class;
|
2023-02-23 09:59:45 +02:00
|
|
|
|
decoder->dynamic_base = physical_device->va.dynamic_state_pool.addr;
|
|
|
|
|
|
decoder->surface_base = physical_device->va.internal_surface_state_pool.addr;
|
2026-02-26 16:38:29 -08:00
|
|
|
|
decoder->instruction_base = physical_device->va.shader_heap.addr;
|
2023-01-30 14:46:26 -08:00
|
|
|
|
}
|
2019-06-12 12:41:36 +03:00
|
|
|
|
}
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
2022-08-22 20:07:21 +08:00
|
|
|
|
anv_device_set_physical(device, physical_device);
|
2023-01-26 11:06:46 -08:00
|
|
|
|
device->kmd_backend = anv_kmd_backend_get(device->info->kmd_type);
|
2015-07-09 16:31:39 -07:00
|
|
|
|
|
|
|
|
|
|
/* XXX(chadv): Can we dup() physicalDevice->fd here? */
|
2015-07-09 18:20:10 -07:00
|
|
|
|
device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
|
2016-01-03 22:43:47 -08:00
|
|
|
|
if (device->fd == -1) {
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
goto fail_device;
|
2016-01-03 22:43:47 -08:00
|
|
|
|
}
|
2015-11-13 10:12:18 -08:00
|
|
|
|
|
2025-11-17 03:52:43 +03:00
|
|
|
|
if (intel_virtio_init_fd(device->fd) < 0) {
|
|
|
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
|
|
goto fail_fd;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-09 12:34:50 -08:00
|
|
|
|
switch (device->info->kmd_type) {
|
|
|
|
|
|
case INTEL_KMD_TYPE_I915:
|
|
|
|
|
|
device->vk.check_status = anv_i915_device_check_status;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case INTEL_KMD_TYPE_XE:
|
|
|
|
|
|
device->vk.check_status = anv_xe_device_check_status;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2025-07-23 09:17:35 +02:00
|
|
|
|
UNREACHABLE("Missing");
|
2023-02-09 12:34:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-15 11:39:24 -04:00
|
|
|
|
device->vk.copy_sync_payloads = vk_drm_syncobj_copy_payloads;
|
2022-08-30 13:42:58 -05:00
|
|
|
|
device->vk.command_buffer_ops = &anv_cmd_buffer_ops;
|
2025-11-17 03:52:43 +03:00
|
|
|
|
|
|
|
|
|
|
if (physical_device->info.is_virtio)
|
|
|
|
|
|
device->vk.sync = intel_virtio_sync_provider(device->fd);
|
|
|
|
|
|
else
|
|
|
|
|
|
vk_device_set_drm_fd(&device->vk, device->fd);
|
2021-11-08 12:53:10 -06:00
|
|
|
|
|
2019-03-24 01:00:37 -07:00
|
|
|
|
uint32_t num_queues = 0;
|
|
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
|
|
|
|
|
|
num_queues += pCreateInfo->pQueueCreateInfos[i].queueCount;
|
|
|
|
|
|
|
2023-02-09 08:44:04 -08:00
|
|
|
|
result = anv_device_setup_context_or_vm(device, pCreateInfo, num_queues);
|
2022-08-09 13:37:13 -07:00
|
|
|
|
if (result != VK_SUCCESS)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
goto fail_fd;
|
2021-08-19 10:51:17 -05:00
|
|
|
|
|
2018-08-14 02:34:16 -07:00
|
|
|
|
device->queues =
|
|
|
|
|
|
vk_zalloc(&device->vk.alloc, num_queues * sizeof(*device->queues), 8,
|
|
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
|
|
|
|
|
|
if (device->queues == NULL) {
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2019-08-23 12:30:42 +02:00
|
|
|
|
goto fail_context_id;
|
2018-08-14 02:34:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-30 13:25:50 -07:00
|
|
|
|
result = anv_device_init_vma_heaps(device);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
2024-04-29 17:40:56 +03:00
|
|
|
|
goto fail_queues_alloc;
|
2023-10-16 16:27:57 -07:00
|
|
|
|
|
2019-02-26 18:05:34 -06:00
|
|
|
|
list_inithead(&device->memory_objects);
|
2023-05-11 12:43:00 +03:00
|
|
|
|
list_inithead(&device->image_private_objects);
|
2019-02-26 18:05:34 -06:00
|
|
|
|
|
2016-11-30 06:59:15 +09:00
|
|
|
|
if (pthread_mutex_init(&device->mutex, NULL) != 0) {
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
|
2025-07-30 16:51:13 -07:00
|
|
|
|
goto fail_vmas;
|
2016-11-30 06:59:15 +09:00
|
|
|
|
}
|
2015-09-17 18:23:21 -07:00
|
|
|
|
|
2026-02-06 16:12:29 -08:00
|
|
|
|
result = anv_device_bind_null_va(device,
|
|
|
|
|
|
&device->physical->va.null_initialized_heap,
|
|
|
|
|
|
ANV_VM_BIND);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_mutex;
|
|
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
|
if (physical_device->instance->vk.trace_mode & VK_TRACE_MODE_RMV)
|
|
|
|
|
|
anv_memory_trace_init(device);
|
|
|
|
|
|
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = anv_bo_cache_init(&device->bo_cache, device);
|
2017-03-13 17:20:15 -07:00
|
|
|
|
if (result != VK_SUCCESS)
|
2026-02-06 16:12:29 -08:00
|
|
|
|
goto fail_null_vma_init;
|
2019-10-28 15:42:20 -05:00
|
|
|
|
|
2025-07-30 16:51:13 -07:00
|
|
|
|
if (!anv_slab_bo_init(device))
|
|
|
|
|
|
goto fail_cache;
|
|
|
|
|
|
|
2023-10-05 18:03:41 +03:00
|
|
|
|
anv_bo_pool_init(&device->batch_bo_pool, device, "batch",
|
2025-02-19 09:24:37 -08:00
|
|
|
|
ANV_BO_ALLOC_BATCH_BUFFER_FLAGS);
|
2023-10-05 17:54:35 +03:00
|
|
|
|
if (device->vk.enabled_extensions.KHR_acceleration_structure) {
|
|
|
|
|
|
anv_bo_pool_init(&device->bvh_bo_pool, device, "bvh build",
|
|
|
|
|
|
0 /* alloc_flags */);
|
|
|
|
|
|
}
|
2017-03-13 17:20:15 -07:00
|
|
|
|
|
2026-04-17 12:25:06 -07:00
|
|
|
|
result = anv_state_pools_init(device);
|
2020-05-04 17:08:00 -05:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_batch_bo_pool;
|
|
|
|
|
|
|
2022-08-04 12:56:17 -07:00
|
|
|
|
if (device->info->has_aux_map) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
device->aux_map_ctx = intel_aux_map_init(device, &aux_map_allocator,
|
2021-03-09 09:44:02 -08:00
|
|
|
|
&physical_device->info);
|
2018-03-28 01:42:50 -07:00
|
|
|
|
if (!device->aux_map_ctx)
|
2023-10-24 22:31:11 +03:00
|
|
|
|
goto fail_aux_tt_pool;
|
2018-03-28 01:42:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 13:57:15 +02:00
|
|
|
|
result = anv_device_alloc_bo(device, "workaround", 8192,
|
2020-08-28 13:01:53 -07:00
|
|
|
|
ANV_BO_ALLOC_CAPTURE |
|
2023-11-30 10:05:58 -08:00
|
|
|
|
ANV_BO_ALLOC_HOST_COHERENT |
|
2023-12-29 12:06:39 +02:00
|
|
|
|
ANV_BO_ALLOC_MAPPED |
|
|
|
|
|
|
ANV_BO_ALLOC_INTERNAL,
|
2019-12-02 15:22:38 -06:00
|
|
|
|
0 /* explicit_address */,
|
|
|
|
|
|
&device->workaround_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->workaround_bo, result);
|
2016-11-30 06:59:15 +09:00
|
|
|
|
if (result != VK_SUCCESS)
|
2018-03-28 01:42:50 -07:00
|
|
|
|
goto fail_surface_aux_map_pool;
|
2015-11-10 16:42:34 -08:00
|
|
|
|
|
2023-08-16 09:27:44 -07:00
|
|
|
|
if (intel_needs_workaround(device->info, 14019708328)) {
|
|
|
|
|
|
result = anv_device_alloc_bo(device, "dummy_aux", 4096,
|
|
|
|
|
|
0 /* alloc_flags */,
|
|
|
|
|
|
0 /* explicit_address */,
|
|
|
|
|
|
&device->dummy_aux_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->dummy_aux_bo, result);
|
2023-08-16 09:27:44 -07:00
|
|
|
|
if (result != VK_SUCCESS)
|
2024-12-16 10:39:22 -08:00
|
|
|
|
goto fail_alloc_device_bo;
|
2023-08-16 09:27:44 -07:00
|
|
|
|
|
|
|
|
|
|
device->isl_dev.dummy_aux_address = device->dummy_aux_bo->offset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-16 10:39:22 -08:00
|
|
|
|
/* Programming note from MI_MEM_FENCE specification:
|
|
|
|
|
|
*
|
|
|
|
|
|
* Software must ensure STATE_SYSTEM_MEM_FENCE_ADDRESS command is
|
|
|
|
|
|
* programmed prior to programming this command.
|
|
|
|
|
|
*
|
|
|
|
|
|
* HAS 1607240579 then provides the size information: 4K
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (device->info->verx10 >= 200) {
|
|
|
|
|
|
result = anv_device_alloc_bo(device, "mem_fence", 4096,
|
|
|
|
|
|
ANV_BO_ALLOC_NO_LOCAL_MEM, 0,
|
|
|
|
|
|
&device->mem_fence_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->mem_fence_bo, result);
|
2024-12-16 10:39:22 -08:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_alloc_device_bo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-26 09:44:31 +03:00
|
|
|
|
struct anv_address wa_addr = (struct anv_address) {
|
2020-02-21 17:36:36 +02:00
|
|
|
|
.bo = device->workaround_bo,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-26 09:44:31 +03:00
|
|
|
|
wa_addr = anv_address_add_aligned(wa_addr,
|
|
|
|
|
|
intel_debug_write_identifiers(
|
|
|
|
|
|
device->workaround_bo->map,
|
|
|
|
|
|
device->workaround_bo->size,
|
|
|
|
|
|
"Anv"), 32);
|
2022-11-03 01:41:53 +02:00
|
|
|
|
|
2024-08-26 09:44:31 +03:00
|
|
|
|
device->rt_uuid_addr = wa_addr;
|
2021-01-21 02:18:32 -06:00
|
|
|
|
memcpy(device->rt_uuid_addr.bo->map + device->rt_uuid_addr.offset,
|
|
|
|
|
|
physical_device->rt_uuid,
|
|
|
|
|
|
sizeof(physical_device->rt_uuid));
|
|
|
|
|
|
|
2026-03-02 22:57:57 -08:00
|
|
|
|
/* A null cache line for bounded UBO loads. */
|
|
|
|
|
|
wa_addr = anv_address_add_aligned(wa_addr, 64, 64);
|
|
|
|
|
|
device->null_cacheline_addr = wa_addr;
|
|
|
|
|
|
|
2024-08-26 09:44:31 +03:00
|
|
|
|
/* Make sure the workaround address is the last one in the workaround BO,
|
|
|
|
|
|
* so that writes never overwrite other bits of data stored in the
|
|
|
|
|
|
* workaround BO.
|
|
|
|
|
|
*/
|
2024-08-27 17:53:37 -07:00
|
|
|
|
wa_addr = anv_address_add_aligned(wa_addr,
|
2024-08-26 09:44:31 +03:00
|
|
|
|
sizeof(physical_device->rt_uuid), 64);
|
|
|
|
|
|
device->workaround_address = wa_addr;
|
|
|
|
|
|
|
|
|
|
|
|
/* Make sure we don't over the allocated BO. */
|
|
|
|
|
|
assert(device->workaround_address.offset < device->workaround_bo->size);
|
|
|
|
|
|
/* We also need 64B (maximum GRF size) from the workaround address (see
|
|
|
|
|
|
* TBIMR workaround)
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert((device->workaround_bo->size -
|
|
|
|
|
|
device->workaround_address.offset) >= 64);
|
|
|
|
|
|
|
|
|
|
|
|
device->workarounds.doom64_images = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-05 01:15:57 +02:00
|
|
|
|
device->debug_frame_desc =
|
|
|
|
|
|
intel_debug_get_identifier_block(device->workaround_bo->map,
|
|
|
|
|
|
device->workaround_bo->size,
|
2021-04-05 11:13:16 -07:00
|
|
|
|
INTEL_DEBUG_BLOCK_TYPE_FRAME);
|
2019-12-25 23:26:48 +02:00
|
|
|
|
|
2026-01-21 13:31:39 -08:00
|
|
|
|
if (device->vk.enabled_extensions.KHR_ray_query) {
|
|
|
|
|
|
uint32_t ray_queries_size =
|
|
|
|
|
|
align(brw_rt_ray_queries_hw_stacks_size(device->info), 4096);
|
|
|
|
|
|
|
|
|
|
|
|
result = anv_device_alloc_bo(device, "ray queries",
|
|
|
|
|
|
ray_queries_size,
|
|
|
|
|
|
ANV_BO_ALLOC_INTERNAL,
|
|
|
|
|
|
0 /* explicit_address */,
|
|
|
|
|
|
&device->ray_query_bo[0]);
|
|
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->ray_query_bo[0], result);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_alloc_device_bo;
|
|
|
|
|
|
|
|
|
|
|
|
/* We need a separate ray query bo for CCS engine with Wa_14022863161. */
|
|
|
|
|
|
if (intel_needs_workaround(device->isl_dev.info, 14022863161) &&
|
|
|
|
|
|
device_has_compute_queue) {
|
|
|
|
|
|
result = anv_device_alloc_bo(device, "ray queries",
|
|
|
|
|
|
ray_queries_size,
|
|
|
|
|
|
ANV_BO_ALLOC_INTERNAL,
|
|
|
|
|
|
0 /* explicit_address */,
|
|
|
|
|
|
&device->ray_query_bo[1]);
|
|
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->ray_query_bo[1], result);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_ray_query_bo;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-28 17:28:09 -05:00
|
|
|
|
result = anv_device_init_trivial_batch(device);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
2026-01-21 13:31:39 -08:00
|
|
|
|
goto fail_ray_query_bo;
|
2018-05-30 20:16:30 -07:00
|
|
|
|
|
2022-11-19 03:35:27 +02:00
|
|
|
|
/* Emit the CPS states before running the initialization batch as those
|
|
|
|
|
|
* structures are referenced.
|
|
|
|
|
|
*/
|
2023-10-19 17:40:08 -07:00
|
|
|
|
if (device->info->ver >= 12 && device->info->ver < 30) {
|
2021-02-05 21:16:38 +02:00
|
|
|
|
uint32_t n_cps_states = 3 * 3; /* All combinaisons of X by Y CP sizes (1, 2, 4) */
|
|
|
|
|
|
|
2022-08-04 12:56:17 -07:00
|
|
|
|
if (device->info->has_coarse_pixel_primitive_and_cb)
|
2021-02-05 21:16:38 +02:00
|
|
|
|
n_cps_states *= 5 * 5; /* 5 combiners by 2 operators */
|
|
|
|
|
|
|
|
|
|
|
|
n_cps_states += 1; /* Disable CPS */
|
|
|
|
|
|
|
|
|
|
|
|
/* Each of the combinaison must be replicated on all viewports */
|
|
|
|
|
|
n_cps_states *= MAX_VIEWPORTS;
|
|
|
|
|
|
|
|
|
|
|
|
device->cps_states =
|
|
|
|
|
|
anv_state_pool_alloc(&device->dynamic_state_pool,
|
2022-08-04 12:56:17 -07:00
|
|
|
|
n_cps_states * CPS_STATE_length(device->info) * 4,
|
2021-02-05 21:16:38 +02:00
|
|
|
|
32);
|
|
|
|
|
|
if (device->cps_states.map == NULL)
|
|
|
|
|
|
goto fail_trivial_batch;
|
|
|
|
|
|
|
2022-08-04 12:56:17 -07:00
|
|
|
|
anv_genX(device->info, init_cps_device_state)(device);
|
2021-02-05 21:16:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-24 11:45:04 +02:00
|
|
|
|
if (device->physical->indirect_descriptors) {
|
|
|
|
|
|
/* Allocate a null surface state at surface state offset 0. This makes
|
|
|
|
|
|
* NULL descriptor handling trivial because we can just memset
|
|
|
|
|
|
* structures to zero and they have a valid descriptor.
|
|
|
|
|
|
*/
|
|
|
|
|
|
device->null_surface_state =
|
|
|
|
|
|
anv_state_pool_alloc(&device->bindless_surface_state_pool,
|
|
|
|
|
|
device->isl_dev.ss.size,
|
|
|
|
|
|
device->isl_dev.ss.align);
|
|
|
|
|
|
isl_null_fill_state(&device->isl_dev, device->null_surface_state.map,
|
|
|
|
|
|
.size = isl_extent3d(1, 1, 1) /* This shouldn't matter */);
|
|
|
|
|
|
assert(device->null_surface_state.offset == 0);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* When using direct descriptors, those can hold the null surface state
|
|
|
|
|
|
* directly. We still need a null surface for the binding table entries
|
|
|
|
|
|
* though but this one can live anywhere the internal surface state
|
|
|
|
|
|
* pool.
|
|
|
|
|
|
*/
|
|
|
|
|
|
device->null_surface_state =
|
|
|
|
|
|
anv_state_pool_alloc(&device->internal_surface_state_pool,
|
|
|
|
|
|
device->isl_dev.ss.size,
|
|
|
|
|
|
device->isl_dev.ss.align);
|
|
|
|
|
|
isl_null_fill_state(&device->isl_dev, device->null_surface_state.map,
|
|
|
|
|
|
.size = isl_extent3d(1, 1, 1) /* This shouldn't matter */);
|
|
|
|
|
|
}
|
2020-02-06 21:18:59 -06:00
|
|
|
|
|
2024-02-12 12:39:41 +02:00
|
|
|
|
isl_null_fill_state(&device->isl_dev, &device->host_null_surface_state,
|
|
|
|
|
|
.size = isl_extent3d(1, 1, 1) /* This shouldn't matter */);
|
|
|
|
|
|
|
2024-06-19 09:06:35 +03:00
|
|
|
|
anv_scratch_pool_init(device, &device->scratch_pool, false);
|
|
|
|
|
|
anv_scratch_pool_init(device, &device->protected_scratch_pool, true);
|
2015-06-19 15:41:30 -07:00
|
|
|
|
|
2020-08-06 22:53:06 -05:00
|
|
|
|
/* TODO(RT): Do we want some sort of data structure for this? */
|
|
|
|
|
|
memset(device->rt_scratch_bos, 0, sizeof(device->rt_scratch_bos));
|
|
|
|
|
|
|
2020-05-13 15:45:06 -05:00
|
|
|
|
if (ANV_SUPPORT_RT && device->info->has_ray_tracing) {
|
2020-11-09 15:33:17 -06:00
|
|
|
|
/* The docs say to always allocate 128KB per DSS */
|
|
|
|
|
|
const uint32_t btd_fifo_bo_size =
|
|
|
|
|
|
128 * 1024 * intel_device_info_dual_subslice_id_bound(device->info);
|
|
|
|
|
|
result = anv_device_alloc_bo(device,
|
|
|
|
|
|
"rt-btd-fifo",
|
|
|
|
|
|
btd_fifo_bo_size,
|
2023-12-29 12:06:39 +02:00
|
|
|
|
ANV_BO_ALLOC_INTERNAL,
|
2020-11-09 15:33:17 -06:00
|
|
|
|
0 /* explicit_address */,
|
|
|
|
|
|
&device->btd_fifo_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC(&device->vk.base, device->btd_fifo_bo, result);
|
2020-11-09 15:33:17 -06:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_trivial_batch_bo_and_scratch_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-20 08:21:55 +03:00
|
|
|
|
struct vk_pipeline_cache_create_info pcc_info = { .weak_ref = true, };
|
2024-05-17 10:09:16 +03:00
|
|
|
|
device->vk.mem_cache =
|
2021-10-04 13:38:19 -05:00
|
|
|
|
vk_pipeline_cache_create(&device->vk, &pcc_info, NULL);
|
2024-05-17 10:09:16 +03:00
|
|
|
|
if (!device->vk.mem_cache) {
|
2021-10-04 13:38:19 -05:00
|
|
|
|
result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2024-05-06 10:42:46 +03:00
|
|
|
|
goto fail_btd_fifo_bo;
|
2021-10-04 13:38:19 -05:00
|
|
|
|
}
|
2018-06-29 17:29:35 -07:00
|
|
|
|
|
2022-05-27 11:27:55 +03:00
|
|
|
|
/* Internal shaders need their own pipeline cache because, unlike the rest
|
|
|
|
|
|
* of ANV, it won't work at all without the cache. It depends on it for
|
|
|
|
|
|
* shaders to remain resident while it runs. Therefore, we need a special
|
|
|
|
|
|
* cache just for BLORP/RT that's forced to always be enabled.
|
|
|
|
|
|
*/
|
2024-05-20 08:21:55 +03:00
|
|
|
|
struct vk_pipeline_cache_create_info internal_pcc_info = {
|
|
|
|
|
|
.force_enable = true,
|
|
|
|
|
|
.weak_ref = false,
|
|
|
|
|
|
};
|
2022-05-27 11:27:55 +03:00
|
|
|
|
device->internal_cache =
|
2024-05-20 08:21:55 +03:00
|
|
|
|
vk_pipeline_cache_create(&device->vk, &internal_pcc_info, NULL);
|
2022-05-27 11:27:55 +03:00
|
|
|
|
if (device->internal_cache == NULL) {
|
|
|
|
|
|
result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2021-10-04 14:13:33 -05:00
|
|
|
|
goto fail_default_pipeline_cache;
|
2022-05-27 11:27:55 +03:00
|
|
|
|
}
|
2021-04-02 17:03:13 +03:00
|
|
|
|
|
2026-04-06 22:22:29 +03:00
|
|
|
|
if (anv_needs_printf_buffer()) {
|
2023-09-07 18:59:15 +03:00
|
|
|
|
result = anv_device_print_init(device);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_internal_cache;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-22 00:22:22 +02:00
|
|
|
|
device->robust_buffer_access =
|
|
|
|
|
|
device->vk.enabled_features.robustBufferAccess ||
|
|
|
|
|
|
device->vk.enabled_features.nullDescriptor;
|
|
|
|
|
|
|
2023-07-19 19:04:21 -07:00
|
|
|
|
device->breakpoint = anv_state_pool_alloc(&device->dynamic_state_pool, 4,
|
|
|
|
|
|
4);
|
|
|
|
|
|
p_atomic_set(&device->draw_call_count, 0);
|
2025-05-03 01:31:15 +00:00
|
|
|
|
p_atomic_set(&device->dispatch_call_count, 0);
|
2023-07-19 19:04:21 -07:00
|
|
|
|
|
2023-05-11 11:41:39 -07:00
|
|
|
|
/* Create a separate command pool for companion RCS command buffer. */
|
|
|
|
|
|
if (device->info->verx10 >= 125) {
|
|
|
|
|
|
VkCommandPoolCreateInfo pool_info = {
|
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
|
|
|
|
|
.queueFamilyIndex =
|
|
|
|
|
|
anv_get_first_render_queue_index(device->physical),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vk_common_CreateCommandPool(anv_device_to_handle(device),
|
|
|
|
|
|
&pool_info, NULL,
|
|
|
|
|
|
&device->companion_rcs_cmd_pool);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
2024-04-29 17:40:56 +03:00
|
|
|
|
goto fail_print;
|
2023-05-11 11:41:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
result = anv_device_init_trtt(device);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_companion_cmd_pool;
|
|
|
|
|
|
|
2024-04-29 17:40:56 +03:00
|
|
|
|
result = anv_device_init_rt_shaders(device);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
|
result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
goto fail_trtt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 14:58:40 +03:00
|
|
|
|
result = anv_device_init_shader_dump(device);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
|
result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
goto fail_rt_shaders;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-27 11:27:55 +03:00
|
|
|
|
anv_device_init_blorp(device);
|
|
|
|
|
|
|
2015-05-29 16:06:06 -07:00
|
|
|
|
anv_device_init_border_colors(device);
|
|
|
|
|
|
|
2023-05-16 16:10:31 +03:00
|
|
|
|
anv_device_init_internal_kernels(device);
|
2022-02-25 16:56:04 +02:00
|
|
|
|
|
2023-09-28 09:40:36 -07:00
|
|
|
|
anv_device_init_astc_emu(device);
|
|
|
|
|
|
|
2018-06-07 18:02:03 +01:00
|
|
|
|
anv_device_perf_init(device);
|
|
|
|
|
|
|
2024-04-22 20:27:08 +03:00
|
|
|
|
anv_device_init_embedded_samplers(device);
|
|
|
|
|
|
|
2025-05-22 13:21:00 +03:00
|
|
|
|
anv_device_init_descriptors_view(device);
|
|
|
|
|
|
|
2023-08-02 11:36:39 +03:00
|
|
|
|
BITSET_ONES(device->gfx_dirty_state);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_INDEX_BUFFER);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_SO_DECL_LIST);
|
|
|
|
|
|
if (device->info->ver < 11)
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_VF_SGVS_2);
|
|
|
|
|
|
if (device->info->ver < 12) {
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_PRIMITIVE_REPLICATION);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_DEPTH_BOUNDS);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!device->vk.enabled_extensions.EXT_sample_locations)
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_SAMPLE_PATTERN);
|
2023-10-19 17:40:08 -07:00
|
|
|
|
if (!device->vk.enabled_extensions.KHR_fragment_shading_rate) {
|
2025-09-19 00:11:36 +03:00
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_CPS);
|
2023-10-19 17:40:08 -07:00
|
|
|
|
}
|
2023-08-02 11:36:39 +03:00
|
|
|
|
if (!device->vk.enabled_extensions.EXT_mesh_shader) {
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_SBE_MESH);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_CLIP_MESH);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_MESH_CONTROL);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_MESH_SHADER);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_MESH_DISTRIB);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_TASK_CONTROL);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_TASK_SHADER);
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_TASK_REDISTRIB);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!intel_needs_workaround(device->info, 18019816803))
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_WA_18019816803);
|
2023-09-06 08:01:25 +03:00
|
|
|
|
if (!intel_needs_workaround(device->info, 14018283232))
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_WA_14018283232);
|
2023-08-02 11:36:39 +03:00
|
|
|
|
if (device->info->ver > 9)
|
|
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_PMA_FIX);
|
|
|
|
|
|
|
2025-09-01 15:47:37 +03:00
|
|
|
|
BITSET_CLEAR(device->gfx_dirty_state, ANV_GFX_STATE_WA_14024997852);
|
|
|
|
|
|
|
2024-04-29 17:40:56 +03:00
|
|
|
|
device->queue_count = 0;
|
|
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
|
|
|
|
|
|
const VkDeviceQueueCreateInfo *queueCreateInfo =
|
|
|
|
|
|
&pCreateInfo->pQueueCreateInfos[i];
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < queueCreateInfo->queueCount; j++) {
|
|
|
|
|
|
result = anv_queue_init(device, &device->queues[device->queue_count],
|
|
|
|
|
|
queueCreateInfo, j);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_queues;
|
|
|
|
|
|
|
|
|
|
|
|
device->queue_count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
anv_device_utrace_init(device);
|
|
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
result = vk_meta_device_init(&device->vk, &device->meta_device);
|
2024-04-29 11:50:56 +03:00
|
|
|
|
if (result != VK_SUCCESS)
|
2024-04-29 17:40:56 +03:00
|
|
|
|
goto fail_utrace;
|
2024-04-29 11:50:56 +03:00
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
result = anv_genX(device->info, init_device_state)(device);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail_meta_device;
|
|
|
|
|
|
|
2025-12-23 23:05:47 +00:00
|
|
|
|
device->vk.disable_lto = device->physical->instance->disable_lto;
|
|
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
simple_mtx_init(&device->accel_struct_build.mutex, mtx_plain);
|
2026-01-16 09:48:45 +02:00
|
|
|
|
simple_mtx_init(&device->fp64_mutex, mtx_plain);
|
2024-06-12 18:06:22 -07:00
|
|
|
|
|
2015-07-09 18:41:27 -07:00
|
|
|
|
*pDevice = anv_device_to_handle(device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
fail_meta_device:
|
|
|
|
|
|
vk_meta_device_finish(&device->vk, &device->meta_device);
|
2024-04-29 17:40:56 +03:00
|
|
|
|
fail_utrace:
|
2024-04-29 11:50:56 +03:00
|
|
|
|
anv_device_utrace_finish(device);
|
2024-04-29 17:40:56 +03:00
|
|
|
|
fail_queues:
|
|
|
|
|
|
for (uint32_t i = 0; i < device->queue_count; i++)
|
|
|
|
|
|
anv_queue_finish(&device->queues[i]);
|
2025-05-22 13:21:00 +03:00
|
|
|
|
anv_device_finish_descriptors_view(device);
|
2024-04-29 17:40:56 +03:00
|
|
|
|
anv_device_finish_embedded_samplers(device);
|
2024-04-29 11:50:56 +03:00
|
|
|
|
anv_device_finish_blorp(device);
|
|
|
|
|
|
anv_device_finish_astc_emu(device);
|
|
|
|
|
|
anv_device_finish_internal_kernels(device);
|
2026-04-28 14:58:40 +03:00
|
|
|
|
anv_device_finish_shader_dump(device);
|
|
|
|
|
|
fail_rt_shaders:
|
2024-04-29 17:40:56 +03:00
|
|
|
|
anv_device_finish_rt_shaders(device);
|
|
|
|
|
|
fail_trtt:
|
|
|
|
|
|
anv_device_finish_trtt(device);
|
2024-04-29 11:37:03 +03:00
|
|
|
|
fail_companion_cmd_pool:
|
2024-04-29 11:50:56 +03:00
|
|
|
|
if (device->info->verx10 >= 125) {
|
|
|
|
|
|
vk_common_DestroyCommandPool(anv_device_to_handle(device),
|
|
|
|
|
|
device->companion_rcs_cmd_pool, NULL);
|
|
|
|
|
|
}
|
2023-09-07 18:59:15 +03:00
|
|
|
|
fail_print:
|
2026-04-06 22:22:29 +03:00
|
|
|
|
if (anv_needs_printf_buffer())
|
2023-09-07 18:59:15 +03:00
|
|
|
|
anv_device_print_fini(device);
|
2022-05-27 11:27:55 +03:00
|
|
|
|
fail_internal_cache:
|
|
|
|
|
|
vk_pipeline_cache_destroy(device->internal_cache, NULL);
|
2021-10-04 14:13:33 -05:00
|
|
|
|
fail_default_pipeline_cache:
|
2024-05-17 10:09:16 +03:00
|
|
|
|
vk_pipeline_cache_destroy(device->vk.mem_cache, NULL);
|
2020-11-09 15:33:17 -06:00
|
|
|
|
fail_btd_fifo_bo:
|
2025-02-17 10:07:04 +00:00
|
|
|
|
if (ANV_SUPPORT_RT && device->info->has_ray_tracing) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->btd_fifo_bo);
|
2020-11-09 15:33:17 -06:00
|
|
|
|
anv_device_release_bo(device, device->btd_fifo_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
2021-04-07 14:05:21 -07:00
|
|
|
|
fail_trivial_batch_bo_and_scratch_pool:
|
2019-12-25 22:08:51 +02:00
|
|
|
|
anv_scratch_pool_finish(device, &device->scratch_pool);
|
2024-06-19 09:06:35 +03:00
|
|
|
|
anv_scratch_pool_finish(device, &device->protected_scratch_pool);
|
2021-02-05 21:16:38 +02:00
|
|
|
|
fail_trivial_batch:
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->trivial_batch_bo);
|
2019-10-28 17:28:09 -05:00
|
|
|
|
anv_device_release_bo(device, device->trivial_batch_bo);
|
2026-01-21 13:31:39 -08:00
|
|
|
|
fail_ray_query_bo:
|
|
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(device->ray_query_bo); i++) {
|
|
|
|
|
|
if (device->ray_query_bo[i]) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->ray_query_bo[i]);
|
|
|
|
|
|
anv_device_release_bo(device, device->ray_query_bo[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-16 10:39:22 -08:00
|
|
|
|
fail_alloc_device_bo:
|
2025-02-17 10:07:04 +00:00
|
|
|
|
if (device->mem_fence_bo) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->mem_fence_bo);
|
2024-12-16 10:39:22 -08:00
|
|
|
|
anv_device_release_bo(device, device->mem_fence_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (device->dummy_aux_bo) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->dummy_aux_bo);
|
2023-08-16 09:27:44 -07:00
|
|
|
|
anv_device_release_bo(device, device->dummy_aux_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->workaround_bo);
|
2019-12-25 22:08:51 +02:00
|
|
|
|
anv_device_release_bo(device, device->workaround_bo);
|
2018-03-28 01:42:50 -07:00
|
|
|
|
fail_surface_aux_map_pool:
|
2022-08-04 12:56:17 -07:00
|
|
|
|
if (device->info->has_aux_map) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
intel_aux_map_finish(device->aux_map_ctx);
|
2018-03-28 01:42:50 -07:00
|
|
|
|
device->aux_map_ctx = NULL;
|
|
|
|
|
|
}
|
2023-10-24 22:31:11 +03:00
|
|
|
|
fail_aux_tt_pool:
|
2026-04-17 12:25:06 -07:00
|
|
|
|
anv_state_pools_finish(device);
|
2016-11-30 06:59:15 +09:00
|
|
|
|
fail_batch_bo_pool:
|
2023-10-19 09:46:14 +03:00
|
|
|
|
if (device->vk.enabled_extensions.KHR_acceleration_structure)
|
|
|
|
|
|
anv_bo_pool_finish(&device->bvh_bo_pool);
|
2016-11-30 06:59:15 +09:00
|
|
|
|
anv_bo_pool_finish(&device->batch_bo_pool);
|
2025-07-30 16:51:13 -07:00
|
|
|
|
anv_slab_bo_deinit(device);
|
|
|
|
|
|
fail_cache:
|
2019-10-28 15:42:20 -05:00
|
|
|
|
anv_bo_cache_finish(&device->bo_cache);
|
2026-02-06 16:12:29 -08:00
|
|
|
|
fail_null_vma_init:
|
|
|
|
|
|
anv_device_bind_null_va(device,
|
|
|
|
|
|
&device->physical->va.null_initialized_heap,
|
|
|
|
|
|
ANV_VM_UNBIND);
|
2016-11-30 06:59:15 +09:00
|
|
|
|
fail_mutex:
|
|
|
|
|
|
pthread_mutex_destroy(&device->mutex);
|
2019-10-18 15:28:30 +03:00
|
|
|
|
fail_vmas:
|
2025-06-30 13:25:50 -07:00
|
|
|
|
anv_device_finish_vma_heaps(device);
|
2024-04-29 17:40:56 +03:00
|
|
|
|
fail_queues_alloc:
|
2018-08-14 02:34:16 -07:00
|
|
|
|
vk_free(&device->vk.alloc, device->queues);
|
2019-10-22 15:34:12 +03:00
|
|
|
|
fail_context_id:
|
2023-02-09 08:44:04 -08:00
|
|
|
|
anv_device_destroy_context_or_vm(device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
fail_fd:
|
2025-11-17 03:52:43 +03:00
|
|
|
|
intel_virtio_unref_fd(device->fd);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
close(device->fd);
|
|
|
|
|
|
fail_device:
|
2021-01-23 04:33:02 -06:00
|
|
|
|
vk_device_finish(&device->vk);
|
2021-01-24 09:26:24 -06:00
|
|
|
|
fail_alloc:
|
2020-04-21 12:42:59 -05:00
|
|
|
|
vk_free(&device->vk.alloc, device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2016-01-03 22:43:47 -08:00
|
|
|
|
return result;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 20:50:51 -07:00
|
|
|
|
void anv_DestroyDevice(
|
2015-12-02 03:28:27 -08:00
|
|
|
|
VkDevice _device,
|
|
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
{
|
2015-07-09 18:20:10 -07:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2017-03-01 08:39:49 -08:00
|
|
|
|
if (!device)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2026-04-15 14:11:11 +03:00
|
|
|
|
if (anv_needs_printf_buffer())
|
|
|
|
|
|
vk_check_printf_status(&device->vk, &device->printf);
|
|
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
|
anv_memory_trace_finish(device);
|
|
|
|
|
|
|
2023-01-30 14:46:26 -08:00
|
|
|
|
struct anv_physical_device *pdevice = device->physical;
|
|
|
|
|
|
|
2024-04-29 11:37:03 +03:00
|
|
|
|
/* Do TRTT batch garbage collection before destroying queues. */
|
2024-05-06 10:42:46 +03:00
|
|
|
|
anv_device_finish_trtt(device);
|
|
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
if (device->accel_struct_build.radix_sort) {
|
|
|
|
|
|
radix_sort_vk_destroy(device->accel_struct_build.radix_sort,
|
|
|
|
|
|
_device, &device->vk.alloc);
|
|
|
|
|
|
}
|
|
|
|
|
|
vk_meta_device_finish(&device->vk, &device->meta_device);
|
|
|
|
|
|
|
2024-04-29 17:40:56 +03:00
|
|
|
|
anv_device_utrace_finish(device);
|
|
|
|
|
|
|
2023-10-19 11:00:49 +03:00
|
|
|
|
for (uint32_t i = 0; i < device->queue_count; i++)
|
|
|
|
|
|
anv_queue_finish(&device->queues[i]);
|
|
|
|
|
|
vk_free(&device->vk.alloc, device->queues);
|
|
|
|
|
|
|
2016-08-22 21:37:28 -07:00
|
|
|
|
anv_device_finish_blorp(device);
|
|
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
anv_device_finish_rt_shaders(device);
|
|
|
|
|
|
|
2023-09-28 09:40:36 -07:00
|
|
|
|
anv_device_finish_astc_emu(device);
|
|
|
|
|
|
|
2023-05-16 16:10:31 +03:00
|
|
|
|
anv_device_finish_internal_kernels(device);
|
2022-02-25 16:56:04 +02:00
|
|
|
|
|
2025-05-22 13:21:00 +03:00
|
|
|
|
anv_device_finish_descriptors_view(device);
|
|
|
|
|
|
|
2026-04-06 22:22:29 +03:00
|
|
|
|
if (anv_needs_printf_buffer())
|
2023-09-07 18:59:15 +03:00
|
|
|
|
anv_device_print_fini(device);
|
|
|
|
|
|
|
2022-05-27 11:27:55 +03:00
|
|
|
|
vk_pipeline_cache_destroy(device->internal_cache, NULL);
|
2024-05-17 10:09:16 +03:00
|
|
|
|
vk_pipeline_cache_destroy(device->vk.mem_cache, NULL);
|
2018-06-29 17:29:35 -07:00
|
|
|
|
|
2024-04-22 20:27:08 +03:00
|
|
|
|
anv_device_finish_embedded_samplers(device);
|
|
|
|
|
|
|
2025-02-17 10:07:04 +00:00
|
|
|
|
if (ANV_SUPPORT_RT && device->info->has_ray_tracing) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->btd_fifo_bo);
|
2020-11-09 15:33:17 -06:00
|
|
|
|
anv_device_release_bo(device, device->btd_fifo_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
2020-11-09 15:33:17 -06:00
|
|
|
|
|
2023-05-11 11:41:39 -07:00
|
|
|
|
if (device->info->verx10 >= 125) {
|
|
|
|
|
|
vk_common_DestroyCommandPool(anv_device_to_handle(device),
|
|
|
|
|
|
device->companion_rcs_cmd_pool, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-09 11:41:31 -07:00
|
|
|
|
#ifdef HAVE_VALGRIND
|
|
|
|
|
|
/* We only need to free these to prevent valgrind errors. The backing
|
|
|
|
|
|
* BO will go away in a couple of lines so we don't actually leak.
|
|
|
|
|
|
*/
|
2015-07-08 11:44:52 -07:00
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, device->border_colors);
|
2019-07-22 10:56:53 -07:00
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, device->slice_hash);
|
2021-02-05 21:16:38 +02:00
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, device->cps_states);
|
2023-07-19 19:04:21 -07:00
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, device->breakpoint);
|
2015-06-09 11:41:31 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-08-06 22:53:06 -05:00
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(device->rt_scratch_bos); i++) {
|
2025-02-17 10:07:04 +00:00
|
|
|
|
if (device->rt_scratch_bos[i] != NULL) {
|
|
|
|
|
|
struct anv_bo *bo = device->rt_scratch_bos[i];
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, bo);
|
|
|
|
|
|
anv_device_release_bo(device, bo);
|
|
|
|
|
|
}
|
2020-08-06 22:53:06 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-25 23:34:46 +09:00
|
|
|
|
anv_scratch_pool_finish(device, &device->scratch_pool);
|
2024-06-19 09:06:35 +03:00
|
|
|
|
anv_scratch_pool_finish(device, &device->protected_scratch_pool);
|
2016-11-25 23:34:46 +09:00
|
|
|
|
|
2021-06-08 16:24:54 +03:00
|
|
|
|
if (device->vk.enabled_extensions.KHR_ray_query) {
|
2026-01-21 13:31:39 -08:00
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(device->ray_query_bo); i++) {
|
|
|
|
|
|
for (unsigned j = 0; j < ARRAY_SIZE(device->ray_query_shadow_bos[0]); j++) {
|
|
|
|
|
|
if (device->ray_query_shadow_bos[i][j] != NULL) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->ray_query_shadow_bos[i][j]);
|
|
|
|
|
|
anv_device_release_bo(device, device->ray_query_shadow_bos[i][j]);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
2024-11-04 10:30:41 +02:00
|
|
|
|
}
|
2026-01-21 13:31:39 -08:00
|
|
|
|
if (device->ray_query_bo[i]) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->ray_query_bo[i]);
|
|
|
|
|
|
anv_device_release_bo(device, device->ray_query_bo[i]);
|
|
|
|
|
|
}
|
2021-06-08 16:24:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->workaround_bo);
|
2019-10-28 17:28:09 -05:00
|
|
|
|
anv_device_release_bo(device, device->workaround_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
if (device->dummy_aux_bo) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->dummy_aux_bo);
|
2023-08-16 09:27:44 -07:00
|
|
|
|
anv_device_release_bo(device, device->dummy_aux_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (device->mem_fence_bo) {
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->mem_fence_bo);
|
2024-12-16 10:39:22 -08:00
|
|
|
|
anv_device_release_bo(device, device->mem_fence_bo);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
ANV_DMR_BO_FREE(&device->vk.base, device->trivial_batch_bo);
|
2019-10-28 17:28:09 -05:00
|
|
|
|
anv_device_release_bo(device, device->trivial_batch_bo);
|
2017-02-27 16:34:13 -08:00
|
|
|
|
|
2022-08-04 12:56:17 -07:00
|
|
|
|
if (device->info->has_aux_map) {
|
2021-03-03 13:49:18 -08:00
|
|
|
|
intel_aux_map_finish(device->aux_map_ctx);
|
2018-03-28 01:42:50 -07:00
|
|
|
|
device->aux_map_ctx = NULL;
|
|
|
|
|
|
}
|
2026-04-17 12:25:06 -07:00
|
|
|
|
anv_state_pools_finish(device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2023-10-19 09:46:14 +03:00
|
|
|
|
if (device->vk.enabled_extensions.KHR_acceleration_structure)
|
|
|
|
|
|
anv_bo_pool_finish(&device->bvh_bo_pool);
|
2016-11-25 23:34:46 +09:00
|
|
|
|
anv_bo_pool_finish(&device->batch_bo_pool);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2025-02-07 04:55:18 -08:00
|
|
|
|
anv_slab_bo_deinit(device);
|
2019-10-28 15:42:20 -05:00
|
|
|
|
anv_bo_cache_finish(&device->bo_cache);
|
|
|
|
|
|
|
2025-06-30 13:25:50 -07:00
|
|
|
|
anv_device_finish_vma_heaps(device);
|
2019-10-18 15:28:30 +03:00
|
|
|
|
|
2016-01-05 11:43:25 -08:00
|
|
|
|
pthread_mutex_destroy(&device->mutex);
|
|
|
|
|
|
|
2024-06-12 18:06:22 -07:00
|
|
|
|
simple_mtx_destroy(&device->accel_struct_build.mutex);
|
2026-01-16 09:48:45 +02:00
|
|
|
|
simple_mtx_destroy(&device->fp64_mutex);
|
2024-06-12 18:06:22 -07:00
|
|
|
|
|
2023-09-25 15:15:05 +03:00
|
|
|
|
ralloc_free(device->fp64_nir);
|
|
|
|
|
|
|
2023-02-09 08:44:04 -08:00
|
|
|
|
anv_device_destroy_context_or_vm(device);
|
2016-11-25 23:34:46 +09:00
|
|
|
|
|
2025-04-23 09:00:50 +03:00
|
|
|
|
if (INTEL_DEBUG(DEBUG_BATCH) || INTEL_DEBUG(DEBUG_BATCH_STATS)) {
|
2023-06-07 00:37:03 +03:00
|
|
|
|
for (unsigned i = 0; i < pdevice->queue.family_count; i++) {
|
|
|
|
|
|
if (INTEL_DEBUG(DEBUG_BATCH_STATS))
|
|
|
|
|
|
intel_batch_print_stats(&device->decoder[i]);
|
2023-01-30 14:46:26 -08:00
|
|
|
|
intel_batch_decode_ctx_finish(&device->decoder[i]);
|
2023-06-07 00:37:03 +03:00
|
|
|
|
}
|
2023-01-30 14:46:26 -08:00
|
|
|
|
}
|
2019-02-23 23:27:17 +00:00
|
|
|
|
|
2016-11-25 23:34:46 +09:00
|
|
|
|
close(device->fd);
|
|
|
|
|
|
|
2020-04-21 12:42:59 -05:00
|
|
|
|
vk_device_finish(&device->vk);
|
|
|
|
|
|
vk_free(&device->vk.alloc, device);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-06 09:25:03 -07:00
|
|
|
|
VkResult anv_EnumerateInstanceLayerProperties(
|
2015-11-30 16:28:36 -08:00
|
|
|
|
uint32_t* pPropertyCount,
|
2015-07-14 16:11:21 -07:00
|
|
|
|
VkLayerProperties* pProperties)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pProperties == NULL) {
|
2015-11-30 16:28:36 -08:00
|
|
|
|
*pPropertyCount = 0;
|
2015-07-14 16:11:21 -07:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* None supported at this time */
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
|
2015-07-14 16:11:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-27 16:03:57 -07:00
|
|
|
|
VkResult
|
|
|
|
|
|
anv_device_wait(struct anv_device *device, struct anv_bo *bo,
|
|
|
|
|
|
int64_t timeout)
|
|
|
|
|
|
{
|
|
|
|
|
|
int ret = anv_gem_wait(device, bo->gem_handle, &timeout);
|
|
|
|
|
|
if (ret == -1 && errno == ETIME) {
|
|
|
|
|
|
return VK_TIMEOUT;
|
|
|
|
|
|
} else if (ret == -1) {
|
|
|
|
|
|
/* We don't know the real error. */
|
2021-10-19 18:44:01 -05:00
|
|
|
|
return vk_device_set_lost(&device->vk, "gem wait failed: %m");
|
2021-11-08 12:53:10 -06:00
|
|
|
|
} else {
|
|
|
|
|
|
return VK_SUCCESS;
|
2017-03-27 16:03:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-06 16:32:49 +02:00
|
|
|
|
static struct util_vma_heap *
|
|
|
|
|
|
anv_vma_heap_for_flags(struct anv_device *device,
|
|
|
|
|
|
enum anv_bo_alloc_flags alloc_flags)
|
|
|
|
|
|
{
|
2023-10-16 16:27:57 -07:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_TRTT)
|
|
|
|
|
|
return &device->vma_trtt;
|
|
|
|
|
|
|
2022-12-06 16:32:49 +02:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_32BIT_ADDRESS)
|
|
|
|
|
|
return &device->vma_lo;
|
|
|
|
|
|
|
2023-02-22 09:00:35 +02:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_DESCRIPTOR_POOL)
|
|
|
|
|
|
return &device->vma_desc;
|
|
|
|
|
|
|
2024-07-05 16:22:10 +03:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_DYNAMIC_VISIBLE_POOL)
|
|
|
|
|
|
return &device->vma_dynamic_visible;
|
2023-10-20 17:33:21 +03:00
|
|
|
|
|
2026-02-06 16:12:29 -08:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_NULL_INITIALIZED_HEAP)
|
|
|
|
|
|
return &device->vma_null_initialized;
|
|
|
|
|
|
|
2022-12-06 16:32:49 +02:00
|
|
|
|
return &device->vma_hi;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-22 16:40:13 -06:00
|
|
|
|
uint64_t
|
|
|
|
|
|
anv_vma_alloc(struct anv_device *device,
|
|
|
|
|
|
uint64_t size, uint64_t align,
|
|
|
|
|
|
enum anv_bo_alloc_flags alloc_flags,
|
2022-12-06 16:32:49 +02:00
|
|
|
|
uint64_t client_address,
|
|
|
|
|
|
struct util_vma_heap **out_vma_heap)
|
2018-03-07 09:18:37 -08:00
|
|
|
|
{
|
|
|
|
|
|
pthread_mutex_lock(&device->vma_mutex);
|
|
|
|
|
|
|
2020-01-22 16:40:13 -06:00
|
|
|
|
uint64_t addr = 0;
|
2022-12-06 16:32:49 +02:00
|
|
|
|
*out_vma_heap = anv_vma_heap_for_flags(device, alloc_flags);
|
2018-03-07 09:18:37 -08:00
|
|
|
|
|
2020-01-22 16:40:13 -06:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) {
|
2023-10-16 16:27:57 -07:00
|
|
|
|
assert(*out_vma_heap == &device->vma_hi ||
|
2024-07-05 16:22:10 +03:00
|
|
|
|
*out_vma_heap == &device->vma_dynamic_visible ||
|
2023-10-16 16:27:57 -07:00
|
|
|
|
*out_vma_heap == &device->vma_trtt);
|
2023-10-13 14:56:03 -07:00
|
|
|
|
|
2019-12-02 16:03:56 -06:00
|
|
|
|
if (client_address) {
|
2022-12-06 16:32:49 +02:00
|
|
|
|
if (util_vma_heap_alloc_addr(*out_vma_heap,
|
2020-01-22 16:40:13 -06:00
|
|
|
|
client_address, size)) {
|
|
|
|
|
|
addr = client_address;
|
2019-12-02 16:03:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2023-10-13 14:56:03 -07:00
|
|
|
|
(*out_vma_heap)->alloc_high = false;
|
2022-12-06 16:32:49 +02:00
|
|
|
|
addr = util_vma_heap_alloc(*out_vma_heap, size, align);
|
2023-10-13 14:56:03 -07:00
|
|
|
|
(*out_vma_heap)->alloc_high = true;
|
2019-12-02 16:03:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
/* We don't want to fall back to other heaps */
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assert(client_address == 0);
|
|
|
|
|
|
|
2022-12-06 16:32:49 +02:00
|
|
|
|
addr = util_vma_heap_alloc(*out_vma_heap, size, align);
|
2018-03-07 09:18:37 -08:00
|
|
|
|
|
2019-12-02 16:03:56 -06:00
|
|
|
|
done:
|
2018-03-07 09:18:37 -08:00
|
|
|
|
pthread_mutex_unlock(&device->vma_mutex);
|
|
|
|
|
|
|
2026-05-05 16:52:58 +03:00
|
|
|
|
if (addr == 0 && client_address) {
|
|
|
|
|
|
mesa_logi("Virtual address allocation failed, "
|
|
|
|
|
|
"consider running with ANV_DEBUG=no-alloc-oversubscription");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
assert(addr == intel_48b_address(addr));
|
|
|
|
|
|
return intel_canonical_address(addr);
|
2018-03-07 09:18:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-01-22 16:40:13 -06:00
|
|
|
|
anv_vma_free(struct anv_device *device,
|
2022-12-06 16:32:49 +02:00
|
|
|
|
struct util_vma_heap *vma_heap,
|
2020-01-22 16:40:13 -06:00
|
|
|
|
uint64_t address, uint64_t size)
|
2018-03-07 09:18:37 -08:00
|
|
|
|
{
|
2022-12-06 16:32:49 +02:00
|
|
|
|
assert(vma_heap == &device->vma_lo ||
|
2023-02-22 09:00:35 +02:00
|
|
|
|
vma_heap == &device->vma_hi ||
|
2023-10-16 16:27:57 -07:00
|
|
|
|
vma_heap == &device->vma_desc ||
|
2024-07-05 16:22:10 +03:00
|
|
|
|
vma_heap == &device->vma_dynamic_visible ||
|
2026-02-06 16:12:29 -08:00
|
|
|
|
vma_heap == &device->vma_trtt ||
|
|
|
|
|
|
vma_heap == &device->vma_null_initialized);
|
2022-12-06 16:32:49 +02:00
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
const uint64_t addr_48b = intel_48b_address(address);
|
2018-03-07 09:18:37 -08:00
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&device->vma_mutex);
|
|
|
|
|
|
|
2022-12-06 16:32:49 +02:00
|
|
|
|
util_vma_heap_free(vma_heap, addr_48b, size);
|
2018-03-07 09:18:37 -08:00
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&device->vma_mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-02 03:28:27 -08:00
|
|
|
|
VkResult anv_AllocateMemory(
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDevice _device,
|
2015-12-02 03:28:27 -08:00
|
|
|
|
const VkMemoryAllocateInfo* pAllocateInfo,
|
|
|
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDeviceMemory* pMem)
|
|
|
|
|
|
{
|
2015-07-09 18:20:10 -07:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2020-01-17 22:23:30 -06:00
|
|
|
|
struct anv_physical_device *pdevice = device->physical;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
struct anv_device_memory *mem;
|
2017-02-28 10:58:40 -08:00
|
|
|
|
VkResult result = VK_SUCCESS;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2015-12-02 03:28:27 -08:00
|
|
|
|
assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2019-12-02 14:37:56 -06:00
|
|
|
|
VkDeviceSize aligned_alloc_size =
|
2022-12-02 14:37:31 +05:30
|
|
|
|
align64(pAllocateInfo->allocationSize, 4096);
|
2017-04-11 08:33:19 -07:00
|
|
|
|
|
2019-12-02 14:37:56 -06:00
|
|
|
|
assert(pAllocateInfo->memoryTypeIndex < pdevice->memory.type_count);
|
2023-01-18 09:01:15 -07:00
|
|
|
|
const struct anv_memory_type *mem_type =
|
2019-12-02 14:37:56 -06:00
|
|
|
|
&pdevice->memory.types[pAllocateInfo->memoryTypeIndex];
|
|
|
|
|
|
assert(mem_type->heapIndex < pdevice->memory.heap_count);
|
|
|
|
|
|
struct anv_memory_heap *mem_heap =
|
|
|
|
|
|
&pdevice->memory.heaps[mem_type->heapIndex];
|
|
|
|
|
|
|
2023-03-14 16:39:34 -07:00
|
|
|
|
if (aligned_alloc_size > mem_heap->size)
|
|
|
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
|
|
|
|
|
|
2019-12-02 14:37:56 -06:00
|
|
|
|
uint64_t mem_heap_used = p_atomic_read(&mem_heap->used);
|
|
|
|
|
|
if (mem_heap_used + aligned_alloc_size > mem_heap->size)
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
2015-07-09 19:59:44 -07:00
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
mem = vk_device_memory_create(&device->vk, pAllocateInfo,
|
|
|
|
|
|
pAllocator, sizeof(*mem));
|
2015-05-08 22:32:37 -07:00
|
|
|
|
if (mem == NULL)
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2019-12-02 14:37:56 -06:00
|
|
|
|
mem->type = mem_type;
|
2021-11-15 11:32:38 -06:00
|
|
|
|
mem->map = NULL;
|
|
|
|
|
|
mem->map_size = 0;
|
|
|
|
|
|
mem->map_delta = 0;
|
2016-11-07 17:25:07 -08:00
|
|
|
|
|
2019-10-25 17:45:28 -05:00
|
|
|
|
enum anv_bo_alloc_flags alloc_flags = 0;
|
2018-05-30 15:34:25 -07:00
|
|
|
|
|
2019-06-26 18:02:19 -05:00
|
|
|
|
const VkImportMemoryFdInfoKHR *fd_info = NULL;
|
|
|
|
|
|
const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL;
|
2024-01-31 12:56:29 -08:00
|
|
|
|
const struct wsi_memory_allocate_info *wsi_info = NULL;
|
2019-12-02 16:28:58 -06:00
|
|
|
|
uint64_t client_address = 0;
|
2018-05-30 15:34:25 -07:00
|
|
|
|
|
2019-06-26 18:02:19 -05:00
|
|
|
|
vk_foreach_struct_const(ext, pAllocateInfo->pNext) {
|
2024-01-31 12:56:29 -08:00
|
|
|
|
/* VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA isn't a real enum
|
|
|
|
|
|
* value, so use cast to avoid compiler warn
|
|
|
|
|
|
*/
|
|
|
|
|
|
switch ((uint32_t)ext->sType) {
|
2023-04-05 10:44:31 +02:00
|
|
|
|
case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO:
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID:
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT:
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR:
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO:
|
|
|
|
|
|
/* handled by vk_device_memory_create */
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-06-26 18:02:19 -05:00
|
|
|
|
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
|
|
|
|
|
|
fd_info = (void *)ext;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
|
|
|
|
|
|
dedicated_info = (void *)ext;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2022-07-01 13:03:31 +01:00
|
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO: {
|
|
|
|
|
|
const VkMemoryOpaqueCaptureAddressAllocateInfo *addr_info =
|
|
|
|
|
|
(const VkMemoryOpaqueCaptureAddressAllocateInfo *)ext;
|
2019-12-02 16:28:58 -06:00
|
|
|
|
client_address = addr_info->opaqueCaptureAddress;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-31 12:56:29 -08:00
|
|
|
|
case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA:
|
|
|
|
|
|
wsi_info = (void *)ext;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-06-26 18:02:19 -05:00
|
|
|
|
default:
|
2024-05-01 13:35:32 -04:00
|
|
|
|
vk_debug_ignored_stype(ext->sType);
|
2019-06-26 18:02:19 -05:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-08 10:20:35 +02:00
|
|
|
|
|
2022-05-02 12:38:16 +03:00
|
|
|
|
/* If i915 reported a mappable/non_mappable vram regions and the
|
|
|
|
|
|
* application want lmem mappable, then we need to use the
|
|
|
|
|
|
* I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS flag to create our BO.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (pdevice->vram_mappable.size > 0 &&
|
|
|
|
|
|
pdevice->vram_non_mappable.size > 0 &&
|
|
|
|
|
|
(mem_type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) &&
|
|
|
|
|
|
(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_LOCAL_MEM_CPU_VISIBLE;
|
|
|
|
|
|
|
2023-04-27 09:35:38 -07:00
|
|
|
|
if (!mem_heap->is_local_mem)
|
2022-09-02 21:53:18 +03:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_NO_LOCAL_MEM;
|
|
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
if (mem->vk.alloc_flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT)
|
2019-12-02 16:28:58 -06:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS;
|
|
|
|
|
|
|
2023-12-08 14:00:28 +02:00
|
|
|
|
if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT)
|
2020-12-04 13:44:37 +02:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_PROTECTED;
|
|
|
|
|
|
|
2024-01-16 14:10:20 +02:00
|
|
|
|
/* For now, always allocated AUX-TT aligned memory, regardless of dedicated
|
|
|
|
|
|
* allocations. An application can for example, suballocate a large
|
|
|
|
|
|
* VkDeviceMemory and try to bind an image created with a CCS modifier. In
|
|
|
|
|
|
* that case we cannot disable CCS if the alignment doesn´t meet the AUX-TT
|
|
|
|
|
|
* requirements, so we need to ensure both the VkDeviceMemory and the
|
|
|
|
|
|
* alignment reported through vkGetImageMemoryRequirements() meet the
|
|
|
|
|
|
* AUX-TT requirement.
|
|
|
|
|
|
*
|
2024-07-22 23:09:08 -07:00
|
|
|
|
* Allocations with the special dynamic_visible mem type are for things like
|
|
|
|
|
|
* descriptor buffers, so AUX-TT alignment is not needed here.
|
2024-01-16 14:10:20 +02:00
|
|
|
|
*/
|
2024-07-22 23:09:08 -07:00
|
|
|
|
if (device->info->has_aux_map && !mem_type->dynamic_visible)
|
2024-01-16 14:10:20 +02:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_AUX_TT_ALIGNED;
|
|
|
|
|
|
|
2024-02-14 09:39:12 +02:00
|
|
|
|
/* If the allocation is not dedicated nor a host pointer, allocate
|
|
|
|
|
|
* additional CCS space.
|
2023-12-27 11:16:50 +02:00
|
|
|
|
*
|
2024-07-22 23:09:08 -07:00
|
|
|
|
* Allocations with the special dynamic_visible mem type are for things like
|
|
|
|
|
|
* descriptor buffers, which don't need any compression.
|
2023-12-27 11:16:50 +02:00
|
|
|
|
*/
|
2024-02-14 09:39:12 +02:00
|
|
|
|
if (device->physical->alloc_aux_tt_mem &&
|
|
|
|
|
|
dedicated_info == NULL &&
|
2024-07-22 23:09:08 -07:00
|
|
|
|
mem->vk.host_ptr == NULL &&
|
|
|
|
|
|
!mem_type->dynamic_visible)
|
2023-12-27 11:16:50 +02:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_AUX_CCS;
|
|
|
|
|
|
|
2024-01-31 12:56:29 -08:00
|
|
|
|
/* TODO: Android, ChromeOS and other applications may need another way to
|
|
|
|
|
|
* allocate buffers that can be scanout to display but it should pretty
|
|
|
|
|
|
* easy to catch those as Xe KMD driver will print warnings in dmesg when
|
|
|
|
|
|
* scanning buffers allocated without proper flag set.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (wsi_info)
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_SCANOUT;
|
|
|
|
|
|
|
2024-07-30 16:45:39 -07:00
|
|
|
|
struct anv_image *image = dedicated_info ?
|
|
|
|
|
|
anv_image_from_handle(dedicated_info->image) :
|
|
|
|
|
|
NULL;
|
2025-07-12 19:14:49 -07:00
|
|
|
|
mem->dedicated_image = image;
|
2024-07-30 16:45:39 -07:00
|
|
|
|
|
2026-01-09 10:48:45 +02:00
|
|
|
|
/* If there is a dedicated image with a modifier, use that to determine
|
|
|
|
|
|
* compression, otherwise use the memory type.
|
|
|
|
|
|
*/
|
2024-07-30 16:45:39 -07:00
|
|
|
|
if (device->info->ver >= 20 && image &&
|
2026-01-09 10:48:45 +02:00
|
|
|
|
image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
|
|
|
|
|
|
const bool needs_compression =
|
|
|
|
|
|
isl_drm_modifier_has_aux(image->vk.drm_format_mod);
|
|
|
|
|
|
assert(!needs_compression || !INTEL_DEBUG(DEBUG_NO_CCS));
|
|
|
|
|
|
alloc_flags |= needs_compression ? ANV_BO_ALLOC_COMPRESSED : 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
alloc_flags |= (mem_type->compressed && !INTEL_DEBUG(DEBUG_NO_CCS)) ?
|
|
|
|
|
|
ANV_BO_ALLOC_COMPRESSED : 0;
|
2024-07-30 16:45:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-31 11:50:00 -08:00
|
|
|
|
/* Anything imported or exported is EXTERNAL */
|
|
|
|
|
|
if (mem->vk.export_handle_types || mem->vk.import_handle_type) {
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_EXTERNAL;
|
|
|
|
|
|
|
|
|
|
|
|
/* wsi has its own way of synchronizing with the compositor */
|
2024-07-30 16:45:39 -07:00
|
|
|
|
if (!wsi_info && image) {
|
2024-01-31 11:50:00 -08:00
|
|
|
|
/* Apply implicit sync to be compatible with clients relying on
|
|
|
|
|
|
* implicit fencing. This matches the behavior in iris i915_batch
|
|
|
|
|
|
* submit. An example client is VA-API (iHD), so only dedicated
|
|
|
|
|
|
* image scenario has to be covered.
|
|
|
|
|
|
*/
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_IMPLICIT_SYNC;
|
2024-01-31 14:59:35 -08:00
|
|
|
|
|
|
|
|
|
|
/* For color attachment, apply IMPLICIT_WRITE so a client on the
|
|
|
|
|
|
* consumer side relying on implicit fencing can have a fence to
|
|
|
|
|
|
* wait for render complete.
|
|
|
|
|
|
*/
|
2025-02-17 21:01:00 +02:00
|
|
|
|
if (pdevice->instance->external_memory_implicit_sync &&
|
|
|
|
|
|
(image->vk.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
|
2024-01-31 14:59:35 -08:00
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_IMPLICIT_WRITE;
|
2024-01-31 11:50:00 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-08 10:20:35 +02:00
|
|
|
|
|
2024-07-05 16:22:10 +03:00
|
|
|
|
if (mem_type->dynamic_visible)
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_DYNAMIC_VISIBLE_POOL;
|
2023-03-03 17:07:44 +02:00
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
if (mem->vk.ahardware_buffer) {
|
2025-10-23 14:14:25 -07:00
|
|
|
|
result = anv_import_ahb_memory(_device, mem);
|
2018-11-08 10:20:35 +02:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
goto success;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-13 12:18:15 -07:00
|
|
|
|
/* The Vulkan spec permits handleType to be 0, in which case the struct is
|
|
|
|
|
|
* ignored.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (fd_info && fd_info->handleType) {
|
2017-11-27 18:33:44 -08:00
|
|
|
|
/* At the moment, we support only the below handle types. */
|
2017-07-13 12:18:15 -07:00
|
|
|
|
assert(fd_info->handleType ==
|
2017-09-20 13:16:26 -07:00
|
|
|
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
2017-11-27 18:33:44 -08:00
|
|
|
|
fd_info->handleType ==
|
|
|
|
|
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
2024-08-24 09:41:54 -07:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_COMPRESSED) {
|
|
|
|
|
|
/* First, when importing a compressed buffer on Xe2+, we are sure
|
|
|
|
|
|
* about that the buffer is from a resource created with modifiers
|
|
|
|
|
|
* supporting compression, even the info of modifier is not available
|
|
|
|
|
|
* on the path of allocation. (Buffers created with modifiers not
|
|
|
|
|
|
* supporting compression must be uncompressed or resolved first
|
|
|
|
|
|
* for sharing.)
|
|
|
|
|
|
*
|
|
|
|
|
|
* We assume the source of the sharing (a GL driver or this driver)
|
|
|
|
|
|
* would create the shared buffer for scanout usage as well by
|
|
|
|
|
|
* following the above reasons. As a result, configure the imported
|
|
|
|
|
|
* buffer for scanout.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Such assumption could fit on pre-Xe2 platforms as well but become
|
|
|
|
|
|
* more relevant on Xe2+ because the alloc flags will determine bo's
|
|
|
|
|
|
* heap and then PAT entry in the later vm_bind stage.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(device->info->ver >= 20);
|
2025-10-28 12:41:40 -04:00
|
|
|
|
assert(image);
|
|
|
|
|
|
if (vk_format_is_color(image->vk.format))
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_SCANOUT;
|
2024-08-24 09:41:54 -07:00
|
|
|
|
}
|
2017-07-13 12:18:15 -07:00
|
|
|
|
|
2019-10-25 17:45:28 -05:00
|
|
|
|
result = anv_device_import_bo(device, fd_info->fd, alloc_flags,
|
2019-12-02 16:28:58 -06:00
|
|
|
|
client_address, &mem->bo);
|
2017-07-13 12:18:15 -07:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail;
|
2017-09-11 16:41:21 -07:00
|
|
|
|
|
anv: Move size check from anv_bo_cache_import() to caller (v2)
This change prepares for VK_ANDROID_native_buffer. When the user imports
a gralloc hande into a VkImage using VK_ANDROID_native_buffer, the user
provides no size. The driver must infer the size from the internals of
the gralloc buffer.
The patch is essentially a refactor patch, but it does change behavior
in some edge cases, described below. In what follows, the "nominal size"
of the bo refers to anv_bo::size, which may not match the bo's "actual
size" according to the kernel.
Post-patch, the nominal size of the bo returned from
anv_bo_cache_import() is always the size of imported dma-buf according
to lseek(). Pre-patch, the bo's nominal size was difficult to predict.
If the imported dma-buf's gem handle was not resident in the cache, then
the bo's nominal size was align(VkMemoryAllocateInfo::allocationSize,
4096). If it *was* resident, then the bo's nominal size was whatever
the cache returned. As a consequence, the first cache insert decided the
bo's nominal size, which could be significantly smaller compared to the
dma-buf's actual size, as the nominal size was determined by
VkMemoryAllocationInfo::allocationSize and not lseek().
I believe this patch cleans up that messy behavior. For an imported or
exported VkDeviceMemory, anv_bo::size should now be the true size of the
bo, if I correctly understand the problem (which I possibly don't).
v2:
- Preserve behavior of aligning size to 4096 before checking. [for
jekstrand]
- Check size with < instead of <=, to match behavior of commit c0a4f56
"anv: bo_cache: allow importing a BO larger than needed". [for
chadv]
2017-09-12 14:05:08 -07:00
|
|
|
|
/* For security purposes, we reject importing the bo if it's smaller
|
|
|
|
|
|
* than the requested allocation size. This prevents a malicious client
|
|
|
|
|
|
* from passing a buffer to a trusted client, lying about the size, and
|
|
|
|
|
|
* telling the trusted client to try and texture from an image that goes
|
|
|
|
|
|
* out-of-bounds. This sort of thing could lead to GPU hangs or worse
|
|
|
|
|
|
* in the trusted client. The trusted client can protect itself against
|
|
|
|
|
|
* this sort of attack but only if it can trust the buffer size.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (mem->bo->size < aligned_alloc_size) {
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
|
anv: Move size check from anv_bo_cache_import() to caller (v2)
This change prepares for VK_ANDROID_native_buffer. When the user imports
a gralloc hande into a VkImage using VK_ANDROID_native_buffer, the user
provides no size. The driver must infer the size from the internals of
the gralloc buffer.
The patch is essentially a refactor patch, but it does change behavior
in some edge cases, described below. In what follows, the "nominal size"
of the bo refers to anv_bo::size, which may not match the bo's "actual
size" according to the kernel.
Post-patch, the nominal size of the bo returned from
anv_bo_cache_import() is always the size of imported dma-buf according
to lseek(). Pre-patch, the bo's nominal size was difficult to predict.
If the imported dma-buf's gem handle was not resident in the cache, then
the bo's nominal size was align(VkMemoryAllocateInfo::allocationSize,
4096). If it *was* resident, then the bo's nominal size was whatever
the cache returned. As a consequence, the first cache insert decided the
bo's nominal size, which could be significantly smaller compared to the
dma-buf's actual size, as the nominal size was determined by
VkMemoryAllocationInfo::allocationSize and not lseek().
I believe this patch cleans up that messy behavior. For an imported or
exported VkDeviceMemory, anv_bo::size should now be the true size of the
bo, if I correctly understand the problem (which I possibly don't).
v2:
- Preserve behavior of aligning size to 4096 before checking. [for
jekstrand]
- Check size with < instead of <=, to match behavior of commit c0a4f56
"anv: bo_cache: allow importing a BO larger than needed". [for
chadv]
2017-09-12 14:05:08 -07:00
|
|
|
|
"aligned allocationSize too large for "
|
2019-01-08 18:04:54 +00:00
|
|
|
|
"VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
|
anv: Move size check from anv_bo_cache_import() to caller (v2)
This change prepares for VK_ANDROID_native_buffer. When the user imports
a gralloc hande into a VkImage using VK_ANDROID_native_buffer, the user
provides no size. The driver must infer the size from the internals of
the gralloc buffer.
The patch is essentially a refactor patch, but it does change behavior
in some edge cases, described below. In what follows, the "nominal size"
of the bo refers to anv_bo::size, which may not match the bo's "actual
size" according to the kernel.
Post-patch, the nominal size of the bo returned from
anv_bo_cache_import() is always the size of imported dma-buf according
to lseek(). Pre-patch, the bo's nominal size was difficult to predict.
If the imported dma-buf's gem handle was not resident in the cache, then
the bo's nominal size was align(VkMemoryAllocateInfo::allocationSize,
4096). If it *was* resident, then the bo's nominal size was whatever
the cache returned. As a consequence, the first cache insert decided the
bo's nominal size, which could be significantly smaller compared to the
dma-buf's actual size, as the nominal size was determined by
VkMemoryAllocationInfo::allocationSize and not lseek().
I believe this patch cleans up that messy behavior. For an imported or
exported VkDeviceMemory, anv_bo::size should now be the true size of the
bo, if I correctly understand the problem (which I possibly don't).
v2:
- Preserve behavior of aligning size to 4096 before checking. [for
jekstrand]
- Check size with < instead of <=, to match behavior of commit c0a4f56
"anv: bo_cache: allow importing a BO larger than needed". [for
chadv]
2017-09-12 14:05:08 -07:00
|
|
|
|
"%"PRIu64"B > %"PRIu64"B",
|
|
|
|
|
|
aligned_alloc_size, mem->bo->size);
|
2019-10-25 17:45:28 -05:00
|
|
|
|
anv_device_release_bo(device, mem->bo);
|
anv: Move size check from anv_bo_cache_import() to caller (v2)
This change prepares for VK_ANDROID_native_buffer. When the user imports
a gralloc hande into a VkImage using VK_ANDROID_native_buffer, the user
provides no size. The driver must infer the size from the internals of
the gralloc buffer.
The patch is essentially a refactor patch, but it does change behavior
in some edge cases, described below. In what follows, the "nominal size"
of the bo refers to anv_bo::size, which may not match the bo's "actual
size" according to the kernel.
Post-patch, the nominal size of the bo returned from
anv_bo_cache_import() is always the size of imported dma-buf according
to lseek(). Pre-patch, the bo's nominal size was difficult to predict.
If the imported dma-buf's gem handle was not resident in the cache, then
the bo's nominal size was align(VkMemoryAllocateInfo::allocationSize,
4096). If it *was* resident, then the bo's nominal size was whatever
the cache returned. As a consequence, the first cache insert decided the
bo's nominal size, which could be significantly smaller compared to the
dma-buf's actual size, as the nominal size was determined by
VkMemoryAllocationInfo::allocationSize and not lseek().
I believe this patch cleans up that messy behavior. For an imported or
exported VkDeviceMemory, anv_bo::size should now be the true size of the
bo, if I correctly understand the problem (which I possibly don't).
v2:
- Preserve behavior of aligning size to 4096 before checking. [for
jekstrand]
- Check size with < instead of <=, to match behavior of commit c0a4f56
"anv: bo_cache: allow importing a BO larger than needed". [for
chadv]
2017-09-12 14:05:08 -07:00
|
|
|
|
goto fail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-11 16:41:21 -07:00
|
|
|
|
/* From the Vulkan spec:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "Importing memory from a file descriptor transfers ownership of
|
|
|
|
|
|
* the file descriptor from the application to the Vulkan
|
|
|
|
|
|
* implementation. The application must not perform any operations on
|
|
|
|
|
|
* the file descriptor after a successful import."
|
|
|
|
|
|
*
|
|
|
|
|
|
* If the import fails, we leave the file descriptor open.
|
|
|
|
|
|
*/
|
|
|
|
|
|
close(fd_info->fd);
|
2018-10-09 09:53:55 +03:00
|
|
|
|
goto success;
|
|
|
|
|
|
}
|
2017-11-28 08:49:29 -08:00
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
if (mem->vk.host_ptr) {
|
|
|
|
|
|
if (mem->vk.import_handle_type ==
|
2019-03-01 13:15:31 -08:00
|
|
|
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT) {
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
|
2019-03-01 13:15:31 -08:00
|
|
|
|
goto fail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
assert(mem->vk.import_handle_type ==
|
2019-03-01 13:15:31 -08:00
|
|
|
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT);
|
|
|
|
|
|
|
2019-10-25 17:45:28 -05:00
|
|
|
|
result = anv_device_import_bo_from_host_ptr(device,
|
2023-03-20 18:00:38 -05:00
|
|
|
|
mem->vk.host_ptr,
|
|
|
|
|
|
mem->vk.size,
|
2019-10-25 17:45:28 -05:00
|
|
|
|
alloc_flags,
|
2019-12-02 16:28:58 -06:00
|
|
|
|
client_address,
|
2019-10-25 17:45:28 -05:00
|
|
|
|
&mem->bo);
|
2019-03-01 13:15:31 -08:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
goto success;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-30 10:05:58 -08:00
|
|
|
|
if (alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT)) {
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_HOST_COHERENT;
|
|
|
|
|
|
} else if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
|
|
|
|
|
|
if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_HOST_COHERENT;
|
|
|
|
|
|
if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_HOST_CACHED;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Required to set some host mode to have a valid pat index set */
|
|
|
|
|
|
alloc_flags |= ANV_BO_ALLOC_HOST_COHERENT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-09 09:53:55 +03:00
|
|
|
|
/* Regular allocate (not importing memory). */
|
2017-11-28 08:49:29 -08:00
|
|
|
|
|
2020-06-17 15:37:33 +03:00
|
|
|
|
result = anv_device_alloc_bo(device, "user", pAllocateInfo->allocationSize,
|
2019-12-02 16:28:58 -06:00
|
|
|
|
alloc_flags, client_address, &mem->bo);
|
2018-10-09 09:53:55 +03:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
2024-07-30 16:45:39 -07:00
|
|
|
|
if (image && image->vk.wsi_legacy_scanout) {
|
2018-10-09 09:53:55 +03:00
|
|
|
|
/* Some legacy (non-modifiers) consumers need the tiling to be set on
|
|
|
|
|
|
* the BO. In this case, we have a dedicated allocation.
|
|
|
|
|
|
*/
|
2024-07-30 16:45:39 -07:00
|
|
|
|
const struct isl_surf *surf = &image->planes[0].primary_surface.isl;
|
|
|
|
|
|
result = anv_device_set_bo_tiling(device, mem->bo,
|
|
|
|
|
|
surf->row_pitch_B,
|
|
|
|
|
|
surf->tiling);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
|
anv_device_release_bo(device, mem->bo);
|
|
|
|
|
|
goto fail;
|
2017-11-28 08:49:29 -08:00
|
|
|
|
}
|
2017-07-13 12:18:15 -07:00
|
|
|
|
}
|
2017-02-28 10:58:40 -08:00
|
|
|
|
|
2018-10-09 09:53:55 +03:00
|
|
|
|
success:
|
2019-12-02 14:37:56 -06:00
|
|
|
|
mem_heap_used = p_atomic_add_return(&mem_heap->used, mem->bo->size);
|
|
|
|
|
|
if (mem_heap_used > mem_heap->size) {
|
|
|
|
|
|
p_atomic_add(&mem_heap->used, -mem->bo->size);
|
|
|
|
|
|
anv_device_release_bo(device, mem->bo);
|
2021-09-24 12:06:32 -05:00
|
|
|
|
result = vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
2019-12-02 14:37:56 -06:00
|
|
|
|
"Out of heap memory");
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-26 18:05:34 -06:00
|
|
|
|
pthread_mutex_lock(&device->mutex);
|
|
|
|
|
|
list_addtail(&mem->link, &device->memory_objects);
|
|
|
|
|
|
pthread_mutex_unlock(&device->mutex);
|
|
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
|
ANV_RMV(heap_create, device, mem, false, 0);
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC_IMPORT(&mem->vk.base, mem->bo, result,
|
|
|
|
|
|
mem->vk.import_handle_type);
|
2023-12-28 12:27:05 +02:00
|
|
|
|
|
2015-07-09 18:41:27 -07:00
|
|
|
|
*pMem = anv_device_memory_to_handle(mem);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2015-07-09 18:20:10 -07:00
|
|
|
|
return VK_SUCCESS;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
fail:
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_ALLOC_IMPORT(&mem->vk.base, mem->bo, result,
|
|
|
|
|
|
mem->vk.import_handle_type);
|
2023-03-20 18:00:38 -05:00
|
|
|
|
vk_device_memory_destroy(&device->vk, pAllocator, &mem->vk);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-13 12:18:15 -07:00
|
|
|
|
VkResult anv_GetMemoryFdKHR(
|
|
|
|
|
|
VkDevice device_h,
|
|
|
|
|
|
const VkMemoryGetFdInfoKHR* pGetFdInfo,
|
|
|
|
|
|
int* pFd)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, dev, device_h);
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, pGetFdInfo->memory);
|
|
|
|
|
|
|
|
|
|
|
|
assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
|
|
|
|
|
|
|
2017-09-20 13:16:26 -07:00
|
|
|
|
assert(pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
2017-11-27 18:33:44 -08:00
|
|
|
|
pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
2017-07-13 12:18:15 -07:00
|
|
|
|
|
2019-10-25 17:45:28 -05:00
|
|
|
|
return anv_device_export_bo(dev, mem->bo, pFd);
|
2017-07-13 12:18:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult anv_GetMemoryFdPropertiesKHR(
|
2017-11-27 18:33:44 -08:00
|
|
|
|
VkDevice _device,
|
2019-01-08 18:04:54 +00:00
|
|
|
|
VkExternalMemoryHandleTypeFlagBits handleType,
|
2017-07-13 12:18:15 -07:00
|
|
|
|
int fd,
|
|
|
|
|
|
VkMemoryFdPropertiesKHR* pMemoryFdProperties)
|
|
|
|
|
|
{
|
2017-11-27 18:33:44 -08:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
|
|
|
|
|
|
switch (handleType) {
|
2017-12-05 21:19:51 +01:00
|
|
|
|
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
|
2017-11-27 18:33:44 -08:00
|
|
|
|
/* dma-buf can be imported as any memory type */
|
|
|
|
|
|
pMemoryFdProperties->memoryTypeBits =
|
2020-01-17 22:23:30 -06:00
|
|
|
|
(1 << device->physical->memory.type_count) - 1;
|
2017-11-27 18:33:44 -08:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
/* The valid usage section for this function says:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "handleType must not be one of the handle types defined as
|
|
|
|
|
|
* opaque."
|
|
|
|
|
|
*
|
|
|
|
|
|
* So opaque handle types fall into the default "unsupported" case.
|
|
|
|
|
|
*/
|
2021-09-24 12:06:32 -05:00
|
|
|
|
return vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
|
2017-11-27 18:33:44 -08:00
|
|
|
|
}
|
2017-07-13 12:18:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 13:15:31 -08:00
|
|
|
|
VkResult anv_GetMemoryHostPointerPropertiesEXT(
|
|
|
|
|
|
VkDevice _device,
|
|
|
|
|
|
VkExternalMemoryHandleTypeFlagBits handleType,
|
|
|
|
|
|
const void* pHostPointer,
|
|
|
|
|
|
VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
|
|
|
|
|
|
assert(pMemoryHostPointerProperties->sType ==
|
|
|
|
|
|
VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT);
|
|
|
|
|
|
|
|
|
|
|
|
switch (handleType) {
|
2020-01-17 22:23:30 -06:00
|
|
|
|
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
|
2025-07-14 14:02:11 -07:00
|
|
|
|
|
2019-03-01 13:15:31 -08:00
|
|
|
|
pMemoryHostPointerProperties->memoryTypeBits =
|
2025-07-14 14:02:11 -07:00
|
|
|
|
device->info->ver >= 20 ?
|
|
|
|
|
|
device->physical->memory.default_buffer_mem_types :
|
2020-01-17 22:23:30 -06:00
|
|
|
|
(1ull << device->physical->memory.type_count) - 1;
|
2019-03-01 13:15:31 -08:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2020-01-17 22:23:30 -06:00
|
|
|
|
|
2019-03-01 13:15:31 -08:00
|
|
|
|
default:
|
|
|
|
|
|
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 20:50:51 -07:00
|
|
|
|
void anv_FreeMemory(
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDevice _device,
|
2015-12-02 03:28:27 -08:00
|
|
|
|
VkDeviceMemory _mem,
|
|
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
{
|
2015-07-09 18:20:10 -07:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2015-12-17 11:00:38 -08:00
|
|
|
|
if (mem == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-02-26 18:05:34 -06:00
|
|
|
|
pthread_mutex_lock(&device->mutex);
|
|
|
|
|
|
list_del(&mem->link);
|
|
|
|
|
|
pthread_mutex_unlock(&device->mutex);
|
|
|
|
|
|
|
2023-03-20 17:02:45 -05:00
|
|
|
|
if (mem->map) {
|
2026-04-28 12:08:54 +03:00
|
|
|
|
const VkMemoryUnmapInfo unmap = {
|
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_MEMORY_UNMAP_INFO,
|
2023-03-20 17:02:45 -05:00
|
|
|
|
.memory = _mem,
|
|
|
|
|
|
};
|
2026-04-28 12:08:54 +03:00
|
|
|
|
anv_UnmapMemory2(_device, &unmap);
|
2023-03-20 17:02:45 -05:00
|
|
|
|
}
|
2021-11-15 11:32:38 -06:00
|
|
|
|
|
2020-01-17 22:23:30 -06:00
|
|
|
|
p_atomic_add(&device->physical->memory.heaps[mem->type->heapIndex].used,
|
2019-05-08 11:39:09 +01:00
|
|
|
|
-mem->bo->size);
|
|
|
|
|
|
|
2025-02-17 10:07:04 +00:00
|
|
|
|
ANV_DMR_BO_FREE_IMPORT(&mem->vk.base, mem->bo,
|
|
|
|
|
|
mem->vk.import_handle_type);
|
|
|
|
|
|
|
2019-10-25 17:45:28 -05:00
|
|
|
|
anv_device_release_bo(device, mem->bo);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2023-12-28 12:27:05 +02:00
|
|
|
|
ANV_RMV(resource_destroy, device, mem);
|
|
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
vk_device_memory_destroy(&device->vk, pAllocator, &mem->vk);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 12:08:54 +03:00
|
|
|
|
VkResult anv_MapMemory2(
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDevice _device,
|
2026-04-28 12:08:54 +03:00
|
|
|
|
const VkMemoryMapInfo* pMemoryMapInfo,
|
2015-05-08 22:32:37 -07:00
|
|
|
|
void** ppData)
|
|
|
|
|
|
{
|
2015-07-09 18:20:10 -07:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2023-03-20 17:02:45 -05:00
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryMapInfo->memory);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2015-12-17 11:00:38 -08:00
|
|
|
|
if (mem == NULL) {
|
|
|
|
|
|
*ppData = NULL;
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
if (mem->vk.host_ptr) {
|
|
|
|
|
|
*ppData = mem->vk.host_ptr + pMemoryMapInfo->offset;
|
2019-03-01 13:15:31 -08:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-02 13:09:44 +03:00
|
|
|
|
/* From the Vulkan spec version 1.0.32 docs for MapMemory:
|
|
|
|
|
|
*
|
|
|
|
|
|
* * memory must have been created with a memory type that reports
|
|
|
|
|
|
* VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (!(mem->type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) {
|
|
|
|
|
|
return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED,
|
|
|
|
|
|
"Memory object not mappable.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
assert(pMemoryMapInfo->size > 0);
|
2023-03-20 17:02:45 -05:00
|
|
|
|
const VkDeviceSize offset = pMemoryMapInfo->offset;
|
2023-03-20 18:00:38 -05:00
|
|
|
|
const VkDeviceSize size =
|
|
|
|
|
|
vk_device_memory_range(&mem->vk, pMemoryMapInfo->offset,
|
|
|
|
|
|
pMemoryMapInfo->size);
|
2016-11-07 17:23:44 -08:00
|
|
|
|
|
2021-10-30 16:32:47 -05:00
|
|
|
|
if (size != (size_t)size) {
|
|
|
|
|
|
return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED,
|
|
|
|
|
|
"requested size 0x%"PRIx64" does not fit in %u bits",
|
|
|
|
|
|
size, (unsigned)(sizeof(size_t) * 8));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* From the Vulkan 1.2.194 spec:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "memory must not be currently host mapped"
|
|
|
|
|
|
*/
|
2021-11-15 11:32:38 -06:00
|
|
|
|
if (mem->map != NULL) {
|
2021-10-30 16:32:47 -05:00
|
|
|
|
return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED,
|
|
|
|
|
|
"Memory object already mapped.");
|
|
|
|
|
|
}
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2024-03-04 15:53:02 +02:00
|
|
|
|
void *placed_addr = NULL;
|
|
|
|
|
|
if (pMemoryMapInfo->flags & VK_MEMORY_MAP_PLACED_BIT_EXT) {
|
|
|
|
|
|
const VkMemoryMapPlacedInfoEXT *placed_info =
|
|
|
|
|
|
vk_find_struct_const(pMemoryMapInfo->pNext, MEMORY_MAP_PLACED_INFO_EXT);
|
|
|
|
|
|
assert(placed_info != NULL);
|
|
|
|
|
|
placed_addr = placed_info->pPlacedAddress;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-30 18:43:34 +03:00
|
|
|
|
uint64_t map_offset, map_size;
|
2025-02-07 04:55:18 -08:00
|
|
|
|
anv_sanitize_map_params(device, mem->bo, offset, size, &map_offset, &map_size);
|
2016-01-01 09:26:06 -08:00
|
|
|
|
|
2021-10-30 17:02:41 -05:00
|
|
|
|
void *map;
|
2024-03-04 15:53:02 +02:00
|
|
|
|
VkResult result = anv_device_map_bo(device, mem->bo, map_offset,
|
|
|
|
|
|
map_size, placed_addr, &map);
|
2021-10-30 17:02:41 -05:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
2016-11-07 17:24:24 -08:00
|
|
|
|
|
2021-11-15 11:32:38 -06:00
|
|
|
|
mem->map = map;
|
|
|
|
|
|
mem->map_size = map_size;
|
2021-10-30 16:57:02 -05:00
|
|
|
|
mem->map_delta = (offset - map_offset);
|
2021-11-15 11:32:38 -06:00
|
|
|
|
*ppData = mem->map + mem->map_delta;
|
2015-11-13 10:12:18 -08:00
|
|
|
|
|
2015-05-08 22:32:37 -07:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 12:08:54 +03:00
|
|
|
|
VkResult anv_UnmapMemory2(
|
2015-05-08 22:32:37 -07:00
|
|
|
|
VkDevice _device,
|
2026-04-28 12:08:54 +03:00
|
|
|
|
const VkMemoryUnmapInfo* pMemoryUnmapInfo)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
{
|
2019-02-20 15:26:43 -08:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2023-03-20 17:02:45 -05:00
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryUnmapInfo->memory);
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
2023-03-20 18:00:38 -05:00
|
|
|
|
if (mem == NULL || mem->vk.host_ptr)
|
2023-03-20 17:02:45 -05:00
|
|
|
|
return VK_SUCCESS;
|
2015-12-17 11:00:38 -08:00
|
|
|
|
|
2024-03-04 15:53:02 +02:00
|
|
|
|
VkResult result =
|
|
|
|
|
|
anv_device_unmap_bo(device, mem->bo, mem->map, mem->map_size,
|
|
|
|
|
|
pMemoryUnmapInfo->flags & VK_MEMORY_UNMAP_RESERVE_BIT_EXT);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
2016-11-07 17:25:07 -08:00
|
|
|
|
|
2021-11-15 11:32:38 -06:00
|
|
|
|
mem->map = NULL;
|
|
|
|
|
|
mem->map_size = 0;
|
2021-10-30 16:57:02 -05:00
|
|
|
|
mem->map_delta = 0;
|
2023-03-20 17:02:45 -05:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-07 17:22:29 -07:00
|
|
|
|
VkResult anv_FlushMappedMemoryRanges(
|
2015-12-01 15:25:07 -08:00
|
|
|
|
VkDevice _device,
|
2015-11-30 21:18:12 -08:00
|
|
|
|
uint32_t memoryRangeCount,
|
|
|
|
|
|
const VkMappedMemoryRange* pMemoryRanges)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
{
|
2022-11-22 07:26:58 -08:00
|
|
|
|
#ifdef SUPPORT_INTEL_INTEGRATED_GPUS
|
2015-12-01 15:25:07 -08:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
|
2023-08-04 11:22:05 -07:00
|
|
|
|
if (!device->physical->memory.need_flush)
|
2015-12-01 15:25:07 -08:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
/* Make sure the writes we're flushing have landed. */
|
2016-01-29 12:10:12 -08:00
|
|
|
|
__builtin_ia32_mfence();
|
2015-12-01 15:25:07 -08:00
|
|
|
|
|
2022-06-12 22:18:45 +03:00
|
|
|
|
for (uint32_t i = 0; i < memoryRangeCount; i++) {
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryRanges[i].memory);
|
2022-07-12 11:21:57 +03:00
|
|
|
|
if (mem->type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
2022-06-12 22:18:45 +03:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2022-07-12 11:21:57 +03:00
|
|
|
|
uint64_t map_offset = pMemoryRanges[i].offset + mem->map_delta;
|
|
|
|
|
|
if (map_offset >= mem->map_size)
|
2022-06-12 22:18:45 +03:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2025-10-10 17:18:33 -04:00
|
|
|
|
util_flush_range(mem->map + map_offset,
|
|
|
|
|
|
MIN2(pMemoryRanges[i].size,
|
|
|
|
|
|
mem->map_size - map_offset));
|
2022-06-12 22:18:45 +03:00
|
|
|
|
}
|
2022-11-22 07:26:58 -08:00
|
|
|
|
#endif
|
2015-05-08 22:32:37 -07:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-07 17:22:29 -07:00
|
|
|
|
VkResult anv_InvalidateMappedMemoryRanges(
|
2015-12-01 15:25:07 -08:00
|
|
|
|
VkDevice _device,
|
2015-11-30 21:18:12 -08:00
|
|
|
|
uint32_t memoryRangeCount,
|
|
|
|
|
|
const VkMappedMemoryRange* pMemoryRanges)
|
2015-05-08 22:32:37 -07:00
|
|
|
|
{
|
2022-11-22 07:26:58 -08:00
|
|
|
|
#ifdef SUPPORT_INTEL_INTEGRATED_GPUS
|
2015-12-01 15:25:07 -08:00
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
|
2023-08-04 11:22:05 -07:00
|
|
|
|
if (!device->physical->memory.need_flush)
|
2015-12-01 15:25:07 -08:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
2022-06-12 22:18:45 +03:00
|
|
|
|
for (uint32_t i = 0; i < memoryRangeCount; i++) {
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryRanges[i].memory);
|
2022-07-12 11:21:57 +03:00
|
|
|
|
if (mem->type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
2022-06-12 22:18:45 +03:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2022-07-12 11:21:57 +03:00
|
|
|
|
uint64_t map_offset = pMemoryRanges[i].offset + mem->map_delta;
|
|
|
|
|
|
if (map_offset >= mem->map_size)
|
2022-06-12 22:18:45 +03:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2025-10-10 17:18:33 -04:00
|
|
|
|
util_flush_inval_range(mem->map + map_offset,
|
2022-06-12 22:18:45 +03:00
|
|
|
|
MIN2(pMemoryRanges[i].size,
|
|
|
|
|
|
mem->map_size - map_offset));
|
|
|
|
|
|
}
|
2015-12-01 15:25:07 -08:00
|
|
|
|
|
|
|
|
|
|
/* Make sure no reads get moved up above the invalidate. */
|
2016-01-29 12:10:12 -08:00
|
|
|
|
__builtin_ia32_mfence();
|
2022-11-22 07:26:58 -08:00
|
|
|
|
#endif
|
2015-12-01 15:25:07 -08:00
|
|
|
|
return VK_SUCCESS;
|
2015-05-08 22:32:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-30 12:21:19 -08:00
|
|
|
|
void anv_GetDeviceMemoryCommitment(
|
2015-07-14 17:06:11 -07:00
|
|
|
|
VkDevice device,
|
|
|
|
|
|
VkDeviceMemory memory,
|
|
|
|
|
|
VkDeviceSize* pCommittedMemoryInBytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
*pCommittedMemoryInBytes = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-23 10:55:09 -07:00
|
|
|
|
static inline VkTimeDomainKHR
|
|
|
|
|
|
anv_get_default_cpu_time_domain(void)
|
2023-08-09 10:06:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
#ifdef CLOCK_MONOTONIC_RAW
|
2026-03-23 10:55:09 -07:00
|
|
|
|
return VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR;
|
2023-08-09 10:06:28 -07:00
|
|
|
|
#else
|
2026-03-23 10:55:09 -07:00
|
|
|
|
return VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR;
|
2023-08-09 10:06:28 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-09 10:49:19 -07:00
|
|
|
|
static inline clockid_t
|
2023-12-11 11:27:07 +02:00
|
|
|
|
vk_time_domain_to_clockid(VkTimeDomainKHR domain)
|
2023-08-09 10:49:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
switch (domain) {
|
|
|
|
|
|
#ifdef CLOCK_MONOTONIC_RAW
|
2023-12-11 11:27:07 +02:00
|
|
|
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR:
|
2023-08-09 10:49:19 -07:00
|
|
|
|
return CLOCK_MONOTONIC_RAW;
|
|
|
|
|
|
#endif
|
2023-12-11 11:27:07 +02:00
|
|
|
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR:
|
2023-08-09 10:49:19 -07:00
|
|
|
|
return CLOCK_MONOTONIC;
|
|
|
|
|
|
default:
|
2025-07-23 09:17:35 +02:00
|
|
|
|
UNREACHABLE("Missing");
|
2023-08-09 10:49:19 -07:00
|
|
|
|
return CLOCK_MONOTONIC;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2023-12-11 11:27:07 +02:00
|
|
|
|
is_cpu_time_domain(VkTimeDomainKHR domain)
|
2023-08-09 10:49:19 -07:00
|
|
|
|
{
|
2023-12-11 11:27:07 +02:00
|
|
|
|
return domain == VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR ||
|
|
|
|
|
|
domain == VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR;
|
2023-08-09 10:49:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2023-12-11 11:27:07 +02:00
|
|
|
|
is_gpu_time_domain(VkTimeDomainKHR domain)
|
2023-08-09 10:49:19 -07:00
|
|
|
|
{
|
2023-12-11 11:27:07 +02:00
|
|
|
|
return domain == VK_TIME_DOMAIN_DEVICE_KHR;
|
2023-08-09 10:49:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 11:39:43 +01:00
|
|
|
|
static VkTimeDomainKHR
|
|
|
|
|
|
get_effective_time_domain(const VkCalibratedTimestampInfoKHR *timestamp)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (timestamp->timeDomain == VK_TIME_DOMAIN_PRESENT_STAGE_LOCAL_EXT) {
|
|
|
|
|
|
const VkSwapchainCalibratedTimestampInfoEXT *swap =
|
|
|
|
|
|
vk_find_struct_const(timestamp->pNext, SWAPCHAIN_CALIBRATED_TIMESTAMP_INFO_EXT);
|
|
|
|
|
|
return wsi_common_get_time_domain(swap->swapchain, swap->presentStage, swap->timeDomainId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return timestamp->timeDomain;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-11 11:27:07 +02:00
|
|
|
|
VkResult anv_GetCalibratedTimestampsKHR(
|
2018-10-11 16:05:18 -07:00
|
|
|
|
VkDevice _device,
|
|
|
|
|
|
uint32_t timestampCount,
|
2023-12-11 11:27:07 +02:00
|
|
|
|
const VkCalibratedTimestampInfoKHR *pTimestampInfos,
|
2018-10-11 16:05:18 -07:00
|
|
|
|
uint64_t *pTimestamps,
|
|
|
|
|
|
uint64_t *pMaxDeviation)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2023-08-09 10:49:19 -07:00
|
|
|
|
const uint64_t timestamp_frequency = device->info->timestamp_frequency;
|
|
|
|
|
|
const uint64_t device_period = DIV_ROUND_UP(1000000000, timestamp_frequency);
|
|
|
|
|
|
uint32_t d, increment;
|
2018-10-11 16:05:18 -07:00
|
|
|
|
uint64_t begin, end;
|
|
|
|
|
|
uint64_t max_clock_period = 0;
|
2023-08-09 10:49:19 -07:00
|
|
|
|
const enum intel_kmd_type kmd_type = device->physical->info.kmd_type;
|
|
|
|
|
|
const bool has_correlate_timestamp = kmd_type == INTEL_KMD_TYPE_XE;
|
2026-03-23 10:55:09 -07:00
|
|
|
|
const VkTimeDomainKHR default_cpu_time_domain = anv_get_default_cpu_time_domain();
|
|
|
|
|
|
const clockid_t default_cpu_clock_id = vk_time_domain_to_clockid(default_cpu_time_domain);
|
2023-08-09 10:49:19 -07:00
|
|
|
|
clockid_t cpu_clock_id = -1;
|
2026-03-23 10:55:09 -07:00
|
|
|
|
VkResult result;
|
2023-08-09 10:49:19 -07:00
|
|
|
|
|
2026-03-23 10:55:09 -07:00
|
|
|
|
result = vk_device_get_timestamp(&device->vk, default_cpu_time_domain, &end);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return vk_error(device, result);
|
|
|
|
|
|
begin = end;
|
2023-08-09 10:49:19 -07:00
|
|
|
|
|
|
|
|
|
|
for (d = 0, increment = 1; d < timestampCount; d += increment) {
|
2026-01-16 11:39:43 +01:00
|
|
|
|
const VkTimeDomainKHR current = get_effective_time_domain(&pTimestampInfos[d]);
|
2023-08-09 10:49:19 -07:00
|
|
|
|
/* If we have a request pattern like this :
|
2023-12-11 11:27:07 +02:00
|
|
|
|
* - domain0 = VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR or VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR
|
|
|
|
|
|
* - domain1 = VK_TIME_DOMAIN_DEVICE_KHR
|
2023-08-09 10:49:19 -07:00
|
|
|
|
* - domain2 = domain0 (optional)
|
|
|
|
|
|
*
|
|
|
|
|
|
* We can combine all of those into a single ioctl for maximum accuracy.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (has_correlate_timestamp && (d + 1) < timestampCount) {
|
2026-01-16 11:39:43 +01:00
|
|
|
|
const VkTimeDomainKHR next = get_effective_time_domain(&pTimestampInfos[d + 1]);
|
2023-08-09 10:49:19 -07:00
|
|
|
|
|
|
|
|
|
|
if ((is_cpu_time_domain(current) && is_gpu_time_domain(next)) ||
|
|
|
|
|
|
(is_gpu_time_domain(current) && is_cpu_time_domain(next))) {
|
|
|
|
|
|
/* We'll consume at least 2 elements. */
|
|
|
|
|
|
increment = 2;
|
|
|
|
|
|
|
|
|
|
|
|
if (is_cpu_time_domain(current))
|
|
|
|
|
|
cpu_clock_id = vk_time_domain_to_clockid(current);
|
|
|
|
|
|
else
|
|
|
|
|
|
cpu_clock_id = vk_time_domain_to_clockid(next);
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t cpu_timestamp, gpu_timestamp, cpu_delta_timestamp, cpu_end_timestamp;
|
|
|
|
|
|
if (!intel_gem_read_correlate_cpu_gpu_timestamp(device->fd,
|
|
|
|
|
|
kmd_type,
|
|
|
|
|
|
INTEL_ENGINE_CLASS_RENDER,
|
|
|
|
|
|
0 /* engine_instance */,
|
|
|
|
|
|
cpu_clock_id,
|
|
|
|
|
|
&cpu_timestamp,
|
|
|
|
|
|
&gpu_timestamp,
|
|
|
|
|
|
&cpu_delta_timestamp))
|
|
|
|
|
|
return vk_device_set_lost(&device->vk, "Failed to read correlate timestamp %m");
|
|
|
|
|
|
|
|
|
|
|
|
cpu_end_timestamp = cpu_timestamp + cpu_delta_timestamp;
|
|
|
|
|
|
if (is_cpu_time_domain(current)) {
|
|
|
|
|
|
pTimestamps[d] = cpu_timestamp;
|
|
|
|
|
|
pTimestamps[d + 1] = gpu_timestamp;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pTimestamps[d] = gpu_timestamp;
|
|
|
|
|
|
pTimestamps[d + 1] = cpu_end_timestamp;
|
|
|
|
|
|
}
|
|
|
|
|
|
max_clock_period = MAX2(max_clock_period, device_period);
|
|
|
|
|
|
|
|
|
|
|
|
/* If we can consume a third element */
|
|
|
|
|
|
if ((d + 2) < timestampCount &&
|
|
|
|
|
|
is_cpu_time_domain(current) &&
|
2026-01-16 11:39:43 +01:00
|
|
|
|
current == get_effective_time_domain(&pTimestampInfos[d + 2])) {
|
2023-08-09 10:49:19 -07:00
|
|
|
|
pTimestamps[d + 2] = cpu_end_timestamp;
|
|
|
|
|
|
increment++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If we're the first element, we can replace begin */
|
2026-03-23 10:55:09 -07:00
|
|
|
|
if (d == 0 && cpu_clock_id == default_cpu_clock_id)
|
2023-08-09 10:49:19 -07:00
|
|
|
|
begin = cpu_timestamp;
|
|
|
|
|
|
|
|
|
|
|
|
/* If we're in the same clock domain as begin/end. We can set the end. */
|
2026-03-23 10:55:09 -07:00
|
|
|
|
if (cpu_clock_id == default_cpu_clock_id)
|
2023-08-09 10:49:19 -07:00
|
|
|
|
end = cpu_end_timestamp;
|
2018-10-11 16:05:18 -07:00
|
|
|
|
|
2023-08-09 10:49:19 -07:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-10-11 16:05:18 -07:00
|
|
|
|
|
2023-08-09 10:49:19 -07:00
|
|
|
|
/* fallback to regular method */
|
|
|
|
|
|
increment = 1;
|
|
|
|
|
|
switch (current) {
|
2023-12-11 11:27:07 +02:00
|
|
|
|
case VK_TIME_DOMAIN_DEVICE_KHR:
|
2022-10-06 13:33:15 -07:00
|
|
|
|
if (!intel_gem_read_render_timestamp(device->fd,
|
|
|
|
|
|
device->info->kmd_type,
|
|
|
|
|
|
&pTimestamps[d])) {
|
2021-10-19 18:44:01 -05:00
|
|
|
|
return vk_device_set_lost(&device->vk, "Failed to read the "
|
|
|
|
|
|
"TIMESTAMP register: %m");
|
2018-10-11 16:05:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
max_clock_period = MAX2(max_clock_period, device_period);
|
|
|
|
|
|
break;
|
2023-12-11 11:27:07 +02:00
|
|
|
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR:
|
2026-03-23 10:55:09 -07:00
|
|
|
|
result = vk_device_get_timestamp(
|
|
|
|
|
|
&device->vk, VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR, &pTimestamps[d]);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return vk_error(device, result);
|
2018-10-11 16:05:18 -07:00
|
|
|
|
max_clock_period = MAX2(max_clock_period, 1);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-09-01 12:13:43 +10:00
|
|
|
|
#ifdef CLOCK_MONOTONIC_RAW
|
2023-12-11 11:27:07 +02:00
|
|
|
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR:
|
2018-10-11 16:05:18 -07:00
|
|
|
|
pTimestamps[d] = begin;
|
|
|
|
|
|
break;
|
2020-09-01 12:13:43 +10:00
|
|
|
|
#endif
|
2018-10-11 16:05:18 -07:00
|
|
|
|
default:
|
|
|
|
|
|
pTimestamps[d] = 0;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 11:39:43 +01:00
|
|
|
|
for (uint32_t i = 0; i < timestampCount; i++) {
|
|
|
|
|
|
if (pTimestampInfos[i].timeDomain == VK_TIME_DOMAIN_PRESENT_STAGE_LOCAL_EXT) {
|
|
|
|
|
|
/* Need to rescale device timestamps to nanoseconds. */
|
|
|
|
|
|
const VkSwapchainCalibratedTimestampInfoEXT *swap =
|
|
|
|
|
|
vk_find_struct_const(pTimestampInfos[i].pNext, SWAPCHAIN_CALIBRATED_TIMESTAMP_INFO_EXT);
|
|
|
|
|
|
if (wsi_common_get_time_domain(swap->swapchain, swap->presentStage, swap->timeDomainId) ==
|
|
|
|
|
|
VK_TIME_DOMAIN_DEVICE_KHR) {
|
|
|
|
|
|
pTimestamps[i] = (uint64_t)((double)pTimestamps[i] * 1e9 / (double)device->physical->info.timestamp_frequency);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Timestamps in QueueOperationsEnd are always derived from a device timestamp,
|
|
|
|
|
|
* even if the reported time domain is not. */
|
|
|
|
|
|
if (swap->presentStage == VK_PRESENT_STAGE_QUEUE_OPERATIONS_END_BIT_EXT)
|
|
|
|
|
|
max_clock_period = MAX2(max_clock_period, device_period);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-09 10:49:19 -07:00
|
|
|
|
/* If last timestamp was not get with has_correlate_timestamp method or
|
|
|
|
|
|
* if it was but last cpu clock is not the default one, get time again
|
|
|
|
|
|
*/
|
2026-03-23 10:55:09 -07:00
|
|
|
|
if (increment == 1 || cpu_clock_id != default_cpu_clock_id) {
|
|
|
|
|
|
result = vk_device_get_timestamp(&device->vk, default_cpu_time_domain, &end);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return vk_error(device, result);
|
|
|
|
|
|
}
|
2018-10-11 16:05:18 -07:00
|
|
|
|
|
2022-08-29 14:29:31 -03:00
|
|
|
|
*pMaxDeviation = vk_time_max_deviation(begin, end, max_clock_period);
|
2018-10-11 16:05:18 -07:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-07 14:07:13 -07:00
|
|
|
|
const struct intel_device_info_pat_entry *
|
|
|
|
|
|
anv_device_get_pat_entry(struct anv_device *device,
|
|
|
|
|
|
enum anv_bo_alloc_flags alloc_flags)
|
|
|
|
|
|
{
|
2024-06-26 17:26:03 -07:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_COMPRESSED) {
|
|
|
|
|
|
/* Compressed PAT entries are available on Xe2+. */
|
|
|
|
|
|
assert(device->info->ver >= 20);
|
|
|
|
|
|
return alloc_flags & ANV_BO_ALLOC_SCANOUT ?
|
|
|
|
|
|
&device->info->pat.compressed_scanout :
|
|
|
|
|
|
&device->info->pat.compressed;
|
|
|
|
|
|
}
|
2024-07-15 07:55:08 -07:00
|
|
|
|
|
2025-07-03 09:47:00 -07:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_IMPORTED)
|
|
|
|
|
|
return &device->info->pat.cached_coherent;
|
|
|
|
|
|
|
2025-01-14 08:11:04 -08:00
|
|
|
|
if (alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT))
|
|
|
|
|
|
return &device->info->pat.scanout;
|
|
|
|
|
|
|
2023-11-22 07:36:36 -08:00
|
|
|
|
/* PAT indexes has no actual effect in DG2 and DG1, smem caches will always
|
|
|
|
|
|
* be snopped by GPU and lmem will always be WC.
|
|
|
|
|
|
* This might change in future discrete platforms.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (anv_physical_device_has_vram(device->physical)) {
|
2024-01-12 08:31:31 -08:00
|
|
|
|
if (alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM)
|
2023-11-22 07:36:36 -08:00
|
|
|
|
return &device->info->pat.cached_coherent;
|
|
|
|
|
|
return &device->info->pat.writecombining;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-15 07:55:08 -07:00
|
|
|
|
/* Integrated platforms handling only */
|
|
|
|
|
|
if ((alloc_flags & (ANV_BO_ALLOC_HOST_CACHED_COHERENT)) == ANV_BO_ALLOC_HOST_CACHED_COHERENT)
|
2023-09-18 09:22:58 -07:00
|
|
|
|
return &device->info->pat.cached_coherent;
|
2023-09-13 08:16:49 -07:00
|
|
|
|
else if (alloc_flags & ANV_BO_ALLOC_HOST_CACHED)
|
|
|
|
|
|
return &device->info->pat.writeback_incoherent;
|
2023-09-07 14:07:13 -07:00
|
|
|
|
else
|
2023-09-13 06:53:29 -07:00
|
|
|
|
return &device->info->pat.writecombining;
|
2023-09-07 14:07:13 -07:00
|
|
|
|
}
|