isl/state: Don't set QPitch for GEN4_3D surfaces
[mesa.git] / src / intel / vulkan / anv_wsi_wayland.c
index 0c21029a56d8393082823559e6ae8e170aeff3ad..d210e79bbcbc2eaa7a200f789c6204ffe00ba0d5 100644 (file)
 
 #include "anv_wsi.h"
 
+#include "vk_format_info.h"
 #include <util/hash_table.h>
 
 #define MIN_NUM_IMAGES 2
 
 struct wsi_wl_display {
+   struct anv_physical_device                  *physical_device;
    struct wl_display *                          display;
    struct wl_drm *                              drm;
 
@@ -59,11 +61,12 @@ wsi_wl_display_add_vk_format(struct wsi_wl_display *display, VkFormat format)
       if (*f == format)
          return;
 
-   /* Don't add formats which aren't supported by the driver */
-   if (anv_format_for_vk_format(format)->isl_format ==
-       ISL_FORMAT_UNSUPPORTED) {
+   /* Don't add formats that aren't renderable. */
+   VkFormatProperties props;
+   anv_GetPhysicalDeviceFormatProperties(
+      anv_physical_device_to_handle(display->physical_device), format, &props);
+   if (!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
       return;
-   }
 
    f = anv_vector_add(&display->formats);
    if (f)
@@ -113,7 +116,7 @@ wl_drm_format_for_vk_format(VkFormat vk_format, bool alpha)
 #endif
 
    default:
-      assert("!Unsupported Vulkan format");
+      assert(!"Unsupported Vulkan format");
       return 0;
    }
 }
@@ -241,6 +244,7 @@ wsi_wl_display_create(struct wsi_wayland *wsi, struct wl_display *wl_display)
    memset(display, 0, sizeof(*display));
 
    display->display = wl_display;
+   display->physical_device = wsi->physical_device;
 
    if (!anv_vector_init(&display->formats, sizeof(VkFormat), 8))
       goto fail;
@@ -603,7 +607,9 @@ static const struct wl_buffer_listener buffer_listener = {
 };
 
 static VkResult
-wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image,
+wsi_wl_image_init(struct wsi_wl_swapchain *chain,
+                  struct wsi_wl_image *image,
+                  const VkSwapchainCreateInfoKHR *pCreateInfo,
                   const VkAllocationCallbacks* pAllocator)
 {
    VkDevice vk_device = anv_device_to_handle(chain->base.device);
@@ -629,7 +635,8 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image,
          .samples = 1,
          /* FIXME: Need a way to use X tiling to allow scanout */
          .tiling = VK_IMAGE_TILING_OPTIMAL,
-         .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+         .usage = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
+                   pCreateInfo->imageUsage),
          .flags = 0,
       }},
       pAllocator,
@@ -639,7 +646,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image,
       return result;
 
    image->image = anv_image_from_handle(vk_image);
-   assert(anv_format_is_color(image->image->format));
+   assert(vk_format_is_color(image->image->vk_format));
 
    struct anv_surface *surface = &image->image->color_surface;
 
@@ -778,15 +785,20 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
 
    chain->display = wsi_wl_get_display(&device->instance->physicalDevice,
                                        surface->display);
-   if (!chain->display)
+   if (!chain->display) {
+      result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
       goto fail;
+   }
 
    chain->queue = wl_display_create_queue(chain->display->display);
-   if (!chain->queue)
+   if (!chain->queue) {
+      result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
       goto fail;
+   }
 
    for (uint32_t i = 0; i < chain->image_count; i++) {
-      result = wsi_wl_image_init(chain, &chain->images[i], pAllocator);
+      result = wsi_wl_image_init(chain, &chain->images[i],
+                                 pCreateInfo, pAllocator);
       if (result != VK_SUCCESS)
          goto fail;
       chain->images[i].busy = false;