2 * Copyright © 2015 Broadcom
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:
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
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
24 #include "compiler/v3d_compiler.h"
25 #include "compiler/nir/nir_builder.h"
28 * Walks the NIR generated by TGSI-to-NIR or GLSL-to-NIR to lower its io
29 * intrinsics into something amenable to the V3D architecture.
31 * After moving more and more logic to NIR, all that's left here is fixing up
32 * addressing on uniform loads. FS input and VS output scalarization is
33 * handled by nir_lower_io_to_scalar().
36 /* Convert the uniform offset to bytes. If it happens to be a constant,
37 * constant-folding will clean up the shift for us.
40 v3d_nir_lower_uniform(struct v3d_compile
*c
, nir_builder
*b
,
41 nir_intrinsic_instr
*intr
)
43 b
->cursor
= nir_before_instr(&intr
->instr
);
45 nir_intrinsic_set_base(intr
, nir_intrinsic_base(intr
) * 16);
47 nir_instr_rewrite_src(&intr
->instr
,
49 nir_src_for_ssa(nir_ishl(b
, intr
->src
[0].ssa
,
54 v3d_nir_lower_io_instr(struct v3d_compile
*c
, nir_builder
*b
,
55 struct nir_instr
*instr
)
57 if (instr
->type
!= nir_instr_type_intrinsic
)
59 nir_intrinsic_instr
*intr
= nir_instr_as_intrinsic(instr
);
61 switch (intr
->intrinsic
) {
62 case nir_intrinsic_load_uniform
:
63 v3d_nir_lower_uniform(c
, b
, intr
);
72 v3d_nir_lower_io_impl(struct v3d_compile
*c
, nir_function_impl
*impl
)
75 nir_builder_init(&b
, impl
);
77 nir_foreach_block(block
, impl
) {
78 nir_foreach_instr_safe(instr
, block
)
79 v3d_nir_lower_io_instr(c
, &b
, instr
);
82 nir_metadata_preserve(impl
, nir_metadata_block_index
|
83 nir_metadata_dominance
);
89 v3d_nir_lower_io(nir_shader
*s
, struct v3d_compile
*c
)
91 nir_foreach_function(function
, s
) {
93 v3d_nir_lower_io_impl(c
, function
->impl
);