vk: clflush all state for non-LLC GPUs
[mesa.git] / src / vulkan / anv_device.c
index 75a889f134d372a4595179ac7a06e7f99000db32..384a457742f81ba9e90a1185a49302b34b36445e 100644 (file)
 #include "mesa/main/git_sha1.h"
 #include "util/strtod.h"
 
+#include "gen7_pack.h"
+
 struct anv_dispatch_table dtable;
 
+static void
+compiler_debug_log(void *data, const char *fmt, ...)
+{ }
+
+static void
+compiler_perf_log(void *data, const char *fmt, ...)
+{
+   va_list args;
+   va_start(args, fmt);
+
+   if (unlikely(INTEL_DEBUG & DEBUG_PERF))
+      vfprintf(stderr, fmt, args);
+
+   va_end(args);
+}
+
 static VkResult
 anv_physical_device_init(struct anv_physical_device *device,
                          struct anv_instance *instance,
@@ -43,127 +61,183 @@ anv_physical_device_init(struct anv_physical_device *device,
 
    fd = open(path, O_RDWR | O_CLOEXEC);
    if (fd < 0)
-      return vk_errorf(VK_ERROR_UNAVAILABLE, "failed to open %s: %m", path);
+      return vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                       "failed to open %s: %m", path);
 
+   device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    device->instance = instance;
    device->path = path;
-   
+
    device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID);
    if (!device->chipset_id) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get chipset id: %m");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "failed to get chipset id: %m");
       goto fail;
    }
 
    device->name = brw_get_device_name(device->chipset_id);
-   device->info = brw_get_device_info(device->chipset_id, -1);
+   device->info = brw_get_device_info(device->chipset_id);
    if (!device->info) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get device info");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "failed to get device info");
       goto fail;
    }
-   
+
+   if (device->info->is_haswell) {
+      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) {
+      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 {
+      result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
+                         "Vulkan not yet supported on %s", device->name);
+      goto fail;
+   }
+
    if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get aperture size: %m");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "failed to get aperture size: %m");
       goto fail;
    }
 
    if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "kernel missing gem wait");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "kernel missing gem wait");
       goto fail;
    }
 
    if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "kernel missing execbuf2");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "kernel missing execbuf2");
       goto fail;
    }
 
    if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC)) {
-      result = vk_errorf(VK_ERROR_UNAVAILABLE, "non-llc gpu");
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "non-llc gpu");
       goto fail;
    }
-   
+
    close(fd);
 
+   brw_process_intel_debug_variable();
+
+   device->compiler = brw_compiler_create(NULL, device->info);
+   if (device->compiler == NULL) {
+      result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+      goto fail;
+   }
+   device->compiler->shader_debug_log = compiler_debug_log;
+   device->compiler->shader_perf_log = compiler_perf_log;
+
+   isl_device_init(&device->isl_dev, device->info);
+
    return VK_SUCCESS;
-   
+
 fail:
    close(fd);
    return result;
 }
 
-static void *default_alloc(
-    void*                                       pUserData,
-    size_t                                      size,
-    size_t                                      alignment,
-    VkSystemAllocType                           allocType)
-{
-   return malloc(size);
-}
-
-static void default_free(
-    void*                                       pUserData,
-    void*                                       pMem)
+static void
+anv_physical_device_finish(struct anv_physical_device *device)
 {
-   free(pMem);
+   ralloc_free(device->compiler);
 }
 
-static const VkAllocCallbacks default_alloc_callbacks = {
-   .pUserData = NULL,
-   .pfnAlloc = default_alloc,
-   .pfnFree = default_free
-};
-
 static const VkExtensionProperties global_extensions[] = {
    {
-      .extName = "VK_WSI_swapchain",
-      .specVersion = 12
+      .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
+      .specVersion = 24,
    },
+   {
+      .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
+      .specVersion = 5,
+   },
+#ifdef HAVE_WAYLAND_PLATFORM
+   {
+      .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
+      .specVersion = 4,
+   },
+#endif
 };
 
 static const VkExtensionProperties device_extensions[] = {
    {
-      .extName = "VK_WSI_device_swapchain",
-      .specVersion = 12
+      .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME,
+      .specVersion = 67,
    },
 };
 
+static void *
+default_alloc_func(void *pUserData, size_t size, size_t align, 
+                   VkSystemAllocationScope allocationScope)
+{
+   return malloc(size);
+}
+
+static void *
+default_realloc_func(void *pUserData, void *pOriginal, size_t size,
+                     size_t align, VkSystemAllocationScope allocationScope)
+{
+   return realloc(pOriginal, size);
+}
+
+static void
+default_free_func(void *pUserData, void *pMemory)
+{
+   free(pMemory);
+}
+
+static const VkAllocationCallbacks default_alloc = {
+   .pUserData = NULL,
+   .pfnAllocation = default_alloc_func,
+   .pfnReallocation = default_realloc_func,
+   .pfnFree = default_free_func,
+};
 
 VkResult anv_CreateInstance(
     const VkInstanceCreateInfo*                 pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkInstance*                                 pInstance)
 {
    struct anv_instance *instance;
-   const VkAllocCallbacks *alloc_callbacks = &default_alloc_callbacks;
-   void *user_data = NULL;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
 
-   for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
+   if (pCreateInfo->pApplicationInfo->apiVersion != VK_MAKE_VERSION(0, 210, 1))
+      return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
+
+   for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
       bool found = false;
       for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) {
          if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                    global_extensions[j].extName) == 0) {
+                    global_extensions[j].extensionName) == 0) {
             found = true;
             break;
          }
       }
       if (!found)
-         return vk_error(VK_ERROR_INVALID_EXTENSION);
+         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
    }
 
-   if (pCreateInfo->pAllocCb) {
-      alloc_callbacks = pCreateInfo->pAllocCb;
-      user_data = pCreateInfo->pAllocCb->pUserData;
-   }
-   instance = alloc_callbacks->pfnAlloc(user_data, sizeof(*instance), 8,
-                                        VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   instance = anv_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
+                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!instance)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   instance->pAllocUserData = alloc_callbacks->pUserData;
-   instance->pfnAlloc = alloc_callbacks->pfnAlloc;
-   instance->pfnFree = alloc_callbacks->pfnFree;
-   instance->apiVersion = pCreateInfo->pAppInfo->apiVersion;
-   instance->physicalDeviceCount = 0;
+   instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
+
+   if (pAllocator)
+      instance->alloc = *pAllocator;
+   else
+      instance->alloc = default_alloc;
+
+   instance->apiVersion = pCreateInfo->pApplicationInfo->apiVersion;
+   instance->physicalDeviceCount = -1;
 
    _mesa_locale_init();
 
@@ -176,44 +250,25 @@ VkResult anv_CreateInstance(
    return VK_SUCCESS;
 }
 
-VkResult anv_DestroyInstance(
-    VkInstance                                  _instance)
+void anv_DestroyInstance(
+    VkInstance                                  _instance,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_instance, instance, _instance);
 
+   if (instance->physicalDeviceCount > 0) {
+      /* We support at most one physical device. */
+      assert(instance->physicalDeviceCount == 1);
+      anv_physical_device_finish(&instance->physicalDevice);
+   }
+
    anv_finish_wsi(instance);
 
    VG(VALGRIND_DESTROY_MEMPOOL(instance));
 
    _mesa_locale_fini();
 
-   instance->pfnFree(instance->pAllocUserData, instance);
-
-   return VK_SUCCESS;
-}
-
-void *
-anv_instance_alloc(struct anv_instance *instance, size_t size,
-                   size_t alignment, VkSystemAllocType allocType)
-{
-   void *mem = instance->pfnAlloc(instance->pAllocUserData,
-                                  size, alignment, allocType);
-   if (mem) {
-      VALGRIND_MEMPOOL_ALLOC(instance, mem, size);
-      VALGRIND_MAKE_MEM_UNDEFINED(mem, size);
-   }
-   return mem;
-}
-
-void
-anv_instance_free(struct anv_instance *instance, void *mem)
-{
-   if (mem == NULL)
-      return;
-
-   VALGRIND_MEMPOOL_FREE(instance, mem);
-
-   instance->pfnFree(instance->pAllocUserData, mem);
+   anv_free(&instance->alloc, instance);
 }
 
 VkResult anv_EnumeratePhysicalDevices(
@@ -224,13 +279,16 @@ VkResult anv_EnumeratePhysicalDevices(
    ANV_FROM_HANDLE(anv_instance, instance, _instance);
    VkResult result;
 
-   if (instance->physicalDeviceCount == 0) {
+   if (instance->physicalDeviceCount < 0) {
       result = anv_physical_device_init(&instance->physicalDevice,
                                         instance, "/dev/dri/renderD128");
-      if (result != VK_SUCCESS)
+      if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
+         instance->physicalDeviceCount = 0;
+      } else if (result == VK_SUCCESS) {
+         instance->physicalDeviceCount = 1;
+      } else {
          return result;
-
-      instance->physicalDeviceCount = 1;
+      }
    }
 
    /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
@@ -262,7 +320,7 @@ VkResult anv_EnumeratePhysicalDevices(
    return VK_SUCCESS;
 }
 
-VkResult anv_GetPhysicalDeviceFeatures(
+void anv_GetPhysicalDeviceFeatures(
     VkPhysicalDevice                            physicalDevice,
     VkPhysicalDeviceFeatures*                   pFeatures)
 {
@@ -276,98 +334,111 @@ VkResult anv_GetPhysicalDeviceFeatures(
       .geometryShader                           = true,
       .tessellationShader                       = false,
       .sampleRateShading                        = false,
-      .dualSourceBlend                          = true,
+      .dualSrcBlend                             = true,
       .logicOp                                  = true,
-      .instancedDrawIndirect                    = true,
-      .depthClip                                = false,
+      .multiDrawIndirect                        = true,
+      .depthClamp                               = false,
       .depthBiasClamp                           = false,
       .fillModeNonSolid                         = true,
       .depthBounds                              = false,
       .wideLines                                = true,
       .largePoints                              = true,
+      .alphaToOne                               = true,
+      .multiViewport                            = true,
+      .samplerAnisotropy                        = false, /* FINISHME */
       .textureCompressionETC2                   = true,
       .textureCompressionASTC_LDR               = true,
       .textureCompressionBC                     = true,
+      .occlusionQueryPrecise                    = false, /* FINISHME */
       .pipelineStatisticsQuery                  = true,
-      .vertexSideEffects                        = false,
-      .tessellationSideEffects                  = false,
-      .geometrySideEffects                      = false,
-      .fragmentSideEffects                      = false,
-      .shaderTessellationPointSize              = false,
-      .shaderGeometryPointSize                  = true,
-      .shaderTextureGatherExtended              = true,
+      .vertexPipelineStoresAndAtomics           = false,
+      .fragmentStoresAndAtomics                 = true,
+      .shaderTessellationAndGeometryPointSize   = true,
+      .shaderImageGatherExtended                = true,
       .shaderStorageImageExtendedFormats        = false,
       .shaderStorageImageMultisample            = false,
-      .shaderStorageBufferArrayConstantIndexing = false,
-      .shaderStorageImageArrayConstantIndexing  = false,
       .shaderUniformBufferArrayDynamicIndexing  = true,
       .shaderSampledImageArrayDynamicIndexing   = false,
       .shaderStorageBufferArrayDynamicIndexing  = false,
       .shaderStorageImageArrayDynamicIndexing   = false,
+      .shaderStorageImageReadWithoutFormat      = false,
+      .shaderStorageImageWriteWithoutFormat     = true,
       .shaderClipDistance                       = false,
       .shaderCullDistance                       = false,
       .shaderFloat64                            = false,
       .shaderInt64                              = false,
-      .shaderFloat16                            = false,
       .shaderInt16                              = false,
+      .alphaToOne                               = true,
+      .variableMultisampleRate                  = false,
    };
-
-   return VK_SUCCESS;
 }
 
-VkResult anv_GetPhysicalDeviceLimits(
+void anv_GetPhysicalDeviceProperties(
     VkPhysicalDevice                            physicalDevice,
-    VkPhysicalDeviceLimits*                     pLimits)
+    VkPhysicalDeviceProperties*                 pProperties)
 {
-   ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
-   const struct brw_device_info *devinfo = physical_device->info;
+   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+   const struct brw_device_info *devinfo = pdevice->info;
+
+   anv_finishme("Get correct values for VkPhysicalDeviceLimits");
 
-   anv_finishme("Get correct values for PhysicalDeviceLimits");
+   VkSampleCountFlags sample_counts =
+      VK_SAMPLE_COUNT_1_BIT |
+      VK_SAMPLE_COUNT_2_BIT |
+      VK_SAMPLE_COUNT_4_BIT |
+      VK_SAMPLE_COUNT_8_BIT;
 
-   *pLimits = (VkPhysicalDeviceLimits) {
+   VkPhysicalDeviceLimits limits = {
       .maxImageDimension1D                      = (1 << 14),
       .maxImageDimension2D                      = (1 << 14),
       .maxImageDimension3D                      = (1 << 10),
       .maxImageDimensionCube                    = (1 << 14),
       .maxImageArrayLayers                      = (1 << 10),
-      .maxTexelBufferSize                       = (1 << 14),
-      .maxUniformBufferSize                     = UINT32_MAX,
-      .maxStorageBufferSize                     = UINT32_MAX,
+      .maxTexelBufferElements                   = (1 << 14),
+      .maxUniformBufferRange                    = UINT32_MAX,
+      .maxStorageBufferRange                    = UINT32_MAX,
       .maxPushConstantsSize                     = MAX_PUSH_CONSTANTS_SIZE,
       .maxMemoryAllocationCount                 = UINT32_MAX,
+      .maxSamplerAllocationCount                = UINT32_MAX,
       .bufferImageGranularity                   = 64, /* A cache line */
+      .sparseAddressSpaceSize                   = 0,
       .maxBoundDescriptorSets                   = MAX_SETS,
-      .maxDescriptorSets                        = UINT32_MAX,
       .maxPerStageDescriptorSamplers            = 64,
       .maxPerStageDescriptorUniformBuffers      = 64,
       .maxPerStageDescriptorStorageBuffers      = 64,
       .maxPerStageDescriptorSampledImages       = 64,
       .maxPerStageDescriptorStorageImages       = 64,
+      .maxPerStageDescriptorInputAttachments    = 64,
+      .maxPerStageResources                     = 128,
       .maxDescriptorSetSamplers                 = 256,
       .maxDescriptorSetUniformBuffers           = 256,
+      .maxDescriptorSetUniformBuffersDynamic    = 256,
       .maxDescriptorSetStorageBuffers           = 256,
+      .maxDescriptorSetStorageBuffersDynamic    = 256,
       .maxDescriptorSetSampledImages            = 256,
       .maxDescriptorSetStorageImages            = 256,
+      .maxDescriptorSetInputAttachments         = 256,
       .maxVertexInputAttributes                 = 32,
+      .maxVertexInputBindings                   = 32,
       .maxVertexInputAttributeOffset            = 256,
       .maxVertexInputBindingStride              = 256,
       .maxVertexOutputComponents                = 32,
-      .maxTessGenLevel                          = 0,
-      .maxTessPatchSize                         = 0,
-      .maxTessControlPerVertexInputComponents   = 0,
-      .maxTessControlPerVertexOutputComponents  = 0,
-      .maxTessControlPerPatchOutputComponents   = 0,
-      .maxTessControlTotalOutputComponents      = 0,
-      .maxTessEvaluationInputComponents         = 0,
-      .maxTessEvaluationOutputComponents        = 0,
+      .maxTessellationGenerationLevel           = 0,
+      .maxTessellationPatchSize                 = 0,
+      .maxTessellationControlPerVertexInputComponents = 0,
+      .maxTessellationControlPerVertexOutputComponents = 0,
+      .maxTessellationControlPerPatchOutputComponents = 0,
+      .maxTessellationControlTotalOutputComponents = 0,
+      .maxTessellationEvaluationInputComponents = 0,
+      .maxTessellationEvaluationOutputComponents = 0,
       .maxGeometryShaderInvocations             = 6,
       .maxGeometryInputComponents               = 16,
       .maxGeometryOutputComponents              = 16,
       .maxGeometryOutputVertices                = 16,
       .maxGeometryTotalOutputComponents         = 16,
       .maxFragmentInputComponents               = 16,
-      .maxFragmentOutputBuffers                 = 8,
-      .maxFragmentDualSourceBuffers             = 2,
+      .maxFragmentOutputAttachments             = 8,
+      .maxFragmentDualSrcAttachments            = 2,
       .maxFragmentCombinedOutputResources       = 8,
       .maxComputeSharedMemorySize               = 1024,
       .maxComputeWorkGroupCount = {
@@ -385,12 +456,10 @@ VkResult anv_GetPhysicalDeviceLimits(
       .subTexelPrecisionBits                    = 4 /* FIXME */,
       .mipmapPrecisionBits                      = 4 /* FIXME */,
       .maxDrawIndexedIndexValue                 = UINT32_MAX,
-      .maxDrawIndirectInstanceCount             = UINT32_MAX,
-      .primitiveRestartForPatches               = UINT32_MAX,
+      .maxDrawIndirectCount                     = UINT32_MAX,
       .maxSamplerLodBias                        = 16,
       .maxSamplerAnisotropy                     = 16,
-      .maxViewports                             = 16,
-      .maxDynamicViewportStates                 = UINT32_MAX,
+      .maxViewports                             = MAX_VIEWPORTS,
       .maxViewportDimensions                    = { (1 << 14), (1 << 14) },
       .viewportBoundsRange                      = { -1.0, 1.0 }, /* FIXME */
       .viewportSubPixelBits                     = 13, /* We take a float? */
@@ -408,77 +477,71 @@ VkResult anv_GetPhysicalDeviceLimits(
       .maxFramebufferWidth                      = (1 << 14),
       .maxFramebufferHeight                     = (1 << 14),
       .maxFramebufferLayers                     = (1 << 10),
-      .maxFramebufferColorSamples               = 8,
-      .maxFramebufferDepthSamples               = 8,
-      .maxFramebufferStencilSamples             = 8,
+      .framebufferColorSampleCounts             = sample_counts,
+      .framebufferDepthSampleCounts             = sample_counts,
+      .framebufferStencilSampleCounts           = sample_counts,
+      .framebufferNoAttachmentsSampleCounts     = sample_counts,
       .maxColorAttachments                      = MAX_RTS,
-      .maxSampledImageColorSamples              = 8,
-      .maxSampledImageDepthSamples              = 8,
-      .maxSampledImageIntegerSamples            = 1,
-      .maxStorageImageSamples                   = 1,
+      .sampledImageColorSampleCounts            = sample_counts,
+      .sampledImageIntegerSampleCounts          = VK_SAMPLE_COUNT_1_BIT,
+      .sampledImageDepthSampleCounts            = sample_counts,
+      .sampledImageStencilSampleCounts          = sample_counts,
+      .storageImageSampleCounts                 = VK_SAMPLE_COUNT_1_BIT,
       .maxSampleMaskWords                       = 1,
-      .timestampFrequency                       = 1000 * 1000 * 1000 / 80,
+      .timestampPeriod                          = 80.0 / (1000 * 1000 * 1000),
       .maxClipDistances                         = 0 /* FIXME */,
       .maxCullDistances                         = 0 /* FIXME */,
       .maxCombinedClipAndCullDistances          = 0 /* FIXME */,
+      .discreteQueuePriorities                  = 1,
       .pointSizeRange                           = { 0.125, 255.875 },
       .lineWidthRange                           = { 0.0, 7.9921875 },
       .pointSizeGranularity                     = (1.0 / 8.0),
       .lineWidthGranularity                     = (1.0 / 128.0),
+      .strictLines                              = false, /* FINISHME */
+      .standardSampleLocations                  = true, /* FINISHME */
+      .optimalBufferCopyOffsetAlignment         = 128,
+      .optimalBufferCopyRowPitchAlignment       = 128,
+      .nonCoherentAtomSize                      = 64,
    };
 
-   return VK_SUCCESS;
-}
-
-VkResult anv_GetPhysicalDeviceProperties(
-    VkPhysicalDevice                            physicalDevice,
-    VkPhysicalDeviceProperties*                 pProperties)
-{
-   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
-
    *pProperties = (VkPhysicalDeviceProperties) {
-      .apiVersion = VK_MAKE_VERSION(0, 138, 1),
+      .apiVersion = VK_MAKE_VERSION(0, 210, 1),
       .driverVersion = 1,
-      .vendorId = 0x8086,
-      .deviceId = pdevice->chipset_id,
+      .vendorID = 0x8086,
+      .deviceID = pdevice->chipset_id,
       .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
+      .limits = limits,
+      .sparseProperties = {0}, /* Broadwell doesn't do sparse. */
    };
 
    strcpy(pProperties->deviceName, pdevice->name);
-   snprintf((char *)pProperties->pipelineCacheUUID, VK_UUID_LENGTH,
+   snprintf((char *)pProperties->pipelineCacheUUID, VK_UUID_SIZE,
             "anv-%s", MESA_GIT_SHA1 + 4);
-
-   return VK_SUCCESS;
 }
 
-VkResult anv_GetPhysicalDeviceQueueCount(
+void anv_GetPhysicalDeviceQueueFamilyProperties(
     VkPhysicalDevice                            physicalDevice,
-    uint32_t*                                   pCount)
+    uint32_t*                                   pCount,
+    VkQueueFamilyProperties*                    pQueueFamilyProperties)
 {
-   *pCount = 1;
-
-   return VK_SUCCESS;
-}
+   if (pQueueFamilyProperties == NULL) {
+      *pCount = 1;
+      return;
+   }
 
-VkResult anv_GetPhysicalDeviceQueueProperties(
-    VkPhysicalDevice                            physicalDevice,
-    uint32_t                                    count,
-    VkPhysicalDeviceQueueProperties*            pQueueProperties)
-{
-   assert(count == 1);
+   assert(*pCount >= 1);
 
-   *pQueueProperties = (VkPhysicalDeviceQueueProperties) {
+   *pQueueFamilyProperties = (VkQueueFamilyProperties) {
       .queueFlags = VK_QUEUE_GRAPHICS_BIT |
                     VK_QUEUE_COMPUTE_BIT |
-                    VK_QUEUE_DMA_BIT,
+                    VK_QUEUE_TRANSFER_BIT,
       .queueCount = 1,
-      .supportsTimestamps = true,
+      .timestampValidBits = 0, /* XXX: Real value here */
+      .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
    };
-
-   return VK_SUCCESS;
 }
 
-VkResult anv_GetPhysicalDeviceMemoryProperties(
+void anv_GetPhysicalDeviceMemoryProperties(
     VkPhysicalDevice                            physicalDevice,
     VkPhysicalDeviceMemoryProperties*           pMemoryProperties)
 {
@@ -493,17 +556,18 @@ VkResult anv_GetPhysicalDeviceMemoryProperties(
    /* The property flags below are valid only for llc platforms. */
    pMemoryProperties->memoryTypeCount = 1;
    pMemoryProperties->memoryTypes[0] = (VkMemoryType) {
-      .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+      .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+                       VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
+                       VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
+                       VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
       .heapIndex = 1,
    };
 
    pMemoryProperties->memoryHeapCount = 1;
    pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) {
       .size = heap_size,
-      .flags = VK_MEMORY_HEAP_HOST_LOCAL,
+      .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
    };
-
-   return VK_SUCCESS;
 }
 
 PFN_vkVoidFunction anv_GetInstanceProcAddr(
@@ -523,86 +587,93 @@ PFN_vkVoidFunction anv_GetDeviceProcAddr(
 static VkResult
 anv_queue_init(struct anv_device *device, struct anv_queue *queue)
 {
+   queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    queue->device = device;
    queue->pool = &device->surface_state_pool;
 
-   queue->completed_serial = anv_state_pool_alloc(queue->pool, 4, 4);
-   if (queue->completed_serial.map == NULL)
-      return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
-
-   *(uint32_t *)queue->completed_serial.map = 0;
-   queue->next_serial = 1;
-
    return VK_SUCCESS;
 }
 
 static void
 anv_queue_finish(struct anv_queue *queue)
 {
-#ifdef HAVE_VALGRIND
-   /* This gets torn down with the device so we only need to do this if
-    * valgrind is present.
-    */
-   anv_state_pool_free(queue->pool, queue->completed_serial);
-#endif
+}
+
+static struct anv_state
+anv_state_pool_emit_data(struct anv_state_pool *pool, size_t size, size_t align, const void *p)
+{
+   struct anv_state state;
+
+   state = anv_state_pool_alloc(pool, size, align);
+   memcpy(state.map, p, size);
+
+   if (!pool->block_pool->device->info.has_llc)
+      anv_state_clflush(state);
+
+   return state;
 }
 
 static void
 anv_device_init_border_colors(struct anv_device *device)
 {
    static const VkClearColorValue border_colors[] = {
-      [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] =  { .f32 = { 0.0, 0.0, 0.0, 0.0 } },
-      [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] =       { .f32 = { 0.0, 0.0, 0.0, 1.0 } },
-      [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] =       { .f32 = { 1.0, 1.0, 1.0, 1.0 } },
-      [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] =    { .u32 = { 0, 0, 0, 0 } },
-      [VK_BORDER_COLOR_INT_OPAQUE_BLACK] =         { .u32 = { 0, 0, 0, 1 } },
-      [VK_BORDER_COLOR_INT_OPAQUE_WHITE] =         { .u32 = { 1, 1, 1, 1 } },
+      [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] =  { .float32 = { 0.0, 0.0, 0.0, 0.0 } },
+      [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] =       { .float32 = { 0.0, 0.0, 0.0, 1.0 } },
+      [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] =       { .float32 = { 1.0, 1.0, 1.0, 1.0 } },
+      [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] =    { .uint32 = { 0, 0, 0, 0 } },
+      [VK_BORDER_COLOR_INT_OPAQUE_BLACK] =         { .uint32 = { 0, 0, 0, 1 } },
+      [VK_BORDER_COLOR_INT_OPAQUE_WHITE] =         { .uint32 = { 1, 1, 1, 1 } },
    };
 
-   device->border_colors =
-      anv_state_pool_alloc(&device->dynamic_state_pool,
-                           sizeof(border_colors), 32);
-   memcpy(device->border_colors.map, border_colors, sizeof(border_colors));
+   device->border_colors = anv_state_pool_emit_data(&device->dynamic_state_pool,
+                                                    sizeof(border_colors), 32, border_colors);
 }
 
 VkResult anv_CreateDevice(
     VkPhysicalDevice                            physicalDevice,
     const VkDeviceCreateInfo*                   pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkDevice*                                   pDevice)
 {
    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
-   struct anv_instance *instance = physical_device->instance;
    struct anv_device *device;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
 
-   for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
+   for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
       bool found = false;
       for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) {
          if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                    device_extensions[j].extName) == 0) {
+                    device_extensions[j].extensionName) == 0) {
             found = true;
             break;
          }
       }
       if (!found)
-         return vk_error(VK_ERROR_INVALID_EXTENSION);
+         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
    }
 
-   anv_set_dispatch_gen(physical_device->info->gen);
+   anv_set_dispatch_devinfo(physical_device->info);
 
-   device = anv_instance_alloc(instance, sizeof(*device), 8,
-                               VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   device = anv_alloc2(&physical_device->instance->alloc, pAllocator,
+                       sizeof(*device), 8,
+                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!device)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    device->instance = physical_device->instance;
 
+   if (pAllocator)
+      device->alloc = *pAllocator;
+   else
+      device->alloc = physical_device->instance->alloc;
+
    /* XXX(chadv): Can we dup() physicalDevice->fd here? */
    device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
    if (device->fd == -1)
       goto fail_device;
-      
+
    device->context_id = anv_gem_create_context(device);
    if (device->context_id == -1)
       goto fail_fd;
@@ -616,17 +687,18 @@ 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, 2048);
-   anv_block_pool_init(&device->surface_state_block_pool, device, 2048);
+   anv_block_pool_init(&device->instruction_block_pool, device, 4096);
+   anv_block_pool_init(&device->surface_state_block_pool, device, 4096);
 
    anv_state_pool_init(&device->surface_state_pool,
                        &device->surface_state_block_pool);
 
+   anv_bo_init_new(&device->workaround_bo, device, 1024);
+
    anv_block_pool_init(&device->scratch_block_pool, device, 0x10000);
 
    device->info = *physical_device->info;
-
-   device->compiler = anv_compiler_create(device);
+   device->isl_dev = physical_device->isl_dev;
 
    anv_queue_init(device, &device->queue);
 
@@ -641,18 +713,17 @@ VkResult anv_CreateDevice(
  fail_fd:
    close(device->fd);
  fail_device:
-   anv_device_free(device, device);
+   anv_free(&device->alloc, device);
 
-   return vk_error(VK_ERROR_UNAVAILABLE);
+   return vk_error(VK_ERROR_INITIALIZATION_FAILED);
 }
 
-VkResult anv_DestroyDevice(
-    VkDevice                                    _device)
+void anv_DestroyDevice(
+    VkDevice                                    _device,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
 
-   anv_compiler_destroy(device->compiler);
-
    anv_queue_finish(&device->queue);
 
    anv_device_finish_meta(device);
@@ -664,6 +735,9 @@ VkResult anv_DestroyDevice(
    anv_state_pool_free(&device->dynamic_state_pool, device->border_colors);
 #endif
 
+   anv_gem_munmap(device->workaround_bo.map, device->workaround_bo.size);
+   anv_gem_close(device, device->workaround_bo.gem_handle);
+
    anv_bo_pool_finish(&device->batch_bo_pool);
    anv_state_pool_finish(&device->dynamic_state_pool);
    anv_block_pool_finish(&device->dynamic_state_block_pool);
@@ -674,76 +748,74 @@ VkResult anv_DestroyDevice(
 
    close(device->fd);
 
-   anv_instance_free(device->instance, device);
-
-   return VK_SUCCESS;
+   anv_free(&device->alloc, device);
 }
 
-VkResult anv_GetGlobalExtensionProperties(
+VkResult anv_EnumerateInstanceExtensionProperties(
     const char*                                 pLayerName,
-    uint32_t*                                   pCount,
+    uint32_t*                                   pPropertyCount,
     VkExtensionProperties*                      pProperties)
 {
    if (pProperties == NULL) {
-      *pCount = ARRAY_SIZE(global_extensions);
+      *pPropertyCount = ARRAY_SIZE(global_extensions);
       return VK_SUCCESS;
    }
 
-   assert(*pCount >= ARRAY_SIZE(global_extensions));
+   assert(*pPropertyCount >= ARRAY_SIZE(global_extensions));
 
-   *pCount = ARRAY_SIZE(global_extensions);
+   *pPropertyCount = ARRAY_SIZE(global_extensions);
    memcpy(pProperties, global_extensions, sizeof(global_extensions));
 
    return VK_SUCCESS;
 }
 
-VkResult anv_GetPhysicalDeviceExtensionProperties(
+VkResult anv_EnumerateDeviceExtensionProperties(
     VkPhysicalDevice                            physicalDevice,
     const char*                                 pLayerName,
-    uint32_t*                                   pCount,
+    uint32_t*                                   pPropertyCount,
     VkExtensionProperties*                      pProperties)
 {
    if (pProperties == NULL) {
-      *pCount = ARRAY_SIZE(device_extensions);
+      *pPropertyCount = ARRAY_SIZE(device_extensions);
       return VK_SUCCESS;
    }
 
-   assert(*pCount >= ARRAY_SIZE(device_extensions));
+   assert(*pPropertyCount >= ARRAY_SIZE(device_extensions));
 
-   *pCount = ARRAY_SIZE(device_extensions);
+   *pPropertyCount = ARRAY_SIZE(device_extensions);
    memcpy(pProperties, device_extensions, sizeof(device_extensions));
 
    return VK_SUCCESS;
 }
 
-VkResult anv_GetGlobalLayerProperties(
-    uint32_t*                                   pCount,
+VkResult anv_EnumerateInstanceLayerProperties(
+    uint32_t*                                   pPropertyCount,
     VkLayerProperties*                          pProperties)
 {
    if (pProperties == NULL) {
-      *pCount = 0;
+      *pPropertyCount = 0;
       return VK_SUCCESS;
    }
 
    /* None supported at this time */
-   return vk_error(VK_ERROR_INVALID_LAYER);
+   return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
 }
 
-VkResult anv_GetPhysicalDeviceLayerProperties(
+VkResult anv_EnumerateDeviceLayerProperties(
     VkPhysicalDevice                            physicalDevice,
-    uint32_t*                                   pCount,
+    uint32_t*                                   pPropertyCount,
     VkLayerProperties*                          pProperties)
 {
    if (pProperties == NULL) {
-      *pCount = 0;
+      *pPropertyCount = 0;
       return VK_SUCCESS;
    }
 
    /* None supported at this time */
-   return vk_error(VK_ERROR_INVALID_LAYER);
+   return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
 }
 
-VkResult anv_GetDeviceQueue(
+void anv_GetDeviceQueue(
     VkDevice                                    _device,
     uint32_t                                    queueNodeIndex,
     uint32_t                                    queueIndex,
@@ -754,14 +826,12 @@ VkResult anv_GetDeviceQueue(
    assert(queueIndex == 0);
 
    *pQueue = anv_queue_to_handle(&device->queue);
-
-   return VK_SUCCESS;
 }
 
 VkResult anv_QueueSubmit(
     VkQueue                                     _queue,
-    uint32_t                                    cmdBufferCount,
-    const VkCmdBuffer*                          pCmdBuffers,
+    uint32_t                                    submitCount,
+    const VkSubmitInfo*                         pSubmits,
     VkFence                                     _fence)
 {
    ANV_FROM_HANDLE(anv_queue, queue, _queue);
@@ -769,23 +839,31 @@ VkResult anv_QueueSubmit(
    struct anv_device *device = queue->device;
    int ret;
 
-   for (uint32_t i = 0; i < cmdBufferCount; i++) {
-      ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, pCmdBuffers[i]);
-
-      assert(cmd_buffer->level == VK_CMD_BUFFER_LEVEL_PRIMARY);
+   for (uint32_t i = 0; i < submitCount; i++) {
+      for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) {
+         ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer,
+                         pSubmits[i].pCommandBuffers[j]);
+         assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
+
+         ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf);
+         if (ret != 0) {
+            /* We don't know the real error. */
+            return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
+                             "execbuf2 failed: %m");
+         }
 
-      ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf);
-      if (ret != 0)
-         return vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m");
+         if (fence) {
+            ret = anv_gem_execbuffer(device, &fence->execbuf);
+            if (ret != 0) {
+               /* We don't know the real error. */
+               return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
+                                "execbuf2 failed: %m");
+            }
+         }
 
-      if (fence) {
-         ret = anv_gem_execbuffer(device, &fence->execbuf);
-         if (ret != 0)
-            return vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m");
+         for (uint32_t k = 0; k < cmd_buffer->execbuf2.bo_count; k++)
+            cmd_buffer->execbuf2.bos[k]->offset = cmd_buffer->execbuf2.objects[k].offset;
       }
-
-      for (uint32_t i = 0; i < cmd_buffer->execbuf2.bo_count; i++)
-         cmd_buffer->execbuf2.bos[i]->offset = cmd_buffer->execbuf2.objects[i].offset;
    }
 
    return VK_SUCCESS;
@@ -819,6 +897,9 @@ VkResult anv_DeviceWaitIdle(
    anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END);
    anv_batch_emit(&batch, GEN7_MI_NOOP);
 
+   if (!device->info.has_llc)
+      anv_state_clflush(state);
+
    exec2_objects[0].handle = bo->gem_handle;
    exec2_objects[0].relocation_count = 0;
    exec2_objects[0].relocs_ptr = 0;
@@ -844,14 +925,16 @@ VkResult anv_DeviceWaitIdle(
 
    ret = anv_gem_execbuffer(device, &execbuf);
    if (ret != 0) {
-      result = vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m");
+      /* We don't know the real error. */
+      result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m");
       goto fail;
    }
 
    timeout = INT64_MAX;
    ret = anv_gem_wait(device, bo->gem_handle, &timeout);
    if (ret != 0) {
-      result = vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m");
+      /* We don't know the real error. */
+      result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m");
       goto fail;
    }
 
@@ -865,22 +948,6 @@ VkResult anv_DeviceWaitIdle(
    return result;
 }
 
-void *
-anv_device_alloc(struct anv_device *            device,
-                 size_t                         size,
-                 size_t                         alignment,
-                 VkSystemAllocType              allocType)
-{
-   return anv_instance_alloc(device->instance, size, alignment, allocType);
-}
-
-void
-anv_device_free(struct anv_device *             device,
-                void *                          mem)
-{
-   anv_instance_free(device->instance, mem);
-}
-
 VkResult
 anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size)
 {
@@ -896,30 +963,29 @@ anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size)
    return VK_SUCCESS;
 }
 
-VkResult anv_AllocMemory(
+VkResult anv_AllocateMemory(
     VkDevice                                    _device,
-    const VkMemoryAllocInfo*                    pAllocInfo,
+    const VkMemoryAllocateInfo*                 pAllocateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkDeviceMemory*                             pMem)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    struct anv_device_memory *mem;
    VkResult result;
 
-   assert(pAllocInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO);
+   assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
 
-   if (pAllocInfo->memoryTypeIndex != 0) {
-      /* We support exactly one memory heap. */
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+   /* We support exactly one memory heap. */
+   assert(pAllocateInfo->memoryTypeIndex == 0);
 
    /* FINISHME: Fail if allocation request exceeds heap size. */
 
-   mem = anv_device_alloc(device, sizeof(*mem), 8,
-                          VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   mem = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+                    VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (mem == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   result = anv_bo_init_new(&mem->bo, device, pAllocInfo->allocationSize);
+   result = anv_bo_init_new(&mem->bo, device, pAllocateInfo->allocationSize);
    if (result != VK_SUCCESS)
       goto fail;
 
@@ -928,14 +994,15 @@ VkResult anv_AllocMemory(
    return VK_SUCCESS;
 
  fail:
-   anv_device_free(device, mem);
+   anv_free2(&device->alloc, pAllocator, mem);
 
    return result;
 }
 
-VkResult anv_FreeMemory(
+void anv_FreeMemory(
     VkDevice                                    _device,
-    VkDeviceMemory                              _mem)
+    VkDeviceMemory                              _mem,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
@@ -946,21 +1013,19 @@ VkResult anv_FreeMemory(
    if (mem->bo.gem_handle != 0)
       anv_gem_close(device, mem->bo.gem_handle);
 
-   anv_device_free(device, mem);
-
-   return VK_SUCCESS;
+   anv_free2(&device->alloc, pAllocator, mem);
 }
 
 VkResult anv_MapMemory(
     VkDevice                                    _device,
-    VkDeviceMemory                              _mem,
+    VkDeviceMemory                              _memory,
     VkDeviceSize                                offset,
     VkDeviceSize                                size,
     VkMemoryMapFlags                            flags,
     void**                                      ppData)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
 
    /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
     * takes a VkDeviceMemory pointer, it seems like only one map of the memory
@@ -972,40 +1037,73 @@ VkResult anv_MapMemory(
    mem->map_size = size;
 
    *ppData = mem->map;
-   
+
    return VK_SUCCESS;
 }
 
-VkResult anv_UnmapMemory(
+void anv_UnmapMemory(
     VkDevice                                    _device,
-    VkDeviceMemory                              _mem)
+    VkDeviceMemory                              _memory)
 {
-   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
 
    anv_gem_munmap(mem->map, mem->map_size);
+}
 
-   return VK_SUCCESS;
+static void
+clflush_mapped_ranges(struct anv_device         *device,
+                      uint32_t                   count,
+                      const VkMappedMemoryRange *ranges)
+{
+   for (uint32_t i = 0; i < count; i++) {
+      ANV_FROM_HANDLE(anv_device_memory, mem, ranges[i].memory);
+      void *p = mem->map + (ranges[i].offset & ~CACHELINE_MASK);
+      void *end = mem->map + ranges[i].offset + ranges[i].size;
+
+      while (p < end) {
+         __builtin_ia32_clflush(p);
+         p += CACHELINE_SIZE;
+      }
+   }
 }
 
 VkResult anv_FlushMappedMemoryRanges(
-    VkDevice                                    device,
-    uint32_t                                    memRangeCount,
-    const VkMappedMemoryRange*                  pMemRanges)
+    VkDevice                                    _device,
+    uint32_t                                    memoryRangeCount,
+    const VkMappedMemoryRange*                  pMemoryRanges)
 {
-   /* clflush here for !llc platforms */
+   ANV_FROM_HANDLE(anv_device, device, _device);
+
+   if (device->info.has_llc)
+      return VK_SUCCESS;
+
+   /* Make sure the writes we're flushing have landed. */
+   __builtin_ia32_sfence();
+
+   clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges);
 
    return VK_SUCCESS;
 }
 
 VkResult anv_InvalidateMappedMemoryRanges(
-    VkDevice                                    device,
-    uint32_t                                    memRangeCount,
-    const VkMappedMemoryRange*                  pMemRanges)
+    VkDevice                                    _device,
+    uint32_t                                    memoryRangeCount,
+    const VkMappedMemoryRange*                  pMemoryRanges)
 {
-   return anv_FlushMappedMemoryRanges(device, memRangeCount, pMemRanges);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+
+   if (device->info.has_llc)
+      return VK_SUCCESS;
+
+   clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges);
+
+   /* Make sure no reads get moved up above the invalidate. */
+   __builtin_ia32_lfence();
+
+   return VK_SUCCESS;
 }
 
-VkResult anv_GetBufferMemoryRequirements(
+void anv_GetBufferMemoryRequirements(
     VkDevice                                    device,
     VkBuffer                                    _buffer,
     VkMemoryRequirements*                       pMemoryRequirements)
@@ -1025,11 +1123,9 @@ VkResult anv_GetBufferMemoryRequirements(
 
    pMemoryRequirements->size = buffer->size;
    pMemoryRequirements->alignment = 16;
-
-   return VK_SUCCESS;
 }
 
-VkResult anv_GetImageMemoryRequirements(
+void anv_GetImageMemoryRequirements(
     VkDevice                                    device,
     VkImage                                     _image,
     VkMemoryRequirements*                       pMemoryRequirements)
@@ -1049,39 +1145,36 @@ VkResult anv_GetImageMemoryRequirements(
 
    pMemoryRequirements->size = image->size;
    pMemoryRequirements->alignment = image->alignment;
-
-   return VK_SUCCESS;
 }
 
-VkResult anv_GetImageSparseMemoryRequirements(
+void anv_GetImageSparseMemoryRequirements(
     VkDevice                                    device,
     VkImage                                     image,
-    uint32_t*                                   pNumRequirements,
+    uint32_t*                                   pSparseMemoryRequirementCount,
     VkSparseImageMemoryRequirements*            pSparseMemoryRequirements)
 {
-   return vk_error(VK_UNSUPPORTED);
+   stub();
 }
 
-VkResult anv_GetDeviceMemoryCommitment(
+void anv_GetDeviceMemoryCommitment(
     VkDevice                                    device,
     VkDeviceMemory                              memory,
     VkDeviceSize*                               pCommittedMemoryInBytes)
 {
    *pCommittedMemoryInBytes = 0;
-   stub_return(VK_SUCCESS);
 }
 
 VkResult anv_BindBufferMemory(
     VkDevice                                    device,
     VkBuffer                                    _buffer,
-    VkDeviceMemory                              _mem,
-    VkDeviceSize                                memOffset)
+    VkDeviceMemory                              _memory,
+    VkDeviceSize                                memoryOffset)
 {
-   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
    buffer->bo = &mem->bo;
-   buffer->offset = memOffset;
+   buffer->offset = memoryOffset;
 
    return VK_SUCCESS;
 }
@@ -1089,48 +1182,31 @@ VkResult anv_BindBufferMemory(
 VkResult anv_BindImageMemory(
     VkDevice                                    device,
     VkImage                                     _image,
-    VkDeviceMemory                              _mem,
-    VkDeviceSize                                memOffset)
+    VkDeviceMemory                              _memory,
+    VkDeviceSize                                memoryOffset)
 {
-   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
    ANV_FROM_HANDLE(anv_image, image, _image);
 
    image->bo = &mem->bo;
-   image->offset = memOffset;
+   image->offset = memoryOffset;
 
    return VK_SUCCESS;
 }
 
-VkResult anv_QueueBindSparseBufferMemory(
+VkResult anv_QueueBindSparse(
     VkQueue                                     queue,
-    VkBuffer                                    buffer,
-    uint32_t                                    numBindings,
-    const VkSparseMemoryBindInfo*               pBindInfo)
-{
-   stub_return(VK_UNSUPPORTED);
-}
-
-VkResult anv_QueueBindSparseImageOpaqueMemory(
-    VkQueue                                     queue,
-    VkImage                                     image,
-    uint32_t                                    numBindings,
-    const VkSparseMemoryBindInfo*               pBindInfo)
-{
-   stub_return(VK_UNSUPPORTED);
-}
-
-VkResult anv_QueueBindSparseImageMemory(
-    VkQueue                                     queue,
-    VkImage                                     image,
-    uint32_t                                    numBindings,
-    const VkSparseImageMemoryBindInfo*          pBindInfo)
+    uint32_t                                    bindInfoCount,
+    const VkBindSparseInfo*                     pBindInfo,
+    VkFence                                     fence)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
 VkResult anv_CreateFence(
     VkDevice                                    _device,
     const VkFenceCreateInfo*                    pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkFence*                                    pFence)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
@@ -1142,8 +1218,8 @@ VkResult anv_CreateFence(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
 
-   fence = anv_device_alloc(device, sizeof(*fence), 8,
-                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   fence = anv_alloc2(&device->alloc, pAllocator, sizeof(*fence), 8,
+                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (fence == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -1158,6 +1234,13 @@ VkResult anv_CreateFence(
    anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END);
    anv_batch_emit(&batch, GEN7_MI_NOOP);
 
+   if (!device->info.has_llc) {
+      assert(((uintptr_t) fence->bo.map & CACHELINE_MASK) == 0);
+      assert(batch.next - fence->bo.map <= CACHELINE_SIZE);
+      __builtin_ia32_sfence();
+      __builtin_ia32_clflush(fence->bo.map);
+   }
+
    fence->exec2_objects[0].handle = fence->bo.gem_handle;
    fence->exec2_objects[0].relocation_count = 0;
    fence->exec2_objects[0].relocs_ptr = 0;
@@ -1186,23 +1269,22 @@ VkResult anv_CreateFence(
    return VK_SUCCESS;
 
  fail:
-   anv_device_free(device, fence);
+   anv_free2(&device->alloc, pAllocator, fence);
 
    return result;
 }
 
-VkResult anv_DestroyFence(
+void anv_DestroyFence(
     VkDevice                                    _device,
-    VkFence                                     _fence)
+    VkFence                                     _fence,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_fence, fence, _fence);
 
    anv_gem_munmap(fence->bo.map, fence->bo.size);
    anv_gem_close(device, fence->bo.gem_handle);
-   anv_device_free(device, fence);
-
-   return VK_SUCCESS;
+   anv_free2(&device->alloc, pAllocator, fence);
 }
 
 VkResult anv_ResetFences(
@@ -1247,18 +1329,31 @@ VkResult anv_WaitForFences(
     uint64_t                                    timeout)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
+
+   /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed
+    * to block indefinitely timeouts <= 0.  Unfortunately, this was broken
+    * for a couple of kernel releases.  Since there's no way to know
+    * whether or not the kernel we're using is one of the broken ones, the
+    * best we can do is to clamp the timeout to INT64_MAX.  This limits the
+    * maximum timeout from 584 years to 292 years - likely not a big deal.
+    */
+   if (timeout > INT64_MAX)
+      timeout = INT64_MAX;
+
    int64_t t = timeout;
-   int ret;
 
    /* FIXME: handle !waitAll */
 
    for (uint32_t i = 0; i < fenceCount; i++) {
       ANV_FROM_HANDLE(anv_fence, fence, pFences[i]);
-      ret = anv_gem_wait(device, fence->bo.gem_handle, &t);
-      if (ret == -1 && errno == ETIME)
+      int ret = anv_gem_wait(device, fence->bo.gem_handle, &t);
+      if (ret == -1 && errno == ETIME) {
          return VK_TIMEOUT;
-      else if (ret == -1)
-         return vk_errorf(VK_ERROR_UNKNOWN, "gem wait failed: %m");
+      } else if (ret == -1) {
+         /* We don't know the real error. */
+         return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
+                          "gem wait failed: %m");
+      }
    }
 
    return VK_SUCCESS;
@@ -1269,30 +1364,19 @@ VkResult anv_WaitForFences(
 VkResult anv_CreateSemaphore(
     VkDevice                                    device,
     const VkSemaphoreCreateInfo*                pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkSemaphore*                                pSemaphore)
 {
-   stub_return(VK_UNSUPPORTED);
+   *pSemaphore = (VkSemaphore)1;
+   stub_return(VK_SUCCESS);
 }
 
-VkResult anv_DestroySemaphore(
+void anv_DestroySemaphore(
     VkDevice                                    device,
-    VkSemaphore                                 semaphore)
-{
-   stub_return(VK_UNSUPPORTED);
-}
-
-VkResult anv_QueueSignalSemaphore(
-    VkQueue                                     queue,
-    VkSemaphore                                 semaphore)
+    VkSemaphore                                 semaphore,
+    const VkAllocationCallbacks*                pAllocator)
 {
-   stub_return(VK_UNSUPPORTED);
-}
-
-VkResult anv_QueueWaitSemaphore(
-    VkQueue                                     queue,
-    VkSemaphore                                 semaphore)
-{
-   stub_return(VK_UNSUPPORTED);
+   stub();
 }
 
 // Event functions
@@ -1300,37 +1384,39 @@ VkResult anv_QueueWaitSemaphore(
 VkResult anv_CreateEvent(
     VkDevice                                    device,
     const VkEventCreateInfo*                    pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkEvent*                                    pEvent)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
-VkResult anv_DestroyEvent(
+void anv_DestroyEvent(
     VkDevice                                    device,
-    VkEvent                                     event)
+    VkEvent                                     event,
+    const VkAllocationCallbacks*                pAllocator)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub();
 }
 
 VkResult anv_GetEventStatus(
     VkDevice                                    device,
     VkEvent                                     event)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
 VkResult anv_SetEvent(
     VkDevice                                    device,
     VkEvent                                     event)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
 VkResult anv_ResetEvent(
     VkDevice                                    device,
     VkEvent                                     event)
 {
-   stub_return(VK_UNSUPPORTED);
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
 // Buffer functions
@@ -1338,6 +1424,7 @@ VkResult anv_ResetEvent(
 VkResult anv_CreateBuffer(
     VkDevice                                    _device,
     const VkBufferCreateInfo*                   pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkBuffer*                                   pBuffer)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
@@ -1345,8 +1432,8 @@ VkResult anv_CreateBuffer(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
 
-   buffer = anv_device_alloc(device, sizeof(*buffer), 8,
-                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   buffer = anv_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
+                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (buffer == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -1359,615 +1446,72 @@ VkResult anv_CreateBuffer(
    return VK_SUCCESS;
 }
 
-VkResult anv_DestroyBuffer(
+void anv_DestroyBuffer(
     VkDevice                                    _device,
-    VkBuffer                                    _buffer)
+    VkBuffer                                    _buffer,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
-   anv_device_free(device, buffer);
-
-   return VK_SUCCESS;
+   anv_free2(&device->alloc, pAllocator, buffer);
 }
 
 void
 anv_fill_buffer_surface_state(struct anv_device *device, void *state,
                               const struct anv_format *format,
-                              uint32_t offset, uint32_t range)
+                              uint32_t offset, uint32_t range, uint32_t stride)
 {
    switch (device->info.gen) {
    case 7:
-      gen7_fill_buffer_surface_state(state, format, offset, range);
+      if (device->info.is_haswell)
+         gen75_fill_buffer_surface_state(state, format, offset, range, stride);
+      else
+         gen7_fill_buffer_surface_state(state, format, offset, range, stride);
       break;
    case 8:
-      gen8_fill_buffer_surface_state(state, format, offset, range);
+      gen8_fill_buffer_surface_state(state, format, offset, range, stride);
+      break;
+   case 9:
+      gen9_fill_buffer_surface_state(state, format, offset, range, stride);
       break;
    default:
       unreachable("unsupported gen\n");
    }
 }
 
-VkResult
-anv_buffer_view_create(
-   struct anv_device *                          device,
-   const VkBufferViewCreateInfo*                pCreateInfo,
-   struct anv_buffer_view **                    view_out)
-{
-   ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
-   struct anv_buffer_view *view;
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
-
-   view = anv_device_alloc(device, sizeof(*view), 8,
-                           VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (view == NULL)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   view->view = (struct anv_surface_view) {
-      .bo = buffer->bo,
-      .offset = buffer->offset + pCreateInfo->offset,
-      .surface_state = anv_state_pool_alloc(&device->surface_state_pool, 64, 64),
-      .format = anv_format_for_vk_format(pCreateInfo->format),
-      .range = pCreateInfo->range,
-   };
-
-   *view_out = view;
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyBufferView(
+VkResult anv_CreateBufferView(
     VkDevice                                    _device,
-    VkBufferView                                _bview)
+    const VkBufferViewCreateInfo*               pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
+    VkBufferView*                               pView)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_buffer_view, bview, _bview);
-
-   anv_surface_view_fini(device, &bview->view);
-   anv_device_free(device, bview);
-
-   return VK_SUCCESS;
+   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
 }
 
-VkResult anv_DestroySampler(
+void anv_DestroyBufferView(
     VkDevice                                    _device,
-    VkSampler                                   _sampler)
+    VkBufferView                                _bview,
+    const VkAllocationCallbacks*                pAllocator)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_sampler, sampler, _sampler);
-
-   anv_device_free(device, sampler);
-
-   return VK_SUCCESS;
-}
-
-// Descriptor set functions
-
-VkResult anv_CreateDescriptorSetLayout(
-    VkDevice                                    _device,
-    const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
-    VkDescriptorSetLayout*                      pSetLayout)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_descriptor_set_layout *set_layout;
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
-
-   uint32_t sampler_count[VK_SHADER_STAGE_NUM] = { 0, };
-   uint32_t surface_count[VK_SHADER_STAGE_NUM] = { 0, };
-   uint32_t num_dynamic_buffers = 0;
-   uint32_t count = 0;
-   uint32_t stages = 0;
-   uint32_t s;
-
-   for (uint32_t i = 0; i < pCreateInfo->count; i++) {
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-         for_each_bit(s, pCreateInfo->pBinding[i].stageFlags)
-            sampler_count[s] += pCreateInfo->pBinding[i].arraySize;
-         break;
-      default:
-         break;
-      }
-
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
-      case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-         for_each_bit(s, pCreateInfo->pBinding[i].stageFlags)
-            surface_count[s] += pCreateInfo->pBinding[i].arraySize;
-         break;
-      default:
-         break;
-      }
-
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-         num_dynamic_buffers += pCreateInfo->pBinding[i].arraySize;
-         break;
-      default:
-         break;
-      }
-
-      stages |= pCreateInfo->pBinding[i].stageFlags;
-      count += pCreateInfo->pBinding[i].arraySize;
-   }
-
-   uint32_t sampler_total = 0;
-   uint32_t surface_total = 0;
-   for (uint32_t s = 0; s < VK_SHADER_STAGE_NUM; s++) {
-      sampler_total += sampler_count[s];
-      surface_total += surface_count[s];
-   }
-
-   size_t size = sizeof(*set_layout) +
-      (sampler_total + surface_total) * sizeof(set_layout->entries[0]);
-   set_layout = anv_device_alloc(device, size, 8,
-                                 VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (!set_layout)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   set_layout->num_dynamic_buffers = num_dynamic_buffers;
-   set_layout->count = count;
-   set_layout->shader_stages = stages;
-
-   struct anv_descriptor_slot *p = set_layout->entries;
-   struct anv_descriptor_slot *sampler[VK_SHADER_STAGE_NUM];
-   struct anv_descriptor_slot *surface[VK_SHADER_STAGE_NUM];
-   for (uint32_t s = 0; s < VK_SHADER_STAGE_NUM; s++) {
-      set_layout->stage[s].surface_count = surface_count[s];
-      set_layout->stage[s].surface_start = surface[s] = p;
-      p += surface_count[s];
-      set_layout->stage[s].sampler_count = sampler_count[s];
-      set_layout->stage[s].sampler_start = sampler[s] = p;
-      p += sampler_count[s];
-   }
-
-   uint32_t descriptor = 0;
-   int8_t dynamic_slot = 0;
-   bool is_dynamic;
-   for (uint32_t i = 0; i < pCreateInfo->count; i++) {
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-         for_each_bit(s, pCreateInfo->pBinding[i].stageFlags)
-            for (uint32_t j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
-               sampler[s]->index = descriptor + j;
-               sampler[s]->dynamic_slot = -1;
-               sampler[s]++;
-            }
-         break;
-      default:
-         break;
-      }
-
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-         is_dynamic = true;
-         break;
-      default:
-         is_dynamic = false;
-         break;
-      }
-
-      switch (pCreateInfo->pBinding[i].descriptorType) {
-      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
-      case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-         for_each_bit(s, pCreateInfo->pBinding[i].stageFlags)
-            for (uint32_t j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
-               surface[s]->index = descriptor + j;
-               if (is_dynamic)
-                  surface[s]->dynamic_slot = dynamic_slot + j;
-               else
-                  surface[s]->dynamic_slot = -1;
-               surface[s]++;
-            }
-         break;
-      default:
-         break;
-      }
-
-      if (is_dynamic)
-         dynamic_slot += pCreateInfo->pBinding[i].arraySize;
-
-      descriptor += pCreateInfo->pBinding[i].arraySize;
-   }
-
-   *pSetLayout = anv_descriptor_set_layout_to_handle(set_layout);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyDescriptorSetLayout(
-    VkDevice                                    _device,
-    VkDescriptorSetLayout                       _set_layout)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout, _set_layout);
-
-   anv_device_free(device, set_layout);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_CreateDescriptorPool(
-    VkDevice                                    device,
-    VkDescriptorPoolUsage                       poolUsage,
-    uint32_t                                    maxSets,
-    const VkDescriptorPoolCreateInfo*           pCreateInfo,
-    VkDescriptorPool*                           pDescriptorPool)
-{
-   anv_finishme("VkDescriptorPool is a stub");
-   pDescriptorPool->handle = 1;
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyDescriptorPool(
-    VkDevice                                    _device,
-    VkDescriptorPool                            _pool)
-{
-   anv_finishme("VkDescriptorPool is a stub: free the pool's descriptor sets");
-   return VK_SUCCESS;
-}
-
-VkResult anv_ResetDescriptorPool(
-    VkDevice                                    device,
-    VkDescriptorPool                            descriptorPool)
-{
-   anv_finishme("VkDescriptorPool is a stub: free the pool's descriptor sets");
-   return VK_SUCCESS;
-}
-
-VkResult
-anv_descriptor_set_create(struct anv_device *device,
-                          const struct anv_descriptor_set_layout *layout,
-                          struct anv_descriptor_set **out_set)
-{
-   struct anv_descriptor_set *set;
-   size_t size = sizeof(*set) + layout->count * sizeof(set->descriptors[0]);
-
-   set = anv_device_alloc(device, size, 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (!set)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   /* A descriptor set may not be 100% filled. Clear the set so we can can
-    * later detect holes in it.
-    */
-   memset(set, 0, size);
-
-   *out_set = set;
-
-   return VK_SUCCESS;
-}
-
-void
-anv_descriptor_set_destroy(struct anv_device *device,
-                           struct anv_descriptor_set *set)
-{
-   anv_device_free(device, set);
-}
-
-VkResult anv_AllocDescriptorSets(
-    VkDevice                                    _device,
-    VkDescriptorPool                            descriptorPool,
-    VkDescriptorSetUsage                        setUsage,
-    uint32_t                                    count,
-    const VkDescriptorSetLayout*                pSetLayouts,
-    VkDescriptorSet*                            pDescriptorSets,
-    uint32_t*                                   pCount)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-
-   VkResult result;
-   struct anv_descriptor_set *set;
-
-   for (uint32_t i = 0; i < count; i++) {
-      ANV_FROM_HANDLE(anv_descriptor_set_layout, layout, pSetLayouts[i]);
-
-      result = anv_descriptor_set_create(device, layout, &set);
-      if (result != VK_SUCCESS) {
-         *pCount = i;
-         return result;
-      }
-
-      pDescriptorSets[i] = anv_descriptor_set_to_handle(set);
-   }
-
-   *pCount = count;
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_FreeDescriptorSets(
-    VkDevice                                    _device,
-    VkDescriptorPool                            descriptorPool,
-    uint32_t                                    count,
-    const VkDescriptorSet*                      pDescriptorSets)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-
-   for (uint32_t i = 0; i < count; i++) {
-      ANV_FROM_HANDLE(anv_descriptor_set, set, pDescriptorSets[i]);
-
-      anv_descriptor_set_destroy(device, set);
-   }
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_UpdateDescriptorSets(
-    VkDevice                                    device,
-    uint32_t                                    writeCount,
-    const VkWriteDescriptorSet*                 pDescriptorWrites,
-    uint32_t                                    copyCount,
-    const VkCopyDescriptorSet*                  pDescriptorCopies)
-{
-   for (uint32_t i = 0; i < writeCount; i++) {
-      const VkWriteDescriptorSet *write = &pDescriptorWrites[i];
-      ANV_FROM_HANDLE(anv_descriptor_set, set, write->destSet);
-
-      switch (write->descriptorType) {
-      case VK_DESCRIPTOR_TYPE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-         for (uint32_t j = 0; j < write->count; j++) {
-            set->descriptors[write->destBinding + j].sampler =
-               anv_sampler_from_handle(write->pDescriptors[j].sampler);
-         }
-
-         if (write->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
-            break;
-
-         /* fallthrough */
-
-      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
-      case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-         for (uint32_t j = 0; j < write->count; j++) {
-            ANV_FROM_HANDLE(anv_image_view, iview,
-                            write->pDescriptors[j].imageView);
-            set->descriptors[write->destBinding + j].view = &iview->view;
-         }
-         break;
-
-      case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-         anv_finishme("texel buffers not implemented");
-         break;
-
-      case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-         anv_finishme("input attachments not implemented");
-         break;
-
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
-      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-         for (uint32_t j = 0; j < write->count; j++) {
-            ANV_FROM_HANDLE(anv_buffer_view, bview,
-                            write->pDescriptors[j].bufferView);
-            set->descriptors[write->destBinding + j].view = &bview->view;
-         }
-
-      default:
-         break;
-      }
-   }
-
-   for (uint32_t i = 0; i < copyCount; i++) {
-      const VkCopyDescriptorSet *copy = &pDescriptorCopies[i];
-      ANV_FROM_HANDLE(anv_descriptor_set, src, copy->destSet);
-      ANV_FROM_HANDLE(anv_descriptor_set, dest, copy->destSet);
-      for (uint32_t j = 0; j < copy->count; j++) {
-         dest->descriptors[copy->destBinding + j] =
-            src->descriptors[copy->srcBinding + j];
-      }
-   }
-
-   return VK_SUCCESS;
-}
-
-// State object functions
-
-static inline int64_t
-clamp_int64(int64_t x, int64_t min, int64_t max)
-{
-   if (x < min)
-      return min;
-   else if (x < max)
-      return x;
-   else
-      return max;
-}
-
-VkResult anv_CreateDynamicViewportState(
-    VkDevice                                    _device,
-    const VkDynamicViewportStateCreateInfo*     pCreateInfo,
-    VkDynamicViewportState*                     pState)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_dynamic_vp_state *state;
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO);
-
-   state = anv_device_alloc(device, sizeof(*state), 8,
-                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (state == NULL)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   unsigned count = pCreateInfo->viewportAndScissorCount;
-   state->sf_clip_vp = anv_state_pool_alloc(&device->dynamic_state_pool,
-                                            count * 64, 64);
-   state->cc_vp = anv_state_pool_alloc(&device->dynamic_state_pool,
-                                       count * 8, 32);
-   state->scissor = anv_state_pool_alloc(&device->dynamic_state_pool,
-                                         count * 32, 32);
-
-   for (uint32_t i = 0; i < pCreateInfo->viewportAndScissorCount; i++) {
-      const VkViewport *vp = &pCreateInfo->pViewports[i];
-      const VkRect2D *s = &pCreateInfo->pScissors[i];
-
-      /* The gen7 state struct has just the matrix and guardband fields, the
-       * gen8 struct adds the min/max viewport fields. */
-      struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport = {
-         .ViewportMatrixElementm00 = vp->width / 2,
-         .ViewportMatrixElementm11 = vp->height / 2,
-         .ViewportMatrixElementm22 = (vp->maxDepth - vp->minDepth) / 2,
-         .ViewportMatrixElementm30 = vp->originX + vp->width / 2,
-         .ViewportMatrixElementm31 = vp->originY + vp->height / 2,
-         .ViewportMatrixElementm32 = (vp->maxDepth + vp->minDepth) / 2,
-         .XMinClipGuardband = -1.0f,
-         .XMaxClipGuardband = 1.0f,
-         .YMinClipGuardband = -1.0f,
-         .YMaxClipGuardband = 1.0f,
-         .XMinViewPort = vp->originX,
-         .XMaxViewPort = vp->originX + vp->width - 1,
-         .YMinViewPort = vp->originY,
-         .YMaxViewPort = vp->originY + vp->height - 1,
-      };
-
-      struct GEN7_CC_VIEWPORT cc_viewport = {
-         .MinimumDepth = vp->minDepth,
-         .MaximumDepth = vp->maxDepth
-      };
-
-      /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
-       * ymax < ymin for empty clips.  In case clip x, y, width height are all
-       * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
-       * what we want. Just special case empty clips and produce a canonical
-       * empty clip. */
-      static const struct GEN7_SCISSOR_RECT empty_scissor = {
-         .ScissorRectangleYMin = 1,
-         .ScissorRectangleXMin = 1,
-         .ScissorRectangleYMax = 0,
-         .ScissorRectangleXMax = 0
-      };
-
-      const int max = 0xffff;
-      struct GEN7_SCISSOR_RECT scissor = {
-         /* Do this math using int64_t so overflow gets clamped correctly. */
-         .ScissorRectangleYMin = clamp_int64(s->offset.y, 0, max),
-         .ScissorRectangleXMin = clamp_int64(s->offset.x, 0, max),
-         .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, max),
-         .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, max)
-      };
-
-      GEN8_SF_CLIP_VIEWPORT_pack(NULL, state->sf_clip_vp.map + i * 64, &sf_clip_viewport);
-      GEN7_CC_VIEWPORT_pack(NULL, state->cc_vp.map + i * 32, &cc_viewport);
-
-      if (s->extent.width <= 0 || s->extent.height <= 0) {
-         GEN7_SCISSOR_RECT_pack(NULL, state->scissor.map + i * 32, &empty_scissor);
-      } else {
-         GEN7_SCISSOR_RECT_pack(NULL, state->scissor.map + i * 32, &scissor);
-      }
-   }
-
-   *pState = anv_dynamic_vp_state_to_handle(state);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyDynamicViewportState(
-    VkDevice                                    _device,
-    VkDynamicViewportState                      _vp_state)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_dynamic_vp_state, vp_state, _vp_state);
-
-   anv_state_pool_free(&device->dynamic_state_pool, vp_state->sf_clip_vp);
-   anv_state_pool_free(&device->dynamic_state_pool, vp_state->cc_vp);
-   anv_state_pool_free(&device->dynamic_state_pool, vp_state->scissor);
-
-   anv_device_free(device, vp_state);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyDynamicRasterState(
-    VkDevice                                    _device,
-    VkDynamicRasterState                        _rs_state)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_dynamic_rs_state, rs_state, _rs_state);
-
-   anv_device_free(device, rs_state);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_CreateDynamicColorBlendState(
-    VkDevice                                    _device,
-    const VkDynamicColorBlendStateCreateInfo*   pCreateInfo,
-    VkDynamicColorBlendState*                   pState)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_dynamic_cb_state *state;
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO);
-
-   state = anv_device_alloc(device, sizeof(*state), 8,
-                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (state == NULL)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   struct GEN7_COLOR_CALC_STATE color_calc_state = {
-      .BlendConstantColorRed = pCreateInfo->blendConst[0],
-      .BlendConstantColorGreen = pCreateInfo->blendConst[1],
-      .BlendConstantColorBlue = pCreateInfo->blendConst[2],
-      .BlendConstantColorAlpha = pCreateInfo->blendConst[3]
-   };
-
-   GEN7_COLOR_CALC_STATE_pack(NULL, state->color_calc_state, &color_calc_state);
-
-   *pState = anv_dynamic_cb_state_to_handle(state);
-
-   return VK_SUCCESS;
+   stub();
 }
 
-VkResult anv_DestroyDynamicColorBlendState(
+void anv_DestroySampler(
     VkDevice                                    _device,
-    VkDynamicColorBlendState                    _cb_state)
+    VkSampler                                   _sampler,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_dynamic_cb_state, cb_state, _cb_state);
-
-   anv_device_free(device, cb_state);
+   ANV_FROM_HANDLE(anv_sampler, sampler, _sampler);
 
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyDynamicDepthStencilState(
-    VkDevice                                    _device,
-    VkDynamicDepthStencilState                  _ds_state)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_dynamic_ds_state, ds_state, _ds_state);
-
-   anv_device_free(device, ds_state);
-
-   return VK_SUCCESS;
+   anv_free2(&device->alloc, pAllocator, sampler);
 }
 
 VkResult anv_CreateFramebuffer(
     VkDevice                                    _device,
     const VkFramebufferCreateInfo*              pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
     VkFramebuffer*                              pFramebuffer)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
@@ -1976,213 +1520,54 @@ VkResult anv_CreateFramebuffer(
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
 
    size_t size = sizeof(*framebuffer) +
-                 sizeof(struct anv_attachment_view *) * pCreateInfo->attachmentCount;
-   framebuffer = anv_device_alloc(device, size, 8,
-                                  VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+                 sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount;
+   framebuffer = anv_alloc2(&device->alloc, pAllocator, size, 8,
+                            VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (framebuffer == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
    framebuffer->attachment_count = pCreateInfo->attachmentCount;
    for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
-      ANV_FROM_HANDLE(anv_attachment_view, view,
-                      pCreateInfo->pAttachments[i].view);
-
-      framebuffer->attachments[i] = view;
+      VkImageView _iview = pCreateInfo->pAttachments[i];
+      framebuffer->attachments[i] = anv_image_view_from_handle(_iview);
    }
 
    framebuffer->width = pCreateInfo->width;
    framebuffer->height = pCreateInfo->height;
    framebuffer->layers = pCreateInfo->layers;
 
-   anv_CreateDynamicViewportState(anv_device_to_handle(device),
-      &(VkDynamicViewportStateCreateInfo) {
-         .sType = VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO,
-         .viewportAndScissorCount = 1,
-         .pViewports = (VkViewport[]) {
-            {
-               .originX = 0,
-               .originY = 0,
-               .width = pCreateInfo->width,
-               .height = pCreateInfo->height,
-               .minDepth = 0,
-               .maxDepth = 1
-            },
-         },
-         .pScissors = (VkRect2D[]) {
-            { {  0,  0 },
-              { pCreateInfo->width, pCreateInfo->height } },
-         }
-      },
-      &framebuffer->vp_state);
-
    *pFramebuffer = anv_framebuffer_to_handle(framebuffer);
 
    return VK_SUCCESS;
 }
 
-VkResult anv_DestroyFramebuffer(
+void anv_DestroyFramebuffer(
     VkDevice                                    _device,
-    VkFramebuffer                               _fb)
+    VkFramebuffer                               _fb,
+    const VkAllocationCallbacks*                pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_framebuffer, fb, _fb);
 
-   anv_DestroyDynamicViewportState(anv_device_to_handle(device),
-                                   fb->vp_state);
-   anv_device_free(device, fb);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_CreateRenderPass(
-    VkDevice                                    _device,
-    const VkRenderPassCreateInfo*               pCreateInfo,
-    VkRenderPass*                               pRenderPass)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_render_pass *pass;
-   size_t size;
-   size_t attachments_offset;
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
-
-   size = sizeof(*pass);
-   size += pCreateInfo->subpassCount * sizeof(pass->subpasses[0]);
-   attachments_offset = size;
-   size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]);
-
-   pass = anv_device_alloc(device, size, 8,
-                           VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (pass == NULL)
-      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
-   /* Clear the subpasses along with the parent pass. This required because
-    * each array member of anv_subpass must be a valid pointer if not NULL.
-    */
-   memset(pass, 0, size);
-   pass->attachment_count = pCreateInfo->attachmentCount;
-   pass->subpass_count = pCreateInfo->subpassCount;
-   pass->attachments = (void *) pass + attachments_offset;
-
-   for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
-      struct anv_render_pass_attachment *att = &pass->attachments[i];
-
-      att->format = anv_format_for_vk_format(pCreateInfo->pAttachments[i].format);
-      att->samples = pCreateInfo->pAttachments[i].samples;
-      att->load_op = pCreateInfo->pAttachments[i].loadOp;
-      att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
-      // att->store_op = pCreateInfo->pAttachments[i].storeOp;
-      // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
-
-      if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         if (anv_format_is_color(att->format)) {
-            ++pass->num_color_clear_attachments;
-         } else if (att->format->depth_format) {
-            pass->has_depth_clear_attachment = true;
-         }
-      } else if (att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         assert(att->format->has_stencil);
-         pass->has_stencil_clear_attachment = true;
-      }
-   }
-
-   for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
-      const VkSubpassDescription *desc = &pCreateInfo->pSubpasses[i];
-      struct anv_subpass *subpass = &pass->subpasses[i];
-
-      subpass->input_count = desc->inputCount;
-      subpass->color_count = desc->colorCount;
-
-      if (desc->inputCount > 0) {
-         subpass->input_attachments =
-            anv_device_alloc(device, desc->inputCount * sizeof(uint32_t),
-                             8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-
-         for (uint32_t j = 0; j < desc->inputCount; j++) {
-            subpass->input_attachments[j]
-               = desc->inputAttachments[j].attachment;
-         }
-      }
-
-      if (desc->colorCount > 0) {
-         subpass->color_attachments =
-            anv_device_alloc(device, desc->colorCount * sizeof(uint32_t),
-                             8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-
-         for (uint32_t j = 0; j < desc->colorCount; j++) {
-            subpass->color_attachments[j]
-               = desc->colorAttachments[j].attachment;
-         }
-      }
-
-      if (desc->resolveAttachments) {
-         subpass->resolve_attachments =
-            anv_device_alloc(device, desc->colorCount * sizeof(uint32_t),
-                             8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-
-         for (uint32_t j = 0; j < desc->colorCount; j++) {
-            subpass->resolve_attachments[j]
-               = desc->resolveAttachments[j].attachment;
-         }
-      }
-
-      subpass->depth_stencil_attachment = desc->depthStencilAttachment.attachment;
-   }
-
-   *pRenderPass = anv_render_pass_to_handle(pass);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_DestroyRenderPass(
-    VkDevice                                    _device,
-    VkRenderPass                                _pass)
-{
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
-
-   for (uint32_t i = 0; i < pass->subpass_count; i++) {
-      /* In VkSubpassCreateInfo, each of the attachment arrays may be null.
-       * Don't free the null arrays.
-       */
-      struct anv_subpass *subpass = &pass->subpasses[i];
-
-      anv_device_free(device, subpass->input_attachments);
-      anv_device_free(device, subpass->color_attachments);
-      anv_device_free(device, subpass->resolve_attachments);
-   }
-
-   anv_device_free(device, pass);
-
-   return VK_SUCCESS;
-}
-
-VkResult anv_GetRenderAreaGranularity(
-    VkDevice                                    device,
-    VkRenderPass                                renderPass,
-    VkExtent2D*                                 pGranularity)
-{
-   *pGranularity = (VkExtent2D) { 1, 1 };
-
-   return VK_SUCCESS;
+   anv_free2(&device->alloc, pAllocator, fb);
 }
 
 void vkCmdDbgMarkerBegin(
-    VkCmdBuffer                              cmdBuffer,
+    VkCommandBuffer                              commandBuffer,
     const char*                                 pMarker)
    __attribute__ ((visibility ("default")));
 
 void vkCmdDbgMarkerEnd(
-   VkCmdBuffer                              cmdBuffer)
+   VkCommandBuffer                              commandBuffer)
    __attribute__ ((visibility ("default")));
 
 void vkCmdDbgMarkerBegin(
-    VkCmdBuffer                              cmdBuffer,
+    VkCommandBuffer                              commandBuffer,
     const char*                                 pMarker)
 {
 }
 
 void vkCmdDbgMarkerEnd(
-    VkCmdBuffer                              cmdBuffer)
+    VkCommandBuffer                              commandBuffer)
 {
 }