diff options
author | Felix Kuehling <[email protected]> | 2005-01-03 22:24:44 +0000 |
---|---|---|
committer | Felix Kuehling <[email protected]> | 2005-01-03 22:24:44 +0000 |
commit | e3748eb19ba444f411ad66905dfddbe809225ca0 (patch) | |
tree | 726327849feaf57de43d5992201190042f252020 /src/mesa/drivers/dri/savage/savagespan.c | |
parent | 87889aeab46ece5800cca9390fe95e83515b313d (diff) |
Added support for floating point depth buffers on Savage4-based
hardware. By also reversing the depth range this can compensate the loss
of accuracy of far objects caused by the projective transformation.
Software fallbacks work but are slightly slower since floats in a custom
(non IEEE) format have to be encoded and decoded. I havn't done anything
about polygon offsets yet. There doesn't seem to be an easy way do get
it right except making the offset unit as big as the lowest resolution
of depth values. For now float depth is disabled by default but can be
enabled through driconf (though I have seen only positive effects so
far).
Diffstat (limited to 'src/mesa/drivers/dri/savage/savagespan.c')
-rw-r--r-- | src/mesa/drivers/dri/savage/savagespan.c | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/src/mesa/drivers/dri/savage/savagespan.c b/src/mesa/drivers/dri/savage/savagespan.c index 0caee3a652d..6cda13cc295 100644 --- a/src/mesa/drivers/dri/savage/savagespan.c +++ b/src/mesa/drivers/dri/savage/savagespan.c @@ -158,13 +158,14 @@ do { \ -/* 16 bit depthbuffer functions. +/* 16 bit integer depthbuffer functions + * Depth range is reversed. See also savageCalcViewport. */ #define WRITE_DEPTH( _x, _y, d ) \ - *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = d + *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = 0xFFFF - d #define READ_DEPTH( d, _x, _y ) \ - d = *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) + d = 0xFFFF - *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) #define TAG(x) savage##x##_16 #include "depthtmp.h" @@ -173,22 +174,62 @@ do { \ -/* 8-bit stencil /24-bit depth depthbuffer functions. +/* 16 bit float depthbuffer functions + */ +#define WRITE_DEPTH( _x, _y, d ) \ + *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) = \ + savageEncodeFloat16( 1.0 - (GLfloat)d/65535.0 ) + +#define READ_DEPTH( d, _x, _y ) \ + d = 65535 - \ + savageDecodeFloat16( *(GLushort *)(buf + ((_x)<<1) + (_y)*pitch) ) * \ + 65535.0 + +#define TAG(x) savage##x##_16f +#include "depthtmp.h" + + + + + +/* 8-bit stencil /24-bit integer depth depthbuffer functions. + * Depth range is reversed. See also savageCalcViewport. */ #define WRITE_DEPTH( _x, _y, d ) do { \ GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \ tmp &= 0xFF000000; \ - tmp |= d; \ + tmp |= 0x00FFFFFF - d; \ *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \ } while(0) #define READ_DEPTH( d, _x, _y ) \ - d = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) + d = 0x00FFFFFF - (*(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF) #define TAG(x) savage##x##_8_24 #include "depthtmp.h" + + + +/* 24 bit float depthbuffer functions + */ +#define WRITE_DEPTH( _x, _y, d ) do { \ + GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \ + tmp &= 0xFF000000; \ + tmp |= savageEncodeFloat24( 1.0 - (GLfloat)d/16777215.0 ); \ + *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \ +} while(0) + +#define READ_DEPTH( d, _x, _y ) \ + d = 16777215 - savageDecodeFloat24( \ + *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch) & 0x00FFFFFF) \ + * 16777215.0 + +#define TAG(x) savage##x##_8_24f +#include "depthtmp.h" + + #define WRITE_STENCIL( _x, _y, d ) do { \ GLuint tmp = *(GLuint *)(buf + ((_x)<<2) + (_y)*pitch); \ tmp &= 0x00FFFFFF; \ @@ -315,20 +356,36 @@ void savageDDInitSpanFuncs( GLcontext *ctx ) switch (imesa->savageScreen->zpp) { - case 2: - swdd->ReadDepthSpan = savageReadDepthSpan_16; - swdd->WriteDepthSpan = savageWriteDepthSpan_16; - swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_16; - swdd->ReadDepthPixels = savageReadDepthPixels_16; - swdd->WriteDepthPixels = savageWriteDepthPixels_16; + case 2: + if (imesa->float_depth) { + swdd->ReadDepthSpan = savageReadDepthSpan_16f; + swdd->WriteDepthSpan = savageWriteDepthSpan_16f; + swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_16f; + swdd->ReadDepthPixels = savageReadDepthPixels_16f; + swdd->WriteDepthPixels = savageWriteDepthPixels_16f; + } else { + swdd->ReadDepthSpan = savageReadDepthSpan_16; + swdd->WriteDepthSpan = savageWriteDepthSpan_16; + swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_16; + swdd->ReadDepthPixels = savageReadDepthPixels_16; + swdd->WriteDepthPixels = savageWriteDepthPixels_16; + } break; case 4: - swdd->ReadDepthSpan = savageReadDepthSpan_8_24; - swdd->WriteDepthSpan = savageWriteDepthSpan_8_24; - swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_8_24; - swdd->ReadDepthPixels = savageReadDepthPixels_8_24; - swdd->WriteDepthPixels = savageWriteDepthPixels_8_24; + if (imesa->float_depth) { + swdd->ReadDepthSpan = savageReadDepthSpan_8_24f; + swdd->WriteDepthSpan = savageWriteDepthSpan_8_24f; + swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_8_24f; + swdd->ReadDepthPixels = savageReadDepthPixels_8_24f; + swdd->WriteDepthPixels = savageWriteDepthPixels_8_24f; + } else { + swdd->ReadDepthSpan = savageReadDepthSpan_8_24; + swdd->WriteDepthSpan = savageWriteDepthSpan_8_24; + swdd->WriteMonoDepthSpan = savageWriteMonoDepthSpan_8_24; + swdd->ReadDepthPixels = savageReadDepthPixels_8_24; + swdd->WriteDepthPixels = savageWriteDepthPixels_8_24; + } swdd->ReadStencilSpan = savageReadStencilSpan_8_24; swdd->WriteStencilSpan = savageWriteStencilSpan_8_24; swdd->ReadStencilPixels = savageReadStencilPixels_8_24; |