iris: Track a binding history for buffer resources

This will let us know what caches to flush / state to dirty when
altering the contents of a buffer.
This commit is contained in:
Kenneth Graunke
2018-11-21 00:38:49 -08:00
parent f49f506b13
commit d169747a3e
3 changed files with 31 additions and 3 deletions

View File

@@ -489,9 +489,12 @@ iris_get_query_result_resource(struct pipe_context *ctx,
struct iris_query *q = (void *) query; struct iris_query *q = (void *) query;
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER]; struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
const struct gen_device_info *devinfo = &batch->screen->devinfo; const struct gen_device_info *devinfo = &batch->screen->devinfo;
struct iris_resource *res = (void *) p_res;
unsigned snapshots_landed_offset = unsigned snapshots_landed_offset =
offsetof(struct iris_query_snapshots, snapshots_landed); offsetof(struct iris_query_snapshots, snapshots_landed);
res->bind_history |= PIPE_BIND_QUERY_BUFFER;
if (index == -1) { if (index == -1) {
/* They're asking for the availability of the result. If we still /* They're asking for the availability of the result. If we still
* have commands queued up which produce the result, submit them * have commands queued up which produce the result, submit them

View File

@@ -46,6 +46,12 @@ struct iris_resource {
enum pipe_format internal_format; enum pipe_format internal_format;
struct isl_surf surf; struct isl_surf surf;
struct iris_bo *bo; struct iris_bo *bo;
/**
* A bitfield of PIPE_BIND_* indicating how this resource was bound
* in the past. Only meaningful for PIPE_BUFFER; used for flushing.
*/
unsigned bind_history;
}; };
/** /**

View File

@@ -1672,6 +1672,8 @@ iris_set_shader_images(struct pipe_context *ctx,
struct iris_resource *res = (void *) img->resource; struct iris_resource *res = (void *) img->resource;
pipe_resource_reference(&shs->image[start_slot + i].res, &res->base); pipe_resource_reference(&shs->image[start_slot + i].res, &res->base);
res->bind_history |= PIPE_BIND_SHADER_IMAGE;
// XXX: these are not retained forever, use a separate uploader? // XXX: these are not retained forever, use a separate uploader?
void *map = void *map =
upload_state(ice->state.surface_uploader, upload_state(ice->state.surface_uploader,
@@ -1746,6 +1748,9 @@ iris_set_sampler_views(struct pipe_context *ctx,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
pipe_sampler_view_reference((struct pipe_sampler_view **) pipe_sampler_view_reference((struct pipe_sampler_view **)
&shs->textures[i], views[i]); &shs->textures[i], views[i]);
struct iris_sampler_view *view = (void *) views[i];
if (view)
view->res->bind_history |= PIPE_BIND_SAMPLER_VIEW;
} }
for (; i < shs->num_textures; i++) { for (; i < shs->num_textures; i++) {
pipe_sampler_view_reference((struct pipe_sampler_view **) pipe_sampler_view_reference((struct pipe_sampler_view **)
@@ -2181,6 +2186,9 @@ iris_set_constant_buffer(struct pipe_context *ctx,
pipe_resource_reference(&cbuf->data.res, input->buffer); pipe_resource_reference(&cbuf->data.res, input->buffer);
cbuf->data.offset = input->buffer_offset; cbuf->data.offset = input->buffer_offset;
struct iris_resource *res = (void *) cbuf->data.res;
res->bind_history |= PIPE_BIND_CONSTANT_BUFFER;
upload_ubo_surf_state(ice, cbuf, input->buffer_size); upload_ubo_surf_state(ice, cbuf, input->buffer_size);
} else { } else {
pipe_resource_reference(&cbuf->data.res, NULL); pipe_resource_reference(&cbuf->data.res, NULL);
@@ -2265,6 +2273,8 @@ iris_set_shader_buffers(struct pipe_context *ctx,
struct iris_resource *res = (void *) buffer->buffer; struct iris_resource *res = (void *) buffer->buffer;
pipe_resource_reference(&shs->ssbo[start_slot + i], &res->base); pipe_resource_reference(&shs->ssbo[start_slot + i], &res->base);
res->bind_history |= PIPE_BIND_SHADER_BUFFER;
// XXX: these are not retained forever, use a separate uploader? // XXX: these are not retained forever, use a separate uploader?
void *map = void *map =
upload_state(ice->state.surface_uploader, upload_state(ice->state.surface_uploader,
@@ -2352,6 +2362,9 @@ iris_set_vertex_buffers(struct pipe_context *ctx,
pipe_resource_reference(&cso->resources[i], buffers[i].buffer.resource); pipe_resource_reference(&cso->resources[i], buffers[i].buffer.resource);
struct iris_resource *res = (void *) cso->resources[i]; struct iris_resource *res = (void *) cso->resources[i];
if (res)
res->bind_history |= PIPE_BIND_VERTEX_BUFFER;
iris_pack_state(GENX(VERTEX_BUFFER_STATE), vb_pack_dest, vb) { iris_pack_state(GENX(VERTEX_BUFFER_STATE), vb_pack_dest, vb) {
vb.VertexBufferIndex = start_slot + i; vb.VertexBufferIndex = start_slot + i;
vb.MOCS = MOCS_WB; vb.MOCS = MOCS_WB;
@@ -2507,16 +2520,19 @@ struct iris_stream_output_target {
*/ */
static struct pipe_stream_output_target * static struct pipe_stream_output_target *
iris_create_stream_output_target(struct pipe_context *ctx, iris_create_stream_output_target(struct pipe_context *ctx,
struct pipe_resource *res, struct pipe_resource *p_res,
unsigned buffer_offset, unsigned buffer_offset,
unsigned buffer_size) unsigned buffer_size)
{ {
struct iris_resource *res = (void *) p_res;
struct iris_stream_output_target *cso = calloc(1, sizeof(*cso)); struct iris_stream_output_target *cso = calloc(1, sizeof(*cso));
if (!cso) if (!cso)
return NULL; return NULL;
res->bind_history |= PIPE_BIND_STREAM_OUTPUT;
pipe_reference_init(&cso->base.reference, 1); pipe_reference_init(&cso->base.reference, 1);
pipe_resource_reference(&cso->base.buffer, res); pipe_resource_reference(&cso->base.buffer, p_res);
cso->base.buffer_offset = buffer_offset; cso->base.buffer_offset = buffer_offset;
cso->base.buffer_size = buffer_size; cso->base.buffer_size = buffer_size;
cso->base.context = ctx; cso->base.context = ctx;
@@ -2525,7 +2541,7 @@ iris_create_stream_output_target(struct pipe_context *ctx,
iris_pack_command(GENX(3DSTATE_SO_BUFFER), cso->so_buffer, sob) { iris_pack_command(GENX(3DSTATE_SO_BUFFER), cso->so_buffer, sob) {
sob.SurfaceBaseAddress = sob.SurfaceBaseAddress =
rw_bo(NULL, iris_resource_bo(res)->gtt_offset + buffer_offset); rw_bo(NULL, res->bo->gtt_offset + buffer_offset);
sob.SOBufferEnable = true; sob.SOBufferEnable = true;
sob.StreamOffsetWriteEnable = true; sob.StreamOffsetWriteEnable = true;
sob.StreamOutputBufferOffsetAddressEnable = true; sob.StreamOutputBufferOffsetAddressEnable = true;
@@ -4436,6 +4452,9 @@ iris_upload_render_state(struct iris_context *ice,
draw->count * draw->index_size, 4, draw->index.user, draw->count * draw->index_size, 4, draw->index.user,
&offset, &ice->state.last_res.index_buffer); &offset, &ice->state.last_res.index_buffer);
} else { } else {
struct iris_resource *res = (void *) draw->index.resource;
res->bind_history |= PIPE_BIND_INDEX_BUFFER;
pipe_resource_reference(&ice->state.last_res.index_buffer, pipe_resource_reference(&ice->state.last_res.index_buffer,
draw->index.resource); draw->index.resource);
offset = 0; offset = 0;