1 /**************************************************************************
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keithw@vmware.com>
37 - Scissor implementation
38 - buffer swap/copy ioctls
41 - cmdbuffer management
45 #include "main/glheader.h"
46 #include "main/context.h"
47 #include "main/enums.h"
48 #include "main/fbobject.h"
49 #include "main/framebuffer.h"
50 #include "main/renderbuffer.h"
51 #include "drivers/common/meta.h"
53 #include "radeon_common.h"
54 #include "radeon_drm.h"
55 #include "radeon_queryobj.h"
58 * Enable verbose debug output for emit code.
61 * 2 also print state alues
63 #define RADEON_CMDBUF 0
65 /* =============================================================
70 * Update cliprects and scissors.
72 void radeonSetCliprects(radeonContextPtr radeon
)
74 __DRIdrawable
*const drawable
= radeon_get_drawable(radeon
);
75 __DRIdrawable
*const readable
= radeon_get_readable(radeon
);
77 if(drawable
== NULL
&& readable
== NULL
)
80 struct radeon_framebuffer
*const draw_rfb
= drawable
->driverPrivate
;
81 struct radeon_framebuffer
*const read_rfb
= readable
->driverPrivate
;
83 if ((draw_rfb
->base
.Width
!= drawable
->w
) ||
84 (draw_rfb
->base
.Height
!= drawable
->h
)) {
85 _mesa_resize_framebuffer(&radeon
->glCtx
, &draw_rfb
->base
,
86 drawable
->w
, drawable
->h
);
89 if (drawable
!= readable
) {
90 if ((read_rfb
->base
.Width
!= readable
->w
) ||
91 (read_rfb
->base
.Height
!= readable
->h
)) {
92 _mesa_resize_framebuffer(&radeon
->glCtx
, &read_rfb
->base
,
93 readable
->w
, readable
->h
);
97 if (radeon
->state
.scissor
.enabled
)
98 radeonUpdateScissor(&radeon
->glCtx
);
104 void radeonUpdateScissor( struct gl_context
*ctx
)
106 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
107 GLint x
= ctx
->Scissor
.ScissorArray
[0].X
, y
= ctx
->Scissor
.ScissorArray
[0].Y
;
108 GLsizei w
= ctx
->Scissor
.ScissorArray
[0].Width
, h
= ctx
->Scissor
.ScissorArray
[0].Height
;
110 int min_x
, min_y
, max_x
, max_y
;
112 if (!ctx
->DrawBuffer
)
115 max_x
= ctx
->DrawBuffer
->Width
- 1;
116 max_y
= ctx
->DrawBuffer
->Height
- 1;
118 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
120 y1
= ctx
->DrawBuffer
->Height
- (y
+ h
);
131 rmesa
->state
.scissor
.rect
.x1
= CLAMP(x1
, min_x
, max_x
);
132 rmesa
->state
.scissor
.rect
.y1
= CLAMP(y1
, min_y
, max_y
);
133 rmesa
->state
.scissor
.rect
.x2
= CLAMP(x2
, min_x
, max_x
);
134 rmesa
->state
.scissor
.rect
.y2
= CLAMP(y2
, min_y
, max_y
);
136 if (rmesa
->vtbl
.update_scissor
)
137 rmesa
->vtbl
.update_scissor(ctx
);
140 /* =============================================================
144 void radeonScissor(struct gl_context
*ctx
)
146 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
147 if (ctx
->Scissor
.EnableFlags
) {
148 /* We don't pipeline cliprect changes */
149 radeon_firevertices(radeon
);
150 radeonUpdateScissor(ctx
);
154 /* ================================================================
155 * SwapBuffers with client-side throttling
158 uint32_t radeonGetAge(radeonContextPtr radeon
)
160 drm_radeon_getparam_t gp
;
164 gp
.param
= RADEON_PARAM_LAST_CLEAR
;
165 gp
.value
= (int *)&age
;
166 ret
= drmCommandWriteRead(radeon
->radeonScreen
->driScreen
->fd
, DRM_RADEON_GETPARAM
,
169 fprintf(stderr
, "%s: drmRadeonGetParam: %d\n", __func__
,
177 void radeon_draw_buffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
179 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
180 struct radeon_renderbuffer
*rrbDepth
= NULL
, *rrbStencil
= NULL
,
186 /* this can happen during the initial context initialization */
190 /* radeons only handle 1 color draw so far */
191 if (fb
->_NumColorDrawBuffers
!= 1) {
192 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
196 /* Do this here, note core Mesa, since this function is called from
197 * many places within the driver.
199 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
200 /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */
201 _mesa_update_framebuffer(ctx
, ctx
->ReadBuffer
, ctx
->DrawBuffer
);
202 /* this updates the DrawBuffer's Width/Height if it's a FBO */
203 _mesa_update_draw_buffer_bounds(ctx
, ctx
->DrawBuffer
);
206 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
207 /* this may occur when we're called by glBindFrameBuffer() during
208 * the process of someone setting up renderbuffers, etc.
210 /*_mesa_debug(ctx, "DrawBuffer: incomplete user FBO\n");*/
215 ;/* do something depthy/stencily TODO */
220 if (fb
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
) {
221 rrbColor
= radeon_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
222 radeon
->front_cliprects
= GL_TRUE
;
224 rrbColor
= radeon_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
225 radeon
->front_cliprects
= GL_FALSE
;
228 /* user FBO in theory */
229 struct radeon_renderbuffer
*rrb
;
230 rrb
= radeon_renderbuffer(fb
->_ColorDrawBuffers
[0]);
232 offset
= rrb
->draw_offset
;
237 if (rrbColor
== NULL
)
238 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
240 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
243 if (fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
) {
244 rrbDepth
= radeon_renderbuffer(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
245 if (rrbDepth
&& rrbDepth
->bo
) {
246 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DEPTH_BUFFER
, GL_FALSE
);
248 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DEPTH_BUFFER
, GL_TRUE
);
251 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_DEPTH_BUFFER
, GL_FALSE
);
255 if (fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
) {
256 rrbStencil
= radeon_renderbuffer(fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
257 if (rrbStencil
&& rrbStencil
->bo
) {
258 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_STENCIL_BUFFER
, GL_FALSE
);
259 /* need to re-compute stencil hw state */
261 rrbDepth
= rrbStencil
;
263 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_STENCIL_BUFFER
, GL_TRUE
);
266 radeon
->vtbl
.fallback(ctx
, RADEON_FALLBACK_STENCIL_BUFFER
, GL_FALSE
);
267 if (ctx
->Driver
.Enable
!= NULL
)
268 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
270 ctx
->NewState
|= _NEW_STENCIL
;
273 /* Update culling direction which changes depending on the
274 * orientation of the buffer:
276 if (ctx
->Driver
.FrontFace
)
277 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
279 ctx
->NewState
|= _NEW_POLYGON
;
282 * Update depth test state
284 if (ctx
->Driver
.Enable
) {
285 ctx
->Driver
.Enable(ctx
, GL_DEPTH_TEST
,
286 (ctx
->Depth
.Test
&& fb
->Visual
.depthBits
> 0));
287 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
,
288 (ctx
->Stencil
.Enabled
&& fb
->Visual
.stencilBits
> 0));
290 ctx
->NewState
|= (_NEW_DEPTH
| _NEW_STENCIL
);
293 _mesa_reference_renderbuffer(&radeon
->state
.depth
.rb
, &rrbDepth
->base
.Base
);
294 _mesa_reference_renderbuffer(&radeon
->state
.color
.rb
, &rrbColor
->base
.Base
);
295 radeon
->state
.color
.draw_offset
= offset
;
297 ctx
->NewState
|= _NEW_VIEWPORT
;
299 /* Set state we know depends on drawable parameters:
301 radeonUpdateScissor(ctx
);
302 radeon
->NewGLState
|= _NEW_SCISSOR
;
304 if (ctx
->Driver
.DepthRange
)
305 ctx
->Driver
.DepthRange(ctx
);
307 /* Update culling direction which changes depending on the
308 * orientation of the buffer:
310 if (ctx
->Driver
.FrontFace
)
311 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
313 ctx
->NewState
|= _NEW_POLYGON
;
317 * Called via glDrawBuffer.
319 void radeonDrawBuffer(struct gl_context
*ctx
)
321 if (RADEON_DEBUG
& RADEON_DRI
)
322 fprintf(stderr
, "%s\n", __func__
);
324 if (_mesa_is_front_buffer_drawing(ctx
->DrawBuffer
)) {
325 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
327 /* If we might be front-buffer rendering on this buffer for
328 * the first time, invalidate our DRI drawable so we'll ask
329 * for new buffers (including the fake front) before we start
332 radeon_update_renderbuffers(radeon
->driContext
,
333 radeon
->driContext
->driDrawablePriv
,
337 radeon_draw_buffer(ctx
, ctx
->DrawBuffer
);
340 void radeonReadBuffer( struct gl_context
*ctx
, GLenum mode
)
342 if (_mesa_is_front_buffer_reading(ctx
->ReadBuffer
)) {
343 struct radeon_context
*const rmesa
= RADEON_CONTEXT(ctx
);
344 radeon_update_renderbuffers(rmesa
->driContext
,
345 rmesa
->driContext
->driReadablePriv
, GL_FALSE
);
347 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
348 if (ctx
->ReadBuffer
== ctx
->DrawBuffer
) {
349 /* This will update FBO completeness status.
350 * A framebuffer will be incomplete if the GL_READ_BUFFER setting
351 * refers to a missing renderbuffer. Calling glReadBuffer can set
352 * that straight and can make the drawing buffer complete.
354 radeon_draw_buffer(ctx
, ctx
->DrawBuffer
);
358 void radeon_window_moved(radeonContextPtr radeon
)
360 /* Cliprects has to be updated before doing anything else */
361 radeonSetCliprects(radeon
);
364 void radeon_viewport(struct gl_context
*ctx
)
366 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
367 __DRIcontext
*driContext
= radeon
->driContext
;
368 void (*old_viewport
)(struct gl_context
*ctx
);
370 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
371 if (_mesa_is_front_buffer_drawing(ctx
->DrawBuffer
)) {
372 ctx
->Driver
.Flush(ctx
);
374 radeon_update_renderbuffers(driContext
, driContext
->driDrawablePriv
, GL_FALSE
);
375 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
376 radeon_update_renderbuffers(driContext
, driContext
->driReadablePriv
, GL_FALSE
);
379 old_viewport
= ctx
->Driver
.Viewport
;
380 ctx
->Driver
.Viewport
= NULL
;
381 radeon_window_moved(radeon
);
382 radeon_draw_buffer(ctx
, radeon
->glCtx
.DrawBuffer
);
383 ctx
->Driver
.Viewport
= old_viewport
;
386 static void radeon_print_state_atom(radeonContextPtr radeon
, struct radeon_state_atom
*state
)
388 int i
, j
, reg
, count
;
391 if (!radeon_is_debug_enabled(RADEON_STATE
, RADEON_VERBOSE
) )
394 dwords
= state
->check(&radeon
->glCtx
, state
);
396 fprintf(stderr
, " emit %s %d/%d\n", state
->name
, dwords
, state
->cmd_size
);
398 if (state
->cmd
&& radeon_is_debug_enabled(RADEON_STATE
, RADEON_TRACE
)) {
399 if (dwords
> state
->cmd_size
)
400 dwords
= state
->cmd_size
;
401 for (i
= 0; i
< dwords
;) {
402 packet0
= state
->cmd
[i
];
403 reg
= (packet0
& 0x1FFF) << 2;
404 count
= ((packet0
& 0x3FFF0000) >> 16) + 1;
405 fprintf(stderr
, " %s[%d]: cmdpacket0 (first reg=0x%04x, count=%d)\n",
406 state
->name
, i
, reg
, count
);
408 for (j
= 0; j
< count
&& i
< dwords
; j
++) {
409 fprintf(stderr
, " %s[%d]: 0x%04x = %08x\n",
410 state
->name
, i
, reg
, state
->cmd
[i
]);
419 * Count total size for next state emit.
421 GLuint
radeonCountStateEmitSize(radeonContextPtr radeon
)
423 struct radeon_state_atom
*atom
;
425 /* check if we are going to emit full state */
427 if (radeon
->cmdbuf
.cs
->cdw
&& !radeon
->hw
.all_dirty
) {
428 if (!radeon
->hw
.is_dirty
)
430 foreach(atom
, &radeon
->hw
.atomlist
) {
432 const GLuint atom_size
= atom
->check(&radeon
->glCtx
, atom
);
434 if (RADEON_CMDBUF
&& atom_size
) {
435 radeon_print_state_atom(radeon
, atom
);
440 foreach(atom
, &radeon
->hw
.atomlist
) {
441 const GLuint atom_size
= atom
->check(&radeon
->glCtx
, atom
);
443 if (RADEON_CMDBUF
&& atom_size
) {
444 radeon_print_state_atom(radeon
, atom
);
450 radeon_print(RADEON_STATE
, RADEON_NORMAL
, "%s %u\n", __func__
, dwords
);
454 static inline void radeon_emit_atom(radeonContextPtr radeon
, struct radeon_state_atom
*atom
)
456 BATCH_LOCALS(radeon
);
459 dwords
= atom
->check(&radeon
->glCtx
, atom
);
462 radeon_print_state_atom(radeon
, atom
);
465 atom
->emit(&radeon
->glCtx
, atom
);
468 OUT_BATCH_TABLE(atom
->cmd
, dwords
);
471 atom
->dirty
= GL_FALSE
;
474 radeon_print(RADEON_STATE
, RADEON_VERBOSE
, " skip state %s\n", atom
->name
);
479 static inline void radeonEmitAtoms(radeonContextPtr radeon
, GLboolean emitAll
)
481 struct radeon_state_atom
*atom
;
483 /* Emit actual atoms */
484 if (radeon
->hw
.all_dirty
|| emitAll
) {
485 foreach(atom
, &radeon
->hw
.atomlist
)
486 radeon_emit_atom( radeon
, atom
);
488 foreach(atom
, &radeon
->hw
.atomlist
) {
490 radeon_emit_atom( radeon
, atom
);
497 void radeonEmitState(radeonContextPtr radeon
)
499 radeon_print(RADEON_STATE
, RADEON_NORMAL
, "%s\n", __func__
);
501 if (radeon
->vtbl
.pre_emit_state
)
502 radeon
->vtbl
.pre_emit_state(radeon
);
504 /* this code used to return here but now it emits zbs */
505 if (radeon
->cmdbuf
.cs
->cdw
&& !radeon
->hw
.is_dirty
&& !radeon
->hw
.all_dirty
)
508 if (!radeon
->cmdbuf
.cs
->cdw
) {
509 if (RADEON_DEBUG
& RADEON_STATE
)
510 fprintf(stderr
, "Begin reemit state\n");
512 radeonEmitAtoms(radeon
, GL_TRUE
);
515 if (RADEON_DEBUG
& RADEON_STATE
)
516 fprintf(stderr
, "Begin dirty state\n");
518 radeonEmitAtoms(radeon
, GL_FALSE
);
521 radeon
->hw
.is_dirty
= GL_FALSE
;
522 radeon
->hw
.all_dirty
= GL_FALSE
;
526 void radeonFlush(struct gl_context
*ctx
)
528 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
529 if (RADEON_DEBUG
& RADEON_IOCTL
)
530 fprintf(stderr
, "%s %d\n", __func__
, radeon
->cmdbuf
.cs
->cdw
);
532 /* okay if we have no cmds in the buffer &&
533 we have no DMA flush &&
534 we have no DMA buffer allocated.
535 then no point flushing anything at all.
537 if (!radeon
->dma
.flush
&& !radeon
->cmdbuf
.cs
->cdw
&& is_empty_list(&radeon
->dma
.reserved
))
540 if (radeon
->dma
.flush
)
541 radeon
->dma
.flush( ctx
);
543 if (radeon
->cmdbuf
.cs
->cdw
)
544 rcommonFlushCmdBuf(radeon
, __func__
);
547 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
) && radeon
->front_buffer_dirty
) {
548 __DRIscreen
*const screen
= radeon
->radeonScreen
->driScreen
;
550 if (screen
->dri2
.loader
&& (screen
->dri2
.loader
->base
.version
>= 2)
551 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
552 __DRIdrawable
* drawable
= radeon_get_drawable(radeon
);
554 /* We set the dirty bit in radeon_prepare_render() if we're
555 * front buffer rendering once we get there.
557 radeon
->front_buffer_dirty
= GL_FALSE
;
559 screen
->dri2
.loader
->flushFrontBuffer(drawable
, drawable
->loaderPrivate
);
564 /* Make sure all commands have been sent to the hardware and have
565 * completed processing.
567 void radeonFinish(struct gl_context
* ctx
)
569 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
570 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
571 struct radeon_renderbuffer
*rrb
;
574 if (ctx
->Driver
.Flush
)
575 ctx
->Driver
.Flush(ctx
); /* +r6/r7 */
577 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
578 struct radeon_renderbuffer
*rrb
;
579 rrb
= radeon_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
581 radeon_bo_wait(rrb
->bo
);
583 rrb
= radeon_get_depthbuffer(radeon
);
585 radeon_bo_wait(rrb
->bo
);
590 * Send the current command buffer via ioctl to the hardware.
592 int rcommonFlushCmdBufLocked(radeonContextPtr rmesa
, const char *caller
)
596 if (rmesa
->cmdbuf
.flushing
) {
597 fprintf(stderr
, "Recursive call into r300FlushCmdBufLocked!\n");
600 rmesa
->cmdbuf
.flushing
= 1;
602 if (RADEON_DEBUG
& RADEON_IOCTL
) {
603 fprintf(stderr
, "%s from %s\n", __func__
, caller
);
606 radeonEmitQueryEnd(&rmesa
->glCtx
);
608 if (rmesa
->cmdbuf
.cs
->cdw
) {
609 ret
= radeon_cs_emit(rmesa
->cmdbuf
.cs
);
610 rmesa
->hw
.all_dirty
= GL_TRUE
;
612 radeon_cs_erase(rmesa
->cmdbuf
.cs
);
613 rmesa
->cmdbuf
.flushing
= 0;
615 if (!rmesa
->vtbl
.revalidate_all_buffers(&rmesa
->glCtx
))
616 fprintf(stderr
,"failed to revalidate buffers\n");
621 int rcommonFlushCmdBuf(radeonContextPtr rmesa
, const char *caller
)
625 radeonReleaseDmaRegions(rmesa
);
627 ret
= rcommonFlushCmdBufLocked(rmesa
, caller
);
630 fprintf(stderr
, "drmRadeonCmdBuffer: %d. Kernel failed to "
631 "parse or rejected command stream. See dmesg "
632 "for more info.\n", ret
);
640 * Make sure that enough space is available in the command buffer
641 * by flushing if necessary.
643 * \param dwords The number of dwords we need to be free on the command buffer
645 GLboolean
rcommonEnsureCmdBufSpace(radeonContextPtr rmesa
, int dwords
, const char *caller
)
647 if ((rmesa
->cmdbuf
.cs
->cdw
+ dwords
+ 128) > rmesa
->cmdbuf
.size
648 || radeon_cs_need_flush(rmesa
->cmdbuf
.cs
)) {
649 /* If we try to flush empty buffer there is too big rendering operation. */
650 assert(rmesa
->cmdbuf
.cs
->cdw
);
651 rcommonFlushCmdBuf(rmesa
, caller
);
657 void rcommonInitCmdBuf(radeonContextPtr rmesa
)
660 struct drm_radeon_gem_info mminfo
= { 0 };
661 int fd
= rmesa
->radeonScreen
->driScreen
->fd
;
663 /* Initialize command buffer */
664 size
= 256 * driQueryOptioni(&rmesa
->optionCache
,
665 "command_buffer_size");
666 if (size
< 2 * rmesa
->hw
.max_state_size
) {
667 size
= 2 * rmesa
->hw
.max_state_size
+ 65535;
672 radeon_print(RADEON_CS
, RADEON_VERBOSE
,
673 "sizeof(drm_r300_cmd_header_t)=%zd\n", sizeof(drm_r300_cmd_header_t
));
674 radeon_print(RADEON_CS
, RADEON_VERBOSE
,
675 "sizeof(drm_radeon_cmd_buffer_t)=%zd\n", sizeof(drm_radeon_cmd_buffer_t
));
676 radeon_print(RADEON_CS
, RADEON_VERBOSE
,
677 "Allocating %d bytes command buffer (max state is %d bytes)\n",
678 size
* 4, rmesa
->hw
.max_state_size
* 4);
680 rmesa
->cmdbuf
.csm
= radeon_cs_manager_gem_ctor(fd
);
681 if (rmesa
->cmdbuf
.csm
== NULL
) {
682 /* FIXME: fatal error */
685 rmesa
->cmdbuf
.cs
= radeon_cs_create(rmesa
->cmdbuf
.csm
, size
);
686 assert(rmesa
->cmdbuf
.cs
!= NULL
);
687 rmesa
->cmdbuf
.size
= size
;
689 radeon_cs_space_set_flush(rmesa
->cmdbuf
.cs
,
690 (void (*)(void *))rmesa
->glCtx
.Driver
.Flush
, &rmesa
->glCtx
);
693 if (!drmCommandWriteRead(fd
, DRM_RADEON_GEM_INFO
,
694 &mminfo
, sizeof(mminfo
))) {
695 radeon_cs_set_limit(rmesa
->cmdbuf
.cs
, RADEON_GEM_DOMAIN_VRAM
,
696 mminfo
.vram_visible
);
697 radeon_cs_set_limit(rmesa
->cmdbuf
.cs
, RADEON_GEM_DOMAIN_GTT
,
703 * Destroy the command buffer
705 void rcommonDestroyCmdBuf(radeonContextPtr rmesa
)
707 radeon_cs_destroy(rmesa
->cmdbuf
.cs
);
708 radeon_cs_manager_gem_dtor(rmesa
->cmdbuf
.csm
);
711 void rcommonBeginBatch(radeonContextPtr rmesa
, int n
,
713 const char *function
,
716 radeon_cs_begin(rmesa
->cmdbuf
.cs
, n
, file
, function
, line
);
718 radeon_print(RADEON_CS
, RADEON_VERBOSE
, "BEGIN_BATCH(%d) at %d, from %s:%i\n",
719 n
, rmesa
->cmdbuf
.cs
->cdw
, function
, line
);
723 void radeonUserClear(struct gl_context
*ctx
, GLuint mask
)
725 _mesa_meta_Clear(ctx
, mask
);