From f563ce8c7ea2bcdf5ca97ebba1d8c16079f04344 Mon Sep 17 00:00:00 2001 From: Patrick Lerda Date: Fri, 15 Nov 2024 20:20:58 +0100 Subject: [PATCH] r600: restructure r600_create_vertex_fetch_shader() to remove memcpy() Cc: mesa-stable Signed-off-by: Patrick Lerda Part-of: (cherry picked from commit 275535774c175d2597ef7605d66f1c30a5cb04e7) --- .pick_status.json | 2 +- src/gallium/drivers/r600/r600_shader.c | 57 +++++++++++--------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 1c7d017db02..4a0990e78d7 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -594,7 +594,7 @@ "description": "r600: restructure r600_create_vertex_fetch_shader() to remove memcpy()", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 64809b120ca..154b3dba3a3 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -354,10 +354,14 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, int i, j, r, fs_size; uint32_t buffer_mask = 0; struct r600_fetch_shader *shader; - unsigned strides[PIPE_MAX_ATTRIBS]; assert(count < 32); + /* Allocate the CSO. */ + shader = CALLOC_STRUCT(r600_fetch_shader); + if (unlikely(!shader)) + return NULL; + memset(&bc, 0, sizeof(bc)); r600_bytecode_init(&bc, rctx->b.gfx_level, rctx->b.family, rctx->screen->has_compressed_msaa_texturing); @@ -379,10 +383,8 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, alu.dst.chan = j; alu.dst.write = j == 3; alu.last = j == 3; - if ((r = r600_bytecode_add_alu(&bc, &alu))) { - r600_bytecode_clear(&bc); - return NULL; - } + if (unlikely(r = r600_bytecode_add_alu(&bc, &alu))) + goto fail; } } else { struct r600_bytecode_alu alu; @@ -396,13 +398,11 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, alu.dst.chan = 3; alu.dst.write = 1; alu.last = 1; - if ((r = r600_bytecode_add_alu(&bc, &alu))) { - r600_bytecode_clear(&bc); - return NULL; - } + if (unlikely(r = r600_bytecode_add_alu(&bc, &alu))) + goto fail; } } - strides[elements[i].vertex_buffer_index] = elements[i].src_stride; + shader->strides[elements[i].vertex_buffer_index] = elements[i].src_stride; buffer_mask |= BITFIELD_BIT(elements[i].vertex_buffer_index); } @@ -412,10 +412,9 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, desc = util_format_description(elements[i].src_format); - if (elements[i].src_offset > 65535) { - r600_bytecode_clear(&bc); + if (unlikely(elements[i].src_offset > 65535)) { R600_ERR("too big src_offset: %u\n", elements[i].src_offset); - return NULL; + goto fail; } memset(&vtx, 0, sizeof(vtx)); @@ -435,18 +434,14 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, vtx.offset = elements[i].src_offset; vtx.endian = endian; - if ((r = r600_bytecode_add_vtx(&bc, &vtx))) { - r600_bytecode_clear(&bc); - return NULL; - } + if (unlikely(r = r600_bytecode_add_vtx(&bc, &vtx))) + goto fail; } r600_bytecode_add_cfinst(&bc, CF_OP_RET); - if ((r = r600_bytecode_build(&bc))) { - r600_bytecode_clear(&bc); - return NULL; - } + if (unlikely(r = r600_bytecode_build(&bc))) + goto fail; if (rctx->screen->b.debug_flags & DBG_FS) { fprintf(stderr, "--------------------------------------------------------------\n"); @@ -462,23 +457,13 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, fs_size = bc.ndw*4; - /* Allocate the CSO. */ - shader = CALLOC_STRUCT(r600_fetch_shader); - if (!shader) { - r600_bytecode_clear(&bc); - return NULL; - } - memcpy(shader->strides, strides, sizeof(strides)); shader->buffer_mask = buffer_mask; u_suballocator_alloc(&rctx->allocator_fetch_shader, fs_size, 256, &shader->offset, (struct pipe_resource**)&shader->buffer); - if (!shader->buffer) { - r600_bytecode_clear(&bc); - FREE(shader); - return NULL; - } + if (unlikely(!shader->buffer)) + goto fail; bytecode = r600_buffer_map_sync_with_rings (&rctx->b, shader->buffer, @@ -496,6 +481,12 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx, r600_bytecode_clear(&bc); return shader; + + fail: + r600_bytecode_clear(&bc); + FREE(shader); + return NULL; + } int eg_get_interpolator_index(unsigned interpolate, unsigned location)