1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
35 #include "pipe/draw/draw_context.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_winsys.h"
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
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.
55 i915_supported_formats(struct pipe_context
*pipe
,
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
,
69 PIPE_FORMAT_YCBCR_REV
,
74 /* Actually a lot more than this - add later:
76 static const GLuint render_supported
[] = {
77 PIPE_FORMAT_U_A8_R8_G8_B8
,
78 PIPE_FORMAT_U_R5_G6_B5
,
83 static const GLuint z_stencil_supported
[] = {
90 case PIPE_RENDER_FORMAT
:
91 *numFormats
= Elements(render_supported
);
92 return render_supported
;
95 *numFormats
= Elements(tex_supported
);
96 return render_supported
;
98 case PIPE_Z_STENCIL_FORMAT
:
99 *numFormats
= Elements(render_supported
);
100 return render_supported
;
107 static const GLuint render_supported
[] = {
108 PIPE_FORMAT_U_A8_R8_G8_B8
,
109 PIPE_FORMAT_U_R5_G6_B5
,
113 return render_supported
;
119 * We might want to return max texture levels instead...
122 i915_max_texture_size(struct pipe_context
*pipe
, GLuint textureType
,
123 GLuint
*maxWidth
, GLuint
*maxHeight
, GLuint
*maxDepth
)
125 switch (textureType
) {
126 case PIPE_TEXTURE_1D
:
129 case PIPE_TEXTURE_2D
:
133 case PIPE_TEXTURE_3D
:
138 case PIPE_TEXTURE_CUBE
:
148 static void i915_destroy( struct pipe_context
*pipe
)
150 struct i915_context
*i915
= i915_context( pipe
);
152 draw_destroy( i915
->draw
);
157 static void i915_draw_vb( struct pipe_context
*pipe
,
158 struct vertex_buffer
*VB
)
160 struct i915_context
*i915
= i915_context( pipe
);
163 i915_update_derived( i915
);
165 draw_vb( i915
->draw
, VB
);
170 i915_draw_vertices(struct pipe_context
*pipe
,
172 GLuint numVertex
, const GLfloat
*verts
,
173 GLuint numAttribs
, const GLuint attribs
[])
175 struct i915_context
*i915
= i915_context( pipe
);
178 i915_update_derived( i915
);
180 draw_vertices(i915
->draw
, mode
, numVertex
, verts
, numAttribs
, attribs
);
186 struct pipe_context
*i915_create( struct pipe_winsys
*pipe_winsys
,
187 struct i915_winsys
*i915_winsys
,
190 struct i915_context
*i915
;
191 unsigned is_i945
= 0;
193 /* TODO: Push this down into the pipe driver:
196 case PCI_CHIP_I915_G
:
197 case PCI_CHIP_I915_GM
:
200 case PCI_CHIP_I945_G
:
201 case PCI_CHIP_I945_GM
:
202 case PCI_CHIP_I945_GME
:
210 pipe_winsys
->printf(pipe_winsys
,
211 "%s: unknown pci id 0x%x, cannot create context\n",
212 __FUNCTION__
, pci_id
);
216 i915
= CALLOC_STRUCT(i915_context
);
220 i915
->winsys
= i915_winsys
;
221 i915
->pipe
.winsys
= pipe_winsys
;
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
;
234 * Create drawing context and plug our rendering stage into it.
236 i915
->draw
= draw_create();
238 draw_set_setup_stage(i915
->draw
, i915_draw_render_stage(i915
));
240 i915_init_region_functions(i915
);
241 i915_init_surface_functions(i915
);
242 i915_init_state_functions(i915
);
243 i915_init_flush_functions(i915
);
246 if (i915
->flags
.is_i945
)
247 i915
->pipe
.mipmap_tree_layout
= i945_miptree_layout
;
249 i915
->pipe
.mipmap_tree_layout
= i945_miptree_layout
;
253 i915
->hardware_dirty
= ~0;
255 /* Batch stream debugging is a bit hacked up at the moment:
257 i915
->batch_start
= BEGIN_BATCH(0, 0);
260 * XXX we could plug GL selection/feedback into the drawing pipeline
261 * by specifying a different setup/render stage.