diff options
author | Joakim Sindholt <[email protected]> | 2011-08-04 15:14:06 +0200 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2014-11-18 02:02:54 +0000 |
commit | fdd96578ef2dfe9c4ad5aab5858036298d444a64 (patch) | |
tree | 3230b0fb321381250a506503825318facb10ca73 /src/gallium/state_trackers/nine/cubetexture9.c | |
parent | 7d2573b5376bb4f9ce9a50e0b965e06032b135a9 (diff) |
nine: Add state tracker nine for Direct3D9 (v3)
Work of Joakim Sindholt (zhasha) and Christoph Bumiller (chrisbmr).
DRI3 port done by Axel Davy (mannerov).
v2: - nine_debug.c: klass extended from 32 chars to 96 (for sure) by glennk
- Nine improvements by Axel Davy (which also fixed some wine tests)
- by Emil Velikov:
- convert to static/shared drivers
- Sort and cleanup the includes
- Use AM_CPPFLAGS for the defines
- Add the linker garbage collector
- Restrict the exported symbols (think llvm)
v3: - small nine fixes
- build system improvements by Emil Velikov
v4: [Emil Velikov]
- Do no link against libudev. No longer needed.
Acked-by: Jose Fonseca <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Axel Davy <[email protected]>
Signed-off-by: David Heidelberg <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/nine/cubetexture9.c')
-rw-r--r-- | src/gallium/state_trackers/nine/cubetexture9.c | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/nine/cubetexture9.c b/src/gallium/state_trackers/nine/cubetexture9.c new file mode 100644 index 00000000000..77802e70220 --- /dev/null +++ b/src/gallium/state_trackers/nine/cubetexture9.c @@ -0,0 +1,274 @@ +/* + * Copyright 2011 Joakim Sindholt <[email protected]> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "device9.h" +#include "cubetexture9.h" +#include "nine_helpers.h" +#include "nine_pipe.h" + +#define DBG_CHANNEL DBG_CUBETEXTURE + + +static HRESULT +NineCubeTexture9_ctor( struct NineCubeTexture9 *This, + struct NineUnknownParams *pParams, + UINT EdgeLength, UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + HANDLE *pSharedHandle ) +{ + struct pipe_resource *info = &This->base.base.info; + unsigned i; + D3DSURFACE_DESC sfdesc; + HRESULT hr; + + user_assert(!(Usage & D3DUSAGE_AUTOGENMIPMAP) || + (Pool != D3DPOOL_SYSTEMMEM && Levels <= 1), D3DERR_INVALIDCALL); + + user_assert(!pSharedHandle, D3DERR_INVALIDCALL); /* TODO */ + + if (Usage & D3DUSAGE_AUTOGENMIPMAP) + Levels = 0; + + This->base.format = Format; + This->base.base.usage = Usage; + + info->screen = pParams->device->screen; + info->target = PIPE_TEXTURE_CUBE; + info->format = d3d9_to_pipe_format(Format); + info->width0 = EdgeLength; + info->height0 = EdgeLength; + info->depth0 = 1; + if (Levels) + info->last_level = Levels - 1; + else + info->last_level = util_logbase2(EdgeLength); + info->array_size = 6; + info->nr_samples = 0; + info->bind = PIPE_BIND_SAMPLER_VIEW; + info->usage = PIPE_USAGE_DEFAULT; + info->flags = 0; + + if (Usage & D3DUSAGE_RENDERTARGET) + info->bind |= PIPE_BIND_RENDER_TARGET; + if (Usage & D3DUSAGE_DEPTHSTENCIL) + info->bind |= PIPE_BIND_DEPTH_STENCIL; + + if (Usage & D3DUSAGE_DYNAMIC) { + info->usage = PIPE_USAGE_DYNAMIC; + info->bind |= + PIPE_BIND_TRANSFER_READ | + PIPE_BIND_TRANSFER_WRITE; + } + + This->surfaces = CALLOC(6 * (info->last_level + 1), sizeof(*This->surfaces)); + if (!This->surfaces) + return E_OUTOFMEMORY; + + hr = NineBaseTexture9_ctor(&This->base, pParams, D3DRTYPE_CUBETEXTURE, + Pool); + if (FAILED(hr)) + return hr; + This->base.pstype = 2; + + /* Create all the surfaces right away. + * They manage backing storage, and transfers (LockRect) are deferred + * to them. + */ + sfdesc.Format = Format; + sfdesc.Type = D3DRTYPE_SURFACE; + sfdesc.Usage = Usage; + sfdesc.Pool = Pool; + sfdesc.MultiSampleType = D3DMULTISAMPLE_NONE; + sfdesc.MultiSampleQuality = 0; + for (i = 0; i < (info->last_level + 1) * 6; ++i) { + sfdesc.Width = sfdesc.Height = u_minify(EdgeLength, i / 6); + + hr = NineSurface9_new(This->base.base.base.device, NineUnknown(This), + This->base.base.resource, D3DRTYPE_CUBETEXTURE, + i / 6, i % 6, + &sfdesc, &This->surfaces[i]); + if (FAILED(hr)) + return hr; + } + for (i = 0; i < 6; ++i) /* width = 0 means empty, depth stays 1 */ + This->dirty_rect[i].depth = 1; + + return D3D_OK; +} + +static void +NineCubeTexture9_dtor( struct NineCubeTexture9 *This ) +{ + unsigned i; + + DBG("This=%p\n", This); + + if (This->surfaces) { + for (i = 0; i < This->base.base.info.last_level * 6; ++i) + NineUnknown_Destroy(&This->surfaces[i]->base.base); + FREE(This->surfaces); + } + + NineBaseTexture9_dtor(&This->base); +} + +HRESULT WINAPI +NineCubeTexture9_GetLevelDesc( struct NineCubeTexture9 *This, + UINT Level, + D3DSURFACE_DESC *pDesc ) +{ + user_assert(Level <= This->base.base.info.last_level, D3DERR_INVALIDCALL); + user_assert(Level == 0 || !(This->base.base.usage & D3DUSAGE_AUTOGENMIPMAP), + D3DERR_INVALIDCALL); + + *pDesc = This->surfaces[Level]->desc; + + return D3D_OK; +} + +HRESULT WINAPI +NineCubeTexture9_GetCubeMapSurface( struct NineCubeTexture9 *This, + D3DCUBEMAP_FACES FaceType, + UINT Level, + IDirect3DSurface9 **ppCubeMapSurface ) +{ + const unsigned s = Level * 6 + FaceType; + + user_assert(Level <= This->base.base.info.last_level, D3DERR_INVALIDCALL); + user_assert(Level == 0 || !(This->base.base.usage & D3DUSAGE_AUTOGENMIPMAP), + D3DERR_INVALIDCALL); + user_assert(FaceType < 6, D3DERR_INVALIDCALL); + + NineUnknown_AddRef(NineUnknown(This->surfaces[s])); + *ppCubeMapSurface = (IDirect3DSurface9 *)This->surfaces[s]; + + return D3D_OK; +} + +HRESULT WINAPI +NineCubeTexture9_LockRect( struct NineCubeTexture9 *This, + D3DCUBEMAP_FACES FaceType, + UINT Level, + D3DLOCKED_RECT *pLockedRect, + const RECT *pRect, + DWORD Flags ) +{ + const unsigned s = Level * 6 + FaceType; + + user_assert(Level <= This->base.base.info.last_level, D3DERR_INVALIDCALL); + user_assert(Level == 0 || !(This->base.base.usage & D3DUSAGE_AUTOGENMIPMAP), + D3DERR_INVALIDCALL); + user_assert(FaceType < 6, D3DERR_INVALIDCALL); + + return NineSurface9_LockRect(This->surfaces[s], pLockedRect, pRect, Flags); +} + +HRESULT WINAPI +NineCubeTexture9_UnlockRect( struct NineCubeTexture9 *This, + D3DCUBEMAP_FACES FaceType, + UINT Level ) +{ + const unsigned s = Level * 6 + FaceType; + + user_assert(Level <= This->base.base.info.last_level, D3DERR_INVALIDCALL); + user_assert(FaceType < 6, D3DERR_INVALIDCALL); + + return NineSurface9_UnlockRect(This->surfaces[s]); +} + +HRESULT WINAPI +NineCubeTexture9_AddDirtyRect( struct NineCubeTexture9 *This, + D3DCUBEMAP_FACES FaceType, + const RECT *pDirtyRect ) +{ + user_assert(FaceType < 6, D3DERR_INVALIDCALL); + + if (This->base.base.pool != D3DPOOL_MANAGED) { + if (This->base.base.usage & D3DUSAGE_AUTOGENMIPMAP) + This->base.dirty_mip = TRUE; + return D3D_OK; + } + This->base.dirty = TRUE; + + BASETEX_REGISTER_UPDATE(&This->base); + + if (!pDirtyRect) { + u_box_origin_2d(This->base.base.info.width0, + This->base.base.info.height0, + &This->dirty_rect[FaceType]); + } else { + struct pipe_box box; + rect_to_pipe_box_clamp(&box, pDirtyRect); + u_box_union_2d(&This->dirty_rect[FaceType], &This->dirty_rect[FaceType], + &box); + } + return D3D_OK; +} + +IDirect3DCubeTexture9Vtbl NineCubeTexture9_vtable = { + (void *)NineUnknown_QueryInterface, + (void *)NineUnknown_AddRef, + (void *)NineUnknown_Release, + (void *)NineUnknown_GetDevice, /* actually part of Resource9 iface */ + (void *)NineResource9_SetPrivateData, + (void *)NineResource9_GetPrivateData, + (void *)NineResource9_FreePrivateData, + (void *)NineResource9_SetPriority, + (void *)NineResource9_GetPriority, + (void *)NineBaseTexture9_PreLoad, + (void *)NineResource9_GetType, + (void *)NineBaseTexture9_SetLOD, + (void *)NineBaseTexture9_GetLOD, + (void *)NineBaseTexture9_GetLevelCount, + (void *)NineBaseTexture9_SetAutoGenFilterType, + (void *)NineBaseTexture9_GetAutoGenFilterType, + (void *)NineBaseTexture9_GenerateMipSubLevels, + (void *)NineCubeTexture9_GetLevelDesc, + (void *)NineCubeTexture9_GetCubeMapSurface, + (void *)NineCubeTexture9_LockRect, + (void *)NineCubeTexture9_UnlockRect, + (void *)NineCubeTexture9_AddDirtyRect +}; + +static const GUID *NineCubeTexture9_IIDs[] = { + &IID_IDirect3DCubeTexture9, + &IID_IDirect3DBaseTexture9, + &IID_IDirect3DResource9, + &IID_IUnknown, + NULL +}; + +HRESULT +NineCubeTexture9_new( struct NineDevice9 *pDevice, + UINT EdgeLength, UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + struct NineCubeTexture9 **ppOut, + HANDLE *pSharedHandle ) +{ + NINE_DEVICE_CHILD_NEW(CubeTexture9, ppOut, pDevice, + EdgeLength, Levels, + Usage, Format, Pool, pSharedHandle); +} |