vk: Fill out buffer surface state when updating descriptor set
[mesa.git] / src / vulkan / anv_device.c
index 7e1b552ca7faba1b9b2bf39750608483fbeb11b7..88515c353eea5fbb00054409ea004ae4911933ef 100644 (file)
@@ -87,10 +87,14 @@ anv_physical_device_init(struct anv_physical_device *device,
       fprintf(stderr, "WARNING: Haswell Vulkan support is incomplete\n");
    } else if (device->info->gen == 7 && !device->info->is_baytrail) {
       fprintf(stderr, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
-   } else if (device->info->gen == 9) {
+   } else if (device->info->gen == 7 && device->info->is_baytrail) {
+      fprintf(stderr, "WARNING: Bay Trail Vulkan support is incomplete\n");
+   } else if (device->info->gen == 9 && !device->info->is_broxton) {
       fprintf(stderr, "WARNING: Skylake Vulkan support is incomplete\n");
-   } else if (device->info->gen == 8 && !device->info->is_cherryview) {
-      /* Broadwell is as fully supported as anything */
+   } else if (device->info->gen == 9 && device->info->is_broxton) {
+      fprintf(stderr, "WARNING: Broxton Vulkan support is incomplete\n");
+   } else if (device->info->gen == 8) {
+      /* Broadwell/Cherryview is as fully supported as anything */
    } else {
       result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
                          "Vulkan not yet supported on %s", device->name);
@@ -115,13 +119,8 @@ anv_physical_device_init(struct anv_physical_device *device,
       goto fail;
    }
 
-   if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC)) {
-      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
-                         "non-llc gpu");
-      goto fail;
-   }
-
-   if (anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION < 1)) {
+   if (!device->info->has_llc &&
+       anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) {
       result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
                          "kernel missing wc mmap");
       goto fail;
@@ -707,6 +706,9 @@ VkResult anv_CreateDevice(
    if (device->context_id == -1)
       goto fail_fd;
 
+   device->info = *physical_device->info;
+   device->isl_dev = physical_device->isl_dev;
+
    pthread_mutex_init(&device->mutex, NULL);
 
    anv_bo_pool_init(&device->batch_bo_pool, device, ANV_CMD_BUFFER_BATCH_SIZE);
@@ -716,7 +718,7 @@ VkResult anv_CreateDevice(
    anv_state_pool_init(&device->dynamic_state_pool,
                        &device->dynamic_state_block_pool);
 
-   anv_block_pool_init(&device->instruction_block_pool, device, 4096);
+   anv_block_pool_init(&device->instruction_block_pool, device, 8192);
    anv_block_pool_init(&device->surface_state_block_pool, device, 4096);
 
    anv_state_pool_init(&device->surface_state_pool,
@@ -726,9 +728,6 @@ VkResult anv_CreateDevice(
 
    anv_block_pool_init(&device->scratch_block_pool, device, 0x10000);
 
-   device->info = *physical_device->info;
-   device->isl_dev = physical_device->isl_dev;
-
    anv_queue_init(device, &device->queue);
 
    anv_device_init_meta(device);
@@ -1004,6 +1003,12 @@ VkResult anv_AllocateMemory(
 
    assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
 
+   if (pAllocateInfo->allocationSize == 0) {
+      /* Apparently, this is allowed */
+      *pMem = VK_NULL_HANDLE;
+      return VK_SUCCESS;
+   }
+
    /* We support exactly one memory heap. */
    assert(pAllocateInfo->memoryTypeIndex == 0 ||
           (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2));
@@ -1039,6 +1044,9 @@ void anv_FreeMemory(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
 
+   if (mem == NULL)
+      return;
+
    if (mem->bo.map)
       anv_gem_munmap(mem->bo.map, mem->bo.size);
 
@@ -1059,6 +1067,11 @@ VkResult anv_MapMemory(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
 
+   if (mem == NULL) {
+      *ppData = NULL;
+      return VK_SUCCESS;
+   }
+
    /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
     * takes a VkDeviceMemory pointer, it seems like only one map of the memory
     * at a time is valid. We could just mmap up front and return an offset
@@ -1083,6 +1096,9 @@ void anv_UnmapMemory(
 {
    ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
 
+   if (mem == NULL)
+      return;
+
    anv_gem_munmap(mem->map, mem->map_size);
 }
 
@@ -1209,8 +1225,13 @@ VkResult anv_BindBufferMemory(
    ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
-   buffer->bo = &mem->bo;
-   buffer->offset = memoryOffset;
+   if (mem) {
+      buffer->bo = &mem->bo;
+      buffer->offset = memoryOffset;
+   } else {
+      buffer->bo = NULL;
+      buffer->offset = 0;
+   }
 
    return VK_SUCCESS;
 }
@@ -1224,8 +1245,13 @@ VkResult anv_BindImageMemory(
    ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
    ANV_FROM_HANDLE(anv_image, image, _image);
 
-   image->bo = &mem->bo;
-   image->offset = memoryOffset;
+   if (mem) {
+      image->bo = &mem->bo;
+      image->offset = memoryOffset;
+   } else {
+      image->bo = NULL;
+      image->offset = 0;
+   }
 
    return VK_SUCCESS;
 }
@@ -1403,8 +1429,13 @@ VkResult anv_CreateSemaphore(
     const VkAllocationCallbacks*                pAllocator,
     VkSemaphore*                                pSemaphore)
 {
+   /* The DRM execbuffer ioctl always execute in-oder, even between different
+    * rings. As such, there's nothing to do for the user space semaphore.
+    */
+
    *pSemaphore = (VkSemaphore)1;
-   stub_return(VK_SUCCESS);
+
+   return VK_SUCCESS;
 }
 
 void anv_DestroySemaphore(
@@ -1412,47 +1443,100 @@ void anv_DestroySemaphore(
     VkSemaphore                                 semaphore,
     const VkAllocationCallbacks*                pAllocator)
 {
-   stub();
 }
 
 // Event functions
 
 VkResult anv_CreateEvent(
-    VkDevice                                    device,
+    VkDevice                                    _device,
     const VkEventCreateInfo*                    pCreateInfo,
     const VkAllocationCallbacks*                pAllocator,
     VkEvent*                                    pEvent)
 {
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   struct anv_state state;
+   struct anv_event *event;
+
+   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
+
+   state = anv_state_pool_alloc(&device->dynamic_state_pool,
+                                sizeof(*event), 4);
+   event = state.map;
+   event->state = state;
+   event->semaphore = VK_EVENT_RESET;
+
+   if (!device->info.has_llc) {
+      /* Make sure the writes we're flushing have landed. */
+      __builtin_ia32_sfence();
+      __builtin_ia32_clflush(event);
+   }
+
+   *pEvent = anv_event_to_handle(event);
+
+   return VK_SUCCESS;
 }
 
 void anv_DestroyEvent(
-    VkDevice                                    device,
-    VkEvent                                     event,
+    VkDevice                                    _device,
+    VkEvent                                     _event,
     const VkAllocationCallbacks*                pAllocator)
 {
-   stub();
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_event, event, _event);
+
+   anv_state_pool_free(&device->dynamic_state_pool, event->state);
 }
 
 VkResult anv_GetEventStatus(
-    VkDevice                                    device,
-    VkEvent                                     event)
+    VkDevice                                    _device,
+    VkEvent                                     _event)
 {
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_event, event, _event);
+
+   if (!device->info.has_llc) {
+      /* Make sure the writes we're flushing have landed. */
+      __builtin_ia32_clflush(event);
+      __builtin_ia32_lfence();
+   }
+
+   return event->semaphore;
 }
 
 VkResult anv_SetEvent(
-    VkDevice                                    device,
-    VkEvent                                     event)
+    VkDevice                                    _device,
+    VkEvent                                     _event)
 {
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_event, event, _event);
+
+   event->semaphore = VK_EVENT_SET;
+
+   if (!device->info.has_llc) {
+      /* Make sure the writes we're flushing have landed. */
+      __builtin_ia32_sfence();
+      __builtin_ia32_clflush(event);
+   }
+
+   return VK_SUCCESS;
 }
 
 VkResult anv_ResetEvent(
-    VkDevice                                    device,
-    VkEvent                                     event)
+    VkDevice                                    _device,
+    VkEvent                                     _event)
 {
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_event, event, _event);
+
+   event->semaphore = VK_EVENT_RESET;
+
+   if (!device->info.has_llc) {
+      /* Make sure the writes we're flushing have landed. */
+      __builtin_ia32_sfence();
+      __builtin_ia32_clflush(event);
+   }
+
+   return VK_SUCCESS;
 }
 
 // Buffer functions
@@ -1474,6 +1558,7 @@ VkResult anv_CreateBuffer(
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
    buffer->size = pCreateInfo->size;
+   buffer->usage = pCreateInfo->usage;
    buffer->bo = NULL;
    buffer->offset = 0;
 
@@ -1495,7 +1580,7 @@ void anv_DestroyBuffer(
 
 void
 anv_fill_buffer_surface_state(struct anv_device *device, void *state,
-                              const struct anv_format *format,
+                              enum isl_format format,
                               uint32_t offset, uint32_t range, uint32_t stride)
 {
    switch (device->info.gen) {
@@ -1516,23 +1601,6 @@ anv_fill_buffer_surface_state(struct anv_device *device, void *state,
    }
 }
 
-VkResult anv_CreateBufferView(
-    VkDevice                                    _device,
-    const VkBufferViewCreateInfo*               pCreateInfo,
-    const VkAllocationCallbacks*                pAllocator,
-    VkBufferView*                               pView)
-{
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
-}
-
-void anv_DestroyBufferView(
-    VkDevice                                    _device,
-    VkBufferView                                _bview,
-    const VkAllocationCallbacks*                pAllocator)
-{
-   stub();
-}
-
 void anv_DestroySampler(
     VkDevice                                    _device,
     VkSampler                                   _sampler,