• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 2022 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_SHADER_VS_H
28 #define SFN_SHADER_VS_H
29 
30 #include "sfn_shader.h"
31 
32 namespace r600 {
33 
34 class VertexStageShader : public Shader {
35 protected:
36    using Shader::Shader;
37 
38 public:
primitive_id()39    PRegister primitive_id() const { return m_primitive_id; }
set_primitive_id(PRegister prim_id)40    void set_primitive_id(PRegister prim_id) { m_primitive_id = prim_id; }
41 
42    void combine_enabled_stream_buffers_mask(uint32_t mask);
43    uint32_t enabled_stream_buffers_mask() const override;
44 
45 private:
46    PRegister m_primitive_id{nullptr};
47    uint32_t m_enabled_stream_buffers_mask{0};
48 };
49 
50 class VertexExportStage : public Allocate {
51 public:
52    VertexExportStage(VertexStageShader *parent);
53 
54    bool store_output(nir_intrinsic_instr& intr);
55 
56    virtual void finalize() = 0;
57 
58    virtual void get_shader_info(r600_shader *sh_info) const = 0;
59 
60 protected:
61    struct store_loc {
62       unsigned frac;
63       unsigned location;
64       unsigned driver_location;
65       int data_loc;
66    };
67 
68    virtual bool do_store_output(const store_loc& store_info,
69                                 nir_intrinsic_instr& intr) = 0;
70 
71    VertexStageShader *m_parent;
72 
73 private:
74 };
75 
76 class VertexExportForFs : public VertexExportStage {
77    friend VertexExportStage;
78 
79 public:
80    VertexExportForFs(VertexStageShader *parent,
81                      const pipe_stream_output_info *so_info,
82                      const r600_shader_key& key);
83 
84    void finalize() override;
85 
86    void get_shader_info(r600_shader *sh_info) const override;
87 
88 private:
89    bool do_store_output(const store_loc& store_info, nir_intrinsic_instr& intr) override;
90 
91    bool emit_varying_pos(const store_loc& store_info,
92                          nir_intrinsic_instr& intr,
93                          std::array<uint8_t, 4> *swizzle_override = nullptr);
94    bool emit_varying_param(const store_loc& store_info, nir_intrinsic_instr& intr);
95 
96    bool emit_clip_vertices(const store_loc& store_info, const nir_intrinsic_instr& instr);
97 
98    bool emit_stream(int stream);
99 
100    const RegisterVec4 *output_register(int loc) const;
101 
102    ExportInstr *m_last_param_export{nullptr};
103    ExportInstr *m_last_pos_export{nullptr};
104 
105    int m_num_clip_dist{0};
106    int m_next_param{0};
107    uint8_t m_cc_dist_mask{0};
108    uint8_t m_clip_dist_write{0};
109    int m_cur_clip_pos{1};
110    bool m_writes_point_size{false};
111    bool m_out_misc_write{false};
112    bool m_vs_out_layer{false};
113    bool m_vs_as_gs_a{false};
114    bool m_out_edgeflag{false};
115    bool m_out_viewport{false};
116    bool m_out_point_size{false};
117    RegisterVec4 m_clip_vertex;
118 
119    const pipe_stream_output_info *m_so_info{nullptr};
120 
121    template <typename Key, typename T>
122    using unordered_map_alloc = std::unordered_map<Key,
123                                                   T,
124                                                   std::hash<Key>,
125                                                   std::equal_to<Key>,
126                                                   Allocator<std::pair<const Key, T>>>;
127 
128    unordered_map_alloc<int, RegisterVec4 *> m_output_registers;
129 };
130 
131 class VertexExportForGS : public VertexExportStage {
132 public:
133    VertexExportForGS(VertexStageShader *parent, const r600_shader *gs_shader);
134    void finalize() override;
135 
136    void get_shader_info(r600_shader *sh_info) const override;
137 
138 private:
139    bool do_store_output(const store_loc& store_info, nir_intrinsic_instr& intr) override;
140    unsigned m_num_clip_dist{0};
141    bool m_vs_out_viewport{false};
142    bool m_vs_out_misc_write{false};
143 
144    const r600_shader *m_gs_shader;
145 };
146 
147 class VertexExportForTCS : public VertexExportStage {
148 public:
149    VertexExportForTCS(VertexStageShader *parent);
150    void finalize() override;
151    void get_shader_info(r600_shader *sh_info) const override;
152 
153 private:
154    bool do_store_output(const store_loc& store_info, nir_intrinsic_instr& intr) override;
155 };
156 
157 class VertexShader : public VertexStageShader {
158 public:
159    VertexShader(const pipe_stream_output_info *so_info,
160                 r600_shader *gs_shader,
161                 const r600_shader_key& key);
162 
163    bool load_input(nir_intrinsic_instr *intr) override;
164    bool store_output(nir_intrinsic_instr *intr) override;
165 
166    bool process_stage_intrinsic(nir_intrinsic_instr *intr) override;
167 
168 private:
169    bool do_scan_instruction(nir_instr *instr) override;
170    int do_allocate_reserved_registers() override;
171 
172    void do_finalize() override;
173 
174    bool read_prop(std::istream& is) override;
175 
176    void do_print_properties(std::ostream& os) const override;
177    void do_get_shader_info(r600_shader *sh_info) override;
178 
179    VertexExportStage *m_export_stage{nullptr};
180    int m_last_vertex_attribute_register{0};
181    PRegister m_vertex_id{nullptr};
182    PRegister m_instance_id{nullptr};
183    PRegister m_rel_vertex_id{nullptr};
184    bool m_vs_as_gs_a;
185 };
186 
187 } // namespace r600
188 
189 #endif
190