turnip: shared_consts and push_consts are mutually exclusive

Skip gather_push_constants when shared consts are enabled.  This makes
sure push_consts is only zero-initialized, and reserved_user_consts is
0.  This saves some space in the const file.

This change also adds a few asserts and a comment to
lower_load_push_constant.  Because shared consts share the same range
for all stages, we should not apply per-stage offsets in
lower_load_push_constant.  It worked because nir_lower_explicit_io
always sets base to 0 for nir_var_mem_push_const and
shader->push_consts.lo was always 0 for all stages.

Fixes: 0c787d57e6 ("tu: increase maxPushConstantsSize to 256.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17777>
This commit is contained in:
Chia-I Wu 2022-07-27 16:48:36 -07:00 committed by Marge Bot
parent 562e5ba286
commit 6929ccedff
2 changed files with 19 additions and 4 deletions

View File

@ -4213,6 +4213,12 @@ tu6_emit_consts(struct tu_cmd_buffer *cmd,
if (pipeline->shared_consts.dwords > 0) {
tu6_emit_shared_consts(&cs, pipeline, cmd->push_constants, compute);
for (uint32_t i = 0; i < ARRAY_SIZE(pipeline->program.link); i++) {
const struct tu_program_descriptor_linkage *link =
&pipeline->program.link[i];
assert(!link->push_consts.dwords);
}
} else {
if (compute) {
tu6_emit_user_consts(&cs, pipeline, MESA_SHADER_COMPUTE, cmd->push_constants);

View File

@ -146,11 +146,17 @@ lower_load_push_constant(struct tu_device *dev,
{
uint32_t base = nir_intrinsic_base(instr);
assert(base % 4 == 0);
assert(base >= shader->push_consts.lo * 4);
base -= shader->push_consts.lo * 4;
if (tu6_shared_constants_enable(layout, dev->compiler))
if (tu6_shared_constants_enable(layout, dev->compiler)) {
/* All stages share the same range. We could potentially add
* push_constant_offset to layout and apply it, but this is good for
* now.
*/
base += dev->compiler->shared_consts_base_offset * 4;
} else {
assert(base >= shader->push_consts.lo * 4);
base -= shader->push_consts.lo * 4;
}
nir_ssa_def *load =
nir_load_uniform(b, instr->num_components,
@ -641,7 +647,8 @@ tu_lower_io(nir_shader *shader, struct tu_device *dev,
struct tu_shader *tu_shader,
const struct tu_pipeline_layout *layout)
{
gather_push_constants(shader, tu_shader);
if (!tu6_shared_constants_enable(layout, dev->compiler))
gather_push_constants(shader, tu_shader);
struct lower_instr_params params = {
.dev = dev,
@ -835,6 +842,8 @@ tu_shader_create(struct tu_device *dev,
uint32_t reserved_consts_vec4 = align(shader->push_consts.dwords, 16) / 4;
bool shared_consts_enable = tu6_shared_constants_enable(layout, dev->compiler);
if (shared_consts_enable)
assert(!shader->push_consts.dwords);
shader->ir3_shader =
ir3_shader_from_nir(dev->compiler, nir, &(struct ir3_shader_options) {