added pipe->max_texture_size() query, use it in st_drawpixels()
[mesa.git] / src / mesa / pipe / i915simple / i915_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 #include "main/imports.h" /* CALLOC */
29 #include "i915_context.h"
30 #include "i915_winsys.h"
31 #include "i915_state.h"
32 #include "i915_batch.h"
33 #include "i915_tex_layout.h"
34
35 #include "pipe/draw/draw_context.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_winsys.h"
38
39 #define PCI_CHIP_I915_G 0x2582
40 #define PCI_CHIP_I915_GM 0x2592
41 #define PCI_CHIP_I945_G 0x2772
42 #define PCI_CHIP_I945_GM 0x27A2
43 #define PCI_CHIP_I945_GME 0x27AE
44 #define PCI_CHIP_G33_G 0x29C2
45 #define PCI_CHIP_Q35_G 0x29B2
46 #define PCI_CHIP_Q33_G 0x29D2
47
48
49 /**
50 * Return list of supported surface/texture formats.
51 * If we find texture and drawable support differs, add a selector
52 * parameter or another function.
53 */
54 static const GLuint *
55 i915_supported_formats(struct pipe_context *pipe,
56 // GLuint type,
57 GLuint *numFormats)
58 {
59 #if 0
60 static const GLuint tex_supported[] = {
61 PIPE_FORMAT_U_R8_G8_B8_A8,
62 PIPE_FORMAT_U_A8_R8_G8_B8,
63 PIPE_FORMAT_U_R5_G6_B5,
64 PIPE_FORMAT_U_L8,
65 PIPE_FORMAT_U_A8,
66 PIPE_FORMAT_U_I8,
67 PIPE_FORMAT_U_L8_A8,
68 PIPE_FORMAT_YCBCR,
69 PIPE_FORMAT_YCBCR_REV,
70 PIPE_FORMAT_S8_Z24,
71 };
72
73
74 /* Actually a lot more than this - add later:
75 */
76 static const GLuint render_supported[] = {
77 PIPE_FORMAT_U_A8_R8_G8_B8,
78 PIPE_FORMAT_U_R5_G6_B5,
79 };
80
81 /*
82 */
83 static const GLuint z_stencil_supported[] = {
84 PIPE_FORMAT_U_Z16,
85 PIPE_FORMAT_U_Z32,
86 PIPE_FORMAT_S8_Z24,
87 };
88
89 switch (type) {
90 case PIPE_RENDER_FORMAT:
91 *numFormats = Elements(render_supported);
92 return render_supported;
93
94 case PIPE_TEX_FORMAT:
95 *numFormats = Elements(tex_supported);
96 return render_supported;
97
98 case PIPE_Z_STENCIL_FORMAT:
99 *numFormats = Elements(render_supported);
100 return render_supported;
101
102 default:
103 *numFormats = 0;
104 return NULL;
105 }
106 #else
107 static const GLuint render_supported[] = {
108 PIPE_FORMAT_U_A8_R8_G8_B8,
109 PIPE_FORMAT_U_R5_G6_B5,
110 PIPE_FORMAT_S8_Z24,
111 };
112 *numFormats = 3;
113 return render_supported;
114 #endif
115 }
116
117
118 /**
119 * We might want to return max texture levels instead...
120 */
121 static void
122 i915_max_texture_size(struct pipe_context *pipe, GLuint textureType,
123 GLuint *maxWidth, GLuint *maxHeight, GLuint *maxDepth)
124 {
125 switch (textureType) {
126 case PIPE_TEXTURE_1D:
127 *maxWidth = 2048;
128 break;
129 case PIPE_TEXTURE_2D:
130 *maxWidth =
131 *maxHeight = 2048;
132 break;
133 case PIPE_TEXTURE_3D:
134 *maxWidth =
135 *maxHeight =
136 *maxDepth = 256;
137 break;
138 case PIPE_TEXTURE_CUBE:
139 *maxWidth =
140 *maxHeight = 2048;
141 break;
142 default:
143 assert(0);
144 }
145 }
146
147
148 static void i915_destroy( struct pipe_context *pipe )
149 {
150 struct i915_context *i915 = i915_context( pipe );
151
152 draw_destroy( i915->draw );
153
154 free( i915 );
155 }
156
157 static void i915_draw_vb( struct pipe_context *pipe,
158 struct vertex_buffer *VB )
159 {
160 struct i915_context *i915 = i915_context( pipe );
161
162 if (i915->dirty)
163 i915_update_derived( i915 );
164
165 draw_vb( i915->draw, VB );
166 }
167
168
169 static void
170 i915_draw_vertices(struct pipe_context *pipe,
171 GLuint mode,
172 GLuint numVertex, const GLfloat *verts,
173 GLuint numAttribs, const GLuint attribs[])
174 {
175 struct i915_context *i915 = i915_context( pipe );
176
177 if (i915->dirty)
178 i915_update_derived( i915 );
179
180 draw_vertices(i915->draw, mode, numVertex, verts, numAttribs, attribs);
181 }
182
183
184
185
186 struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
187 struct i915_winsys *i915_winsys,
188 unsigned pci_id )
189 {
190 struct i915_context *i915;
191 unsigned is_i945 = 0;
192
193 /* TODO: Push this down into the pipe driver:
194 */
195 switch (pci_id) {
196 case PCI_CHIP_I915_G:
197 case PCI_CHIP_I915_GM:
198 break;
199
200 case PCI_CHIP_I945_G:
201 case PCI_CHIP_I945_GM:
202 case PCI_CHIP_I945_GME:
203 case PCI_CHIP_G33_G:
204 case PCI_CHIP_Q33_G:
205 case PCI_CHIP_Q35_G:
206 is_i945 = 1;
207 break;
208
209 default:
210 pipe_winsys->printf(pipe_winsys,
211 "%s: unknown pci id 0x%x, cannot create context\n",
212 __FUNCTION__, pci_id);
213 return NULL;
214 }
215
216 i915 = CALLOC_STRUCT(i915_context);
217 if (i915 == NULL)
218 return NULL;
219
220 i915->winsys = i915_winsys;
221 i915->pipe.winsys = pipe_winsys;
222
223 i915->pipe.destroy = i915_destroy;
224 i915->pipe.supported_formats = i915_supported_formats;
225 i915->pipe.max_texture_size = i915_max_texture_size;
226 i915->pipe.draw_vb = i915_draw_vb;
227 i915->pipe.draw_vertices = i915_draw_vertices;
228 i915->pipe.clear = i915_clear;
229 i915->pipe.reset_occlusion_counter = NULL; /* no support */
230 i915->pipe.get_occlusion_counter = NULL;
231
232
233 /*
234 * Create drawing context and plug our rendering stage into it.
235 */
236 i915->draw = draw_create();
237 assert(i915->draw);
238 draw_set_setup_stage(i915->draw, i915_draw_render_stage(i915));
239
240 i915_init_region_functions(i915);
241 i915_init_surface_functions(i915);
242 i915_init_state_functions(i915);
243 i915_init_flush_functions(i915);
244
245
246 if (i915->flags.is_i945)
247 i915->pipe.mipmap_tree_layout = i945_miptree_layout;
248 else
249 i915->pipe.mipmap_tree_layout = i945_miptree_layout;
250
251
252 i915->dirty = ~0;
253 i915->hardware_dirty = ~0;
254
255 /* Batch stream debugging is a bit hacked up at the moment:
256 */
257 i915->batch_start = BEGIN_BATCH(0, 0);
258
259 /*
260 * XXX we could plug GL selection/feedback into the drawing pipeline
261 * by specifying a different setup/render stage.
262 */
263
264 return &i915->pipe;
265 }
266