nvk: Use nvkmd_mem for descriptor tables
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30033>
This commit is contained in:
committed by
Marge Bot
parent
a87ee75737
commit
17623bc8a9
@@ -14,32 +14,27 @@ nvk_descriptor_table_grow_locked(struct nvk_device *dev,
|
||||
struct nvk_descriptor_table *table,
|
||||
uint32_t new_alloc)
|
||||
{
|
||||
struct nouveau_ws_bo *new_bo;
|
||||
void *new_map;
|
||||
struct nvkmd_mem *new_mem;
|
||||
uint32_t *new_free_table;
|
||||
VkResult result;
|
||||
|
||||
assert(new_alloc > table->alloc && new_alloc <= table->max_alloc);
|
||||
|
||||
const uint32_t new_bo_size = new_alloc * table->desc_size;
|
||||
new_bo = nouveau_ws_bo_new_mapped(dev->ws_dev, new_bo_size, 256,
|
||||
NOUVEAU_WS_BO_LOCAL |
|
||||
NOUVEAU_WS_BO_NO_SHARE,
|
||||
NOUVEAU_WS_BO_WR,
|
||||
&new_map);
|
||||
if (new_bo == NULL) {
|
||||
return vk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
||||
"Failed to allocate the image descriptor table");
|
||||
}
|
||||
const uint32_t new_mem_size = new_alloc * table->desc_size;
|
||||
result = nvkmd_dev_alloc_mapped_mem(dev->nvkmd, &dev->vk.base,
|
||||
new_mem_size, 256,
|
||||
NVKMD_MEM_LOCAL | NVKMD_MEM_NO_SHARE,
|
||||
NVKMD_MEM_MAP_WR,
|
||||
&new_mem);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
if (table->bo) {
|
||||
assert(new_bo_size >= table->bo->size);
|
||||
memcpy(new_map, table->map, table->bo->size);
|
||||
|
||||
nouveau_ws_bo_unmap(table->bo, table->map);
|
||||
nouveau_ws_bo_destroy(table->bo);
|
||||
if (table->mem) {
|
||||
assert(new_mem_size >= table->mem->size_B);
|
||||
memcpy(new_mem->map, table->mem->map, table->mem->size_B);
|
||||
nvkmd_mem_unref(table->mem);
|
||||
}
|
||||
table->bo = new_bo;
|
||||
table->map = new_map;
|
||||
table->mem = new_mem;
|
||||
|
||||
const size_t new_free_table_size = new_alloc * sizeof(uint32_t);
|
||||
new_free_table = vk_realloc(&dev->vk.alloc, table->free_table,
|
||||
@@ -90,10 +85,8 @@ void
|
||||
nvk_descriptor_table_finish(struct nvk_device *dev,
|
||||
struct nvk_descriptor_table *table)
|
||||
{
|
||||
if (table->bo != NULL) {
|
||||
nouveau_ws_bo_unmap(table->bo, table->map);
|
||||
nouveau_ws_bo_destroy(table->bo);
|
||||
}
|
||||
if (table->mem != NULL)
|
||||
nvkmd_mem_unref(table->mem);
|
||||
vk_free(&dev->vk.alloc, table->free_table);
|
||||
simple_mtx_destroy(&table->mutex);
|
||||
}
|
||||
@@ -142,7 +135,7 @@ nvk_descriptor_table_add_locked(struct nvk_device *dev,
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
void *map = (char *)table->map + (*index_out * table->desc_size);
|
||||
void *map = (char *)table->mem->map + (*index_out * table->desc_size);
|
||||
|
||||
assert(desc_size == table->desc_size);
|
||||
memcpy(map, desc_data, table->desc_size);
|
||||
@@ -172,7 +165,7 @@ nvk_descriptor_table_remove(struct nvk_device *dev,
|
||||
{
|
||||
simple_mtx_lock(&table->mutex);
|
||||
|
||||
void *map = (char *)table->map + (index * table->desc_size);
|
||||
void *map = (char *)table->mem->map + (index * table->desc_size);
|
||||
memset(map, 0, table->desc_size);
|
||||
|
||||
/* Sanity check for double-free */
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "nvk_private.h"
|
||||
|
||||
#include "nouveau_bo.h"
|
||||
#include "util/simple_mtx.h"
|
||||
#include "nvkmd/nvkmd.h"
|
||||
|
||||
struct nvk_device;
|
||||
|
||||
@@ -21,8 +21,7 @@ struct nvk_descriptor_table {
|
||||
uint32_t next_desc; /**< Next unallocated descriptor */
|
||||
uint32_t free_count; /**< Size of free_table */
|
||||
|
||||
struct nouveau_ws_bo *bo;
|
||||
void *map;
|
||||
struct nvkmd_mem *mem;
|
||||
|
||||
/* Stack for free descriptor elements */
|
||||
uint32_t *free_table;
|
||||
@@ -46,18 +45,18 @@ void nvk_descriptor_table_remove(struct nvk_device *dev,
|
||||
struct nvk_descriptor_table *table,
|
||||
uint32_t index);
|
||||
|
||||
static inline struct nouveau_ws_bo *
|
||||
nvk_descriptor_table_get_bo_ref(struct nvk_descriptor_table *table,
|
||||
uint32_t *alloc_count_out)
|
||||
static inline struct nvkmd_mem *
|
||||
nvk_descriptor_table_get_mem_ref(struct nvk_descriptor_table *table,
|
||||
uint32_t *alloc_count_out)
|
||||
{
|
||||
simple_mtx_lock(&table->mutex);
|
||||
struct nouveau_ws_bo *bo = table->bo;
|
||||
if (bo)
|
||||
nouveau_ws_bo_ref(bo);
|
||||
struct nvkmd_mem *mem = table->mem;
|
||||
if (mem)
|
||||
nvkmd_mem_ref(mem);
|
||||
*alloc_count_out = table->alloc;
|
||||
simple_mtx_unlock(&table->mutex);
|
||||
|
||||
return bo;
|
||||
return mem;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,10 +31,10 @@ static void
|
||||
nvk_queue_state_finish(struct nvk_device *dev,
|
||||
struct nvk_queue_state *qs)
|
||||
{
|
||||
if (qs->images.bo)
|
||||
nouveau_ws_bo_destroy(qs->images.bo);
|
||||
if (qs->samplers.bo)
|
||||
nouveau_ws_bo_destroy(qs->samplers.bo);
|
||||
if (qs->images.mem)
|
||||
nvkmd_mem_unref(qs->images.mem);
|
||||
if (qs->samplers.mem)
|
||||
nvkmd_mem_unref(qs->samplers.mem);
|
||||
if (qs->slm.bo)
|
||||
nouveau_ws_bo_destroy(qs->slm.bo);
|
||||
if (qs->push.bo) {
|
||||
@@ -62,33 +62,34 @@ nvk_queue_state_update(struct nvk_device *dev,
|
||||
{
|
||||
struct nvk_physical_device *pdev = nvk_device_physical(dev);
|
||||
struct nouveau_ws_bo *bo;
|
||||
struct nvkmd_mem *mem;
|
||||
uint32_t alloc_count, bytes_per_warp, bytes_per_tpc;
|
||||
bool dirty = false;
|
||||
|
||||
bo = nvk_descriptor_table_get_bo_ref(&dev->images, &alloc_count);
|
||||
if (qs->images.bo != bo || qs->images.alloc_count != alloc_count) {
|
||||
if (qs->images.bo)
|
||||
nouveau_ws_bo_destroy(qs->images.bo);
|
||||
qs->images.bo = bo;
|
||||
mem = nvk_descriptor_table_get_mem_ref(&dev->images, &alloc_count);
|
||||
if (qs->images.mem != mem || qs->images.alloc_count != alloc_count) {
|
||||
if (qs->images.mem)
|
||||
nvkmd_mem_unref(qs->images.mem);
|
||||
qs->images.mem = mem;
|
||||
qs->images.alloc_count = alloc_count;
|
||||
dirty = true;
|
||||
} else {
|
||||
/* No change */
|
||||
if (bo)
|
||||
nouveau_ws_bo_destroy(bo);
|
||||
if (mem)
|
||||
nvkmd_mem_unref(mem);
|
||||
}
|
||||
|
||||
bo = nvk_descriptor_table_get_bo_ref(&dev->samplers, &alloc_count);
|
||||
if (qs->samplers.bo != bo || qs->samplers.alloc_count != alloc_count) {
|
||||
if (qs->samplers.bo)
|
||||
nouveau_ws_bo_destroy(qs->samplers.bo);
|
||||
qs->samplers.bo = bo;
|
||||
mem = nvk_descriptor_table_get_mem_ref(&dev->samplers, &alloc_count);
|
||||
if (qs->samplers.mem != mem || qs->samplers.alloc_count != alloc_count) {
|
||||
if (qs->samplers.mem)
|
||||
nvkmd_mem_unref(qs->samplers.mem);
|
||||
qs->samplers.mem = mem;
|
||||
qs->samplers.alloc_count = alloc_count;
|
||||
dirty = true;
|
||||
} else {
|
||||
/* No change */
|
||||
if (bo)
|
||||
nouveau_ws_bo_destroy(bo);
|
||||
if (mem)
|
||||
nvkmd_mem_unref(mem);
|
||||
}
|
||||
|
||||
bo = nvk_slm_area_get_bo_ref(&dev->slm, &bytes_per_warp, &bytes_per_tpc);
|
||||
@@ -130,11 +131,11 @@ nvk_queue_state_update(struct nvk_device *dev,
|
||||
nv_push_init(&push, push_map, 256);
|
||||
struct nv_push *p = &push;
|
||||
|
||||
if (qs->images.bo) {
|
||||
if (qs->images.mem) {
|
||||
/* Compute */
|
||||
P_MTHD(p, NVA0C0, SET_TEX_HEADER_POOL_A);
|
||||
P_NVA0C0_SET_TEX_HEADER_POOL_A(p, qs->images.bo->offset >> 32);
|
||||
P_NVA0C0_SET_TEX_HEADER_POOL_B(p, qs->images.bo->offset);
|
||||
P_NVA0C0_SET_TEX_HEADER_POOL_A(p, qs->images.mem->va->addr >> 32);
|
||||
P_NVA0C0_SET_TEX_HEADER_POOL_B(p, qs->images.mem->va->addr);
|
||||
P_NVA0C0_SET_TEX_HEADER_POOL_C(p, qs->images.alloc_count - 1);
|
||||
P_IMMD(p, NVA0C0, INVALIDATE_TEXTURE_HEADER_CACHE_NO_WFI, {
|
||||
.lines = LINES_ALL
|
||||
@@ -142,19 +143,19 @@ nvk_queue_state_update(struct nvk_device *dev,
|
||||
|
||||
/* 3D */
|
||||
P_MTHD(p, NV9097, SET_TEX_HEADER_POOL_A);
|
||||
P_NV9097_SET_TEX_HEADER_POOL_A(p, qs->images.bo->offset >> 32);
|
||||
P_NV9097_SET_TEX_HEADER_POOL_B(p, qs->images.bo->offset);
|
||||
P_NV9097_SET_TEX_HEADER_POOL_A(p, qs->images.mem->va->addr >> 32);
|
||||
P_NV9097_SET_TEX_HEADER_POOL_B(p, qs->images.mem->va->addr);
|
||||
P_NV9097_SET_TEX_HEADER_POOL_C(p, qs->images.alloc_count - 1);
|
||||
P_IMMD(p, NV9097, INVALIDATE_TEXTURE_HEADER_CACHE_NO_WFI, {
|
||||
.lines = LINES_ALL
|
||||
});
|
||||
}
|
||||
|
||||
if (qs->samplers.bo) {
|
||||
if (qs->samplers.mem) {
|
||||
/* Compute */
|
||||
P_MTHD(p, NVA0C0, SET_TEX_SAMPLER_POOL_A);
|
||||
P_NVA0C0_SET_TEX_SAMPLER_POOL_A(p, qs->samplers.bo->offset >> 32);
|
||||
P_NVA0C0_SET_TEX_SAMPLER_POOL_B(p, qs->samplers.bo->offset);
|
||||
P_NVA0C0_SET_TEX_SAMPLER_POOL_A(p, qs->samplers.mem->va->addr >> 32);
|
||||
P_NVA0C0_SET_TEX_SAMPLER_POOL_B(p, qs->samplers.mem->va->addr);
|
||||
P_NVA0C0_SET_TEX_SAMPLER_POOL_C(p, qs->samplers.alloc_count - 1);
|
||||
P_IMMD(p, NVA0C0, INVALIDATE_SAMPLER_CACHE_NO_WFI, {
|
||||
.lines = LINES_ALL
|
||||
@@ -162,8 +163,8 @@ nvk_queue_state_update(struct nvk_device *dev,
|
||||
|
||||
/* 3D */
|
||||
P_MTHD(p, NV9097, SET_TEX_SAMPLER_POOL_A);
|
||||
P_NV9097_SET_TEX_SAMPLER_POOL_A(p, qs->samplers.bo->offset >> 32);
|
||||
P_NV9097_SET_TEX_SAMPLER_POOL_B(p, qs->samplers.bo->offset);
|
||||
P_NV9097_SET_TEX_SAMPLER_POOL_A(p, qs->samplers.mem->va->addr >> 32);
|
||||
P_NV9097_SET_TEX_SAMPLER_POOL_B(p, qs->samplers.mem->va->addr);
|
||||
P_NV9097_SET_TEX_SAMPLER_POOL_C(p, qs->samplers.alloc_count - 1);
|
||||
P_IMMD(p, NV9097, INVALIDATE_SAMPLER_CACHE_NO_WFI, {
|
||||
.lines = LINES_ALL
|
||||
|
||||
@@ -14,15 +14,16 @@ struct nouveau_ws_context;
|
||||
struct novueau_ws_push;
|
||||
struct nv_push;
|
||||
struct nvk_device;
|
||||
struct nvkmd_mem;
|
||||
|
||||
struct nvk_queue_state {
|
||||
struct {
|
||||
struct nouveau_ws_bo *bo;
|
||||
struct nvkmd_mem *mem;
|
||||
uint32_t alloc_count;
|
||||
} images;
|
||||
|
||||
struct {
|
||||
struct nouveau_ws_bo *bo;
|
||||
struct nvkmd_mem *mem;
|
||||
uint32_t alloc_count;
|
||||
} samplers;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user