radv/rra: Implement ahit/isec counters
Reviewed-by: Friedrich Vock <friedrich.vock@gmx.de> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25548>
This commit is contained in:
@@ -203,6 +203,8 @@ struct rt_variables {
|
||||
|
||||
nir_variable *stack_ptr;
|
||||
|
||||
nir_variable *ahit_isec_count;
|
||||
|
||||
/* global address of the SBT entry used for the shader */
|
||||
nir_variable *shader_record_ptr;
|
||||
|
||||
@@ -247,6 +249,9 @@ create_rt_variables(nir_shader *shader, struct radv_device *device, const VkPipe
|
||||
vars.stack_ptr = nir_variable_create(shader, nir_var_shader_temp, glsl_uint_type(), "stack_ptr");
|
||||
vars.shader_record_ptr = nir_variable_create(shader, nir_var_shader_temp, glsl_uint64_t_type(), "shader_record_ptr");
|
||||
|
||||
if (device->rra_trace.ray_history_addr)
|
||||
vars.ahit_isec_count = nir_variable_create(shader, nir_var_shader_temp, glsl_uint_type(), "ahit_isec_count");
|
||||
|
||||
const struct glsl_type *vec3_type = glsl_vector_type(GLSL_TYPE_FLOAT, 3);
|
||||
vars.accel_struct = nir_variable_create(shader, nir_var_shader_temp, glsl_uint64_t_type(), "accel_struct");
|
||||
vars.cull_mask_and_flags = nir_variable_create(shader, nir_var_shader_temp, glsl_uint_type(), "cull_mask_and_flags");
|
||||
@@ -284,6 +289,9 @@ map_rt_variables(struct hash_table *var_remap, struct rt_variables *src, const s
|
||||
_mesa_hash_table_insert(var_remap, src->stack_ptr, dst->stack_ptr);
|
||||
_mesa_hash_table_insert(var_remap, src->shader_record_ptr, dst->shader_record_ptr);
|
||||
|
||||
if (dst->ahit_isec_count)
|
||||
_mesa_hash_table_insert(var_remap, src->ahit_isec_count, dst->ahit_isec_count);
|
||||
|
||||
_mesa_hash_table_insert(var_remap, src->accel_struct, dst->accel_struct);
|
||||
_mesa_hash_table_insert(var_remap, src->cull_mask_and_flags, dst->cull_mask_and_flags);
|
||||
_mesa_hash_table_insert(var_remap, src->sbt_offset, dst->sbt_offset);
|
||||
@@ -960,6 +968,9 @@ radv_build_end_trace_token(nir_builder *b, struct rt_variables *vars, nir_def *t
|
||||
nir_build_store_global(b, iteration_instance_count, dst_addr, .align_mul = 4);
|
||||
dst_addr = nir_iadd_imm(b, dst_addr, 4);
|
||||
|
||||
nir_build_store_global(b, nir_load_var(b, vars->ahit_isec_count), dst_addr, .align_mul = 4);
|
||||
dst_addr = nir_iadd_imm(b, dst_addr, 4);
|
||||
|
||||
nir_push_if(b, hit);
|
||||
{
|
||||
nir_build_store_global(b, nir_load_var(b, vars->primitive_id), dst_addr, .align_mul = 4);
|
||||
@@ -1402,6 +1413,10 @@ handle_candidate_triangle(nir_builder *b, struct radv_triangle_intersection *int
|
||||
.vars = &inner_vars,
|
||||
};
|
||||
|
||||
if (data->vars->ahit_isec_count)
|
||||
nir_store_var(b, data->vars->ahit_isec_count, nir_iadd_imm(b, nir_load_var(b, data->vars->ahit_isec_count), 1),
|
||||
0x1);
|
||||
|
||||
radv_visit_inlined_shaders(
|
||||
b, nir_load_var(b, inner_vars.idx),
|
||||
!(data->vars->flags & VK_PIPELINE_CREATE_2_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR), &case_data,
|
||||
@@ -1463,6 +1478,10 @@ handle_candidate_aabb(nir_builder *b, struct radv_leaf_intersection *intersectio
|
||||
nir_store_var(b, data->vars->ahit_accept, nir_imm_false(b), 0x1);
|
||||
nir_store_var(b, data->vars->ahit_terminate, nir_imm_false(b), 0x1);
|
||||
|
||||
if (data->vars->ahit_isec_count)
|
||||
nir_store_var(b, data->vars->ahit_isec_count,
|
||||
nir_iadd_imm(b, nir_load_var(b, data->vars->ahit_isec_count), 1 << 16), 0x1);
|
||||
|
||||
struct radv_rt_case_data case_data = {
|
||||
.device = data->device,
|
||||
.pipeline = data->pipeline,
|
||||
@@ -1569,6 +1588,8 @@ radv_build_traversal(struct radv_device *device, struct radv_ray_tracing_pipelin
|
||||
nir_variable_create(b->shader, nir_var_shader_temp, glsl_uint_type(), "iteration_instance_count");
|
||||
nir_store_var(b, iteration_instance_count, nir_imm_int(b, 0), 0x1);
|
||||
trav_vars_args.iteration_instance_count = nir_build_deref_var(b, iteration_instance_count);
|
||||
|
||||
nir_store_var(b, vars->ahit_isec_count, nir_imm_int(b, 0), 0x1);
|
||||
}
|
||||
|
||||
struct traversal_data data = {
|
||||
|
@@ -885,6 +885,9 @@ struct radv_packed_end_trace_token {
|
||||
uint32_t iteration_count : 16;
|
||||
uint32_t instance_count : 16;
|
||||
|
||||
uint32_t ahit_count : 16;
|
||||
uint32_t isec_count : 16;
|
||||
|
||||
uint32_t primitive_id;
|
||||
uint32_t geometry_id;
|
||||
|
||||
@@ -893,7 +896,7 @@ struct radv_packed_end_trace_token {
|
||||
|
||||
float t;
|
||||
};
|
||||
static_assert(sizeof(struct radv_packed_end_trace_token) == 72, "Unexpected radv_packed_end_trace_token size");
|
||||
static_assert(sizeof(struct radv_packed_end_trace_token) == 76, "Unexpected radv_packed_end_trace_token size");
|
||||
|
||||
enum radv_rra_ray_history_metadata_type {
|
||||
RADV_RRA_COUNTER_INFO = 1,
|
||||
|
@@ -1421,9 +1421,10 @@ radv_rra_dump_trace(VkQueue vk_queue, char *filename)
|
||||
history_size_mb);
|
||||
}
|
||||
|
||||
uint32_t history_size = MIN2(history_header->offset, device->rra_trace.ray_history_buffer_size);
|
||||
|
||||
uint32_t token_size;
|
||||
for (uint32_t offset = sizeof(struct radv_ray_history_header); offset < history_header->offset;
|
||||
offset += token_size) {
|
||||
for (uint32_t offset = sizeof(struct radv_ray_history_header); offset < history_size; offset += token_size) {
|
||||
struct radv_packed_end_trace_token *src = (void *)(history + offset);
|
||||
token_size = src->header.hit ? sizeof(struct radv_packed_end_trace_token)
|
||||
: offsetof(struct radv_packed_end_trace_token, primitive_id);
|
||||
@@ -1476,6 +1477,32 @@ radv_rra_dump_trace(VkQueue vk_queue, char *filename)
|
||||
fwrite(&begin_control, sizeof(begin_control), 1, file);
|
||||
fwrite(&begin, sizeof(begin), 1, file);
|
||||
|
||||
for (uint32_t i = 0; i < src->ahit_count; i++) {
|
||||
struct rra_ray_history_id_token ahit_status_id = {
|
||||
.id = src->header.launch_index,
|
||||
.has_control = true,
|
||||
};
|
||||
struct rra_ray_history_control_token ahit_status_control = {
|
||||
.type = rra_ray_history_token_ahit_status,
|
||||
.data = i == src->ahit_count - 1 ? 2 : 0,
|
||||
};
|
||||
fwrite(&ahit_status_id, sizeof(ahit_status_id), 1, file);
|
||||
fwrite(&ahit_status_control, sizeof(ahit_status_control), 1, file);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < src->isec_count; i++) {
|
||||
struct rra_ray_history_id_token isec_status_id = {
|
||||
.id = src->header.launch_index,
|
||||
.has_control = true,
|
||||
};
|
||||
struct rra_ray_history_control_token isec_status_control = {
|
||||
.type = rra_ray_history_token_isec_status,
|
||||
.data = i == src->ahit_count - 1 ? 2 : 0,
|
||||
};
|
||||
fwrite(&isec_status_id, sizeof(isec_status_id), 1, file);
|
||||
fwrite(&isec_status_control, sizeof(isec_status_control), 1, file);
|
||||
}
|
||||
|
||||
struct rra_ray_history_id_token end_id = {
|
||||
.id = src->header.launch_index,
|
||||
.has_control = true,
|
||||
|
Reference in New Issue
Block a user