anv: add a protected scratch pool

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: mesa-stable
Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29778>
This commit is contained in:
Lionel Landwerlin
2024-06-19 09:06:35 +03:00
committed by Marge Bot
parent c0138e99e6
commit 08a4e0a2e3
3 changed files with 19 additions and 8 deletions

View File

@@ -1297,9 +1297,13 @@ anv_bo_pool_free(struct anv_bo_pool *pool, struct anv_bo *bo)
// Scratch pool
void
anv_scratch_pool_init(struct anv_device *device, struct anv_scratch_pool *pool)
anv_scratch_pool_init(struct anv_device *device, struct anv_scratch_pool *pool,
bool protected)
{
memset(pool, 0, sizeof(*pool));
pool->alloc_flags = ANV_BO_ALLOC_INTERNAL |
(protected ? ANV_BO_ALLOC_PROTECTED : 0) |
(device->info->verx10 < 125 ? ANV_BO_ALLOC_32BIT_ADDRESS : 0);
}
void
@@ -1367,11 +1371,8 @@ anv_scratch_pool_alloc(struct anv_device *device, struct anv_scratch_pool *pool,
*
* so nothing will ever touch the top page.
*/
const enum anv_bo_alloc_flags alloc_flags =
ANV_BO_ALLOC_INTERNAL |
(devinfo->verx10 < 125 ? ANV_BO_ALLOC_32BIT_ADDRESS : 0);
VkResult result = anv_device_alloc_bo(device, "scratch", size,
alloc_flags,
pool->alloc_flags,
0 /* explicit_address */,
&bo);
if (result != VK_SUCCESS)
@@ -1413,10 +1414,14 @@ anv_scratch_pool_get_surf(struct anv_device *device,
anv_state_pool_alloc(&device->scratch_surface_state_pool,
device->isl_dev.ss.size, 64);
isl_surf_usage_flags_t usage =
(pool->alloc_flags & ANV_BO_ALLOC_PROTECTED) ?
ISL_SURF_USAGE_PROTECTED_BIT : 0;
isl_buffer_fill_state(&device->isl_dev, state.map,
.address = anv_address_physical(addr),
.size_B = bo->size,
.mocs = anv_mocs(device, bo, 0),
.mocs = anv_mocs(device, bo, usage),
.format = ISL_FORMAT_RAW,
.swizzle = ISL_SWIZZLE_IDENTITY,
.stride_B = per_thread_scratch,

View File

@@ -3839,7 +3839,8 @@ VkResult anv_CreateDevice(
isl_null_fill_state(&device->isl_dev, &device->host_null_surface_state,
.size = isl_extent3d(1, 1, 1) /* This shouldn't matter */);
anv_scratch_pool_init(device, &device->scratch_pool);
anv_scratch_pool_init(device, &device->scratch_pool, false);
anv_scratch_pool_init(device, &device->protected_scratch_pool, true);
/* TODO(RT): Do we want some sort of data structure for this? */
memset(device->rt_scratch_bos, 0, sizeof(device->rt_scratch_bos));
@@ -4027,6 +4028,7 @@ VkResult anv_CreateDevice(
anv_device_release_bo(device, device->btd_fifo_bo);
fail_trivial_batch_bo_and_scratch_pool:
anv_scratch_pool_finish(device, &device->scratch_pool);
anv_scratch_pool_finish(device, &device->protected_scratch_pool);
fail_trivial_batch:
anv_device_release_bo(device, device->trivial_batch_bo);
fail_ray_query_bo:
@@ -4182,6 +4184,7 @@ void anv_DestroyDevice(
}
anv_scratch_pool_finish(device, &device->scratch_pool);
anv_scratch_pool_finish(device, &device->protected_scratch_pool);
if (device->vk.enabled_extensions.KHR_ray_query) {
for (unsigned i = 0; i < ARRAY_SIZE(device->ray_query_shadow_bos); i++) {

View File

@@ -902,6 +902,7 @@ VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, uint32_t size,
void anv_bo_pool_free(struct anv_bo_pool *pool, struct anv_bo *bo);
struct anv_scratch_pool {
enum anv_bo_alloc_flags alloc_flags;
/* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
struct anv_bo *bos[16][MESA_SHADER_STAGES];
uint32_t surfs[16];
@@ -909,7 +910,8 @@ struct anv_scratch_pool {
};
void anv_scratch_pool_init(struct anv_device *device,
struct anv_scratch_pool *pool);
struct anv_scratch_pool *pool,
bool protected);
void anv_scratch_pool_finish(struct anv_device *device,
struct anv_scratch_pool *pool);
struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
@@ -1903,6 +1905,7 @@ struct anv_device {
struct anv_queue * queues;
struct anv_scratch_pool scratch_pool;
struct anv_scratch_pool protected_scratch_pool;
struct anv_bo *rt_scratch_bos[16];
struct anv_bo *btd_fifo_bo;
struct anv_address rt_uuid_addr;