vulkan: Generate entrypoints that enqueue commands

For drivers such as Lavapipe that record the commands at the execution
stage.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12369>
This commit is contained in:
Tomeu Vizoso
2021-08-24 11:14:33 +02:00
committed by Marge Bot
parent a7b0946ef0
commit 997a6ca226
2 changed files with 143 additions and 0 deletions

View File

@@ -38,10 +38,15 @@ vk_cmd_queue_gen_depend_files = [
files('vk_dispatch_table_gen.py'),
vk_dispatch_table_gen_depend_files,
]
vk_commands_gen_depend_files = [
files('vk_dispatch_table_gen.py'),
vk_dispatch_table_gen_depend_files,
]
vk_entrypoints_gen = files('vk_entrypoints_gen.py')
vk_extensions_gen = files('vk_extensions_gen.py')
vk_icd_gen = files('vk_icd_gen.py')
vk_commands_gen = files('vk_commands_gen.py')
files_vulkan_util = files(
'vk_alloc.c',

View File

@@ -0,0 +1,138 @@
# coding=utf-8
COPYRIGHT=u"""
/* Copyright © 2015-2021 Intel Corporation
* Copyright © 2021 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
"""
import argparse
import os
import re
import xml.etree.ElementTree as et
from mako.template import Template
# Mesa-local imports must be declared in meson variable
# '{file_without_suffix}_depend_files'.
from vk_dispatch_table_gen import get_entrypoints_from_xml, EntrypointParam
MANUAL_COMMANDS = ['CmdPushDescriptorSetKHR', # This script doesn't know how to copy arrays in structs in arrays
'CmdPushDescriptorSetWithTemplateKHR', # pData's size cannot be calculated from the xml
'CmdDrawMultiEXT', # The size of the elements is specified in a stride param
'CmdDrawMultiIndexedEXT', # The size of the elements is specified in a stride param
'CmdBindDescriptorSets', # The VkPipelineLayout object could be released before the command is executed
'CmdCopyImageToBuffer', # There are wrappers that implement these in terms of the newer variants
'CmdCopyImage',
'CmdCopyBuffer',
'CmdCopyImage',
'CmdCopyBufferToImage',
'CmdCopyImageToBuffer',
'CmdBlitImage',
'CmdResolveImage',
]
TEMPLATE_C = Template(COPYRIGHT + """
/* This file generated from ${filename}, don't edit directly. */
#define VK_PROTOTYPES
#include <vulkan/vulkan.h>
#include "lvp_private.h"
#include "pipe/p_context.h"
#include "vk_util.h"
% for c in commands:
% if c.name in manual_commands:
<% continue %>
% endif
% if c.guard is not None:
#ifdef ${c.guard}
% endif
VKAPI_ATTR ${c.return_type} VKAPI_CALL lvp_${c.name} (VkCommandBuffer commandBuffer
% for p in c.params[1:]:
, ${p.decl}
% endfor
)
{
LVP_FROM_HANDLE(lvp_cmd_buffer, cmd_buffer, commandBuffer);
vk_enqueue_${to_underscore(c.name)}(&cmd_buffer->queue
% for p in c.params[1:]:
, ${p.name}
% endfor
);
% if c.return_type == 'VkResult':
return VK_SUCCESS;
% endif
}
% if c.guard is not None:
#endif // ${c.guard}
% endif
% endfor
""", output_encoding='utf-8')
def to_underscore(name):
return re.sub('([A-Z]+)', r'_\1', name).lower().removeprefix('_')
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--out-c', required=True, help='Output C file.')
parser.add_argument('--xml',
help='Vulkan API XML file.',
required=True, action='append', dest='xml_files')
parser.add_argument('--prefix',
help='Prefix to use for all dispatch tables.',
action='append', default=[], dest='prefixes')
args = parser.parse_args()
commands = []
for e in get_entrypoints_from_xml(args.xml_files):
if e.name.startswith('Cmd') and \
not e.alias:
commands.append(e)
environment = {
'commands': commands,
'filename': os.path.basename(__file__),
'to_underscore': to_underscore,
'manual_commands': MANUAL_COMMANDS,
}
try:
with open(args.out_c, 'wb') as f:
f.write(TEMPLATE_C.render(**environment))
except Exception:
# In the event there's an error, this imports some helpers from mako
# to print a useful stack trace and prints it, then exits with
# status 1, if python is run with debug; otherwise it just raises
# the exception
if __debug__:
import sys
from mako import exceptions
sys.stderr.write(exceptions.text_error_template().render() + '\n')
sys.exit(1)
raise
if __name__ == '__main__':
main()