llvmpipe: Pass state to setup.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_context.h
1 /**************************************************************************
2 *
3 * Copyright 2007-2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef LP_SETUP_CONTEXT_H
29 #define LP_SETUP_CONTEXT_H
30
31 #include "lp_setup.h"
32 #include "lp_rast.h"
33
34 /* We're limited to 2K by 2K for 32bit fixed point rasterization.
35 * Will need a 64-bit version for larger framebuffers.
36 */
37 #define MAXHEIGHT 2048
38 #define MAXWIDTH 2048
39 #define TILES_X (MAXWIDTH / TILESIZE)
40 #define TILES_Y (MAXHEIGHT / TILESIZE)
41
42 #define CMD_BLOCK_MAX 128
43 #define DATA_BLOCK_SIZE (16 * 1024 - sizeof(unsigned) - sizeof(void *))
44
45
46 /* switch to a non-pointer value for this:
47 */
48 typedef void (*lp_rast_cmd)( struct lp_rasterizer *, const union lp_rast_cmd_arg );
49
50 struct cmd_block {
51 lp_rast_cmd cmd[CMD_BLOCK_MAX];
52 union lp_rast_cmd_arg arg[CMD_BLOCK_MAX];
53 unsigned count;
54 struct cmd_block *next;
55 };
56
57 struct data_block {
58 ubyte data[DATA_BLOCK_SIZE];
59 unsigned used;
60 struct data_block *next;
61 };
62
63 struct cmd_block_list {
64 struct cmd_block *head;
65 struct cmd_block *tail;
66 };
67
68 struct data_block_list {
69 struct data_block *head;
70 struct data_block *tail;
71 };
72
73
74 struct setup_context {
75
76 struct lp_rasterizer *rast;
77
78 /* When there are multiple threads, will want to double-buffer the
79 * bin arrays:
80 */
81 struct cmd_block_list tile[TILES_X][TILES_Y];
82 struct data_block_list data;
83
84 unsigned tiles_x;
85 unsigned tiles_y;
86
87 boolean ccw_is_frontface;
88 unsigned cullmode;
89
90 struct {
91 struct pipe_surface *cbuf;
92 struct pipe_surface *zsbuf;
93 unsigned width;
94 unsigned height;
95 } fb;
96
97 struct {
98 unsigned flags;
99 union lp_rast_cmd_arg color;
100 union lp_rast_cmd_arg zstencil;
101 } clear;
102
103 enum {
104 SETUP_FLUSHED,
105 SETUP_CLEARED,
106 SETUP_ACTIVE
107 } state;
108
109 struct {
110 struct lp_shader_input input[PIPE_MAX_ATTRIBS];
111 unsigned nr_inputs;
112
113 struct lp_jit_context jit_context;
114 lp_jit_frag_func jit_function;
115
116 boolean jit_context_dirty;
117 } fs;
118
119 void (*point)( struct setup_context *,
120 const float (*v0)[4]);
121
122 void (*line)( struct setup_context *,
123 const float (*v0)[4],
124 const float (*v1)[4]);
125
126 void (*triangle)( struct setup_context *,
127 const float (*v0)[4],
128 const float (*v1)[4],
129 const float (*v2)[4]);
130 };
131
132 void lp_setup_choose_triangle( struct setup_context *setup );
133 void lp_setup_choose_line( struct setup_context *setup );
134 void lp_setup_choose_point( struct setup_context *setup );
135
136
137 void lp_setup_new_data_block( struct data_block_list *list );
138 void lp_setup_new_cmd_block( struct cmd_block_list *list );
139
140 static INLINE void *get_data( struct data_block_list *list,
141 unsigned size)
142 {
143
144 if (list->tail->used + size > DATA_BLOCK_SIZE) {
145 lp_setup_new_data_block( list );
146 }
147
148 {
149 struct data_block *tail = list->tail;
150 ubyte *data = tail->data + tail->used;
151 tail->used += size;
152 return data;
153 }
154 }
155
156 /* Add a command to a given bin.
157 */
158 static INLINE void bin_command( struct cmd_block_list *list,
159 lp_rast_cmd cmd,
160 union lp_rast_cmd_arg arg )
161 {
162 if (list->tail->count == CMD_BLOCK_MAX) {
163 lp_setup_new_cmd_block( list );
164 }
165
166 {
167 struct cmd_block *tail = list->tail;
168 unsigned i = tail->count;
169 tail->cmd[i] = cmd;
170 tail->arg[i] = arg;
171 tail->count++;
172 }
173 }
174
175
176
177 #endif