vk/compiler: Add an index_count to the bind map and check for OOB
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 1 Jun 2015 19:24:31 +0000 (12:24 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 1 Jun 2015 19:25:58 +0000 (12:25 -0700)
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_fs_nir.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/vulkan/compiler.cpp

index b6cdc82..5a35e48 100644 (file)
@@ -360,7 +360,10 @@ struct brw_stage_prog_data {
    } binding_table;
 
    uint32_t *map_entries;
-   uint32_t *bind_map[8]; /* MAX_SETS from vulkan/private.h */
+   struct {
+      uint32_t index_count;
+      uint32_t *index;
+   } bind_map[8]; /* MAX_SETS from vulkan/private.h */
 
    GLuint nr_params;       /**< number of float params/constants */
    GLuint nr_pull_params;
index 2623241..270131a 100644 (file)
@@ -1403,7 +1403,13 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)
          uint32_t set = shader->base.UniformBlocks[index].Set;
          uint32_t binding = shader->base.UniformBlocks[index].Binding;
 
-         surf_index = fs_reg(stage_prog_data->bind_map[set][binding]);
+         /* FIXME: We should probably assert here, but dota2 seems to hit
+          * it and we'd like to keep going.
+          */
+         if (binding >= stage_prog_data->bind_map[set].index_count)
+            binding = 0;
+
+         surf_index = fs_reg(stage_prog_data->bind_map[set].index[binding]);
       } else {
          assert(0 && "need more info from the ir for this.");
          /* The block index is not a constant. Evaluate the index expression
@@ -1623,8 +1629,12 @@ void
 fs_visitor::nir_emit_texture(nir_tex_instr *instr)
 {
    uint32_t set = instr->sampler_set;
-   uint32_t index = instr->sampler_index;
-   unsigned sampler = stage_prog_data->bind_map[set][index];
+   uint32_t binding = instr->sampler_index;
+
+   assert(binding < stage_prog_data->bind_map[set].index_count);
+   assert(stage_prog_data->bind_map[set].index[binding] < 1000);
+
+   unsigned sampler = stage_prog_data->bind_map[set].index[binding];
    fs_reg sampler_reg(sampler);
 
    /* FINISHME: We're failing to recompile our programs when the sampler is
index 07853c0..e1f47d4 100644 (file)
@@ -1207,7 +1207,7 @@ fs_visitor::visit(ir_expression *ir)
          index = const_uniform_block->value.u[0];
          set = shader->base.UniformBlocks[index].Set;
          set_index = shader->base.UniformBlocks[index].Binding;
-         binding = stage_prog_data->bind_map[set][set_index];
+         binding = stage_prog_data->bind_map[set].index[set_index];
          surf_index = fs_reg(binding);
       } else {
          assert(0 && "need more info from the ir for this.");
@@ -2302,7 +2302,7 @@ fs_visitor::visit(ir_texture *ir)
    assert(deref_var);
    ir_variable *var = deref_var->var;
 
-   sampler = stage_prog_data->bind_map[var->data.set][var->data.index];
+   sampler = stage_prog_data->bind_map[var->data.set].index[var->data.index];
 
    ir_rvalue *nonconst_sampler_index =
       _mesa_get_sampler_array_nonconst_index(ir->sampler);
index 42c54fb..ead4117 100644 (file)
@@ -80,9 +80,12 @@ set_binding_table_layout(struct brw_stage_prog_data *prog_data,
    k = bias;
    map = prog_data->map_entries;
    for (uint32_t i = 0; i < layout->num_sets; i++) {
-      prog_data->bind_map[i] = map;
+      prog_data->bind_map[i].index = map;
       for (uint32_t j = 0; j < layout->set[i].layout->stage[stage].surface_count; j++)
          *map++ = k++;
+
+      prog_data->bind_map[i].index_count =
+         layout->set[i].layout->stage[stage].surface_count;
    }
 
    return VK_SUCCESS;