*
**************************************************************************/
+#include "util/u_memory.h"
+
#include "brw_batchbuffer.h"
-#include "brw_decode.h"
#include "brw_reg.h"
#include "brw_winsys.h"
+#include "brw_debug.h"
+#include "brw_structs.h"
+#define ALWAYS_EMIT_MI_FLUSH 1
-void
+enum pipe_error
brw_batchbuffer_reset(struct brw_batchbuffer *batch)
{
- struct intel_context *intel = batch->intel;
+ enum pipe_error ret;
- if (batch->buf != NULL) {
- brw->sws->bo_unreference(batch->buf);
- batch->buf = NULL;
- }
+ ret = batch->sws->bo_alloc( batch->sws,
+ BRW_BUFFER_TYPE_BATCH,
+ BRW_BATCH_SIZE, 4096,
+ &batch->buf );
+ if (ret)
+ return ret;
+
+ batch->size = BRW_BATCH_SIZE;
+
+ /* With map_range semantics, the winsys can decide whether to
+ * inject a malloc'ed bounce buffer instead of mapping directly.
+ */
+ batch->map = batch->sws->bo_map(batch->buf,
+ BRW_DATA_BATCH_BUFFER,
+ 0, batch->size,
+ GL_TRUE,
+ GL_TRUE,
+ GL_TRUE);
- if (!batch->buffer && intel->ttm == GL_TRUE)
- batch->buffer = malloc (intel->maxBatchSize);
-
- batch->buf = batch->sws->bo_alloc(batch->sws,
- BRW_BUFFER_TYPE_BATCH,
- intel->maxBatchSize, 4096);
- if (batch->buffer)
- batch->map = batch->buffer;
- else {
- batch->sws->bo_map(batch->buf, GL_TRUE);
- batch->map = batch->buf->virtual;
- }
- batch->size = intel->maxBatchSize;
batch->ptr = batch->map;
- batch->dirty_state = ~0;
- batch->cliprect_mode = IGNORE_CLIPRECTS;
+ return PIPE_OK;
}
struct brw_batchbuffer *
-brw_batchbuffer_alloc(struct brw_winsys_screen *sws)
+brw_batchbuffer_alloc(struct brw_winsys_screen *sws,
+ struct brw_chipset chipset)
{
struct brw_batchbuffer *batch = CALLOC_STRUCT(brw_batchbuffer);
batch->sws = sws;
+ batch->chipset = chipset;
brw_batchbuffer_reset(batch);
return batch;
brw_batchbuffer_free(struct brw_batchbuffer *batch)
{
if (batch->map) {
- dri_bo_unmap(batch->buf);
+ batch->sws->bo_unmap(batch->buf);
batch->map = NULL;
}
- brw->sws->bo_unreference(batch->buf);
- batch->buf = NULL;
+ bo_reference(&batch->buf, NULL);
FREE(batch);
}
void
-_brw_batchbuffer_flush(struct brw_batchbuffer *batch, const char *file,
- int line)
+_brw_batchbuffer_flush(struct brw_batchbuffer *batch,
+ const char *file,
+ int line)
{
- struct intel_context *intel = batch->intel;
GLuint used = batch->ptr - batch->map;
if (used == 0)
return;
- if (intel->first_post_swapbuffers_batch == NULL) {
- intel->first_post_swapbuffers_batch = intel->batch->buf;
- batch->sws->bo_reference(intel->first_post_swapbuffers_batch);
- }
-
- if (intel->first_post_swapbuffers_batch == NULL) {
- intel->first_post_swapbuffers_batch = intel->batch->buf;
- batch->sws->bo_reference(intel->first_post_swapbuffers_batch);
- }
-
+ /* Post-swap throttling done by the state tracker.
+ */
if (BRW_DEBUG & DEBUG_BATCH)
- debug_printf("%s:%d: Batchbuffer flush with %db used\n", file, line,
- used);
+ debug_printf("%s:%d: Batchbuffer flush with %db used\n",
+ file, line, used);
- /* Emit a flush if the bufmgr doesn't do it for us. */
- if (intel->always_flush_cache || !intel->ttm) {
- *(GLuint *) (batch->ptr) = ((CMD_MI_FLUSH << 16) | BRW_FLUSH_STATE_CACHE);
+ if (ALWAYS_EMIT_MI_FLUSH) {
+ *(GLuint *) (batch->ptr) = MI_FLUSH | BRW_FLUSH_STATE_CACHE;
batch->ptr += 4;
used = batch->ptr - batch->map;
}
- /* Round batchbuffer usage to 2 DWORDs. */
-
+ /* Round batchbuffer usage to 2 DWORDs.
+ */
if ((used & 4) == 0) {
*(GLuint *) (batch->ptr) = 0; /* noop */
batch->ptr += 4;
used = batch->ptr - batch->map;
}
- /* Mark the end of the buffer. */
- *(GLuint *) (batch->ptr) = MI_BATCH_BUFFER_END; /* noop */
+ /* Mark the end of the buffer.
+ */
+ *(GLuint *) (batch->ptr) = MI_BATCH_BUFFER_END;
batch->ptr += 4;
used = batch->ptr - batch->map;
+ batch->sws->bo_flush_range(batch->buf, 0, used);
batch->sws->bo_unmap(batch->buf);
-
batch->map = NULL;
batch->ptr = NULL;
- batch->sws->bo_exec(batch->buf, used, NULL, 0, 0 );
-
- if (BRW_DEBUG & DEBUG_BATCH) {
- dri_bo_map(batch->buf, GL_FALSE);
- intel_decode(batch->buf->virtual, used / 4, batch->buf->offset,
- brw->brw_screen->pci_id);
- dri_bo_unmap(batch->buf);
- }
+ batch->sws->bo_exec(batch->buf, used );
if (BRW_DEBUG & DEBUG_SYNC) {
+ /* Abuse map/unmap to achieve wait-for-fence.
+ *
+ * XXX: hide this inside the winsys and export a fence
+ * interface.
+ */
debug_printf("waiting for idle\n");
- dri_bo_map(batch->buf, GL_TRUE);
- dri_bo_unmap(batch->buf);
+ batch->sws->bo_wait_idle(batch->buf);
}
/* Reset the buffer:
}
-/* This is the only way buffers get added to the validate list.
+/* The OUT_RELOC() macro ends up here, generating a relocation within
+ * the batch buffer.
*/
-GLboolean
+enum pipe_error
brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
- struct brw_winsys_buffer *buffer,
- uint32_t read_domains, uint32_t write_domain,
- uint32_t delta)
+ struct brw_winsys_buffer *buffer,
+ enum brw_buffer_usage usage,
+ uint32_t delta)
{
int ret;
- if (batch->ptr - batch->map > batch->buf->size)
- debug_printf ("bad relocation ptr %p map %p offset %d size %d\n",
- batch->ptr, batch->map, batch->ptr - batch->map, batch->buf->size);
+ if (batch->ptr - batch->map > batch->buf->size) {
+ debug_printf("bad relocation ptr %p map %p offset %li size %i\n",
+ batch->ptr, batch->map, (long) (batch->ptr - batch->map), batch->buf->size);
+
+ return PIPE_ERROR_OUT_OF_MEMORY;
+ }
ret = batch->sws->bo_emit_reloc(batch->buf,
- read_domains,
- write_domain,
+ usage,
delta,
batch->ptr - batch->map,
buffer);
+ if (ret != 0)
+ return ret;
- /*
- * Using the old buffer offset, write in what the right data would be, in case
- * the buffer doesn't move and we can short-circuit the relocation processing
- * in the kernel
+ /* bo_emit_reloc was resposible for writing a zero into the
+ * batchbuffer if necessary. Just need to update our pointer.
*/
- brw_batchbuffer_emit_dword (batch, buffer->offset + delta);
+ batch->ptr += 4;
- return GL_TRUE;
+ return 0;
}
-void
+enum pipe_error
brw_batchbuffer_data(struct brw_batchbuffer *batch,
const void *data, GLuint bytes,
enum cliprect_mode cliprect_mode)
{
+ enum pipe_error ret;
+
assert((bytes & 3) == 0);
- brw_batchbuffer_require_space(batch, bytes);
- __memcpy(batch->ptr, data, bytes);
+
+ ret = brw_batchbuffer_require_space(batch, bytes);
+ if (ret)
+ return ret;
+
+ memcpy(batch->ptr, data, bytes);
batch->ptr += bytes;
+ return 0;
}