diff options
author | Vladimir Dergachev <[email protected]> | 2005-01-13 09:05:31 +0000 |
---|---|---|
committer | Vladimir Dergachev <[email protected]> | 2005-01-13 09:05:31 +0000 |
commit | d456ef48e5e23bc8c9d90bfe80f781eafe65eb39 (patch) | |
tree | fee9a6e6a53b36f51687f52470d710c9ce5a59ad /src/mesa/drivers/dri | |
parent | 3ff4eca05c67b2969386db36ee8123fc8a5e55ac (diff) |
Incorporate TX_FORMAT information contributed by Wladimir van der Laan.
Attempt to use it in r300_state.c
We are still missing something and the formats do not quite work.
Perhaps something in texture management code ?
Diffstat (limited to 'src/mesa/drivers/dri')
-rw-r--r-- | src/mesa/drivers/dri/r300/r300_reg.h | 59 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r300/r300_state.c | 154 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r300/r300_texmem.c | 10 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r300/r300_texstate.c | 8 |
4 files changed, 164 insertions, 67 deletions
diff --git a/src/mesa/drivers/dri/r300/r300_reg.h b/src/mesa/drivers/dri/r300/r300_reg.h index 33b2f3da547..5650e488c62 100644 --- a/src/mesa/drivers/dri/r300/r300_reg.h +++ b/src/mesa/drivers/dri/r300/r300_reg.h @@ -598,11 +598,60 @@ I am fairly certain that they are correct unless stated otherwise in comments. # define R300_TX_SIZE_SHIFT 26 /* largest of width, height */ # define R300_TX_SIZE_MASK (15 << 26) #define R300_TX_FORMAT_0 0x44C0 - /* Note - other bits are not known yet.. */ -# define R300_TX_FORMAT_WIDTH_SHIFT 12 -# define R300_TX_FORMAT_WIDTH_MASK (0xf<<R300_TX_FORMAT_WIDTH_SHIFT) -# define R300_TX_FORMAT_HEIGHT_SHIFT 16 -# define R300_TX_FORMAT_HEIGHT_MASK (0xf<<R300_TX_FORMAT_HEIGHT_SHIFT) + /* The interpretation of the format word by Wladimir van der Laan */ +# define R300_TX_FORMAT_I8 0x0 +# define R300_TX_FORMAT_I16 0x1 + /* gap */ +# define R300_TX_FORMAT_I8A8 0x3 +# define R300_TX_FORMAT_I16A16 0x4 + /* gap */ +# define R300_TX_FORMAT_R5G5B5 0x6 + /* gap */ +# define R300_TX_FORMAT_A4R4G4B4 0xA +# define R300_TX_FORMAT_A1R5G5B5 0xB +# define R300_TX_FORMAT_R8G8B8A8 0xC +# define R300_TX_FORMAT_R10G10B10A2 0xD +# define R300_TX_FORMAT_R16G16B16A16 0xE +# define R300_TX_FORMAT_DXT1 0xF +# define R300_TX_FORMAT_DXT3 0x10 +# define R300_TX_FORMAT_DXT5 0x15 + /* gap */ + /* Floating point formats */ + /* Note - hardware supports both 16 and 32 bit floating point */ +# define R300_TX_FORMAT_FL_I16 0x18 +# define R300_TX_FORMAT_FL_I16A16 0x19 +# define R300_TX_FORMAT_FL_R16G16B16A16 0x1A +# define R300_TX_FORMAT_FL_I32 0x1B +# define R300_TX_FORMAT_FL_I32A32 0x1C +# define R300_TX_FORMAT_FL_R32G32B32A32 0x1D + /* alpha modes, convenience mostly */ + /* if you have alpha, pick constant appropriate to the + number of channels (1 for I8, 2 for I8A8, 4 for R8G8B8A8, etc */ +# define R300_TX_FORMAT_ALPHA_1CH 0x000 +# define R300_TX_FORMAT_ALPHA_2CH 0x200 +# define R300_TX_FORMAT_ALPHA_4CH 0x600 +# define R300_TX_FORMAT_ALPHA_NONE 0xA00 + /* Swizzling */ + /* constats */ +# define R300_TX_FORMAT_X 0 +# define R300_TX_FORMAT_Y 1 +# define R300_TX_FORMAT_Z 2 +# define R300_TX_FORMAT_W 3 +# define R300_TX_FORMAT_ZERO 4 +# define R300_TX_FORMAT_ONE 5 + +# define R300_TX_FORMAT_R_SHIFT 18 +# define R300_TX_FORMAT_G_SHIFT 15 +# define R300_TX_FORMAT_B_SHIFT 12 +# define R300_TX_FORMAT_A_SHIFT 9 +# define R300_EASY_TX_FORMAT(R, G, B, A, FMT) (\ + ((R300_TX_FORMAT_##R)<<R300_TX_FORMAT_R_SHIFT) \ + | ((R300_TX_FORMAT_##G)<<R300_TX_FORMAT_G_SHIFT) \ + | ((R300_TX_FORMAT_##B)<<R300_TX_FORMAT_B_SHIFT) \ + | ((R300_TX_FORMAT_##A)<<R300_TX_FORMAT_A_SHIFT) \ + | (R300_TX_FORMAT_##FMT) \ + ) + #define R300_TX_OFFSET_0 0x4540 /* BEGIN: Guess from R200 */ # define R300_TXO_ENDIAN_NO_SWAP (0 << 0) diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 142d34bd839..e7e8a75c377 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -792,6 +792,22 @@ static int inline translate_src(int src) } } +static int known_formats[]={ + 0x0, + 0xAA06, + 0xA60E, + 0xA60E, + 0xA60A, + 0x8860C, + 0x88A0C, + 0xA00, + 0xA61D, + 0xA61D, + 0xA61A, + 0xA61A, + -1 + }; + /* I think 357 and 457 are prime numbers.. wiggle them if you get coincidences */ #define FORMAT_HASH(opRGB, srcRGB, modeRGB, opA, srcA, modeA, format, intFormat) ( \ (\ @@ -803,12 +819,37 @@ static int inline translate_src(int src) ^ (((format)) *457) \ ^ ((intFormat) * 7) \ ) + static GLuint translate_texture_format(GLcontext *ctx, GLint tex_unit, GLuint format, GLint IntFormat) { const struct gl_texture_unit *texUnit= &ctx->Texture.Unit[tex_unit]; int i=0; /* number of alpha args .. */ + GLuint fmt; + + switch(IntFormat){ + case 4: + case GL_RGBA: + case GL_RGBA8: + fmt=R300_EASY_TX_FORMAT(Z, Y, X, W, R8G8B8A8); + break; + case 3: + case GL_RGB8: + fmt=R300_EASY_TX_FORMAT(Z, Y, X, ONE, R8G8B8A8); + break; + default: + return 0; + } + #if 0 + //fmt &= 0x00fff; + //fmt |= ((format) & 0xff00)<<4; + fprintf(stderr, "NumArgsRGB=%d NumArgsA=%d\n", + texUnit->_CurrentCombine->_NumArgsRGB, + texUnit->_CurrentCombine->_NumArgsA); + fprintf(stderr, "fmt=%08x\n", fmt); + #endif + //return fmt; /* Size field in format specific first */ switch(FORMAT_HASH( texUnit->_CurrentCombine->OperandRGB[i] -GL_SRC_COLOR, @@ -820,84 +861,73 @@ static GLuint translate_texture_format(GLcontext *ctx, GLint tex_unit, GLuint fo format, IntFormat )){ - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00088047, 0x1908): + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x0008847, GL_RGBA): /* tested with: kfiresaver.kss */ - return 0x7a0c; /* kfiresaver.kss */ - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00088047, 0x8058): + return 0x760c; /* kfiresaver.kss */ + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x0008847, GL_RGBA8): /* tested with: Quake3demo */ - return 0x8a0c; /* Quake3demo -small font on the bottom */ - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00077047, 4): + return fmt; + return 0x860c; /* Quake3demo -small font on the bottom */ + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00005547, GL_RGBA8): + return fmt; + return 0x4860c; + return 0; + return 0x8a0c; /* Quake3demo - mouse cursor*/ + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00007747, 4): /* tested with: kfiresaver.kss */ - return 0x4ba0c; - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00055047, 4): + return R300_EASY_TX_FORMAT(Y, Z, W, ONE, R8G8B8A8); + return 0x4b60c; + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00005547, 4): /* tested with: kfiresaver.kss kfountain.kss */ + return R300_EASY_TX_FORMAT(Y, Z, W, ONE, R8G8B8A8); return 0x51a0c; - case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00088047, 3): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00008847, 3): /* tested with lesson 06 lesson 07 */ - return 0x53a0c; - case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00077047, 0x00000003): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00007747, 0x00000003): /* Tested with NeHe lesson 08 */ - return 0x53a0c; - //case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00055047, 0): + //case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x0005547, 0): /* Can't remember what I tested this with.. try putting return 0 of you see broken textures which are not being complained about */ - return 0x53a0c; - case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00099047, 0x8051): - //case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00089047, 0x8058): - case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00077047, 0x8051): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00009947, GL_RGB8): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00007747, GL_RGB8): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00003347, GL_RGB8): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00008947, 3): /* Tested with: Quake3demo */ + return R300_EASY_TX_FORMAT(Y, Z, W, ONE, R8G8B8A8); return 0x53a0c; - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00055045, 0x00008056): - case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00088045, 0x00008056): - return 0x53a23; - case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00099004, 0x00008050): - return 0; - return 0x2a0b; - } - // return 0x53a0c; - - /* Just key on internal format - useful for quick tryouts*/ - - return 0; - #if 1 - switch(IntFormat - ){ - case 0x3: - return 0x53a0c; - case 0x8050: - return 0x2a0b; - case 0x8056: - - return 0x53a23; - case 0x8058: - return 0; - return 0x8a0c; - //fprintf(stderr, "%08x\n", format); + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00007847, GL_RGBA8): + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00006747, GL_RGBA8): + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00006647, GL_RGBA8): + case FORMAT_HASH(0, 1, 0x2100, 0, 4, 0x1e01, 0x00008947, GL_RGBA8): /* Tested with: Quake3demo */ - return 0x53a0c; - default: - return 0x53a0c; + return R300_EASY_TX_FORMAT(Y, Z, W, W, R8G8B8A8); + return 0x5360c; + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x00007747, GL_RGBA8): + return R300_EASY_TX_FORMAT(Z, Y, X, W, R8G8B8A8) ; + case FORMAT_HASH(0, 1, 0x2100, 0, 1, 0x2100, 0x0008845, 0x00008056): + //return 0; + fprintf(stderr, "***\n"); + return R300_EASY_TX_FORMAT(Y, Z, W, W, R8G8B8A8); + return 0x53a23; } - #endif - - + { static int warn_once=1; @@ -966,14 +996,19 @@ void r300_setup_textures(GLcontext *ctx) r300->hw.tex.offset.cmd[R300_TEX_VALUE_0+i]=r300->radeon.radeonScreen->fbLocation+t->offset; r300->hw.tex.unknown4.cmd[R300_TEX_VALUE_0+i]=0x0; r300->hw.tex.unknown5.cmd[R300_TEX_VALUE_0+i]=0x0; - - - + /* We don't know how to set this yet */ //value from r300_lib.c for RGB24 //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x88a0c; r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=translate_texture_format(ctx, i, t->format, r300->state.texture.unit[i].texobj!=NULL?t->base.tObj->Image[0][0]->IntFormat:3); + + + #if 0 + fprintf(stderr, "pitch=%08x filter=%08x format=%08x\n", t->pitch, t->filter, r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]); + fprintf(stderr, "unknown1=%08x size=%08x\n", r300->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+i], + r300->hw.tex.size.cmd[R300_TEX_VALUE_0+i]); + #endif /* Use the code below to quickly find matching texture formats. Requires an app that displays the same texture repeatedly */ @@ -982,11 +1017,11 @@ void r300_setup_textures(GLcontext *ctx) static int fmt=0x0; static int k=0; k++; - if(k>400){ + if(k>20){ k=0; fmt++; texUnit = &ctx->Texture.Unit[i]; - fprintf(stderr, "Want to set FORMAT_HASH(%d, %d, 0x%04x, %d, %d, 0x%04x, 0x%08x, 0x%08x)\n", + fprintf(stderr, "Want to set FORMAT_HASH(%d, %d, 0x%04x, %d, %d, 0x%04x, 0x%08x, %s(%08x))\n", texUnit->_CurrentCombine->OperandRGB[0] -GL_SRC_COLOR, translate_src(texUnit->_CurrentCombine->SourceRGB[0]), texUnit->_CurrentCombine->ModeRGB, @@ -994,21 +1029,24 @@ void r300_setup_textures(GLcontext *ctx) translate_src(texUnit->_CurrentCombine->SourceA[0]), texUnit->_CurrentCombine->ModeA, t->format, + _mesa_lookup_enum_by_nr(t->base.tObj->Image[0][0]->IntFormat), t->base.tObj->Image[0][0]->IntFormat ); fprintf(stderr, "Also known: format_x=%08x border_color=%08x cubic_faces=%08x\n", t->format_x, t->pp_border_color, t->pp_cubic_faces); fprintf(stderr, "\t_ReallyEnabled=%08x EnvMode=%08x IntFormat=%08x\n", texUnit->_ReallyEnabled, texUnit->EnvMode, t->base.tObj->Image[0][0]->IntFormat); - if(fmt>0xff){ - //exit(-1); + if(fmt>0xfff){ fmt=0; } //sleep(1); fprintf(stderr, "Now trying format %08x\n", - 0x00a0c | (fmt<<12)); + fmt); fprintf(stderr, "size=%08x\n", t->size); } - r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x00a0c | (fmt<<12); - //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x51a00 | (fmt); + //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=known_formats[fmt]; + r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]= + R300_EASY_TX_FORMAT(Z, Y, X, W, R8G8B8A8) | (fmt<<21); + //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x08a0c | (fmt<<16); + //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x58a00 | (fmt); //r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x53a0c | (fmt<<24); } #endif diff --git a/src/mesa/drivers/dri/r300/r300_texmem.c b/src/mesa/drivers/dri/r300/r300_texmem.c index 78c077fa40f..926031c8051 100644 --- a/src/mesa/drivers/dri/r300/r300_texmem.c +++ b/src/mesa/drivers/dri/r300/r300_texmem.c @@ -366,9 +366,13 @@ static void uploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t, * width to dictate the blit width - but that won't work for compressed * textures. (Brian) */ + tex.offset = offset; tex.pitch = BLIT_WIDTH_BYTES / 64; tex.format = R200_TXFORMAT_I8; /* any 1-byte texel format */ + #if 0 /* I am not sure HOSTDATA_BLT actually works.. Experiment here - V.D */ + tex.format = R200_TXFORMAT_RGBA8888; /* any 4-byte texel format */ + #endif if (texImage->TexFormat->TexelBytes) { tex.width = imageWidth * texImage->TexFormat->TexelBytes; /* in bytes */ tex.height = imageHeight; @@ -379,9 +383,15 @@ static void uploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t, tex.height = 4; } tex.image = &tmp; + #if 0 + tex.width /= 4; + #endif /* copy (x,y,width,height,data) */ memcpy(&tmp, &t->image[face][hwlevel], sizeof(tmp)); + #if 0 + tex.image->width /=4; + #endif LOCK_HARDWARE(&rmesa->radeon); do { diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c index 15d3605d01e..d10ff4b09ae 100644 --- a/src/mesa/drivers/dri/r300/r300_texstate.c +++ b/src/mesa/drivers/dri/r300/r300_texstate.c @@ -248,13 +248,13 @@ static void r300SetTexImages(r300ContextPtr rmesa, t->filter &= ~R200_MAX_MIP_LEVEL_MASK; t->filter |= (numLevels - 1) << R200_MAX_MIP_LEVEL_SHIFT; #endif - t->format &= ~(R300_TX_FORMAT_WIDTH_MASK | - R300_TX_FORMAT_HEIGHT_MASK | + t->format &= ~(R200_TXFORMAT_WIDTH_MASK | + R200_TXFORMAT_HEIGHT_MASK | R200_TXFORMAT_CUBIC_MAP_ENABLE | R200_TXFORMAT_F5_WIDTH_MASK | R200_TXFORMAT_F5_HEIGHT_MASK); - t->format |= ((log2Width << R300_TX_FORMAT_WIDTH_SHIFT) | - (log2Height << R300_TX_FORMAT_HEIGHT_SHIFT)); + t->format |= ((log2Width << R200_TXFORMAT_WIDTH_SHIFT) | + (log2Height << R200_TXFORMAT_HEIGHT_SHIFT)); t->format_x &= ~(R200_DEPTH_LOG2_MASK | R200_TEXCOORD_MASK); if (tObj->Target == GL_TEXTURE_3D) { |