v3dv: port to using common dispatch code.

This moves v3dv over to using the new common dispatch layer code.

v2 (Jason Ekstrand):
 - Remove some now dead function declarations

Acked-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8676>
This commit is contained in:
Alejandro Piñeiro 2021-01-28 00:21:38 +01:00 committed by Marge Bot
parent 3e2bbf5d50
commit 21f9a88673
6 changed files with 51 additions and 1201 deletions

View file

@ -19,14 +19,13 @@
# SOFTWARE.
v3dv_entrypoints = custom_target(
'v3dv_entrypoints.[ch]',
input : ['v3dv_entrypoints_gen.py', vk_api_xml],
'v3dv_entrypoints',
input : [vk_entrypoints_gen, vk_api_xml],
output : ['v3dv_entrypoints.h', 'v3dv_entrypoints.c'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--outdir',
meson.current_build_dir()
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--proto', '--weak',
'--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', '--prefix', 'v3dv',
],
depend_files : files('v3dv_extensions.py'),
)
v3dv_extensions_c = custom_target(

View file

@ -99,10 +99,10 @@ v3dv_EnumerateInstanceExtensionProperties(const char *pLayerName,
VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
for (int i = 0; i < V3DV_INSTANCE_EXTENSION_COUNT; i++) {
for (int i = 0; i < VK_INSTANCE_EXTENSION_COUNT; i++) {
if (v3dv_instance_extensions_supported.extensions[i]) {
vk_outarray_append(&out, prop) {
*prop = v3dv_instance_extensions[i];
*prop = vk_instance_extensions[i];
}
}
}
@ -120,24 +120,6 @@ v3dv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
struct v3dv_instance_extension_table enabled_extensions = {};
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < V3DV_INSTANCE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
v3dv_instance_extensions[idx].extensionName) == 0)
break;
}
if (idx >= V3DV_INSTANCE_EXTENSION_COUNT)
return vk_error(NULL, VK_ERROR_EXTENSION_NOT_PRESENT);
if (!v3dv_instance_extensions_supported.extensions[idx])
return vk_error(NULL, VK_ERROR_EXTENSION_NOT_PRESENT);
enabled_extensions.extensions[idx] = true;
}
if (pAllocator == NULL)
pAllocator = &default_alloc;
@ -146,7 +128,13 @@ v3dv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
if (!instance)
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
result = vk_instance_init(&instance->vk, NULL, NULL,
struct vk_instance_dispatch_table dispatch_table;
vk_instance_dispatch_table_from_entrypoints(
&dispatch_table, &v3dv_instance_entrypoints, true);
result = vk_instance_init(&instance->vk,
&v3dv_instance_extensions_supported,
&dispatch_table,
pCreateInfo, pAllocator);
if (result != VK_SUCCESS) {
@ -156,52 +144,6 @@ v3dv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
v3d_process_debug_variable();
instance->enabled_extensions = enabled_extensions;
for (unsigned i = 0; i < ARRAY_SIZE(instance->dispatch.entrypoints); i++) {
/* Vulkan requires that entrypoints for extensions which have not been
* enabled must not be advertised.
*/
if (!v3dv_instance_entrypoint_is_enabled(i,
instance->vk.app_info.api_version,
&instance->enabled_extensions)) {
instance->dispatch.entrypoints[i] = NULL;
} else {
instance->dispatch.entrypoints[i] =
v3dv_instance_dispatch_table.entrypoints[i];
}
}
struct v3dv_physical_device *pdevice = &instance->physicalDevice;
for (unsigned i = 0; i < ARRAY_SIZE(pdevice->dispatch.entrypoints); i++) {
/* Vulkan requires that entrypoints for extensions which have not been
* enabled must not be advertised.
*/
if (!v3dv_physical_device_entrypoint_is_enabled(i,
instance->vk.app_info.api_version,
&instance->enabled_extensions)) {
pdevice->dispatch.entrypoints[i] = NULL;
} else {
pdevice->dispatch.entrypoints[i] =
v3dv_physical_device_dispatch_table.entrypoints[i];
}
}
for (unsigned i = 0; i < ARRAY_SIZE(instance->device_dispatch.entrypoints); i++) {
/* Vulkan requires that entrypoints for extensions which have not been
* enabled must not be advertised.
*/
if (!v3dv_device_entrypoint_is_enabled(i,
instance->vk.app_info.api_version,
&instance->enabled_extensions,
NULL)) {
instance->device_dispatch.entrypoints[i] = NULL;
} else {
instance->device_dispatch.entrypoints[i] =
v3dv_device_dispatch_table.entrypoints[i];
}
}
instance->physicalDeviceCount = -1;
result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
@ -675,7 +617,12 @@ physical_device_init(struct v3dv_physical_device *device,
VkResult result = VK_SUCCESS;
int32_t master_fd = -1;
result = vk_physical_device_init(&device->vk, &instance->vk, NULL, NULL);
struct vk_physical_device_dispatch_table dispatch_table;
vk_physical_device_dispatch_table_from_entrypoints
(&dispatch_table, &v3dv_physical_device_entrypoints, true);
result = vk_physical_device_init(&device->vk, &instance->vk, NULL,
&dispatch_table);
if (result != VK_SUCCESS)
goto fail;
@ -693,7 +640,7 @@ physical_device_init(struct v3dv_physical_device *device,
* we postpone that until a swapchain is created.
*/
if (instance->enabled_extensions.KHR_display) {
if (instance->vk.enabled_extensions.KHR_display) {
#if !using_v3d_simulator
/* Open the primary node on the vc4 display device */
assert(drm_primary_device);
@ -764,7 +711,7 @@ physical_device_init(struct v3dv_physical_device *device,
}
v3dv_physical_device_get_supported_extensions(device,
&device->supported_extensions);
&device->vk.supported_extensions);
pthread_mutex_init(&device->mutex, NULL);
@ -1306,39 +1253,9 @@ v3dv_GetInstanceProcAddr(VkInstance _instance,
const char *pName)
{
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
/* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
* when we have to return valid function pointers, NULL, or it's left
* undefined. See the table for exact details.
*/
if (pName == NULL)
return NULL;
#define LOOKUP_V3DV_ENTRYPOINT(entrypoint) \
if (strcmp(pName, "vk" #entrypoint) == 0) \
return (PFN_vkVoidFunction)v3dv_##entrypoint
LOOKUP_V3DV_ENTRYPOINT(EnumerateInstanceExtensionProperties);
LOOKUP_V3DV_ENTRYPOINT(CreateInstance);
#undef LOOKUP_V3DV_ENTRYPOINT
if (instance == NULL)
return NULL;
int idx = v3dv_get_instance_entrypoint_index(pName);
if (idx >= 0)
return instance->dispatch.entrypoints[idx];
idx = v3dv_get_physical_device_entrypoint_index(pName);
if (idx >= 0)
return instance->physicalDevice.dispatch.entrypoints[idx];
idx = v3dv_get_device_entrypoint_index(pName);
if (idx >= 0)
return instance->device_dispatch.entrypoints[idx];
return NULL;
return vk_instance_get_proc_addr(&instance->vk,
&v3dv_instance_entrypoints,
pName);
}
/* With version 1+ of the loader interface the ICD should expose
@ -1357,22 +1274,6 @@ vk_icdGetInstanceProcAddr(VkInstance instance,
return v3dv_GetInstanceProcAddr(instance, pName);
}
PFN_vkVoidFunction
v3dv_GetDeviceProcAddr(VkDevice _device,
const char *pName)
{
V3DV_FROM_HANDLE(v3dv_device, device, _device);
if (!device || !pName)
return NULL;
int idx = v3dv_get_device_entrypoint_index(pName);
if (idx < 0)
return NULL;
return device->dispatch.entrypoints[idx];
}
/* With version 4+ of the loader interface the ICD should expose
* vk_icdGetPhysicalDeviceProcAddr()
*/
@ -1387,38 +1288,7 @@ vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance,
{
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
if (!pName || !instance)
return NULL;
int idx = v3dv_get_physical_device_entrypoint_index(pName);
if (idx < 0)
return NULL;
return instance->physicalDevice.dispatch.entrypoints[idx];
}
VkResult
v3dv_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
/* We don't support any layers */
if (pLayerName)
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
V3DV_FROM_HANDLE(v3dv_physical_device, device, physicalDevice);
VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
for (int i = 0; i < V3DV_DEVICE_EXTENSION_COUNT; i++) {
if (device->supported_extensions.extensions[i]) {
vk_outarray_append(&out, prop) {
*prop = v3dv_device_extensions[i];
}
}
}
return vk_outarray_status(&out);
return vk_instance_get_physical_device_proc_addr(&instance->vk, pName);
}
VkResult
@ -1471,24 +1341,6 @@ queue_finish(struct v3dv_queue *queue)
pthread_mutex_destroy(&queue->mutex);
}
static void
init_device_dispatch(struct v3dv_device *device)
{
for (unsigned i = 0; i < ARRAY_SIZE(device->dispatch.entrypoints); i++) {
/* Vulkan requires that entrypoints for extensions which have not been
* enabled must not be advertised.
*/
if (!v3dv_device_entrypoint_is_enabled(i, device->instance->vk.app_info.api_version,
&device->instance->enabled_extensions,
&device->enabled_extensions)) {
device->dispatch.entrypoints[i] = NULL;
} else {
device->dispatch.entrypoints[i] =
v3dv_device_dispatch_table.entrypoints[i];
}
}
}
static void
init_device_meta(struct v3dv_device *device)
{
@ -1520,25 +1372,6 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
/* Check enabled extensions */
struct v3dv_device_extension_table enabled_extensions = { };
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < V3DV_DEVICE_EXTENSION_COUNT; idx++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
v3dv_device_extensions[idx].extensionName) == 0)
break;
}
if (idx >= V3DV_DEVICE_EXTENSION_COUNT)
return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT);
if (!physical_device->supported_extensions.extensions[idx])
return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT);
enabled_extensions.extensions[idx] = true;
}
/* Check enabled features */
if (pCreateInfo->pEnabledFeatures) {
VkPhysicalDeviceFeatures supported_features;
@ -1567,7 +1400,11 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
if (!device)
return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
result = vk_device_init(&device->vk, NULL, NULL, pCreateInfo,
struct vk_device_dispatch_table dispatch_table;
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
&v3dv_device_entrypoints, true);
result = vk_device_init(&device->vk, &physical_device->vk,
&dispatch_table, pCreateInfo,
&physical_device->vk.instance->alloc, pAllocator);
if (result != VK_SUCCESS) {
vk_free(&device->vk.alloc, device);
@ -1589,7 +1426,6 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
goto fail;
device->devinfo = physical_device->devinfo;
device->enabled_extensions = enabled_extensions;
if (pCreateInfo->pEnabledFeatures) {
memcpy(&device->features, pCreateInfo->pEnabledFeatures,
@ -1604,7 +1440,6 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
goto fail;
}
init_device_dispatch(device);
init_device_meta(device);
v3dv_bo_cache_init(device);
v3dv_pipeline_cache_init(&device->default_pipeline_cache, device,

View file

@ -1,798 +0,0 @@
# coding=utf-8
#
# Copyright © 2015, 2017 Intel Corporation
#
# 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 math
import os
import xml.etree.cElementTree as et
from collections import OrderedDict, namedtuple
from mako.template import Template
from v3dv_extensions import VkVersion, MAX_API_VERSION, EXTENSIONS
# We currently don't use layers in v3dv, but keeping the ability for anv
# anyways, so we can use it for device groups.
LAYERS = [
'v3dv'
]
TEMPLATE_H = Template("""\
/* This file generated from ${filename}, don't edit directly. */
struct v3dv_instance_dispatch_table {
union {
void *entrypoints[${len(instance_entrypoints)}];
struct {
% for e in instance_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
PFN_${e.name} ${e.name};
#else
void *${e.name};
# endif
% else:
PFN_${e.name} ${e.name};
% endif
% endfor
};
};
};
struct v3dv_physical_device_dispatch_table {
union {
void *entrypoints[${len(physical_device_entrypoints)}];
struct {
% for e in physical_device_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
PFN_${e.name} ${e.name};
#else
void *${e.name};
# endif
% else:
PFN_${e.name} ${e.name};
% endif
% endfor
};
};
};
struct v3dv_device_dispatch_table {
union {
void *entrypoints[${len(device_entrypoints)}];
struct {
% for e in device_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
PFN_${e.name} ${e.name};
#else
void *${e.name};
# endif
% else:
PFN_${e.name} ${e.name};
% endif
% endfor
};
};
};
extern const struct v3dv_instance_dispatch_table v3dv_instance_dispatch_table;
%for layer in LAYERS:
extern const struct v3dv_physical_device_dispatch_table ${layer}_physical_device_dispatch_table;
%endfor
%for layer in LAYERS:
extern const struct v3dv_device_dispatch_table ${layer}_device_dispatch_table;
%endfor
% for e in instance_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
${e.return_type} ${e.prefixed_name('v3dv')}(${e.decl_params()});
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
% for e in physical_device_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
% for layer in LAYERS:
${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()});
% endfor
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
% for e in device_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
% for layer in LAYERS:
${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()});
% endfor
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
""", output_encoding='utf-8')
TEMPLATE_C = Template(u"""\
/*
* Copyright © 2015 Intel Corporation
*
* 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.
*/
/* This file generated from ${filename}, don't edit directly. */
#include "v3dv_private.h"
#include "util/macros.h"
struct string_map_entry {
uint32_t name;
uint32_t hash;
uint32_t num;
};
/* We use a big string constant to avoid lots of reloctions from the entry
* point table to lots of little strings. The entries in the entry point table
* store the index into this big string.
*/
<%def name="strmap(strmap, prefix)">
static const char ${prefix}_strings[] =
% for s in strmap.sorted_strings:
"${s.string}\\0"
% endfor
;
static const struct string_map_entry ${prefix}_string_map_entries[] = {
% for s in strmap.sorted_strings:
{ ${s.offset}, ${'{:0=#8x}'.format(s.hash)}, ${s.num} }, /* ${s.string} */
% endfor
};
/* Hash table stats:
* size ${len(strmap.sorted_strings)} entries
* collisions entries:
% for i in range(10):
* ${i}${'+' if i == 9 else ' '} ${strmap.collisions[i]}
% endfor
*/
#define none 0xffff
static const uint16_t ${prefix}_string_map[${strmap.hash_size}] = {
% for e in strmap.mapping:
${ '{:0=#6x}'.format(e) if e >= 0 else 'none' },
% endfor
};
static int
${prefix}_string_map_lookup(const char *str)
{
static const uint32_t prime_factor = ${strmap.prime_factor};
static const uint32_t prime_step = ${strmap.prime_step};
const struct string_map_entry *e;
uint32_t hash, h;
uint16_t i;
const char *p;
hash = 0;
for (p = str; *p; p++)
hash = hash * prime_factor + *p;
h = hash;
while (1) {
i = ${prefix}_string_map[h & ${strmap.hash_mask}];
if (i == none)
return -1;
e = &${prefix}_string_map_entries[i];
if (e->hash == hash && strcmp(str, ${prefix}_strings + e->name) == 0)
return e->num;
h += prime_step;
}
return -1;
}
static const char *
${prefix}_entry_name(int num)
{
for (int i = 0; i < ARRAY_SIZE(${prefix}_string_map_entries); i++) {
if (${prefix}_string_map_entries[i].num == num)
return &${prefix}_strings[${prefix}_string_map_entries[i].name];
}
return NULL;
}
</%def>
${strmap(instance_strmap, 'instance')}
${strmap(physical_device_strmap, 'physical_device')}
${strmap(device_strmap, 'device')}
/* Weak aliases for all potential implementations. These will resolve to
* NULL if they're not defined, which lets the resolve_entrypoint() function
* either pick the correct entry point.
*/
% for e in instance_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
${e.return_type} ${e.prefixed_name('v3dv')}(${e.decl_params()}) __attribute__ ((weak));
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
const struct v3dv_instance_dispatch_table v3dv_instance_dispatch_table = {
% for e in instance_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
% endif
.${e.name} = ${e.prefixed_name('v3dv')},
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
};
% for layer in LAYERS:
% for e in physical_device_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
% if layer == 'v3dv':
${e.return_type} __attribute__ ((weak))
${e.prefixed_name('v3dv')}(${e.decl_params()})
{
% if e.params[0].type == 'VkPhysicalDevice':
V3DV_FROM_HANDLE(v3dv_physical_device, v3dv_physical_device, ${e.params[0].name});
return v3dv_physical_device->dispatch.${e.name}(${e.call_params()});
% else:
assert(!"Unhandled device child trampoline case: ${e.params[0].type}");
% endif
}
% else:
${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()}) __attribute__ ((weak));
% endif
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
const struct v3dv_physical_device_dispatch_table ${layer}_physical_device_dispatch_table = {
% for e in physical_device_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
% endif
.${e.name} = ${e.prefixed_name(layer)},
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
};
% endfor
% for layer in LAYERS:
% for e in device_entrypoints:
% if e.alias:
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
% if layer == 'v3dv':
${e.return_type} __attribute__ ((weak))
${e.prefixed_name('v3dv')}(${e.decl_params()})
{
% if e.params[0].type == 'VkDevice':
V3DV_FROM_HANDLE(v3dv_device, v3dv_device, ${e.params[0].name});
return v3dv_device->dispatch.${e.name}(${e.call_params()});
% elif e.params[0].type == 'VkCommandBuffer':
V3DV_FROM_HANDLE(v3dv_cmd_buffer, v3dv_cmd_buffer, ${e.params[0].name});
return v3dv_cmd_buffer->device->dispatch.${e.name}(${e.call_params()});
% elif e.params[0].type == 'VkQueue':
V3DV_FROM_HANDLE(v3dv_queue, v3dv_queue, ${e.params[0].name});
return v3dv_queue->device->dispatch.${e.name}(${e.call_params()});
% else:
assert(!"Unhandled device child trampoline case: ${e.params[0].type}");
% endif
}
% else:
${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()}) __attribute__ ((weak));
% endif
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
const struct v3dv_device_dispatch_table ${layer}_device_dispatch_table = {
% for e in device_entrypoints:
% if e.guard is not None:
#ifdef ${e.guard}
% endif
.${e.name} = ${e.prefixed_name(layer)},
% if e.guard is not None:
#endif // ${e.guard}
% endif
% endfor
};
% endfor
/** Return true if the core version or extension in which the given entrypoint
* is defined is enabled.
*
* If device is NULL, all device extensions are considered enabled.
*/
bool
v3dv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance)
{
switch (index) {
% for e in instance_entrypoints:
case ${e.num}:
/* ${e.name} */
% if e.core_version:
return ${e.core_version.c_vk_version()} <= core_version;
% elif e.extensions:
% for ext in e.extensions:
% if ext.type == 'instance':
if (instance->${ext.name[3:]}) return true;
% else:
/* All device extensions are considered enabled at the instance level */
return true;
% endif
% endfor
return false;
% else:
return true;
% endif
% endfor
default:
return false;
}
}
/** Return true if the core version or extension in which the given entrypoint
* is defined is enabled.
*
* If device is NULL, all device extensions are considered enabled.
*/
bool
v3dv_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance)
{
switch (index) {
% for e in physical_device_entrypoints:
case ${e.num}:
/* ${e.name} */
% if e.core_version:
return ${e.core_version.c_vk_version()} <= core_version;
% elif e.extensions:
% for ext in e.extensions:
% if ext.type == 'instance':
if (instance->${ext.name[3:]}) return true;
% else:
/* All device extensions are considered enabled at the instance level */
return true;
% endif
% endfor
return false;
% else:
return true;
% endif
% endfor
default:
return false;
}
}
/** Return true if the core version or extension in which the given entrypoint
* is defined is enabled.
*
* If device is NULL, all device extensions are considered enabled.
*/
bool
v3dv_device_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance,
const struct v3dv_device_extension_table *device)
{
switch (index) {
% for e in device_entrypoints:
case ${e.num}:
/* ${e.name} */
% if e.core_version:
return ${e.core_version.c_vk_version()} <= core_version;
% elif e.extensions:
% for ext in e.extensions:
% if ext.type == 'instance':
<% assert False %>
% else:
if (!device || device->${ext.name[3:]}) return true;
% endif
% endfor
return false;
% else:
return true;
% endif
% endfor
default:
return false;
}
}
int
v3dv_get_instance_entrypoint_index(const char *name)
{
return instance_string_map_lookup(name);
}
int
v3dv_get_physical_device_entrypoint_index(const char *name)
{
return physical_device_string_map_lookup(name);
}
int
v3dv_get_device_entrypoint_index(const char *name)
{
return device_string_map_lookup(name);
}
const char *
v3dv_get_instance_entry_name(int index)
{
return instance_entry_name(index);
}
const char *
v3dv_get_physical_device_entry_name(int index)
{
return physical_device_entry_name(index);
}
const char *
v3dv_get_device_entry_name(int index)
{
return device_entry_name(index);
}
void *
v3dv_lookup_entrypoint(const struct v3d_device_info *devinfo, const char *name)
{
int idx = v3dv_get_instance_entrypoint_index(name);
if (idx >= 0)
return v3dv_instance_dispatch_table.entrypoints[idx];
idx = v3dv_get_physical_device_entrypoint_index(name);
if (idx >= 0)
return v3dv_physical_device_dispatch_table.entrypoints[idx];
idx = v3dv_get_device_entrypoint_index(name);
if (idx >= 0)
return v3dv_device_dispatch_table.entrypoints[idx];
return NULL;
}""", output_encoding='utf-8')
U32_MASK = 2**32 - 1
PRIME_FACTOR = 5024183
PRIME_STEP = 19
class StringIntMapEntry(object):
def __init__(self, string, num):
self.string = string
self.num = num
# Calculate the same hash value that we will calculate in C.
h = 0
for c in string:
h = ((h * PRIME_FACTOR) + ord(c)) & U32_MASK
self.hash = h
self.offset = None
def round_to_pow2(x):
return 2**int(math.ceil(math.log(x, 2)))
class StringIntMap(object):
def __init__(self):
self.baked = False
self.strings = dict()
def add_string(self, string, num):
assert not self.baked
assert string not in self.strings
assert 0 <= num < 2**31
self.strings[string] = StringIntMapEntry(string, num)
def bake(self):
self.sorted_strings = \
sorted(self.strings.values(), key=lambda x: x.string)
offset = 0
for entry in self.sorted_strings:
entry.offset = offset
offset += len(entry.string) + 1
# Save off some values that we'll need in C
self.hash_size = round_to_pow2(len(self.strings) * 1.25)
self.hash_mask = self.hash_size - 1
self.prime_factor = PRIME_FACTOR
self.prime_step = PRIME_STEP
self.mapping = [-1] * self.hash_size
self.collisions = [0] * 10
for idx, s in enumerate(self.sorted_strings):
level = 0
h = s.hash
while self.mapping[h & self.hash_mask] >= 0:
h = h + PRIME_STEP
level = level + 1
self.collisions[min(level, 9)] += 1
self.mapping[h & self.hash_mask] = idx
EntrypointParam = namedtuple('EntrypointParam', 'type name decl')
class EntrypointBase(object):
def __init__(self, name):
self.name = name
self.alias = None
self.guard = None
self.enabled = False
self.num = None
# Extensions which require this entrypoint
self.core_version = None
self.extensions = []
class Entrypoint(EntrypointBase):
def __init__(self, name, return_type, params, guard=None):
super(Entrypoint, self).__init__(name)
self.return_type = return_type
self.params = params
self.guard = guard
def is_physical_device_entrypoint(self):
return self.params[0].type in ('VkPhysicalDevice', )
def is_device_entrypoint(self):
return self.params[0].type in ('VkDevice', 'VkCommandBuffer', 'VkQueue')
def prefixed_name(self, prefix):
assert self.name.startswith('vk')
return prefix + '_' + self.name[2:]
def decl_params(self):
return ', '.join(p.decl for p in self.params)
def call_params(self):
return ', '.join(p.name for p in self.params)
class EntrypointAlias(EntrypointBase):
def __init__(self, name, entrypoint):
super(EntrypointAlias, self).__init__(name)
self.alias = entrypoint
def is_physical_device_entrypoint(self):
return self.alias.is_physical_device_entrypoint()
def is_device_entrypoint(self):
return self.alias.is_device_entrypoint()
def prefixed_name(self, prefix):
return self.alias.prefixed_name(prefix)
def get_entrypoints(doc, entrypoints_to_defines):
"""Extract the entry points from the registry."""
entrypoints = OrderedDict()
for command in doc.findall('./commands/command'):
if 'alias' in command.attrib:
alias = command.attrib['name']
target = command.attrib['alias']
entrypoints[alias] = EntrypointAlias(alias, entrypoints[target])
else:
name = command.find('./proto/name').text
ret_type = command.find('./proto/type').text
params = [EntrypointParam(
type=p.find('./type').text,
name=p.find('./name').text,
decl=''.join(p.itertext())
) for p in command.findall('./param')]
guard = entrypoints_to_defines.get(name)
# They really need to be unique
assert name not in entrypoints
entrypoints[name] = Entrypoint(name, ret_type, params, guard)
for feature in doc.findall('./feature'):
assert feature.attrib['api'] == 'vulkan'
version = VkVersion(feature.attrib['number'])
if version > MAX_API_VERSION:
continue
for command in feature.findall('./require/command'):
e = entrypoints[command.attrib['name']]
e.enabled = True
assert e.core_version is None
e.core_version = version
supported_exts = dict((ext.name, ext) for ext in EXTENSIONS)
for extension in doc.findall('.extensions/extension'):
ext_name = extension.attrib['name']
if ext_name not in supported_exts:
continue
ext = supported_exts[ext_name]
ext.type = extension.attrib['type']
for command in extension.findall('./require/command'):
e = entrypoints[command.attrib['name']]
e.enabled = True
assert e.core_version is None
e.extensions.append(ext)
return [e for e in entrypoints.values() if e.enabled]
def get_entrypoints_defines(doc):
"""Maps entry points to extension defines."""
entrypoints_to_defines = {}
platform_define = {}
for platform in doc.findall('./platforms/platform'):
name = platform.attrib['name']
define = platform.attrib['protect']
platform_define[name] = define
for extension in doc.findall('./extensions/extension[@platform]'):
platform = extension.attrib['platform']
define = platform_define[platform]
for entrypoint in extension.findall('./require/command'):
fullname = entrypoint.attrib['name']
entrypoints_to_defines[fullname] = define
return entrypoints_to_defines
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--outdir', help='Where to write the files.',
required=True)
parser.add_argument('--xml',
help='Vulkan API XML file.',
required=True,
action='append',
dest='xml_files')
args = parser.parse_args()
entrypoints = []
for filename in args.xml_files:
doc = et.parse(filename)
entrypoints += get_entrypoints(doc, get_entrypoints_defines(doc))
device_entrypoints = []
physical_device_entrypoints = []
instance_entrypoints = []
for e in entrypoints:
if e.is_device_entrypoint():
device_entrypoints.append(e)
elif e.is_physical_device_entrypoint():
physical_device_entrypoints.append(e)
else:
instance_entrypoints.append(e)
device_strmap = StringIntMap()
for num, e in enumerate(device_entrypoints):
device_strmap.add_string(e.name, num)
e.num = num
device_strmap.bake()
physical_device_strmap = StringIntMap()
for num, e in enumerate(physical_device_entrypoints):
physical_device_strmap.add_string(e.name, num)
e.num = num
physical_device_strmap.bake()
instance_strmap = StringIntMap()
for num, e in enumerate(instance_entrypoints):
instance_strmap.add_string(e.name, num)
e.num = num
instance_strmap.bake()
# For outputting entrypoints.h we generate a v3dv_EntryPoint() prototype
# per entry point.
try:
with open(os.path.join(args.outdir, 'v3dv_entrypoints.h'), 'wb') as f:
f.write(TEMPLATE_H.render(instance_entrypoints=instance_entrypoints,
physical_device_entrypoints=physical_device_entrypoints,
device_entrypoints=device_entrypoints,
LAYERS=LAYERS,
filename=os.path.basename(__file__)))
with open(os.path.join(args.outdir, 'v3dv_entrypoints.c'), 'wb') as f:
f.write(TEMPLATE_C.render(instance_entrypoints=instance_entrypoints,
physical_device_entrypoints=physical_device_entrypoints,
device_entrypoints=device_entrypoints,
LAYERS=LAYERS,
instance_strmap=instance_strmap,
physical_device_strmap=physical_device_strmap,
device_strmap=device_strmap,
filename=os.path.basename(__file__)))
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()

View file

@ -24,163 +24,15 @@ COPYRIGHT = """\
*/
"""
import argparse
import xml.etree.cElementTree as et
from mako.template import Template
import os.path
import sys
from v3dv_extensions import *
platform_defines = []
VULKAN_UTIL = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../vulkan/util'))
sys.path.append(VULKAN_UTIL)
def _init_exts_from_xml(xml):
""" Walk the Vulkan XML and fill out extra extension information. """
xml = et.parse(xml)
ext_name_map = {}
for ext in EXTENSIONS:
ext_name_map[ext.name] = ext
# KHR_display is missing from the list.
platform_defines.append('VK_USE_PLATFORM_DISPLAY_KHR')
for platform in xml.findall('./platforms/platform'):
platform_defines.append(platform.attrib['protect'])
for ext_elem in xml.findall('.extensions/extension'):
ext_name = ext_elem.attrib['name']
if ext_name not in ext_name_map:
continue
ext = ext_name_map[ext_name]
ext.type = ext_elem.attrib['type']
_TEMPLATE_H = Template(COPYRIGHT + """
#ifndef V3DV_EXTENSIONS_H
#define V3DV_EXTENSIONS_H
#include "stdbool.h"
#define V3DV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
extern const VkExtensionProperties v3dv_instance_extensions[];
struct v3dv_instance_extension_table {
union {
bool extensions[V3DV_INSTANCE_EXTENSION_COUNT];
struct {
%for ext in instance_extensions:
bool ${ext.name[3:]};
%endfor
};
};
};
extern const struct v3dv_instance_extension_table v3dv_instance_extensions_supported;
#define V3DV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
extern const VkExtensionProperties v3dv_device_extensions[];
struct v3dv_device_extension_table {
union {
bool extensions[V3DV_DEVICE_EXTENSION_COUNT];
struct {
%for ext in device_extensions:
bool ${ext.name[3:]};
%endfor
};
};
};
struct v3dv_physical_device;
void
v3dv_physical_device_get_supported_extensions(const struct v3dv_physical_device *device,
struct v3dv_device_extension_table *extensions);
#endif /* V3DV_EXTENSIONS_H */
""")
_TEMPLATE_C = Template(COPYRIGHT + """
#include "v3dv_private.h"
#include "vk_util.h"
/* Convert the VK_USE_PLATFORM_* defines to booleans */
%for platform_define in platform_defines:
#ifdef ${platform_define}
# undef ${platform_define}
# define ${platform_define} true
#else
# define ${platform_define} false
#endif
%endfor
/* And ANDROID too */
#ifdef ANDROID
# undef ANDROID
# define ANDROID true
#else
# define ANDROID false
#endif
#define V3DV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
VK_USE_PLATFORM_XCB_KHR || \\
VK_USE_PLATFORM_XLIB_KHR || \\
VK_USE_PLATFORM_DISPLAY_KHR)
static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
const VkExtensionProperties v3dv_instance_extensions[V3DV_INSTANCE_EXTENSION_COUNT] = {
%for ext in instance_extensions:
{"${ext.name}", ${ext.ext_version}},
%endfor
};
const struct v3dv_instance_extension_table v3dv_instance_extensions_supported = {
%for ext in instance_extensions:
.${ext.name[3:]} = ${ext.enable},
%endfor
};
uint32_t
v3dv_physical_device_api_version(struct v3dv_physical_device *device)
{
uint32_t version = 0;
uint32_t override = vk_get_version_override();
if (override)
return MIN2(override, MAX_API_VERSION);
%for version in API_VERSIONS:
if (!(${version.enable}))
return version;
version = ${version.version.c_vk_version()};
%endfor
return version;
}
const VkExtensionProperties v3dv_device_extensions[V3DV_DEVICE_EXTENSION_COUNT] = {
%for ext in device_extensions:
{"${ext.name}", ${ext.ext_version}},
%endfor
};
void
v3dv_physical_device_get_supported_extensions(const struct v3dv_physical_device *device,
struct v3dv_device_extension_table *extensions)
{
*extensions = (struct v3dv_device_extension_table) {
%for ext in device_extensions:
.${ext.name[3:]} = ${ext.enable},
%endfor
};
}
""")
from vk_extensions_gen import *
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@ -193,24 +45,8 @@ if __name__ == '__main__':
dest='xml_files')
args = parser.parse_args()
for filename in args.xml_files:
_init_exts_from_xml(filename)
includes = [
]
for ext in EXTENSIONS:
assert ext.type == 'instance' or ext.type == 'device'
template_env = {
'API_VERSIONS': API_VERSIONS,
'MAX_API_VERSION': MAX_API_VERSION,
'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'],
'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],
'platform_defines': platform_defines,
}
if args.out_h:
with open(args.out_h, 'w') as f:
f.write(_TEMPLATE_H.render(**template_env))
if args.out_c:
with open(args.out_c, 'w') as f:
f.write(_TEMPLATE_C.render(**template_env))
gen_extensions('v3dv', args.xml_files, API_VERSIONS, MAX_API_VERSION,
EXTENSIONS, args.out_c, args.out_h, type_prefix='vk')

View file

@ -129,9 +129,6 @@ struct v3d_simulator_file;
struct v3dv_physical_device {
struct vk_physical_device vk;
struct v3dv_device_extension_table supported_extensions;
struct v3dv_physical_device_dispatch_table dispatch;
char *name;
int32_t render_fd;
int32_t display_fd;
@ -178,10 +175,6 @@ void v3dv_meta_texel_buffer_copy_finish(struct v3dv_device *device);
struct v3dv_instance {
struct vk_instance vk;
struct v3dv_instance_extension_table enabled_extensions;
struct v3dv_instance_dispatch_table dispatch;
struct v3dv_device_dispatch_table device_dispatch;
int physicalDeviceCount;
struct v3dv_physical_device physicalDevice;
@ -290,9 +283,6 @@ struct v3dv_device {
struct v3dv_instance *instance;
struct v3dv_physical_device *pdevice;
struct v3dv_device_extension_table enabled_extensions;
struct v3dv_device_dispatch_table dispatch;
struct v3d_device_info devinfo;
struct v3dv_queue queue;
@ -1821,28 +1811,6 @@ uint32_t v3dv_physical_device_api_version(struct v3dv_physical_device *dev);
uint32_t v3dv_physical_device_vendor_id(struct v3dv_physical_device *dev);
uint32_t v3dv_physical_device_device_id(struct v3dv_physical_device *dev);
int v3dv_get_instance_entrypoint_index(const char *name);
int v3dv_get_device_entrypoint_index(const char *name);
int v3dv_get_physical_device_entrypoint_index(const char *name);
const char *v3dv_get_instance_entry_name(int index);
const char *v3dv_get_physical_device_entry_name(int index);
const char *v3dv_get_device_entry_name(int index);
bool
v3dv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance);
bool
v3dv_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance);
bool
v3dv_device_entrypoint_is_enabled(int index, uint32_t core_version,
const struct v3dv_instance_extension_table *instance,
const struct v3dv_device_extension_table *device);
void *v3dv_lookup_entrypoint(const struct v3d_device_info *devinfo,
const char *name);
VkResult __vk_errorf(struct v3dv_instance *instance, VkResult error,
const char *file, int line,
const char *format, ...);

View file

@ -32,8 +32,18 @@
static PFN_vkVoidFunction
v3dv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
{
V3DV_FROM_HANDLE(v3dv_physical_device, physical_device, physicalDevice);
return v3dv_lookup_entrypoint(&physical_device->devinfo, pName);
V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, physicalDevice);
PFN_vkVoidFunction func;
func = vk_instance_dispatch_table_get(&pdevice->vk.instance->dispatch_table, pName);
if (func != NULL)
return func;
func = vk_physical_device_dispatch_table_get(&pdevice->vk.dispatch_table, pName);
if (func != NULL)
return func;
return vk_device_dispatch_table_get(&vk_device_trampolines, pName);
}
VkResult