[Mesa-dev] [PATCH 1/6] radeonsi: extract IB and bo list saving into separate functions

Ilia Mirkin imirkin at alum.mit.edu
Thu Jun 23 02:29:14 UTC 2016


On Wed, Jun 22, 2016 at 6:01 AM, Michael Schellenberger Costa
<mschellenbergercosta at googlemail.com> wrote:
> Hi Nicolai
>
> Am 22.06.2016 um 11:40 schrieb Nicolai Hähnle:
>> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>>
>> ---
>>  src/gallium/drivers/radeon/r600_pipe_common.c | 53 +++++++++++++++++++++++++++
>>  src/gallium/drivers/radeon/r600_pipe_common.h | 12 ++++++
>>  src/gallium/drivers/radeonsi/si_debug.c       | 39 +++++++++-----------
>>  src/gallium/drivers/radeonsi/si_hw_context.c  | 25 +------------
>>  src/gallium/drivers/radeonsi/si_pipe.c        |  8 +---
>>  src/gallium/drivers/radeonsi/si_pipe.h        |  5 +--
>>  6 files changed, 88 insertions(+), 54 deletions(-)
>>
>> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
>> index fa9f70d..ee70a1a 100644
>> --- a/src/gallium/drivers/radeon/r600_pipe_common.c
>> +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
>> @@ -302,6 +302,59 @@ static void r600_flush_dma_ring(void *ctx, unsigned flags,
>>               rctx->ws->fence_reference(fence, rctx->last_sdma_fence);
>>  }
>>
>> +/**
>> + * Store a linearized copy of all chunks of \p cs together with the buffer
>> + * list in \p saved.
>> + */
>> +void radeon_save_cs(struct radeon_winsys *ws, struct radeon_winsys_cs *cs,
>> +                 struct radeon_saved_cs *saved)
>> +{
>> +     void *buf;
>> +     unsigned i;
>> +
>> +     /* Save the IB chunks. */
>> +     saved->num_dw = cs->prev_dw + cs->current.cdw;
>> +     saved->ib = MALLOC(4 * saved->num_dw);
>> +     if (!saved->ib)
>> +             goto oom;
>> +
>> +     buf = saved->ib;
>> +     for (i = 0; i < cs->num_prev; ++i) {
>> +             memcpy(buf, cs->prev[i].buf, cs->prev[i].cdw * 4);
>> +             buf += cs->prev[i].cdw;
>> +     }
>> +     memcpy(buf, cs->current.buf, cs->current.cdw * 4);
>> +
>> +     /* Save the buffer list. */
>> +     saved->bo_count = ws->cs_get_buffer_list(cs, NULL);
>> +     saved->bo_list = CALLOC(saved->bo_count,
>> +                             sizeof(saved->bo_list[0]));
>> +     if (!saved->bo_list) {
>> +             FREE(saved->ib);
>> +             goto oom;
>> +     }
>> +     ws->cs_get_buffer_list(cs, saved->bo_list);
>> +
>> +     return;
>> +
>> +oom:
>> +     fprintf(stderr, "%s: out of memory\n", __func__);
>> +     memset(saved, 0, sizeof(*saved));
> Is that Goto really worth it? It costs you one extra line of code and
> obfuscates things.

goto is a pretty common way to do error handling in C. This is
perfectly fine, and, in fact, preferable to an alternative that
duplicates the code.

  -ilia


More information about the mesa-dev mailing list