[Mesa-dev] [PATCH] anv: don't try to free VK_NULL_HANDLE objects
Iago Toral Quiroga
itoral at igalia.com
Wed Nov 16 12:34:06 UTC 2016
Initial Vulkan documentation stated that it was invalid to free VK_NULL_HANDLE
objects, however this has been changed. From the Vulkan 1.0.33 specification.
2.6.2. Implicit Valid Usage. Valid Usage for Object Handles:
"It is valid to pass VK_NULL_HANDLE to any vkDestroy* or vkFree* command,
which will silently ignore these values."
This patch changes all anv_Destroy and anv_Free entry points to return early
when the target of the command is a NULL object.
This fixes crashes and fails in new Vulkan CTS tests in the vulkan-cts-1.0-dev
branch that have been added to verify this behavior.
Fixes:
dEQP-VK.api.null_handle.*
---
Maybe tag for stable?
src/intel/vulkan/anv_cmd_buffer.c | 6 ++++++
src/intel/vulkan/anv_descriptor_set.c | 12 ++++++++++++
src/intel/vulkan/anv_device.c | 21 +++++++++++++++++++++
src/intel/vulkan/anv_image.c | 9 +++++++++
src/intel/vulkan/anv_pass.c | 3 +++
src/intel/vulkan/anv_pipeline.c | 6 ++++++
src/intel/vulkan/anv_pipeline_cache.c | 3 +++
src/intel/vulkan/anv_query.c | 3 +++
src/intel/vulkan/anv_wsi.c | 6 ++++++
9 files changed, 69 insertions(+)
diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c
index 7ff7dba..e1c6193 100644
--- a/src/intel/vulkan/anv_cmd_buffer.c
+++ b/src/intel/vulkan/anv_cmd_buffer.c
@@ -298,6 +298,9 @@ VkResult anv_AllocateCommandBuffers(
static void
anv_cmd_buffer_destroy(struct anv_cmd_buffer *cmd_buffer)
{
+ if (!cmd_buffer)
+ return;
+
list_del(&cmd_buffer->pool_link);
anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer);
@@ -793,6 +796,9 @@ void anv_DestroyCommandPool(
VkCommandPool commandPool,
const VkAllocationCallbacks* pAllocator)
{
+ if (!commandPool)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_cmd_pool, pool, commandPool);
diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c
index 7d5a78d..81f48ef 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -197,6 +197,9 @@ void anv_DestroyDescriptorSetLayout(
VkDescriptorSetLayout _set_layout,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_set_layout)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout, _set_layout);
@@ -279,6 +282,9 @@ void anv_DestroyPipelineLayout(
VkPipelineLayout _pipelineLayout,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_pipelineLayout)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, _pipelineLayout);
@@ -352,6 +358,9 @@ void anv_DestroyDescriptorPool(
VkDescriptorPool _pool,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_pool)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_descriptor_pool, pool, _pool);
@@ -484,6 +493,9 @@ anv_descriptor_set_destroy(struct anv_device *device,
struct anv_descriptor_pool *pool,
struct anv_descriptor_set *set)
{
+ if (!set)
+ return;
+
/* Put the buffer view surface state back on the free list. */
for (uint32_t b = 0; b < set->buffer_count; b++) {
struct surface_state_free_list_entry *entry =
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 0999fcf..fdca633 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -322,6 +322,9 @@ void anv_DestroyInstance(
VkInstance _instance,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_instance)
+ return;
+
ANV_FROM_HANDLE(anv_instance, instance, _instance);
if (instance->physicalDeviceCount > 0) {
@@ -966,6 +969,9 @@ void anv_DestroyDevice(
VkDevice _device,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_device)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
anv_queue_finish(&device->queue);
@@ -1565,6 +1571,9 @@ void anv_DestroyFence(
VkFence _fence,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_fence)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_fence, fence, _fence);
@@ -1804,6 +1813,9 @@ void anv_DestroyEvent(
VkEvent _event,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_event)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_event, event, _event);
@@ -1896,6 +1908,9 @@ void anv_DestroyBuffer(
VkBuffer _buffer,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_buffer)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
@@ -1923,6 +1938,9 @@ void anv_DestroySampler(
VkSampler _sampler,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_sampler)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_sampler, sampler, _sampler);
@@ -1967,6 +1985,9 @@ void anv_DestroyFramebuffer(
VkFramebuffer _fb,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_fb)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_framebuffer, fb, _fb);
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index b7c2e99..16fafe0 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -274,6 +274,9 @@ void
anv_DestroyImage(VkDevice _device, VkImage _image,
const VkAllocationCallbacks *pAllocator)
{
+ if (!_image)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
vk_free2(&device->alloc, pAllocator, anv_image_from_handle(_image));
@@ -562,6 +565,9 @@ void
anv_DestroyImageView(VkDevice _device, VkImageView _iview,
const VkAllocationCallbacks *pAllocator)
{
+ if (!_iview)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_image_view, iview, _iview);
@@ -652,6 +658,9 @@ void
anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator)
{
+ if (!bufferView)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c
index 6eaa5c8..a72ea46 100644
--- a/src/intel/vulkan/anv_pass.c
+++ b/src/intel/vulkan/anv_pass.c
@@ -143,6 +143,9 @@ void anv_DestroyRenderPass(
VkRenderPass _pass,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_pass)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index bdc2f01..c9f8a91 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -72,6 +72,9 @@ void anv_DestroyShaderModule(
VkShaderModule _module,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_module)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_shader_module, module, _module);
@@ -186,6 +189,9 @@ void anv_DestroyPipeline(
VkPipeline _pipeline,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_pipeline)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c
index ff6e651..596f8ff 100644
--- a/src/intel/vulkan/anv_pipeline_cache.c
+++ b/src/intel/vulkan/anv_pipeline_cache.c
@@ -451,6 +451,9 @@ void anv_DestroyPipelineCache(
VkPipelineCache _cache,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_cache)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_pipeline_cache, cache, _cache);
diff --git a/src/intel/vulkan/anv_query.c b/src/intel/vulkan/anv_query.c
index 4afdaaf..2078fb9 100644
--- a/src/intel/vulkan/anv_query.c
+++ b/src/intel/vulkan/anv_query.c
@@ -84,6 +84,9 @@ void anv_DestroyQueryPool(
VkQueryPool _pool,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_pool)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_query_pool, pool, _pool);
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index b95e965..3f9cf2b 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -73,6 +73,9 @@ void anv_DestroySurfaceKHR(
VkSurfaceKHR _surface,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_surface)
+ return;
+
ANV_FROM_HANDLE(anv_instance, instance, _instance);
ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
@@ -290,6 +293,9 @@ void anv_DestroySwapchainKHR(
VkSwapchainKHR _swapchain,
const VkAllocationCallbacks* pAllocator)
{
+ if (!_swapchain)
+ return;
+
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
const VkAllocationCallbacks *alloc;
--
2.7.4
More information about the mesa-dev
mailing list