37caeed85fda5b8575243210920b3a623bc1febd
[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 const 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 struct {
88 struct pipe_surface *cbuf;
89 struct pipe_surface *zsbuf;
90 } fb;
91
92 struct {
93 unsigned flags;
94 union lp_rast_cmd_arg color;
95 union lp_rast_cmd_arg zstencil;
96 } clear;
97
98 enum {
99 SETUP_FLUSHED,
100 SETUP_CLEARED,
101 SETUP_ACTIVE
102 } state;
103
104 struct {
105 struct lp_shader_input input[PIPE_MAX_ATTRIBS];
106 unsigned nr_inputs;
107 } fs;
108
109 void (*point)( struct setup_context *,
110 const float (*v0)[4]);
111
112 void (*line)( struct setup_context *,
113 const float (*v0)[4],
114 const float (*v1)[4]);
115
116 void (*triangle)( struct setup_context *,
117 const float (*v0)[4],
118 const float (*v1)[4],
119 const float (*v2)[4]);
120 };
121
122 void lp_setup_choose_triangle( struct setup_context *setup );
123 void lp_setup_choose_line( struct setup_context *setup );
124 void lp_setup_choose_point( struct setup_context *setup );
125
126
127 void lp_setup_new_data_block( struct data_block_list *list );
128 void lp_setup_new_cmd_block( struct cmd_block_list *list );
129
130 static INLINE void *get_data( struct data_block_list *list,
131 unsigned size)
132 {
133
134 if (list->tail->used + size > DATA_BLOCK_SIZE) {
135 lp_setup_new_data_block( list );
136 }
137
138 {
139 struct data_block *tail = list->tail;
140 ubyte *data = tail->data + tail->used;
141 tail->used += size;
142 return data;
143 }
144 }
145
146 /* Add a command to a given bin.
147 */
148 static INLINE void bin_cmd( struct cmd_block_list *list,
149 lp_rast_cmd cmd,
150 const union lp_rast_cmd_arg *arg )
151 {
152 if (list->tail->count == CMD_BLOCK_MAX) {
153 lp_setup_new_cmd_block( list );
154 }
155
156 {
157 struct cmd_block *tail = list->tail;
158 unsigned i = tail->count;
159 tail->cmd[i] = cmd;
160 tail->arg[i] = arg;
161 tail->count++;
162 }
163 }
164
165
166
167 #endif