From 77f0ecf9cead20ee6f61149f66663258cebd6179 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Sun, 7 Dec 2014 18:11:40 +0100 Subject: [PATCH] st/nine: Add ATI1 and ATI2 support Adds ATI1 and ATI2 support to nine. They map to PIPE_FORMAT_RGTC1_UNORM and PIPE_FORMAT_RGTC2_UNORM, but need special handling. Reviewed-by: David Heidelberg Signed-off-by: Axel Davy Signed-off-by: Xavier Bouchoux Cc: "10.4" --- src/gallium/state_trackers/nine/adapter9.c | 3 +++ .../state_trackers/nine/basetexture9.c | 9 ++++++--- .../state_trackers/nine/cubetexture9.c | 4 ++++ src/gallium/state_trackers/nine/nine_pipe.h | 2 ++ src/gallium/state_trackers/nine/surface9.c | 19 +++++++++++++++---- .../state_trackers/nine/volumetexture9.c | 4 ++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/gallium/state_trackers/nine/adapter9.c b/src/gallium/state_trackers/nine/adapter9.c index 871a9a3cc75..481f86362f8 100644 --- a/src/gallium/state_trackers/nine/adapter9.c +++ b/src/gallium/state_trackers/nine/adapter9.c @@ -302,6 +302,9 @@ NineAdapter9_CheckDeviceFormat( struct NineAdapter9 *This, return D3DERR_NOTAVAILABLE; } + /* we support ATI1 and ATI2 hack only for 2D textures */ + if (RType != D3DRTYPE_TEXTURE && (CheckFormat == D3DFMT_ATI1 || CheckFormat == D3DFMT_ATI2)) + return D3DERR_NOTAVAILABLE; /* if (Usage & D3DUSAGE_NONSECURE) { don't know the implications of this } */ /* if (Usage & D3DUSAGE_SOFTWAREPROCESSING) { we can always support this } */ diff --git a/src/gallium/state_trackers/nine/basetexture9.c b/src/gallium/state_trackers/nine/basetexture9.c index c09d443f2d0..5134de24e23 100644 --- a/src/gallium/state_trackers/nine/basetexture9.c +++ b/src/gallium/state_trackers/nine/basetexture9.c @@ -492,9 +492,12 @@ NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This, swizzle[2] = PIPE_SWIZZLE_RED; swizzle[3] = PIPE_SWIZZLE_RED; } - } else if (resource->format != PIPE_FORMAT_A8_UNORM) { - /* A8 is the only exception that should have 0.0 as default values - * for RGB. It is already what gallium does. All the other ones + } else if (resource->format != PIPE_FORMAT_A8_UNORM && + resource->format != PIPE_FORMAT_RGTC1_UNORM) { + /* exceptions: + * A8 should have 0.0 as default values for RGB. + * ATI1/RGTC1 should be r 0 0 1 (tested on windows). + * It is already what gallium does. All the other ones * should have 1.0 for non-defined values */ for (i = 0; i < 4; i++) { if (SWIZZLE_TO_REPLACE(desc->swizzle[i])) diff --git a/src/gallium/state_trackers/nine/cubetexture9.c b/src/gallium/state_trackers/nine/cubetexture9.c index bb1219aa88f..8e1659a06ee 100644 --- a/src/gallium/state_trackers/nine/cubetexture9.c +++ b/src/gallium/state_trackers/nine/cubetexture9.c @@ -63,6 +63,10 @@ NineCubeTexture9_ctor( struct NineCubeTexture9 *This, return D3DERR_INVALIDCALL; } + /* We support ATI1 and ATI2 hacks only for 2D textures */ + if (Format == D3DFMT_ATI1 || Format == D3DFMT_ATI2) + return D3DERR_INVALIDCALL; + info->screen = pParams->device->screen; info->target = PIPE_TEXTURE_CUBE; info->format = pf; diff --git a/src/gallium/state_trackers/nine/nine_pipe.h b/src/gallium/state_trackers/nine/nine_pipe.h index 06e4dc92aa8..41792f09e8c 100644 --- a/src/gallium/state_trackers/nine/nine_pipe.h +++ b/src/gallium/state_trackers/nine/nine_pipe.h @@ -185,6 +185,8 @@ d3d9_to_pipe_format(D3DFORMAT format) case D3DFMT_DXT3: return PIPE_FORMAT_DXT3_RGBA; case D3DFMT_DXT4: return PIPE_FORMAT_DXT5_RGBA; /* XXX */ case D3DFMT_DXT5: return PIPE_FORMAT_DXT5_RGBA; + case D3DFMT_ATI1: return PIPE_FORMAT_RGTC1_UNORM; + case D3DFMT_ATI2: return PIPE_FORMAT_RGTC2_UNORM; case D3DFMT_UYVY: return PIPE_FORMAT_UYVY; case D3DFMT_YUY2: return PIPE_FORMAT_YUYV; /* XXX check */ case D3DFMT_NV12: return PIPE_FORMAT_NV12; diff --git a/src/gallium/state_trackers/nine/surface9.c b/src/gallium/state_trackers/nine/surface9.c index 59288927a84..b3c7c189a46 100644 --- a/src/gallium/state_trackers/nine/surface9.c +++ b/src/gallium/state_trackers/nine/surface9.c @@ -38,6 +38,8 @@ #define DBG_CHANNEL DBG_SURFACE +#define is_ATI1_ATI2(format) (format == PIPE_FORMAT_RGTC1_UNORM || format == PIPE_FORMAT_RGTC2_UNORM) + HRESULT NineSurface9_ctor( struct NineSurface9 *This, struct NineUnknownParams *pParams, @@ -382,10 +384,19 @@ NineSurface9_LockRect( struct NineSurface9 *This, if (This->data) { DBG("returning system memory\n"); - - pLockedRect->Pitch = This->stride; - pLockedRect->pBits = NineSurface9_GetSystemMemPointer(This, - box.x, box.y); + /* ATI1 and ATI2 need special handling, because of d3d9 bug. + * We must advertise to the application as if it is uncompressed + * and bpp 8, and the app has a workaround to work with the fact + * that it is actually compressed. */ + if (is_ATI1_ATI2(This->base.info.format)) { + pLockedRect->Pitch = This->desc.Height; + pLockedRect->pBits = This->data + box.y * This->desc.Height + box.x; + } else { + pLockedRect->Pitch = This->stride; + pLockedRect->pBits = NineSurface9_GetSystemMemPointer(This, + box.x, + box.y); + } } else { DBG("mapping pipe_resource %p (level=%u usage=%x)\n", resource, This->level, usage); diff --git a/src/gallium/state_trackers/nine/volumetexture9.c b/src/gallium/state_trackers/nine/volumetexture9.c index f116899bcef..81d4808dd2b 100644 --- a/src/gallium/state_trackers/nine/volumetexture9.c +++ b/src/gallium/state_trackers/nine/volumetexture9.c @@ -65,6 +65,10 @@ NineVolumeTexture9_ctor( struct NineVolumeTexture9 *This, return D3DERR_INVALIDCALL; } + /* We support ATI1 and ATI2 hacks only for 2D textures */ + if (Format == D3DFMT_ATI1 || Format == D3DFMT_ATI2) + return D3DERR_INVALIDCALL; + info->screen = pParams->device->screen; info->target = PIPE_TEXTURE_3D; info->format = pf; -- 2.30.2