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.h"
35 #include <vector>
36
37 namespace r600 {
38
39 class NirLowerInstruction {
40 public:
41 NirLowerInstruction();
42
43 bool run(nir_shader *shader);
44
45 private:
46 static bool filter_instr(const nir_instr *instr, const void *data);
47 static nir_ssa_def *lower_instr(nir_builder *b, nir_instr *instr, void *data);
48
set_builder(nir_builder * _b)49 void set_builder(nir_builder *_b) { b = _b;}
50
51 virtual bool filter(const nir_instr *instr) const = 0;
52 virtual nir_ssa_def *lower(nir_instr *instr) = 0;
53 protected:
54 nir_builder *b;
55 };
56
57 bool r600_lower_scratch_addresses(nir_shader *shader);
58
59 bool r600_lower_ubo_to_align16(nir_shader *shader);
60
61 bool r600_nir_split_64bit_io(nir_shader *sh);
62
63 bool r600_nir_64_to_vec2(nir_shader *sh);
64
65 bool r600_merge_vec2_stores(nir_shader *shader);
66
67 bool r600_split_64bit_uniforms_and_ubo(nir_shader *sh);
68 bool r600_lower_64bit_to_vec2(nir_shader *sh);
69 bool r600_split_64bit_alu_and_phi(nir_shader *sh);
70 bool r600_lower_clipvertex_to_clipdist(nir_shader *sh);
71
72
73 class AssemblyFromShader {
74 public:
75 virtual ~AssemblyFromShader();
76 bool lower(const Shader& s);
77 private:
78 virtual bool do_lower(const Shader& s) = 0 ;
79 };
80
81 }
82
83 static inline nir_ssa_def *
r600_imm_ivec3(nir_builder * build,int x,int y,int z)84 r600_imm_ivec3(nir_builder *build, int x, int y, int z)
85 {
86 nir_const_value v[3] = {
87 nir_const_value_for_int(x, 32),
88 nir_const_value_for_int(y, 32),
89 nir_const_value_for_int(z, 32),
90 };
91
92 return nir_build_imm(build, 3, 32, v);
93 }
94
95 bool r600_lower_tess_io(nir_shader *shader, enum pipe_prim_type prim_type);
96 bool r600_append_tcs_TF_emission(nir_shader *shader, enum pipe_prim_type prim_type);
97 bool r600_lower_tess_coord(nir_shader *sh, enum pipe_prim_type prim_type);
98
99 bool
100 r600_legalize_image_load_store(nir_shader *shader);
101
102
103 #else
104 #include "gallium/drivers/r600/r600_shader.h"
105 #endif
106
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110
111 bool r600_vectorize_vs_inputs(nir_shader *shader);
112
113 bool r600_lower_to_scalar_instr_filter(const nir_instr *instr, const void *);
114
115 int r600_shader_from_nir(struct r600_context *rctx,
116 struct r600_pipe_shader *pipeshader,
117 union r600_shader_key *key);
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123
124 #endif // SFN_NIR_H
125