[Mesa-dev] [PATCH 3/4] anv/pipeline: Only do buffer bounds checks if robustBufferAccess is enabled

Jason Ekstrand jason at jlekstrand.net
Thu May 19 04:42:02 UTC 2016


---
 src/intel/vulkan/anv_nir_apply_dynamic_offsets.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/intel/vulkan/anv_nir_apply_dynamic_offsets.c b/src/intel/vulkan/anv_nir_apply_dynamic_offsets.c
index a7ed3e5..ef9d1f4 100644
--- a/src/intel/vulkan/anv_nir_apply_dynamic_offsets.c
+++ b/src/intel/vulkan/anv_nir_apply_dynamic_offsets.c
@@ -27,6 +27,7 @@
 static void
 apply_dynamic_offsets_block(nir_block *block, nir_builder *b,
                             const struct anv_pipeline_layout *layout,
+                            bool add_bounds_checks,
                             uint32_t indices_start)
 {
    struct anv_descriptor_set_layout *set_layout;
@@ -80,11 +81,15 @@ apply_dynamic_offsets_block(nir_block *block, nir_builder *b,
       nir_ssa_dest_init(&offset_load->instr, &offset_load->dest, 2, 32, NULL);
       nir_builder_instr_insert(b, &offset_load->instr);
 
-      nir_ssa_def *new_offset = nir_iadd(b, nir_ssa_for_src(*offset_src),
+      nir_src *offset_src = nir_get_io_offset_src(intrin);
+      nir_ssa_def *new_offset = nir_iadd(b, nir_ssa_for_src(b, *offset_src, 1),
                                          &offset_load->dest.ssa);
-      nir_instr_rewrite_src(&intrin->instr, nir_get_io_offset_src(intrin),
+      nir_instr_rewrite_src(&intrin->instr, offset_src,
                             nir_src_for_ssa(new_offset));
 
+      if (!add_bounds_checks)
+         continue;
+
       /* In order to avoid out-of-bounds access, we predicate */
       nir_ssa_def *pred = nir_uge(b, nir_channel(b, &offset_load->dest.ssa, 1),
                                   offset_src->ssa);
@@ -137,6 +142,8 @@ anv_nir_apply_dynamic_offsets(struct anv_pipeline *pipeline,
    if (!layout || !layout->stage[shader->stage].has_dynamic_offsets)
       return;
 
+   const bool add_bounds_checks = pipeline->device->robust_buffer_access;
+
    nir_foreach_function(function, shader) {
       if (!function->impl)
          continue;
@@ -146,7 +153,7 @@ anv_nir_apply_dynamic_offsets(struct anv_pipeline *pipeline,
 
       nir_foreach_block(block, function->impl) {
          apply_dynamic_offsets_block(block, &builder, pipeline->layout,
-                                     shader->num_uniforms);
+                                     add_bounds_checks, shader->num_uniforms);
       }
 
       nir_metadata_preserve(function->impl, nir_metadata_block_index |
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list