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 b6cdc82444c81f59d8683e6dc0b331935b533790..5a35e48a48137fca5032df03bc5ddddac24b0748 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 2623241a0563b686549ac7cab1184d98ceae86cf..270131a73d15c979e8804380e42dd8726414fa94 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 07853c0d0d6f44286e3da7d56e208ae40e78629d..e1f47d4ec44b0a32910a0b43f9ee71915b39cccc 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 42c54fbe8d3f35e5df72a02c2982ffa4f6233679..ead4117479c4ed6d02f020fbb8d15ff1aaf62c44 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;