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