mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 05:08:08 +02:00
venus: add vn_cs_encoder_storage_type
It generalizes cs->indirect. Signed-off-by: Chia-I Wu <olvaffe@gmail.com> Reviewed-by: Ryan Neph <ryanneph@google.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14179>
This commit is contained in:
parent
1fe8f0fea0
commit
487926aa86
4 changed files with 34 additions and 19 deletions
|
|
@ -560,7 +560,8 @@ vn_AllocateCommandBuffers(VkDevice device,
|
|||
list_addtail(&cmd->head, &pool->command_buffers);
|
||||
|
||||
cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
|
||||
vn_cs_encoder_init_indirect(&cmd->cs, dev->instance, 16 * 1024);
|
||||
vn_cs_encoder_init(&cmd->cs, dev->instance,
|
||||
VN_CS_ENCODER_STORAGE_SHMEM_ARRAY, 16 * 1024);
|
||||
|
||||
VkCommandBuffer cmd_handle = vn_command_buffer_to_handle(cmd);
|
||||
pCommandBuffers[i] = cmd_handle;
|
||||
|
|
|
|||
|
|
@ -88,20 +88,24 @@ vn_cs_encoder_gc_buffers(struct vn_cs_encoder *enc)
|
|||
}
|
||||
|
||||
void
|
||||
vn_cs_encoder_init_indirect(struct vn_cs_encoder *enc,
|
||||
struct vn_instance *instance,
|
||||
size_t min_size)
|
||||
vn_cs_encoder_init(struct vn_cs_encoder *enc,
|
||||
struct vn_instance *instance,
|
||||
enum vn_cs_encoder_storage_type storage_type,
|
||||
size_t min_size)
|
||||
{
|
||||
/* VN_CS_ENCODER_INITIALIZER* should be used instead */
|
||||
assert(storage_type != VN_CS_ENCODER_STORAGE_POINTER);
|
||||
|
||||
memset(enc, 0, sizeof(*enc));
|
||||
enc->instance = instance;
|
||||
enc->storage_type = storage_type;
|
||||
enc->min_buffer_size = min_size;
|
||||
enc->indirect = true;
|
||||
}
|
||||
|
||||
void
|
||||
vn_cs_encoder_fini(struct vn_cs_encoder *enc)
|
||||
{
|
||||
if (unlikely(!enc->indirect))
|
||||
if (unlikely(enc->storage_type == VN_CS_ENCODER_STORAGE_POINTER))
|
||||
return;
|
||||
|
||||
for (uint32_t i = 0; i < enc->buffer_count; i++)
|
||||
|
|
@ -163,7 +167,7 @@ vn_cs_encoder_grow_buffer_array(struct vn_cs_encoder *enc)
|
|||
bool
|
||||
vn_cs_encoder_reserve_internal(struct vn_cs_encoder *enc, size_t size)
|
||||
{
|
||||
if (unlikely(!enc->indirect))
|
||||
if (unlikely(enc->storage_type == VN_CS_ENCODER_STORAGE_POINTER))
|
||||
return false;
|
||||
|
||||
if (enc->buffer_count >= enc->buffer_max) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#define VN_CS_ENCODER_INITIALIZER_LOCAL(storage, size) \
|
||||
(struct vn_cs_encoder) \
|
||||
{ \
|
||||
.storage_type = VN_CS_ENCODER_STORAGE_POINTER, \
|
||||
.buffers = &VN_CS_ENCODER_BUFFER_INITIALIZER(storage), \
|
||||
.buffer_count = 1, .buffer_max = 1, .current_buffer_size = size, \
|
||||
.cur = storage, .end = (const void *)(storage) + (size), \
|
||||
|
|
@ -23,9 +24,9 @@
|
|||
#define VN_CS_ENCODER_INITIALIZER(buf, size) \
|
||||
(struct vn_cs_encoder) \
|
||||
{ \
|
||||
.buffers = (buf), .buffer_count = 1, .buffer_max = 1, \
|
||||
.current_buffer_size = size, .cur = (buf)->base, \
|
||||
.end = (buf)->base + (size), \
|
||||
.storage_type = VN_CS_ENCODER_STORAGE_POINTER, .buffers = (buf), \
|
||||
.buffer_count = 1, .buffer_max = 1, .current_buffer_size = size, \
|
||||
.cur = (buf)->base, .end = (buf)->base + (size), \
|
||||
}
|
||||
|
||||
#define VN_CS_DECODER_INITIALIZER(storage, size) \
|
||||
|
|
@ -34,6 +35,13 @@
|
|||
.cur = storage, .end = (const void *)(storage) + (size), \
|
||||
}
|
||||
|
||||
enum vn_cs_encoder_storage_type {
|
||||
/* a pointer to an externally-managed storage */
|
||||
VN_CS_ENCODER_STORAGE_POINTER,
|
||||
/* an array of dynamically allocated shmems */
|
||||
VN_CS_ENCODER_STORAGE_SHMEM_ARRAY,
|
||||
};
|
||||
|
||||
struct vn_cs_encoder_buffer {
|
||||
struct vn_renderer_shmem *shmem;
|
||||
size_t offset;
|
||||
|
|
@ -43,8 +51,8 @@ struct vn_cs_encoder_buffer {
|
|||
|
||||
struct vn_cs_encoder {
|
||||
struct vn_instance *instance; /* TODO shmem cache */
|
||||
enum vn_cs_encoder_storage_type storage_type;
|
||||
size_t min_buffer_size;
|
||||
bool indirect;
|
||||
|
||||
bool fatal_error;
|
||||
|
||||
|
|
@ -70,9 +78,10 @@ struct vn_cs_decoder {
|
|||
};
|
||||
|
||||
void
|
||||
vn_cs_encoder_init_indirect(struct vn_cs_encoder *enc,
|
||||
struct vn_instance *instance,
|
||||
size_t min_size);
|
||||
vn_cs_encoder_init(struct vn_cs_encoder *enc,
|
||||
struct vn_instance *instance,
|
||||
enum vn_cs_encoder_storage_type storage_type,
|
||||
size_t min_size);
|
||||
|
||||
void
|
||||
vn_cs_encoder_fini(struct vn_cs_encoder *enc);
|
||||
|
|
|
|||
|
|
@ -160,8 +160,8 @@ vn_instance_init_ring(struct vn_instance *instance)
|
|||
vn_renderer_submit_simple(instance->renderer, create_ring_data,
|
||||
vn_cs_encoder_get_len(&local_enc));
|
||||
|
||||
vn_cs_encoder_init_indirect(&instance->ring.upload, instance,
|
||||
1 * 1024 * 1024);
|
||||
vn_cs_encoder_init(&instance->ring.upload, instance,
|
||||
VN_CS_ENCODER_STORAGE_SHMEM_ARRAY, 1 * 1024 * 1024);
|
||||
|
||||
mtx_init(&instance->ring.roundtrip_mutex, mtx_plain);
|
||||
instance->ring.roundtrip_next = 1;
|
||||
|
|
@ -478,7 +478,8 @@ static struct vn_cs_encoder *
|
|||
vn_instance_ring_cs_upload_locked(struct vn_instance *instance,
|
||||
const struct vn_cs_encoder *cs)
|
||||
{
|
||||
assert(!cs->indirect && cs->buffer_count == 1);
|
||||
assert(cs->storage_type == VN_CS_ENCODER_STORAGE_POINTER &&
|
||||
cs->buffer_count == 1);
|
||||
const void *cs_data = cs->buffers[0].base;
|
||||
const size_t cs_size = cs->total_committed_size;
|
||||
assert(cs_size == vn_cs_encoder_get_len(cs));
|
||||
|
|
@ -505,11 +506,11 @@ vn_instance_ring_submit_locked(struct vn_instance *instance,
|
|||
struct vn_ring *ring = &instance->ring.ring;
|
||||
|
||||
const bool direct = vn_instance_submission_can_direct(instance, cs);
|
||||
if (!direct && !cs->indirect) {
|
||||
if (!direct && cs->storage_type == VN_CS_ENCODER_STORAGE_POINTER) {
|
||||
cs = vn_instance_ring_cs_upload_locked(instance, cs);
|
||||
if (!cs)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
assert(cs->indirect);
|
||||
assert(cs->storage_type != VN_CS_ENCODER_STORAGE_POINTER);
|
||||
}
|
||||
|
||||
struct vn_instance_submission submit;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue