1 /**************************************************************************
3 * Copyright 2012 Jose Fonseca
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 **************************************************************************/
30 * Auxiliary functions to compute the size of array/blob arguments.
33 #ifndef _D3D10SIZE_HPP_
34 #define _D3D10SIZE_HPP_
37 /* We purposedly don't include any D3D header, so that this header can be used
38 * with all D3D versions. */
44 _getMapSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT DepthPitch = 0) {
45 if (Width == 0 || Height == 0 || Depth == 0) {
50 os::log("apitrace: warning: %s: negative row pitch %i\n", __FUNCTION__, RowPitch);
55 os::log("apitrace: warning: %s: negative slice pitch %i\n", __FUNCTION__, DepthPitch);
60 case DXGI_FORMAT_BC1_TYPELESS:
61 case DXGI_FORMAT_BC1_UNORM:
62 case DXGI_FORMAT_BC1_UNORM_SRGB:
63 case DXGI_FORMAT_BC2_TYPELESS:
64 case DXGI_FORMAT_BC2_UNORM:
65 case DXGI_FORMAT_BC2_UNORM_SRGB:
66 case DXGI_FORMAT_BC3_TYPELESS:
67 case DXGI_FORMAT_BC3_UNORM:
68 case DXGI_FORMAT_BC3_UNORM_SRGB:
69 case DXGI_FORMAT_BC4_TYPELESS:
70 case DXGI_FORMAT_BC4_UNORM:
71 case DXGI_FORMAT_BC4_SNORM:
72 case DXGI_FORMAT_BC5_TYPELESS:
73 case DXGI_FORMAT_BC5_UNORM:
74 case DXGI_FORMAT_BC5_SNORM:
75 Width = (Width + 3) / 4;
76 Height = (Height + 3) / 4;
79 case DXGI_FORMAT_R8G8_B8G8_UNORM:
80 case DXGI_FORMAT_G8R8_G8B8_UNORM:
81 Width = (Width + 1) / 2;
84 case DXGI_FORMAT_UNKNOWN:
94 size_t size = Height * RowPitch;
97 size += (Depth - 1) * DepthPitch;
104 _getMapInfo(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * ppData,
105 void * & pMappedData, size_t & MappedSize) {
109 if (MapType == D3D10_MAP_READ) {
113 D3D10_BUFFER_DESC Desc;
114 pResource->GetDesc(&Desc);
116 pMappedData = *ppData;
117 MappedSize = Desc.ByteWidth;
121 _getMapInfo(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, void * * ppData,
122 void * & pMappedData, size_t & MappedSize) {
126 if (MapType == D3D10_MAP_READ) {
130 D3D10_TEXTURE1D_DESC Desc;
131 pResource->GetDesc(&Desc);
133 pMappedData = *ppData;
134 MappedSize = _getMapSize(Desc.Format, Desc.Width, 1, 0);
138 _getMapInfo(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE2D * pMappedTex2D,
139 void * & pMappedData, size_t & MappedSize) {
143 if (MapType == D3D10_MAP_READ) {
147 D3D10_TEXTURE2D_DESC Desc;
148 pResource->GetDesc(&Desc);
150 pMappedData = pMappedTex2D->pData;
151 MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pMappedTex2D->RowPitch);
155 _getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE3D * pMappedTex3D,
156 void * & pMappedData, size_t & MappedSize) {
160 if (MapType == D3D10_MAP_READ) {
164 D3D10_TEXTURE3D_DESC Desc;
165 pResource->GetDesc(&Desc);
167 pMappedData = pMappedTex3D->pData;
168 MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pMappedTex3D->RowPitch, Desc.Depth, pMappedTex3D->DepthPitch);
173 _getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags,
174 void * & pMappedData, size_t & MappedSize) {
178 if (!(MapFlags & DXGI_MAP_WRITE)) {
182 DXGI_SURFACE_DESC Desc;
183 HRESULT hr = pResource->GetDesc(&Desc);
188 pMappedData = pLockedRect->pBits;
189 MappedSize = _getMapSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch);
193 #endif /* _D3D10SIZE_HPP_ */