Commit 21f9a886 authored by Alejandro Piñeiro's avatar Alejandro Piñeiro Committed by Marge Bot
Browse files

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's avatarIago Toral Quiroga <itoral@igalia.com>
Part-of: <mesa/mesa!8676>
parent 3e2bbf5d
......@@ -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(
......
......@@ -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,
......
This diff is collapsed.
......@@ -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 = []
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;
VULKAN_UTIL = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../vulkan/util'))
sys.path.append(VULKAN_UTIL)
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)
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))
includes = [
]
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')
......@@ -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, ...);
......
......@@ -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);
}