[Mesa-dev] Batchbuffer question

Rogovin, Kevin kevin.rogovin at intel.com
Fri Nov 8 04:49:08 PST 2013

Hi all,

 As I was poking into the magicks for the batchbuffer, I saw the following logical bits of code, that make sense by themselves but get me paranoid together. Firstly in intel_batchbuffer_begin() [ intel_batchbuffer.h, and this is what BEGIN_BATCH maps to] there is a intel_batchbuffer_require_space() call that if too much room is needed then calls intel_batchbuffer_begin():

from intel_batchbuffer_require_space():

  115    if (intel_batchbuffer_space(brw) < sz)
  116       intel_batchbuffer_flush(brw);

and from intel_batchbuffer_space():

   80 intel_batchbuffer_space(struct brw_context *brw)
   81 {
   82    return (brw->batch.state_batch_offset - brw->batch.reserved_space)
   83       - brw->batch.used*4;
   84 }

Now, for allocating space for state, there is brw_state_batch():

  128    offset = ROUND_DOWN_TO(batch->state_batch_offset - size, alignment);
  130    /* If allocating from the top would wrap below the batchbuffer, or
  131     * if the batch's used space (plus the reserved pad) collides with our
  132     * space, then flush and try again.
  133     */
  134    if (batch->state_batch_offset < size ||
  135        offset < 4*batch->used + batch->reserved_space) {
  136       intel_batchbuffer_flush(brw);
  137       offset = ROUND_DOWN_TO(batch->state_batch_offset - size, alignment);
  138    }

These taken together, I interpret as meaning that state and commands try to be separated by atleast batch->reserved_space bytes. I guess state could take up more than (batch->bo->size - batch->reserved_space) from that second ROUND_DOWN_TO, but that would only happen right after a flush and any state or command afterwards would flush too.

Now my questions:
  1) it looks like the reserved space is not to be used for either state or commands. Is that correct? What is it used for?

  2) if a function first calls brw_state_batch() to place state and it barely fits and then calls BEGIN_BATCH that does not fit, then the command will refer to an offset on the previous batch buffer, that cannot be good. Or does this never happen for other reasons? If so what are those reasons?


More information about the mesa-dev mailing list