comp: Only use dedicated allocation when supported/preferred

Fixes OpenGL depth formats on Tegra
This commit is contained in:
Christoph Haag 2021-08-06 13:48:33 +02:00
parent b4145a1543
commit 1b179306dc
12 changed files with 42 additions and 7 deletions

View file

@ -893,6 +893,8 @@ vk_get_device_functions(struct vk_bundle *vk)
vk->vkFlushMappedMemoryRanges = GET_DEV_PROC(vk, vkFlushMappedMemoryRanges); vk->vkFlushMappedMemoryRanges = GET_DEV_PROC(vk, vkFlushMappedMemoryRanges);
vk->vkCreateImage = GET_DEV_PROC(vk, vkCreateImage); vk->vkCreateImage = GET_DEV_PROC(vk, vkCreateImage);
vk->vkGetImageMemoryRequirements = GET_DEV_PROC(vk, vkGetImageMemoryRequirements); vk->vkGetImageMemoryRequirements = GET_DEV_PROC(vk, vkGetImageMemoryRequirements);
// because we use Vulkan API Version 1.0.x, we can only get the KHR version of this function
vk->vkGetImageMemoryRequirements2 = GET_DEV_PROC(vk, vkGetImageMemoryRequirements2KHR);
vk->vkBindImageMemory = GET_DEV_PROC(vk, vkBindImageMemory); vk->vkBindImageMemory = GET_DEV_PROC(vk, vkBindImageMemory);
vk->vkDestroyImage = GET_DEV_PROC(vk, vkDestroyImage); vk->vkDestroyImage = GET_DEV_PROC(vk, vkDestroyImage);
vk->vkCreateImageView = GET_DEV_PROC(vk, vkCreateImageView); vk->vkCreateImageView = GET_DEV_PROC(vk, vkCreateImageView);

View file

@ -150,6 +150,7 @@ struct vk_bundle
PFN_vkCreateImage vkCreateImage; PFN_vkCreateImage vkCreateImage;
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2;
PFN_vkBindImageMemory vkBindImageMemory; PFN_vkBindImageMemory vkBindImageMemory;
PFN_vkDestroyImage vkDestroyImage; PFN_vkDestroyImage vkDestroyImage;
PFN_vkCreateImageView vkCreateImageView; PFN_vkCreateImageView vkCreateImageView;

View file

@ -204,6 +204,24 @@ create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info,
return ret; return ret;
} }
VkImageMemoryRequirementsInfo2 memory_requirements_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
.image = image,
};
VkMemoryDedicatedRequirements memory_dedicated_requirements = {
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
};
VkMemoryRequirements2 memory_requirements = {
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
.pNext = &memory_dedicated_requirements,
};
vk->vkGetImageMemoryRequirements2(vk->device, &memory_requirements_info, &memory_requirements);
VkBool32 use_dedicated_allocation = (memory_dedicated_requirements.requiresDedicatedAllocation != VK_FALSE) ||
(memory_dedicated_requirements.prefersDedicatedAllocation != VK_FALSE);
U_LOG_D("create_image: Use dedicated allocation: %d", use_dedicated_allocation);
/* /*
* Create and bind the memory. * Create and bind the memory.
*/ */
@ -218,7 +236,7 @@ create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info,
VkExportMemoryAllocateInfo export_alloc_info = { VkExportMemoryAllocateInfo export_alloc_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
.pNext = &dedicated_memory_info, .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
}; };
@ -226,7 +244,7 @@ create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info,
VkExportMemoryAllocateInfo export_alloc_info = { VkExportMemoryAllocateInfo export_alloc_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
.pNext = &dedicated_memory_info, .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID, .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
}; };
@ -234,7 +252,7 @@ create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info,
VkExportMemoryAllocateInfo export_alloc_info = { VkExportMemoryAllocateInfo export_alloc_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
.pNext = &dedicated_memory_info, .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR, .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR,
}; };
@ -252,6 +270,7 @@ create_image(struct vk_bundle *vk, const struct xrt_swapchain_create_info *info,
out_image->handle = image; out_image->handle = image;
out_image->memory = device_memory; out_image->memory = device_memory;
out_image->size = size; out_image->size = size;
out_image->use_dedicated_allocation = use_dedicated_allocation;
return ret; return ret;
} }

View file

@ -28,6 +28,7 @@ struct vk_image
VkImage handle; VkImage handle;
VkDeviceMemory memory; VkDeviceMemory memory;
VkDeviceSize size; VkDeviceSize size;
bool use_dedicated_allocation;
}; };
struct vk_image_collection struct vk_image_collection

View file

@ -96,7 +96,7 @@ client_gl_memobj_swapchain_create(struct xrt_compositor *xc,
glCreateMemoryObjectsEXT(native_xsc->num_images, &sc->memory[0]); glCreateMemoryObjectsEXT(native_xsc->num_images, &sc->memory[0]);
for (uint32_t i = 0; i < native_xsc->num_images; i++) { for (uint32_t i = 0; i < native_xsc->num_images; i++) {
GLint dedicated = GL_TRUE; GLint dedicated = xscn->images[i].use_dedicated_allocation ? GL_TRUE : GL_FALSE;
glMemoryObjectParameterivEXT(sc->memory[i], GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated); glMemoryObjectParameterivEXT(sc->memory[i], GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
glImportMemoryFdEXT(sc->memory[i], xscn->images[i].size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, glImportMemoryFdEXT(sc->memory[i], xscn->images[i].size, GL_HANDLE_TYPE_OPAQUE_FD_EXT,
xscn->images[i].handle); xscn->images[i].handle);

View file

@ -327,6 +327,7 @@ comp_swapchain_create(struct xrt_compositor *xc,
for (uint32_t i = 0; i < sc->vkic.num_images; i++) { for (uint32_t i = 0; i < sc->vkic.num_images; i++) {
sc->base.images[i].handle = handles[i]; sc->base.images[i].handle = handles[i];
sc->base.images[i].size = sc->vkic.images[i].size; sc->base.images[i].size = sc->vkic.images[i].size;
sc->base.images[i].use_dedicated_allocation = sc->vkic.images[i].use_dedicated_allocation;
} }
do_post_create_vulkan_setup(c, info, sc); do_post_create_vulkan_setup(c, info, sc);

View file

@ -1370,6 +1370,8 @@ struct xrt_image_native
* into Vulkan. * into Vulkan.
*/ */
size_t size; size_t size;
bool use_dedicated_allocation;
}; };
/*! /*!

View file

@ -207,12 +207,14 @@ swapchain_server_create(struct ipc_client_compositor *icc,
uint32_t handle; uint32_t handle;
uint32_t num_images; uint32_t num_images;
uint64_t size; uint64_t size;
bool use_dedicated_allocation;
r = ipc_call_swapchain_create(icc->ipc_c, // connection r = ipc_call_swapchain_create(icc->ipc_c, // connection
info, // in info, // in
&handle, // out &handle, // out
&num_images, // out &num_images, // out
&size, // out &size, // out
&use_dedicated_allocation, // out
remote_handles, // handles remote_handles, // handles
IPC_MAX_SWAPCHAIN_HANDLES); // handles IPC_MAX_SWAPCHAIN_HANDLES); // handles
if (r != XRT_SUCCESS) { if (r != XRT_SUCCESS) {
@ -232,6 +234,7 @@ swapchain_server_create(struct ipc_client_compositor *icc,
for (uint32_t i = 0; i < num_images; i++) { for (uint32_t i = 0; i < num_images; i++) {
ics->base.images[i].handle = remote_handles[i]; ics->base.images[i].handle = remote_handles[i];
ics->base.images[i].size = size; ics->base.images[i].size = size;
ics->base.images[i].use_dedicated_allocation = use_dedicated_allocation;
} }
*out_xsc = &ics->base.base; *out_xsc = &ics->base.base;

View file

@ -679,6 +679,7 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *ics,
uint32_t *out_id, uint32_t *out_id,
uint32_t *out_num_images, uint32_t *out_num_images,
uint64_t *out_size, uint64_t *out_size,
bool *out_use_dedicated_allocation,
uint32_t max_num_handles, uint32_t max_num_handles,
xrt_graphics_buffer_handle_t *out_handles, xrt_graphics_buffer_handle_t *out_handles,
uint32_t *out_num_handles) uint32_t *out_num_handles)
@ -718,6 +719,8 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *ics,
*out_id = index; *out_id = index;
*out_size = xscn->images[0].size; *out_size = xscn->images[0].size;
*out_num_images = xsc->num_images; *out_num_images = xsc->num_images;
// assuming all images allocated in the same swapchain have the same allocation requirements
*out_use_dedicated_allocation = xscn->images[0].use_dedicated_allocation;
// Setup the fds. // Setup the fds.
*out_num_handles = xsc->num_images; *out_num_handles = xsc->num_images;

View file

@ -55,7 +55,8 @@ class Arg:
# Keep all these synchronized with the definitions in the JSON Schema. # Keep all these synchronized with the definitions in the JSON Schema.
SCALAR_TYPES = set(("uint32_t", SCALAR_TYPES = set(("uint32_t",
"int64_t", "int64_t",
"uint64_t")) "uint64_t",
"bool"))
AGGREGATE_RE = re.compile(r"((const )?struct|union) (xrt|ipc)_[a-z_]+") AGGREGATE_RE = re.compile(r"((const )?struct|union) (xrt|ipc)_[a-z_]+")
ENUM_RE = re.compile(r"enum xrt_[a-z_]+") ENUM_RE = re.compile(r"enum xrt_[a-z_]+")

View file

@ -125,7 +125,8 @@
"out": [ "out": [
{"name": "id", "type": "uint32_t"}, {"name": "id", "type": "uint32_t"},
{"name": "num_images", "type": "uint32_t"}, {"name": "num_images", "type": "uint32_t"},
{"name": "size", "type": "uint64_t"} {"name": "size", "type": "uint64_t"},
{"name": "use_dedicated_allocation", "type": "bool"}
], ],
"out_handles": {"type": "xrt_graphics_buffer_handle_t"} "out_handles": {"type": "xrt_graphics_buffer_handle_t"}
}, },

View file

@ -12,7 +12,8 @@
"enum": [ "enum": [
"uint32_t", "uint32_t",
"int64_t", "int64_t",
"uint64_t" "uint64_t",
"bool"
] ]
}, },
"aggregate": { "aggregate": {