From b60ee4251ecd3cabc5cc9eb519724cd268780f45 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 19 Dec 2024 16:39:03 +0100 Subject: [PATCH] panfrost: propagate errors from panfrost_batch_create_bo Without this, we just assert and/or crash because the allocation fails. This should allow us to survive a bit longer. Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 14 ++++++++++++-- src/gallium/drivers/panfrost/pan_context.c | 4 ++++ src/gallium/drivers/panfrost/pan_job.c | 17 +++++++++-------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index b91846994e0..bec355c3e7c 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -1574,6 +1574,9 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch, struct panfrost_bo *bo = panfrost_batch_get_shared_memory(batch, size, 1); + if (!bo) + return 0; + info.wls.ptr = bo->ptr.gpu; } @@ -4001,6 +4004,12 @@ batch_get_polygon_list(struct panfrost_batch *batch) batch->polygon_list_bo = panfrost_batch_create_bo( batch, size, init_polygon_list ? 0 : PAN_BO_INVISIBLE, PIPE_SHADER_VERTEX, "Polygon list"); + + if (!batch->polygon_list_bo) { + mesa_loge("failed to allocate memory for polygon-list"); + return 0; + } + batch->tiler_ctx.midgard.polygon_list = batch->polygon_list_bo->ptr.gpu; panfrost_batch_add_bo(batch, batch->polygon_list_bo, PIPE_SHADER_FRAGMENT); @@ -4035,8 +4044,9 @@ init_polygon_list(struct panfrost_batch *batch) { #if PAN_ARCH <= 5 uint64_t polygon_list = batch_get_polygon_list(batch); - pan_jc_initialize_tiler(&batch->pool.base, &batch->jm.jobs.vtc_jc, - polygon_list); + if (polygon_list) + pan_jc_initialize_tiler(&batch->pool.base, &batch->jm.jobs.vtc_jc, + polygon_list); #endif } diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 8ab01d92031..fbf2e3d9413 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -209,6 +209,10 @@ panfrost_get_blend(struct panfrost_batch *batch, unsigned rti, if (!(*bo)) { *bo = panfrost_batch_create_bo(batch, 4096, PAN_BO_EXECUTE, PIPE_SHADER_FRAGMENT, "Blend shader"); + if (!(*bo)) { + mesa_loge("failed to allocate blend-shader"); + return 0; + } } struct panfrost_compiled_shader *ss = ctx->prog[PIPE_SHADER_FRAGMENT]; diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index e009165dfcf..e785da90f19 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -409,15 +409,16 @@ panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size, bo = panfrost_bo_create(pan_device(batch->ctx->base.screen), size, create_flags, label); - assert(bo); - panfrost_batch_add_bo(batch, bo, stage); + if (bo) { + panfrost_batch_add_bo(batch, bo, stage); - /* panfrost_batch_add_bo() has retained a reference and - * panfrost_bo_create() initialize the refcnt to 1, so let's - * unreference the BO here so it gets released when the batch is - * destroyed (unless it's retained by someone else in the meantime). - */ - panfrost_bo_unreference(bo); + /* panfrost_batch_add_bo() has retained a reference and + * panfrost_bo_create() initialize the refcnt to 1, so let's + * unreference the BO here so it gets released when the batch is + * destroyed (unless it's retained by someone else in the meantime). + */ + panfrost_bo_unreference(bo); + } return bo; }