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