summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2011-02-26 21:15:58 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2011-02-26 21:15:58 +0100
commit8dc02e193cedf20ed628daa57c5f937ca410c7c8 (patch)
treebf301c51126859d3fb8793eafe3a95ce14e66f95
parentcc71a98d94a71b44eb0c96d2532ac5df4bd94934 (diff)
i915g: buffer validation for render state
Also contains the first few bits for hw state atoms. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--src/gallium/drivers/i915/i915_batchbuffer.h8
-rw-r--r--src/gallium/drivers/i915/i915_context.h3
-rw-r--r--src/gallium/drivers/i915/i915_state_emit.c82
3 files changed, 93 insertions, 0 deletions
diff --git a/src/gallium/drivers/i915/i915_batchbuffer.h b/src/gallium/drivers/i915/i915_batchbuffer.h
index d92b2ccb31..b4a91dabb3 100644
--- a/src/gallium/drivers/i915/i915_batchbuffer.h
+++ b/src/gallium/drivers/i915/i915_batchbuffer.h
@@ -75,6 +75,14 @@ i915_winsys_batchbuffer_write(struct i915_winsys_batchbuffer *batch,
batch->ptr += size;
}
+static INLINE boolean
+i915_winsys_validate_buffers(struct i915_winsys_batchbuffer *batch,
+ struct i915_winsys_buffer **buffers,
+ int num_of_buffers)
+{
+ return batch->iws->validate_buffers(batch, buffers, num_of_buffers);
+}
+
static INLINE int
i915_winsys_batchbuffer_reloc(struct i915_winsys_batchbuffer *batch,
struct i915_winsys_buffer *buffer,
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h
index 2cf53424f0..e77641149b 100644
--- a/src/gallium/drivers/i915/i915_context.h
+++ b/src/gallium/drivers/i915/i915_context.h
@@ -238,6 +238,9 @@ struct i915_context {
unsigned immediate_dirty;
unsigned dynamic_dirty;
+ struct i915_winsys_buffer *validation_buffers[2 + 1 + I915_TEX_UNITS];
+ int num_validation_buffers;
+
struct util_slab_mempool transfer_pool;
};
diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c
index 1c77de1acc..29001bc0b5 100644
--- a/src/gallium/drivers/i915/i915_state_emit.c
+++ b/src/gallium/drivers/i915/i915_state_emit.c
@@ -36,6 +36,14 @@
#include "pipe/p_defines.h"
#include "util/u_math.h"
+#include "util/u_memory.h"
+
+struct i915_tracked_hw_state {
+ const char *name;
+ void (*update)(struct i915_context *);
+ void (*emit)(struct i915_context *);
+ unsigned dirty;
+};
static unsigned translate_format( enum pipe_format format )
{
@@ -105,6 +113,74 @@ buf_3d_tiling_bits(enum i915_winsys_buffer_tile tiling)
return tiling_bits;
}
+static void
+update_immediate(struct i915_context *i915)
+{
+ if (i915->immediate_dirty & (1 << I915_IMMEDIATE_S0))
+ i915->validation_buffers[i915->num_validation_buffers++] = i915->vbo;
+}
+
+static void
+update_static(struct i915_context *i915)
+{
+ struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
+ struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;
+ struct i915_texture *tex;
+
+ if (cbuf_surface) {
+ tex = i915_texture(cbuf_surface->texture);
+ i915->validation_buffers[i915->num_validation_buffers++] = tex->buffer;
+ }
+
+ if (depth_surface) {
+ tex = i915_texture(depth_surface->texture);
+ i915->validation_buffers[i915->num_validation_buffers++] = tex->buffer;
+ }
+}
+
+static void
+update_map(struct i915_context *i915)
+{
+ const uint enabled = i915->current.sampler_enable_flags;
+ uint unit;
+ struct i915_texture *tex;
+
+
+ for (unit = 0; unit < I915_TEX_UNITS; unit++) {
+ if (enabled & (1 << unit)) {
+ tex = i915_texture(i915->fragment_sampler_views[unit]->texture);
+ i915->validation_buffers[i915->num_validation_buffers++] = tex->buffer;
+ }
+ }
+}
+
+const static struct i915_tracked_hw_state hw_atoms[] = {
+ { "immediate", update_immediate, NULL, I915_HW_IMMEDIATE },
+ { "static", update_static, NULL, I915_HW_STATIC },
+ { "map", update_map, NULL, I915_HW_MAP }
+};
+
+static boolean
+i915_validate_state(struct i915_context *i915)
+{
+ int i;
+
+ i915->num_validation_buffers = 0;
+
+ for (i = 0; i < Elements(hw_atoms); i++)
+ if ((i915->hardware_dirty & hw_atoms[i].dirty) && hw_atoms[i].update)
+ hw_atoms[i].update(i915);
+
+ if (i915->num_validation_buffers == 0)
+ return TRUE;
+
+ if (!i915_winsys_validate_buffers(i915->batch, i915->validation_buffers,
+ i915->num_validation_buffers))
+ return FALSE;
+
+ return TRUE;
+}
+
/* Push the state into the sarea and/or texture memory.
*/
void
@@ -135,8 +211,14 @@ i915_emit_hardware_state(struct i915_context *i915 )
if (I915_DBG_ON(DBG_ATOMS))
i915_dump_hardware_dirty(i915, __FUNCTION__);
+ if (!i915_validate_state(i915)) {
+ FLUSH_BATCH(NULL);
+ assert(i915_validate_state(i915));
+ }
+
if(!BEGIN_BATCH(dwords, relocs)) {
FLUSH_BATCH(NULL);
+ assert(i915_validate_state(i915));
assert(BEGIN_BATCH(dwords, relocs));
}