2019-11-25 15:29:12 +00:00
|
|
|
/*
|
2022-02-17 11:38:42 +00:00
|
|
|
* Copyright © 2019 Raspberry Pi Ltd
|
2019-11-25 15:29:12 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2019-11-28 08:48:29 +00:00
|
|
|
#include <fcntl.h>
|
2019-11-25 15:29:12 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
#include <unistd.h>
|
2019-11-27 12:58:02 +00:00
|
|
|
#include <xf86drm.h>
|
2019-11-25 15:29:12 +00:00
|
|
|
|
2021-02-28 18:52:36 +00:00
|
|
|
#ifdef MAJOR_IN_MKDEV
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#endif
|
|
|
|
#ifdef MAJOR_IN_SYSMACROS
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#endif
|
|
|
|
|
2019-11-25 15:29:12 +00:00
|
|
|
#include "v3dv_private.h"
|
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
#include "common/v3d_debug.h"
|
2019-12-13 09:31:05 +00:00
|
|
|
|
2019-12-02 12:59:04 +00:00
|
|
|
#include "compiler/v3d_compiler.h"
|
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
#include "drm-uapi/v3d_drm.h"
|
2020-01-23 10:24:05 +00:00
|
|
|
#include "format/u_format.h"
|
2022-03-29 23:52:32 +01:00
|
|
|
#include "vk_drm_syncobj.h"
|
2019-12-04 09:39:01 +00:00
|
|
|
#include "vk_util.h"
|
2022-01-24 10:36:37 +00:00
|
|
|
#include "git_sha1.h"
|
2019-11-27 10:49:49 +00:00
|
|
|
|
2020-07-04 12:09:58 +01:00
|
|
|
#include "util/build_id.h"
|
2020-07-07 14:56:44 +01:00
|
|
|
#include "util/debug.h"
|
2020-07-04 12:09:58 +01:00
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/dri3.h>
|
2020-11-16 08:50:22 +00:00
|
|
|
#include <X11/Xlib-xcb.h>
|
2020-01-20 09:45:06 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-20 08:57:07 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
#include <wayland-client.h>
|
|
|
|
#include "wayland-drm-client-protocol.h"
|
|
|
|
#endif
|
|
|
|
|
2022-05-11 11:35:08 +01:00
|
|
|
#define V3DV_API_VERSION VK_MAKE_VERSION(1, 2, VK_HEADER_VERSION)
|
2021-04-27 13:01:48 +01:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2021-04-27 13:01:48 +01:00
|
|
|
v3dv_EnumerateInstanceVersion(uint32_t *pApiVersion)
|
|
|
|
{
|
|
|
|
*pApiVersion = V3DV_API_VERSION;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-12-10 09:08:21 +00:00
|
|
|
#if defined(VK_USE_PLATFORM_WIN32_KHR) || \
|
|
|
|
defined(VK_USE_PLATFORM_WAYLAND_KHR) || \
|
|
|
|
defined(VK_USE_PLATFORM_XCB_KHR) || \
|
|
|
|
defined(VK_USE_PLATFORM_XLIB_KHR) || \
|
|
|
|
defined(VK_USE_PLATFORM_DISPLAY_KHR)
|
|
|
|
#define V3DV_USE_WSI_PLATFORM
|
|
|
|
#endif
|
2021-04-27 13:01:48 +01:00
|
|
|
|
|
|
|
static const struct vk_instance_extension_table instance_extensions = {
|
2021-05-27 08:16:18 +01:00
|
|
|
.KHR_device_group_creation = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
|
|
|
|
.KHR_display = true,
|
2021-12-03 16:38:27 +00:00
|
|
|
.KHR_get_display_properties2 = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
#endif
|
2021-06-01 08:41:48 +01:00
|
|
|
.KHR_external_fence_capabilities = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_external_memory_capabilities = true,
|
2021-06-01 08:41:48 +01:00
|
|
|
.KHR_external_semaphore_capabilities = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_get_physical_device_properties2 = true,
|
2021-12-10 09:08:21 +00:00
|
|
|
#ifdef V3DV_USE_WSI_PLATFORM
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_get_surface_capabilities2 = true,
|
|
|
|
.KHR_surface = true,
|
2021-10-10 15:42:30 +01:00
|
|
|
.KHR_surface_protected_capabilities = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
#endif
|
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
.KHR_wayland_surface = true,
|
|
|
|
#endif
|
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
|
.KHR_xcb_surface = true,
|
|
|
|
#endif
|
|
|
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
|
|
.KHR_xlib_surface = true,
|
|
|
|
#endif
|
|
|
|
.EXT_debug_report = true,
|
2022-03-24 16:32:01 +00:00
|
|
|
.EXT_debug_utils = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_device_extensions(const struct v3dv_physical_device *device,
|
|
|
|
struct vk_device_extension_table *ext)
|
|
|
|
{
|
|
|
|
*ext = (struct vk_device_extension_table) {
|
2022-01-21 12:31:19 +00:00
|
|
|
.KHR_8bit_storage = true,
|
2022-01-18 10:17:29 +00:00
|
|
|
.KHR_16bit_storage = true,
|
2021-05-25 12:21:55 +01:00
|
|
|
.KHR_bind_memory2 = true,
|
2022-06-27 13:12:25 +01:00
|
|
|
.KHR_buffer_device_address = true,
|
2021-06-17 09:26:36 +01:00
|
|
|
.KHR_copy_commands2 = true,
|
2021-10-28 09:29:33 +01:00
|
|
|
.KHR_create_renderpass2 = true,
|
2021-05-26 08:14:02 +01:00
|
|
|
.KHR_dedicated_allocation = true,
|
2021-05-27 08:16:18 +01:00
|
|
|
.KHR_device_group = true,
|
2022-01-24 10:36:37 +00:00
|
|
|
.KHR_driver_properties = true,
|
2021-06-07 08:08:22 +01:00
|
|
|
.KHR_descriptor_update_template = true,
|
2022-01-27 10:58:30 +00:00
|
|
|
.KHR_depth_stencil_resolve = true,
|
2021-06-01 08:41:48 +01:00
|
|
|
.KHR_external_fence = true,
|
|
|
|
.KHR_external_fence_fd = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_external_memory = true,
|
|
|
|
.KHR_external_memory_fd = true,
|
2021-06-01 08:41:48 +01:00
|
|
|
.KHR_external_semaphore = true,
|
|
|
|
.KHR_external_semaphore_fd = true,
|
2022-05-10 21:01:51 +01:00
|
|
|
.KHR_format_feature_flags2 = true,
|
2021-05-26 08:34:04 +01:00
|
|
|
.KHR_get_memory_requirements2 = true,
|
2021-06-09 20:04:40 +01:00
|
|
|
.KHR_image_format_list = true,
|
2022-01-24 12:38:08 +00:00
|
|
|
.KHR_imageless_framebuffer = true,
|
2021-11-23 22:29:48 +00:00
|
|
|
.KHR_performance_query = device->caps.perfmon,
|
2021-06-02 13:26:16 +01:00
|
|
|
.KHR_relaxed_block_layout = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_maintenance1 = true,
|
2021-05-19 13:27:28 +01:00
|
|
|
.KHR_maintenance2 = true,
|
2021-05-25 09:49:06 +01:00
|
|
|
.KHR_maintenance3 = true,
|
2021-07-20 10:32:17 +01:00
|
|
|
.KHR_multiview = true,
|
2022-05-06 11:01:09 +01:00
|
|
|
.KHR_pipeline_executable_properties = true,
|
2022-05-05 08:54:38 +01:00
|
|
|
.KHR_separate_depth_stencil_layouts = true,
|
2022-05-10 11:53:08 +01:00
|
|
|
.KHR_shader_float_controls = true,
|
2021-06-17 08:18:23 +01:00
|
|
|
.KHR_shader_non_semantic_info = true,
|
2021-06-09 20:08:40 +01:00
|
|
|
.KHR_sampler_mirror_clamp_to_edge = true,
|
2022-05-11 08:16:09 +01:00
|
|
|
.KHR_spirv_1_4 = true,
|
2021-06-04 13:00:47 +01:00
|
|
|
.KHR_storage_buffer_storage_class = true,
|
2022-04-05 00:37:26 +01:00
|
|
|
.KHR_timeline_semaphore = true,
|
2021-06-09 20:20:34 +01:00
|
|
|
.KHR_uniform_buffer_standard_layout = true,
|
2021-12-14 09:53:33 +00:00
|
|
|
#ifdef V3DV_USE_WSI_PLATFORM
|
2021-04-27 13:01:48 +01:00
|
|
|
.KHR_swapchain = true,
|
2021-10-10 15:24:00 +01:00
|
|
|
.KHR_swapchain_mutable_format = true,
|
2021-06-09 20:16:30 +01:00
|
|
|
.KHR_incremental_present = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
#endif
|
2021-06-08 10:05:36 +01:00
|
|
|
.KHR_variable_pointers = true,
|
2022-05-18 12:59:24 +01:00
|
|
|
.KHR_vulkan_memory_model = true,
|
2022-01-13 08:00:10 +00:00
|
|
|
.EXT_4444_formats = true,
|
2021-07-10 21:02:47 +01:00
|
|
|
.EXT_color_write_enable = true,
|
2021-07-28 09:53:00 +01:00
|
|
|
.EXT_custom_border_color = true,
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
.EXT_inline_uniform_block = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.EXT_external_memory_dma_buf = true,
|
2021-10-12 17:58:33 +01:00
|
|
|
.EXT_host_query_reset = true,
|
2022-03-17 10:49:03 +00:00
|
|
|
.EXT_image_drm_format_modifier = true,
|
2021-06-17 11:12:46 +01:00
|
|
|
.EXT_index_type_uint8 = true,
|
2022-03-17 11:20:41 +00:00
|
|
|
.EXT_line_rasterization = true,
|
2021-02-28 18:52:36 +00:00
|
|
|
.EXT_physical_device_drm = true,
|
2021-08-14 15:09:23 +01:00
|
|
|
.EXT_pipeline_creation_cache_control = true,
|
2021-08-02 23:13:25 +01:00
|
|
|
.EXT_pipeline_creation_feedback = true,
|
2021-04-27 13:01:48 +01:00
|
|
|
.EXT_private_data = true,
|
2021-08-15 15:50:39 +01:00
|
|
|
.EXT_provoking_vertex = true,
|
2022-05-05 07:58:54 +01:00
|
|
|
.EXT_separate_stencil_usage = true,
|
2021-09-02 11:30:52 +01:00
|
|
|
.EXT_vertex_attribute_divisor = true,
|
2021-12-08 10:15:38 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
.ANDROID_native_buffer = true,
|
|
|
|
#endif
|
2021-04-27 13:01:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_EnumerateInstanceExtensionProperties(const char *pLayerName,
|
|
|
|
uint32_t *pPropertyCount,
|
|
|
|
VkExtensionProperties *pProperties)
|
|
|
|
{
|
2019-11-29 10:09:51 +00:00
|
|
|
/* We don't support any layers */
|
|
|
|
if (pLayerName)
|
|
|
|
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
|
|
|
|
|
2021-01-30 17:03:27 +00:00
|
|
|
return vk_enumerate_instance_extension_properties(
|
2021-04-27 13:01:48 +01:00
|
|
|
&instance_extensions, pPropertyCount, pProperties);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkInstance *pInstance)
|
|
|
|
{
|
2019-11-27 10:49:49 +00:00
|
|
|
struct v3dv_instance *instance;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
|
|
|
|
|
2021-01-27 12:46:58 +00:00
|
|
|
if (pAllocator == NULL)
|
2021-06-01 17:35:27 +01:00
|
|
|
pAllocator = vk_default_allocator();
|
2021-01-27 12:46:58 +00:00
|
|
|
|
2021-06-01 17:35:27 +01:00
|
|
|
instance = vk_alloc(pAllocator, sizeof(*instance), 8,
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
|
2019-11-27 10:49:49 +00:00
|
|
|
if (!instance)
|
|
|
|
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
2021-01-27 23:21:38 +00:00
|
|
|
struct vk_instance_dispatch_table dispatch_table;
|
|
|
|
vk_instance_dispatch_table_from_entrypoints(
|
|
|
|
&dispatch_table, &v3dv_instance_entrypoints, true);
|
2021-10-06 17:45:06 +01:00
|
|
|
vk_instance_dispatch_table_from_entrypoints(
|
|
|
|
&dispatch_table, &wsi_instance_entrypoints, false);
|
2021-01-27 23:21:38 +00:00
|
|
|
|
|
|
|
result = vk_instance_init(&instance->vk,
|
2021-04-27 13:01:48 +01:00
|
|
|
&instance_extensions,
|
2021-01-27 23:21:38 +00:00
|
|
|
&dispatch_table,
|
2021-01-27 12:46:58 +00:00
|
|
|
pCreateInfo, pAllocator);
|
2019-11-27 10:49:49 +00:00
|
|
|
|
2021-01-27 12:46:58 +00:00
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
vk_free(pAllocator, instance);
|
2021-10-06 10:28:15 +01:00
|
|
|
return vk_error(NULL, result);
|
2021-01-27 12:46:58 +00:00
|
|
|
}
|
2019-11-27 10:49:49 +00:00
|
|
|
|
|
|
|
instance->physicalDeviceCount = -1;
|
|
|
|
|
2020-09-20 21:54:33 +01:00
|
|
|
/* We start with the default values for the pipeline_cache envvars */
|
|
|
|
instance->pipeline_cache_enabled = true;
|
|
|
|
instance->default_pipeline_cache_enabled = true;
|
|
|
|
const char *pipeline_cache_str = getenv("V3DV_ENABLE_PIPELINE_CACHE");
|
|
|
|
if (pipeline_cache_str != NULL) {
|
|
|
|
if (strncmp(pipeline_cache_str, "full", 4) == 0) {
|
|
|
|
/* nothing to do, just to filter correct values */
|
|
|
|
} else if (strncmp(pipeline_cache_str, "no-default-cache", 16) == 0) {
|
|
|
|
instance->default_pipeline_cache_enabled = false;
|
|
|
|
} else if (strncmp(pipeline_cache_str, "off", 3) == 0) {
|
|
|
|
instance->pipeline_cache_enabled = false;
|
|
|
|
instance->default_pipeline_cache_enabled = false;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Wrong value for envvar V3DV_ENABLE_PIPELINE_CACHE. "
|
|
|
|
"Allowed values are: full, no-default-cache, off\n");
|
|
|
|
}
|
|
|
|
}
|
2020-07-07 14:56:44 +01:00
|
|
|
|
2020-08-05 09:35:16 +01:00
|
|
|
if (instance->pipeline_cache_enabled == false) {
|
|
|
|
fprintf(stderr, "WARNING: v3dv pipeline cache is disabled. Performance "
|
|
|
|
"can be affected negatively\n");
|
2020-09-20 21:54:33 +01:00
|
|
|
} else {
|
|
|
|
if (instance->default_pipeline_cache_enabled == false) {
|
|
|
|
fprintf(stderr, "WARNING: default v3dv pipeline cache is disabled. "
|
|
|
|
"Performance can be affected negatively\n");
|
|
|
|
}
|
2020-08-05 09:35:16 +01:00
|
|
|
}
|
|
|
|
|
2019-11-27 10:49:49 +00:00
|
|
|
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
|
|
|
|
|
|
|
|
*pInstance = v3dv_instance_to_handle(instance);
|
2019-11-25 15:29:12 +00:00
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:56:50 +00:00
|
|
|
static void
|
|
|
|
v3dv_physical_device_free_disk_cache(struct v3dv_physical_device *device)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_SHADER_CACHE
|
|
|
|
if (device->disk_cache)
|
|
|
|
disk_cache_destroy(device->disk_cache);
|
|
|
|
#else
|
|
|
|
assert(device->disk_cache == NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-11-27 11:43:36 +00:00
|
|
|
static void
|
|
|
|
physical_device_finish(struct v3dv_physical_device *device)
|
|
|
|
{
|
2020-02-24 16:16:09 +00:00
|
|
|
v3dv_wsi_finish(device);
|
2021-03-18 21:56:50 +00:00
|
|
|
v3dv_physical_device_free_disk_cache(device);
|
2020-04-23 09:46:07 +01:00
|
|
|
v3d_compiler_free(device->compiler);
|
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
util_sparse_array_finish(&device->bo_map);
|
|
|
|
|
2020-01-23 10:59:28 +00:00
|
|
|
close(device->render_fd);
|
2020-01-20 09:45:06 +00:00
|
|
|
if (device->display_fd >= 0)
|
|
|
|
close(device->display_fd);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
if (device->master_fd >= 0)
|
|
|
|
close(device->master_fd);
|
2019-11-29 12:55:38 +00:00
|
|
|
|
2019-11-29 08:01:56 +00:00
|
|
|
free(device->name);
|
|
|
|
|
2019-11-29 12:55:38 +00:00
|
|
|
#if using_v3d_simulator
|
|
|
|
v3d_simulator_destroy(device->sim_file);
|
|
|
|
#endif
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
|
2021-01-27 12:46:58 +00:00
|
|
|
vk_physical_device_finish(&device->vk);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
mtx_destroy(&device->mutex);
|
2019-11-27 11:43:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_DestroyInstance(VkInstance _instance,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
2019-11-27 11:43:36 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
|
|
|
|
|
|
|
|
if (!instance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (instance->physicalDeviceCount > 0) {
|
|
|
|
/* We support at most one physical device. */
|
|
|
|
assert(instance->physicalDeviceCount == 1);
|
|
|
|
physical_device_finish(&instance->physicalDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
VG(VALGRIND_DESTROY_MEMPOOL(instance));
|
|
|
|
|
2021-01-27 12:46:58 +00:00
|
|
|
vk_instance_finish(&instance->vk);
|
|
|
|
vk_free(&instance->vk.alloc, instance);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 09:25:21 +00:00
|
|
|
static uint64_t
|
|
|
|
compute_heap_size()
|
|
|
|
{
|
2020-08-08 23:46:20 +01:00
|
|
|
#if !using_v3d_simulator
|
2019-12-04 09:25:21 +00:00
|
|
|
/* Query the total ram from the system */
|
|
|
|
struct sysinfo info;
|
|
|
|
sysinfo(&info);
|
|
|
|
|
|
|
|
uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
|
2020-08-08 23:46:20 +01:00
|
|
|
#else
|
|
|
|
uint64_t total_ram = (uint64_t) v3d_simulator_get_mem_size();
|
|
|
|
#endif
|
2019-12-04 09:25:21 +00:00
|
|
|
|
|
|
|
/* We don't want to burn too much ram with the GPU. If the user has 4GiB
|
|
|
|
* or less, we use at most half. If they have more than 4GiB, we use 3/4.
|
|
|
|
*/
|
|
|
|
uint64_t available_ram;
|
|
|
|
if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
|
|
|
|
available_ram = total_ram / 2;
|
|
|
|
else
|
|
|
|
available_ram = total_ram * 3 / 4;
|
|
|
|
|
|
|
|
return available_ram;
|
|
|
|
}
|
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
#if !using_v3d_simulator
|
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
|
static int
|
2020-11-16 08:50:22 +00:00
|
|
|
create_display_fd_xcb(VkIcdSurfaceBase *surface)
|
2020-01-20 09:45:06 +00:00
|
|
|
{
|
2020-09-17 15:12:31 +01:00
|
|
|
int fd = -1;
|
|
|
|
|
2020-11-16 08:50:22 +00:00
|
|
|
xcb_connection_t *conn;
|
2021-03-16 23:07:12 +00:00
|
|
|
xcb_dri3_open_reply_t *reply = NULL;
|
2020-11-16 08:50:22 +00:00
|
|
|
if (surface) {
|
|
|
|
if (surface->platform == VK_ICD_WSI_PLATFORM_XLIB)
|
|
|
|
conn = XGetXCBConnection(((VkIcdSurfaceXlib *)surface)->dpy);
|
|
|
|
else
|
|
|
|
conn = ((VkIcdSurfaceXcb *)surface)->connection;
|
|
|
|
} else {
|
|
|
|
conn = xcb_connect(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2020-09-17 15:12:31 +01:00
|
|
|
if (xcb_connection_has_error(conn))
|
|
|
|
goto finish;
|
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
const xcb_setup_t *setup = xcb_get_setup(conn);
|
|
|
|
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
|
|
|
|
xcb_screen_t *screen = iter.data;
|
|
|
|
|
|
|
|
xcb_dri3_open_cookie_t cookie;
|
|
|
|
cookie = xcb_dri3_open(conn, screen->root, None);
|
|
|
|
reply = xcb_dri3_open_reply(conn, cookie, NULL);
|
|
|
|
if (!reply)
|
2020-09-17 15:12:31 +01:00
|
|
|
goto finish;
|
2020-01-20 09:45:06 +00:00
|
|
|
|
2020-09-17 15:12:31 +01:00
|
|
|
if (reply->nfd != 1)
|
|
|
|
goto finish;
|
2020-01-20 09:45:06 +00:00
|
|
|
|
2020-09-17 15:12:31 +01:00
|
|
|
fd = xcb_dri3_open_reply_fds(conn, reply)[0];
|
2020-01-20 09:45:06 +00:00
|
|
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
|
|
|
|
2020-09-17 15:12:31 +01:00
|
|
|
finish:
|
2020-11-16 08:50:22 +00:00
|
|
|
if (!surface)
|
|
|
|
xcb_disconnect(conn);
|
2020-09-17 15:12:31 +01:00
|
|
|
if (reply)
|
|
|
|
free(reply);
|
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
#endif
|
2020-11-16 08:50:22 +00:00
|
|
|
|
2020-11-20 08:57:07 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
struct v3dv_wayland_info {
|
|
|
|
struct wl_drm *wl_drm;
|
|
|
|
int fd;
|
|
|
|
bool is_set;
|
|
|
|
bool authenticated;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
|
|
|
|
{
|
|
|
|
struct v3dv_wayland_info *info = data;
|
|
|
|
info->fd = open(device, O_RDWR | O_CLOEXEC);
|
|
|
|
info->is_set = info->fd != -1;
|
2020-12-02 06:57:32 +00:00
|
|
|
if (!info->is_set) {
|
|
|
|
fprintf(stderr, "v3dv_drm_handle_device: could not open %s (%s)\n",
|
|
|
|
device, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2020-11-20 08:57:07 +00:00
|
|
|
|
|
|
|
drm_magic_t magic;
|
2020-11-30 06:44:28 +00:00
|
|
|
if (drmGetMagic(info->fd, &magic)) {
|
2020-12-02 06:57:32 +00:00
|
|
|
fprintf(stderr, "v3dv_drm_handle_device: drmGetMagic failed\n");
|
|
|
|
close(info->fd);
|
|
|
|
info->fd = -1;
|
|
|
|
info->is_set = false;
|
2020-11-30 06:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-20 08:57:07 +00:00
|
|
|
wl_drm_authenticate(info->wl_drm, magic);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_drm_handle_format(void *data, struct wl_drm *drm, uint32_t format)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_drm_handle_authenticated(void *data, struct wl_drm *drm)
|
|
|
|
{
|
|
|
|
struct v3dv_wayland_info *info = data;
|
|
|
|
info->authenticated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_drm_handle_capabilities(void *data, struct wl_drm *drm, uint32_t value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_drm_listener v3dv_drm_listener = {
|
|
|
|
.device = v3dv_drm_handle_device,
|
|
|
|
.format = v3dv_drm_handle_format,
|
|
|
|
.authenticated = v3dv_drm_handle_authenticated,
|
|
|
|
.capabilities = v3dv_drm_handle_capabilities
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_registry_global(void *data,
|
|
|
|
struct wl_registry *registry,
|
|
|
|
uint32_t name,
|
|
|
|
const char *interface,
|
|
|
|
uint32_t version)
|
|
|
|
{
|
|
|
|
struct v3dv_wayland_info *info = data;
|
|
|
|
if (strcmp(interface, "wl_drm") == 0) {
|
|
|
|
info->wl_drm = wl_registry_bind(registry, name, &wl_drm_interface,
|
|
|
|
MIN2(version, 2));
|
|
|
|
wl_drm_add_listener(info->wl_drm, &v3dv_drm_listener, data);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
v3dv_registry_global_remove_cb(void *data,
|
|
|
|
struct wl_registry *registry,
|
|
|
|
uint32_t name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
create_display_fd_wayland(VkIcdSurfaceBase *surface)
|
|
|
|
{
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_registry *registry = NULL;
|
|
|
|
|
|
|
|
struct v3dv_wayland_info info = {
|
|
|
|
.wl_drm = NULL,
|
|
|
|
.fd = -1,
|
|
|
|
.is_set = false,
|
|
|
|
.authenticated = false
|
|
|
|
};
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
display = ((VkIcdSurfaceWayland *) surface)->display;
|
|
|
|
else
|
|
|
|
display = wl_display_connect(NULL);
|
|
|
|
|
|
|
|
if (!display)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
registry = wl_display_get_registry(display);
|
|
|
|
if (!registry) {
|
|
|
|
if (!surface)
|
|
|
|
wl_display_disconnect(display);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_registry_listener registry_listener = {
|
|
|
|
v3dv_registry_global,
|
|
|
|
v3dv_registry_global_remove_cb
|
|
|
|
};
|
|
|
|
wl_registry_add_listener(registry, ®istry_listener, &info);
|
|
|
|
|
|
|
|
wl_display_roundtrip(display); /* For the registry advertisement */
|
|
|
|
wl_display_roundtrip(display); /* For the DRM device event */
|
|
|
|
wl_display_roundtrip(display); /* For the authentication event */
|
|
|
|
|
|
|
|
wl_drm_destroy(info.wl_drm);
|
|
|
|
wl_registry_destroy(registry);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
wl_display_disconnect(display);
|
|
|
|
|
|
|
|
if (!info.is_set)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!info.authenticated)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return info.fd;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 08:50:22 +00:00
|
|
|
/* Acquire an authenticated display fd without a surface reference. This is the
|
|
|
|
* case where the application is making WSI allocations outside the Vulkan
|
|
|
|
* swapchain context (only Zink, for now). Since we lack information about the
|
|
|
|
* underlying surface we just try our best to figure out the correct display
|
|
|
|
* and platform to use. It should work in most cases.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acquire_display_device_no_surface(struct v3dv_instance *instance,
|
|
|
|
struct v3dv_physical_device *pdevice)
|
|
|
|
{
|
2020-11-20 08:57:07 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
pdevice->display_fd = create_display_fd_wayland(NULL);
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 08:50:22 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
2020-11-20 08:57:07 +00:00
|
|
|
if (pdevice->display_fd == -1)
|
|
|
|
pdevice->display_fd = create_display_fd_xcb(NULL);
|
2020-11-16 08:50:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
|
|
|
|
if (pdevice->display_fd == - 1 && pdevice->master_fd >= 0)
|
|
|
|
pdevice->display_fd = dup(pdevice->master_fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acquire an authenticated display fd from the surface. This is the regular
|
|
|
|
* case where the application is using swapchains to create WSI allocations.
|
|
|
|
* In this case we use the surface information to figure out the correct
|
|
|
|
* display and platform combination.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acquire_display_device_surface(struct v3dv_instance *instance,
|
|
|
|
struct v3dv_physical_device *pdevice,
|
|
|
|
VkIcdSurfaceBase *surface)
|
|
|
|
{
|
|
|
|
/* Mesa will set both of VK_USE_PLATFORM_{XCB,XLIB} when building with
|
|
|
|
* platform X11, so only check for XCB and rely on XCB to get an
|
|
|
|
* authenticated device also for Xlib.
|
|
|
|
*/
|
|
|
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
|
|
if (surface->platform == VK_ICD_WSI_PLATFORM_XCB ||
|
|
|
|
surface->platform == VK_ICD_WSI_PLATFORM_XLIB) {
|
|
|
|
pdevice->display_fd = create_display_fd_xcb(surface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-20 08:57:07 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
if (surface->platform == VK_ICD_WSI_PLATFORM_WAYLAND)
|
|
|
|
pdevice->display_fd = create_display_fd_wayland(surface);
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 08:50:22 +00:00
|
|
|
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
|
|
|
|
if (surface->platform == VK_ICD_WSI_PLATFORM_DISPLAY &&
|
|
|
|
pdevice->master_fd >= 0) {
|
|
|
|
pdevice->display_fd = dup(pdevice->master_fd);
|
|
|
|
}
|
2020-01-20 09:45:06 +00:00
|
|
|
#endif
|
2020-11-16 08:50:22 +00:00
|
|
|
}
|
|
|
|
#endif /* !using_v3d_simulator */
|
2020-01-20 09:45:06 +00:00
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
/* Attempts to get an authenticated display fd from the display server that
|
|
|
|
* we can use to allocate BOs for presentable images.
|
|
|
|
*/
|
|
|
|
VkResult
|
|
|
|
v3dv_physical_device_acquire_display(struct v3dv_instance *instance,
|
2020-11-16 08:50:22 +00:00
|
|
|
struct v3dv_physical_device *pdevice,
|
|
|
|
VkIcdSurfaceBase *surface)
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
{
|
|
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
mtx_lock(&pdevice->mutex);
|
|
|
|
|
|
|
|
if (pdevice->display_fd != -1)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* When running on the simulator we do everything on a single render node so
|
|
|
|
* we don't need to get an authenticated display fd from the display server.
|
|
|
|
*/
|
|
|
|
#if !using_v3d_simulator
|
2020-11-16 08:50:22 +00:00
|
|
|
if (surface)
|
|
|
|
acquire_display_device_surface(instance, pdevice, surface);
|
|
|
|
else
|
|
|
|
acquire_display_device_no_surface(instance, pdevice);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
|
|
|
|
if (pdevice->display_fd == -1)
|
|
|
|
result = VK_ERROR_INITIALIZATION_FAILED;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
done:
|
|
|
|
mtx_unlock(&pdevice->mutex);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-26 07:38:31 +01:00
|
|
|
static bool
|
|
|
|
v3d_has_feature(struct v3dv_physical_device *device, enum drm_v3d_param feature)
|
|
|
|
{
|
|
|
|
struct drm_v3d_get_param p = {
|
|
|
|
.param = feature,
|
|
|
|
};
|
|
|
|
if (v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_GET_PARAM, &p) != 0)
|
|
|
|
return false;
|
|
|
|
return p.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
device_has_expected_features(struct v3dv_physical_device *device)
|
|
|
|
{
|
|
|
|
return v3d_has_feature(device, DRM_V3D_PARAM_SUPPORTS_TFU) &&
|
|
|
|
v3d_has_feature(device, DRM_V3D_PARAM_SUPPORTS_CSD) &&
|
|
|
|
v3d_has_feature(device, DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH);
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:09:58 +01:00
|
|
|
|
|
|
|
static VkResult
|
|
|
|
init_uuids(struct v3dv_physical_device *device)
|
|
|
|
{
|
|
|
|
const struct build_id_note *note =
|
|
|
|
build_id_find_nhdr_for_addr(init_uuids);
|
|
|
|
if (!note) {
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_errorf(device->vk.instance,
|
2020-07-04 12:09:58 +01:00
|
|
|
VK_ERROR_INITIALIZATION_FAILED,
|
|
|
|
"Failed to find build-id");
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned build_id_len = build_id_length(note);
|
|
|
|
if (build_id_len < 20) {
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_errorf(device->vk.instance,
|
2020-07-04 12:09:58 +01:00
|
|
|
VK_ERROR_INITIALIZATION_FAILED,
|
|
|
|
"build-id too short. It needs to be a SHA");
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:56:50 +00:00
|
|
|
memcpy(device->driver_build_sha1, build_id_data(note), 20);
|
|
|
|
|
2020-10-05 09:44:59 +01:00
|
|
|
uint32_t vendor_id = v3dv_physical_device_vendor_id(device);
|
|
|
|
uint32_t device_id = v3dv_physical_device_device_id(device);
|
|
|
|
|
2020-07-04 12:09:58 +01:00
|
|
|
struct mesa_sha1 sha1_ctx;
|
|
|
|
uint8_t sha1[20];
|
|
|
|
STATIC_ASSERT(VK_UUID_SIZE <= sizeof(sha1));
|
|
|
|
|
|
|
|
/* The pipeline cache UUID is used for determining when a pipeline cache is
|
|
|
|
* invalid. It needs both a driver build and the PCI ID of the device.
|
|
|
|
*/
|
|
|
|
_mesa_sha1_init(&sha1_ctx);
|
|
|
|
_mesa_sha1_update(&sha1_ctx, build_id_data(note), build_id_len);
|
|
|
|
_mesa_sha1_update(&sha1_ctx, &device_id, sizeof(device_id));
|
|
|
|
_mesa_sha1_final(&sha1_ctx, sha1);
|
|
|
|
memcpy(device->pipeline_cache_uuid, sha1, VK_UUID_SIZE);
|
|
|
|
|
2020-10-05 09:44:59 +01:00
|
|
|
/* The driver UUID is used for determining sharability of images and memory
|
|
|
|
* between two Vulkan instances in separate processes. People who want to
|
|
|
|
* share memory need to also check the device UUID (below) so all this
|
|
|
|
* needs to be is the build-id.
|
|
|
|
*/
|
|
|
|
memcpy(device->driver_uuid, build_id_data(note), VK_UUID_SIZE);
|
|
|
|
|
|
|
|
/* The device UUID uniquely identifies the given device within the machine.
|
|
|
|
* Since we never have more than one device, this doesn't need to be a real
|
|
|
|
* UUID.
|
|
|
|
*/
|
|
|
|
_mesa_sha1_init(&sha1_ctx);
|
|
|
|
_mesa_sha1_update(&sha1_ctx, &vendor_id, sizeof(vendor_id));
|
|
|
|
_mesa_sha1_update(&sha1_ctx, &device_id, sizeof(device_id));
|
|
|
|
_mesa_sha1_final(&sha1_ctx, sha1);
|
|
|
|
memcpy(device->device_uuid, sha1, VK_UUID_SIZE);
|
|
|
|
|
2020-07-04 12:09:58 +01:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:56:50 +00:00
|
|
|
static void
|
|
|
|
v3dv_physical_device_init_disk_cache(struct v3dv_physical_device *device)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_SHADER_CACHE
|
|
|
|
char timestamp[41];
|
|
|
|
_mesa_sha1_format(timestamp, device->driver_build_sha1);
|
|
|
|
|
|
|
|
assert(device->name);
|
|
|
|
device->disk_cache = disk_cache_create(device->name, timestamp, 0);
|
|
|
|
#else
|
|
|
|
device->disk_cache = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-11-27 12:58:02 +00:00
|
|
|
static VkResult
|
|
|
|
physical_device_init(struct v3dv_physical_device *device,
|
|
|
|
struct v3dv_instance *instance,
|
2020-11-04 17:45:10 +00:00
|
|
|
drmDevicePtr drm_render_device,
|
|
|
|
drmDevicePtr drm_primary_device)
|
2019-11-27 12:58:02 +00:00
|
|
|
{
|
2019-11-29 08:01:56 +00:00
|
|
|
VkResult result = VK_SUCCESS;
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
int32_t master_fd = -1;
|
2021-02-07 18:12:23 +00:00
|
|
|
int32_t render_fd = -1;
|
2019-11-29 08:01:56 +00:00
|
|
|
|
2021-01-27 23:21:38 +00:00
|
|
|
struct vk_physical_device_dispatch_table dispatch_table;
|
|
|
|
vk_physical_device_dispatch_table_from_entrypoints
|
|
|
|
(&dispatch_table, &v3dv_physical_device_entrypoints, true);
|
2021-10-06 17:45:06 +01:00
|
|
|
vk_physical_device_dispatch_table_from_entrypoints(
|
|
|
|
&dispatch_table, &wsi_physical_device_entrypoints, false);
|
2021-01-27 23:21:38 +00:00
|
|
|
|
|
|
|
result = vk_physical_device_init(&device->vk, &instance->vk, NULL,
|
|
|
|
&dispatch_table);
|
2021-01-27 12:46:58 +00:00
|
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
goto fail;
|
2019-11-28 08:48:29 +00:00
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
assert(drm_render_device);
|
2020-11-04 17:45:10 +00:00
|
|
|
const char *path = drm_render_device->nodes[DRM_NODE_RENDER];
|
2021-02-07 18:12:23 +00:00
|
|
|
render_fd = open(path, O_RDWR | O_CLOEXEC);
|
2021-01-27 12:46:58 +00:00
|
|
|
if (render_fd < 0) {
|
2021-02-27 22:28:19 +00:00
|
|
|
fprintf(stderr, "Opening %s failed: %s\n", path, strerror(errno));
|
2021-01-27 12:46:58 +00:00
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-01-20 09:45:06 +00:00
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
/* If we are running on VK_KHR_display we need to acquire the master
|
|
|
|
* display device now for the v3dv_wsi_init() call below. For anything else
|
|
|
|
* we postpone that until a swapchain is created.
|
2020-01-20 09:45:06 +00:00
|
|
|
*/
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
|
2021-02-28 18:52:36 +00:00
|
|
|
const char *primary_path;
|
|
|
|
#if !using_v3d_simulator
|
|
|
|
if (drm_primary_device)
|
|
|
|
primary_path = drm_primary_device->nodes[DRM_NODE_PRIMARY];
|
|
|
|
else
|
|
|
|
primary_path = NULL;
|
|
|
|
#else
|
|
|
|
primary_path = drm_render_device->nodes[DRM_NODE_PRIMARY];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stat primary_stat = {0}, render_stat = {0};
|
|
|
|
|
|
|
|
device->has_primary = primary_path;
|
|
|
|
if (device->has_primary) {
|
|
|
|
if (stat(primary_path, &primary_stat) != 0) {
|
2021-09-24 21:31:03 +01:00
|
|
|
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
|
2021-02-28 18:52:36 +00:00
|
|
|
"failed to stat DRM primary node %s",
|
|
|
|
primary_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->primary_devid = primary_stat.st_rdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fstat(render_fd, &render_stat) != 0) {
|
2021-09-24 21:31:03 +01:00
|
|
|
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
|
2021-02-28 18:52:36 +00:00
|
|
|
"failed to stat DRM render node %s",
|
|
|
|
path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
device->has_render = true;
|
|
|
|
device->render_devid = render_stat.st_rdev;
|
|
|
|
|
2022-04-27 10:30:06 +01:00
|
|
|
#if using_v3d_simulator
|
|
|
|
device->device_id = drm_render_device->deviceinfo.pci->device_id;
|
|
|
|
#endif
|
|
|
|
|
2021-01-27 23:21:38 +00:00
|
|
|
if (instance->vk.enabled_extensions.KHR_display) {
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
#if !using_v3d_simulator
|
2020-11-04 17:45:10 +00:00
|
|
|
/* Open the primary node on the vc4 display device */
|
|
|
|
assert(drm_primary_device);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
|
2020-11-04 17:45:10 +00:00
|
|
|
#else
|
|
|
|
/* There is only one device with primary and render nodes.
|
|
|
|
* Open its primary node.
|
|
|
|
*/
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
|
|
|
|
#endif
|
2020-11-04 17:45:10 +00:00
|
|
|
}
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
|
|
|
|
#if using_v3d_simulator
|
2020-11-04 17:45:10 +00:00
|
|
|
device->sim_file = v3d_simulator_init(render_fd);
|
2020-01-20 09:45:06 +00:00
|
|
|
#endif
|
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
device->render_fd = render_fd; /* The v3d render node */
|
|
|
|
device->display_fd = -1; /* Authenticated vc4 primary node */
|
|
|
|
device->master_fd = master_fd; /* Master vc4 primary node */
|
2019-11-28 08:48:29 +00:00
|
|
|
|
2020-01-23 10:59:28 +00:00
|
|
|
if (!v3d_get_device_info(device->render_fd, &device->devinfo, &v3dv_ioctl)) {
|
2019-11-29 08:01:56 +00:00
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-05-26 07:38:31 +01:00
|
|
|
if (device->devinfo.ver < 42) {
|
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!device_has_expected_features(device)) {
|
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2021-10-04 12:53:17 +01:00
|
|
|
device->caps.multisync =
|
|
|
|
v3d_has_feature(device, DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT);
|
|
|
|
|
2021-11-23 22:29:48 +00:00
|
|
|
device->caps.perfmon =
|
|
|
|
v3d_has_feature(device, DRM_V3D_PARAM_SUPPORTS_PERFMON);
|
|
|
|
|
2020-10-05 09:44:59 +01:00
|
|
|
result = init_uuids(device);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
device->compiler = v3d_compiler_init(&device->devinfo,
|
|
|
|
MAX_INLINE_UNIFORM_BUFFERS);
|
2019-12-02 12:59:04 +00:00
|
|
|
device->next_program_id = 0;
|
|
|
|
|
2021-03-18 22:13:43 +00:00
|
|
|
ASSERTED int len =
|
|
|
|
asprintf(&device->name, "V3D %d.%d",
|
|
|
|
device->devinfo.ver / 10, device->devinfo.ver % 10);
|
|
|
|
assert(len != -1);
|
2019-11-29 08:01:56 +00:00
|
|
|
|
2021-03-18 21:56:50 +00:00
|
|
|
v3dv_physical_device_init_disk_cache(device);
|
|
|
|
|
2019-12-04 09:25:21 +00:00
|
|
|
/* Setup available memory heaps and types */
|
|
|
|
VkPhysicalDeviceMemoryProperties *mem = &device->memory;
|
|
|
|
mem->memoryHeapCount = 1;
|
|
|
|
mem->memoryHeaps[0].size = compute_heap_size();
|
|
|
|
mem->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
|
|
|
|
|
|
|
|
/* This is the only combination required by the spec */
|
2020-09-23 10:28:41 +01:00
|
|
|
mem->memoryTypeCount = 1;
|
2019-12-04 09:25:21 +00:00
|
|
|
mem->memoryTypes[0].propertyFlags =
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
|
|
mem->memoryTypes[0].heapIndex = 0;
|
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
/* Initialize sparse array for refcounting imported BOs */
|
|
|
|
util_sparse_array_init(&device->bo_map, sizeof(struct v3dv_bo), 512);
|
|
|
|
|
2022-07-05 12:04:59 +01:00
|
|
|
device->options.merge_jobs = !(V3D_DEBUG & V3D_DEBUG_NO_MERGE_JOBS);
|
2020-01-10 10:31:51 +00:00
|
|
|
|
2022-03-29 23:52:32 +01:00
|
|
|
device->drm_syncobj_type = vk_drm_syncobj_get_type(device->render_fd);
|
|
|
|
|
|
|
|
/* We don't support timelines in the uAPI yet and we don't want it getting
|
|
|
|
* suddenly turned on by vk_drm_syncobj_get_type() without us adding v3dv
|
|
|
|
* code for it first.
|
|
|
|
*/
|
|
|
|
device->drm_syncobj_type.features &= ~VK_SYNC_FEATURE_TIMELINE;
|
|
|
|
|
|
|
|
/* Sync file export is incompatible with the current model of execution
|
|
|
|
* where some jobs may run on the CPU. There are CTS tests which do the
|
|
|
|
* following:
|
|
|
|
*
|
|
|
|
* 1. Create a command buffer with a vkCmdWaitEvents()
|
|
|
|
* 2. Submit the command buffer
|
|
|
|
* 3. vkGetSemaphoreFdKHR() to try to get a sync_file
|
|
|
|
* 4. vkSetEvent()
|
|
|
|
*
|
|
|
|
* This deadlocks because we have to wait for the syncobj to get a real
|
|
|
|
* fence in vkGetSemaphoreFdKHR() which only happens after all the work
|
|
|
|
* from the command buffer is complete which only happens after
|
|
|
|
* vkSetEvent(). No amount of CPU threading in userspace will ever fix
|
|
|
|
* this. Sadly, this is pretty explicitly allowed by the Vulkan spec:
|
|
|
|
*
|
|
|
|
* VUID-vkCmdWaitEvents-pEvents-01163
|
|
|
|
*
|
|
|
|
* "If pEvents includes one or more events that will be signaled by
|
|
|
|
* vkSetEvent after commandBuffer has been submitted to a queue, then
|
|
|
|
* vkCmdWaitEvents must not be called inside a render pass instance"
|
|
|
|
*
|
|
|
|
* Disable sync file support for now.
|
|
|
|
*/
|
|
|
|
device->drm_syncobj_type.import_sync_file = NULL;
|
|
|
|
device->drm_syncobj_type.export_sync_file = NULL;
|
|
|
|
|
2022-04-05 00:37:26 +01:00
|
|
|
/* Multiwait is required for emulated timeline semaphores and is supported
|
|
|
|
* by the v3d kernel interface.
|
|
|
|
*/
|
|
|
|
device->drm_syncobj_type.features |= VK_SYNC_FEATURE_GPU_MULTI_WAIT;
|
|
|
|
|
|
|
|
device->sync_timeline_type =
|
|
|
|
vk_sync_timeline_get_type(&device->drm_syncobj_type);
|
|
|
|
|
2022-03-29 23:52:32 +01:00
|
|
|
device->sync_types[0] = &device->drm_syncobj_type;
|
2022-04-05 00:37:26 +01:00
|
|
|
device->sync_types[1] = &device->sync_timeline_type.sync;
|
|
|
|
device->sync_types[2] = NULL;
|
2022-03-29 23:52:32 +01:00
|
|
|
device->vk.supported_sync_types = device->sync_types;
|
|
|
|
|
2020-01-16 10:14:17 +00:00
|
|
|
result = v3dv_wsi_init(device);
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
vk_error(instance, result);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2021-04-27 13:01:48 +01:00
|
|
|
get_device_extensions(device, &device->vk.supported_extensions);
|
2020-06-04 10:14:10 +01:00
|
|
|
|
2022-04-04 14:40:30 +01:00
|
|
|
mtx_init(&device->mutex, mtx_plain);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
return VK_SUCCESS;
|
2020-01-16 10:14:17 +00:00
|
|
|
|
2019-12-04 09:25:21 +00:00
|
|
|
fail:
|
2021-01-27 12:46:58 +00:00
|
|
|
vk_physical_device_finish(&device->vk);
|
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
if (render_fd >= 0)
|
|
|
|
close(render_fd);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
if (master_fd >= 0)
|
|
|
|
close(master_fd);
|
2019-11-29 08:01:56 +00:00
|
|
|
|
|
|
|
return result;
|
2019-11-27 12:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VkResult
|
|
|
|
enumerate_devices(struct v3dv_instance *instance)
|
|
|
|
{
|
|
|
|
/* TODO: Check for more devices? */
|
|
|
|
drmDevicePtr devices[8];
|
|
|
|
VkResult result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
int max_devices;
|
|
|
|
|
|
|
|
instance->physicalDeviceCount = 0;
|
|
|
|
|
|
|
|
max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
|
|
|
|
if (max_devices < 1)
|
|
|
|
return VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
#if !using_v3d_simulator
|
|
|
|
int32_t v3d_idx = -1;
|
|
|
|
int32_t vc4_idx = -1;
|
|
|
|
#endif
|
2019-11-27 12:58:02 +00:00
|
|
|
for (unsigned i = 0; i < (unsigned)max_devices; i++) {
|
2020-01-20 09:45:06 +00:00
|
|
|
#if using_v3d_simulator
|
2022-04-27 10:32:00 +01:00
|
|
|
/* In the simulator, we look for an Intel/AMD render node */
|
2020-11-04 17:45:10 +00:00
|
|
|
const int required_nodes = (1 << DRM_NODE_RENDER) | (1 << DRM_NODE_PRIMARY);
|
|
|
|
if ((devices[i]->available_nodes & required_nodes) == required_nodes &&
|
|
|
|
devices[i]->bustype == DRM_BUS_PCI &&
|
2022-04-27 10:32:00 +01:00
|
|
|
(devices[i]->deviceinfo.pci->vendor_id == 0x8086 ||
|
|
|
|
devices[i]->deviceinfo.pci->vendor_id == 0x1002)) {
|
2020-01-20 09:45:06 +00:00
|
|
|
result = physical_device_init(&instance->physicalDevice, instance,
|
2020-11-04 17:45:10 +00:00
|
|
|
devices[i], NULL);
|
2019-11-27 12:58:02 +00:00
|
|
|
if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
|
|
|
|
break;
|
|
|
|
}
|
2020-01-20 09:45:06 +00:00
|
|
|
#else
|
|
|
|
/* On actual hardware, we should have a render node (v3d)
|
|
|
|
* and a primary node (vc4). We will need to use the primary
|
|
|
|
* to allocate WSI buffers and share them with the render node
|
|
|
|
* via prime, but that is a privileged operation so we need the
|
|
|
|
* primary node to be authenticated, and for that we need the
|
|
|
|
* display server to provide the device fd (with DRI3), so we
|
|
|
|
* here we only check that the device is present but we don't
|
|
|
|
* try to open it.
|
|
|
|
*/
|
|
|
|
if (devices[i]->bustype != DRM_BUS_PLATFORM)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER) {
|
|
|
|
char **compat = devices[i]->deviceinfo.platform->compatible;
|
|
|
|
while (*compat) {
|
|
|
|
if (strncmp(*compat, "brcm,2711-v3d", 13) == 0) {
|
|
|
|
v3d_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
compat++;
|
|
|
|
}
|
|
|
|
} else if (devices[i]->available_nodes & 1 << DRM_NODE_PRIMARY) {
|
|
|
|
char **compat = devices[i]->deviceinfo.platform->compatible;
|
|
|
|
while (*compat) {
|
2020-07-03 09:46:51 +01:00
|
|
|
if (strncmp(*compat, "brcm,bcm2711-vc5", 16) == 0 ||
|
|
|
|
strncmp(*compat, "brcm,bcm2835-vc4", 16) == 0 ) {
|
2020-01-20 09:45:06 +00:00
|
|
|
vc4_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
compat++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-27 12:58:02 +00:00
|
|
|
}
|
2020-01-20 09:45:06 +00:00
|
|
|
|
|
|
|
#if !using_v3d_simulator
|
|
|
|
if (v3d_idx == -1 || vc4_idx == -1)
|
|
|
|
result = VK_ERROR_INCOMPATIBLE_DRIVER;
|
|
|
|
else
|
|
|
|
result = physical_device_init(&instance->physicalDevice, instance,
|
2020-11-04 17:45:10 +00:00
|
|
|
devices[v3d_idx], devices[vc4_idx]);
|
2020-01-20 09:45:06 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-27 12:58:02 +00:00
|
|
|
drmFreeDevices(devices, max_devices);
|
|
|
|
|
|
|
|
if (result == VK_SUCCESS)
|
|
|
|
instance->physicalDeviceCount = 1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VkResult
|
|
|
|
instance_ensure_physical_device(struct v3dv_instance *instance)
|
|
|
|
{
|
|
|
|
if (instance->physicalDeviceCount < 0) {
|
|
|
|
VkResult result = enumerate_devices(instance);
|
|
|
|
if (result != VK_SUCCESS &&
|
|
|
|
result != VK_ERROR_INCOMPATIBLE_DRIVER)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_EnumeratePhysicalDevices(VkInstance _instance,
|
|
|
|
uint32_t *pPhysicalDeviceCount,
|
|
|
|
VkPhysicalDevice *pPhysicalDevices)
|
|
|
|
{
|
2019-11-27 12:58:02 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
|
2022-03-23 12:28:36 +00:00
|
|
|
VK_OUTARRAY_MAKE_TYPED(VkPhysicalDevice, out,
|
|
|
|
pPhysicalDevices, pPhysicalDeviceCount);
|
2019-11-27 12:58:02 +00:00
|
|
|
|
|
|
|
VkResult result = instance_ensure_physical_device(instance);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (instance->physicalDeviceCount == 0)
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
assert(instance->physicalDeviceCount == 1);
|
2022-03-23 12:28:36 +00:00
|
|
|
vk_outarray_append_typed(VkPhysicalDevice, &out, i) {
|
2019-11-27 12:58:02 +00:00
|
|
|
*i = v3dv_physical_device_to_handle(&instance->physicalDevice);
|
|
|
|
}
|
2019-11-25 15:29:12 +00:00
|
|
|
|
2019-11-27 12:58:02 +00:00
|
|
|
return vk_outarray_status(&out);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2021-05-27 08:16:18 +01:00
|
|
|
v3dv_EnumeratePhysicalDeviceGroups(
|
|
|
|
VkInstance _instance,
|
|
|
|
uint32_t *pPhysicalDeviceGroupCount,
|
|
|
|
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
|
2022-03-23 12:28:36 +00:00
|
|
|
VK_OUTARRAY_MAKE_TYPED(VkPhysicalDeviceGroupProperties, out,
|
|
|
|
pPhysicalDeviceGroupProperties,
|
|
|
|
pPhysicalDeviceGroupCount);
|
2021-05-27 08:16:18 +01:00
|
|
|
|
|
|
|
VkResult result = instance_ensure_physical_device(instance);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
assert(instance->physicalDeviceCount == 1);
|
|
|
|
|
2022-03-23 12:28:36 +00:00
|
|
|
vk_outarray_append_typed(VkPhysicalDeviceGroupProperties, &out, p) {
|
2021-05-27 08:16:18 +01:00
|
|
|
p->physicalDeviceCount = 1;
|
|
|
|
memset(p->physicalDevices, 0, sizeof(p->physicalDevices));
|
|
|
|
p->physicalDevices[0] =
|
|
|
|
v3dv_physical_device_to_handle(&instance->physicalDevice);
|
|
|
|
p->subsetAllocation = false;
|
|
|
|
|
|
|
|
vk_foreach_struct(ext, p->pNext)
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vk_outarray_status(&out);
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceFeatures *pFeatures)
|
|
|
|
{
|
2019-11-29 09:58:53 +00:00
|
|
|
memset(pFeatures, 0, sizeof(*pFeatures));
|
|
|
|
|
|
|
|
*pFeatures = (VkPhysicalDeviceFeatures) {
|
2020-02-21 08:33:03 +00:00
|
|
|
.robustBufferAccess = true, /* This feature is mandatory */
|
2020-11-04 12:35:08 +00:00
|
|
|
.fullDrawIndexUint32 = false, /* Only available since V3D 4.4.9.1 */
|
2020-06-28 01:08:16 +01:00
|
|
|
.imageCubeArray = true,
|
2020-11-04 12:35:08 +00:00
|
|
|
.independentBlend = true,
|
2021-07-01 08:42:24 +01:00
|
|
|
.geometryShader = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.tessellationShader = false,
|
2020-08-06 13:15:41 +01:00
|
|
|
.sampleRateShading = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.dualSrcBlend = false,
|
2020-10-26 12:00:07 +00:00
|
|
|
.logicOp = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.multiDrawIndirect = false,
|
2020-11-04 12:35:08 +00:00
|
|
|
.drawIndirectFirstInstance = true,
|
2022-07-04 13:49:53 +01:00
|
|
|
.depthClamp = false, /* Only available since V3D 4.5.1.1 */
|
2021-02-09 12:12:03 +00:00
|
|
|
.depthBiasClamp = true,
|
2020-07-22 09:12:51 +01:00
|
|
|
.fillModeNonSolid = true,
|
2020-05-13 10:21:12 +01:00
|
|
|
.depthBounds = false, /* Only available since V3D 4.3.16.2 */
|
2020-05-13 11:21:55 +01:00
|
|
|
.wideLines = true,
|
2020-08-16 01:19:10 +01:00
|
|
|
.largePoints = true,
|
2020-10-27 11:39:53 +00:00
|
|
|
.alphaToOne = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.multiViewport = false,
|
2020-03-29 15:29:55 +01:00
|
|
|
.samplerAnisotropy = true,
|
2020-02-27 07:55:40 +00:00
|
|
|
.textureCompressionETC2 = true,
|
2021-06-11 20:02:10 +01:00
|
|
|
.textureCompressionASTC_LDR = true,
|
2021-02-10 11:38:35 +00:00
|
|
|
/* Note that textureCompressionBC requires that the driver support all
|
|
|
|
* the BC formats. V3D 4.2 only support the BC1-3, so we can't claim
|
|
|
|
* that we support it.
|
|
|
|
*/
|
2019-11-29 09:58:53 +00:00
|
|
|
.textureCompressionBC = false,
|
v3dv: implement occlusion queries
The design for queries in Vulkan requires that some commands execute
in the GPU as part of a command buffer. Unfortunately, V3D doesn't
really have supprt for this, which means that we need to execute them
in the CPU but we still need to make it look as if they happened
inside the comamnd buffer from the point of view of the user, which
adds certain hassle.
The above means that in some cases we need to do CPU waits for certain
parts of the command buffer to execute so we can then run the CPU
code. For exmaple, we need to wait before executing a query resets
just in case the GPU is using them, and we have to do a CPU wait wait
for previous GPU jobs to complete before copying query results if the
user has asked us to do that. In the future, we may want to have
submission thread instead so we don't block the main thread in these
scenarios.
Because we now need to execute some tasks in the CPU as part of a
command buffer, this introduces the concept of job types, there is one
type for all GPU jobs, and then we have one type for each kind of job
that needs to execute in the CPU. CPU jobs are executed by the queue
in order just like GPU jobs, only that they are exclusively CPU tasks.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-04-16 09:30:38 +01:00
|
|
|
.occlusionQueryPrecise = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.pipelineStatisticsQuery = false,
|
v3dv: initial descriptor set support
Focused on getting the basic UBO and SSBO cases implemented. So no
dynamic offset, push contanst, samplers, and so on.
This include a initial implementation for CreatedescriptorPool,
CreateDescriptorSetLayout, AllocateDescriptorSets,
UpdateDescriptorSets, CreatePipelineLayout, and CmdBindDescriptorSets.
Also introduces lowering vulkan intrinsics. For now just
vulkan_resource_index.
We also introduce a descriptor_map, in this case for the ubos and
ssbos, used to assign a index for each set/binding combination, that
would be used when filling back the details of the ubo or ssbo on
other places (like QUNIFORM_UBO_ADDR or QUNIFORM_SSBO_OFFSET).
Note that at this point we don't need a bo for the descriptor pool, so
descriptor sets are not getting a piece of it. That would likely
change as we start to support more descriptor set types.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-01-20 14:29:38 +00:00
|
|
|
.vertexPipelineStoresAndAtomics = true,
|
|
|
|
.fragmentStoresAndAtomics = true,
|
2021-07-01 08:42:24 +01:00
|
|
|
.shaderTessellationAndGeometryPointSize = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.shaderImageGatherExtended = false,
|
2020-11-04 12:35:08 +00:00
|
|
|
.shaderStorageImageExtendedFormats = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.shaderStorageImageMultisample = false,
|
|
|
|
.shaderStorageImageReadWithoutFormat = false,
|
|
|
|
.shaderStorageImageWriteWithoutFormat = false,
|
|
|
|
.shaderUniformBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderSampledImageArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageImageArrayDynamicIndexing = false,
|
2020-07-21 09:29:21 +01:00
|
|
|
.shaderClipDistance = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
.shaderCullDistance = false,
|
|
|
|
.shaderFloat64 = false,
|
|
|
|
.shaderInt64 = false,
|
|
|
|
.shaderInt16 = false,
|
|
|
|
.shaderResourceResidency = false,
|
|
|
|
.shaderResourceMinLod = false,
|
|
|
|
.sparseBinding = false,
|
|
|
|
.sparseResidencyBuffer = false,
|
|
|
|
.sparseResidencyImage2D = false,
|
|
|
|
.sparseResidencyImage3D = false,
|
|
|
|
.sparseResidency2Samples = false,
|
|
|
|
.sparseResidency4Samples = false,
|
|
|
|
.sparseResidency8Samples = false,
|
|
|
|
.sparseResidency16Samples = false,
|
|
|
|
.sparseResidencyAliased = false,
|
|
|
|
.variableMultisampleRate = false,
|
2020-05-26 11:05:43 +01:00
|
|
|
.inheritedQueries = true,
|
2019-11-29 09:58:53 +00:00
|
|
|
};
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceFeatures2 *pFeatures)
|
|
|
|
{
|
2021-11-23 22:29:48 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, physical_device, physicalDevice);
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
|
|
|
|
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
VkPhysicalDeviceVulkan13Features vk13 = {
|
|
|
|
.inlineUniformBlock = true,
|
|
|
|
/* Inline buffers work like push constants, so after their are bound
|
|
|
|
* some of their contents may be copied into the uniform stream as soon
|
|
|
|
* as the next draw/dispatch is recorded in the command buffer. This means
|
|
|
|
* that if the client updates the buffer contents after binding it to
|
|
|
|
* a command buffer, the next queue submit of that command buffer may
|
|
|
|
* not use the latest update to the buffer contents, but the data that
|
|
|
|
* was present in the buffer at the time it was bound to the command
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
.descriptorBindingInlineUniformBlockUpdateAfterBind = false,
|
2022-04-05 00:24:30 +01:00
|
|
|
.pipelineCreationCacheControl = true,
|
|
|
|
.privateData = true,
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
};
|
|
|
|
|
2022-01-21 12:31:19 +00:00
|
|
|
VkPhysicalDeviceVulkan12Features vk12 = {
|
2022-01-25 11:49:44 +00:00
|
|
|
.hostQueryReset = true,
|
2022-01-21 12:31:19 +00:00
|
|
|
.uniformAndStorageBuffer8BitAccess = true,
|
2022-01-25 11:49:44 +00:00
|
|
|
.uniformBufferStandardLayout = true,
|
2022-01-25 11:53:20 +00:00
|
|
|
/* V3D 4.2 wraps TMU vector accesses to 16-byte boundaries, so loads and
|
|
|
|
* stores of vectors that cross these boundaries would not work correcly
|
|
|
|
* with scalarBlockLayout and would need to be split into smaller vectors
|
|
|
|
* (and/or scalars) that don't cross these boundaries. For load/stores
|
|
|
|
* with dynamic offsets where we can't identify if the offset is
|
|
|
|
* problematic, we would always have to scalarize. Overall, this would
|
|
|
|
* not lead to best performance so let's just not support it.
|
|
|
|
*/
|
|
|
|
.scalarBlockLayout = false,
|
2022-05-05 08:54:38 +01:00
|
|
|
/* This tells applications 2 things:
|
|
|
|
*
|
|
|
|
* 1. If they can select just one aspect for barriers. For us barriers
|
|
|
|
* decide if we need to split a job and we don't care if it is only
|
|
|
|
* for one of the aspects of the image or both, so we don't really
|
|
|
|
* benefit from seeing barriers that select just one aspect.
|
|
|
|
*
|
|
|
|
* 2. If they can program different layouts for each aspect. We
|
|
|
|
* generally don't care about layouts, so again, we don't get any
|
|
|
|
* benefits from this to limit the scope of image layout transitions.
|
|
|
|
*
|
2022-05-09 11:57:13 +01:00
|
|
|
* Still, Vulkan 1.2 requires this feature to be supported so we
|
|
|
|
* advertise it even though we don't really take advantage of it.
|
2022-05-05 08:54:38 +01:00
|
|
|
*/
|
2022-05-09 11:57:13 +01:00
|
|
|
.separateDepthStencilLayouts = true,
|
2022-01-25 11:49:44 +00:00
|
|
|
.storageBuffer8BitAccess = true,
|
2022-01-21 12:31:19 +00:00
|
|
|
.storagePushConstant8 = true,
|
2022-04-05 00:24:30 +01:00
|
|
|
.imagelessFramebuffer = true,
|
2022-04-05 00:37:26 +01:00
|
|
|
.timelineSemaphore = true,
|
2022-05-18 12:59:24 +01:00
|
|
|
|
2022-05-11 13:01:28 +01:00
|
|
|
.samplerMirrorClampToEdge = true,
|
|
|
|
|
2022-05-12 07:25:05 +01:00
|
|
|
/* These are mandatory by Vulkan 1.2, however, we don't support any of
|
|
|
|
* the optional features affected by them (non 32-bit types for
|
|
|
|
* shaderSubgroupExtendedTypes and additional subgroup ballot for
|
|
|
|
* subgroupBroadcastDynamicId), so in practice setting them to true
|
|
|
|
* doesn't have any implications for us until we implement any of these
|
|
|
|
* optional features.
|
|
|
|
*/
|
|
|
|
.shaderSubgroupExtendedTypes = true,
|
|
|
|
.subgroupBroadcastDynamicId = true,
|
|
|
|
|
2022-05-18 12:59:24 +01:00
|
|
|
.vulkanMemoryModel = true,
|
|
|
|
.vulkanMemoryModelDeviceScope = true,
|
|
|
|
.vulkanMemoryModelAvailabilityVisibilityChains = true,
|
2022-06-27 13:12:25 +01:00
|
|
|
|
|
|
|
.bufferDeviceAddress = true,
|
|
|
|
.bufferDeviceAddressCaptureReplay = false,
|
|
|
|
.bufferDeviceAddressMultiDevice = false,
|
2022-01-21 12:31:19 +00:00
|
|
|
};
|
|
|
|
|
2021-06-10 12:17:45 +01:00
|
|
|
VkPhysicalDeviceVulkan11Features vk11 = {
|
2022-01-18 10:17:29 +00:00
|
|
|
.storageBuffer16BitAccess = true,
|
|
|
|
.uniformAndStorageBuffer16BitAccess = true,
|
2022-01-19 11:33:10 +00:00
|
|
|
.storagePushConstant16 = true,
|
2021-06-10 12:17:45 +01:00
|
|
|
.storageInputOutput16 = false,
|
2021-07-20 10:32:17 +01:00
|
|
|
.multiview = true,
|
2021-06-10 12:17:45 +01:00
|
|
|
.multiviewGeometryShader = false,
|
|
|
|
.multiviewTessellationShader = false,
|
|
|
|
.variablePointersStorageBuffer = true,
|
|
|
|
/* FIXME: this needs support for non-constant index on UBO/SSBO */
|
|
|
|
.variablePointers = false,
|
|
|
|
.protectedMemory = false,
|
|
|
|
.samplerYcbcrConversion = false,
|
|
|
|
.shaderDrawParameters = false,
|
|
|
|
};
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
vk_foreach_struct(ext, pFeatures->pNext) {
|
2022-04-05 00:24:30 +01:00
|
|
|
if (vk_get_physical_device_core_1_1_feature_ext(ext, &vk11))
|
|
|
|
continue;
|
|
|
|
if (vk_get_physical_device_core_1_2_feature_ext(ext, &vk12))
|
|
|
|
continue;
|
|
|
|
if (vk_get_physical_device_core_1_3_feature_ext(ext, &vk13))
|
|
|
|
continue;
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
switch (ext->sType) {
|
2022-01-13 08:00:10 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT: {
|
|
|
|
VkPhysicalDevice4444FormatsFeaturesEXT *features =
|
|
|
|
(VkPhysicalDevice4444FormatsFeaturesEXT *)ext;
|
|
|
|
features->formatA4R4G4B4 = true;
|
|
|
|
features->formatA4B4G4R4 = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-28 09:53:00 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceCustomBorderColorFeaturesEXT *features =
|
|
|
|
(VkPhysicalDeviceCustomBorderColorFeaturesEXT *)ext;
|
|
|
|
features->customBorderColors = true;
|
|
|
|
features->customBorderColorWithoutFormat = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-17 11:12:46 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceIndexTypeUint8FeaturesEXT *features =
|
|
|
|
(VkPhysicalDeviceIndexTypeUint8FeaturesEXT *)ext;
|
|
|
|
features->indexTypeUint8 = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-17 11:20:41 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceLineRasterizationFeaturesEXT *features =
|
|
|
|
(VkPhysicalDeviceLineRasterizationFeaturesEXT *)ext;
|
|
|
|
features->rectangularLines = true;
|
|
|
|
features->bresenhamLines = true;
|
|
|
|
features->smoothLines = false;
|
|
|
|
features->stippledRectangularLines = false;
|
|
|
|
features->stippledBresenhamLines = false;
|
|
|
|
features->stippledSmoothLines = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-10 21:02:47 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceColorWriteEnableFeaturesEXT *features = (void *) ext;
|
|
|
|
features->colorWriteEnable = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-06 11:01:09 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR: {
|
|
|
|
VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *features =
|
|
|
|
(VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *) ext;
|
|
|
|
features->pipelineExecutableInfo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-15 15:50:39 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceProvokingVertexFeaturesEXT *features = (void *) ext;
|
|
|
|
features->provokingVertexLast = true;
|
|
|
|
/* FIXME: update when supporting EXT_transform_feedback */
|
|
|
|
features->transformFeedbackPreservesProvokingVertex = false;
|
|
|
|
break;
|
2021-08-14 15:09:23 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 11:30:52 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
|
|
|
|
VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features =
|
|
|
|
(void *) ext;
|
|
|
|
features->vertexAttributeInstanceRateDivisor = true;
|
|
|
|
features->vertexAttributeInstanceRateZeroDivisor = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-23 22:29:48 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR: {
|
|
|
|
VkPhysicalDevicePerformanceQueryFeaturesKHR *features =
|
|
|
|
(void *) ext;
|
|
|
|
|
|
|
|
features->performanceCounterQueryPools =
|
|
|
|
physical_device->caps.perfmon;
|
|
|
|
features->performanceCounterMultipleQueryPools = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2021-05-27 08:16:18 +01:00
|
|
|
v3dv_GetDeviceGroupPeerMemoryFeatures(VkDevice device,
|
|
|
|
uint32_t heapIndex,
|
|
|
|
uint32_t localDeviceIndex,
|
|
|
|
uint32_t remoteDeviceIndex,
|
|
|
|
VkPeerMemoryFeatureFlags *pPeerMemoryFeatures)
|
|
|
|
{
|
|
|
|
assert(localDeviceIndex == 0 && remoteDeviceIndex == 0);
|
|
|
|
*pPeerMemoryFeatures = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT |
|
|
|
|
VK_PEER_MEMORY_FEATURE_COPY_DST_BIT |
|
|
|
|
VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT |
|
|
|
|
VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT;
|
|
|
|
}
|
|
|
|
|
2020-07-04 00:32:11 +01:00
|
|
|
uint32_t
|
|
|
|
v3dv_physical_device_vendor_id(struct v3dv_physical_device *dev)
|
|
|
|
{
|
2020-10-05 09:44:59 +01:00
|
|
|
return 0x14E4; /* Broadcom */
|
2020-07-04 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
v3dv_physical_device_device_id(struct v3dv_physical_device *dev)
|
|
|
|
{
|
2020-07-07 11:23:12 +01:00
|
|
|
#if using_v3d_simulator
|
2022-04-27 10:30:06 +01:00
|
|
|
return dev->device_id;
|
2020-07-07 11:23:12 +01:00
|
|
|
#else
|
2021-09-15 07:30:15 +01:00
|
|
|
switch (dev->devinfo.ver) {
|
|
|
|
case 42:
|
|
|
|
return 0xBE485FD3; /* Broadcom deviceID for 2711 */
|
|
|
|
default:
|
|
|
|
unreachable("Unsupported V3D version");
|
|
|
|
}
|
2020-07-07 11:23:12 +01:00
|
|
|
#endif
|
2020-07-04 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceProperties *pProperties)
|
|
|
|
{
|
2019-11-28 11:47:19 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, physicalDevice);
|
|
|
|
|
2021-04-13 22:18:37 +01:00
|
|
|
STATIC_ASSERT(MAX_SAMPLED_IMAGES + MAX_STORAGE_IMAGES + MAX_INPUT_ATTACHMENTS
|
|
|
|
<= V3D_MAX_TEXTURE_SAMPLERS);
|
2021-04-15 10:59:34 +01:00
|
|
|
STATIC_ASSERT(MAX_UNIFORM_BUFFERS >= MAX_DYNAMIC_UNIFORM_BUFFERS);
|
|
|
|
STATIC_ASSERT(MAX_STORAGE_BUFFERS >= MAX_DYNAMIC_STORAGE_BUFFERS);
|
2021-04-13 22:18:37 +01:00
|
|
|
|
2019-11-28 11:47:19 +00:00
|
|
|
const uint32_t page_size = 4096;
|
|
|
|
const uint32_t mem_size = compute_heap_size();
|
|
|
|
|
|
|
|
const uint32_t max_varying_components = 16 * 4;
|
|
|
|
|
2022-03-17 10:24:49 +00:00
|
|
|
const float v3d_point_line_granularity = 2.0f / (1 << V3D_COORD_SHIFT);
|
2022-07-13 07:41:10 +01:00
|
|
|
const uint32_t max_fb_size = V3D_MAX_IMAGE_DIMENSION;
|
2019-11-28 11:47:19 +00:00
|
|
|
|
2020-02-21 08:26:47 +00:00
|
|
|
const VkSampleCountFlags supported_sample_counts =
|
|
|
|
VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
|
2019-11-28 11:47:19 +00:00
|
|
|
|
2020-10-29 10:55:23 +00:00
|
|
|
struct timespec clock_res;
|
|
|
|
clock_getres(CLOCK_MONOTONIC, &clock_res);
|
|
|
|
const float timestamp_period =
|
|
|
|
clock_res.tv_sec * 1000000000.0f + clock_res.tv_nsec;
|
|
|
|
|
2019-11-28 11:47:19 +00:00
|
|
|
/* FIXME: this will probably require an in-depth review */
|
|
|
|
VkPhysicalDeviceLimits limits = {
|
2022-07-13 07:41:10 +01:00
|
|
|
.maxImageDimension1D = V3D_MAX_IMAGE_DIMENSION,
|
|
|
|
.maxImageDimension2D = V3D_MAX_IMAGE_DIMENSION,
|
|
|
|
.maxImageDimension3D = V3D_MAX_IMAGE_DIMENSION,
|
|
|
|
.maxImageDimensionCube = V3D_MAX_IMAGE_DIMENSION,
|
|
|
|
.maxImageArrayLayers = V3D_MAX_ARRAY_LAYERS,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxTexelBufferElements = (1ul << 28),
|
2021-05-25 08:48:39 +01:00
|
|
|
.maxUniformBufferRange = V3D_MAX_BUFFER_RANGE,
|
|
|
|
.maxStorageBufferRange = V3D_MAX_BUFFER_RANGE,
|
2020-09-11 22:26:07 +01:00
|
|
|
.maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxMemoryAllocationCount = mem_size / page_size,
|
|
|
|
.maxSamplerAllocationCount = 64 * 1024,
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
.bufferImageGranularity = V3D_NON_COHERENT_ATOM_SIZE,
|
2019-11-28 11:47:19 +00:00
|
|
|
.sparseAddressSpaceSize = 0,
|
v3dv: initial descriptor set support
Focused on getting the basic UBO and SSBO cases implemented. So no
dynamic offset, push contanst, samplers, and so on.
This include a initial implementation for CreatedescriptorPool,
CreateDescriptorSetLayout, AllocateDescriptorSets,
UpdateDescriptorSets, CreatePipelineLayout, and CmdBindDescriptorSets.
Also introduces lowering vulkan intrinsics. For now just
vulkan_resource_index.
We also introduce a descriptor_map, in this case for the ubos and
ssbos, used to assign a index for each set/binding combination, that
would be used when filling back the details of the ubo or ssbo on
other places (like QUNIFORM_UBO_ADDR or QUNIFORM_SSBO_OFFSET).
Note that at this point we don't need a bo for the descriptor pool, so
descriptor sets are not getting a piece of it. That would likely
change as we start to support more descriptor set types.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-01-20 14:29:38 +00:00
|
|
|
.maxBoundDescriptorSets = MAX_SETS,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxPerStageDescriptorSamplers = V3D_MAX_TEXTURE_SAMPLERS,
|
|
|
|
.maxPerStageDescriptorUniformBuffers = MAX_UNIFORM_BUFFERS,
|
|
|
|
.maxPerStageDescriptorStorageBuffers = MAX_STORAGE_BUFFERS,
|
|
|
|
.maxPerStageDescriptorSampledImages = MAX_SAMPLED_IMAGES,
|
|
|
|
.maxPerStageDescriptorStorageImages = MAX_STORAGE_IMAGES,
|
|
|
|
.maxPerStageDescriptorInputAttachments = MAX_INPUT_ATTACHMENTS,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxPerStageResources = 128,
|
|
|
|
|
2021-04-15 10:59:34 +01:00
|
|
|
/* Some of these limits are multiplied by 6 because they need to
|
|
|
|
* include all possible shader stages (even if not supported). See
|
|
|
|
* 'Required Limits' table in the Vulkan spec.
|
|
|
|
*/
|
|
|
|
.maxDescriptorSetSamplers = 6 * V3D_MAX_TEXTURE_SAMPLERS,
|
|
|
|
.maxDescriptorSetUniformBuffers = 6 * MAX_UNIFORM_BUFFERS,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_UNIFORM_BUFFERS,
|
2021-04-15 10:59:34 +01:00
|
|
|
.maxDescriptorSetStorageBuffers = 6 * MAX_STORAGE_BUFFERS,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_STORAGE_BUFFERS,
|
2021-04-15 10:59:34 +01:00
|
|
|
.maxDescriptorSetSampledImages = 6 * MAX_SAMPLED_IMAGES,
|
|
|
|
.maxDescriptorSetStorageImages = 6 * MAX_STORAGE_IMAGES,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxDescriptorSetInputAttachments = MAX_INPUT_ATTACHMENTS,
|
2019-11-28 11:47:19 +00:00
|
|
|
|
|
|
|
/* Vertex limits */
|
2020-07-31 00:11:39 +01:00
|
|
|
.maxVertexInputAttributes = MAX_VERTEX_ATTRIBS,
|
|
|
|
.maxVertexInputBindings = MAX_VBS,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxVertexInputAttributeOffset = 0xffffffff,
|
|
|
|
.maxVertexInputBindingStride = 0xffffffff,
|
|
|
|
.maxVertexOutputComponents = max_varying_components,
|
|
|
|
|
|
|
|
/* Tessellation limits */
|
|
|
|
.maxTessellationGenerationLevel = 0,
|
|
|
|
.maxTessellationPatchSize = 0,
|
|
|
|
.maxTessellationControlPerVertexInputComponents = 0,
|
|
|
|
.maxTessellationControlPerVertexOutputComponents = 0,
|
|
|
|
.maxTessellationControlPerPatchOutputComponents = 0,
|
|
|
|
.maxTessellationControlTotalOutputComponents = 0,
|
|
|
|
.maxTessellationEvaluationInputComponents = 0,
|
|
|
|
.maxTessellationEvaluationOutputComponents = 0,
|
|
|
|
|
|
|
|
/* Geometry limits */
|
2021-07-01 08:42:24 +01:00
|
|
|
.maxGeometryShaderInvocations = 32,
|
|
|
|
.maxGeometryInputComponents = 64,
|
|
|
|
.maxGeometryOutputComponents = 64,
|
|
|
|
.maxGeometryOutputVertices = 256,
|
|
|
|
.maxGeometryTotalOutputComponents = 1024,
|
2019-11-28 11:47:19 +00:00
|
|
|
|
|
|
|
/* Fragment limits */
|
|
|
|
.maxFragmentInputComponents = max_varying_components,
|
|
|
|
.maxFragmentOutputAttachments = 4,
|
|
|
|
.maxFragmentDualSrcAttachments = 0,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxFragmentCombinedOutputResources = MAX_RENDER_TARGETS +
|
|
|
|
MAX_STORAGE_BUFFERS +
|
|
|
|
MAX_STORAGE_IMAGES,
|
2019-11-28 11:47:19 +00:00
|
|
|
|
|
|
|
/* Compute limits */
|
|
|
|
.maxComputeSharedMemorySize = 16384,
|
|
|
|
.maxComputeWorkGroupCount = { 65535, 65535, 65535 },
|
|
|
|
.maxComputeWorkGroupInvocations = 256,
|
|
|
|
.maxComputeWorkGroupSize = { 256, 256, 256 },
|
|
|
|
|
2022-03-17 10:24:49 +00:00
|
|
|
.subPixelPrecisionBits = V3D_COORD_SHIFT,
|
2019-11-28 11:47:19 +00:00
|
|
|
.subTexelPrecisionBits = 8,
|
|
|
|
.mipmapPrecisionBits = 8,
|
|
|
|
.maxDrawIndexedIndexValue = 0x00ffffff,
|
|
|
|
.maxDrawIndirectCount = 0x7fffffff,
|
|
|
|
.maxSamplerLodBias = 14.0f,
|
|
|
|
.maxSamplerAnisotropy = 16.0f,
|
2019-12-28 10:59:32 +00:00
|
|
|
.maxViewports = MAX_VIEWPORTS,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxViewportDimensions = { max_fb_size, max_fb_size },
|
|
|
|
.viewportBoundsRange = { -2.0 * max_fb_size,
|
|
|
|
2.0 * max_fb_size - 1 },
|
|
|
|
.viewportSubPixelBits = 0,
|
|
|
|
.minMemoryMapAlignment = page_size,
|
2021-04-23 09:24:57 +01:00
|
|
|
.minTexelBufferOffsetAlignment = V3D_UIFBLOCK_SIZE,
|
v3dv/descriptor_set: support for array of ubo/ssbo
For that we include the array_index when asking for a ubo/ssbo index
from the descriptor_map.
Until now, array_index was not included, but the descriptor_map took
into account the array_size. This had the advantage that you only need
a entry on the descriptor map, and the index was properly return.
But this make it complex to get back the set, binding and array_index
back from the ubo/ssbo binding. So it was more easy to just add
array_index. Somehow now the "key" on the descriptor map is the
combination of (set, binding, array_index).
Note that this also make sense as the vulkan api identifies each array
index as a descriptor, so for example, from spec,
VkDescriptorSetLayoutBinding:descriptorCount
"descriptorCount is the number of descriptors contained in the
binding, accessed in a shader as an array"
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-02-13 21:22:18 +00:00
|
|
|
.minUniformBufferOffsetAlignment = 32,
|
|
|
|
.minStorageBufferOffsetAlignment = 32,
|
2019-11-28 11:47:19 +00:00
|
|
|
.minTexelOffset = -8,
|
|
|
|
.maxTexelOffset = 7,
|
|
|
|
.minTexelGatherOffset = -8,
|
|
|
|
.maxTexelGatherOffset = 7,
|
|
|
|
.minInterpolationOffset = -0.5,
|
|
|
|
.maxInterpolationOffset = 0.5,
|
2022-03-17 10:24:49 +00:00
|
|
|
.subPixelInterpolationOffsetBits = V3D_COORD_SHIFT,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxFramebufferWidth = max_fb_size,
|
|
|
|
.maxFramebufferHeight = max_fb_size,
|
|
|
|
.maxFramebufferLayers = 256,
|
|
|
|
.framebufferColorSampleCounts = supported_sample_counts,
|
|
|
|
.framebufferDepthSampleCounts = supported_sample_counts,
|
|
|
|
.framebufferStencilSampleCounts = supported_sample_counts,
|
|
|
|
.framebufferNoAttachmentsSampleCounts = supported_sample_counts,
|
2021-04-13 22:18:37 +01:00
|
|
|
.maxColorAttachments = MAX_RENDER_TARGETS,
|
2019-11-28 11:47:19 +00:00
|
|
|
.sampledImageColorSampleCounts = supported_sample_counts,
|
|
|
|
.sampledImageIntegerSampleCounts = supported_sample_counts,
|
|
|
|
.sampledImageDepthSampleCounts = supported_sample_counts,
|
|
|
|
.sampledImageStencilSampleCounts = supported_sample_counts,
|
|
|
|
.storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.maxSampleMaskWords = 1,
|
2020-10-29 10:55:23 +00:00
|
|
|
.timestampComputeAndGraphics = true,
|
|
|
|
.timestampPeriod = timestamp_period,
|
2020-07-21 09:29:21 +01:00
|
|
|
.maxClipDistances = 8,
|
2019-11-28 11:47:19 +00:00
|
|
|
.maxCullDistances = 0,
|
2020-07-21 09:29:21 +01:00
|
|
|
.maxCombinedClipAndCullDistances = 8,
|
2019-11-28 11:47:19 +00:00
|
|
|
.discreteQueuePriorities = 2,
|
2020-08-15 23:05:01 +01:00
|
|
|
.pointSizeRange = { v3d_point_line_granularity,
|
|
|
|
V3D_MAX_POINT_SIZE },
|
|
|
|
.lineWidthRange = { 1.0f, V3D_MAX_LINE_WIDTH },
|
|
|
|
.pointSizeGranularity = v3d_point_line_granularity,
|
|
|
|
.lineWidthGranularity = v3d_point_line_granularity,
|
2019-11-28 11:47:19 +00:00
|
|
|
.strictLines = true,
|
|
|
|
.standardSampleLocations = false,
|
|
|
|
.optimalBufferCopyOffsetAlignment = 32,
|
|
|
|
.optimalBufferCopyRowPitchAlignment = 32,
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
.nonCoherentAtomSize = V3D_NON_COHERENT_ATOM_SIZE,
|
2019-11-28 11:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*pProperties = (VkPhysicalDeviceProperties) {
|
2021-04-27 13:01:48 +01:00
|
|
|
.apiVersion = V3DV_API_VERSION,
|
2019-11-28 11:47:19 +00:00
|
|
|
.driverVersion = vk_get_driver_version(),
|
2020-07-04 00:32:11 +01:00
|
|
|
.vendorID = v3dv_physical_device_vendor_id(pdevice),
|
|
|
|
.deviceID = v3dv_physical_device_device_id(pdevice),
|
2019-11-28 11:47:19 +00:00
|
|
|
.deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
|
|
|
|
.limits = limits,
|
|
|
|
.sparseProperties = { 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
snprintf(pProperties->deviceName, sizeof(pProperties->deviceName),
|
|
|
|
"%s", pdevice->name);
|
|
|
|
memcpy(pProperties->pipelineCacheUUID,
|
|
|
|
pdevice->pipeline_cache_uuid, VK_UUID_SIZE);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceProperties2 *pProperties)
|
|
|
|
{
|
2020-10-05 09:44:59 +01:00
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, physicalDevice);
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
|
|
|
|
|
2022-04-05 00:33:55 +01:00
|
|
|
/* We don't really have special restrictions for the maximum
|
|
|
|
* descriptors per set, other than maybe not exceeding the limits
|
|
|
|
* of addressable memory in a single allocation on either the host
|
|
|
|
* or the GPU. This will be a much larger limit than any of the
|
|
|
|
* per-stage limits already available in Vulkan though, so in practice,
|
|
|
|
* it is not expected to limit anything beyond what is already
|
|
|
|
* constrained through per-stage limits.
|
|
|
|
*/
|
|
|
|
const uint32_t max_host_descriptors =
|
|
|
|
(UINT32_MAX - sizeof(struct v3dv_descriptor_set)) /
|
|
|
|
sizeof(struct v3dv_descriptor);
|
|
|
|
const uint32_t max_gpu_descriptors =
|
|
|
|
(UINT32_MAX / v3dv_X(pdevice, max_descriptor_bo_size)());
|
|
|
|
|
|
|
|
VkPhysicalDeviceVulkan13Properties vk13 = {
|
|
|
|
.maxInlineUniformBlockSize = 4096,
|
|
|
|
.maxPerStageDescriptorInlineUniformBlocks = MAX_INLINE_UNIFORM_BUFFERS,
|
|
|
|
.maxDescriptorSetInlineUniformBlocks = MAX_INLINE_UNIFORM_BUFFERS,
|
|
|
|
.maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks =
|
|
|
|
MAX_INLINE_UNIFORM_BUFFERS,
|
|
|
|
.maxDescriptorSetUpdateAfterBindInlineUniformBlocks =
|
|
|
|
MAX_INLINE_UNIFORM_BUFFERS,
|
|
|
|
};
|
|
|
|
|
|
|
|
VkPhysicalDeviceVulkan12Properties vk12 = {
|
|
|
|
.driverID = VK_DRIVER_ID_MESA_V3DV,
|
|
|
|
.conformanceVersion = {
|
|
|
|
.major = 1,
|
|
|
|
.minor = 2,
|
|
|
|
.subminor = 7,
|
|
|
|
.patch = 1,
|
|
|
|
},
|
|
|
|
.supportedDepthResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,
|
|
|
|
.supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,
|
|
|
|
/* FIXME: if we want to support independentResolveNone then we would
|
|
|
|
* need to honor attachment load operations on resolve attachments,
|
|
|
|
* which we currently ignore because the resolve makes them irrelevant,
|
|
|
|
* as it unconditionally writes all pixels in the render area. However,
|
|
|
|
* with independentResolveNone, it is possible to have one aspect of a
|
|
|
|
* D/S resolve attachment stay unresolved, in which case the attachment
|
|
|
|
* load operation is relevant.
|
|
|
|
*
|
|
|
|
* NOTE: implementing attachment load for resolve attachments isn't
|
|
|
|
* immediately trivial because these attachments are not part of the
|
|
|
|
* framebuffer and therefore we can't use the same mechanism we use
|
|
|
|
* for framebuffer attachments. Instead, we should probably have to
|
|
|
|
* emit a meta operation for that right at the start of the render
|
|
|
|
* pass (or subpass).
|
|
|
|
*/
|
|
|
|
.independentResolveNone = false,
|
|
|
|
.independentResolve = false,
|
2022-04-05 00:37:26 +01:00
|
|
|
.maxTimelineSemaphoreValueDifference = UINT64_MAX,
|
2022-05-10 11:53:08 +01:00
|
|
|
|
|
|
|
.denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL,
|
|
|
|
.roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL,
|
|
|
|
.shaderSignedZeroInfNanPreserveFloat16 = true,
|
|
|
|
.shaderSignedZeroInfNanPreserveFloat32 = true,
|
|
|
|
.shaderSignedZeroInfNanPreserveFloat64 = false,
|
|
|
|
.shaderDenormPreserveFloat16 = true,
|
|
|
|
.shaderDenormPreserveFloat32 = true,
|
|
|
|
.shaderDenormPreserveFloat64 = false,
|
|
|
|
.shaderDenormFlushToZeroFloat16 = false,
|
|
|
|
.shaderDenormFlushToZeroFloat32 = false,
|
|
|
|
.shaderDenormFlushToZeroFloat64 = false,
|
|
|
|
.shaderRoundingModeRTEFloat16 = true,
|
|
|
|
.shaderRoundingModeRTEFloat32 = true,
|
|
|
|
.shaderRoundingModeRTEFloat64 = false,
|
|
|
|
.shaderRoundingModeRTZFloat16 = false,
|
|
|
|
.shaderRoundingModeRTZFloat32 = false,
|
|
|
|
.shaderRoundingModeRTZFloat64 = false,
|
2022-05-11 11:33:11 +01:00
|
|
|
|
|
|
|
/* V3D doesn't support min/max filtering */
|
|
|
|
.filterMinmaxSingleComponentFormats = false,
|
|
|
|
.filterMinmaxImageComponentMapping = false,
|
2022-05-11 13:11:39 +01:00
|
|
|
|
|
|
|
.framebufferIntegerColorSampleCounts =
|
|
|
|
VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT,
|
2022-04-05 00:33:55 +01:00
|
|
|
};
|
2022-07-01 13:04:28 +01:00
|
|
|
memset(vk12.driverName, 0, VK_MAX_DRIVER_NAME_SIZE);
|
|
|
|
snprintf(vk12.driverName, VK_MAX_DRIVER_NAME_SIZE, "V3DV Mesa");
|
|
|
|
memset(vk12.driverInfo, 0, VK_MAX_DRIVER_INFO_SIZE);
|
|
|
|
snprintf(vk12.driverInfo, VK_MAX_DRIVER_INFO_SIZE,
|
2022-04-05 00:33:55 +01:00
|
|
|
"Mesa " PACKAGE_VERSION MESA_GIT_SHA1);
|
|
|
|
|
|
|
|
VkPhysicalDeviceVulkan11Properties vk11 = {
|
|
|
|
.deviceLUIDValid = false,
|
|
|
|
.subgroupSize = V3D_CHANNELS,
|
|
|
|
.subgroupSupportedStages = VK_SHADER_STAGE_COMPUTE_BIT,
|
|
|
|
.subgroupSupportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT,
|
|
|
|
.subgroupQuadOperationsInAllStages = false,
|
|
|
|
.pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES,
|
|
|
|
.maxMultiviewViewCount = MAX_MULTIVIEW_VIEW_COUNT,
|
|
|
|
.maxMultiviewInstanceIndex = UINT32_MAX - 1,
|
|
|
|
.protectedNoFault = false,
|
|
|
|
.maxPerSetDescriptors = MIN2(max_host_descriptors, max_gpu_descriptors),
|
|
|
|
/* Minimum required by the spec */
|
|
|
|
.maxMemoryAllocationSize = MAX_MEMORY_ALLOCATION_SIZE,
|
|
|
|
};
|
|
|
|
memcpy(vk11.deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
|
|
|
|
memcpy(vk11.driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
|
|
|
|
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
vk_foreach_struct(ext, pProperties->pNext) {
|
2022-04-05 00:33:55 +01:00
|
|
|
if (vk_get_physical_device_core_1_1_property_ext(ext, &vk11))
|
|
|
|
continue;
|
|
|
|
if (vk_get_physical_device_core_1_2_property_ext(ext, &vk12))
|
|
|
|
continue;
|
|
|
|
if (vk_get_physical_device_core_1_3_property_ext(ext, &vk13))
|
|
|
|
continue;
|
|
|
|
|
2020-01-15 07:48:07 +00:00
|
|
|
switch (ext->sType) {
|
2021-07-28 09:53:00 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT: {
|
|
|
|
VkPhysicalDeviceCustomBorderColorPropertiesEXT *props =
|
|
|
|
(VkPhysicalDeviceCustomBorderColorPropertiesEXT *)ext;
|
|
|
|
props->maxCustomBorderColorSamplers = V3D_MAX_TEXTURE_SAMPLERS;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-15 15:50:39 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_PROPERTIES_EXT: {
|
|
|
|
VkPhysicalDeviceProvokingVertexPropertiesEXT *props =
|
|
|
|
(VkPhysicalDeviceProvokingVertexPropertiesEXT *)ext;
|
|
|
|
props->provokingVertexModePerPipeline = true;
|
|
|
|
/* FIXME: update when supporting EXT_transform_feedback */
|
|
|
|
props->transformFeedbackPreservesTriangleFanProvokingVertex = false;
|
|
|
|
break;
|
|
|
|
}
|
2021-09-02 11:30:52 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
|
|
|
|
VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *props =
|
|
|
|
(VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *)ext;
|
|
|
|
props->maxVertexAttribDivisor = 0xffff;
|
|
|
|
break;
|
|
|
|
}
|
2021-11-23 22:29:48 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_PROPERTIES_KHR : {
|
|
|
|
VkPhysicalDevicePerformanceQueryPropertiesKHR *props =
|
|
|
|
(VkPhysicalDevicePerformanceQueryPropertiesKHR *)ext;
|
|
|
|
|
|
|
|
props->allowCommandBufferQueryCopies = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-02-28 18:52:36 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT: {
|
|
|
|
VkPhysicalDeviceDrmPropertiesEXT *props =
|
|
|
|
(VkPhysicalDeviceDrmPropertiesEXT *)ext;
|
|
|
|
props->hasPrimary = pdevice->has_primary;
|
|
|
|
if (props->hasPrimary) {
|
|
|
|
props->primaryMajor = (int64_t) major(pdevice->primary_devid);
|
|
|
|
props->primaryMinor = (int64_t) minor(pdevice->primary_devid);
|
|
|
|
}
|
|
|
|
props->hasRender = pdevice->has_render;
|
|
|
|
if (props->hasRender) {
|
|
|
|
props->renderMajor = (int64_t) major(pdevice->render_devid);
|
|
|
|
props->renderMinor = (int64_t) minor(pdevice->render_devid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-03-17 11:20:41 +00:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT: {
|
|
|
|
VkPhysicalDeviceLineRasterizationPropertiesEXT *props =
|
|
|
|
(VkPhysicalDeviceLineRasterizationPropertiesEXT *)ext;
|
|
|
|
props->lineSubPixelPrecisionBits = V3D_COORD_SHIFT;
|
|
|
|
break;
|
|
|
|
}
|
2021-06-10 12:17:45 +01:00
|
|
|
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT:
|
|
|
|
/* Do nothing, not even logging. This is a non-PCI device, so we will
|
|
|
|
* never provide this extension.
|
|
|
|
*/
|
|
|
|
break;
|
2020-01-15 07:48:07 +00:00
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 10:33:37 +00:00
|
|
|
/* We support exactly one queue family. */
|
|
|
|
static const VkQueueFamilyProperties
|
|
|
|
v3dv_queue_family_properties = {
|
|
|
|
.queueFlags = VK_QUEUE_GRAPHICS_BIT |
|
|
|
|
VK_QUEUE_COMPUTE_BIT |
|
|
|
|
VK_QUEUE_TRANSFER_BIT,
|
|
|
|
.queueCount = 1,
|
2020-10-29 10:55:23 +00:00
|
|
|
.timestampValidBits = 64,
|
2019-11-29 10:33:37 +00:00
|
|
|
.minImageTransferGranularity = { 1, 1, 1 },
|
|
|
|
};
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
|
|
|
|
uint32_t *pQueueFamilyPropertyCount,
|
|
|
|
VkQueueFamilyProperties2 *pQueueFamilyProperties)
|
|
|
|
{
|
2022-03-23 12:28:36 +00:00
|
|
|
VK_OUTARRAY_MAKE_TYPED(VkQueueFamilyProperties2, out,
|
|
|
|
pQueueFamilyProperties, pQueueFamilyPropertyCount);
|
2020-01-15 07:48:07 +00:00
|
|
|
|
2022-03-23 12:28:36 +00:00
|
|
|
vk_outarray_append_typed(VkQueueFamilyProperties2, &out, p) {
|
2020-01-15 07:48:07 +00:00
|
|
|
p->queueFamilyProperties = v3dv_queue_family_properties;
|
|
|
|
|
|
|
|
vk_foreach_struct(s, p->pNext) {
|
|
|
|
v3dv_debug_ignored_stype(s->sType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceMemoryProperties *pMemoryProperties)
|
|
|
|
{
|
2019-12-04 09:25:21 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, device, physicalDevice);
|
|
|
|
*pMemoryProperties = device->memory;
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-01-15 07:48:07 +00:00
|
|
|
v3dv_GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,
|
|
|
|
VkPhysicalDeviceMemoryProperties2 *pMemoryProperties)
|
|
|
|
{
|
|
|
|
v3dv_GetPhysicalDeviceMemoryProperties(physicalDevice,
|
|
|
|
&pMemoryProperties->memoryProperties);
|
|
|
|
|
|
|
|
vk_foreach_struct(ext, pMemoryProperties->pNext) {
|
|
|
|
switch (ext->sType) {
|
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-25 15:29:12 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_GetInstanceProcAddr(VkInstance _instance,
|
|
|
|
const char *pName)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
|
2021-01-27 23:21:38 +00:00
|
|
|
return vk_instance_get_proc_addr(&instance->vk,
|
|
|
|
&v3dv_instance_entrypoints,
|
|
|
|
pName);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* With version 1+ of the loader interface the ICD should expose
|
|
|
|
* vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
|
|
|
|
*/
|
|
|
|
PUBLIC
|
|
|
|
VKAPI_ATTR PFN_vkVoidFunction
|
|
|
|
VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance,
|
|
|
|
const char *pName);
|
|
|
|
|
|
|
|
PUBLIC
|
|
|
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
|
|
|
|
vk_icdGetInstanceProcAddr(VkInstance instance,
|
|
|
|
const char* pName)
|
|
|
|
{
|
|
|
|
return v3dv_GetInstanceProcAddr(instance, pName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* With version 4+ of the loader interface the ICD should expose
|
|
|
|
* vk_icdGetPhysicalDeviceProcAddr()
|
|
|
|
*/
|
|
|
|
PUBLIC
|
|
|
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
|
|
|
|
vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance,
|
|
|
|
const char* pName);
|
|
|
|
|
|
|
|
PFN_vkVoidFunction
|
|
|
|
vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance,
|
|
|
|
const char* pName)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_instance, instance, _instance);
|
|
|
|
|
2021-01-27 23:21:38 +00:00
|
|
|
return vk_instance_get_physical_device_proc_addr(&instance->vk, pName);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-12-03 08:10:10 +00:00
|
|
|
v3dv_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
|
|
|
|
VkLayerProperties *pProperties)
|
|
|
|
{
|
|
|
|
if (pProperties == NULL) {
|
|
|
|
*pPropertyCount = 0;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-12-03 08:10:10 +00:00
|
|
|
v3dv_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
|
|
|
|
uint32_t *pPropertyCount,
|
|
|
|
VkLayerProperties *pProperties)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, physical_device, physicalDevice);
|
|
|
|
|
|
|
|
if (pProperties == NULL) {
|
|
|
|
*pPropertyCount = 0;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(physical_device, VK_ERROR_LAYER_NOT_PRESENT);
|
2019-12-03 08:10:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 23:52:32 +01:00
|
|
|
static void
|
|
|
|
destroy_queue_syncs(struct v3dv_queue *queue)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < V3DV_QUEUE_COUNT; i++) {
|
|
|
|
if (queue->last_job_syncs.syncs[i]) {
|
|
|
|
drmSyncobjDestroy(queue->device->pdevice->render_fd,
|
|
|
|
queue->last_job_syncs.syncs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 11:44:40 +00:00
|
|
|
static VkResult
|
2021-09-23 17:14:36 +01:00
|
|
|
queue_init(struct v3dv_device *device, struct v3dv_queue *queue,
|
|
|
|
const VkDeviceQueueCreateInfo *create_info,
|
|
|
|
uint32_t index_in_family)
|
2019-11-29 11:44:40 +00:00
|
|
|
{
|
2021-09-23 17:14:36 +01:00
|
|
|
VkResult result = vk_queue_init(&queue->vk, &device->vk, create_info,
|
|
|
|
index_in_family);
|
2021-04-06 13:30:32 +01:00
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
return result;
|
2022-03-29 23:52:32 +01:00
|
|
|
|
|
|
|
result = vk_queue_enable_submit_thread(&queue->vk);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
goto fail_submit_thread;
|
|
|
|
|
2019-11-29 11:44:40 +00:00
|
|
|
queue->device = device;
|
2022-03-29 23:52:32 +01:00
|
|
|
queue->vk.driver_submit = v3dv_queue_driver_submit;
|
|
|
|
|
|
|
|
for (int i = 0; i < V3DV_QUEUE_COUNT; i++) {
|
|
|
|
queue->last_job_syncs.first[i] = true;
|
|
|
|
int ret = drmSyncobjCreate(device->pdevice->render_fd,
|
|
|
|
DRM_SYNCOBJ_CREATE_SIGNALED,
|
|
|
|
&queue->last_job_syncs.syncs[i]);
|
|
|
|
if (ret) {
|
|
|
|
result = vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
|
|
|
|
"syncobj create failed: %m");
|
|
|
|
goto fail_last_job_syncs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 17:02:05 +01:00
|
|
|
queue->noop_job = NULL;
|
2019-11-29 11:44:40 +00:00
|
|
|
return VK_SUCCESS;
|
2022-03-29 23:52:32 +01:00
|
|
|
|
|
|
|
fail_last_job_syncs:
|
|
|
|
destroy_queue_syncs(queue);
|
|
|
|
fail_submit_thread:
|
|
|
|
vk_queue_finish(&queue->vk);
|
|
|
|
return result;
|
2019-11-29 11:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
queue_finish(struct v3dv_queue *queue)
|
|
|
|
{
|
2020-09-18 17:02:05 +01:00
|
|
|
if (queue->noop_job)
|
|
|
|
v3dv_job_destroy(queue->noop_job);
|
2022-03-29 23:52:32 +01:00
|
|
|
destroy_queue_syncs(queue);
|
|
|
|
vk_queue_finish(&queue->vk);
|
2019-11-29 11:44:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 12:06:55 +01:00
|
|
|
static void
|
|
|
|
init_device_meta(struct v3dv_device *device)
|
|
|
|
{
|
|
|
|
mtx_init(&device->meta.mtx, mtx_plain);
|
2020-08-26 07:38:41 +01:00
|
|
|
v3dv_meta_clear_init(device);
|
|
|
|
v3dv_meta_blit_init(device);
|
2020-11-12 09:43:54 +00:00
|
|
|
v3dv_meta_texel_buffer_copy_init(device);
|
2020-08-25 13:25:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 12:06:55 +01:00
|
|
|
static void
|
|
|
|
destroy_device_meta(struct v3dv_device *device)
|
|
|
|
{
|
|
|
|
mtx_destroy(&device->meta.mtx);
|
2020-08-26 07:38:41 +01:00
|
|
|
v3dv_meta_clear_finish(device);
|
|
|
|
v3dv_meta_blit_finish(device);
|
2020-11-12 09:43:54 +00:00
|
|
|
v3dv_meta_texel_buffer_copy_finish(device);
|
2020-03-31 12:06:55 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
|
|
|
|
const VkDeviceCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkDevice *pDevice)
|
|
|
|
{
|
2019-11-29 11:44:40 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_physical_device, physical_device, physicalDevice);
|
2021-01-27 22:45:28 +00:00
|
|
|
struct v3dv_instance *instance = (struct v3dv_instance*) physical_device->vk.instance;
|
2019-11-29 11:44:40 +00:00
|
|
|
VkResult result;
|
|
|
|
struct v3dv_device *device;
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
|
|
|
|
|
|
|
|
/* Check requested queues (we only expose one queue ) */
|
|
|
|
assert(pCreateInfo->queueCreateInfoCount == 1);
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
|
|
|
|
assert(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex == 0);
|
|
|
|
assert(pCreateInfo->pQueueCreateInfos[i].queueCount == 1);
|
|
|
|
if (pCreateInfo->pQueueCreateInfos[i].flags != 0)
|
|
|
|
return vk_error(instance, VK_ERROR_INITIALIZATION_FAILED);
|
|
|
|
}
|
|
|
|
|
2021-01-27 22:45:28 +00:00
|
|
|
device = vk_zalloc2(&physical_device->vk.instance->alloc, pAllocator,
|
2019-11-29 11:44:40 +00:00
|
|
|
sizeof(*device), 8,
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
|
|
|
|
if (!device)
|
|
|
|
return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
2021-01-27 23:21:38 +00:00
|
|
|
struct vk_device_dispatch_table dispatch_table;
|
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
&v3dv_device_entrypoints, true);
|
2021-10-06 17:45:06 +01:00
|
|
|
vk_device_dispatch_table_from_entrypoints(&dispatch_table,
|
|
|
|
&wsi_device_entrypoints, false);
|
2021-01-27 23:21:38 +00:00
|
|
|
result = vk_device_init(&device->vk, &physical_device->vk,
|
2021-01-29 18:30:34 +00:00
|
|
|
&dispatch_table, pCreateInfo, pAllocator);
|
2021-01-24 15:26:24 +00:00
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
vk_free(&device->vk.alloc, device);
|
2021-10-06 10:28:15 +01:00
|
|
|
return vk_error(NULL, result);
|
2021-01-24 15:26:24 +00:00
|
|
|
}
|
2020-11-12 15:30:41 +00:00
|
|
|
|
2019-11-29 11:44:40 +00:00
|
|
|
device->instance = instance;
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
device->pdevice = physical_device;
|
2019-11-29 11:44:40 +00:00
|
|
|
|
2022-04-04 16:25:15 +01:00
|
|
|
mtx_init(&device->query_mutex, mtx_plain);
|
|
|
|
cnd_init(&device->query_ended);
|
2020-05-18 09:41:11 +01:00
|
|
|
|
2022-03-29 23:52:32 +01:00
|
|
|
vk_device_set_drm_fd(&device->vk, physical_device->render_fd);
|
|
|
|
vk_device_enable_threaded_submit(&device->vk);
|
|
|
|
|
2021-09-23 17:14:36 +01:00
|
|
|
result = queue_init(device, &device->queue,
|
|
|
|
pCreateInfo->pQueueCreateInfos, 0);
|
2019-11-29 11:44:40 +00:00
|
|
|
if (result != VK_SUCCESS)
|
2020-01-20 09:45:06 +00:00
|
|
|
goto fail;
|
2019-11-29 11:44:40 +00:00
|
|
|
|
|
|
|
device->devinfo = physical_device->devinfo;
|
|
|
|
|
2021-09-03 11:15:03 +01:00
|
|
|
/* Vulkan 1.1 and VK_KHR_get_physical_device_properties2 added
|
|
|
|
* VkPhysicalDeviceFeatures2 which can be used in the pNext chain of
|
|
|
|
* vkDeviceCreateInfo, in which case it should be used instead of
|
|
|
|
* pEnabledFeatures.
|
|
|
|
*/
|
|
|
|
const VkPhysicalDeviceFeatures2 *features2 =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext, PHYSICAL_DEVICE_FEATURES_2);
|
|
|
|
if (features2) {
|
|
|
|
memcpy(&device->features, &features2->features,
|
|
|
|
sizeof(device->features));
|
|
|
|
} else if (pCreateInfo->pEnabledFeatures) {
|
2020-08-27 09:48:29 +01:00
|
|
|
memcpy(&device->features, pCreateInfo->pEnabledFeatures,
|
|
|
|
sizeof(device->features));
|
|
|
|
}
|
|
|
|
|
2021-09-03 11:15:03 +01:00
|
|
|
if (device->features.robustBufferAccess)
|
|
|
|
perf_debug("Device created with Robust Buffer Access enabled.\n");
|
|
|
|
|
2021-06-01 09:39:20 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
v3dv_X(device, device_check_prepacked_sizes)();
|
|
|
|
#endif
|
2020-03-31 12:06:55 +01:00
|
|
|
init_device_meta(device);
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
v3dv_bo_cache_init(device);
|
2021-08-14 15:09:23 +01:00
|
|
|
v3dv_pipeline_cache_init(&device->default_pipeline_cache, device, 0,
|
2020-09-20 21:54:33 +01:00
|
|
|
device->instance->default_pipeline_cache_enabled);
|
v3dv: define a default attribute values with float type
We are providing a BO with the default attribute values for the
GL_SHADER_STATE_RECORD, that contains 16 vec4. Such default value for
each vec4 is (0, 0, 0, 1). As the attribute format could be int or
float, the "1" value needs to take into account the attribute format.
But in the practice, the most common case is all floats. So we create
one default attribute values BO assuming that all attributes will be
floats, and we store it at v3dv_device and only create a new one if a
int format type is defined. That allows to reduce the amount of BOs
needed.
Note that we could still try to reduce the amount of BOs used by the
pipelines if we create a bigger BO, and we just play with the
offsets. But as mentioned, that's not the usual, and would add an
extra complexity,so it is not a priority right now.
This makes the following test passing when disabling the pipeline
cache support:
dEQP-VK.api.object_management.max_concurrent.graphics_pipeline
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9845>
2021-03-25 12:30:55 +00:00
|
|
|
device->default_attribute_float =
|
|
|
|
v3dv_pipeline_create_default_attribute_values(device, NULL);
|
2019-11-29 11:44:40 +00:00
|
|
|
|
2022-06-27 13:12:25 +01:00
|
|
|
device->device_address_mem_ctx = ralloc_context(NULL);
|
|
|
|
util_dynarray_init(&device->device_address_bo_list,
|
|
|
|
device->device_address_mem_ctx);
|
|
|
|
|
2019-11-29 11:44:40 +00:00
|
|
|
*pDevice = v3dv_device_to_handle(device);
|
2019-11-25 15:29:12 +00:00
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2019-11-29 11:44:40 +00:00
|
|
|
|
2020-01-20 09:45:06 +00:00
|
|
|
fail:
|
2022-04-04 16:25:15 +01:00
|
|
|
cnd_destroy(&device->query_ended);
|
|
|
|
mtx_destroy(&device->query_mutex);
|
2021-01-23 10:29:04 +00:00
|
|
|
vk_device_finish(&device->vk);
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_free(&device->vk.alloc, device);
|
2019-11-29 11:44:40 +00:00
|
|
|
|
|
|
|
return result;
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-25 15:29:12 +00:00
|
|
|
v3dv_DestroyDevice(VkDevice _device,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
2019-11-29 11:44:40 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
2020-01-13 07:53:26 +00:00
|
|
|
|
2022-03-29 23:52:32 +01:00
|
|
|
device->vk.dispatch_table.DeviceWaitIdle(_device);
|
2019-11-29 11:44:40 +00:00
|
|
|
queue_finish(&device->queue);
|
2020-03-31 12:06:55 +01:00
|
|
|
destroy_device_meta(device);
|
2020-07-22 01:08:06 +01:00
|
|
|
v3dv_pipeline_cache_finish(&device->default_pipeline_cache);
|
|
|
|
|
v3dv: define a default attribute values with float type
We are providing a BO with the default attribute values for the
GL_SHADER_STATE_RECORD, that contains 16 vec4. Such default value for
each vec4 is (0, 0, 0, 1). As the attribute format could be int or
float, the "1" value needs to take into account the attribute format.
But in the practice, the most common case is all floats. So we create
one default attribute values BO assuming that all attributes will be
floats, and we store it at v3dv_device and only create a new one if a
int format type is defined. That allows to reduce the amount of BOs
needed.
Note that we could still try to reduce the amount of BOs used by the
pipelines if we create a bigger BO, and we just play with the
offsets. But as mentioned, that's not the usual, and would add an
extra complexity,so it is not a priority right now.
This makes the following test passing when disabling the pipeline
cache support:
dEQP-VK.api.object_management.max_concurrent.graphics_pipeline
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9845>
2021-03-25 12:30:55 +00:00
|
|
|
if (device->default_attribute_float) {
|
|
|
|
v3dv_bo_free(device, device->default_attribute_float);
|
|
|
|
device->default_attribute_float = NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-27 13:12:25 +01:00
|
|
|
ralloc_free(device->device_address_mem_ctx);
|
|
|
|
|
2020-07-22 01:08:06 +01:00
|
|
|
/* Bo cache should be removed the last, as any other object could be
|
|
|
|
* freeing their private bos
|
|
|
|
*/
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
v3dv_bo_cache_destroy(device);
|
2020-01-20 09:45:06 +00:00
|
|
|
|
2022-04-04 16:25:15 +01:00
|
|
|
cnd_destroy(&device->query_ended);
|
|
|
|
mtx_destroy(&device->query_mutex);
|
|
|
|
|
2021-01-23 10:29:04 +00:00
|
|
|
vk_device_finish(&device->vk);
|
2021-06-01 17:35:27 +01:00
|
|
|
vk_free2(&device->vk.alloc, pAllocator, device);
|
2019-11-25 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
static VkResult
|
|
|
|
device_alloc(struct v3dv_device *device,
|
|
|
|
struct v3dv_device_memory *mem,
|
|
|
|
VkDeviceSize size)
|
|
|
|
{
|
|
|
|
/* Our kernel interface is 32-bit */
|
2021-05-25 09:49:06 +01:00
|
|
|
assert(size <= UINT32_MAX);
|
2020-06-29 10:56:48 +01:00
|
|
|
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
mem->bo = v3dv_bo_alloc(device, size, "device_alloc", false);
|
2019-12-12 10:02:04 +00:00
|
|
|
if (!mem->bo)
|
2019-12-04 09:39:01 +00:00
|
|
|
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
2020-06-29 10:56:48 +01:00
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:20:20 +01:00
|
|
|
static void
|
|
|
|
device_free_wsi_dumb(int32_t display_fd, int32_t dumb_handle)
|
|
|
|
{
|
|
|
|
assert(display_fd != -1);
|
|
|
|
if (dumb_handle < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct drm_mode_destroy_dumb destroy_dumb = {
|
|
|
|
.handle = dumb_handle,
|
|
|
|
};
|
2021-04-21 16:23:57 +01:00
|
|
|
if (v3dv_ioctl(display_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb)) {
|
|
|
|
fprintf(stderr, "destroy dumb object %d: %s\n", dumb_handle, strerror(errno));
|
|
|
|
}
|
2020-09-11 11:20:20 +01:00
|
|
|
}
|
|
|
|
|
2019-12-04 09:58:05 +00:00
|
|
|
static void
|
|
|
|
device_free(struct v3dv_device *device, struct v3dv_device_memory *mem)
|
|
|
|
{
|
2020-09-11 11:20:20 +01:00
|
|
|
/* If this memory allocation was for WSI, then we need to use the
|
|
|
|
* display device to free the allocated dumb BO.
|
|
|
|
*/
|
|
|
|
if (mem->is_for_wsi) {
|
|
|
|
device_free_wsi_dumb(device->instance->physicalDevice.display_fd,
|
|
|
|
mem->bo->dumb_handle);
|
|
|
|
}
|
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
v3dv_bo_free(device, mem->bo);
|
2019-12-04 09:58:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 11:56:34 +00:00
|
|
|
static void
|
|
|
|
device_unmap(struct v3dv_device *device, struct v3dv_device_memory *mem)
|
|
|
|
{
|
|
|
|
assert(mem && mem->bo->map && mem->bo->map_size > 0);
|
|
|
|
v3dv_bo_unmap(device, mem->bo);
|
|
|
|
}
|
|
|
|
|
2019-12-04 11:21:35 +00:00
|
|
|
static VkResult
|
2020-06-17 11:15:42 +01:00
|
|
|
device_map(struct v3dv_device *device, struct v3dv_device_memory *mem)
|
2019-12-04 11:21:35 +00:00
|
|
|
{
|
2020-03-11 11:56:34 +00:00
|
|
|
assert(mem && mem->bo);
|
|
|
|
|
2019-12-04 11:21:35 +00:00
|
|
|
/* From the spec:
|
|
|
|
*
|
|
|
|
* "After a successful call to vkMapMemory the memory object memory is
|
|
|
|
* considered to be currently host mapped. It is an application error to
|
|
|
|
* call vkMapMemory on a memory object that is already host mapped."
|
2020-03-11 11:56:34 +00:00
|
|
|
*
|
|
|
|
* We are not concerned with this ourselves (validation layers should
|
|
|
|
* catch these errors and warn users), however, the driver may internally
|
2020-06-17 11:15:42 +01:00
|
|
|
* map things (for example for debug CLIF dumps or some CPU-side operations)
|
|
|
|
* so by the time the user calls here the buffer might already been mapped
|
|
|
|
* internally by the driver.
|
2019-12-04 11:21:35 +00:00
|
|
|
*/
|
2020-06-17 11:15:42 +01:00
|
|
|
if (mem->bo->map) {
|
|
|
|
assert(mem->bo->map_size == mem->bo->size);
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2019-12-04 11:21:35 +00:00
|
|
|
|
2020-06-17 11:15:42 +01:00
|
|
|
bool ok = v3dv_bo_map(device, mem->bo, mem->bo->size);
|
2019-12-10 11:00:49 +00:00
|
|
|
if (!ok)
|
2019-12-04 11:21:35 +00:00
|
|
|
return VK_ERROR_MEMORY_MAP_FAILED;
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-01-15 10:32:09 +00:00
|
|
|
static VkResult
|
|
|
|
device_import_bo(struct v3dv_device *device,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
int fd, uint64_t size,
|
|
|
|
struct v3dv_bo **bo)
|
|
|
|
{
|
2022-01-04 11:56:42 +00:00
|
|
|
*bo = NULL;
|
2020-01-15 10:32:09 +00:00
|
|
|
|
|
|
|
off_t real_size = lseek(fd, 0, SEEK_END);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2022-01-04 11:56:42 +00:00
|
|
|
if (real_size < 0 || (uint64_t) real_size < size)
|
|
|
|
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
2020-01-15 10:32:09 +00:00
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
int render_fd = device->pdevice->render_fd;
|
|
|
|
assert(render_fd >= 0);
|
|
|
|
|
2020-01-15 10:32:09 +00:00
|
|
|
int ret;
|
|
|
|
uint32_t handle;
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
ret = drmPrimeFDToHandle(render_fd, fd, &handle);
|
2022-01-04 11:56:42 +00:00
|
|
|
if (ret)
|
|
|
|
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
2020-01-15 10:32:09 +00:00
|
|
|
|
|
|
|
struct drm_v3d_get_bo_offset get_offset = {
|
|
|
|
.handle = handle,
|
|
|
|
};
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
ret = v3dv_ioctl(render_fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get_offset);
|
2022-01-04 11:56:42 +00:00
|
|
|
if (ret)
|
|
|
|
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
2020-01-15 10:32:09 +00:00
|
|
|
assert(get_offset.offset != 0);
|
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
*bo = v3dv_device_lookup_bo(device->pdevice, handle);
|
|
|
|
assert(*bo);
|
2020-01-15 10:32:09 +00:00
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
if ((*bo)->refcnt == 0)
|
|
|
|
v3dv_bo_init(*bo, handle, size, get_offset.offset, "import", false);
|
|
|
|
else
|
|
|
|
p_atomic_inc(&(*bo)->refcnt);
|
2020-01-15 10:32:09 +00:00
|
|
|
|
2022-01-04 11:56:42 +00:00
|
|
|
return VK_SUCCESS;
|
2020-01-15 10:32:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 10:24:05 +00:00
|
|
|
static VkResult
|
|
|
|
device_alloc_for_wsi(struct v3dv_device *device,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
struct v3dv_device_memory *mem,
|
|
|
|
VkDeviceSize size)
|
|
|
|
{
|
|
|
|
/* In the simulator we can get away with a regular allocation since both
|
|
|
|
* allocation and rendering happen in the same DRM render node. On actual
|
|
|
|
* hardware we need to allocate our winsys BOs on the vc4 display device
|
|
|
|
* and import them into v3d.
|
|
|
|
*/
|
|
|
|
#if using_v3d_simulator
|
|
|
|
return device_alloc(device, mem, size);
|
|
|
|
#else
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
/* If we are allocating for WSI we should have a swapchain and thus,
|
|
|
|
* we should've initialized the display device. However, Zink doesn't
|
|
|
|
* use swapchains, so in that case we can get here without acquiring the
|
|
|
|
* display device and we need to do it now.
|
|
|
|
*/
|
|
|
|
VkResult result;
|
|
|
|
struct v3dv_instance *instance = device->instance;
|
|
|
|
struct v3dv_physical_device *pdevice = &device->instance->physicalDevice;
|
|
|
|
if (unlikely(pdevice->display_fd < 0)) {
|
2020-11-16 08:50:22 +00:00
|
|
|
result = v3dv_physical_device_acquire_display(instance, pdevice, NULL);
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
assert(pdevice->display_fd != -1);
|
|
|
|
|
2020-09-11 11:20:20 +01:00
|
|
|
mem->is_for_wsi = true;
|
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
int display_fd = pdevice->display_fd;
|
2020-01-23 10:24:05 +00:00
|
|
|
struct drm_mode_create_dumb create_dumb = {
|
|
|
|
.width = 1024, /* one page */
|
|
|
|
.height = align(size, 4096) / 4096,
|
|
|
|
.bpp = util_format_get_blocksizebits(PIPE_FORMAT_RGBA8888_UNORM),
|
|
|
|
};
|
|
|
|
|
|
|
|
int err;
|
|
|
|
err = v3dv_ioctl(display_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail_create;
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
err =
|
|
|
|
drmPrimeHandleToFD(display_fd, create_dumb.handle, O_CLOEXEC, &fd);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail_export;
|
|
|
|
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
result = device_import_bo(device, pAllocator, fd, size, &mem->bo);
|
2020-01-23 10:24:05 +00:00
|
|
|
close(fd);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
goto fail_import;
|
|
|
|
|
2020-09-11 11:20:20 +01:00
|
|
|
mem->bo->dumb_handle = create_dumb.handle;
|
2020-01-23 10:24:05 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
fail_import:
|
2020-09-11 11:20:20 +01:00
|
|
|
fail_export:
|
|
|
|
device_free_wsi_dumb(display_fd, create_dumb.handle);
|
2020-01-23 10:24:05 +00:00
|
|
|
|
|
|
|
fail_create:
|
|
|
|
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-27 13:12:25 +01:00
|
|
|
static void
|
|
|
|
device_add_device_address_bo(struct v3dv_device *device,
|
|
|
|
struct v3dv_bo *bo)
|
|
|
|
{
|
|
|
|
util_dynarray_append(&device->device_address_bo_list,
|
|
|
|
struct v3dv_bo *,
|
|
|
|
bo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_remove_device_address_bo(struct v3dv_device *device,
|
|
|
|
struct v3dv_bo *bo)
|
|
|
|
{
|
|
|
|
util_dynarray_delete_unordered(&device->device_address_bo_list,
|
|
|
|
struct v3dv_bo *,
|
|
|
|
bo);
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_AllocateMemory(VkDevice _device,
|
|
|
|
const VkMemoryAllocateInfo *pAllocateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkDeviceMemory *pMem)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_device_memory *mem;
|
2019-12-04 09:39:01 +00:00
|
|
|
struct v3dv_physical_device *pdevice = &device->instance->physicalDevice;
|
2019-11-27 21:08:51 +00:00
|
|
|
|
|
|
|
assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
|
|
|
|
|
|
|
|
/* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
|
|
|
|
assert(pAllocateInfo->allocationSize > 0);
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
mem = vk_object_zalloc(&device->vk, pAllocator, sizeof(*mem),
|
|
|
|
VK_OBJECT_TYPE_DEVICE_MEMORY);
|
2019-11-27 21:08:51 +00:00
|
|
|
if (mem == NULL)
|
|
|
|
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
assert(pAllocateInfo->memoryTypeIndex < pdevice->memory.memoryTypeCount);
|
|
|
|
mem->type = &pdevice->memory.memoryTypes[pAllocateInfo->memoryTypeIndex];
|
2020-09-11 11:20:20 +01:00
|
|
|
mem->is_for_wsi = false;
|
2019-11-27 21:08:51 +00:00
|
|
|
|
2020-01-23 10:24:05 +00:00
|
|
|
const struct wsi_memory_allocate_info *wsi_info = NULL;
|
2020-01-15 10:32:09 +00:00
|
|
|
const VkImportMemoryFdInfoKHR *fd_info = NULL;
|
2022-06-27 13:12:25 +01:00
|
|
|
const VkMemoryAllocateFlagsInfo *flags_info = NULL;
|
2020-01-15 10:32:09 +00:00
|
|
|
vk_foreach_struct_const(ext, pAllocateInfo->pNext) {
|
2020-01-23 10:24:05 +00:00
|
|
|
switch ((unsigned)ext->sType) {
|
|
|
|
case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA:
|
|
|
|
wsi_info = (void *)ext;
|
|
|
|
break;
|
2020-01-15 10:32:09 +00:00
|
|
|
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
|
|
|
|
fd_info = (void *)ext;
|
|
|
|
break;
|
2021-05-27 08:16:18 +01:00
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO:
|
2022-06-27 13:12:25 +01:00
|
|
|
flags_info = (void *)ext;
|
2021-05-27 08:16:18 +01:00
|
|
|
break;
|
2022-07-01 13:04:28 +01:00
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
|
2021-05-26 08:14:02 +01:00
|
|
|
/* We don't have particular optimizations associated with memory
|
|
|
|
* allocations that won't be suballocated to multiple resources.
|
|
|
|
*/
|
|
|
|
break;
|
2022-07-01 13:04:28 +01:00
|
|
|
case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO:
|
2021-05-26 09:45:31 +01:00
|
|
|
/* The mask of handle types specified here must be supported
|
|
|
|
* according to VkExternalImageFormatProperties, so it must be
|
|
|
|
* fd or dmabuf, which don't have special requirements for us.
|
|
|
|
*/
|
|
|
|
break;
|
2020-01-15 10:32:09 +00:00
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VkResult result = VK_SUCCESS;
|
2021-05-25 09:49:06 +01:00
|
|
|
|
|
|
|
/* We always allocate device memory in multiples of a page, so round up
|
|
|
|
* requested size to that.
|
|
|
|
*/
|
|
|
|
VkDeviceSize alloc_size = ALIGN(pAllocateInfo->allocationSize, 4096);
|
|
|
|
|
|
|
|
if (unlikely(alloc_size > MAX_MEMORY_ALLOCATION_SIZE)) {
|
|
|
|
result = VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
2020-01-15 10:32:09 +00:00
|
|
|
} else {
|
2021-05-25 09:49:06 +01:00
|
|
|
if (wsi_info) {
|
|
|
|
result = device_alloc_for_wsi(device, pAllocator, mem, alloc_size);
|
|
|
|
} else if (fd_info && fd_info->handleType) {
|
|
|
|
assert(fd_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
|
|
|
fd_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
|
|
|
result = device_import_bo(device, pAllocator,
|
|
|
|
fd_info->fd, alloc_size, &mem->bo);
|
|
|
|
if (result == VK_SUCCESS)
|
|
|
|
close(fd_info->fd);
|
|
|
|
} else {
|
|
|
|
result = device_alloc(device, mem, alloc_size);
|
|
|
|
}
|
2020-01-15 10:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, mem);
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, result);
|
2020-01-15 10:32:09 +00:00
|
|
|
}
|
2019-11-27 21:08:51 +00:00
|
|
|
|
2022-06-27 13:12:25 +01:00
|
|
|
/* If this memory can be used via VK_KHR_buffer_device_address then we
|
|
|
|
* will need to manually add the BO to any job submit that makes use of
|
|
|
|
* VK_KHR_buffer_device_address, since such jobs may produde buffer
|
|
|
|
* load/store operations that may access any buffer memory allocated with
|
|
|
|
* this flag and we don't have any means to tell which buffers will be
|
|
|
|
* accessed through this mechanism since they don't even have to be bound
|
|
|
|
* through descriptor state.
|
|
|
|
*/
|
|
|
|
if (flags_info &&
|
|
|
|
(flags_info->flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR)) {
|
|
|
|
mem->is_for_device_address = true;
|
|
|
|
device_add_device_address_bo(device, mem->bo);
|
|
|
|
}
|
|
|
|
|
2019-12-04 09:39:01 +00:00
|
|
|
*pMem = v3dv_device_memory_to_handle(mem);
|
|
|
|
return result;
|
2019-11-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_FreeMemory(VkDevice _device,
|
|
|
|
VkDeviceMemory _mem,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, _mem);
|
|
|
|
|
|
|
|
if (mem == NULL)
|
|
|
|
return;
|
|
|
|
|
2019-12-12 10:02:04 +00:00
|
|
|
if (mem->bo->map)
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_UnmapMemory(_device, _mem);
|
|
|
|
|
2022-06-27 13:12:25 +01:00
|
|
|
if (mem->is_for_device_address)
|
|
|
|
device_remove_device_address_bo(device, mem->bo);
|
|
|
|
|
2019-12-04 09:58:05 +00:00
|
|
|
device_free(device, mem);
|
2019-11-27 21:08:51 +00:00
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, mem);
|
2019-11-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_MapMemory(VkDevice _device,
|
|
|
|
VkDeviceMemory _memory,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize size,
|
|
|
|
VkMemoryMapFlags flags,
|
|
|
|
void **ppData)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, _memory);
|
|
|
|
|
|
|
|
if (mem == NULL) {
|
|
|
|
*ppData = NULL;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-12-12 10:02:04 +00:00
|
|
|
assert(offset < mem->bo->size);
|
2019-12-04 11:21:35 +00:00
|
|
|
|
2020-06-17 11:15:42 +01:00
|
|
|
/* Since the driver can map BOs internally as well and the mapped range
|
|
|
|
* required by the user or the driver might not be the same, we always map
|
|
|
|
* the entire BO and then add the requested offset to the start address
|
|
|
|
* of the mapped region.
|
2019-12-04 11:21:35 +00:00
|
|
|
*/
|
2020-06-17 11:15:42 +01:00
|
|
|
VkResult result = device_map(device, mem);
|
2019-12-04 11:21:35 +00:00
|
|
|
if (result != VK_SUCCESS)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, result);
|
2019-11-27 21:08:51 +00:00
|
|
|
|
2019-12-12 10:02:04 +00:00
|
|
|
*ppData = ((uint8_t *) mem->bo->map) + offset;
|
2019-12-04 11:21:35 +00:00
|
|
|
return VK_SUCCESS;
|
2019-11-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_UnmapMemory(VkDevice _device,
|
|
|
|
VkDeviceMemory _memory)
|
|
|
|
{
|
2019-12-04 11:29:00 +00:00
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, _memory);
|
|
|
|
|
|
|
|
if (mem == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_unmap(device, mem);
|
2019-11-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_FlushMappedMemoryRanges(VkDevice _device,
|
|
|
|
uint32_t memoryRangeCount,
|
|
|
|
const VkMappedMemoryRange *pMemoryRanges)
|
|
|
|
{
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-11-27 21:08:51 +00:00
|
|
|
v3dv_InvalidateMappedMemoryRanges(VkDevice _device,
|
|
|
|
uint32_t memoryRangeCount,
|
|
|
|
const VkMappedMemoryRange *pMemoryRanges)
|
|
|
|
{
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2019-12-04 08:24:03 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2021-05-26 08:34:04 +01:00
|
|
|
v3dv_GetImageMemoryRequirements2(VkDevice device,
|
|
|
|
const VkImageMemoryRequirementsInfo2 *pInfo,
|
|
|
|
VkMemoryRequirements2 *pMemoryRequirements)
|
2019-12-04 08:24:03 +00:00
|
|
|
{
|
2021-05-26 08:34:04 +01:00
|
|
|
V3DV_FROM_HANDLE(v3dv_image, image, pInfo->image);
|
2019-12-04 08:24:03 +00:00
|
|
|
|
2021-05-26 08:34:04 +01:00
|
|
|
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
|
|
|
.memoryTypeBits = 0x1,
|
|
|
|
.alignment = image->alignment,
|
|
|
|
.size = image->size
|
|
|
|
};
|
2019-12-04 08:24:03 +00:00
|
|
|
|
2021-05-26 08:34:04 +01:00
|
|
|
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
|
|
|
switch (ext->sType) {
|
2021-05-26 08:14:02 +01:00
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
|
|
|
|
VkMemoryDedicatedRequirements *req =
|
|
|
|
(VkMemoryDedicatedRequirements *) ext;
|
2021-07-26 11:06:17 +01:00
|
|
|
req->requiresDedicatedAllocation = image->vk.external_handle_types != 0;
|
|
|
|
req->prefersDedicatedAllocation = image->vk.external_handle_types != 0;
|
2021-05-26 08:14:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-05-26 08:34:04 +01:00
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 08:24:03 +00:00
|
|
|
}
|
2019-12-05 09:36:24 +00:00
|
|
|
|
2021-05-25 12:21:55 +01:00
|
|
|
static void
|
|
|
|
bind_image_memory(const VkBindImageMemoryInfo *info)
|
2019-12-05 09:36:24 +00:00
|
|
|
{
|
2021-05-25 12:21:55 +01:00
|
|
|
V3DV_FROM_HANDLE(v3dv_image, image, info->image);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, info->memory);
|
2019-12-05 09:36:24 +00:00
|
|
|
|
|
|
|
/* Valid usage:
|
|
|
|
*
|
|
|
|
* "memoryOffset must be an integer multiple of the alignment member of
|
|
|
|
* the VkMemoryRequirements structure returned from a call to
|
|
|
|
* vkGetImageMemoryRequirements with image"
|
|
|
|
*/
|
2021-05-25 12:21:55 +01:00
|
|
|
assert(info->memoryOffset % image->alignment == 0);
|
|
|
|
assert(info->memoryOffset < mem->bo->size);
|
2019-12-05 09:36:24 +00:00
|
|
|
|
|
|
|
image->mem = mem;
|
2021-05-25 12:21:55 +01:00
|
|
|
image->mem_offset = info->memoryOffset;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2021-05-25 12:21:55 +01:00
|
|
|
v3dv_BindImageMemory2(VkDevice _device,
|
|
|
|
uint32_t bindInfoCount,
|
|
|
|
const VkBindImageMemoryInfo *pBindInfos)
|
|
|
|
{
|
2021-05-27 09:17:08 +01:00
|
|
|
for (uint32_t i = 0; i < bindInfoCount; i++) {
|
|
|
|
const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
|
|
|
|
vk_find_struct_const(pBindInfos->pNext,
|
|
|
|
BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR);
|
|
|
|
if (swapchain_info && swapchain_info->swapchain) {
|
|
|
|
struct v3dv_image *swapchain_image =
|
|
|
|
v3dv_wsi_get_image_from_swapchain(swapchain_info->swapchain,
|
|
|
|
swapchain_info->imageIndex);
|
|
|
|
VkBindImageMemoryInfo swapchain_bind = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
|
|
|
|
.image = pBindInfos[i].image,
|
|
|
|
.memory = v3dv_device_memory_to_handle(swapchain_image->mem),
|
|
|
|
.memoryOffset = swapchain_image->mem_offset,
|
|
|
|
};
|
|
|
|
bind_image_memory(&swapchain_bind);
|
|
|
|
} else {
|
|
|
|
bind_image_memory(&pBindInfos[i]);
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 09:36:24 +00:00
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2019-12-09 09:07:36 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2021-05-26 08:34:04 +01:00
|
|
|
v3dv_GetBufferMemoryRequirements2(VkDevice device,
|
|
|
|
const VkBufferMemoryRequirementsInfo2 *pInfo,
|
|
|
|
VkMemoryRequirements2 *pMemoryRequirements)
|
2019-12-09 09:35:03 +00:00
|
|
|
{
|
2021-05-26 08:34:04 +01:00
|
|
|
V3DV_FROM_HANDLE(v3dv_buffer, buffer, pInfo->buffer);
|
|
|
|
|
|
|
|
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
|
|
|
.memoryTypeBits = 0x1,
|
|
|
|
.alignment = buffer->alignment,
|
|
|
|
.size = align64(buffer->size, buffer->alignment),
|
|
|
|
};
|
2019-12-09 09:35:03 +00:00
|
|
|
|
2021-05-26 08:34:04 +01:00
|
|
|
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
|
|
|
switch (ext->sType) {
|
2021-05-26 08:14:02 +01:00
|
|
|
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
|
|
|
|
VkMemoryDedicatedRequirements *req =
|
|
|
|
(VkMemoryDedicatedRequirements *) ext;
|
|
|
|
req->requiresDedicatedAllocation = false;
|
|
|
|
req->prefersDedicatedAllocation = false;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-26 08:34:04 +01:00
|
|
|
default:
|
|
|
|
v3dv_debug_ignored_stype(ext->sType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 09:35:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 12:21:55 +01:00
|
|
|
static void
|
|
|
|
bind_buffer_memory(const VkBindBufferMemoryInfo *info)
|
2019-12-09 09:40:32 +00:00
|
|
|
{
|
2021-05-25 12:21:55 +01:00
|
|
|
V3DV_FROM_HANDLE(v3dv_buffer, buffer, info->buffer);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, info->memory);
|
2019-12-09 09:40:32 +00:00
|
|
|
|
|
|
|
/* Valid usage:
|
|
|
|
*
|
|
|
|
* "memoryOffset must be an integer multiple of the alignment member of
|
|
|
|
* the VkMemoryRequirements structure returned from a call to
|
|
|
|
* vkGetBufferMemoryRequirements with buffer"
|
|
|
|
*/
|
2021-05-25 12:21:55 +01:00
|
|
|
assert(info->memoryOffset % buffer->alignment == 0);
|
|
|
|
assert(info->memoryOffset < mem->bo->size);
|
2019-12-09 09:40:32 +00:00
|
|
|
|
|
|
|
buffer->mem = mem;
|
2021-05-25 12:21:55 +01:00
|
|
|
buffer->mem_offset = info->memoryOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2021-05-25 12:21:55 +01:00
|
|
|
v3dv_BindBufferMemory2(VkDevice device,
|
|
|
|
uint32_t bindInfoCount,
|
|
|
|
const VkBindBufferMemoryInfo *pBindInfos)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < bindInfoCount; i++)
|
|
|
|
bind_buffer_memory(&pBindInfos[i]);
|
2019-12-09 09:40:32 +00:00
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-12-09 09:07:36 +00:00
|
|
|
v3dv_CreateBuffer(VkDevice _device,
|
|
|
|
const VkBufferCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkBuffer *pBuffer)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_buffer *buffer;
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
|
|
|
|
assert(pCreateInfo->usage != 0);
|
|
|
|
|
|
|
|
/* We don't support any flags for now */
|
|
|
|
assert(pCreateInfo->flags == 0);
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
buffer = vk_object_zalloc(&device->vk, pAllocator, sizeof(*buffer),
|
|
|
|
VK_OBJECT_TYPE_BUFFER);
|
2019-12-09 09:07:36 +00:00
|
|
|
if (buffer == NULL)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2019-12-09 09:07:36 +00:00
|
|
|
|
|
|
|
buffer->size = pCreateInfo->size;
|
|
|
|
buffer->usage = pCreateInfo->usage;
|
v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.
We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.
Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-24 09:05:17 +00:00
|
|
|
buffer->alignment = V3D_NON_COHERENT_ATOM_SIZE;
|
2019-12-09 09:07:36 +00:00
|
|
|
|
2020-06-23 10:32:04 +01:00
|
|
|
/* Limit allocations to 32-bit */
|
|
|
|
const VkDeviceSize aligned_size = align64(buffer->size, buffer->alignment);
|
2022-06-22 10:44:12 +01:00
|
|
|
if (aligned_size > UINT32_MAX || aligned_size < buffer->size) {
|
|
|
|
vk_free(&device->vk.alloc, buffer);
|
2020-06-23 10:32:04 +01:00
|
|
|
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
2022-06-22 10:44:12 +01:00
|
|
|
}
|
2019-12-09 09:07:36 +00:00
|
|
|
|
|
|
|
*pBuffer = v3dv_buffer_to_handle(buffer);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-12-09 09:07:36 +00:00
|
|
|
v3dv_DestroyBuffer(VkDevice _device,
|
|
|
|
VkBuffer _buffer,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_buffer, buffer, _buffer);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return;
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, buffer);
|
2019-12-09 09:07:36 +00:00
|
|
|
}
|
2019-12-09 12:16:16 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2019-12-09 12:16:16 +00:00
|
|
|
v3dv_CreateFramebuffer(VkDevice _device,
|
|
|
|
const VkFramebufferCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkFramebuffer *pFramebuffer)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_framebuffer *framebuffer;
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
|
|
|
|
|
|
|
|
size_t size = sizeof(*framebuffer) +
|
|
|
|
sizeof(struct v3dv_image_view *) * pCreateInfo->attachmentCount;
|
2020-11-12 15:30:41 +00:00
|
|
|
framebuffer = vk_object_zalloc(&device->vk, pAllocator, size,
|
|
|
|
VK_OBJECT_TYPE_FRAMEBUFFER);
|
2019-12-09 12:16:16 +00:00
|
|
|
if (framebuffer == NULL)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2019-12-09 12:16:16 +00:00
|
|
|
|
|
|
|
framebuffer->width = pCreateInfo->width;
|
|
|
|
framebuffer->height = pCreateInfo->height;
|
|
|
|
framebuffer->layers = pCreateInfo->layers;
|
2020-10-08 12:24:13 +01:00
|
|
|
framebuffer->has_edge_padding = true;
|
|
|
|
|
2022-01-24 12:38:08 +00:00
|
|
|
const VkFramebufferAttachmentsCreateInfo *imageless =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
FRAMEBUFFER_ATTACHMENTS_CREATE_INFO);
|
|
|
|
|
2019-12-09 12:16:16 +00:00
|
|
|
framebuffer->attachment_count = pCreateInfo->attachmentCount;
|
2020-01-28 12:03:41 +00:00
|
|
|
framebuffer->color_attachment_count = 0;
|
2022-01-24 12:38:08 +00:00
|
|
|
for (uint32_t i = 0; i < framebuffer->attachment_count; i++) {
|
|
|
|
if (!imageless) {
|
|
|
|
framebuffer->attachments[i] =
|
|
|
|
v3dv_image_view_from_handle(pCreateInfo->pAttachments[i]);
|
|
|
|
if (framebuffer->attachments[i]->vk.aspects & VK_IMAGE_ASPECT_COLOR_BIT)
|
|
|
|
framebuffer->color_attachment_count++;
|
|
|
|
} else {
|
|
|
|
assert(i < imageless->attachmentImageInfoCount);
|
|
|
|
if (imageless->pAttachmentImageInfos[i].usage &
|
|
|
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
|
|
|
|
framebuffer->color_attachment_count++;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 12:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*pFramebuffer = v3dv_framebuffer_to_handle(framebuffer);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2019-12-09 12:16:16 +00:00
|
|
|
v3dv_DestroyFramebuffer(VkDevice _device,
|
|
|
|
VkFramebuffer _fb,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_framebuffer, fb, _fb);
|
|
|
|
|
|
|
|
if (!fb)
|
|
|
|
return;
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, fb);
|
2019-12-09 12:16:16 +00:00
|
|
|
}
|
2020-01-15 10:32:09 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-01-15 10:32:09 +00:00
|
|
|
v3dv_GetMemoryFdPropertiesKHR(VkDevice _device,
|
|
|
|
VkExternalMemoryHandleTypeFlagBits handleType,
|
|
|
|
int fd,
|
|
|
|
VkMemoryFdPropertiesKHR *pMemoryFdProperties)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_physical_device *pdevice = &device->instance->physicalDevice;
|
|
|
|
|
|
|
|
switch (handleType) {
|
|
|
|
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
|
|
|
|
pMemoryFdProperties->memoryTypeBits =
|
|
|
|
(1 << pdevice->memory.memoryTypeCount) - 1;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
default:
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
|
2020-01-15 10:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-01-15 10:32:09 +00:00
|
|
|
v3dv_GetMemoryFdKHR(VkDevice _device,
|
|
|
|
const VkMemoryGetFdInfoKHR *pGetFdInfo,
|
|
|
|
int *pFd)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device_memory, mem, pGetFdInfo->memory);
|
|
|
|
|
|
|
|
assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
|
|
|
|
assert(pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
|
|
|
pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
|
|
|
|
|
|
|
int fd, ret;
|
v3dv: move authenticated display fd acquisition to swapchain creation time
So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.
Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.
Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.
There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.
This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.
Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.
Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>
2020-11-11 08:45:33 +00:00
|
|
|
ret = drmPrimeHandleToFD(device->pdevice->render_fd,
|
|
|
|
mem->bo->handle,
|
|
|
|
DRM_CLOEXEC, &fd);
|
2020-01-15 10:32:09 +00:00
|
|
|
if (ret)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2020-01-15 10:32:09 +00:00
|
|
|
|
|
|
|
*pFd = fd;
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2020-02-26 08:36:27 +00:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-02-26 08:36:27 +00:00
|
|
|
v3dv_CreateEvent(VkDevice _device,
|
|
|
|
const VkEventCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkEvent *pEvent)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_event *event =
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_zalloc(&device->vk, pAllocator, sizeof(*event),
|
|
|
|
VK_OBJECT_TYPE_EVENT);
|
2020-02-26 08:36:27 +00:00
|
|
|
if (!event)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2020-02-26 08:36:27 +00:00
|
|
|
|
|
|
|
/* Events are created in the unsignaled state */
|
2020-05-18 09:41:11 +01:00
|
|
|
event->state = false;
|
2020-02-26 08:36:27 +00:00
|
|
|
*pEvent = v3dv_event_to_handle(event);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-02-26 08:36:27 +00:00
|
|
|
v3dv_DestroyEvent(VkDevice _device,
|
|
|
|
VkEvent _event,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_event, event, _event);
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, event);
|
2020-02-26 08:36:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-02-26 08:36:27 +00:00
|
|
|
v3dv_GetEventStatus(VkDevice _device, VkEvent _event)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_event, event, _event);
|
2020-05-18 09:41:11 +01:00
|
|
|
return p_atomic_read(&event->state) ? VK_EVENT_SET : VK_EVENT_RESET;
|
2020-02-26 08:36:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-02-26 08:36:27 +00:00
|
|
|
v3dv_SetEvent(VkDevice _device, VkEvent _event)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_event, event, _event);
|
2020-05-18 09:41:11 +01:00
|
|
|
p_atomic_set(&event->state, 1);
|
2020-02-26 08:36:27 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-02-26 08:36:27 +00:00
|
|
|
v3dv_ResetEvent(VkDevice _device, VkEvent _event)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_event, event, _event);
|
2020-05-18 09:41:11 +01:00
|
|
|
p_atomic_set(&event->state, 0);
|
2020-02-26 08:36:27 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2020-03-29 15:29:55 +01:00
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2020-03-29 15:29:55 +01:00
|
|
|
v3dv_CreateSampler(VkDevice _device,
|
|
|
|
const VkSamplerCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkSampler *pSampler)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
struct v3dv_sampler *sampler;
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
sampler = vk_object_zalloc(&device->vk, pAllocator, sizeof(*sampler),
|
|
|
|
VK_OBJECT_TYPE_SAMPLER);
|
2020-03-29 15:29:55 +01:00
|
|
|
if (!sampler)
|
2021-09-24 21:31:03 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2020-03-29 15:29:55 +01:00
|
|
|
|
v3dv/descriptor_set: combine texture and sampler indices
OpenGL doesn't have the concept of individual texture and sampler, so
texture and sampler indexes have the same value. v3d compiler uses
this assumption, so for example, the texture info at the v3d key
include values that you need to use the texture format and the sampler
to fill (like the return_size).
One option would be to adapt the v3d compiler to handle both, but then
we would need to adapt to the lowerings it uses, like nir_lower_tex,
that also take the same assumption.
We deal with this on the Vulkan driver, by reassigning the texture and
sampler index to a combined one. We add a hash table to map the
combined texture idx and sampler idx to this combined idx, and a
simple array to the opposite map. On the driver we work with the
separate indices to fill up the data, while the v3d compiler works
with the combined one.
As mentioned, this is needed to properly fill up the texture return
size, so as we are here, we fix that. This gets tests like the
following working:
dEQP-VK.glsl.texture_gather.basic.2d.depth32f.base_level.level_2
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-04-06 23:33:14 +01:00
|
|
|
sampler->compare_enable = pCreateInfo->compareEnable;
|
2020-07-01 13:21:09 +01:00
|
|
|
sampler->unnormalized_coordinates = pCreateInfo->unnormalizedCoordinates;
|
2021-07-28 09:53:00 +01:00
|
|
|
|
|
|
|
const VkSamplerCustomBorderColorCreateInfoEXT *bc_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
|
|
|
|
|
|
|
|
v3dv_X(device, pack_sampler_state)(sampler, pCreateInfo, bc_info);
|
2020-03-29 15:29:55 +01:00
|
|
|
|
|
|
|
*pSampler = v3dv_sampler_to_handle(sampler);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-03-29 15:29:55 +01:00
|
|
|
v3dv_DestroySampler(VkDevice _device,
|
|
|
|
VkSampler _sampler,
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_device, device, _device);
|
|
|
|
V3DV_FROM_HANDLE(v3dv_sampler, sampler, _sampler);
|
|
|
|
|
|
|
|
if (!sampler)
|
|
|
|
return;
|
|
|
|
|
2020-11-12 15:30:41 +00:00
|
|
|
vk_object_free(&device->vk, pAllocator, sampler);
|
2020-03-29 15:29:55 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-06-04 08:03:42 +01:00
|
|
|
v3dv_GetDeviceMemoryCommitment(VkDevice device,
|
|
|
|
VkDeviceMemory memory,
|
|
|
|
VkDeviceSize *pCommittedMemoryInBytes)
|
|
|
|
{
|
|
|
|
*pCommittedMemoryInBytes = 0;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2021-05-27 11:55:33 +01:00
|
|
|
v3dv_GetImageSparseMemoryRequirements(
|
|
|
|
VkDevice device,
|
|
|
|
VkImage image,
|
|
|
|
uint32_t *pSparseMemoryRequirementCount,
|
|
|
|
VkSparseImageMemoryRequirements *pSparseMemoryRequirements)
|
|
|
|
{
|
|
|
|
*pSparseMemoryRequirementCount = 0;
|
|
|
|
}
|
|
|
|
|
2021-05-28 13:53:25 +01:00
|
|
|
VKAPI_ATTR void VKAPI_CALL
|
2020-06-04 08:03:42 +01:00
|
|
|
v3dv_GetImageSparseMemoryRequirements2(
|
|
|
|
VkDevice device,
|
|
|
|
const VkImageSparseMemoryRequirementsInfo2 *pInfo,
|
|
|
|
uint32_t *pSparseMemoryRequirementCount,
|
|
|
|
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements)
|
|
|
|
{
|
|
|
|
*pSparseMemoryRequirementCount = 0;
|
|
|
|
}
|
2020-10-13 22:06:35 +01:00
|
|
|
|
|
|
|
/* vk_icd.h does not declare this function, so we declare it here to
|
|
|
|
* suppress Wmissing-prototypes.
|
|
|
|
*/
|
|
|
|
PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
|
|
|
|
vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion);
|
|
|
|
|
|
|
|
PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
|
|
|
|
vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion)
|
|
|
|
{
|
|
|
|
/* For the full details on loader interface versioning, see
|
|
|
|
* <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
|
|
|
|
* What follows is a condensed summary, to help you navigate the large and
|
|
|
|
* confusing official doc.
|
|
|
|
*
|
|
|
|
* - Loader interface v0 is incompatible with later versions. We don't
|
|
|
|
* support it.
|
|
|
|
*
|
|
|
|
* - In loader interface v1:
|
|
|
|
* - The first ICD entrypoint called by the loader is
|
|
|
|
* vk_icdGetInstanceProcAddr(). The ICD must statically expose this
|
|
|
|
* entrypoint.
|
|
|
|
* - The ICD must statically expose no other Vulkan symbol unless it is
|
|
|
|
* linked with -Bsymbolic.
|
|
|
|
* - Each dispatchable Vulkan handle created by the ICD must be
|
|
|
|
* a pointer to a struct whose first member is VK_LOADER_DATA. The
|
|
|
|
* ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
|
|
|
|
* - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
|
|
|
|
* vkDestroySurfaceKHR(). The ICD must be capable of working with
|
|
|
|
* such loader-managed surfaces.
|
|
|
|
*
|
|
|
|
* - Loader interface v2 differs from v1 in:
|
|
|
|
* - The first ICD entrypoint called by the loader is
|
|
|
|
* vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
|
|
|
|
* statically expose this entrypoint.
|
|
|
|
*
|
|
|
|
* - Loader interface v3 differs from v2 in:
|
|
|
|
* - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
|
|
|
|
* vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
|
|
|
|
* because the loader no longer does so.
|
|
|
|
*
|
|
|
|
* - Loader interface v4 differs from v3 in:
|
|
|
|
* - The ICD must implement vk_icdGetPhysicalDeviceProcAddr().
|
2022-01-14 18:14:39 +00:00
|
|
|
*
|
|
|
|
* - Loader interface v5 differs from v4 in:
|
|
|
|
* - The ICD must support Vulkan API version 1.1 and must not return
|
|
|
|
* VK_ERROR_INCOMPATIBLE_DRIVER from vkCreateInstance() unless a
|
|
|
|
* Vulkan Loader with interface v4 or smaller is being used and the
|
|
|
|
* application provides an API version that is greater than 1.0.
|
2020-10-13 22:06:35 +01:00
|
|
|
*/
|
2022-01-14 18:14:39 +00:00
|
|
|
*pSupportedVersion = MIN2(*pSupportedVersion, 5u);
|
2020-10-13 22:06:35 +01:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2022-06-27 13:12:25 +01:00
|
|
|
|
|
|
|
VkDeviceAddress
|
|
|
|
v3dv_GetBufferDeviceAddress(VkDevice device,
|
|
|
|
const VkBufferDeviceAddressInfoKHR *pInfo)
|
|
|
|
{
|
|
|
|
V3DV_FROM_HANDLE(v3dv_buffer, buffer, pInfo->buffer);
|
|
|
|
return buffer->mem_offset + buffer->mem->bo->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
v3dv_GetBufferOpaqueCaptureAddress(VkDevice device,
|
|
|
|
const VkBufferDeviceAddressInfoKHR *pInfo)
|
|
|
|
{
|
|
|
|
/* Not implemented */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
v3dv_GetDeviceMemoryOpaqueCaptureAddress(
|
|
|
|
VkDevice device,
|
|
|
|
const VkDeviceMemoryOpaqueCaptureAddressInfoKHR *pInfo)
|
|
|
|
{
|
|
|
|
/* Not implemented */
|
|
|
|
return 0;
|
|
|
|
}
|