1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2018 Jonathan Marek <jonathan@marek.ca>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Jonathan Marek <jonathan@marek.ca>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifndef IR2_H_
28bf215546Sopenharmony_ci#define IR2_H_
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "compiler/nir/nir.h"
31bf215546Sopenharmony_ci#include "pipe/p_context.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cistruct ir2_fetch_info {
34bf215546Sopenharmony_ci   /* dword offset of the fetch instruction */
35bf215546Sopenharmony_ci   uint16_t offset;
36bf215546Sopenharmony_ci   union {
37bf215546Sopenharmony_ci      /* swizzle to merge with tgsi swizzle */
38bf215546Sopenharmony_ci      struct {
39bf215546Sopenharmony_ci         uint16_t dst_swiz;
40bf215546Sopenharmony_ci      } vtx;
41bf215546Sopenharmony_ci      /* sampler id to patch const_idx */
42bf215546Sopenharmony_ci      struct {
43bf215546Sopenharmony_ci         uint16_t samp_id;
44bf215546Sopenharmony_ci         uint8_t src_swiz;
45bf215546Sopenharmony_ci      } tex;
46bf215546Sopenharmony_ci   };
47bf215546Sopenharmony_ci};
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_cistruct ir2_shader_info {
50bf215546Sopenharmony_ci   /* compiler shader */
51bf215546Sopenharmony_ci   uint32_t *dwords;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   /* size of the compiled shader in dwords */
54bf215546Sopenharmony_ci   uint16_t sizedwords;
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   /* highest GPR # used by shader */
57bf215546Sopenharmony_ci   int8_t max_reg;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   /* offset in dwords of first MEMORY export CF (for a20x hw binning) */
60bf215546Sopenharmony_ci   int16_t mem_export_ptr;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   /* fetch instruction info for patching */
63bf215546Sopenharmony_ci   uint16_t num_fetch_instrs;
64bf215546Sopenharmony_ci   struct ir2_fetch_info fetch_info[64];
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct ir2_frag_linkage {
68bf215546Sopenharmony_ci   unsigned inputs_count;
69bf215546Sopenharmony_ci   struct {
70bf215546Sopenharmony_ci      uint8_t slot;
71bf215546Sopenharmony_ci      uint8_t ncomp;
72bf215546Sopenharmony_ci   } inputs[16];
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   /* driver_location of fragcoord.zw, -1 if not used */
75bf215546Sopenharmony_ci   int fragcoord;
76bf215546Sopenharmony_ci};
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_cistruct ir2_shader_variant {
79bf215546Sopenharmony_ci   struct ir2_shader_info info;
80bf215546Sopenharmony_ci   struct ir2_frag_linkage f;
81bf215546Sopenharmony_ci};
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_cistruct fd2_shader_stateobj;
84bf215546Sopenharmony_cistruct tgsi_token;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_civoid ir2_compile(struct fd2_shader_stateobj *so, unsigned variant,
87bf215546Sopenharmony_ci                 struct fd2_shader_stateobj *fp);
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_cistruct nir_shader *ir2_tgsi_to_nir(const struct tgsi_token *tokens,
90bf215546Sopenharmony_ci                                   struct pipe_screen *screen);
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ciconst nir_shader_compiler_options *ir2_get_compiler_options(void);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ciint ir2_optimize_nir(nir_shader *s, bool lower);
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci#endif /* IR2_H_ */
97