From e10cbb59a5f71ffd40bb2de8d4528863278f352c Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Wed, 7 Aug 2024 10:20:13 +0300 Subject: [PATCH] anv: add assert to detect problematic instruction merges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We stick to a rule in the driver that each field is only set in a single place in the driver. Therefore when merging instructions, we should never have any bit set to 1 from both sides. Signed-off-by: Lionel Landwerlin Reviewed-by: Tapani Pälli Part-of: --- src/intel/vulkan/anv_cmd_buffer.c | 4 +++- src/intel/vulkan/anv_private.h | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 5b013a833d0..57b42430f00 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -1199,8 +1199,10 @@ anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer, state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, dwords * 4, alignment); p = state.map; - for (uint32_t i = 0; i < dwords; i++) + for (uint32_t i = 0; i < dwords; i++) { + assert((a[i] & b[i]) == 0); p[i] = a[i] | b[i]; + } VG(VALGRIND_CHECK_MEM_IS_DEFINED(p, dwords * 4)); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 84c4f0083ac..4b72d9594f7 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2447,6 +2447,9 @@ _anv_combine_address(struct anv_batch *batch, void *location, assert((pipeline)->state.len == __anv_cmd_length(cmd)); \ __anv_cmd_pack(cmd)(batch, _partial, &name); \ for (uint32_t i = 0; i < __anv_cmd_length(cmd); i++) { \ + assert((_partial[i] & \ + (pipeline)->batch_data[ \ + (pipeline)->state.offset + i]) == 0); \ ((uint32_t *)_dst)[i] = _partial[i] | \ (pipeline)->batch_data[(pipeline)->state.offset + i]; \ } \ @@ -2466,6 +2469,9 @@ _anv_combine_address(struct anv_batch *batch, void *location, assert(_cmd_state->len == __anv_cmd_length(cmd)); \ __anv_cmd_pack(cmd)(batch, _partial, &name); \ for (uint32_t i = 0; i < __anv_cmd_length(cmd); i++) { \ + assert((_partial[i] & \ + (pipeline)->batch_data[ \ + (pipeline)->state.offset + i]) == 0); \ ((uint32_t *)_dst)[i] = _partial[i] | \ (pipeline)->batch_data[_cmd_state->offset + i]; \ } \