diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index c223fc7c904..f4102c81da2 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -2053,17 +2053,13 @@ v3dv_CreateSampler(VkDevice _device, sampler->state = v3dv_bo_alloc(device, cl_packet_length(SAMPLER_STATE), "sampler_state"); - if (!sampler->state) { - fprintf(stderr, "Failed to allocate memory for sampler state\n"); - abort(); - } + if (!sampler->state) + goto fail_alloc; bool ok = v3dv_bo_map(device, sampler->state, cl_packet_length(SAMPLER_STATE)); - if (!ok) { - fprintf(stderr, "failed to map sampler state buffer\n"); - abort(); - } + if (!ok) + goto fail_map; } sampler->compare_enable = pCreateInfo->compareEnable; @@ -2072,6 +2068,12 @@ v3dv_CreateSampler(VkDevice _device, *pSampler = v3dv_sampler_to_handle(sampler); return VK_SUCCESS; + +fail_map: + v3dv_bo_free(device, sampler->state); +fail_alloc: + vk_free2(&device->alloc, pAllocator, sampler); + return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); } void diff --git a/src/broadcom/vulkan/v3dv_image.c b/src/broadcom/vulkan/v3dv_image.c index 82b25517ebb..bfa5e6abf62 100644 --- a/src/broadcom/vulkan/v3dv_image.c +++ b/src/broadcom/vulkan/v3dv_image.c @@ -431,7 +431,12 @@ translate_swizzle(unsigned char pipe_swizzle) } } -static void +/* + * Packs and ensure bo for the shader state (the latter can be temporal). + * + * Return false if it was not able to allocate the bo. + */ +static bool pack_texture_shader_state(struct v3dv_device *device, struct v3dv_image_view *image_view) { @@ -443,17 +448,13 @@ pack_texture_shader_state(struct v3dv_device *device, v3dv_bo_alloc(device, cl_packet_length(TEXTURE_SHADER_STATE), "texture_shader_state"); - if (!image_view->texture_shader_state) { - fprintf(stderr, "Failed to allocate memory for texture shader state\n"); - abort(); - } + if (!image_view->texture_shader_state) + return false; bool ok = v3dv_bo_map(device, image_view->texture_shader_state, cl_packet_length(TEXTURE_SHADER_STATE)); - if (!ok) { - fprintf(stderr, "failed to map texture shader state\n"); - abort(); - } + if (!ok) + return false; } int msaa_scale = 1; /* FIXME: hardcoded. Revisit when msaa get supported */ @@ -518,6 +519,8 @@ pack_texture_shader_state(struct v3dv_device *device, v3dv_layer_offset(image, 0, image_view->first_layer); tex.texture_base_pointer = v3dv_cl_address(NULL, base_offset); } + + return true; } static enum pipe_swizzle @@ -647,11 +650,18 @@ v3dv_CreateImageView(VkDevice _device, util_format_compose_swizzles(format_swizzle, image_view_swizzle, iview->swizzle); - pack_texture_shader_state(device, iview); + if (!pack_texture_shader_state(device, iview)) + goto fail_texture_shader_state_alloc; *pView = v3dv_image_view_to_handle(iview); return VK_SUCCESS; + + fail_texture_shader_state_alloc: + if (iview->texture_shader_state) + v3dv_bo_free(device, iview->texture_shader_state); + vk_free2(&device->alloc, pAllocator, iview); + return VK_ERROR_OUT_OF_DEVICE_MEMORY; } void