From: Jason Ekstrand Date: Wed, 6 Nov 2019 16:59:15 +0000 (-0600) Subject: anv: Re-arrange push constant data a bit X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca91ab801522c7a760562fe32d0a2a4b7b333876;p=mesa.git anv: Re-arrange push constant data a bit This moves the compute stuff into a anv_push_constants::cs sub-struct. It also moves dynamic offsets into the push constants. This means we have to duplicate the data per-stage but that doesn't seem like the end of the world and one day we may wish to make dynamic offsets per-stage anyway. Reviewed-by: Lionel Landwerlin --- diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 4bf2725dccc..12ab3a1f728 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -586,13 +586,18 @@ anv_cmd_buffer_bind_descriptor_set(struct anv_cmd_buffer *cmd_buffer, uint32_t dynamic_offset_start = layout->set[set_index].dynamic_offset_start; - /* Assert that everything is in range */ - assert(set_layout->dynamic_offset_count <= *dynamic_offset_count); - assert(dynamic_offset_start + set_layout->dynamic_offset_count <= - ARRAY_SIZE(pipe_state->dynamic_offsets)); + anv_foreach_stage(stage, set_layout->shader_stages) { + struct anv_push_constants *push = + &cmd_buffer->state.push_constants[stage]; - typed_memcpy(&pipe_state->dynamic_offsets[dynamic_offset_start], - *dynamic_offsets, set_layout->dynamic_offset_count); + /* Assert that everything is in range */ + assert(set_layout->dynamic_offset_count <= *dynamic_offset_count); + assert(dynamic_offset_start + set_layout->dynamic_offset_count <= + ARRAY_SIZE(push->dynamic_offsets)); + + typed_memcpy(&push->dynamic_offsets[dynamic_offset_start], + *dynamic_offsets, set_layout->dynamic_offset_count); + } *dynamic_offsets += set_layout->dynamic_offset_count; *dynamic_offset_count -= set_layout->dynamic_offset_count; @@ -749,11 +754,11 @@ anv_push_constant_value(const struct anv_cmd_pipeline_state *state, case BRW_PARAM_BUILTIN_ZERO: return 0; case BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X: - return data->base_work_group_id[0]; + return data->cs.base_work_group_id[0]; case BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y: - return data->base_work_group_id[1]; + return data->cs.base_work_group_id[1]; case BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z: - return data->base_work_group_id[2]; + return data->cs.base_work_group_id[2]; default: unreachable("Invalid param builtin"); } @@ -767,7 +772,7 @@ anv_push_constant_value(const struct anv_cmd_pipeline_state *state, } else if (ANV_PARAM_IS_DYN_OFFSET(param)) { unsigned idx = ANV_PARAM_DYN_OFFSET_IDX(param); assert(idx < MAX_DYNAMIC_BUFFERS); - return state->dynamic_offsets[idx]; + return data->dynamic_offsets[idx]; } assert(!"Invalid param"); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 82e582269de..771268db156 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2371,11 +2371,26 @@ struct anv_xfb_binding { #define ANV_PARAM_DYN_OFFSET_IDX(param) ((param) & 0xffff) struct anv_push_constants { - /* Push constant data provided by the client through vkPushConstants */ + /** Push constant data provided by the client through vkPushConstants */ uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE]; - /* Used for vkCmdDispatchBase */ - uint32_t base_work_group_id[3]; + /** Dynamic offsets for dynamic UBOs and SSBOs */ + uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS]; + + struct { + /** Base workgroup ID + * + * Used for vkCmdDispatchBase. + */ + uint32_t base_work_group_id[3]; + + /** Subgroup ID + * + * This is never set by software but is implicitly filled out when + * uploading the push constants for compute shaders. + */ + uint32_t subgroup_id; + } cs; }; struct anv_dynamic_state { @@ -2495,8 +2510,6 @@ struct anv_cmd_pipeline_state { struct anv_pipeline *pipeline; struct anv_descriptor_set *descriptors[MAX_SETS]; - uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS]; - struct anv_push_descriptor_set *push_descriptors[MAX_SETS]; }; diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 4f35df86fc1..567e556f5a5 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -2309,8 +2309,11 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { /* Compute the offset within the buffer */ + struct anv_push_constants *push = + &cmd_buffer->state.push_constants[stage]; + uint32_t dynamic_offset = - pipe_state->dynamic_offsets[binding->dynamic_offset_index]; + push->dynamic_offsets[binding->dynamic_offset_index]; uint64_t offset = desc->offset + dynamic_offset; /* Clamp to the buffer size */ offset = MIN2(offset, desc->buffer->size); @@ -2570,8 +2573,10 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer, addr = desc->buffer_view->address; } else { assert(desc->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC); + struct anv_push_constants *push = + &cmd_buffer->state.push_constants[stage]; uint32_t dynamic_offset = - gfx_state->base.dynamic_offsets[range->dynamic_offset_index]; + push->dynamic_offsets[range->dynamic_offset_index]; addr = anv_address_add(desc->buffer->address, desc->offset + dynamic_offset); } @@ -3590,12 +3595,12 @@ anv_cmd_buffer_push_base_group_id(struct anv_cmd_buffer *cmd_buffer, struct anv_push_constants *push = &cmd_buffer->state.push_constants[MESA_SHADER_COMPUTE]; - if (push->base_work_group_id[0] != baseGroupX || - push->base_work_group_id[1] != baseGroupY || - push->base_work_group_id[2] != baseGroupZ) { - push->base_work_group_id[0] = baseGroupX; - push->base_work_group_id[1] = baseGroupY; - push->base_work_group_id[2] = baseGroupZ; + if (push->cs.base_work_group_id[0] != baseGroupX || + push->cs.base_work_group_id[1] != baseGroupY || + push->cs.base_work_group_id[2] != baseGroupZ) { + push->cs.base_work_group_id[0] = baseGroupX; + push->cs.base_work_group_id[1] = baseGroupY; + push->cs.base_work_group_id[2] = baseGroupZ; cmd_buffer->state.push_constants_dirty |= VK_SHADER_STAGE_COMPUTE_BIT; }