2 #ifndef COMMON_CONTEXT_H
3 #define COMMON_CONTEXT_H
6 #include "math/m_vector.h"
8 #include "tnl/t_context.h"
9 #include "main/colormac.h"
11 #include "radeon_screen.h"
12 #include "radeon_drm.h"
14 #include "tnl/t_vertex.h"
16 #include "dri_metaops.h"
17 struct radeon_context
;
19 #include "radeon_bocs_wrapper.h"
21 /* This union is used to avoid warnings/miscompilation
22 with float to uint32_t casts due to strict-aliasing */
23 typedef union { GLfloat f
; uint32_t ui32
; } float_ui32_type
;
25 struct radeon_context
;
26 typedef struct radeon_context radeonContextRec
;
27 typedef struct radeon_context
*radeonContextPtr
;
37 /* Rasterizing fallbacks */
38 /* See correponding strings in r200_swtcl.c */
39 #define RADEON_FALLBACK_TEXTURE 0x0001
40 #define RADEON_FALLBACK_DRAW_BUFFER 0x0002
41 #define RADEON_FALLBACK_STENCIL 0x0004
42 #define RADEON_FALLBACK_RENDER_MODE 0x0008
43 #define RADEON_FALLBACK_BLEND_EQ 0x0010
44 #define RADEON_FALLBACK_BLEND_FUNC 0x0020
45 #define RADEON_FALLBACK_DISABLE 0x0040
46 #define RADEON_FALLBACK_BORDER_MODE 0x0080
47 #define RADEON_FALLBACK_DEPTH_BUFFER 0x0100
48 #define RADEON_FALLBACK_STENCIL_BUFFER 0x0200
50 #define R200_FALLBACK_TEXTURE 0x01
51 #define R200_FALLBACK_DRAW_BUFFER 0x02
52 #define R200_FALLBACK_STENCIL 0x04
53 #define R200_FALLBACK_RENDER_MODE 0x08
54 #define R200_FALLBACK_DISABLE 0x10
55 #define R200_FALLBACK_BORDER_MODE 0x20
57 #define RADEON_TCL_FALLBACK_RASTER 0x1 /* rasterization */
58 #define RADEON_TCL_FALLBACK_UNFILLED 0x2 /* unfilled tris */
59 #define RADEON_TCL_FALLBACK_LIGHT_TWOSIDE 0x4 /* twoside tris */
60 #define RADEON_TCL_FALLBACK_MATERIAL 0x8 /* material in vb */
61 #define RADEON_TCL_FALLBACK_TEXGEN_0 0x10 /* texgen, unit 0 */
62 #define RADEON_TCL_FALLBACK_TEXGEN_1 0x20 /* texgen, unit 1 */
63 #define RADEON_TCL_FALLBACK_TEXGEN_2 0x40 /* texgen, unit 2 */
64 #define RADEON_TCL_FALLBACK_TCL_DISABLE 0x80 /* user disable */
65 #define RADEON_TCL_FALLBACK_FOGCOORDSPEC 0x100 /* fogcoord, sep. spec light */
67 /* The blit width for texture uploads
69 #define BLIT_WIDTH_BYTES 1024
71 /* Use the templated vertex format:
74 #define TAG(x) radeon##x
75 #include "tnl_dd/t_dd_vertex.h"
78 #define RADEON_RB_CLASS 0xdeadbeef
80 struct radeon_renderbuffer
82 struct gl_renderbuffer base
;
85 /* unsigned int offset; */
88 uint32_t draw_offset
; /* FBO */
89 /* boo Xorg 6.8.2 compat */
92 GLuint pf_pending
; /**< sequence number of pending flip */
93 GLuint vbl_pending
; /**< vblank sequence number of pending flip */
94 __DRIdrawablePrivate
*dPriv
;
97 struct radeon_framebuffer
99 struct gl_framebuffer base
;
101 struct radeon_renderbuffer
*color_rb
[2];
107 int64_t swap_missed_ust
;
110 GLuint swap_missed_count
;
112 /* Drawable page flipping state */
114 GLint pf_current_page
;
120 struct radeon_colorbuffer_state
{
123 struct gl_renderbuffer
*rb
;
124 uint32_t draw_offset
; /* offset into color renderbuffer - FBOs */
127 struct radeon_depthbuffer_state
{
129 struct gl_renderbuffer
*rb
;
132 struct radeon_scissor_state
{
133 drm_clip_rect_t rect
;
136 GLuint numClipRects
; /* Cliprects active */
137 GLuint numAllocedClipRects
; /* Cliprects available */
138 drm_clip_rect_t
*pClipRects
;
141 struct radeon_stencilbuffer_state
{
142 GLuint clear
; /* rb3d_stencilrefmask value */
145 struct radeon_stipple_state
{
149 struct radeon_state_atom
{
150 struct radeon_state_atom
*next
, *prev
;
151 const char *name
; /* for debug */
152 int cmd_size
; /* size in bytes */
155 GLuint
*cmd
; /* one or more cmd's */
156 GLuint
*lastcmd
; /* one or more cmd's */
157 GLboolean dirty
; /* dirty-mark in emit_state_list */
158 int (*check
) (GLcontext
*, struct radeon_state_atom
*atom
); /* is this state active? */
159 void (*emit
) (GLcontext
*, struct radeon_state_atom
*atom
);
162 struct radeon_hw_state
{
163 /* Head of the linked list of state atoms. */
164 struct radeon_state_atom atomlist
;
165 int max_state_size
; /* Number of bytes necessary for a full state emit. */
166 GLboolean is_dirty
, all_dirty
;
170 /* Texture related */
171 typedef struct _radeon_texture_image radeon_texture_image
;
173 struct _radeon_texture_image
{
174 struct gl_texture_image base
;
177 * If mt != 0, the image is stored in hardware format in the
178 * given mipmap tree. In this case, base.Data may point into the
179 * mapping of the buffer object that contains the mipmap tree.
181 * If mt == 0, the image is stored in normal memory pointed to
184 struct _radeon_mipmap_tree
*mt
;
185 struct radeon_bo
*bo
;
187 int mtlevel
; /** if mt != 0, this is the image's level in the mipmap tree */
188 int mtface
; /** if mt != 0, this is the image's face in the mipmap tree */
192 static INLINE radeon_texture_image
*get_radeon_texture_image(struct gl_texture_image
*image
)
194 return (radeon_texture_image
*)image
;
198 typedef struct radeon_tex_obj radeonTexObj
, *radeonTexObjPtr
;
200 #define RADEON_TXO_MICRO_TILE (1 << 3)
202 /* Texture object in locally shared texture space.
204 struct radeon_tex_obj
{
205 struct gl_texture_object base
;
206 struct _radeon_mipmap_tree
*mt
;
209 * This is true if we've verified that the mipmap tree above is complete
214 GLuint override_offset
;
215 GLboolean image_override
; /* Image overridden by GLX_EXT_tfp */
216 GLuint tile_bits
; /* hw texture tile bits used on this texture */
217 struct radeon_bo
*bo
;
219 GLuint pp_txfilter
; /* hardware register values */
221 GLuint pp_txformat_x
;
222 GLuint pp_txsize
; /* npot only */
223 GLuint pp_txpitch
; /* npot only */
224 GLuint pp_border_color
;
225 GLuint pp_cubic_faces
; /* cube face 1,2,3,4 log2 sizes */
227 GLuint pp_txfilter_1
; /* r300 */
229 /* r700 texture states */
230 GLuint SQ_TEX_RESOURCE0
;
231 GLuint SQ_TEX_RESOURCE1
;
232 GLuint SQ_TEX_RESOURCE2
;
233 GLuint SQ_TEX_RESOURCE3
;
234 GLuint SQ_TEX_RESOURCE4
;
235 GLuint SQ_TEX_RESOURCE5
;
236 GLuint SQ_TEX_RESOURCE6
;
238 GLuint SQ_TEX_SAMPLER0
;
239 GLuint SQ_TEX_SAMPLER1
;
240 GLuint SQ_TEX_SAMPLER2
;
242 GLboolean border_fallback
;
247 static INLINE radeonTexObj
* radeon_tex_obj(struct gl_texture_object
*texObj
)
249 return (radeonTexObj
*)texObj
;
252 /* Need refcounting on dma buffers:
254 struct radeon_dma_buffer
{
255 int refcount
; /* the number of retained regions in buf */
260 struct radeon_bo
*bo
; /** Buffer object where vertex data is stored */
261 int offset
; /** Offset into buffer object, in bytes */
262 int components
; /** Number of components per vertex */
263 int stride
; /** Stride in dwords (may be 0 for repeating) */
264 int count
; /** Number of vertices */
268 /* Active dma region. Allocations for vertices and retained
269 * regions come from here. Also used for emitting random vertices,
270 * these may be flushed by calling flush_current();
272 struct radeon_bo
*current
; /** Buffer that DMA memory is allocated from */
273 int current_used
; /** Number of bytes allocated and forgotten about */
274 int current_vertexptr
; /** End of active vertex region */
277 * If current_vertexptr != current_used then flush must be non-zero.
278 * flush must be called before non-active vertex allocations can be
281 void (*flush
) (GLcontext
*);
283 /* Number of "in-flight" DMA buffers, i.e. the number of buffers
284 * for which a DISCARD command is currently queued in the command buffer
287 GLuint nr_released_bufs
;
292 struct radeon_swtcl_info
{
298 /* Fallback rasterization functions
301 GLenum render_primitive
;
304 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
305 GLuint vertex_attr_count
;
309 #define RADEON_MAX_AOS_ARRAYS 16
310 struct radeon_tcl_info
{
311 struct radeon_aos aos
[RADEON_MAX_AOS_ARRAYS
];
313 struct radeon_bo
*elt_dma_bo
; /** Buffer object that contains element indices */
314 int elt_dma_offset
; /** Offset into this buffer object, in bytes */
317 struct radeon_ioctl
{
318 GLuint vertex_offset
;
319 struct radeon_bo
*bo
;
323 #define RADEON_MAX_PRIMS 64
331 static INLINE GLuint
radeonPackColor(GLuint cpp
,
332 GLubyte r
, GLubyte g
,
333 GLubyte b
, GLubyte a
)
337 return PACK_COLOR_565(r
, g
, b
);
339 return PACK_COLOR_8888(a
, r
, g
, b
);
345 #define MAX_CMD_BUF_SZ (16*1024)
347 #define MAX_DMA_BUF_SZ (64*1024)
349 struct radeon_store
{
352 char cmd_buf
[MAX_CMD_BUF_SZ
];
357 struct radeon_dri_mirror
{
358 __DRIcontextPrivate
*context
; /* DRI context */
359 __DRIscreenPrivate
*screen
; /* DRI screen */
361 drm_context_t hwContext
;
362 drm_hw_lock_t
*hwLock
;
367 #define DEBUG_TEXTURE 0x001
368 #define DEBUG_STATE 0x002
369 #define DEBUG_IOCTL 0x004
370 #define DEBUG_PRIMS 0x008
371 #define DEBUG_VERTS 0x010
372 #define DEBUG_FALLBACKS 0x020
373 #define DEBUG_VFMT 0x040
374 #define DEBUG_CODEGEN 0x080
375 #define DEBUG_VERBOSE 0x100
376 #define DEBUG_DRI 0x200
377 #define DEBUG_DMA 0x400
378 #define DEBUG_SANITY 0x800
379 #define DEBUG_SYNC 0x1000
380 #define DEBUG_PIXEL 0x2000
381 #define DEBUG_MEMORY 0x4000
384 typedef void (*radeon_tri_func
) (radeonContextPtr
,
386 radeonVertex
*, radeonVertex
*);
388 typedef void (*radeon_line_func
) (radeonContextPtr
,
389 radeonVertex
*, radeonVertex
*);
391 typedef void (*radeon_point_func
) (radeonContextPtr
, radeonVertex
*);
393 #define RADEON_MAX_BOS 32
394 struct radeon_state
{
395 struct radeon_colorbuffer_state color
;
396 struct radeon_depthbuffer_state depth
;
397 struct radeon_scissor_state scissor
;
398 struct radeon_stencilbuffer_state stencil
;
400 struct radeon_cs_space_check bos
[RADEON_MAX_BOS
];
401 int validated_bo_count
;
405 * This structure holds the command buffer while it is being constructed.
407 * The first batch of commands in the buffer is always the state that needs
408 * to be re-emitted when the context is lost. This batch can be skipped
411 struct radeon_cmdbuf
{
412 struct radeon_cs_manager
*csm
;
413 struct radeon_cs
*cs
;
414 int size
; /** # of dwords total */
415 unsigned int flushing
:1; /** whether we're currently in FlushCmdBufLocked */
418 struct radeon_context
{
420 radeonScreenPtr radeonScreen
; /* Screen private DRI data */
422 /* Texture object bookkeeping
425 float initialMaxAnisotropy
;
426 uint32_t texture_row_align
;
428 struct radeon_dma dma
;
429 struct radeon_hw_state hw
;
430 /* Rasterization and vertex state:
435 DECLARE_RENDERINPUTS(tnl_index_bitset
); /* index of bits for last tnl_install_attrs */
437 /* Drawable, cliprect and scissor information */
438 GLuint numClipRects
; /* Cliprects for the draw buffer */
439 drm_clip_rect_t
*pClipRects
;
440 unsigned int lastStamp
;
441 GLboolean lost_context
;
442 drm_radeon_sarea_t
*sarea
; /* Private SAREA data */
444 /* Mirrors of some DRI state */
445 struct radeon_dri_mirror dri
;
451 drm_radeon_irq_wait_t iw
;
453 /* Derived state - for r300 only */
454 struct radeon_state state
;
456 struct radeon_swtcl_info swtcl
;
457 struct radeon_tcl_info tcl
;
458 /* Configuration cache
460 driOptionCache optionCache
;
462 struct radeon_cmdbuf cmdbuf
;
464 drm_clip_rect_t fboRect
;
465 GLboolean constant_cliprect
; /* use for FBO or DRI2 rendering */
466 GLboolean front_cliprects
;
469 * Set if rendering has occured to the drawable's front buffer.
471 * This is used in the DRI2 case to detect that glFlush should also copy
472 * the contents of the fake front buffer to the real front buffer.
474 GLboolean front_buffer_dirty
;
477 * Track whether front-buffer rendering is currently enabled
479 * A separate flag is used to track this in order to support MRT more
482 GLboolean is_front_buffer_rendering
;
485 * Track whether front-buffer is the current read target.
487 * This is closely associated with is_front_buffer_rendering, but may
488 * be set separately. The DRI2 fake front buffer must be referenced
491 GLboolean is_front_buffer_reading
;
493 struct dri_metaops meta
;
496 void (*get_lock
)(radeonContextPtr radeon
);
497 void (*update_viewport_offset
)(GLcontext
*ctx
);
498 void (*emit_cs_header
)(struct radeon_cs
*cs
, radeonContextPtr rmesa
);
499 void (*swtcl_flush
)(GLcontext
*ctx
, uint32_t offset
);
500 void (*pre_emit_atoms
)(radeonContextPtr rmesa
);
501 void (*pre_emit_state
)(radeonContextPtr rmesa
);
502 void (*fallback
)(GLcontext
*ctx
, GLuint bit
, GLboolean mode
);
503 void (*free_context
)(GLcontext
*ctx
);
507 #define RADEON_CONTEXT(glctx) ((radeonContextPtr)(ctx->DriverCtx))
509 static inline __DRIdrawablePrivate
* radeon_get_drawable(radeonContextPtr radeon
)
511 return radeon
->dri
.context
->driDrawablePriv
;
514 static inline __DRIdrawablePrivate
* radeon_get_readable(radeonContextPtr radeon
)
516 return radeon
->dri
.context
->driReadablePriv
;
521 * This function takes a float and packs it into a uint32_t
523 static INLINE
uint32_t radeonPackFloat32(float fl
)
534 /* This is probably wrong for some values, I need to test this
535 * some more. Range checking would be a good idea also..
537 * But it works for most things. I'll fix it later if someone
538 * else with a better clue doesn't
540 static INLINE
uint32_t radeonPackFloat24(float f
)
544 uint32_t float24
= 0;
549 mantissa
= frexpf(f
, &exponent
);
553 float24
|= (1 << 23);
554 mantissa
= mantissa
* -1.0;
556 /* Handle exponent, bias of 63 */
558 float24
|= (exponent
<< 16);
559 /* Kill 7 LSB of mantissa */
560 float24
|= (radeonPackFloat32(mantissa
) & 0x7FFFFF) >> 7;
565 GLboolean
radeonInitContext(radeonContextPtr radeon
,
566 struct dd_function_table
* functions
,
567 const __GLcontextModes
* glVisual
,
568 __DRIcontextPrivate
* driContextPriv
,
569 void *sharedContextPrivate
);
571 void radeonCleanupContext(radeonContextPtr radeon
);
572 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
);
573 void radeon_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
);
574 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
575 __DRIdrawablePrivate
* driDrawPriv
,
576 __DRIdrawablePrivate
* driReadPriv
);
577 extern void radeonDestroyContext(__DRIcontextPrivate
* driContextPriv
);
579 /* ================================================================
585 extern int RADEON_DEBUG
;
587 #define RADEON_DEBUG 0
590 #ifndef HAVE_LIBDRM_RADEON
591 #ifndef RADEON_DEBUG_BO
592 #define RADEON_DEBUG_BO 1