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 "v3d_compiler.h"
25 #include "compiler/nir/nir_builder.h"
27 /** @file v3d_nir_lower_txf_ms.c
29 * V3D's MSAA surfaces are laid out in UIF textures where each pixel is a 2x2
30 * quad in the texture. This pass lowers the txf_ms with a ms_index source to
31 * a plain txf with the sample_index pulling out the correct texel from the
35 #define V3D_MAX_SAMPLES 4
38 vc4_nir_lower_txf_ms_instr(struct v3d_compile
*c
, nir_builder
*b
,
41 if (instr
->op
!= nir_texop_txf_ms
)
44 b
->cursor
= nir_before_instr(&instr
->instr
);
46 int coord_index
= nir_tex_instr_src_index(instr
, nir_tex_src_coord
);
47 int sample_index
= nir_tex_instr_src_index(instr
, nir_tex_src_ms_index
);
48 nir_ssa_def
*coord
= instr
->src
[coord_index
].src
.ssa
;
49 nir_ssa_def
*sample
= instr
->src
[sample_index
].src
.ssa
;
51 nir_ssa_def
*one
= nir_imm_int(b
, 1);
52 coord
= nir_ishl(b
, coord
, nir_imm_int(b
, 1));
55 nir_channel(b
, coord
, 0),
56 nir_iand(b
, sample
, one
)),
58 nir_channel(b
, coord
, 1),
59 nir_iand(b
, nir_ushr(b
, sample
, one
), one
)));
61 nir_instr_rewrite_src(&instr
->instr
,
62 &instr
->src
[nir_tex_src_coord
].src
,
63 nir_src_for_ssa(coord
));
64 nir_tex_instr_remove_src(instr
, sample_index
);
65 instr
->op
= nir_texop_txf
;
66 instr
->sampler_dim
= GLSL_SAMPLER_DIM_2D
;
70 v3d_nir_lower_txf_ms(nir_shader
*s
, struct v3d_compile
*c
)
72 nir_foreach_function(function
, s
) {
77 nir_builder_init(&b
, function
->impl
);
79 nir_foreach_block(block
, function
->impl
) {
80 nir_foreach_instr_safe(instr
, block
) {
81 if (instr
->type
!= nir_instr_type_tex
)
84 vc4_nir_lower_txf_ms_instr(c
, &b
,
85 nir_instr_as_tex(instr
));
89 nir_metadata_preserve(function
->impl
,
90 nir_metadata_block_index
|
91 nir_metadata_dominance
);