iris: Use state_refs for draw parameters.

iris_state_ref is a <resource, offset> tuple, which is exactly what we
need here.
This commit is contained in:
Kenneth Graunke 2019-09-18 20:12:33 -07:00
parent ddd314f0ce
commit 6841f11d14
3 changed files with 21 additions and 23 deletions

View File

@ -555,8 +555,7 @@ struct iris_context {
* buffer or to the buffer that stures the previous values for non * buffer or to the buffer that stures the previous values for non
* indirect draws. * indirect draws.
*/ */
struct pipe_resource *draw_params_res; struct iris_state_ref draw_params;
uint32_t draw_params_offset;
struct { struct {
/** /**
@ -577,8 +576,7 @@ struct iris_context {
* contains parameters that are not present in the indirect buffer as * contains parameters that are not present in the indirect buffer as
* drawid and is_indexed_draw. They will go in their own vertex element. * drawid and is_indexed_draw. They will go in their own vertex element.
*/ */
struct pipe_resource *derived_draw_params_res; struct iris_state_ref derived_draw_params;
uint32_t derived_draw_params_offset;
bool is_indirect; bool is_indirect;
} draw; } draw;

View File

@ -114,9 +114,9 @@ iris_update_draw_parameters(struct iris_context *ice,
const struct pipe_draw_info *info) const struct pipe_draw_info *info)
{ {
if (info->indirect) { if (info->indirect) {
pipe_resource_reference(&ice->draw.draw_params_res, pipe_resource_reference(&ice->draw.draw_params.res,
info->indirect->buffer); info->indirect->buffer);
ice->draw.draw_params_offset = info->indirect->offset + ice->draw.draw_params.offset = info->indirect->offset +
(info->index_size ? 12 : 8); (info->index_size ? 12 : 8);
ice->draw.params.firstvertex = 0; ice->draw.params.firstvertex = 0;
ice->draw.params.baseinstance = 0; ice->draw.params.baseinstance = 0;
@ -127,8 +127,8 @@ iris_update_draw_parameters(struct iris_context *ice,
ice->draw.params.firstvertex != ice->draw.params.firstvertex !=
(info->index_size ? info->index_bias : info->start) || (info->index_size ? info->index_bias : info->start) ||
(ice->draw.params.baseinstance != info->start_instance)) { (ice->draw.params.baseinstance != info->start_instance)) {
pipe_resource_reference(&ice->draw.draw_params_res, NULL); pipe_resource_reference(&ice->draw.draw_params.res, NULL);
ice->draw.draw_params_offset = 0; ice->draw.draw_params.offset = 0;
ice->draw.params.firstvertex = ice->draw.params.firstvertex =
info->index_size ? info->index_bias : info->start; info->index_size ? info->index_bias : info->start;
ice->draw.params.baseinstance = info->start_instance; ice->draw.params.baseinstance = info->start_instance;

View File

@ -5293,26 +5293,26 @@ iris_upload_dirty_render_state(struct iris_context *ice,
int dynamic_bound = ice->state.bound_vertex_buffers; int dynamic_bound = ice->state.bound_vertex_buffers;
if (ice->state.vs_uses_draw_params) { if (ice->state.vs_uses_draw_params) {
if (ice->draw.draw_params_offset == 0) { if (ice->draw.draw_params.offset == 0) {
u_upload_data(ice->ctx.stream_uploader, 0, sizeof(ice->draw.params), u_upload_data(ice->ctx.stream_uploader, 0, sizeof(ice->draw.params),
4, &ice->draw.params, &ice->draw.draw_params_offset, 4, &ice->draw.params, &ice->draw.draw_params.offset,
&ice->draw.draw_params_res); &ice->draw.draw_params.res);
} }
assert(ice->draw.draw_params_res); assert(ice->draw.draw_params.res);
struct iris_vertex_buffer_state *state = struct iris_vertex_buffer_state *state =
&(ice->state.genx->vertex_buffers[count]); &(ice->state.genx->vertex_buffers[count]);
pipe_resource_reference(&state->resource, ice->draw.draw_params_res); pipe_resource_reference(&state->resource, ice->draw.draw_params.res);
struct iris_resource *res = (void *) state->resource; struct iris_resource *res = (void *) state->resource;
iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) { iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) {
vb.VertexBufferIndex = count; vb.VertexBufferIndex = count;
vb.AddressModifyEnable = true; vb.AddressModifyEnable = true;
vb.BufferPitch = 0; vb.BufferPitch = 0;
vb.BufferSize = res->bo->size - ice->draw.draw_params_offset; vb.BufferSize = res->bo->size - ice->draw.draw_params.offset;
vb.BufferStartingAddress = vb.BufferStartingAddress =
ro_bo(NULL, res->bo->gtt_offset + ro_bo(NULL, res->bo->gtt_offset +
(int) ice->draw.draw_params_offset); (int) ice->draw.draw_params.offset);
vb.MOCS = mocs(res->bo); vb.MOCS = mocs(res->bo);
} }
dynamic_bound |= 1ull << count; dynamic_bound |= 1ull << count;
@ -5323,24 +5323,24 @@ iris_upload_dirty_render_state(struct iris_context *ice,
u_upload_data(ice->ctx.stream_uploader, 0, u_upload_data(ice->ctx.stream_uploader, 0,
sizeof(ice->draw.derived_params), 4, sizeof(ice->draw.derived_params), 4,
&ice->draw.derived_params, &ice->draw.derived_params,
&ice->draw.derived_draw_params_offset, &ice->draw.derived_draw_params.offset,
&ice->draw.derived_draw_params_res); &ice->draw.derived_draw_params.res);
struct iris_vertex_buffer_state *state = struct iris_vertex_buffer_state *state =
&(ice->state.genx->vertex_buffers[count]); &(ice->state.genx->vertex_buffers[count]);
pipe_resource_reference(&state->resource, pipe_resource_reference(&state->resource,
ice->draw.derived_draw_params_res); ice->draw.derived_draw_params.res);
struct iris_resource *res = (void *) ice->draw.derived_draw_params_res; struct iris_resource *res = (void *) ice->draw.derived_draw_params.res;
iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) { iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) {
vb.VertexBufferIndex = count; vb.VertexBufferIndex = count;
vb.AddressModifyEnable = true; vb.AddressModifyEnable = true;
vb.BufferPitch = 0; vb.BufferPitch = 0;
vb.BufferSize = vb.BufferSize =
res->bo->size - ice->draw.derived_draw_params_offset; res->bo->size - ice->draw.derived_draw_params.offset;
vb.BufferStartingAddress = vb.BufferStartingAddress =
ro_bo(NULL, res->bo->gtt_offset + ro_bo(NULL, res->bo->gtt_offset +
(int) ice->draw.derived_draw_params_offset); (int) ice->draw.derived_draw_params.offset);
vb.MOCS = mocs(res->bo); vb.MOCS = mocs(res->bo);
} }
dynamic_bound |= 1ull << count; dynamic_bound |= 1ull << count;
@ -5930,8 +5930,8 @@ iris_destroy_state(struct iris_context *ice)
{ {
struct iris_genx_state *genx = ice->state.genx; struct iris_genx_state *genx = ice->state.genx;
pipe_resource_reference(&ice->draw.draw_params_res, NULL); pipe_resource_reference(&ice->draw.draw_params.res, NULL);
pipe_resource_reference(&ice->draw.derived_draw_params_res, NULL); pipe_resource_reference(&ice->draw.derived_draw_params.res, NULL);
uint64_t bound_vbs = ice->state.bound_vertex_buffers; uint64_t bound_vbs = ice->state.bound_vertex_buffers;
while (bound_vbs) { while (bound_vbs) {