r600/sfn: Add tesselation shaders
[mesa.git] / src / gallium / drivers / r600 / sfn / sfn_nir.h
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_NIR_H
28 #define SFN_NIR_H
29
30 #include "nir.h"
31 #include "nir_builder.h"
32
33 #ifdef __cplusplus
34 #include "sfn_shader_base.h"
35 #include <vector>
36
37 namespace r600 {
38
39 bool r600_nir_lower_pack_unpack_2x16(nir_shader *shader);
40
41 bool r600_lower_scratch_addresses(nir_shader *shader);
42
43 bool r600_lower_ubo_to_align16(nir_shader *shader);
44
45 class Shader {
46 public:
47 std::vector<InstructionBlock>& m_ir;
48 ValueMap m_temp;
49 };
50
51 class ShaderFromNir {
52 public:
53 ShaderFromNir();
54 ~ShaderFromNir();
55
56 unsigned ninputs() const;
57
58 bool lower(const nir_shader *shader, r600_pipe_shader *sh,
59 r600_pipe_shader_selector *sel, r600_shader_key &key,
60 r600_shader *gs_shader);
61
62 bool process_declaration();
63
64 pipe_shader_type processor_type() const;
65
66 bool emit_instruction(nir_instr *instr);
67
68 const std::vector<InstructionBlock> &shader_ir() const;
69
70 Shader shader() const;
71 private:
72
73 bool process_block();
74 bool process_cf_node(nir_cf_node *node);
75 bool process_if(nir_if *node);
76 bool process_loop(nir_loop *node);
77 bool process_block(nir_block *node);
78
79 std::unique_ptr<ShaderFromNirProcessor> impl;
80 const nir_shader *sh;
81
82 int m_current_if_id;
83 int m_current_loop_id;
84 std::stack<int> m_if_stack;
85 int scratch_size;
86 };
87
88 class AssemblyFromShader {
89 public:
90 virtual ~AssemblyFromShader();
91 bool lower(const std::vector<InstructionBlock> &ir);
92 private:
93 virtual bool do_lower(const std::vector<InstructionBlock>& ir) = 0 ;
94 };
95
96 }
97
98 #endif
99
100 static inline nir_ssa_def *
101 r600_imm_ivec3(nir_builder *build, int x, int y, int z)
102 {
103 nir_const_value v[3] = {
104 nir_const_value_for_int(x, 32),
105 nir_const_value_for_int(y, 32),
106 nir_const_value_for_int(z, 32),
107 };
108
109 return nir_build_imm(build, 3, 32, v);
110 }
111
112 bool r600_lower_tess_io(nir_shader *shader, enum pipe_prim_type prim_type);
113 bool r600_append_tcs_TF_emission(nir_shader *shader, enum pipe_prim_type prim_type);
114
115 #ifdef __cplusplus
116 extern "C" {
117 #endif
118
119 bool r600_vectorize_vs_inputs(nir_shader *shader);
120
121
122 int r600_shader_from_nir(struct r600_context *rctx,
123 struct r600_pipe_shader *pipeshader,
124 union r600_shader_key *key);
125
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131
132 #endif // SFN_NIR_H