e2ed1cc3dda8fe7eab2e1c5b7cb899a95f9edebb
[mesa.git] / src / gallium / drivers / freedreno / a3xx / fd3_program.h
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #ifndef FD3_PROGRAM_H_
30 #define FD3_PROGRAM_H_
31
32 #include "pipe/p_context.h"
33
34 #include "freedreno_context.h"
35 #include "fd3_util.h"
36 #include "ir3.h"
37 #include "disasm.h"
38
39 typedef uint16_t fd3_semantic; /* semantic name + index */
40 static inline fd3_semantic
41 fd3_semantic_name(uint8_t name, uint16_t index)
42 {
43 return (name << 8) | (index & 0xff);
44 }
45
46 static inline uint8_t sem2name(fd3_semantic sem)
47 {
48 return sem >> 8;
49 }
50
51 static inline uint16_t sem2idx(fd3_semantic sem)
52 {
53 return sem & 0xff;
54 }
55
56 struct fd3_shader_variant {
57 struct fd_bo *bo;
58
59 struct fd3_shader_key key;
60
61 struct ir3_info info;
62 struct ir3 *ir;
63
64 /* the instructions length is in units of instruction groups
65 * (4 instructions, 8 dwords):
66 */
67 unsigned instrlen;
68
69 /* the constants length is in units of vec4's, and is the sum of
70 * the uniforms and the built-in compiler constants
71 */
72 unsigned constlen;
73
74 /* About Linkage:
75 * + Let the frag shader determine the position/compmask for the
76 * varyings, since it is the place where we know if the varying
77 * is actually used, and if so, which components are used. So
78 * what the hw calls "outloc" is taken from the "inloc" of the
79 * frag shader.
80 * + From the vert shader, we only need the output regid
81 */
82
83 /* for frag shader, pos_regid holds the frag_pos, ie. what is passed
84 * to bary.f instructions
85 */
86 uint8_t pos_regid;
87 bool frag_coord, frag_face;
88
89 /* varyings/outputs: */
90 unsigned outputs_count;
91 struct {
92 fd3_semantic semantic;
93 uint8_t regid;
94 } outputs[16 + 2]; /* +POSITION +PSIZE */
95 bool writes_pos, writes_psize;
96
97 /* vertices/inputs: */
98 unsigned inputs_count;
99 struct {
100 fd3_semantic semantic;
101 uint8_t regid;
102 uint8_t compmask;
103 uint8_t ncomp;
104 /* in theory inloc of fs should match outloc of vs: */
105 uint8_t inloc;
106 uint8_t bary;
107 } inputs[16 + 2]; /* +POSITION +FACE */
108
109 unsigned total_in; /* sum of inputs (scalar) */
110
111 /* do we have one or more texture sample instructions: */
112 bool has_samp;
113
114 /* const reg # of first immediate, ie. 1 == c1
115 * (not regid, because TGSI thinks in terms of vec4 registers,
116 * not scalar registers)
117 */
118 unsigned first_immediate;
119 unsigned immediates_count;
120 struct {
121 uint32_t val[4];
122 } immediates[64];
123
124 /* shader varients form a linked list: */
125 struct fd3_shader_variant *next;
126
127 /* replicated here to avoid passing extra ptrs everywhere: */
128 enum shader_t type;
129 struct fd3_shader_stateobj *so;
130 };
131
132 struct fd3_shader_stateobj {
133 enum shader_t type;
134
135 struct pipe_context *pctx;
136 const struct tgsi_token *tokens;
137
138 struct fd3_shader_variant *variants;
139
140 /* so far, only used for blit_prog shader.. values for
141 * VPC_VARYING_INTERP[i].MODE and VPC_VARYING_PS_REPL[i].MODE
142 *
143 * Possibly should be in fd3_program_variant?
144 */
145 uint32_t vinterp[4], vpsrepl[4];
146 };
147
148 struct fd3_shader_variant * fd3_shader_variant(struct fd3_shader_stateobj *so,
149 struct fd3_shader_key key);
150
151 void fd3_program_emit(struct fd_ringbuffer *ring,
152 struct fd_program_stateobj *prog, struct fd3_shader_key key);
153
154 void fd3_prog_init(struct pipe_context *pctx);
155
156 #endif /* FD3_PROGRAM_H_ */