zink: only report device-local memory as video-memory
[mesa.git] / src / gallium / drivers / zink / zink_resource.c
index b8af12ed5f4e02cd0cac1154ce9b56e30e487280..a52d8bb6c70448912edc61b73dde0eba58011226 100644 (file)
 
 #include "util/slab.h"
 #include "util/u_debug.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 
-#include "state_tracker/sw_winsys.h"
+#include "frontend/sw_winsys.h"
 
 static void
 zink_resource_destroy(struct pipe_screen *pscreen,
@@ -179,12 +179,8 @@ resource_create(struct pipe_screen *pscreen,
           templ->target == PIPE_TEXTURE_CUBE_ARRAY)
          ici.arrayLayers *= 6;
 
-      if (templ->bind & (PIPE_BIND_DISPLAY_TARGET |
-                         PIPE_BIND_SCANOUT |
-                         PIPE_BIND_SHARED)) {
-         // assert(ici.tiling == VK_IMAGE_TILING_LINEAR);
+      if (templ->bind & PIPE_BIND_SHARED)
          ici.tiling = VK_IMAGE_TILING_LINEAR;
-      }
 
       if (templ->usage == PIPE_USAGE_STAGING)
          ici.tiling = VK_IMAGE_TILING_LINEAR;
@@ -247,7 +243,6 @@ resource_create(struct pipe_screen *pscreen,
    };
 
    if (whandle && whandle->type == WINSYS_HANDLE_TYPE_FD) {
-      imfi.sType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
       imfi.pNext = NULL;
       imfi.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
       imfi.fd = whandle->handle;
@@ -323,11 +318,6 @@ zink_resource_get_handle(struct pipe_screen *pscreen,
    }
 
    if (whandle->type == WINSYS_HANDLE_TYPE_FD) {
-
-      if (!screen->vk_GetMemoryFdKHR)
-         screen->vk_GetMemoryFdKHR = (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(screen->dev, "vkGetMemoryFdKHR");
-      if (!screen->vk_GetMemoryFdKHR)
-         return false;
       fd_info.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR;
       fd_info.memory = res->mem;
       fd_info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
@@ -444,6 +434,21 @@ zink_transfer_map(struct pipe_context *pctx,
 
    void *ptr;
    if (pres->target == PIPE_BUFFER) {
+      if (usage & PIPE_TRANSFER_READ) {
+         /* need to wait for rendering to finish
+          * TODO: optimize/fix this to be much less obtrusive
+          * mesa/mesa#2966
+          */
+         struct pipe_fence_handle *fence = NULL;
+         pctx->flush(pctx, &fence, PIPE_FLUSH_HINT_FINISH);
+         if (fence) {
+            pctx->screen->fence_finish(pctx->screen, NULL, fence,
+                                       PIPE_TIMEOUT_INFINITE);
+            pctx->screen->fence_reference(pctx->screen, &fence, NULL);
+         }
+      }
+
+
       VkResult result = vkMapMemory(screen->dev, res->mem, res->offset, res->size, 0, &ptr);
       if (result != VK_SUCCESS)
          return NULL;