xref: /aosp_15_r20/external/mesa3d/src/compiler/nir/nir_legacy.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2023 Valve Corporation
3  * Copyright 2014 Connor Abbott
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef NIR_LEGACY_H
8 #define NIR_LEGACY_H
9 
10 #include "nir.h"
11 
12 typedef struct {
13    nir_def *handle;
14    /** NULL for no indirect offset */
15    nir_def *indirect;
16    unsigned base_offset;
17 } nir_reg_src;
18 
19 typedef struct {
20    nir_def *handle;
21    /** NULL for no indirect offset */
22    nir_def *indirect;
23    unsigned base_offset;
24 } nir_reg_dest;
25 
26 typedef struct {
27    bool is_ssa;
28 
29    union {
30       nir_reg_src reg;
31       nir_def *ssa;
32    };
33 } nir_legacy_src;
34 
35 typedef struct {
36    bool is_ssa;
37 
38    union {
39       nir_reg_dest reg;
40       nir_def *ssa;
41    };
42 } nir_legacy_dest;
43 
44 typedef struct {
45    /* Base source */
46    nir_legacy_src src;
47 
48    /* For inputs interpreted as floating point, flips the sign bit. */
49    bool fneg;
50 
51    /* Clears the sign bit for floating point values, Note that the negate
52     * modifier acts after the absolute value modifier, therefore if both are set
53     * then all inputs will become negative.
54     */
55    bool fabs;
56 
57    uint8_t swizzle[NIR_MAX_VEC_COMPONENTS];
58 } nir_legacy_alu_src;
59 
60 typedef struct {
61    /* Base destination */
62    nir_legacy_dest dest;
63 
64    nir_component_mask_t write_mask;
65 
66    /**
67     * Saturate output modifier
68     *
69     * Only valid for opcodes that output floating-point numbers. Clamps the
70     * output to between 0.0 and 1.0 inclusive.
71     */
72    bool fsat;
73 } nir_legacy_alu_dest;
74 
75 /* Prepare shader for use with legacy helpers. Must call on final NIR. */
76 void nir_legacy_trivialize(nir_shader *s, bool fuse_fabs);
77 
78 /* Reconstruct a legacy source/destination (including registers) */
79 nir_legacy_src nir_legacy_chase_src(const nir_src *src);
80 nir_legacy_dest nir_legacy_chase_dest(nir_def *def);
81 
82 /* Reconstruct a legacy ALU source/destination (including float modifiers) */
83 nir_legacy_alu_src nir_legacy_chase_alu_src(const nir_alu_src *src,
84                                             bool fuse_fabs);
85 nir_legacy_alu_dest nir_legacy_chase_alu_dest(nir_def *def);
86 
87 /* Check if a source modifier folds. If so, it may be skipped during instruction
88  * selection, avoiding the need for backend dead code elimination.
89  */
90 bool nir_legacy_float_mod_folds(nir_alu_instr *mod);
91 
92 /* Check if an fsat destination modifier folds. If so, it must be skipped to
93  * avoid multiple conflicting writes to the same definition.
94  */
95 bool nir_legacy_fsat_folds(nir_alu_instr *fsat);
96 
97 #endif
98