diff options
-rw-r--r-- | helpers/d3d10size.hpp | 18 | ||||
-rw-r--r-- | helpers/d3d11size.hpp | 18 |
2 files changed, 26 insertions, 10 deletions
diff --git a/helpers/d3d10size.hpp b/helpers/d3d10size.hpp index 96727a3e..c9785615 100644 --- a/helpers/d3d10size.hpp +++ b/helpers/d3d10size.hpp @@ -193,7 +193,7 @@ _calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3 UINT Width; UINT Height = 1; UINT Depth = 1; - UINT MipLevel = 0; + UINT MipLevels = 1; switch (Type) { case D3D10_RESOURCE_DIMENSION_BUFFER: @@ -210,7 +210,7 @@ _calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3 static_cast<ID3D10Texture1D *>(pDstResource)->GetDesc(&Desc); Format = Desc.Format; Width = Desc.Width; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D10_RESOURCE_DIMENSION_TEXTURE2D: @@ -220,7 +220,7 @@ _calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3 Format = Desc.Format; Width = Desc.Width; Height = Desc.Height; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D10_RESOURCE_DIMENSION_TEXTURE3D: @@ -231,7 +231,7 @@ _calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3 Width = Desc.Width; Height = Desc.Height; Depth = Desc.Depth; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D10_RESOURCE_DIMENSION_UNKNOWN: @@ -244,9 +244,17 @@ _calcSubresourceSize(ID3D10Resource *pDstResource, UINT DstSubresource, const D3 Width = pDstBox->right - pDstBox->left; Height = pDstBox->bottom - pDstBox->top; Depth = pDstBox->back - pDstBox->front; + } else { + assert(Width > 0); + assert(Height > 0); + assert(Depth > 0); + UINT MipLevel = DstSubresource % MipLevels; + Width = std::max(Width >> MipLevel, UINT(1)); + Height = std::max(Height >> MipLevel, UINT(1)); + Depth = std::max(Depth >> MipLevel, UINT(1)); } - return _calcMipDataSize(MipLevel, Format, Width, Height, SrcRowPitch, Depth, SrcDepthPitch); + return _calcDataSize(Format, Width, Height, SrcRowPitch, Depth, SrcDepthPitch); } diff --git a/helpers/d3d11size.hpp b/helpers/d3d11size.hpp index fcab7a7b..4c59510f 100644 --- a/helpers/d3d11size.hpp +++ b/helpers/d3d11size.hpp @@ -124,7 +124,7 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 UINT Width; UINT Height = 1; UINT Depth = 1; - UINT MipLevel = 0; + UINT MipLevels = 1; switch (Type) { case D3D11_RESOURCE_DIMENSION_BUFFER: @@ -141,7 +141,7 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 static_cast<ID3D11Texture1D *>(pDstResource)->GetDesc(&Desc); Format = Desc.Format; Width = Desc.Width; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D11_RESOURCE_DIMENSION_TEXTURE2D: @@ -151,7 +151,7 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 Format = Desc.Format; Width = Desc.Width; Height = Desc.Height; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D11_RESOURCE_DIMENSION_TEXTURE3D: @@ -162,7 +162,7 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 Width = Desc.Width; Height = Desc.Height; Depth = Desc.Depth; - MipLevel = DstSubresource % Desc.MipLevels; + MipLevels = Desc.MipLevels; } break; case D3D11_RESOURCE_DIMENSION_UNKNOWN: @@ -175,9 +175,17 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 Width = pDstBox->right - pDstBox->left; Height = pDstBox->bottom - pDstBox->top; Depth = pDstBox->back - pDstBox->front; + } else { + assert(Width > 0); + assert(Height > 0); + assert(Depth > 0); + UINT MipLevel = DstSubresource % MipLevels; + Width = std::max(Width >> MipLevel, UINT(1)); + Height = std::max(Height >> MipLevel, UINT(1)); + Depth = std::max(Depth >> MipLevel, UINT(1)); } - return _calcMipDataSize(MipLevel, Format, Width, Height, SrcRowPitch, Depth, SrcDepthPitch); + return _calcDataSize(Format, Width, Height, SrcRowPitch, Depth, SrcDepthPitch); } |