~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/panfrost/bifrost/bi_opt_message_preload.c

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2021 Collabora, Ltd.
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 FROM,
20
 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 
 * SOFTWARE.
22
 
 */
23
 
 
24
 
#include "compiler.h"
25
 
#include "bi_builder.h"
26
 
 
27
 
/* Bifrost v7 can preload up to two messages of the form:
28
 
 *
29
 
 * 1. +LD_VAR_IMM, register_format f32/f16, sample mode
30
 
 * 2. +VAR_TEX, register format f32/f16, sample mode (TODO)
31
 
 *
32
 
 * Analyze the shader for these instructions and push accordingly.
33
 
 */
34
 
 
35
 
static bool
36
 
bi_is_regfmt_float(enum bi_register_format regfmt)
37
 
{
38
 
        return (regfmt == BI_REGISTER_FORMAT_F32) ||
39
 
                (regfmt == BI_REGISTER_FORMAT_F16);
40
 
}
41
 
 
42
 
/*
43
 
 * Preloaded varyings are interpolated at the sample location. Check if an
44
 
 * instruction can use this interpolation mode.
45
 
 */
46
 
static bool
47
 
bi_can_interp_at_sample(bi_instr *I)
48
 
{
49
 
        /* .sample mode with r61 corresponds to per-sample interpolation */
50
 
        if (I->sample == BI_SAMPLE_SAMPLE)
51
 
                return bi_is_value_equiv(I->src[0], bi_register(61));
52
 
 
53
 
        /* If the shader runs with pixel-frequency shading, .sample is
54
 
         * equivalent to .center, so allow .center
55
 
         *
56
 
         * If the shader runs with sample-frequency shading, .sample and .center
57
 
         * are not equivalent. However, the ESSL 3.20 specification
58
 
         * stipulates in section 4.5 ("Interpolation Qualifiers"):
59
 
         *
60
 
         *    for fragment shader input variables qualified with neither
61
 
         *    centroid nor sample, the value of the assigned variable may be
62
 
         *    interpolated anywhere within the pixel and a single value may be
63
 
         *    assigned to each sample within the pixel, to the extent permitted
64
 
         *    by the OpenGL ES Specification.
65
 
         *
66
 
         * We only produce .center for variables qualified with neither centroid
67
 
         * nor sample, so if .center is specified this section applies. This
68
 
         * suggests that, although per-pixel interpolation is allowed, it is not
69
 
         * mandated ("may" rather than "must" or "should"). Therefore it appears
70
 
         * safe to substitute sample.
71
 
         */
72
 
        return (I->sample == BI_SAMPLE_CENTER);
73
 
}
74
 
 
75
 
static bool
76
 
bi_can_preload_ld_var(bi_instr *I)
77
 
{
78
 
        return (I->op == BI_OPCODE_LD_VAR_IMM) &&
79
 
                bi_can_interp_at_sample(I) &&
80
 
                bi_is_regfmt_float(I->register_format);
81
 
}
82
 
 
83
 
static bool
84
 
bi_is_var_tex(enum bi_opcode op)
85
 
{
86
 
        return (op == BI_OPCODE_VAR_TEX_F32) || (op == BI_OPCODE_VAR_TEX_F16);
87
 
}
88
 
 
89
 
void
90
 
bi_opt_message_preload(bi_context *ctx)
91
 
{
92
 
        unsigned nr_preload = 0;
93
 
 
94
 
        /* We only preload from the first block */
95
 
        bi_block *block = bi_start_block(&ctx->blocks);
96
 
        bi_builder b = bi_init_builder(ctx, bi_before_nonempty_block(block));
97
 
 
98
 
        bi_foreach_instr_in_block_safe(block, I) {
99
 
                if (!bi_is_ssa(I->dest[0])) continue;
100
 
 
101
 
                struct bifrost_message_preload msg;
102
 
 
103
 
                if (bi_can_preload_ld_var(I)) {
104
 
                        msg = (struct bifrost_message_preload) {
105
 
                                .enabled = true,
106
 
                                .varying_index = I->varying_index,
107
 
                                .fp16 = (I->register_format == BI_REGISTER_FORMAT_F16),
108
 
                                .num_components = I->vecsize + 1
109
 
                        };
110
 
                } else if (bi_is_var_tex(I->op)) {
111
 
                        msg = (struct bifrost_message_preload) {
112
 
                                .enabled = true,
113
 
                                .texture = true,
114
 
                                .varying_index = I->varying_index,
115
 
                                .texture_index = I->texture_index,
116
 
                                .fp16 = (I->op == BI_OPCODE_VAR_TEX_F16),
117
 
                                .skip = I->skip,
118
 
                                .zero_lod = I->lod_mode
119
 
                        };
120
 
                } else {
121
 
                        continue;
122
 
                }
123
 
 
124
 
                /* Report the preloading */
125
 
                ctx->info.bifrost->messages[nr_preload] = msg;
126
 
 
127
 
                /* Replace with moves at the start. Ideally, they will be
128
 
                 * coalesced out or copy propagated.
129
 
                 */
130
 
                for (unsigned i = 0; i < bi_count_write_registers(I, 0); ++i) {
131
 
                        bi_mov_i32_to(&b, bi_word(I->dest[0], i),
132
 
                                          bi_register((nr_preload * 4) + i));
133
 
                }
134
 
 
135
 
                bi_remove_instruction(I);
136
 
 
137
 
                /* Maximum number of preloaded messages */
138
 
                if ((++nr_preload) == 2)
139
 
                        break;
140
 
        }
141
 
}