📄 radeon_ioctl.c
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_ioctl.c,v 1.11 2003/01/29 22:04:59 dawes Exp $ *//**************************************************************************Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and VA Linux Systems Inc., Fremont, California.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantialportions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Authors: * Kevin E. Martin <martin@valinux.com> * Gareth Hughes <gareth@valinux.com> * Keith Whitwell <keith@tungstengraphics.com> */#include <sched.h>#include <errno.h> #include "glheader.h"#include "imports.h"#include "simple_list.h"#include "swrast/swrast.h"#include "radeon_context.h"#include "radeon_state.h"#include "radeon_ioctl.h"#include "radeon_tcl.h"#include "radeon_sanity.h"#define STANDALONE_MMIO#include "radeon_macros.h" /* for INREG() */#include "drirenderbuffer.h"#include "vblank.h"#define RADEON_TIMEOUT 512#define RADEON_IDLE_RETRY 16static void radeonWaitForIdle( radeonContextPtr rmesa );static int radeonFlushCmdBufLocked( radeonContextPtr rmesa, const char * caller );static void print_state_atom( struct radeon_state_atom *state ){ int i; fprintf(stderr, "emit %s/%d\n", state->name, state->cmd_size); if (RADEON_DEBUG & DEBUG_VERBOSE) for (i = 0 ; i < state->cmd_size ; i++) fprintf(stderr, "\t%s[%d]: %x\n", state->name, i, state->cmd[i]);}static void radeonSaveHwState( radeonContextPtr rmesa ){ struct radeon_state_atom *atom; char * dest = rmesa->backup_store.cmd_buf; if (RADEON_DEBUG & DEBUG_STATE) fprintf(stderr, "%s\n", __FUNCTION__); rmesa->backup_store.cmd_used = 0; foreach( atom, &rmesa->hw.atomlist ) { if ( atom->check( rmesa->glCtx ) ) { int size = atom->cmd_size * 4; memcpy( dest, atom->cmd, size); dest += size; rmesa->backup_store.cmd_used += size; if (RADEON_DEBUG & DEBUG_STATE) print_state_atom( atom ); } } assert( rmesa->backup_store.cmd_used <= RADEON_CMD_BUF_SZ ); if (RADEON_DEBUG & DEBUG_STATE) fprintf(stderr, "Returning to radeonEmitState\n");}/* At this point we were in FlushCmdBufLocked but we had lost our context, so * we need to unwire our current cmdbuf, hook the one with the saved state in * it, flush it, and then put the current one back. This is so commands at the * start of a cmdbuf can rely on the state being kept from the previous one. */static void radeonBackUpAndEmitLostStateLocked( radeonContextPtr rmesa ){ GLuint nr_released_bufs; struct radeon_store saved_store; if (rmesa->backup_store.cmd_used == 0) return; if (RADEON_DEBUG & DEBUG_STATE) fprintf(stderr, "Emitting backup state on lost context\n"); rmesa->lost_context = GL_FALSE; nr_released_bufs = rmesa->dma.nr_released_bufs; saved_store = rmesa->store; rmesa->dma.nr_released_bufs = 0; rmesa->store = rmesa->backup_store; radeonFlushCmdBufLocked( rmesa, __FUNCTION__ ); rmesa->dma.nr_released_bufs = nr_released_bufs; rmesa->store = saved_store;}/* ============================================================= * Kernel command buffer handling *//* The state atoms will be emitted in the order they appear in the atom list, * so this step is important. */void radeonSetUpAtomList( radeonContextPtr rmesa ){ int i, mtu = rmesa->glCtx->Const.MaxTextureUnits; make_empty_list(&rmesa->hw.atomlist); rmesa->hw.atomlist.name = "atom-list"; insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.ctx); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.set); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.lin); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.msk); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.vpt); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.tcl); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.msc); for (i = 0; i < mtu; ++i) { insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.tex[i]); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.txr[i]); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.cube[i]); } insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.zbs); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.mtl); for (i = 0; i < 3 + mtu; ++i) insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.mat[i]); for (i = 0; i < 8; ++i) insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.lit[i]); for (i = 0; i < 6; ++i) insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.ucp[i]); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.eye); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.grd); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.fog); insert_at_tail(&rmesa->hw.atomlist, &rmesa->hw.glt);}void radeonEmitState( radeonContextPtr rmesa ){ struct radeon_state_atom *atom; char *dest; if (RADEON_DEBUG & (DEBUG_STATE|DEBUG_PRIMS)) fprintf(stderr, "%s\n", __FUNCTION__); if (rmesa->save_on_next_emit) { radeonSaveHwState(rmesa); rmesa->save_on_next_emit = GL_FALSE; } /* this code used to return here but now it emits zbs */ /* To avoid going across the entire set of states multiple times, just check * for enough space for the case of emitting all state, and inline the * radeonAllocCmdBuf code here without all the checks. */ radeonEnsureCmdBufSpace(rmesa, rmesa->hw.max_state_size); dest = rmesa->store.cmd_buf + rmesa->store.cmd_used; /* We always always emit zbs, this is due to a bug found by keithw in the hardware and rediscovered after Erics changes by me. if you ever touch this code make sure you emit zbs otherwise you get tcl lockups on at least M7/7500 class of chips - airlied */ rmesa->hw.zbs.dirty=1; if (RADEON_DEBUG & DEBUG_STATE) { foreach(atom, &rmesa->hw.atomlist) { if (atom->dirty || rmesa->hw.all_dirty) { if (atom->check(rmesa->glCtx)) print_state_atom(atom); else fprintf(stderr, "skip state %s\n", atom->name); } } } foreach(atom, &rmesa->hw.atomlist) { if (rmesa->hw.all_dirty) atom->dirty = GL_TRUE; if (!(rmesa->radeonScreen->chip_flags & RADEON_CHIPSET_TCL) && atom->is_tcl) atom->dirty = GL_FALSE; if (atom->dirty) { if (atom->check(rmesa->glCtx)) { int size = atom->cmd_size * 4; memcpy(dest, atom->cmd, size); dest += size; rmesa->store.cmd_used += size; atom->dirty = GL_FALSE; } } } assert(rmesa->store.cmd_used <= RADEON_CMD_BUF_SZ); rmesa->hw.is_dirty = GL_FALSE; rmesa->hw.all_dirty = GL_FALSE;}/* Fire a section of the retained (indexed_verts) buffer as a regular * primtive. */extern void radeonEmitVbufPrim( radeonContextPtr rmesa, GLuint vertex_format, GLuint primitive, GLuint vertex_nr ){ drm_radeon_cmd_header_t *cmd; assert(!(primitive & RADEON_CP_VC_CNTL_PRIM_WALK_IND)); radeonEmitState( rmesa ); if (RADEON_DEBUG & DEBUG_IOCTL) fprintf(stderr, "%s cmd_used/4: %d\n", __FUNCTION__, rmesa->store.cmd_used/4); cmd = (drm_radeon_cmd_header_t *)radeonAllocCmdBuf( rmesa, VBUF_BUFSZ, __FUNCTION__ );#if RADEON_OLD_PACKETS cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; cmd[1].i = RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM | (3 << 16); cmd[2].i = rmesa->ioctl.vertex_offset; cmd[3].i = vertex_nr; cmd[4].i = vertex_format; cmd[5].i = (primitive | RADEON_CP_VC_CNTL_PRIM_WALK_LIST | RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA | RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE | (vertex_nr << RADEON_CP_VC_CNTL_NUM_SHIFT)); if (RADEON_DEBUG & DEBUG_PRIMS) fprintf(stderr, "%s: header 0x%x offt 0x%x vfmt 0x%x vfcntl %x \n", __FUNCTION__, cmd[1].i, cmd[2].i, cmd[4].i, cmd[5].i);#else cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; cmd[1].i = RADEON_CP_PACKET3_3D_DRAW_VBUF | (1 << 16); cmd[2].i = vertex_format; cmd[3].i = (primitive | RADEON_CP_VC_CNTL_PRIM_WALK_LIST | RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA | RADEON_CP_VC_CNTL_MAOS_ENABLE | RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE | (vertex_nr << RADEON_CP_VC_CNTL_NUM_SHIFT)); if (RADEON_DEBUG & DEBUG_PRIMS) fprintf(stderr, "%s: header 0x%x vfmt 0x%x vfcntl %x \n", __FUNCTION__, cmd[1].i, cmd[2].i, cmd[3].i);#endif}void radeonFlushElts( radeonContextPtr rmesa ){ int *cmd = (int *)(rmesa->store.cmd_buf + rmesa->store.elts_start); int dwords;#if RADEON_OLD_PACKETS int nr = (rmesa->store.cmd_used - (rmesa->store.elts_start + 24)) / 2;#else int nr = (rmesa->store.cmd_used - (rmesa->store.elts_start + 16)) / 2;#endif if (RADEON_DEBUG & DEBUG_IOCTL) fprintf(stderr, "%s\n", __FUNCTION__); assert( rmesa->dma.flush == radeonFlushElts ); rmesa->dma.flush = NULL; /* Cope with odd number of elts: */ rmesa->store.cmd_used = (rmesa->store.cmd_used + 2) & ~2; dwords = (rmesa->store.cmd_used - rmesa->store.elts_start) / 4;#if RADEON_OLD_PACKETS cmd[1] |= (dwords - 3) << 16; cmd[5] |= nr << RADEON_CP_VC_CNTL_NUM_SHIFT;#else cmd[1] |= (dwords - 3) << 16; cmd[3] |= nr << RADEON_CP_VC_CNTL_NUM_SHIFT;#endif if (RADEON_DEBUG & DEBUG_SYNC) { fprintf(stderr, "%s: Syncing\n", __FUNCTION__); radeonFinish( rmesa->glCtx ); }}GLushort *radeonAllocEltsOpenEnded( radeonContextPtr rmesa, GLuint vertex_format, GLuint primitive, GLuint min_nr ){ drm_radeon_cmd_header_t *cmd; GLushort *retval; if (RADEON_DEBUG & DEBUG_IOCTL) fprintf(stderr, "%s %d\n", __FUNCTION__, min_nr); assert((primitive & RADEON_CP_VC_CNTL_PRIM_WALK_IND)); radeonEmitState( rmesa ); cmd = (drm_radeon_cmd_header_t *)radeonAllocCmdBuf( rmesa, ELTS_BUFSZ(min_nr), __FUNCTION__ );#if RADEON_OLD_PACKETS cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; cmd[1].i = RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM; cmd[2].i = rmesa->ioctl.vertex_offset; cmd[3].i = 0xffff; cmd[4].i = vertex_format; cmd[5].i = (primitive | RADEON_CP_VC_CNTL_PRIM_WALK_IND | RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA | RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE); retval = (GLushort *)(cmd+6);#else cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3_CLIP; cmd[1].i = RADEON_CP_PACKET3_3D_DRAW_INDX; cmd[2].i = vertex_format; cmd[3].i = (primitive | RADEON_CP_VC_CNTL_PRIM_WALK_IND | RADEON_CP_VC_CNTL_COLOR_ORDER_RGBA | RADEON_CP_VC_CNTL_MAOS_ENABLE | RADEON_CP_VC_CNTL_VTX_FMT_RADEON_MODE); retval = (GLushort *)(cmd+4);#endif if (RADEON_DEBUG & DEBUG_PRIMS) fprintf(stderr, "%s: header 0x%x vfmt 0x%x prim %x \n", __FUNCTION__, cmd[1].i, vertex_format, primitive); assert(!rmesa->dma.flush); rmesa->glCtx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; rmesa->dma.flush = radeonFlushElts; rmesa->store.elts_start = ((char *)cmd) - rmesa->store.cmd_buf; return retval;}void radeonEmitVertexAOS( radeonContextPtr rmesa, GLuint vertex_size, GLuint offset ){#if RADEON_OLD_PACKETS rmesa->ioctl.vertex_size = vertex_size; rmesa->ioctl.vertex_offset = offset;#else drm_radeon_cmd_header_t *cmd; if (RADEON_DEBUG & (DEBUG_PRIMS|DEBUG_IOCTL)) fprintf(stderr, "%s: vertex_size 0x%x offset 0x%x \n", __FUNCTION__, vertex_size, offset); cmd = (drm_radeon_cmd_header_t *)radeonAllocCmdBuf( rmesa, VERT_AOS_BUFSZ, __FUNCTION__ ); cmd[0].i = 0; cmd[0].header.cmd_type = RADEON_CMD_PACKET3; cmd[1].i = RADEON_CP_PACKET3_3D_LOAD_VBPNTR | (2 << 16); cmd[2].i = 1; cmd[3].i = vertex_size | (vertex_size << 8); cmd[4].i = offset;#endif} void radeonEmitAOS( radeonContextPtr rmesa, struct radeon_dma_region **component, GLuint nr, GLuint offset ){#if RADEON_OLD_PACKETS assert( nr == 1 ); assert( component[0]->aos_size == component[0]->aos_stride ); rmesa->ioctl.vertex_size = component[0]->aos_size; rmesa->ioctl.vertex_offset = (component[0]->aos_start + offset * component[0]->aos_stride * 4);#else drm_radeon_cmd_header_t *cmd;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -