Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Copyright © 2014 Broadcom
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * and/or sell copies of the Software, and to permit persons to whom the
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice (including the next
12
 * paragraph) shall be included in all copies or substantial portions of the
13
 * Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
 * IN THE SOFTWARE.
22
 */
23
 
24
/**
25
 * @file vc4_reorder_uniforms.c
26
 *
27
 * After optimization has occurred, rewrites the shader to have uniform reads
28
 * reading from the c->uniform_contents[] in order, exactly once each.
29
 *
30
 * This allows optimization and instruction scheduling to move things around
31
 * without worrying about how the hardware has the "each uniform read bumps
32
 * the uniform read address" property.
33
 */
34
 
35
#include "util/ralloc.h"
36
#include "util/u_math.h"
37
#include "vc4_qir.h"
38
 
39
void
40
qir_reorder_uniforms(struct vc4_compile *c)
41
{
42
        uint32_t *uniform_index = NULL;
43
        uint32_t uniform_index_size = 0;
44
        uint32_t next_uniform = 0;
45
        struct simple_node *node;
46
        foreach(node, &c->instructions) {
47
                struct qinst *inst = (struct qinst *)node;
48
 
49
                for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
50
                        if (inst->src[i].file != QFILE_UNIF)
51
                                continue;
52
 
53
                        uint32_t new = next_uniform++;
54
                        if (uniform_index_size <= new) {
55
                                uniform_index_size =
56
                                        MAX2(uniform_index_size * 2, 16);
57
                                uniform_index =
58
                                        realloc(uniform_index,
59
                                                uniform_index_size *
60
                                                sizeof(uint32_t));
61
                        }
62
 
63
                        uniform_index[new] = inst->src[i].index;
64
                        inst->src[i].index = new;
65
                }
66
        }
67
 
68
        uint32_t *uniform_data = ralloc_array(c, uint32_t, next_uniform);
69
        enum quniform_contents *uniform_contents =
70
                ralloc_array(c, enum quniform_contents, next_uniform);
71
 
72
        for (uint32_t i = 0; i < next_uniform; i++) {
73
                uniform_data[i] = c->uniform_data[uniform_index[i]];
74
                uniform_contents[i] = c->uniform_contents[uniform_index[i]];
75
        }
76
 
77
        ralloc_free(c->uniform_data);
78
        c->uniform_data = uniform_data;
79
        ralloc_free(c->uniform_contents);
80
        c->uniform_contents = uniform_contents;
81
        c->num_uniforms = next_uniform;
82
 
83
        free(uniform_index);
84
}