X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=helpers%2Fd3d10size.hpp;h=6441bdcb7ae6579e40afcba1eed15f0e47aca7ee;hb=HEAD;hp=b325e52d58fc61284238584ee9efb9095371d920;hpb=30fb4c3b5efba7481993b87e667fbee2f411870c;p=apitrace diff --git a/helpers/d3d10size.hpp b/helpers/d3d10size.hpp index b325e52..6441bdc 100644 --- a/helpers/d3d10size.hpp +++ b/helpers/d3d10size.hpp @@ -41,83 +41,9 @@ #include - -static size_t -_calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) { - if (Width == 0 || Height == 0 || Depth == 0) { - return 0; - } - - switch (Format) { - case DXGI_FORMAT_BC1_TYPELESS: - case DXGI_FORMAT_BC1_UNORM: - case DXGI_FORMAT_BC1_UNORM_SRGB: - case DXGI_FORMAT_BC2_TYPELESS: - case DXGI_FORMAT_BC2_UNORM: - case DXGI_FORMAT_BC2_UNORM_SRGB: - case DXGI_FORMAT_BC3_TYPELESS: - case DXGI_FORMAT_BC3_UNORM: - case DXGI_FORMAT_BC3_UNORM_SRGB: - case DXGI_FORMAT_BC4_TYPELESS: - case DXGI_FORMAT_BC4_UNORM: - case DXGI_FORMAT_BC4_SNORM: - case DXGI_FORMAT_BC5_TYPELESS: - case DXGI_FORMAT_BC5_UNORM: - case DXGI_FORMAT_BC5_SNORM: - Width = (Width + 3) / 4; - Height = (Height + 3) / 4; - break; - - case DXGI_FORMAT_R8G8_B8G8_UNORM: - case DXGI_FORMAT_G8R8_G8B8_UNORM: - Width = (Width + 1) / 2; - break; - - case DXGI_FORMAT_UNKNOWN: - return 0; - - default: - break; - } - - /* FIXME */ - (void)Width; - - size_t size = Height * RowPitch; - - if (Depth > 1) { - size += (Depth - 1) * DepthPitch; - } - - return size; -} - -static size_t -_calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) { - if (Width == 0 || Height == 0 || Depth == 0) { - return 0; - } - - Width = std::max(Width >> MipLevel, UINT(1)); - Height = std::max(Height >> MipLevel, UINT(1)); - Depth = std::max(Depth >> MipLevel, UINT(1)); - - return _calcDataSize(Format, Width, Height, RowPitch, Depth, DepthPitch); -} +#include "dxgisize.hpp" -inline UINT -_getNumMipLevels(UINT Width, UINT Height = 1, UINT Depth = 1) { - UINT MipLevels = 0; - do { - ++MipLevels; - Width >>= 1; - Height >>= 1; - Depth >>= 1; - } while (Width || Height || Depth); - return MipLevels; -} - inline UINT _getNumMipLevels(const D3D10_BUFFER_DESC *pDesc) { return 1; @@ -250,24 +176,75 @@ _getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UIN } -static inline void -_getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +static inline size_t +_calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3D10_BOX *pDstBox, UINT SrcRowPitch, UINT SrcDepthPitch) { + if (pDstBox && + (pDstBox->left >= pDstBox->right || + pDstBox->top >= pDstBox->bottom || + pDstBox->front >= pDstBox->back)) { + return 0; + } - if (!(MapFlags & DXGI_MAP_WRITE)) { - return; + D3D10_RESOURCE_DIMENSION Type = D3D10_RESOURCE_DIMENSION_UNKNOWN; + pDstResource->GetType(&Type); + + DXGI_FORMAT Format; + UINT Width; + UINT Height = 1; + UINT Depth = 1; + UINT MipLevel = 0; + + switch (Type) { + case D3D10_RESOURCE_DIMENSION_BUFFER: + if (pDstBox) { + return pDstBox->right - pDstBox->left; + } else { + D3D10_BUFFER_DESC Desc; + static_cast(pDstResource)->GetDesc(&Desc); + return Desc.ByteWidth; + } + case D3D10_RESOURCE_DIMENSION_TEXTURE1D: + { + D3D10_TEXTURE1D_DESC Desc; + static_cast(pDstResource)->GetDesc(&Desc); + Format = Desc.Format; + Width = Desc.Width; + MipLevel = DstSubresource % Desc.MipLevels; + } + break; + case D3D10_RESOURCE_DIMENSION_TEXTURE2D: + { + D3D10_TEXTURE2D_DESC Desc; + static_cast(pDstResource)->GetDesc(&Desc); + Format = Desc.Format; + Width = Desc.Width; + Height = Desc.Height; + MipLevel = DstSubresource % Desc.MipLevels; + } + break; + case D3D10_RESOURCE_DIMENSION_TEXTURE3D: + { + D3D10_TEXTURE3D_DESC Desc; + static_cast(pDstResource)->GetDesc(&Desc); + Format = Desc.Format; + Width = Desc.Width; + Height = Desc.Height; + Depth = Desc.Depth; + } + break; + case D3D10_RESOURCE_DIMENSION_UNKNOWN: + default: + assert(0); + return 0; } - DXGI_SURFACE_DESC Desc; - HRESULT hr = pResource->GetDesc(&Desc); - if (FAILED(hr)) { - return; + if (pDstBox) { + Width = pDstBox->right - pDstBox->left; + Height = pDstBox->bottom - pDstBox->top; + Depth = pDstBox->back - pDstBox->front; } - pMappedData = pLockedRect->pBits; - MappedSize = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch); + return _calcMipDataSize(MipLevel, Format, Width, Height, SrcRowPitch, Depth, SrcDepthPitch); }