From f74caa30fcb31b9ac3f84b7d13d0d3e084a35c87 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 29 Jul 2021 19:24:48 -0700 Subject: [PATCH] vkr: split out vkr_descriptor_set.c No functional change. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang Reviewed-by: Ryan Neph --- src/meson.build | 1 + src/venus/vkr_descriptor_set.c | 205 +++++++++++++++++++++++++++++++++ src/venus/vkr_descriptor_set.h | 12 ++ src/venus/vkr_renderer.c | 170 +-------------------------- 4 files changed, 222 insertions(+), 166 deletions(-) create mode 100644 src/venus/vkr_descriptor_set.c diff --git a/src/meson.build b/src/meson.build index 53810e4..28076be 100644 --- a/src/meson.build +++ b/src/meson.build @@ -85,6 +85,7 @@ venus_sources = [ 'venus/vkr_context.h', 'venus/vkr_cs.c', 'venus/vkr_cs.h', + 'venus/vkr_descriptor_set.c', 'venus/vkr_descriptor_set.h', 'venus/vkr_device.h', 'venus/vkr_device_memory.h', diff --git a/src/venus/vkr_descriptor_set.c b/src/venus/vkr_descriptor_set.c new file mode 100644 index 0000000..ea219e9 --- /dev/null +++ b/src/venus/vkr_descriptor_set.c @@ -0,0 +1,205 @@ +/* + * Copyright 2020 Google LLC + * SPDX-License-Identifier: MIT + */ + +#include "vkr_descriptor_set.h" + +#include "venus-protocol/vn_protocol_renderer_descriptor_pool.h" +#include "venus-protocol/vn_protocol_renderer_descriptor_set.h" +#include "venus-protocol/vn_protocol_renderer_descriptor_set_layout.h" +#include "venus-protocol/vn_protocol_renderer_descriptor_update_template.h" + +#include "vkr_context.h" +#include "vkr_device.h" + +static void +vkr_dispatch_vkGetDescriptorSetLayoutSupport( + UNUSED struct vn_dispatch_context *dispatch, + struct vn_command_vkGetDescriptorSetLayoutSupport *args) +{ + vn_replace_vkGetDescriptorSetLayoutSupport_args_handle(args); + vkGetDescriptorSetLayoutSupport(args->device, args->pCreateInfo, args->pSupport); +} + +static void +vkr_dispatch_vkCreateDescriptorSetLayout( + struct vn_dispatch_context *dispatch, + struct vn_command_vkCreateDescriptorSetLayout *args) +{ + struct vkr_context *ctx = dispatch->data; + + CREATE_OBJECT(layout, descriptor_set_layout, DESCRIPTOR_SET_LAYOUT, + vkCreateDescriptorSetLayout, pSetLayout); + + util_hash_table_set_u64(ctx->object_table, layout->base.id, layout); +} + +static void +vkr_dispatch_vkDestroyDescriptorSetLayout( + struct vn_dispatch_context *dispatch, + struct vn_command_vkDestroyDescriptorSetLayout *args) +{ + struct vkr_context *ctx = dispatch->data; + + DESTROY_OBJECT(layout, descriptor_set_layout, DESCRIPTOR_SET_LAYOUT, + vkDestroyDescriptorSetLayout, descriptorSetLayout); + + util_hash_table_remove_u64(ctx->object_table, layout->base.id); +} + +static void +vkr_dispatch_vkCreateDescriptorPool(struct vn_dispatch_context *dispatch, + struct vn_command_vkCreateDescriptorPool *args) +{ + struct vkr_context *ctx = dispatch->data; + + CREATE_OBJECT(pool, descriptor_pool, DESCRIPTOR_POOL, vkCreateDescriptorPool, + pDescriptorPool); + + list_inithead(&pool->descriptor_sets); + + util_hash_table_set_u64(ctx->object_table, pool->base.id, pool); +} + +static void +vkr_dispatch_vkDestroyDescriptorPool(struct vn_dispatch_context *dispatch, + struct vn_command_vkDestroyDescriptorPool *args) +{ + struct vkr_context *ctx = dispatch->data; + + DESTROY_OBJECT(pool, descriptor_pool, DESCRIPTOR_POOL, vkDestroyDescriptorPool, + descriptorPool); + + struct vkr_descriptor_set *set, *tmp; + LIST_FOR_EACH_ENTRY_SAFE (set, tmp, &pool->descriptor_sets, head) + util_hash_table_remove_u64(ctx->object_table, set->base.id); + + util_hash_table_remove_u64(ctx->object_table, pool->base.id); +} + +static void +vkr_dispatch_vkResetDescriptorPool(struct vn_dispatch_context *dispatch, + struct vn_command_vkResetDescriptorPool *args) +{ + struct vkr_context *ctx = dispatch->data; + + struct vkr_descriptor_pool *pool = + (struct vkr_descriptor_pool *)(uintptr_t)args->descriptorPool; + if (!pool || pool->base.type != VK_OBJECT_TYPE_DESCRIPTOR_POOL) { + vkr_cs_decoder_set_fatal(&ctx->decoder); + return; + } + + vn_replace_vkResetDescriptorPool_args_handle(args); + args->ret = vkResetDescriptorPool(args->device, args->descriptorPool, args->flags); + + struct vkr_descriptor_set *set, *tmp; + LIST_FOR_EACH_ENTRY_SAFE (set, tmp, &pool->descriptor_sets, head) + util_hash_table_remove_u64(ctx->object_table, set->base.id); + list_inithead(&pool->descriptor_sets); +} + +static void +vkr_dispatch_vkAllocateDescriptorSets(struct vn_dispatch_context *dispatch, + struct vn_command_vkAllocateDescriptorSets *args) +{ + struct vkr_context *ctx = dispatch->data; + + ALLOCATE_OBJECT_ARRAY(set, descriptor_set, DESCRIPTOR_SET, DescriptorSet, + vkAllocateDescriptorSets, descriptorSetCount, descriptorPool, + descriptor_pool, DESCRIPTOR_POOL); +} + +static void +vkr_dispatch_vkFreeDescriptorSets(struct vn_dispatch_context *dispatch, + struct vn_command_vkFreeDescriptorSets *args) +{ + struct vkr_context *ctx = dispatch->data; + + FREE_OBJECT_ARRAY(set, descriptor_set, DESCRIPTOR_SET, vkFreeDescriptorSets, + pDescriptorSets, descriptorSetCount, descriptorPool); + + args->ret = VK_SUCCESS; +} + +static void +vkr_dispatch_vkUpdateDescriptorSets(UNUSED struct vn_dispatch_context *dispatch, + struct vn_command_vkUpdateDescriptorSets *args) +{ + vn_replace_vkUpdateDescriptorSets_args_handle(args); + vkUpdateDescriptorSets(args->device, args->descriptorWriteCount, + args->pDescriptorWrites, args->descriptorCopyCount, + args->pDescriptorCopies); +} + +static void +vkr_dispatch_vkCreateDescriptorUpdateTemplate( + struct vn_dispatch_context *dispatch, + struct vn_command_vkCreateDescriptorUpdateTemplate *args) +{ + struct vkr_context *ctx = dispatch->data; + + CREATE_OBJECT(templ, descriptor_update_template, DESCRIPTOR_UPDATE_TEMPLATE, + vkCreateDescriptorUpdateTemplate, pDescriptorUpdateTemplate); + + util_hash_table_set_u64(ctx->object_table, templ->base.id, templ); +} + +static void +vkr_dispatch_vkDestroyDescriptorUpdateTemplate( + struct vn_dispatch_context *dispatch, + struct vn_command_vkDestroyDescriptorUpdateTemplate *args) +{ + struct vkr_context *ctx = dispatch->data; + + DESTROY_OBJECT(templ, descriptor_update_template, DESCRIPTOR_UPDATE_TEMPLATE, + vkDestroyDescriptorUpdateTemplate, descriptorUpdateTemplate); + + util_hash_table_remove_u64(ctx->object_table, templ->base.id); +} + +void +vkr_context_init_descriptor_set_layout_dispatch(struct vkr_context *ctx) +{ + struct vn_dispatch_context *dispatch = &ctx->dispatch; + + dispatch->dispatch_vkGetDescriptorSetLayoutSupport = + vkr_dispatch_vkGetDescriptorSetLayoutSupport; + dispatch->dispatch_vkCreateDescriptorSetLayout = + vkr_dispatch_vkCreateDescriptorSetLayout; + dispatch->dispatch_vkDestroyDescriptorSetLayout = + vkr_dispatch_vkDestroyDescriptorSetLayout; +} + +void +vkr_context_init_descriptor_pool_dispatch(struct vkr_context *ctx) +{ + struct vn_dispatch_context *dispatch = &ctx->dispatch; + + dispatch->dispatch_vkCreateDescriptorPool = vkr_dispatch_vkCreateDescriptorPool; + dispatch->dispatch_vkDestroyDescriptorPool = vkr_dispatch_vkDestroyDescriptorPool; + dispatch->dispatch_vkResetDescriptorPool = vkr_dispatch_vkResetDescriptorPool; +} + +void +vkr_context_init_descriptor_set_dispatch(struct vkr_context *ctx) +{ + struct vn_dispatch_context *dispatch = &ctx->dispatch; + + dispatch->dispatch_vkAllocateDescriptorSets = vkr_dispatch_vkAllocateDescriptorSets; + dispatch->dispatch_vkFreeDescriptorSets = vkr_dispatch_vkFreeDescriptorSets; + dispatch->dispatch_vkUpdateDescriptorSets = vkr_dispatch_vkUpdateDescriptorSets; +} + +void +vkr_context_init_descriptor_update_template_dispatch(struct vkr_context *ctx) +{ + struct vn_dispatch_context *dispatch = &ctx->dispatch; + + dispatch->dispatch_vkCreateDescriptorUpdateTemplate = + vkr_dispatch_vkCreateDescriptorUpdateTemplate; + dispatch->dispatch_vkDestroyDescriptorUpdateTemplate = + vkr_dispatch_vkDestroyDescriptorUpdateTemplate; + dispatch->dispatch_vkUpdateDescriptorSetWithTemplate = NULL; +} diff --git a/src/venus/vkr_descriptor_set.h b/src/venus/vkr_descriptor_set.h index 5fe4abb..ede884d 100644 --- a/src/venus/vkr_descriptor_set.h +++ b/src/venus/vkr_descriptor_set.h @@ -30,4 +30,16 @@ struct vkr_descriptor_update_template { struct vkr_object base; }; +void +vkr_context_init_descriptor_set_layout_dispatch(struct vkr_context *ctx); + +void +vkr_context_init_descriptor_pool_dispatch(struct vkr_context *ctx); + +void +vkr_context_init_descriptor_set_dispatch(struct vkr_context *ctx); + +void +vkr_context_init_descriptor_update_template_dispatch(struct vkr_context *ctx); + #endif /* VKR_DESCRIPTOR_SET_H */ diff --git a/src/venus/vkr_renderer.c b/src/venus/vkr_renderer.c index 11fa1dc..a9add06 100644 --- a/src/venus/vkr_renderer.c +++ b/src/venus/vkr_renderer.c @@ -2451,152 +2451,6 @@ vkr_dispatch_vkDestroySamplerYcbcrConversion( util_hash_table_remove_u64(ctx->object_table, conv->base.id); } -static void -vkr_dispatch_vkGetDescriptorSetLayoutSupport( - UNUSED struct vn_dispatch_context *dispatch, - struct vn_command_vkGetDescriptorSetLayoutSupport *args) -{ - vn_replace_vkGetDescriptorSetLayoutSupport_args_handle(args); - vkGetDescriptorSetLayoutSupport(args->device, args->pCreateInfo, args->pSupport); -} - -static void -vkr_dispatch_vkCreateDescriptorSetLayout( - struct vn_dispatch_context *dispatch, - struct vn_command_vkCreateDescriptorSetLayout *args) -{ - struct vkr_context *ctx = dispatch->data; - - CREATE_OBJECT(layout, descriptor_set_layout, DESCRIPTOR_SET_LAYOUT, - vkCreateDescriptorSetLayout, pSetLayout); - - util_hash_table_set_u64(ctx->object_table, layout->base.id, layout); -} - -static void -vkr_dispatch_vkDestroyDescriptorSetLayout( - struct vn_dispatch_context *dispatch, - struct vn_command_vkDestroyDescriptorSetLayout *args) -{ - struct vkr_context *ctx = dispatch->data; - - DESTROY_OBJECT(layout, descriptor_set_layout, DESCRIPTOR_SET_LAYOUT, - vkDestroyDescriptorSetLayout, descriptorSetLayout); - - util_hash_table_remove_u64(ctx->object_table, layout->base.id); -} - -static void -vkr_dispatch_vkCreateDescriptorPool(struct vn_dispatch_context *dispatch, - struct vn_command_vkCreateDescriptorPool *args) -{ - struct vkr_context *ctx = dispatch->data; - - CREATE_OBJECT(pool, descriptor_pool, DESCRIPTOR_POOL, vkCreateDescriptorPool, - pDescriptorPool); - - list_inithead(&pool->descriptor_sets); - - util_hash_table_set_u64(ctx->object_table, pool->base.id, pool); -} - -static void -vkr_dispatch_vkDestroyDescriptorPool(struct vn_dispatch_context *dispatch, - struct vn_command_vkDestroyDescriptorPool *args) -{ - struct vkr_context *ctx = dispatch->data; - - DESTROY_OBJECT(pool, descriptor_pool, DESCRIPTOR_POOL, vkDestroyDescriptorPool, - descriptorPool); - - struct vkr_descriptor_set *set, *tmp; - LIST_FOR_EACH_ENTRY_SAFE (set, tmp, &pool->descriptor_sets, head) - util_hash_table_remove_u64(ctx->object_table, set->base.id); - - util_hash_table_remove_u64(ctx->object_table, pool->base.id); -} - -static void -vkr_dispatch_vkResetDescriptorPool(struct vn_dispatch_context *dispatch, - struct vn_command_vkResetDescriptorPool *args) -{ - struct vkr_context *ctx = dispatch->data; - - struct vkr_descriptor_pool *pool = - (struct vkr_descriptor_pool *)(uintptr_t)args->descriptorPool; - if (!pool || pool->base.type != VK_OBJECT_TYPE_DESCRIPTOR_POOL) { - vkr_cs_decoder_set_fatal(&ctx->decoder); - return; - } - - vn_replace_vkResetDescriptorPool_args_handle(args); - args->ret = vkResetDescriptorPool(args->device, args->descriptorPool, args->flags); - - struct vkr_descriptor_set *set, *tmp; - LIST_FOR_EACH_ENTRY_SAFE (set, tmp, &pool->descriptor_sets, head) - util_hash_table_remove_u64(ctx->object_table, set->base.id); - list_inithead(&pool->descriptor_sets); -} - -static void -vkr_dispatch_vkAllocateDescriptorSets(struct vn_dispatch_context *dispatch, - struct vn_command_vkAllocateDescriptorSets *args) -{ - struct vkr_context *ctx = dispatch->data; - - ALLOCATE_OBJECT_ARRAY(set, descriptor_set, DESCRIPTOR_SET, DescriptorSet, - vkAllocateDescriptorSets, descriptorSetCount, descriptorPool, - descriptor_pool, DESCRIPTOR_POOL); -} - -static void -vkr_dispatch_vkFreeDescriptorSets(struct vn_dispatch_context *dispatch, - struct vn_command_vkFreeDescriptorSets *args) -{ - struct vkr_context *ctx = dispatch->data; - - FREE_OBJECT_ARRAY(set, descriptor_set, DESCRIPTOR_SET, vkFreeDescriptorSets, - pDescriptorSets, descriptorSetCount, descriptorPool); - - args->ret = VK_SUCCESS; -} - -static void -vkr_dispatch_vkUpdateDescriptorSets(UNUSED struct vn_dispatch_context *dispatch, - struct vn_command_vkUpdateDescriptorSets *args) -{ - vn_replace_vkUpdateDescriptorSets_args_handle(args); - vkUpdateDescriptorSets(args->device, args->descriptorWriteCount, - args->pDescriptorWrites, args->descriptorCopyCount, - args->pDescriptorCopies); -} - -static void -vkr_dispatch_vkCreateDescriptorUpdateTemplate( - struct vn_dispatch_context *dispatch, - struct vn_command_vkCreateDescriptorUpdateTemplate *args) -{ - struct vkr_context *ctx = dispatch->data; - - CREATE_OBJECT(templ, descriptor_update_template, DESCRIPTOR_UPDATE_TEMPLATE, - vkCreateDescriptorUpdateTemplate, pDescriptorUpdateTemplate); - - util_hash_table_set_u64(ctx->object_table, templ->base.id, templ); -} - -static void -vkr_dispatch_vkDestroyDescriptorUpdateTemplate( - struct vn_dispatch_context *dispatch, - struct vn_command_vkDestroyDescriptorUpdateTemplate *args) -{ - struct vkr_context *ctx = dispatch->data; - - DESTROY_OBJECT(templ, descriptor_update_template, DESCRIPTOR_UPDATE_TEMPLATE, - vkDestroyDescriptorUpdateTemplate, descriptorUpdateTemplate); - - util_hash_table_remove_u64(ctx->object_table, templ->base.id); -} - static void vkr_dispatch_vkCreateEvent(struct vn_dispatch_context *dispatch, struct vn_command_vkCreateEvent *args) @@ -2901,26 +2755,10 @@ vkr_context_init_dispatch(struct vkr_context *ctx) dispatch->dispatch_vkDestroySamplerYcbcrConversion = vkr_dispatch_vkDestroySamplerYcbcrConversion; - dispatch->dispatch_vkGetDescriptorSetLayoutSupport = - vkr_dispatch_vkGetDescriptorSetLayoutSupport; - dispatch->dispatch_vkCreateDescriptorSetLayout = - vkr_dispatch_vkCreateDescriptorSetLayout; - dispatch->dispatch_vkDestroyDescriptorSetLayout = - vkr_dispatch_vkDestroyDescriptorSetLayout; - - dispatch->dispatch_vkCreateDescriptorPool = vkr_dispatch_vkCreateDescriptorPool; - dispatch->dispatch_vkDestroyDescriptorPool = vkr_dispatch_vkDestroyDescriptorPool; - dispatch->dispatch_vkResetDescriptorPool = vkr_dispatch_vkResetDescriptorPool; - - dispatch->dispatch_vkAllocateDescriptorSets = vkr_dispatch_vkAllocateDescriptorSets; - dispatch->dispatch_vkFreeDescriptorSets = vkr_dispatch_vkFreeDescriptorSets; - dispatch->dispatch_vkUpdateDescriptorSets = vkr_dispatch_vkUpdateDescriptorSets; - - dispatch->dispatch_vkCreateDescriptorUpdateTemplate = - vkr_dispatch_vkCreateDescriptorUpdateTemplate; - dispatch->dispatch_vkDestroyDescriptorUpdateTemplate = - vkr_dispatch_vkDestroyDescriptorUpdateTemplate; - dispatch->dispatch_vkUpdateDescriptorSetWithTemplate = NULL; + vkr_context_init_descriptor_set_layout_dispatch(ctx); + vkr_context_init_descriptor_pool_dispatch(ctx); + vkr_context_init_descriptor_set_dispatch(ctx); + vkr_context_init_descriptor_update_template_dispatch(ctx); vkr_context_init_render_pass_dispatch(ctx); vkr_context_init_framebuffer_dispatch(ctx);