diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index 97816c24e8a..5b4275df4f1 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -527,6 +527,20 @@ anv_trtt_bind_add(struct anv_device *device, anv_trtt_bind_list_add_entry(l3l2_binds, n_l3l2_binds, trtt->l3_addr + l3_index * sizeof(uint64_t), l2_addr); + + /* We have just created a new L2 table. Other resources may already have + * been pointing to this L2 table relying on the fact that it was marked + * as NULL, so now we need to mark every one of its entries as NULL in + * order to preserve behavior for those entries. + */ + for (int i = 0; i < 512; i++) { + if (i != l2_index) { + trtt->l2_mirror[l3_index * 512 + i] = ANV_TRTT_L3L2_NULL_ENTRY; + anv_trtt_bind_list_add_entry(l3l2_binds, n_l3l2_binds, + l2_addr + i * sizeof(uint64_t), + ANV_TRTT_L3L2_NULL_ENTRY); + } + } } assert(l2_addr != 0 && l2_addr != ANV_TRTT_L3L2_NULL_ENTRY); @@ -697,6 +711,11 @@ anv_sparse_bind_trtt(struct anv_device *device, * numbers are so small that a little overestimation won't hurt. * * We have assertions below to catch estimation errors. + * + * TODO: a bug fix caused us to put that "+ 1024" in the l3l2 capacity so + * now our estimations are super overestimating things in most cases, as + * most cases are still using a total capacity of just 1 or 2. We should + * replace this whole thing with something more efficient. */ int l3l2_binds_capacity = 1; int l1_binds_capacity = 0; @@ -704,7 +723,7 @@ anv_sparse_bind_trtt(struct anv_device *device, assert(sparse_submit->binds[b].size % (64 * 1024) == 0); int pages = sparse_submit->binds[b].size / (64 * 1024); l1_binds_capacity += pages; - l3l2_binds_capacity += (pages / 1024 + 1) * 2; + l3l2_binds_capacity += (pages / 1024 + 1) * 2 + 1024; } /* Turn a series of virtual address maps, into a list of L3/L2/L1 TRTT page