summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-12-02 18:07:13 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:19:02 -0800
commit9318ce8c5a6e0e315f62ce82314cb72f8bce5c79 (patch)
treeeb700786f15129e503197a24a1fa0cae1f482b0c /src
parent9d62df3800cad8f8a221d2222203cfa0856918f4 (diff)
nir/glsl: Don't allocate a state_slots array for 0 state slots
Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/nir/glsl_to_nir.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 19bc664961c..f29d7fbbb3d 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -330,12 +330,18 @@ nir_visitor::visit(ir_variable *ir)
var->data.max_array_access = ir->data.max_array_access;
var->num_state_slots = ir->get_num_state_slots();
- var->state_slots = ralloc_array(var, nir_state_slot, var->num_state_slots);
- ir_state_slot *state_slots = ir->get_state_slots();
- for (unsigned i = 0; i < var->num_state_slots; i++) {
- for (unsigned j = 0; j < 5; j++)
- var->state_slots[i].tokens[j] = state_slots[i].tokens[j];
- var->state_slots[i].swizzle = state_slots[i].swizzle;
+ if (var->num_state_slots > 0) {
+ var->state_slots = ralloc_array(var, nir_state_slot,
+ var->num_state_slots);
+
+ ir_state_slot *state_slots = ir->get_state_slots();
+ for (unsigned i = 0; i < var->num_state_slots; i++) {
+ for (unsigned j = 0; j < 5; j++)
+ var->state_slots[i].tokens[j] = state_slots[i].tokens[j];
+ var->state_slots[i].swizzle = state_slots[i].swizzle;
+ }
+ } else {
+ var->state_slots = NULL;
}
var->constant_value = constant_copy(ir->constant_value, var);