+static size_t
+_calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT 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);
+}
+
+
+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;
+}
+
+inline UINT
+_getNumMipLevels(const D3D10_TEXTURE1D_DESC *pDesc) {
+ return pDesc->MipLevels != 0 ? pDesc->MipLevels : _getNumMipLevels(pDesc->Width);
+}
+
+inline UINT
+_getNumMipLevels(const D3D10_TEXTURE2D_DESC *pDesc) {
+ return pDesc->MipLevels != 0 ? pDesc->MipLevels : _getNumMipLevels(pDesc->Width, pDesc->Height);
+}
+
+inline UINT
+_getNumMipLevels(const D3D10_TEXTURE3D_DESC *pDesc) {
+ return pDesc->MipLevels != 0 ? pDesc->MipLevels : _getNumMipLevels(pDesc->Width, pDesc->Height, pDesc->Depth);
+}
+
+inline UINT
+_getNumSubResources(const D3D10_BUFFER_DESC *pDesc) {
+ return 1;
+}
+
+inline UINT
+_getNumSubResources(const D3D10_TEXTURE1D_DESC *pDesc) {
+ return _getNumMipLevels(pDesc) * pDesc->ArraySize;
+}
+
+inline UINT
+_getNumSubResources(const D3D10_TEXTURE2D_DESC *pDesc) {
+ return _getNumMipLevels(pDesc) * pDesc->ArraySize;
+}
+
+inline UINT
+_getNumSubResources(const D3D10_TEXTURE3D_DESC *pDesc) {
+ return _getNumMipLevels(pDesc);
+}
+