• 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_process_inputs(nir_variable *input) override;
53    bool do_allocate_reserved_registers() override;
54    bool do_process_outputs(nir_variable *output) override;
55    bool do_emit_load_deref(const nir_variable *in_var, nir_intrinsic_instr* instr) override;
56    bool do_emit_store_deref(const nir_variable *out_var, nir_intrinsic_instr* instr) override;
57    bool emit_export_pixel(const nir_variable *, nir_intrinsic_instr* instr, int outputs);
58    bool load_interpolated(GPRVector &dest, ShaderInput &io, const Interpolator& ip,
59                           int num_components, int start_comp);
60    bool load_interpolated_one_comp(GPRVector &dest, ShaderInput& io, const Interpolator& ip, EAluOp op);
61    bool load_interpolated_two_comp(GPRVector &dest, ShaderInput& io, const Interpolator& ip,EAluOp op, int writemask);
62    bool load_interpolated_two_comp_for_one(GPRVector &dest,
63                                            ShaderInput& io, const Interpolator& ip, EAluOp op, int start, int comp);
64    bool emit_interp_deref_at_centroid(nir_intrinsic_instr* instr);
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_front_face(nir_intrinsic_instr* instr);
72    bool emit_load_sample_mask_in(nir_intrinsic_instr* instr);
73    bool emit_load_sample_pos(nir_intrinsic_instr* instr);
74    bool emit_load_sample_id(nir_intrinsic_instr* instr);
75    bool emit_interp_deref_at_sample(nir_intrinsic_instr* instr);
76    bool emit_interp_deref_at_offset(nir_intrinsic_instr* instr);
77 
78    unsigned m_max_color_exports;
79    unsigned m_max_counted_color_exports;
80    bool m_two_sided_color;
81    ExportInstruction *m_last_pixel_export;
82    const nir_shader& m_nir;
83 
84 
85    std::array<Interpolator, 6> m_interpolator;
86    unsigned m_reserved_registers;
87    unsigned m_frag_pos_index;
88    PGPRValue m_front_face_reg;
89    PGPRValue m_sample_mask_reg;
90    PGPRValue m_sample_id_reg;
91    PGPRValue m_helper_invocation;
92    GPRVector m_frag_pos;
93    bool m_need_back_color;
94    bool m_front_face_loaded;
95    ShaderIO m_shaderio;
96    unsigned m_depth_exports;
97 
98    std::map<unsigned, PValue> m_input_cache;
99    bool m_enable_centroid_interpolators;
100    bool m_enable_sample_interpolators;
101    unsigned m_apply_sample_mask;
102    bool m_dual_source_blend;
103 };
104 
105 }
106 
107 #endif
108