From 0d9c5b4e7ea0aed447183f144682a7f34aeb5c60 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 2 Oct 2018 10:21:57 -0700 Subject: [PATCH] iris: null for non-existent cbufs prevents BTs from being shifted down incorrectly --- src/gallium/drivers/iris/iris_context.h | 3 ++ src/gallium/drivers/iris/iris_program.c | 14 +++++++ src/gallium/drivers/iris/iris_state.c | 55 +++++++++++++------------ 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index 67460fa2669..1f553d71fa2 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -516,6 +516,9 @@ void gen11_init_state(struct iris_context *ice); /* iris_program.c */ const struct shader_info *iris_get_shader_info(const struct iris_context *ice, gl_shader_stage stage); +unsigned iris_get_shader_num_ubos(const struct iris_context *ice, + gl_shader_stage stage); + /* iris_program_cache.c */ diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index a0dcaa77175..b3eea223cc4 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -532,6 +532,20 @@ iris_get_shader_info(const struct iris_context *ice, gl_shader_stage stage) return &nir->info; } +// XXX: this function is gross +unsigned +iris_get_shader_num_ubos(const struct iris_context *ice, gl_shader_stage stage) +{ + const struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[stage]; + + if (ish) { + const nir_shader *nir = ish->nir; + /* see assign_common_binding_table_offsets */ + return nir->info.num_ubos + (nir->num_uniforms > 0 ? 1 : 0); + } + return 0; +} + /** * Get the union of TCS output and TES input slots. * diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index e8a529c7ccc..d3ed36bac9a 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -3180,6 +3180,26 @@ static const uint32_t push_constant_opcodes[] = { [MESA_SHADER_COMPUTE] = 0, }; +static uint32_t +use_null_surface(struct iris_batch *batch, struct iris_context *ice) +{ + struct iris_bo *state_bo = iris_resource_bo(ice->state.unbound_tex.res); + + iris_use_pinned_bo(batch, state_bo, false); + + return ice->state.unbound_tex.offset; +} + +static uint32_t +use_null_fb_surface(struct iris_batch *batch, struct iris_context *ice) +{ + struct iris_bo *state_bo = iris_resource_bo(ice->state.null_fb.res); + + iris_use_pinned_bo(batch, state_bo, false); + + return ice->state.null_fb.offset; +} + /** * Add a surface to the validation list, as well as the buffer containing * the corresponding SURFACE_STATE. @@ -3209,34 +3229,19 @@ use_sampler_view(struct iris_batch *batch, struct iris_sampler_view *isv) } static uint32_t -use_const_buffer(struct iris_batch *batch, struct iris_const_buffer *cbuf) +use_const_buffer(struct iris_batch *batch, + struct iris_context *ice, + struct iris_const_buffer *cbuf) { + if (!cbuf->surface_state.res) + return use_null_surface(batch, ice); + iris_use_pinned_bo(batch, iris_resource_bo(cbuf->data.res), false); iris_use_pinned_bo(batch, iris_resource_bo(cbuf->surface_state.res), false); return cbuf->surface_state.offset; } -static uint32_t -use_null_surface(struct iris_batch *batch, struct iris_context *ice) -{ - struct iris_bo *state_bo = iris_resource_bo(ice->state.unbound_tex.res); - - iris_use_pinned_bo(batch, state_bo, false); - - return ice->state.unbound_tex.offset; -} - -static uint32_t -use_null_fb_surface(struct iris_batch *batch, struct iris_context *ice) -{ - struct iris_bo *state_bo = iris_resource_bo(ice->state.null_fb.res); - - iris_use_pinned_bo(batch, state_bo, false); - - return ice->state.null_fb.offset; -} - static uint32_t use_ssbo(struct iris_batch *batch, struct iris_context *ice, struct iris_shader_state *shs, int i) @@ -3330,12 +3335,10 @@ iris_populate_binding_table(struct iris_context *ice, push_bt_entry(addr); } - for (int i = 0; i < 1 + info->num_ubos; i++) { - struct iris_const_buffer *cbuf = &shs->constbuf[i]; - if (!cbuf->surface_state.res) - break; + const int num_ubos = iris_get_shader_num_ubos(ice, stage); - uint32_t addr = use_const_buffer(batch, cbuf); + for (int i = 0; i < num_ubos; i++) { + uint32_t addr = use_const_buffer(batch, ice, &shs->constbuf[i]); push_bt_entry(addr); } -- 2.30.2