/* invalidate the pipeline */
ilo_3d_pipeline_invalidate(hw3d->pipeline,
ILO_3D_PIPELINE_INVALIDATE_BATCH_BO |
- ILO_3D_PIPELINE_INVALIDATE_STATE_BO);
+ ILO_3D_PIPELINE_INVALIDATE_STATE_BO |
+ ILO_3D_PIPELINE_INVALIDATE_KERNEL_BO);
hw3d->new_batch = true;
}
ilo_3d_destroy(struct ilo_3d *hw3d)
{
ilo_3d_pipeline_destroy(hw3d->pipeline);
-
- if (hw3d->kernel.bo)
- intel_bo_unreference(hw3d->kernel.bo);
-
FREE(hw3d);
}
FREE(restart_info);
}
-static bool
-upload_shaders(struct ilo_3d *hw3d, struct ilo_shader_cache *shc)
-{
- bool incremental = true;
- int upload;
-
- upload = ilo_shader_cache_upload(shc,
- NULL, hw3d->kernel.used, incremental);
- if (!upload)
- return true;
-
- /*
- * Allocate a new bo. When this is a new batch, assume the bo is still in
- * use by the previous batch and force allocation.
- *
- * Does it help to make shader cache upload with unsynchronized mapping,
- * and remove the check for new batch here?
- */
- if (hw3d->kernel.used + upload > hw3d->kernel.size || hw3d->new_batch) {
- unsigned new_size = (hw3d->kernel.size) ?
- hw3d->kernel.size : (8 * 1024);
-
- while (hw3d->kernel.used + upload > new_size)
- new_size *= 2;
-
- if (hw3d->kernel.bo)
- intel_bo_unreference(hw3d->kernel.bo);
-
- hw3d->kernel.bo = intel_winsys_alloc_buffer(hw3d->cp->winsys,
- "kernel bo", new_size, true);
- if (!hw3d->kernel.bo) {
- ilo_err("failed to allocate kernel bo\n");
- return false;
- }
-
- hw3d->kernel.used = 0;
- hw3d->kernel.size = new_size;
- incremental = false;
-
- assert(new_size >= ilo_shader_cache_upload(shc,
- NULL, hw3d->kernel.used, incremental));
-
- ilo_3d_pipeline_invalidate(hw3d->pipeline,
- ILO_3D_PIPELINE_INVALIDATE_KERNEL_BO);
- }
-
- upload = ilo_shader_cache_upload(shc,
- hw3d->kernel.bo, hw3d->kernel.used, incremental);
- if (upload < 0) {
- ilo_err("failed to upload shaders\n");
- return false;
- }
-
- hw3d->kernel.used += upload;
-
- assert(hw3d->kernel.used <= hw3d->kernel.size);
-
- return true;
-}
-
static void
ilo_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
{
ilo_finalize_3d_states(ilo, info);
- if (!upload_shaders(hw3d, ilo->shader_cache))
- return;
+ ilo_shader_cache_upload(ilo->shader_cache, &hw3d->cp->builder);
ilo_blit_resolve_framebuffer(ilo);
bool new_batch;
struct {
- struct intel_bo *bo;
- unsigned used, size;
- } kernel;
-
- struct {
struct pipe_query *query;
unsigned mode;
bool cond;
/* STATE_BASE_ADDRESS */
if (session->state_bo_changed || session->kernel_bo_changed ||
session->batch_bo_changed) {
- const struct ilo_builder_writer *bat =
- &p->cp->builder.writers[ILO_BUILDER_WRITER_BATCH];
-
if (p->dev->gen == ILO_GEN(6))
gen6_wa_pipe_control_post_sync(p, false);
- gen6_emit_STATE_BASE_ADDRESS(p->dev,
- NULL, bat->bo, bat->bo, NULL, ilo->hw3d->kernel.bo,
- 0, 0, 0, 0, p->cp);
+ ilo_builder_batch_state_base_address(&p->cp->builder,
+ session->hw_ctx_changed);
/*
* From the Sandy Bridge PRM, volume 1 part 1, page 28:
gen6_rectlist_wm_multisample(p, blitter, session);
- gen6_emit_STATE_BASE_ADDRESS(p->dev,
- NULL, /* General State Base */
- p->cp->builder.writers[0].bo, /* Surface State Base */
- p->cp->builder.writers[0].bo, /* Dynamic State Base */
- NULL, /* Indirect Object Base */
- NULL, /* Instruction Base */
- 0, 0, 0, 0, p->cp);
+ ilo_builder_batch_state_base_address(&p->cp->builder, true);
gen6_emit_3DSTATE_VERTEX_BUFFERS(p->dev,
&blitter->ve, &blitter->vb, p->cp);
{
gen7_rectlist_wm_multisample(p, blitter, session);
- gen6_emit_STATE_BASE_ADDRESS(p->dev,
- NULL, /* General State Base */
- p->cp->builder.writers[0].bo, /* Surface State Base */
- p->cp->builder.writers[0].bo, /* Dynamic State Base */
- NULL, /* Indirect Object Base */
- NULL, /* Instruction Base */
- 0, 0, 0, 0, p->cp);
+ ilo_builder_batch_state_base_address(&p->cp->builder, true);
gen6_emit_3DSTATE_VERTEX_BUFFERS(p->dev,
&blitter->ve, &blitter->vb, p->cp);
util_slab_create(&ilo->transfer_mempool,
sizeof(struct ilo_transfer), 64, UTIL_SLAB_SINGLETHREADED);
- ilo->cp = ilo_cp_create(ilo->dev, ilo->winsys);
ilo->shader_cache = ilo_shader_cache_create();
+ ilo->cp = ilo_cp_create(ilo->dev, ilo->winsys, ilo->shader_cache);
if (ilo->cp)
ilo->hw3d = ilo_3d_create(ilo->cp, ilo->dev);
#include "intel_winsys.h"
+#include "ilo_shader.h"
#include "ilo_cp.h"
static struct intel_bo *
ilo_cp_end_batch(struct ilo_cp *cp, unsigned *used)
{
+ struct intel_bo *bo;
+
ilo_cp_set_owner(cp, NULL, 0);
if (!ilo_builder_batch_used(&cp->builder)) {
assert(ilo_builder_batch_space(&cp->builder) >= 2);
ilo_builder_batch_mi_batch_buffer_end(&cp->builder);
- return ilo_builder_end(&cp->builder, used);
+ bo = ilo_builder_end(&cp->builder, used);
+
+ /* we have to assume that kernel uploads also failed */
+ if (!bo)
+ ilo_shader_cache_invalidate(cp->shader_cache);
+
+ return bo;
}
/**
* Create a command parser.
*/
struct ilo_cp *
-ilo_cp_create(const struct ilo_dev_info *dev, struct intel_winsys *winsys)
+ilo_cp_create(const struct ilo_dev_info *dev,
+ struct intel_winsys *winsys,
+ struct ilo_shader_cache *shc)
{
struct ilo_cp *cp;
return NULL;
cp->winsys = winsys;
+ cp->shader_cache = shc;
cp->render_ctx = intel_winsys_create_context(winsys);
if (!cp->render_ctx) {
FREE(cp);
#include "ilo_common.h"
struct ilo_cp;
+struct ilo_shader_cache;
typedef void (*ilo_cp_callback)(struct ilo_cp *cp, void *data);
*/
struct ilo_cp {
struct intel_winsys *winsys;
+ struct ilo_shader_cache *shader_cache;
struct intel_context *render_ctx;
ilo_cp_callback flush_callback;
};
struct ilo_cp *
-ilo_cp_create(const struct ilo_dev_info *dev, struct intel_winsys *winsys);
+ilo_cp_create(const struct ilo_dev_info *dev,
+ struct intel_winsys *winsys,
+ struct ilo_shader_cache *shc);
void
ilo_cp_destroy(struct ilo_cp *cp);
#include "intel_winsys.h"
#include "shader/ilo_shader_internal.h"
+#include "ilo_builder.h"
#include "ilo_state.h"
#include "ilo_shader.h"
}
/**
- * Upload a managed shader to the bo.
+ * Upload managed shaders to the bo. Only shaders that are changed or added
+ * after the last upload are uploaded.
*/
-static int
-ilo_shader_cache_upload_shader(struct ilo_shader_cache *shc,
- struct ilo_shader_state *shader,
- struct intel_bo *bo, unsigned offset,
- bool incremental)
+void
+ilo_shader_cache_upload(struct ilo_shader_cache *shc,
+ struct ilo_builder *builder)
{
- const unsigned base = offset;
- struct ilo_shader *sh;
-
- LIST_FOR_EACH_ENTRY(sh, &shader->variants, list) {
- int err;
-
- if (incremental && sh->uploaded)
- continue;
-
- /* kernels must be aligned to 64-byte */
- offset = align(offset, 64);
-
- err = intel_bo_pwrite(bo, offset, sh->kernel_size, sh->kernel);
- if (unlikely(err))
- return -1;
-
- sh->uploaded = true;
- sh->cache_offset = offset;
-
- offset += sh->kernel_size;
- }
+ struct ilo_shader_state *shader, *next;
- return (int) (offset - base);
-}
+ LIST_FOR_EACH_ENTRY_SAFE(shader, next, &shc->changed, list) {
+ struct ilo_shader *sh;
-/**
- * Similar to ilo_shader_cache_upload(), except no upload happens.
- */
-static int
-ilo_shader_cache_get_upload_size(struct ilo_shader_cache *shc,
- unsigned offset,
- bool incremental)
-{
- const unsigned base = offset;
- struct ilo_shader_state *shader;
+ LIST_FOR_EACH_ENTRY(sh, &shader->variants, list) {
+ if (sh->uploaded)
+ continue;
- if (!incremental) {
- LIST_FOR_EACH_ENTRY(shader, &shc->shaders, list) {
- struct ilo_shader *sh;
+ sh->cache_offset = ilo_builder_instruction_write(builder,
+ sh->kernel_size, sh->kernel);
- /* see ilo_shader_cache_upload_shader() */
- LIST_FOR_EACH_ENTRY(sh, &shader->variants, list) {
- if (!incremental || !sh->uploaded)
- offset = align(offset, 64) + sh->kernel_size;
- }
+ sh->uploaded = true;
}
- }
-
- LIST_FOR_EACH_ENTRY(shader, &shc->changed, list) {
- struct ilo_shader *sh;
- /* see ilo_shader_cache_upload_shader() */
- LIST_FOR_EACH_ENTRY(sh, &shader->variants, list) {
- if (!incremental || !sh->uploaded)
- offset = align(offset, 64) + sh->kernel_size;
- }
+ list_del(&shader->list);
+ list_add(&shader->list, &shc->shaders);
}
-
- /*
- * From the Sandy Bridge PRM, volume 4 part 2, page 112:
- *
- * "Due to prefetch of the instruction stream, the EUs may attempt to
- * access up to 8 instructions (128 bytes) beyond the end of the
- * kernel program - possibly into the next memory page. Although
- * these instructions will not be executed, software must account for
- * the prefetch in order to avoid invalid page access faults."
- */
- if (offset > base)
- offset += 128;
-
- return (int) (offset - base);
}
/**
- * Upload managed shaders to the bo. When incremental is true, only shaders
- * that are changed or added after the last upload are uploaded.
+ * Invalidate all shaders so that they get uploaded in next
+ * ilo_shader_cache_upload().
*/
-int
-ilo_shader_cache_upload(struct ilo_shader_cache *shc,
- struct intel_bo *bo, unsigned offset,
- bool incremental)
+void
+ilo_shader_cache_invalidate(struct ilo_shader_cache *shc)
{
struct ilo_shader_state *shader, *next;
- int size = 0, s;
- if (!bo)
- return ilo_shader_cache_get_upload_size(shc, offset, incremental);
-
- if (!incremental) {
- LIST_FOR_EACH_ENTRY(shader, &shc->shaders, list) {
- s = ilo_shader_cache_upload_shader(shc, shader,
- bo, offset, incremental);
- if (unlikely(s < 0))
- return s;
-
- size += s;
- offset += s;
- }
+ LIST_FOR_EACH_ENTRY_SAFE(shader, next, &shc->shaders, list) {
+ list_del(&shader->list);
+ list_add(&shader->list, &shc->changed);
}
- LIST_FOR_EACH_ENTRY_SAFE(shader, next, &shc->changed, list) {
- s = ilo_shader_cache_upload_shader(shc, shader,
- bo, offset, incremental);
- if (unlikely(s < 0))
- return s;
-
- size += s;
- offset += s;
+ LIST_FOR_EACH_ENTRY(shader, &shc->changed, list) {
+ struct ilo_shader *sh;
- list_del(&shader->list);
- list_add(&shader->list, &shc->shaders);
+ LIST_FOR_EACH_ENTRY(sh, &shader->variants, list)
+ sh->uploaded = false;
}
-
- return size;
}
/**
};
struct intel_bo;
+struct ilo_builder;
struct ilo_context;
struct ilo_rasterizer_state;
struct ilo_shader_cache;
ilo_shader_cache_remove(struct ilo_shader_cache *shc,
struct ilo_shader_state *shader);
-int
+void
ilo_shader_cache_upload(struct ilo_shader_cache *shc,
- struct intel_bo *bo, unsigned offset,
- bool incremental);
+ struct ilo_builder *builder);
+
+void
+ilo_shader_cache_invalidate(struct ilo_shader_cache *shc);
struct ilo_shader_state *
ilo_shader_create_vs(const struct ilo_dev_info *dev,