📄 r200_state_init.c
字号:
/*Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.The Weather Channel (TM) funded Tungsten Graphics to develop theinitial release of the Radeon 8500 driver under the XFree86 license.This notice must be preserved.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: * Keith Whitwell <keith@tungstengraphics.com> */#include "glheader.h"#include "imports.h"#include "enums.h"#include "colormac.h"#include "api_arrayelt.h"#include "swrast/swrast.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "tnl/t_pipeline.h"#include "swrast_setup/swrast_setup.h"#include "r200_context.h"#include "r200_ioctl.h"#include "r200_state.h"#include "r200_tcl.h"#include "r200_tex.h"#include "r200_swtcl.h"#include "xmlpool.h"/* ============================================================= * State initialization */void r200PrintDirty( r200ContextPtr rmesa, const char *msg ){ struct r200_state_atom *l; fprintf(stderr, msg); fprintf(stderr, ": "); foreach(l, &rmesa->hw.atomlist) { if (l->dirty || rmesa->hw.all_dirty) fprintf(stderr, "%s, ", l->name); } fprintf(stderr, "\n");}static int cmdpkt( int id ) { drm_radeon_cmd_header_t h; h.i = 0; h.packet.cmd_type = RADEON_CMD_PACKET; h.packet.packet_id = id; return h.i;}static int cmdvec( int offset, int stride, int count ) { drm_radeon_cmd_header_t h; h.i = 0; h.vectors.cmd_type = RADEON_CMD_VECTORS; h.vectors.offset = offset; h.vectors.stride = stride; h.vectors.count = count; return h.i;}/* warning: the count here is divided by 4 compared to other cmds (so it doesn't exceed the char size)! */static int cmdveclinear( int offset, int count ) { drm_radeon_cmd_header_t h; h.i = 0; h.veclinear.cmd_type = RADEON_CMD_VECLINEAR; h.veclinear.addr_lo = offset & 0xff; h.veclinear.addr_hi = (offset & 0xff00) >> 8; h.veclinear.count = count; return h.i;}static int cmdscl( int offset, int stride, int count ) { drm_radeon_cmd_header_t h; h.i = 0; h.scalars.cmd_type = RADEON_CMD_SCALARS; h.scalars.offset = offset; h.scalars.stride = stride; h.scalars.count = count; return h.i;}static int cmdscl2( int offset, int stride, int count ) { drm_radeon_cmd_header_t h; h.i = 0; h.scalars.cmd_type = RADEON_CMD_SCALARS2; h.scalars.offset = offset - 0x100; h.scalars.stride = stride; h.scalars.count = count; return h.i;}#define CHECK( NM, FLAG ) \static GLboolean check_##NM( GLcontext *ctx, int idx ) \{ \ r200ContextPtr rmesa = R200_CONTEXT(ctx); \ (void) idx; \ (void) rmesa; \ return FLAG; \}#define TCL_CHECK( NM, FLAG ) \static GLboolean check_##NM( GLcontext *ctx, int idx ) \{ \ r200ContextPtr rmesa = R200_CONTEXT(ctx); \ (void) idx; \ return !rmesa->TclFallback && !ctx->VertexProgram._Enabled && (FLAG); \}#define TCL_OR_VP_CHECK( NM, FLAG ) \static GLboolean check_##NM( GLcontext *ctx, int idx ) \{ \ r200ContextPtr rmesa = R200_CONTEXT(ctx); \ (void) idx; \ return !rmesa->TclFallback && (FLAG); \}#define VP_CHECK( NM, FLAG ) \static GLboolean check_##NM( GLcontext *ctx, int idx ) \{ \ r200ContextPtr rmesa = R200_CONTEXT(ctx); \ (void) idx; \ return !rmesa->TclFallback && ctx->VertexProgram._Enabled && (FLAG); \}CHECK( always, GL_TRUE )CHECK( never, GL_FALSE )CHECK( tex_any, ctx->Texture._EnabledUnits )CHECK( tf, (ctx->Texture._EnabledUnits && !ctx->ATIFragmentShader._Enabled) );CHECK( tex_pair, (rmesa->state.texture.unit[idx].unitneeded | rmesa->state.texture.unit[idx & ~1].unitneeded) )CHECK( tex, rmesa->state.texture.unit[idx].unitneeded )CHECK( pix_zero, !ctx->ATIFragmentShader._Enabled )CHECK( texenv, (rmesa->state.envneeded & (1 << idx) && !ctx->ATIFragmentShader._Enabled) )CHECK( afs_pass1, (ctx->ATIFragmentShader._Enabled && (ctx->ATIFragmentShader.Current->NumPasses > 1)) )CHECK( afs, ctx->ATIFragmentShader._Enabled )CHECK( tex_cube, rmesa->state.texture.unit[idx].unitneeded & TEXTURE_CUBE_BIT )TCL_CHECK( tcl_fog, ctx->Fog.Enabled )TCL_CHECK( tcl, GL_TRUE )TCL_CHECK( tcl_tex, rmesa->state.texture.unit[idx].unitneeded )TCL_CHECK( tcl_lighting, ctx->Light.Enabled )TCL_CHECK( tcl_light, ctx->Light.Enabled && ctx->Light.Light[idx].Enabled )TCL_OR_VP_CHECK( tcl_ucp, (ctx->Transform.ClipPlanesEnabled & (1 << idx)) )TCL_OR_VP_CHECK( tcl_or_vp, GL_TRUE )VP_CHECK( tcl_vp, GL_TRUE )VP_CHECK( tcl_vp_size, ctx->VertexProgram.Current->Base.NumNativeInstructions > 64 )VP_CHECK( tcl_vpp_size, ctx->VertexProgram.Current->Base.NumNativeParameters > 96 )/* Initialize the context's hardware state. */void r200InitState( r200ContextPtr rmesa ){ GLcontext *ctx = rmesa->glCtx; GLuint color_fmt, depth_fmt, i; GLint drawPitch, drawOffset; switch ( rmesa->r200Screen->cpp ) { case 2: color_fmt = R200_COLOR_FORMAT_RGB565; break; case 4: color_fmt = R200_COLOR_FORMAT_ARGB8888; break; default: fprintf( stderr, "Error: Unsupported pixel depth... exiting\n" ); exit( -1 ); } rmesa->state.color.clear = 0x00000000; switch ( ctx->Visual.depthBits ) { case 16: rmesa->state.depth.clear = 0x0000ffff; rmesa->state.depth.scale = 1.0 / (GLfloat)0xffff; depth_fmt = R200_DEPTH_FORMAT_16BIT_INT_Z; rmesa->state.stencil.clear = 0x00000000; break; case 24: rmesa->state.depth.clear = 0x00ffffff; rmesa->state.depth.scale = 1.0 / (GLfloat)0xffffff; depth_fmt = R200_DEPTH_FORMAT_24BIT_INT_Z; rmesa->state.stencil.clear = 0xffff0000; break; default: fprintf( stderr, "Error: Unsupported depth %d... exiting\n", ctx->Visual.depthBits ); exit( -1 ); } /* Only have hw stencil when depth buffer is 24 bits deep */ rmesa->state.stencil.hwBuffer = ( ctx->Visual.stencilBits > 0 && ctx->Visual.depthBits == 24 ); rmesa->Fallback = 0; if ( ctx->Visual.doubleBufferMode && rmesa->sarea->pfCurrentPage == 0 ) { drawOffset = rmesa->r200Screen->backOffset; drawPitch = rmesa->r200Screen->backPitch; } else { drawOffset = rmesa->r200Screen->frontOffset; drawPitch = rmesa->r200Screen->frontPitch; }#if 000 if ( ctx->Visual.doubleBufferMode && rmesa->sarea->pfCurrentPage == 0 ) { rmesa->state.color.drawOffset = rmesa->r200Screen->backOffset; rmesa->state.color.drawPitch = rmesa->r200Screen->backPitch; } else { rmesa->state.color.drawOffset = rmesa->r200Screen->frontOffset; rmesa->state.color.drawPitch = rmesa->r200Screen->frontPitch; } rmesa->state.pixel.readOffset = rmesa->state.color.drawOffset; rmesa->state.pixel.readPitch = rmesa->state.color.drawPitch;#endif rmesa->hw.max_state_size = 0;#define ALLOC_STATE( ATOM, CHK, SZ, NM, IDX ) \ do { \ rmesa->hw.ATOM.cmd_size = SZ; \ rmesa->hw.ATOM.cmd = (int *)CALLOC(SZ * sizeof(int)); \ rmesa->hw.ATOM.lastcmd = (int *)CALLOC(SZ * sizeof(int)); \ rmesa->hw.ATOM.name = NM; \ rmesa->hw.ATOM.idx = IDX; \ rmesa->hw.ATOM.check = check_##CHK; \ rmesa->hw.ATOM.dirty = GL_FALSE; \ rmesa->hw.max_state_size += SZ * sizeof(int); \ } while (0) /* Allocate state buffers: */ if (rmesa->r200Screen->drmSupportsBlendColor) ALLOC_STATE( ctx, always, CTX_STATE_SIZE_NEWDRM, "CTX/context", 0 ); else ALLOC_STATE( ctx, always, CTX_STATE_SIZE_OLDDRM, "CTX/context", 0 ); ALLOC_STATE( set, always, SET_STATE_SIZE, "SET/setup", 0 ); ALLOC_STATE( lin, always, LIN_STATE_SIZE, "LIN/line", 0 ); ALLOC_STATE( msk, always, MSK_STATE_SIZE, "MSK/mask", 0 ); ALLOC_STATE( vpt, always, VPT_STATE_SIZE, "VPT/viewport", 0 ); ALLOC_STATE( vtx, always, VTX_STATE_SIZE, "VTX/vertex", 0 ); ALLOC_STATE( vap, always, VAP_STATE_SIZE, "VAP/vap", 0 ); ALLOC_STATE( vte, always, VTE_STATE_SIZE, "VTE/vte", 0 ); ALLOC_STATE( msc, always, MSC_STATE_SIZE, "MSC/misc", 0 ); ALLOC_STATE( cst, always, CST_STATE_SIZE, "CST/constant", 0 ); ALLOC_STATE( zbs, always, ZBS_STATE_SIZE, "ZBS/zbias", 0 ); ALLOC_STATE( tf, tf, TF_STATE_SIZE, "TF/tfactor", 0 ); if (rmesa->r200Screen->drmSupportsFragShader) { if (rmesa->r200Screen->chip_family == CHIP_FAMILY_R200) { /* make sure texture units 0/1 are emitted pair-wise for r200 t0 hang workaround */ ALLOC_STATE( tex[0], tex_pair, TEX_STATE_SIZE_NEWDRM, "TEX/tex-0", 0 ); ALLOC_STATE( tex[1], tex_pair, TEX_STATE_SIZE_NEWDRM, "TEX/tex-1", 1 ); ALLOC_STATE( tam, tex_any, TAM_STATE_SIZE, "TAM/tam", 0 ); } else { ALLOC_STATE( tex[0], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-0", 0 ); ALLOC_STATE( tex[1], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-1", 1 ); ALLOC_STATE( tam, never, TAM_STATE_SIZE, "TAM/tam", 0 ); } ALLOC_STATE( tex[2], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-2", 2 ); ALLOC_STATE( tex[3], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-3", 3 ); ALLOC_STATE( tex[4], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-4", 4 ); ALLOC_STATE( tex[5], tex, TEX_STATE_SIZE_NEWDRM, "TEX/tex-5", 5 ); ALLOC_STATE( atf, afs, ATF_STATE_SIZE, "ATF/tfactor", 0 ); ALLOC_STATE( afs[0], afs_pass1, AFS_STATE_SIZE, "AFS/afsinst-0", 0 ); ALLOC_STATE( afs[1], afs, AFS_STATE_SIZE, "AFS/afsinst-1", 1 ); } else { if (rmesa->r200Screen->chip_family == CHIP_FAMILY_R200) { ALLOC_STATE( tex[0], tex_pair, TEX_STATE_SIZE_OLDDRM, "TEX/tex-0", 0 ); ALLOC_STATE( tex[1], tex_pair, TEX_STATE_SIZE_OLDDRM, "TEX/tex-1", 1 ); ALLOC_STATE( tam, tex_any, TAM_STATE_SIZE, "TAM/tam", 0 ); } else { ALLOC_STATE( tex[0], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-0", 0 ); ALLOC_STATE( tex[1], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-1", 1 ); ALLOC_STATE( tam, never, TAM_STATE_SIZE, "TAM/tam", 0 ); } ALLOC_STATE( tex[2], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-2", 2 ); ALLOC_STATE( tex[3], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-3", 3 ); ALLOC_STATE( tex[4], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-4", 4 ); ALLOC_STATE( tex[5], tex, TEX_STATE_SIZE_OLDDRM, "TEX/tex-5", 5 ); ALLOC_STATE( atf, never, ATF_STATE_SIZE, "TF/tfactor", 0 ); ALLOC_STATE( afs[0], never, AFS_STATE_SIZE, "AFS/afsinst-0", 0 ); ALLOC_STATE( afs[1], never, AFS_STATE_SIZE, "AFS/afsinst-1", 1 ); } if (rmesa->r200Screen->drmSupportsCubeMapsR200) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -