[Mesa-dev] [PATCH 5/8] radv: use vk_zalloc instead of vk_alloc+memset

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri Nov 10 08:18:02 UTC 2017


Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/vulkan/radv_cmd_buffer.c |  5 ++---
 src/amd/vulkan/radv_device.c     | 14 +++++---------
 src/amd/vulkan/radv_image.c      |  5 ++---
 src/amd/vulkan/radv_pipeline.c   | 10 ++++------
 4 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 91c9342950..f58731b003 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -198,12 +198,11 @@ static VkResult radv_create_cmd_buffer(
 {
 	struct radv_cmd_buffer *cmd_buffer;
 	unsigned ring;
-	cmd_buffer = vk_alloc(&pool->alloc, sizeof(*cmd_buffer), 8,
-				VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+	cmd_buffer = vk_zalloc(&pool->alloc, sizeof(*cmd_buffer), 8,
+			       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 	if (cmd_buffer == NULL)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(cmd_buffer, 0, sizeof(*cmd_buffer));
 	cmd_buffer->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
 	cmd_buffer->device = device;
 	cmd_buffer->pool = pool;
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index aa0511fd8d..929082182c 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -372,13 +372,11 @@ VkResult radv_CreateInstance(
 			return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
 	}
 
-	instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
-			       VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+	instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
+			      VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 	if (!instance)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(instance, 0, sizeof(*instance));
-
 	instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
 
 	if (pAllocator)
@@ -995,14 +993,12 @@ VkResult radv_CreateDevice(
 		}
 	}
 
-	device = vk_alloc2(&physical_device->instance->alloc, pAllocator,
-			     sizeof(*device), 8,
-			     VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+	device = vk_zalloc2(&physical_device->instance->alloc, pAllocator,
+			    sizeof(*device), 8,
+			    VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
 	if (!device)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(device, 0, sizeof(*device));
-
 	device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
 	device->instance = physical_device->instance;
 	device->physical_device = physical_device;
diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index 0564454c77..163d35d76b 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -863,12 +863,11 @@ radv_image_create(VkDevice _device,
 	radv_assert(pCreateInfo->extent.height > 0);
 	radv_assert(pCreateInfo->extent.depth > 0);
 
-	image = vk_alloc2(&device->alloc, alloc, sizeof(*image), 8,
-			    VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+	image = vk_zalloc2(&device->alloc, alloc, sizeof(*image), 8,
+			   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 	if (!image)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(image, 0, sizeof(*image));
 	image->type = pCreateInfo->imageType;
 	image->info.width = pCreateInfo->extent.width;
 	image->info.height = pCreateInfo->extent.height;
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 92e646b8d0..86f5371ab6 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -2296,12 +2296,11 @@ radv_graphics_pipeline_create(
 	struct radv_pipeline *pipeline;
 	VkResult result;
 
-	pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
-			       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+	pipeline = vk_zalloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
+			      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 	if (pipeline == NULL)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(pipeline, 0, sizeof(*pipeline));
 	result = radv_pipeline_init(pipeline, device, cache,
 				    pCreateInfo, extra, pAllocator);
 	if (result != VK_SUCCESS) {
@@ -2353,12 +2352,11 @@ static VkResult radv_compute_pipeline_create(
 	struct radv_pipeline *pipeline;
 	VkResult result;
 
-	pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
-			       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+	pipeline = vk_zalloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
+			      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 	if (pipeline == NULL)
 		return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-	memset(pipeline, 0, sizeof(*pipeline));
 	pipeline->device = device;
 	pipeline->layout = radv_pipeline_layout_from_handle(pCreateInfo->layout);
 
-- 
2.15.0



More information about the mesa-dev mailing list