]> git.cworth.org Git - apitrace/commitdiff
d3d10: Take mip level in consideration.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 4 Nov 2012 10:03:43 +0000 (10:03 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 4 Nov 2012 10:03:43 +0000 (10:03 +0000)
helpers/d3d10size.hpp
specs/d3d10.py

index 1a488810d9033f8d4ef2b818c1ccd5f420c53146..bd9f838fa771b976ff65f7f0a1001b19f53c64d8 100644 (file)
 
 #include <assert.h>
 
+#include <algorithm>
+
 
 static size_t
-_getMapSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT DepthPitch = 0) {
+_calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT DepthPitch = 0) {
     if (Width == 0 || Height == 0 || Depth == 0) {
         return 0;
     }
@@ -100,6 +102,72 @@ _getMapSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Dept
     return size;
 }
 
+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);
+}
+
 static inline void
 _getMapInfo(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * ppData,
             void * & pMappedData, size_t & MappedSize) {
@@ -130,8 +198,10 @@ _getMapInfo(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
     D3D10_TEXTURE1D_DESC Desc;
     pResource->GetDesc(&Desc);
 
+    UINT MipLevel = Subresource % _getNumMipLevels(&Desc);
+
     pMappedData = *ppData;
-    MappedSize = _getMapSize(Desc.Format, Desc.Width, 1, 0);
+    MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, 1, 0);
 }
 
 static inline void
@@ -147,8 +217,10 @@ _getMapInfo(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
     D3D10_TEXTURE2D_DESC Desc;
     pResource->GetDesc(&Desc);
 
+    UINT MipLevel = Subresource % _getNumMipLevels(&Desc);
+
     pMappedData = pMappedTex2D->pData;
-    MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pMappedTex2D->RowPitch);
+    MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, Desc.Height, pMappedTex2D->RowPitch);
 }
 
 static inline void
@@ -164,8 +236,10 @@ _getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
     D3D10_TEXTURE3D_DESC Desc;
     pResource->GetDesc(&Desc);
 
+    UINT MipLevel = Subresource;
+
     pMappedData = pMappedTex3D->pData;
-    MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pMappedTex3D->RowPitch, Desc.Depth, pMappedTex3D->DepthPitch);
+    MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, Desc.Height, pMappedTex3D->RowPitch, Desc.Depth, pMappedTex3D->DepthPitch);
 }
 
 
@@ -186,7 +260,7 @@ _getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFla
     }
 
     pMappedData = pLockedRect->pBits;
-    MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch);
+    MappedSize = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch);
 }
 
 
index b7c3e653af5a2b7f1447545216da7436daf70461..35cab97d153a1d511f132f9dfc90fc18b08d8172 100644 (file)
@@ -862,9 +862,9 @@ ID3D10Device.methods += [
     Method(Void, "ClearState", []),
     Method(Void, "Flush", []),
     Method(HRESULT, "CreateBuffer", [(Pointer(Const(D3D10_BUFFER_DESC)), "pDesc"), (Pointer(Const(D3D10_SUBRESOURCE_DATA)), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Buffer)), "ppBuffer")]),
-    Method(HRESULT, "CreateTexture1D", [(Pointer(Const(D3D10_TEXTURE1D_DESC)), "pDesc"), (Pointer(Const(D3D10_SUBRESOURCE_DATA)), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture1D)), "ppTexture1D")]),
-    Method(HRESULT, "CreateTexture2D", [(Pointer(Const(D3D10_TEXTURE2D_DESC)), "pDesc"), (Pointer(Const(D3D10_SUBRESOURCE_DATA)), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture2D)), "ppTexture2D")]),
-    Method(HRESULT, "CreateTexture3D", [(Pointer(Const(D3D10_TEXTURE3D_DESC)), "pDesc"), (Pointer(Const(D3D10_SUBRESOURCE_DATA)), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture3D)), "ppTexture3D")]),
+    Method(HRESULT, "CreateTexture1D", [(Pointer(Const(D3D10_TEXTURE1D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture1D)), "ppTexture1D")]),
+    Method(HRESULT, "CreateTexture2D", [(Pointer(Const(D3D10_TEXTURE2D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture2D)), "ppTexture2D")]),
+    Method(HRESULT, "CreateTexture3D", [(Pointer(Const(D3D10_TEXTURE3D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture3D)), "ppTexture3D")]),
     Method(HRESULT, "CreateShaderResourceView", [(ObjPointer(ID3D10Resource), "pResource"), (Pointer(Const(D3D10_SHADER_RESOURCE_VIEW_DESC)), "pDesc"), Out(Pointer(ObjPointer(ID3D10ShaderResourceView)), "ppSRView")]),
     Method(HRESULT, "CreateRenderTargetView", [(ObjPointer(ID3D10Resource), "pResource"), (Pointer(Const(D3D10_RENDER_TARGET_VIEW_DESC)), "pDesc"), Out(Pointer(ObjPointer(ID3D10RenderTargetView)), "ppRTView")]),
     Method(HRESULT, "CreateDepthStencilView", [(ObjPointer(ID3D10Resource), "pResource"), (Pointer(Const(D3D10_DEPTH_STENCIL_VIEW_DESC)), "pDesc"), Out(Pointer(ObjPointer(ID3D10DepthStencilView)), "ppDepthStencilView")]),