• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 2019 Collabora LTD
4  *
5  * Author: Gert Wollny <gert.wollny@collabora.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * on the rights to use, copy, modify, merge, publish, distribute, sub
11  * license, and/or sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #ifndef sfn_fragment_shader_from_nir_h
28 #define sfn_fragment_shader_from_nir_h
29 
30 #include "sfn_shader_base.h"
31 #include "sfn_shaderio.h"
32 #include <bitset>
33 
34 namespace r600 {
35 
36 class FragmentShaderFromNir : public ShaderFromNirProcessor {
37 public:
38    FragmentShaderFromNir(const nir_shader& nir, r600_shader& sh_info,
39                          r600_pipe_shader_selector &sel, const r600_shader_key &key,
40                          enum chip_class chip_class);
41    bool scan_sysvalue_access(nir_instr *instr) override;
42 private:
43 
44    struct Interpolator {
45       bool enabled;
46       unsigned ij_index;
47       PValue i;
48       PValue j;
49    };
50 
51    void emit_shader_start() override;
52    bool do_allocate_reserved_registers() override;
53    bool process_store_output(nir_intrinsic_instr *instr);
54 
55    bool emit_store_output(nir_intrinsic_instr* instr);
56 
57    bool emit_export_pixel(const nir_variable *, nir_intrinsic_instr* instr, int outputs);
58    bool emit_export_pixel(nir_intrinsic_instr* instr, int outputs);
59    bool load_interpolated(GPRVector &dest, ShaderInput &io, const Interpolator& ip,
60                           int num_components, int start_comp);
61    bool load_interpolated_one_comp(GPRVector &dest, ShaderInput& io, const Interpolator& ip, EAluOp op);
62    bool load_interpolated_two_comp(GPRVector &dest, ShaderInput& io, const Interpolator& ip,EAluOp op, int writemask);
63    bool load_interpolated_two_comp_for_one(GPRVector &dest,
64                                            ShaderInput& io, const Interpolator& ip, EAluOp op, int start, int comp);
65 
66    bool emit_intrinsic_instruction_override(nir_intrinsic_instr* instr) override;
67    void do_finalize() override;
68 
69    void load_front_face();
70 
71    bool emit_load_input(nir_intrinsic_instr* instr);
72    bool emit_load_front_face(nir_intrinsic_instr* instr);
73    bool emit_load_sample_mask_in(nir_intrinsic_instr* instr);
74    bool emit_load_sample_pos(nir_intrinsic_instr* instr);
75    bool emit_load_sample_id(nir_intrinsic_instr* instr);
76 
77    bool process_load_input(nir_intrinsic_instr *instr, bool interpolated);
78    bool emit_load_interpolated_input(nir_intrinsic_instr* instr);
79    bool load_barycentric_at_offset(nir_intrinsic_instr* instr);
80    bool load_barycentric_at_sample(nir_intrinsic_instr* instr);
81 
82 
83    unsigned m_max_color_exports;
84    unsigned m_max_counted_color_exports;
85    bool m_two_sided_color;
86    ExportInstruction *m_last_pixel_export;
87    const nir_shader& m_nir;
88 
89 
90    std::array<Interpolator, 6> m_interpolator;
91    unsigned m_reserved_registers;
92    unsigned m_frag_pos_index;
93    PGPRValue m_front_face_reg;
94    PGPRValue m_sample_mask_reg;
95    PGPRValue m_sample_id_reg;
96    PGPRValue m_helper_invocation;
97    GPRVector m_frag_pos;
98    bool m_need_back_color;
99    bool m_front_face_loaded;
100    ShaderIO m_shaderio;
101    unsigned m_depth_exports;
102 
103    std::map<unsigned, PValue> m_input_cache;
104 
105    static const int s_max_interpolators = 6;
106 
107    std::bitset<s_max_interpolators> m_interpolators_used;
108 
109    unsigned m_apply_sample_mask;
110    bool m_dual_source_blend;
111    ShaderInput *m_pos_input;
112 
113 };
114 
115 }
116 
117 #endif
118