0057-vulkan-wsi-Allow-host-visible-memory-to-be-requested.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. From 0bfb1babce715e05151d35dec1daa0afe952b9c0 Mon Sep 17 00:00:00 2001
  2. From: Brendan King <Brendan.King@imgtec.com>
  3. Date: Tue, 16 Feb 2021 20:17:32 +0000
  4. Subject: [PATCH] vulkan/wsi: Allow host visible memory to be requested
  5. Allow host visible memory to be explicitly requested when allocating
  6. native images.
  7. For a software driver on X11, we need to be able to map the memory on
  8. the host, in order to present the contents to the X Server.
  9. ---
  10. src/vulkan/wsi/wsi_common_display.c | 2 +-
  11. src/vulkan/wsi/wsi_common_drm.c | 17 +++++++++++++----
  12. src/vulkan/wsi/wsi_common_private.h | 1 +
  13. src/vulkan/wsi/wsi_common_wayland.c | 3 ++-
  14. src/vulkan/wsi/wsi_common_x11.c | 1 +
  15. 5 files changed, 18 insertions(+), 6 deletions(-)
  16. diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
  17. index aa07cad..71a84e5 100644
  18. --- a/src/vulkan/wsi/wsi_common_display.c
  19. +++ b/src/vulkan/wsi/wsi_common_display.c
  20. @@ -1031,7 +1031,7 @@ wsi_display_image_init(VkDevice device_h,
  21. return VK_ERROR_DEVICE_LOST;
  22. VkResult result = wsi_create_native_image(&chain->base, create_info,
  23. - 0, NULL, NULL,
  24. + 0, NULL, NULL, false,
  25. &image->base);
  26. if (result != VK_SUCCESS)
  27. return result;
  28. diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c
  29. index 70d934a..aabb761 100644
  30. --- a/src/vulkan/wsi/wsi_common_drm.c
  31. +++ b/src/vulkan/wsi/wsi_common_drm.c
  32. @@ -66,6 +66,7 @@ wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd)
  33. static uint32_t
  34. select_memory_type(const struct wsi_device *wsi,
  35. bool want_device_local,
  36. + bool want_host_visible,
  37. uint32_t type_bits)
  38. {
  39. assert(type_bits);
  40. @@ -74,8 +75,10 @@ select_memory_type(const struct wsi_device *wsi,
  41. for (uint32_t i = 0; i < wsi->memory_props.memoryTypeCount; i++) {
  42. const VkMemoryType type = wsi->memory_props.memoryTypes[i];
  43. bool local = type.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
  44. + bool host = type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
  45. - if ((type_bits & (1 << i)) && local == want_device_local)
  46. + if ((type_bits & (1 << i)) && local == want_device_local &&
  47. + (!want_host_visible || host))
  48. return i;
  49. all_local &= local;
  50. }
  51. @@ -83,6 +86,8 @@ select_memory_type(const struct wsi_device *wsi,
  52. /* ignore want_device_local when all memory types are device-local */
  53. if (all_local) {
  54. assert(!want_device_local);
  55. + /* currently, host visibility is only needed with device local */
  56. + assert(!want_host_visible);
  57. return ffs(type_bits) - 1;
  58. }
  59. @@ -107,6 +112,7 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
  60. uint32_t num_modifier_lists,
  61. const uint32_t *num_modifiers,
  62. const uint64_t *const *modifiers,
  63. + bool host_visible,
  64. struct wsi_image *image)
  65. {
  66. const struct wsi_device *wsi = chain->wsi;
  67. @@ -317,7 +323,8 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
  68. .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
  69. .pNext = &memory_dedicated_info,
  70. .allocationSize = reqs.size,
  71. - .memoryTypeIndex = select_memory_type(wsi, true, reqs.memoryTypeBits),
  72. + .memoryTypeIndex = select_memory_type(wsi, true, host_visible,
  73. + reqs.memoryTypeBits),
  74. };
  75. result = wsi->AllocateMemory(chain->device, &memory_info,
  76. &chain->alloc, &image->memory);
  77. @@ -488,7 +495,8 @@ wsi_create_prime_image(const struct wsi_swapchain *chain,
  78. .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
  79. .pNext = &prime_memory_dedicated_info,
  80. .allocationSize = linear_size,
  81. - .memoryTypeIndex = select_memory_type(wsi, false, reqs.memoryTypeBits),
  82. + .memoryTypeIndex = select_memory_type(wsi, false, false,
  83. + reqs.memoryTypeBits),
  84. };
  85. result = wsi->AllocateMemory(chain->device, &prime_memory_info,
  86. &chain->alloc, &image->prime.memory);
  87. @@ -542,7 +550,8 @@ wsi_create_prime_image(const struct wsi_swapchain *chain,
  88. .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
  89. .pNext = &memory_dedicated_info,
  90. .allocationSize = reqs.size,
  91. - .memoryTypeIndex = select_memory_type(wsi, true, reqs.memoryTypeBits),
  92. + .memoryTypeIndex = select_memory_type(wsi, true, false,
  93. + reqs.memoryTypeBits),
  94. };
  95. result = wsi->AllocateMemory(chain->device, &memory_info,
  96. &chain->alloc, &image->memory);
  97. diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h
  98. index 1fe8211..5ad087b 100644
  99. --- a/src/vulkan/wsi/wsi_common_private.h
  100. +++ b/src/vulkan/wsi/wsi_common_private.h
  101. @@ -94,6 +94,7 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
  102. uint32_t num_modifier_lists,
  103. const uint32_t *num_modifiers,
  104. const uint64_t *const *modifiers,
  105. + bool host_visible,
  106. struct wsi_image *image);
  107. VkResult
  108. diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
  109. index 40f5338..983833e 100644
  110. --- a/src/vulkan/wsi/wsi_common_wayland.c
  111. +++ b/src/vulkan/wsi/wsi_common_wayland.c
  112. @@ -1074,7 +1074,8 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain,
  113. result = wsi_create_native_image(&chain->base, pCreateInfo,
  114. chain->num_drm_modifiers > 0 ? 1 : 0,
  115. &chain->num_drm_modifiers,
  116. - &chain->drm_modifiers, &image->base);
  117. + &chain->drm_modifiers, false,
  118. + &image->base);
  119. if (result != VK_SUCCESS)
  120. return result;
  121. diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
  122. index 9eb624d..eb639d6 100644
  123. --- a/src/vulkan/wsi/wsi_common_x11.c
  124. +++ b/src/vulkan/wsi/wsi_common_x11.c
  125. @@ -1315,6 +1315,7 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain,
  126. } else {
  127. result = wsi_create_native_image(&chain->base, pCreateInfo,
  128. num_tranches, num_modifiers, modifiers,
  129. + chain->base.wsi->sw,
  130. &image->base);
  131. }
  132. if (result < 0)