The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

comp: Only use dedicated allocation when supported/preferred

Fixes OpenGL depth formats on Tegra

+42 -7
+2
src/xrt/auxiliary/vk/vk_helpers.c
··· 893 893 vk->vkFlushMappedMemoryRanges = GET_DEV_PROC(vk, vkFlushMappedMemoryRanges); 894 894 vk->vkCreateImage = GET_DEV_PROC(vk, vkCreateImage); 895 895 vk->vkGetImageMemoryRequirements = GET_DEV_PROC(vk, vkGetImageMemoryRequirements); 896 + // because we use Vulkan API Version 1.0.x, we can only get the KHR version of this function 897 + vk->vkGetImageMemoryRequirements2 = GET_DEV_PROC(vk, vkGetImageMemoryRequirements2KHR); 896 898 vk->vkBindImageMemory = GET_DEV_PROC(vk, vkBindImageMemory); 897 899 vk->vkDestroyImage = GET_DEV_PROC(vk, vkDestroyImage); 898 900 vk->vkCreateImageView = GET_DEV_PROC(vk, vkCreateImageView);
+1
src/xrt/auxiliary/vk/vk_helpers.h
··· 150 150 151 151 PFN_vkCreateImage vkCreateImage; 152 152 PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; 153 + PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2; 153 154 PFN_vkBindImageMemory vkBindImageMemory; 154 155 PFN_vkDestroyImage vkDestroyImage; 155 156 PFN_vkCreateImageView vkCreateImageView;
+22 -3
src/xrt/auxiliary/vk/vk_image_allocator.c
··· 204 204 return ret; 205 205 } 206 206 207 + VkImageMemoryRequirementsInfo2 memory_requirements_info = { 208 + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, 209 + .image = image, 210 + }; 211 + 212 + VkMemoryDedicatedRequirements memory_dedicated_requirements = { 213 + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, 214 + }; 215 + VkMemoryRequirements2 memory_requirements = { 216 + .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, 217 + .pNext = &memory_dedicated_requirements, 218 + }; 219 + vk->vkGetImageMemoryRequirements2(vk->device, &memory_requirements_info, &memory_requirements); 220 + 221 + VkBool32 use_dedicated_allocation = (memory_dedicated_requirements.requiresDedicatedAllocation != VK_FALSE) || 222 + (memory_dedicated_requirements.prefersDedicatedAllocation != VK_FALSE); 223 + U_LOG_D("create_image: Use dedicated allocation: %d", use_dedicated_allocation); 224 + 207 225 /* 208 226 * Create and bind the memory. 209 227 */ ··· 218 236 219 237 VkExportMemoryAllocateInfo export_alloc_info = { 220 238 .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, 221 - .pNext = &dedicated_memory_info, 239 + .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL, 222 240 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, 223 241 }; 224 242 ··· 226 244 227 245 VkExportMemoryAllocateInfo export_alloc_info = { 228 246 .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, 229 - .pNext = &dedicated_memory_info, 247 + .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL, 230 248 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID, 231 249 }; 232 250 ··· 234 252 235 253 VkExportMemoryAllocateInfo export_alloc_info = { 236 254 .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, 237 - .pNext = &dedicated_memory_info, 255 + .pNext = use_dedicated_allocation ? &dedicated_memory_info : NULL, 238 256 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR, 239 257 }; 240 258 ··· 252 270 out_image->handle = image; 253 271 out_image->memory = device_memory; 254 272 out_image->size = size; 273 + out_image->use_dedicated_allocation = use_dedicated_allocation; 255 274 256 275 return ret; 257 276 }
+1
src/xrt/auxiliary/vk/vk_image_allocator.h
··· 28 28 VkImage handle; 29 29 VkDeviceMemory memory; 30 30 VkDeviceSize size; 31 + bool use_dedicated_allocation; 31 32 }; 32 33 33 34 struct vk_image_collection
+1 -1
src/xrt/compositor/client/comp_gl_memobj_swapchain.c
··· 96 96 97 97 glCreateMemoryObjectsEXT(native_xsc->num_images, &sc->memory[0]); 98 98 for (uint32_t i = 0; i < native_xsc->num_images; i++) { 99 - GLint dedicated = GL_TRUE; 99 + GLint dedicated = xscn->images[i].use_dedicated_allocation ? GL_TRUE : GL_FALSE; 100 100 glMemoryObjectParameterivEXT(sc->memory[i], GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated); 101 101 glImportMemoryFdEXT(sc->memory[i], xscn->images[i].size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, 102 102 xscn->images[i].handle);
+1
src/xrt/compositor/main/comp_swapchain.c
··· 327 327 for (uint32_t i = 0; i < sc->vkic.num_images; i++) { 328 328 sc->base.images[i].handle = handles[i]; 329 329 sc->base.images[i].size = sc->vkic.images[i].size; 330 + sc->base.images[i].use_dedicated_allocation = sc->vkic.images[i].use_dedicated_allocation; 330 331 } 331 332 332 333 do_post_create_vulkan_setup(c, info, sc);
+2
src/xrt/include/xrt/xrt_compositor.h
··· 1370 1370 * into Vulkan. 1371 1371 */ 1372 1372 size_t size; 1373 + 1374 + bool use_dedicated_allocation; 1373 1375 }; 1374 1376 1375 1377 /*!
+3
src/xrt/ipc/client/ipc_client_compositor.c
··· 207 207 uint32_t handle; 208 208 uint32_t num_images; 209 209 uint64_t size; 210 + bool use_dedicated_allocation; 210 211 211 212 r = ipc_call_swapchain_create(icc->ipc_c, // connection 212 213 info, // in 213 214 &handle, // out 214 215 &num_images, // out 215 216 &size, // out 217 + &use_dedicated_allocation, // out 216 218 remote_handles, // handles 217 219 IPC_MAX_SWAPCHAIN_HANDLES); // handles 218 220 if (r != XRT_SUCCESS) { ··· 232 234 for (uint32_t i = 0; i < num_images; i++) { 233 235 ics->base.images[i].handle = remote_handles[i]; 234 236 ics->base.images[i].size = size; 237 + ics->base.images[i].use_dedicated_allocation = use_dedicated_allocation; 235 238 } 236 239 237 240 *out_xsc = &ics->base.base;
+3
src/xrt/ipc/server/ipc_server_handler.c
··· 679 679 uint32_t *out_id, 680 680 uint32_t *out_num_images, 681 681 uint64_t *out_size, 682 + bool *out_use_dedicated_allocation, 682 683 uint32_t max_num_handles, 683 684 xrt_graphics_buffer_handle_t *out_handles, 684 685 uint32_t *out_num_handles) ··· 718 719 *out_id = index; 719 720 *out_size = xscn->images[0].size; 720 721 *out_num_images = xsc->num_images; 722 + // assuming all images allocated in the same swapchain have the same allocation requirements 723 + *out_use_dedicated_allocation = xscn->images[0].use_dedicated_allocation; 721 724 722 725 // Setup the fds. 723 726 *out_num_handles = xsc->num_images;
+2 -1
src/xrt/ipc/shared/ipcproto/common.py
··· 55 55 # Keep all these synchronized with the definitions in the JSON Schema. 56 56 SCALAR_TYPES = set(("uint32_t", 57 57 "int64_t", 58 - "uint64_t")) 58 + "uint64_t", 59 + "bool")) 59 60 AGGREGATE_RE = re.compile(r"((const )?struct|union) (xrt|ipc)_[a-z_]+") 60 61 ENUM_RE = re.compile(r"enum xrt_[a-z_]+") 61 62
+2 -1
src/xrt/ipc/shared/proto.json
··· 125 125 "out": [ 126 126 {"name": "id", "type": "uint32_t"}, 127 127 {"name": "num_images", "type": "uint32_t"}, 128 - {"name": "size", "type": "uint64_t"} 128 + {"name": "size", "type": "uint64_t"}, 129 + {"name": "use_dedicated_allocation", "type": "bool"} 129 130 ], 130 131 "out_handles": {"type": "xrt_graphics_buffer_handle_t"} 131 132 },
+2 -1
src/xrt/ipc/shared/proto.schema.json
··· 12 12 "enum": [ 13 13 "uint32_t", 14 14 "int64_t", 15 - "uint64_t" 15 + "uint64_t", 16 + "bool" 16 17 ] 17 18 }, 18 19 "aggregate": {