• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors (Collabora):
24  *   Eric Smith <eric.smith@collabora.com>
25  */
26 
27 #include "compiler/nir/nir.h"
28 #include "compiler/nir/nir_builder.h"
29 #include "pan_ir.h"
30 
31 static bool
nir_lower_image_ms(nir_builder * b,nir_intrinsic_instr * intr,UNUSED void * data)32 nir_lower_image_ms(nir_builder *b, nir_intrinsic_instr *intr,
33                         UNUSED void *data)
34 {
35    switch (intr->intrinsic) {
36    case nir_intrinsic_image_load:
37    case nir_intrinsic_image_deref_load:
38    case nir_intrinsic_image_store:
39    case nir_intrinsic_image_deref_store:
40    case nir_intrinsic_image_texel_address:
41       break;
42    default:
43       return false;
44    }
45 
46    if (nir_intrinsic_image_dim(intr) != GLSL_SAMPLER_DIM_MS)
47       return false;
48 
49    b->cursor = nir_before_instr(&intr->instr);
50 
51    nir_def *coord = intr->src[1].ssa;
52    nir_def *index = intr->src[2].ssa;
53 
54    /* image2DMS is treated by panfrost as if it were a 3D image, so
55     * the sample index is in src[2]. We need to put this into the coordinates
56     * in the Z component
57     */
58    nir_src_rewrite(&intr->src[1],
59                    nir_vector_insert_imm(b, coord,
60                                          nir_channel(b, index, 0),
61                                          2) );
62    nir_intrinsic_set_image_dim(intr, GLSL_SAMPLER_DIM_3D);
63    return true;
64 }
65 
66 bool
pan_nir_lower_image_ms(nir_shader * shader)67 pan_nir_lower_image_ms(nir_shader *shader)
68 {
69    return nir_shader_intrinsics_pass(
70       shader, nir_lower_image_ms,
71       nir_metadata_block_index | nir_metadata_dominance, NULL);
72 }
73