radeon_state.c
来自「linux 内核源代码」· C语言 代码 · 共 2,223 行 · 第 1/5 页
C
2,223 行
/* Make sure we restore the 3D state next time. */ dev_priv->sarea_priv->ctx_owner = 0; for (i = 0; i < nbox; i++) { int x = pbox[i].x1; int y = pbox[i].y1; int w = pbox[i].x2 - x; int h = pbox[i].y2 - y; DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n", x, y, w, h, flags); if (flags & RADEON_FRONT) { BEGIN_RING(6); OUT_RING(CP_PACKET3 (RADEON_CNTL_PAINT_MULTI, 4)); OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL | RADEON_GMC_BRUSH_SOLID_COLOR | (dev_priv-> color_fmt << 8) | RADEON_GMC_SRC_DATATYPE_COLOR | RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS); OUT_RING(dev_priv->front_pitch_offset); OUT_RING(clear->clear_color); OUT_RING((x << 16) | y); OUT_RING((w << 16) | h); ADVANCE_RING(); } if (flags & RADEON_BACK) { BEGIN_RING(6); OUT_RING(CP_PACKET3 (RADEON_CNTL_PAINT_MULTI, 4)); OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL | RADEON_GMC_BRUSH_SOLID_COLOR | (dev_priv-> color_fmt << 8) | RADEON_GMC_SRC_DATATYPE_COLOR | RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS); OUT_RING(dev_priv->back_pitch_offset); OUT_RING(clear->clear_color); OUT_RING((x << 16) | y); OUT_RING((w << 16) | h); ADVANCE_RING(); } } } /* hyper z clear */ /* no docs available, based on reverse engeneering by Stephane Marchesin */ if ((flags & (RADEON_DEPTH | RADEON_STENCIL)) && (flags & RADEON_CLEAR_FASTZ)) { int i; int depthpixperline = dev_priv->depth_fmt == RADEON_DEPTH_FORMAT_16BIT_INT_Z ? (dev_priv->depth_pitch / 2) : (dev_priv-> depth_pitch / 4); u32 clearmask; u32 tempRB3D_DEPTHCLEARVALUE = clear->clear_depth | ((clear->depth_mask & 0xff) << 24); /* Make sure we restore the 3D state next time. * we haven't touched any "normal" state - still need this? */ dev_priv->sarea_priv->ctx_owner = 0; if ((dev_priv->flags & RADEON_HAS_HIERZ) && (flags & RADEON_USE_HIERZ)) { /* FIXME : reverse engineer that for Rx00 cards */ /* FIXME : the mask supposedly contains low-res z values. So can't set just to the max (0xff? or actually 0x3fff?), need to take z clear value into account? */ /* pattern seems to work for r100, though get slight rendering errors with glxgears. If hierz is not enabled for r100, only 4 bits which indicate clear (15,16,31,32, all zero) matter, the other ones are ignored, and the same clear mask can be used. That's very different behaviour than R200 which needs different clear mask and different number of tiles to clear if hierz is enabled or not !?! */ clearmask = (0xff << 22) | (0xff << 6) | 0x003f003f; } else { /* clear mask : chooses the clearing pattern. rv250: could be used to clear only parts of macrotiles (but that would get really complicated...)? bit 0 and 1 (either or both of them ?!?!) are used to not clear tile (or maybe one of the bits indicates if the tile is compressed or not), bit 2 and 3 to not clear tile 1,...,. Pattern is as follows: | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29| bits ------------------------------------------------- | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31| rv100: clearmask covers 2x8 4x1 tiles, but one clear still covers 256 pixels ?!? */ clearmask = 0x0; } BEGIN_RING(8); RADEON_WAIT_UNTIL_2D_IDLE(); OUT_RING_REG(RADEON_RB3D_DEPTHCLEARVALUE, tempRB3D_DEPTHCLEARVALUE); /* what offset is this exactly ? */ OUT_RING_REG(RADEON_RB3D_ZMASKOFFSET, 0); /* need ctlstat, otherwise get some strange black flickering */ OUT_RING_REG(RADEON_RB3D_ZCACHE_CTLSTAT, RADEON_RB3D_ZC_FLUSH_ALL); ADVANCE_RING(); for (i = 0; i < nbox; i++) { int tileoffset, nrtilesx, nrtilesy, j; /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */ if ((dev_priv->flags & RADEON_HAS_HIERZ) && !(dev_priv->microcode_version == UCODE_R200)) { /* FIXME : figure this out for r200 (when hierz is enabled). Or maybe r200 actually doesn't need to put the low-res z value into the tile cache like r100, but just needs to clear the hi-level z-buffer? Works for R100, both with hierz and without. R100 seems to operate on 2x1 8x8 tiles, but... odd: offset/nrtiles need to be 64 pix (4 block) aligned? Potentially problematic with resolutions which are not 64 pix aligned? */ tileoffset = ((pbox[i].y1 >> 3) * depthpixperline + pbox[i].x1) >> 6; nrtilesx = ((pbox[i].x2 & ~63) - (pbox[i].x1 & ~63)) >> 4; nrtilesy = (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3); for (j = 0; j <= nrtilesy; j++) { BEGIN_RING(4); OUT_RING(CP_PACKET3 (RADEON_3D_CLEAR_ZMASK, 2)); /* first tile */ OUT_RING(tileoffset * 8); /* the number of tiles to clear */ OUT_RING(nrtilesx + 4); /* clear mask : chooses the clearing pattern. */ OUT_RING(clearmask); ADVANCE_RING(); tileoffset += depthpixperline >> 6; } } else if (dev_priv->microcode_version == UCODE_R200) { /* works for rv250. */ /* find first macro tile (8x2 4x4 z-pixels on rv250) */ tileoffset = ((pbox[i].y1 >> 3) * depthpixperline + pbox[i].x1) >> 5; nrtilesx = (pbox[i].x2 >> 5) - (pbox[i].x1 >> 5); nrtilesy = (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3); for (j = 0; j <= nrtilesy; j++) { BEGIN_RING(4); OUT_RING(CP_PACKET3 (RADEON_3D_CLEAR_ZMASK, 2)); /* first tile */ /* judging by the first tile offset needed, could possibly directly address/clear 4x4 tiles instead of 8x2 * 4x4 macro tiles, though would still need clear mask for right/bottom if truely 4x4 granularity is desired ? */ OUT_RING(tileoffset * 16); /* the number of tiles to clear */ OUT_RING(nrtilesx + 1); /* clear mask : chooses the clearing pattern. */ OUT_RING(clearmask); ADVANCE_RING(); tileoffset += depthpixperline >> 5; } } else { /* rv 100 */ /* rv100 might not need 64 pix alignment, who knows */ /* offsets are, hmm, weird */ tileoffset = ((pbox[i].y1 >> 4) * depthpixperline + pbox[i].x1) >> 6; nrtilesx = ((pbox[i].x2 & ~63) - (pbox[i].x1 & ~63)) >> 4; nrtilesy = (pbox[i].y2 >> 4) - (pbox[i].y1 >> 4); for (j = 0; j <= nrtilesy; j++) { BEGIN_RING(4); OUT_RING(CP_PACKET3 (RADEON_3D_CLEAR_ZMASK, 2)); OUT_RING(tileoffset * 128); /* the number of tiles to clear */ OUT_RING(nrtilesx + 4); /* clear mask : chooses the clearing pattern. */ OUT_RING(clearmask); ADVANCE_RING(); tileoffset += depthpixperline >> 6; } } } /* TODO don't always clear all hi-level z tiles */ if ((dev_priv->flags & RADEON_HAS_HIERZ) && (dev_priv->microcode_version == UCODE_R200) && (flags & RADEON_USE_HIERZ)) /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */ /* FIXME : the mask supposedly contains low-res z values. So can't set just to the max (0xff? or actually 0x3fff?), need to take z clear value into account? */ { BEGIN_RING(4); OUT_RING(CP_PACKET3(RADEON_3D_CLEAR_HIZ, 2)); OUT_RING(0x0); /* First tile */ OUT_RING(0x3cc0); OUT_RING((0xff << 22) | (0xff << 6) | 0x003f003f); ADVANCE_RING(); } } /* We have to clear the depth and/or stencil buffers by * rendering a quad into just those buffers. Thus, we have to * make sure the 3D engine is configured correctly. */ else if ((dev_priv->microcode_version == UCODE_R200) && (flags & (RADEON_DEPTH | RADEON_STENCIL))) { int tempPP_CNTL; int tempRE_CNTL; int tempRB3D_CNTL; int tempRB3D_ZSTENCILCNTL; int tempRB3D_STENCILREFMASK; int tempRB3D_PLANEMASK; int tempSE_CNTL; int tempSE_VTE_CNTL; int tempSE_VTX_FMT_0; int tempSE_VTX_FMT_1; int tempSE_VAP_CNTL; int tempRE_AUX_SCISSOR_CNTL; tempPP_CNTL = 0; tempRE_CNTL = 0; tempRB3D_CNTL = depth_clear->rb3d_cntl; tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl; tempRB3D_STENCILREFMASK = 0x0; tempSE_CNTL = depth_clear->se_cntl; /* Disable TCL */ tempSE_VAP_CNTL = ( /* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK | */ (0x9 << SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT)); tempRB3D_PLANEMASK = 0x0; tempRE_AUX_SCISSOR_CNTL = 0x0; tempSE_VTE_CNTL = SE_VTE_CNTL__VTX_XY_FMT_MASK | SE_VTE_CNTL__VTX_Z_FMT_MASK; /* Vertex format (X, Y, Z, W) */ tempSE_VTX_FMT_0 = SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK | SE_VTX_FMT_0__VTX_W0_PRESENT_MASK; tempSE_VTX_FMT_1 = 0x0; /* * Depth buffer specific enables */ if (flags & RADEON_DEPTH) { /* Enable depth buffer */ tempRB3D_CNTL |= RADEON_Z_ENABLE; } else { /* Disable depth buffer */ tempRB3D_CNTL &= ~RADEON_Z_ENABLE; } /* * Stencil buffer specific enables */ if (flags & RADEON_STENCIL) { tempRB3D_CNTL |= RADEON_STENCIL_ENABLE; tempRB3D_STENCILREFMASK = clear->depth_mask; } else { tempRB3D_CNTL &= ~RADEON_STENCIL_ENABLE; tempRB3D_STENCILREFMASK = 0x00000000; } if (flags & RADEON_USE_COMP_ZBUF) { tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE | RADEON_Z_DECOMPRESSION_ENABLE; } if (flags & RADEON_USE_HIERZ) { tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE; } BEGIN_RING(26); RADEON_WAIT_UNTIL_2D_IDLE(); OUT_RING_REG(RADEON_PP_CNTL, tempPP_CNTL); OUT_RING_REG(R200_RE_CNTL, tempRE_CNTL); OUT_RING_REG(RADEON_RB3D_CNTL, tempRB3D_CNTL); OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL); OUT_RING_REG(RADEON_RB3D_STENCILREFMASK, tempRB3D_STENCILREFMASK); OUT_RING_REG(RADEON_RB3D_PLANEMASK, tempRB3D_PLANEMASK); OUT_RING_REG(RADEON_SE_CNTL, tempSE_CNTL); OUT_RING_REG(R200_SE_VTE_CNTL, tempSE_VTE_CNTL); OUT_RING_REG(R200_SE_VTX_FMT_0, tempSE_VTX_FMT_0); OUT_RING_REG(R200_SE_VTX_FMT_1, tempSE_VTX_FMT_1); OUT_RING_REG(R200_SE_VAP_CNTL, tempSE_VAP_CNTL); OUT_RING_REG(R200_RE_AUX_SCISSOR_CNTL, tempRE_AUX_SCISSOR_CNTL); ADVANCE_RING(); /* Make sure we restore the 3D state next time. */ dev_priv->sarea_priv->ctx_owner = 0; for (i = 0; i < nbox; i++) { /* Funny that this should be required -- * sets top-left? */ radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]); BEGIN_RING(14); OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 12)); OUT_RING((RADEON_PRIM_TYPE_RECT_LIST | RADEON_PRIM_WALK_RING | (3 << RADEON_NUM_VERTICES_SHIFT))); OUT_RING(depth_boxes[i].ui[CLEAR_X1]); OUT_RING(depth_boxes[i].ui[CLEAR_Y1]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x3f800000); OUT_RING(depth_boxes[i].ui[CLEAR_X1]); OUT_RING(depth_boxes[i].ui[CLEAR_Y2]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x3f800000); OUT_RING(depth_boxes[i].ui[CLEAR_X2]); OUT_RING(depth_boxes[i].ui[CLEAR_Y2]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x3f800000); ADVANCE_RING(); } } else if ((flags & (RADEON_DEPTH | RADEON_STENCIL))) { int tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl; rb3d_cntl = depth_clear->rb3d_cntl; if (flags & RADEON_DEPTH) { rb3d_cntl |= RADEON_Z_ENABLE; } else { rb3d_cntl &= ~RADEON_Z_ENABLE; } if (flags & RADEON_STENCIL) { rb3d_cntl |= RADEON_STENCIL_ENABLE; rb3d_stencilrefmask = clear->depth_mask; /* misnamed field */ } else { rb3d_cntl &= ~RADEON_STENCIL_ENABLE; rb3d_stencilrefmask = 0x00000000; } if (flags & RADEON_USE_COMP_ZBUF) { tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE | RADEON_Z_DECOMPRESSION_ENABLE; } if (flags & RADEON_USE_HIERZ) { tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE; } BEGIN_RING(13); RADEON_WAIT_UNTIL_2D_IDLE(); OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 1)); OUT_RING(0x00000000); OUT_RING(rb3d_cntl); OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL); OUT_RING_REG(RADEON_RB3D_STENCILREFMASK, rb3d_stencilrefmask); OUT_RING_REG(RADEON_RB3D_PLANEMASK, 0x00000000); OUT_RING_REG(RADEON_SE_CNTL, depth_clear->se_cntl); ADVANCE_RING(); /* Make sure we restore the 3D state next time. */ dev_priv->sarea_priv->ctx_owner = 0; for (i = 0; i < nbox; i++) { /* Funny that this should be required -- * sets top-left? */ radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]); BEGIN_RING(15); OUT_RING(CP_PACKET3(RADEON_3D_DRAW_IMMD, 13)); OUT_RING(RADEON_VTX_Z_PRESENT | RADEON_VTX_PKCOLOR_PRESENT); OUT_RING((RADEON_PRIM_TYPE_RECT_LIST | RADEON_PRIM_WALK_RING | RADEON_MAOS_ENABLE | RADEON_VTX_FMT_RADEON_MODE | (3 << RADEON_NUM_VERTICES_SHIFT))); OUT_RING(depth_boxes[i].ui[CLEAR_X1]); OUT_RING(depth_boxes[i].ui[CLEAR_Y1]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x0); OUT_RING(depth_boxes[i].ui[CLEAR_X1]); OUT_RING(depth_boxes[i].ui[CLEAR_Y2]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x0); OUT_RING(depth_boxes[i].ui[CLEAR_X2]); OUT_RING(depth_boxes[i].ui[CLEAR_Y2]); OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]); OUT_RING(0x0); ADVANCE_RING(); } } /* Increment the clear counter. The client-side 3D driver must * wait on this value before performing the clear ioctl. We * need this because the card's so damned fast... */ dev_priv->sarea_priv->last_clear++; BEGIN_RING(4); RADEON_CLEAR_AGE(dev_priv->sarea_priv->last_clear);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?