From 6d15d65e19e2a77b64c4ab7b5120ad3b8be2b611 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 29 Apr 2022 10:20:18 -0500 Subject: [PATCH] panvk: Put the sysval and push const UBOs at fixed indices In theory, this may cost us a tiny bit of descriptor space but in practice, given that the viewport transform is a sysval, we'll always need it for 3D and given that SSBO pointers live there, we'll basically always need it for compute. It also makes a lot of things simpler. We're about to start using the sysval UBO directly in our descriptor set code and knowing the index up-front is really nice. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/panfrost/vulkan/panvk_descriptor_set.c | 3 -- src/panfrost/vulkan/panvk_private.h | 5 +++- src/panfrost/vulkan/panvk_vX_cs.c | 29 ++++++++++--------- .../vulkan/panvk_vX_nir_lower_descriptors.c | 10 +++++-- src/panfrost/vulkan/panvk_vX_pipeline.c | 16 ++++------ src/panfrost/vulkan/panvk_vX_shader.c | 8 ++--- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/panfrost/vulkan/panvk_descriptor_set.c b/src/panfrost/vulkan/panvk_descriptor_set.c index 0d1494e6c0d..4537096d5ab 100644 --- a/src/panfrost/vulkan/panvk_descriptor_set.c +++ b/src/panfrost/vulkan/panvk_descriptor_set.c @@ -206,9 +206,6 @@ panvk_CreatePipelineLayout(VkDevice _device, layout->push_constants.size); } - if (layout->push_constants.size) - layout->push_constants.ubo_idx = ubo_idx++; - layout->num_samplers = sampler_idx; layout->num_textures = tex_idx; layout->num_ubos = ubo_idx; diff --git a/src/panfrost/vulkan/panvk_private.h b/src/panfrost/vulkan/panvk_private.h index 644d6a81714..d8bc52c356c 100644 --- a/src/panfrost/vulkan/panvk_private.h +++ b/src/panfrost/vulkan/panvk_private.h @@ -106,6 +106,10 @@ typedef uint32_t xcb_window_t; #define NUM_DEPTH_CLEAR_PIPELINES 3 +#define PANVK_SYSVAL_UBO_INDEX 0 +#define PANVK_PUSH_CONST_UBO_INDEX 1 +#define PANVK_NUM_BUILTIN_UBOS 2 + #define panvk_printflike(a, b) __attribute__((__format__(__printf__, a, b))) void @@ -458,7 +462,6 @@ struct panvk_pipeline_layout { struct { uint32_t size; - unsigned ubo_idx; } push_constants; struct { diff --git a/src/panfrost/vulkan/panvk_vX_cs.c b/src/panfrost/vulkan/panvk_vX_cs.c index 59d7ca14e02..3506b38a8fb 100644 --- a/src/panfrost/vulkan/panvk_vX_cs.c +++ b/src/panfrost/vulkan/panvk_vX_cs.c @@ -389,11 +389,24 @@ panvk_per_arch(emit_ubos)(const struct panvk_pipeline *pipeline, { struct mali_uniform_buffer_packed *ubos = descs; + panvk_per_arch(emit_ubo)(state->sysvals_ptr, + sizeof(state->sysvals), + &ubos[PANVK_SYSVAL_UBO_INDEX]); + + if (pipeline->layout->push_constants.size) { + panvk_per_arch(emit_ubo)(state->push_constants, + ALIGN_POT(pipeline->layout->push_constants.size, 16), + &ubos[PANVK_PUSH_CONST_UBO_INDEX]); + } else { + memset(&ubos[PANVK_PUSH_CONST_UBO_INDEX], 0, sizeof(*ubos)); + } + for (unsigned i = 0; i < ARRAY_SIZE(state->sets); i++) { const struct panvk_descriptor_set_layout *set_layout = pipeline->layout->sets[i].layout; const struct panvk_descriptor_set *set = state->sets[i]; - unsigned offset = pipeline->layout->sets[i].ubo_offset; + unsigned offset = PANVK_NUM_BUILTIN_UBOS + + pipeline->layout->sets[i].ubo_offset; if (!set_layout) continue; @@ -405,7 +418,7 @@ panvk_per_arch(emit_ubos)(const struct panvk_pipeline *pipeline, } } - unsigned offset = pipeline->layout->num_ubos; + unsigned offset = PANVK_NUM_BUILTIN_UBOS + pipeline->layout->num_ubos; for (unsigned i = 0; i < pipeline->layout->num_dyn_ubos; i++) { const struct panvk_buffer_desc *bdesc = &state->dyn.ubos[i]; mali_ptr address = panvk_buffer_gpu_ptr(bdesc->buffer, bdesc->offset); @@ -417,18 +430,6 @@ panvk_per_arch(emit_ubos)(const struct panvk_pipeline *pipeline, else memset(&ubos[offset + i], 0, sizeof(*ubos)); } - - for (unsigned i = 0; i < ARRAY_SIZE(pipeline->sysvals); i++) { - panvk_per_arch(emit_ubo)(state->sysvals_ptr, - sizeof(state->sysvals), - &ubos[pipeline->sysvals[i].ubo_idx]); - } - - if (pipeline->layout->push_constants.size) { - panvk_per_arch(emit_ubo)(state->push_constants, - ALIGN_POT(pipeline->layout->push_constants.size, 16), - &ubos[pipeline->layout->push_constants.ubo_idx]); - } } void diff --git a/src/panfrost/vulkan/panvk_vX_nir_lower_descriptors.c b/src/panfrost/vulkan/panvk_vX_nir_lower_descriptors.c index 7e776b2458f..8fe45d20a51 100644 --- a/src/panfrost/vulkan/panvk_vX_nir_lower_descriptors.c +++ b/src/panfrost/vulkan/panvk_vX_nir_lower_descriptors.c @@ -135,11 +135,15 @@ lower_vulkan_resource_index(nir_builder *b, nir_intrinsic_instr *intr, switch (binding_layout->type) { case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - base = binding_layout->ubo_idx + ctx->layout->sets[set].ubo_offset; + base = PANVK_NUM_BUILTIN_UBOS + + ctx->layout->sets[set].ubo_offset + + binding_layout->ubo_idx; break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: - base = binding_layout->dyn_ubo_idx + ctx->layout->num_ubos + - ctx->layout->sets[set].dyn_ubo_offset; + base = PANVK_NUM_BUILTIN_UBOS + + ctx->layout->sets[set].dyn_ubo_offset + + ctx->layout->num_ubos + + binding_layout->dyn_ubo_idx; break; case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: base = binding_layout->ssbo_idx + ctx->layout->sets[set].ssbo_offset; diff --git a/src/panfrost/vulkan/panvk_vX_pipeline.c b/src/panfrost/vulkan/panvk_vX_pipeline.c index 001c053e0d7..c7c9b01c43f 100644 --- a/src/panfrost/vulkan/panvk_vX_pipeline.c +++ b/src/panfrost/vulkan/panvk_vX_pipeline.c @@ -125,8 +125,6 @@ panvk_pipeline_builder_compile_shaders(struct panvk_pipeline_builder *builder, } /* compile shaders in reverse order */ - unsigned sysval_ubo = builder->layout->num_ubos + builder->layout->num_dyn_ubos; - for (gl_shader_stage stage = MESA_SHADER_STAGES - 1; stage > MESA_SHADER_NONE; stage--) { const VkPipelineShaderStageCreateInfo *stage_info = stage_infos[stage]; @@ -136,16 +134,14 @@ panvk_pipeline_builder_compile_shaders(struct panvk_pipeline_builder *builder, struct panvk_shader *shader; shader = panvk_per_arch(shader_create)(builder->device, stage, stage_info, - builder->layout, sysval_ubo, + builder->layout, + PANVK_SYSVAL_UBO_INDEX, &pipeline->blend.state, panvk_pipeline_static_state(pipeline, VK_DYNAMIC_STATE_BLEND_CONSTANTS), builder->alloc); if (!shader) return VK_ERROR_OUT_OF_HOST_MEMORY; - - if (shader->info.sysvals.sysval_count) - sysval_ubo++; builder->shaders[stage] = shader; builder->shader_total_size = ALIGN_POT(builder->shader_total_size, 128); @@ -319,11 +315,9 @@ panvk_pipeline_builder_init_shaders(struct panvk_pipeline_builder *builder, } } - pipeline->num_ubos = builder->layout->num_ubos + builder->layout->num_dyn_ubos; - for (unsigned i = 0; i < ARRAY_SIZE(pipeline->sysvals); i++) { - if (pipeline->sysvals[i].ids.sysval_count) - pipeline->num_ubos = MAX2(pipeline->num_ubos, pipeline->sysvals[i].ubo_idx + 1); - } + pipeline->num_ubos = PANVK_NUM_BUILTIN_UBOS + + builder->layout->num_ubos + + builder->layout->num_dyn_ubos; } diff --git a/src/panfrost/vulkan/panvk_vX_shader.c b/src/panfrost/vulkan/panvk_vX_shader.c index 293ecb8c8c9..4994582fa8c 100644 --- a/src/panfrost/vulkan/panvk_vX_shader.c +++ b/src/panfrost/vulkan/panvk_vX_shader.c @@ -295,13 +295,11 @@ panvk_lower_load_push_constant(nir_builder *b, nir_instr *instr, void *data) if (intr->intrinsic != nir_intrinsic_load_push_constant) return false; - const struct panvk_pipeline_layout *layout = data; - b->cursor = nir_before_instr(instr); nir_ssa_def *ubo_load = nir_load_ubo(b, nir_dest_num_components(intr->dest), nir_dest_bit_size(intr->dest), - nir_imm_int(b, layout->push_constants.ubo_idx), + nir_imm_int(b, PANVK_PUSH_CONST_UBO_INDEX), intr->src[0].ssa, .align_mul = nir_dest_bit_size(intr->dest) / 8, .align_offset = 0, @@ -454,8 +452,8 @@ panvk_per_arch(shader_create)(struct panvk_device *dev, sizeof(fixed_sysvals)) == 0); /* Patch the descriptor count */ - shader->info.ubo_count = - shader->info.sysvals.sysval_count ? sysval_ubo + 1 : layout->num_ubos; + shader->info.ubo_count = PANVK_NUM_BUILTIN_UBOS + + layout->num_ubos + layout->num_dyn_ubos; shader->info.sampler_count = layout->num_samplers; shader->info.texture_count = layout->num_textures; if (shader->has_img_access)