diff --git a/src/meson.build b/src/meson.build index 6542ad4..efeea85 100644 --- a/src/meson.build +++ b/src/meson.build @@ -115,6 +115,23 @@ venus_sources = [ 'venus/vkr_transport.h', ] +venus_codegen = custom_target( + 'venus_codegen', + input : ['venus/vkr_device_object.py', 'venus/vkr_device_object.json'], + output : [ + 'vkr_buffer_gen.h', + 'vkr_command_buffer_gen.h', + 'vkr_descriptor_set_gen.h', + 'vkr_device_memory_gen.h', + 'vkr_image_gen.h', + 'vkr_pipeline_gen.h', + 'vkr_query_pool_gen.h', + 'vkr_queue_gen.h', + 'vkr_render_pass_gen.h', + ], + command : [prog_python, '@INPUT0@', '-o', '@OUTDIR@', '@INPUT1@'], +) + virgl_depends = [ gallium_dep, epoxy_dep, @@ -145,6 +162,7 @@ endif if with_venus virgl_sources += venus_sources + virgl_sources += venus_codegen virgl_depends += [venus_dep] endif diff --git a/src/venus/vkr_buffer.c b/src/venus/vkr_buffer.c index 69f54bc..6b7b9e3 100644 --- a/src/venus/vkr_buffer.c +++ b/src/venus/vkr_buffer.c @@ -5,11 +5,7 @@ #include "vkr_buffer.h" -#include "venus-protocol/vn_protocol_renderer_buffer.h" -#include "venus-protocol/vn_protocol_renderer_buffer_view.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_buffer_gen.h" #include "vkr_physical_device.h" static void diff --git a/src/venus/vkr_command_buffer.c b/src/venus/vkr_command_buffer.c index 80ab446..fd5c7db 100644 --- a/src/venus/vkr_command_buffer.c +++ b/src/venus/vkr_command_buffer.c @@ -5,11 +5,7 @@ #include "vkr_command_buffer.h" -#include "venus-protocol/vn_protocol_renderer_command_buffer.h" -#include "venus-protocol/vn_protocol_renderer_command_pool.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_command_buffer_gen.h" static void vkr_dispatch_vkCreateCommandPool(struct vn_dispatch_context *dispatch, diff --git a/src/venus/vkr_descriptor_set.c b/src/venus/vkr_descriptor_set.c index 3790a90..9b149e7 100644 --- a/src/venus/vkr_descriptor_set.c +++ b/src/venus/vkr_descriptor_set.c @@ -5,13 +5,7 @@ #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" +#include "vkr_descriptor_set_gen.h" static void vkr_dispatch_vkGetDescriptorSetLayoutSupport( diff --git a/src/venus/vkr_device_memory.c b/src/venus/vkr_device_memory.c index 5e1a0ef..340dcf4 100644 --- a/src/venus/vkr_device_memory.c +++ b/src/venus/vkr_device_memory.c @@ -5,11 +5,9 @@ #include "vkr_device_memory.h" -#include "venus-protocol/vn_protocol_renderer_device_memory.h" #include "venus-protocol/vn_protocol_renderer_transport.h" -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_device_memory_gen.h" #include "vkr_physical_device.h" static bool diff --git a/src/venus/vkr_device_object.json b/src/venus/vkr_device_object.json new file mode 100644 index 0000000..ae8657c --- /dev/null +++ b/src/venus/vkr_device_object.json @@ -0,0 +1,317 @@ +[ + { + "filename": "vkr_buffer_gen.h", + "objects": [ + { + "vkr_type": "buffer", + "vk_type": "VkBuffer", + "vk_enum": "VK_OBJECT_TYPE_BUFFER", + "generator": "simple-object", + "create_cmd": "vkCreateBuffer", + "create_info": "pCreateInfo", + "create_obj": "pBuffer", + "destroy_cmd": "vkDestroyBuffer", + "destroy_obj": "buffer" + }, + { + "vkr_type": "buffer_view", + "vk_type": "VkBufferView", + "vk_enum": "VK_OBJECT_TYPE_BUFFER_VIEW", + "generator": "simple-object", + "create_cmd": "vkCreateBufferView", + "create_info": "pCreateInfo", + "create_obj": "pView", + "destroy_cmd": "vkDestroyBufferView", + "destroy_obj": "bufferView" + } + ] + }, + { + "filename": "vkr_command_buffer_gen.h", + "objects": [ + { + "vkr_type": "command_pool", + "vk_type": "VkCommandPool", + "vk_enum": "VK_OBJECT_TYPE_COMMAND_POOL", + "generator": "simple-object", + "create_cmd": "vkCreateCommandPool", + "create_info": "pCreateInfo", + "create_obj": "pCommandPool", + "destroy_cmd": "vkDestroyCommandPool", + "destroy_obj": "commandPool" + }, + { + "vkr_type": "command_buffer", + "vk_type": "VkCommandBuffer", + "vk_enum": "VK_OBJECT_TYPE_COMMAND_BUFFER", + "generator": "pool-object", + "pool_type": "command_pool", + "create_cmd": "vkAllocateCommandBuffers", + "create_info": "pAllocateInfo", + "create_count": "pAllocateInfo->commandBufferCount", + "create_objs": "pCommandBuffers", + "destroy_cmd": "vkFreeCommandBuffers", + "destroy_pool": "commandPool", + "destroy_count": "commandBufferCount", + "destroy_objs": "pCommandBuffers" + } + ] + }, + { + "filename": "vkr_descriptor_set_gen.h", + "objects": [ + { + "vkr_type": "descriptor_set_layout", + "vk_type": "VkDescriptorSetLayout", + "vk_enum": "VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT", + "generator": "simple-object", + "create_cmd": "vkCreateDescriptorSetLayout", + "create_info": "pCreateInfo", + "create_obj": "pSetLayout", + "destroy_cmd": "vkDestroyDescriptorSetLayout", + "destroy_obj": "descriptorSetLayout" + }, + { + "vkr_type": "descriptor_pool", + "vk_type": "VkDescriptorPool", + "vk_enum": "VK_OBJECT_TYPE_DESCRIPTOR_POOL", + "generator": "simple-object", + "create_cmd": "vkCreateDescriptorPool", + "create_info": "pCreateInfo", + "create_obj": "pDescriptorPool", + "destroy_cmd": "vkDestroyDescriptorPool", + "destroy_obj": "descriptorPool" + }, + { + "vkr_type": "descriptor_set", + "vk_type": "VkDescriptorSet", + "vk_enum": "VK_OBJECT_TYPE_DESCRIPTOR_SET", + "generator": "pool-object", + "pool_type": "descriptor_pool", + "create_cmd": "vkAllocateDescriptorSets", + "create_info": "pAllocateInfo", + "create_count": "pAllocateInfo->descriptorSetCount", + "create_objs": "pDescriptorSets", + "destroy_cmd": "vkFreeDescriptorSets", + "destroy_pool": "descriptorPool", + "destroy_count": "descriptorSetCount", + "destroy_objs": "pDescriptorSets" + }, + { + "vkr_type": "descriptor_update_template", + "vk_type": "VkDescriptorUpdateTemplate", + "vk_enum": "VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE", + "generator": "simple-object", + "create_cmd": "vkCreateDescriptorUpdateTemplate", + "create_info": "pCreateInfo", + "create_obj": "pDescriptorUpdateTemplate", + "destroy_cmd": "vkDestroyDescriptorUpdateTemplate", + "destroy_obj": "descriptorUpdateTemplate" + } + ] + }, + { + "filename": "vkr_device_memory_gen.h", + "objects": [ + { + "vkr_type": "device_memory", + "vk_type": "VkDeviceMemory", + "vk_enum": "VK_OBJECT_TYPE_DEVICE_MEMORY", + "generator": "simple-object", + "create_cmd": "vkAllocateMemory", + "create_info": "pAllocateInfo", + "create_obj": "pMemory", + "destroy_cmd": "vkFreeMemory", + "destroy_obj": "memory" + } + ] + }, + { + "filename": "vkr_image_gen.h", + "objects": [ + { + "vkr_type": "image", + "vk_type": "VkImage", + "vk_enum": "VK_OBJECT_TYPE_IMAGE", + "generator": "simple-object", + "create_cmd": "vkCreateImage", + "create_info": "pCreateInfo", + "create_obj": "pImage", + "destroy_cmd": "vkDestroyImage", + "destroy_obj": "image" + }, + { + "vkr_type": "image_view", + "vk_type": "VkImageView", + "vk_enum": "VK_OBJECT_TYPE_IMAGE_VIEW", + "generator": "simple-object", + "create_cmd": "vkCreateImageView", + "create_info": "pCreateInfo", + "create_obj": "pView", + "destroy_cmd": "vkDestroyImageView", + "destroy_obj": "imageView" + }, + { + "vkr_type": "sampler", + "vk_type": "VkSampler", + "vk_enum": "VK_OBJECT_TYPE_SAMPLER", + "generator": "simple-object", + "create_cmd": "vkCreateSampler", + "create_info": "pCreateInfo", + "create_obj": "pSampler", + "destroy_cmd": "vkDestroySampler", + "destroy_obj": "sampler" + }, + { + "vkr_type": "sampler_ycbcr_conversion", + "vk_type": "VkSamplerYcbcrConversion", + "vk_enum": "VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION", + "generator": "simple-object", + "create_cmd": "vkCreateSamplerYcbcrConversion", + "create_info": "pCreateInfo", + "create_obj": "pYcbcrConversion", + "destroy_cmd": "vkDestroySamplerYcbcrConversion", + "destroy_obj": "ycbcrConversion" + } + ] + }, + { + "filename": "vkr_pipeline_gen.h", + "objects": [ + { + "vkr_type": "shader_module", + "vk_type": "VkShaderModule", + "vk_enum": "VK_OBJECT_TYPE_SHADER_MODULE", + "generator": "simple-object", + "create_cmd": "vkCreateShaderModule", + "create_info": "pCreateInfo", + "create_obj": "pShaderModule", + "destroy_cmd": "vkDestroyShaderModule", + "destroy_obj": "shaderModule" + }, + { + "vkr_type": "pipeline_layout", + "vk_type": "VkPipelineLayout", + "vk_enum": "VK_OBJECT_TYPE_PIPELINE_LAYOUT", + "generator": "simple-object", + "create_cmd": "vkCreatePipelineLayout", + "create_info": "pCreateInfo", + "create_obj": "pPipelineLayout", + "destroy_cmd": "vkDestroyPipelineLayout", + "destroy_obj": "pipelineLayout" + }, + { + "vkr_type": "pipeline_cache", + "vk_type": "VkPipelineCache", + "vk_enum": "VK_OBJECT_TYPE_PIPELINE_CACHE", + "generator": "simple-object", + "create_cmd": "vkCreatePipelineCache", + "create_info": "pCreateInfo", + "create_obj": "pPipelineCache", + "destroy_cmd": "vkDestroyPipelineCache", + "destroy_obj": "pipelineCache" + }, + { + "vkr_type": "pipeline", + "vk_type": "VkPipeline", + "vk_enum": "VK_OBJECT_TYPE_PIPELINE", + "generator": "pipeline-object", + "create_func_name": "graphics_pipeline", + "create_cmd": "vkCreateGraphicsPipelines", + "create_cache": "pipelineCache", + "create_count": "createInfoCount", + "create_info": "pCreateInfos", + "create_objs": "pPipelines", + "destroy_cmd": "vkDestroyPipeline", + "destroy_obj": "pipeline", + "variants": [ + { + "create_func_name": "compute_pipeline", + "create_cmd": "vkCreateComputePipelines" + } + ] + } + ] + }, + { + "filename": "vkr_query_pool_gen.h", + "objects": [ + { + "vkr_type": "query_pool", + "vk_type": "VkQueryPool", + "vk_enum": "VK_OBJECT_TYPE_QUERY_POOL", + "generator": "simple-object", + "create_cmd": "vkCreateQueryPool", + "create_info": "pCreateInfo", + "create_obj": "pQueryPool", + "destroy_cmd": "vkDestroyQueryPool", + "destroy_obj": "queryPool" + } + ] + }, + { + "filename": "vkr_queue_gen.h", + "objects": [ + { + "vkr_type": "fence", + "vk_type": "VkFence", + "vk_enum": "VK_OBJECT_TYPE_FENCE", + "generator": "simple-object", + "create_cmd": "vkCreateFence", + "create_info": "pCreateInfo", + "create_obj": "pFence", + "destroy_cmd": "vkDestroyFence", + "destroy_obj": "fence" + }, + { + "vkr_type": "semaphore", + "vk_type": "VkSemaphore", + "vk_enum": "VK_OBJECT_TYPE_SEMAPHORE", + "generator": "simple-object", + "create_cmd": "vkCreateSemaphore", + "create_info": "pCreateInfo", + "create_obj": "pSemaphore", + "destroy_cmd": "vkDestroySemaphore", + "destroy_obj": "semaphore" + }, + { + "vkr_type": "event", + "vk_type": "VkEvent", + "vk_enum": "VK_OBJECT_TYPE_EVENT", + "generator": "simple-object", + "create_cmd": "vkCreateEvent", + "create_info": "pCreateInfo", + "create_obj": "pEvent", + "destroy_cmd": "vkDestroyEvent", + "destroy_obj": "event" + } + ] + }, + { + "filename": "vkr_render_pass_gen.h", + "objects": [ + { + "vkr_type": "render_pass", + "vk_type": "VkRenderPass", + "vk_enum": "VK_OBJECT_TYPE_RENDER_PASS", + "generator": "simple-object", + "create_cmd": "vkCreateRenderPass", + "create_info": "pCreateInfo", + "create_obj": "pRenderPass", + "destroy_cmd": "vkDestroyRenderPass", + "destroy_obj": "renderPass" + }, + { + "vkr_type": "framebuffer", + "vk_type": "VkFramebuffer", + "vk_enum": "VK_OBJECT_TYPE_FRAMEBUFFER", + "generator": "simple-object", + "create_cmd": "vkCreateFramebuffer", + "create_info": "pCreateInfo", + "create_obj": "pFramebuffer", + "destroy_cmd": "vkDestroyFramebuffer", + "destroy_obj": "framebuffer" + } + ] + } +] diff --git a/src/venus/vkr_device_object.py b/src/venus/vkr_device_object.py new file mode 100644 index 0000000..6a44955 --- /dev/null +++ b/src/venus/vkr_device_object.py @@ -0,0 +1,97 @@ +#Copyright 2021 Google LLC +#SPDX - License - Identifier : MIT + +import argparse +import json +import os + +def simple_object_generator(json_obj): + return '' + +def pool_object_generator(json_obj): + return '' + +def pipeline_object_generator(json_obj): + return '' + +object_generators = { + 'simple-object': simple_object_generator, + 'pool-object': pool_object_generator, + 'pipeline-object': pipeline_object_generator, +} + +FILE_HEADER_TEMPL = ''' +/* This file is generated by {script}. */ + +#ifndef {guard} +#define {guard} + +#include "vkr_common.h" + +{protocol_includes} + +#include "vkr_context.h" +#include "vkr_device.h" +''' + +FILE_FOOTER_TEMPL = ''' +#endif /* {guard} */ +''' + +def get_guard(filename): + return filename.upper().translate(str.maketrans('.', '_')) + +def file_header_generator(json_file): + script = os.path.basename(__file__) + guard = get_guard(json_file['filename']) + + include_filenames = [] + for json_obj in json_file['objects']: + name = 'venus-protocol/vn_protocol_renderer_{}.h'.format( + json_obj['vkr_type']) + include_filenames.append(name) + protocol_includes = '#include "' + '"\n#include "'.join(include_filenames) + '"' + + return FILE_HEADER_TEMPL.format(script=script, guard=guard, + protocol_includes=protocol_includes).lstrip() + +def file_footer_generator(json_file): + guard = get_guard(json_file['filename']) + return FILE_FOOTER_TEMPL.format(guard=guard) + +def process_objects(json_objs): + for json_obj in json_objs: + json_obj.setdefault('create_func_name', json_obj['vkr_type']) + json_obj.setdefault('destroy_func_name', json_obj['vkr_type']) + json_obj.setdefault('variants', []) + +def file_generator(json_file): + contents = file_header_generator(json_file) + for json_obj in json_file['objects']: + contents += object_generators[json_obj['generator']](json_obj) + contents += file_footer_generator(json_file) + + return contents + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('json', help='specifies the input JSON file') + parser.add_argument('-o', '--output-dir', required=True, + help='specifies output directory') + return parser.parse_args() + +def main(): + args = parse_args() + with open(args.json) as f: + json_files = json.load(f) + + for json_file in json_files: + process_objects(json_file['objects']) + + output = os.path.join(args.output_dir, json_file['filename']) + with open(output, 'wb') as f: + contents = file_generator(json_file) + f.write(contents.encode()) + +if __name__ == '__main__': + main() diff --git a/src/venus/vkr_image.c b/src/venus/vkr_image.c index 4a38651..9c84dba 100644 --- a/src/venus/vkr_image.c +++ b/src/venus/vkr_image.c @@ -5,13 +5,7 @@ #include "vkr_image.h" -#include "venus-protocol/vn_protocol_renderer_image.h" -#include "venus-protocol/vn_protocol_renderer_image_view.h" -#include "venus-protocol/vn_protocol_renderer_sampler.h" -#include "venus-protocol/vn_protocol_renderer_sampler_ycbcr_conversion.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_image_gen.h" #include "vkr_physical_device.h" static void diff --git a/src/venus/vkr_pipeline.c b/src/venus/vkr_pipeline.c index df50c55..27ac483 100644 --- a/src/venus/vkr_pipeline.c +++ b/src/venus/vkr_pipeline.c @@ -5,13 +5,7 @@ #include "vkr_pipeline.h" -#include "venus-protocol/vn_protocol_renderer_pipeline.h" -#include "venus-protocol/vn_protocol_renderer_pipeline_cache.h" -#include "venus-protocol/vn_protocol_renderer_pipeline_layout.h" -#include "venus-protocol/vn_protocol_renderer_shader_module.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_pipeline_gen.h" static void vkr_dispatch_vkCreateShaderModule(struct vn_dispatch_context *dispatch, diff --git a/src/venus/vkr_query_pool.c b/src/venus/vkr_query_pool.c index 168ce9a..081f5ea 100644 --- a/src/venus/vkr_query_pool.c +++ b/src/venus/vkr_query_pool.c @@ -5,10 +5,7 @@ #include "vkr_query_pool.h" -#include "venus-protocol/vn_protocol_renderer_query_pool.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_query_pool_gen.h" static void vkr_dispatch_vkCreateQueryPool(struct vn_dispatch_context *dispatch, diff --git a/src/venus/vkr_queue.c b/src/venus/vkr_queue.c index 6704d84..9a657df 100644 --- a/src/venus/vkr_queue.c +++ b/src/venus/vkr_queue.c @@ -5,15 +5,10 @@ #include "vkr_queue.h" -#include "venus-protocol/vn_protocol_renderer_device.h" -#include "venus-protocol/vn_protocol_renderer_event.h" -#include "venus-protocol/vn_protocol_renderer_fence.h" #include "venus-protocol/vn_protocol_renderer_queue.h" -#include "venus-protocol/vn_protocol_renderer_semaphore.h" -#include "vkr_context.h" -#include "vkr_device.h" #include "vkr_physical_device.h" +#include "vkr_queue_gen.h" struct vkr_queue_sync * vkr_device_alloc_queue_sync(struct vkr_device *dev, diff --git a/src/venus/vkr_render_pass.c b/src/venus/vkr_render_pass.c index dd96b0f..e4b0ee7 100644 --- a/src/venus/vkr_render_pass.c +++ b/src/venus/vkr_render_pass.c @@ -5,11 +5,7 @@ #include "vkr_render_pass.h" -#include "venus-protocol/vn_protocol_renderer_framebuffer.h" -#include "venus-protocol/vn_protocol_renderer_render_pass.h" - -#include "vkr_context.h" -#include "vkr_device.h" +#include "vkr_render_pass_gen.h" static void vkr_dispatch_vkCreateRenderPass(struct vn_dispatch_context *dispatch,