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 _DXGISIZE_HPP_
34 #define _DXGISIZE_HPP_
37 /* We purposedly don't include any D3D header, so that this header can be used
38 * with all D3D versions. */
48 _calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
49 if (Width == 0 || Height == 0 || Depth == 0) {
57 case DXGI_FORMAT_UNKNOWN:
59 case DXGI_FORMAT_R32G32B32A32_TYPELESS:
60 case DXGI_FORMAT_R32G32B32A32_FLOAT:
61 case DXGI_FORMAT_R32G32B32A32_UINT:
62 case DXGI_FORMAT_R32G32B32A32_SINT:
65 case DXGI_FORMAT_R32G32B32_TYPELESS:
66 case DXGI_FORMAT_R32G32B32_FLOAT:
67 case DXGI_FORMAT_R32G32B32_UINT:
68 case DXGI_FORMAT_R32G32B32_SINT:
71 case DXGI_FORMAT_R16G16B16A16_TYPELESS:
72 case DXGI_FORMAT_R16G16B16A16_FLOAT:
73 case DXGI_FORMAT_R16G16B16A16_UNORM:
74 case DXGI_FORMAT_R16G16B16A16_UINT:
75 case DXGI_FORMAT_R16G16B16A16_SNORM:
76 case DXGI_FORMAT_R16G16B16A16_SINT:
77 case DXGI_FORMAT_R32G32_TYPELESS:
78 case DXGI_FORMAT_R32G32_FLOAT:
79 case DXGI_FORMAT_R32G32_UINT:
80 case DXGI_FORMAT_R32G32_SINT:
81 case DXGI_FORMAT_R32G8X24_TYPELESS:
82 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
83 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
84 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
87 case DXGI_FORMAT_R10G10B10A2_TYPELESS:
88 case DXGI_FORMAT_R10G10B10A2_UNORM:
89 case DXGI_FORMAT_R10G10B10A2_UINT:
90 case DXGI_FORMAT_R11G11B10_FLOAT:
91 case DXGI_FORMAT_R8G8B8A8_TYPELESS:
92 case DXGI_FORMAT_R8G8B8A8_UNORM:
93 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
94 case DXGI_FORMAT_R8G8B8A8_UINT:
95 case DXGI_FORMAT_R8G8B8A8_SNORM:
96 case DXGI_FORMAT_R8G8B8A8_SINT:
97 case DXGI_FORMAT_R16G16_TYPELESS:
98 case DXGI_FORMAT_R16G16_FLOAT:
99 case DXGI_FORMAT_R16G16_UNORM:
100 case DXGI_FORMAT_R16G16_UINT:
101 case DXGI_FORMAT_R16G16_SNORM:
102 case DXGI_FORMAT_R16G16_SINT:
103 case DXGI_FORMAT_R32_TYPELESS:
104 case DXGI_FORMAT_D32_FLOAT:
105 case DXGI_FORMAT_R32_FLOAT:
106 case DXGI_FORMAT_R32_UINT:
107 case DXGI_FORMAT_R32_SINT:
108 case DXGI_FORMAT_R24G8_TYPELESS:
109 case DXGI_FORMAT_D24_UNORM_S8_UINT:
110 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
111 case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
112 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
113 case DXGI_FORMAT_B8G8R8A8_UNORM:
114 case DXGI_FORMAT_B8G8R8X8_UNORM:
115 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
116 case DXGI_FORMAT_B8G8R8A8_TYPELESS:
117 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
118 case DXGI_FORMAT_B8G8R8X8_TYPELESS:
119 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
122 case DXGI_FORMAT_R8G8_TYPELESS:
123 case DXGI_FORMAT_R8G8_UNORM:
124 case DXGI_FORMAT_R8G8_UINT:
125 case DXGI_FORMAT_R8G8_SNORM:
126 case DXGI_FORMAT_R8G8_SINT:
127 case DXGI_FORMAT_R16_TYPELESS:
128 case DXGI_FORMAT_R16_FLOAT:
129 case DXGI_FORMAT_D16_UNORM:
130 case DXGI_FORMAT_R16_UNORM:
131 case DXGI_FORMAT_R16_UINT:
132 case DXGI_FORMAT_R16_SNORM:
133 case DXGI_FORMAT_R16_SINT:
134 case DXGI_FORMAT_B5G6R5_UNORM:
135 case DXGI_FORMAT_B5G5R5A1_UNORM:
138 case DXGI_FORMAT_R8_TYPELESS:
139 case DXGI_FORMAT_R8_UNORM:
140 case DXGI_FORMAT_R8_UINT:
141 case DXGI_FORMAT_R8_SNORM:
142 case DXGI_FORMAT_R8_SINT:
143 case DXGI_FORMAT_A8_UNORM:
146 case DXGI_FORMAT_R1_UNORM:
149 case DXGI_FORMAT_R8G8_B8G8_UNORM:
150 case DXGI_FORMAT_G8R8_G8B8_UNORM:
154 case DXGI_FORMAT_BC1_TYPELESS:
155 case DXGI_FORMAT_BC1_UNORM:
156 case DXGI_FORMAT_BC1_UNORM_SRGB:
157 case DXGI_FORMAT_BC4_TYPELESS:
158 case DXGI_FORMAT_BC4_UNORM:
159 case DXGI_FORMAT_BC4_SNORM:
164 case DXGI_FORMAT_BC2_TYPELESS:
165 case DXGI_FORMAT_BC2_UNORM:
166 case DXGI_FORMAT_BC2_UNORM_SRGB:
167 case DXGI_FORMAT_BC3_TYPELESS:
168 case DXGI_FORMAT_BC3_UNORM:
169 case DXGI_FORMAT_BC3_UNORM_SRGB:
170 case DXGI_FORMAT_BC5_TYPELESS:
171 case DXGI_FORMAT_BC5_UNORM:
172 case DXGI_FORMAT_BC5_SNORM:
173 case DXGI_FORMAT_BC6H_TYPELESS:
174 case DXGI_FORMAT_BC6H_UF16:
175 case DXGI_FORMAT_BC6H_SF16:
176 case DXGI_FORMAT_BC7_TYPELESS:
177 case DXGI_FORMAT_BC7_UNORM:
178 case DXGI_FORMAT_BC7_UNORM_SRGB:
184 os::log("apitrace: warning: %s: unknown format 0x%04X\n", __FUNCTION__, Format);
188 Width = (Width + BlockWidth - 1) / BlockWidth;
189 Height = (Height + BlockHeight - 1) / BlockHeight;
191 size_t size = (Width * BlockSize + 7)/ 8;
194 size += (Height - 1) * RowPitch;
198 size += (Depth - 1) * DepthPitch;
205 _calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
206 if (Width == 0 || Height == 0 || Depth == 0) {
210 Width = std::max(Width >> MipLevel, UINT(1));
211 Height = std::max(Height >> MipLevel, UINT(1));
212 Depth = std::max(Depth >> MipLevel, UINT(1));
214 return _calcDataSize(Format, Width, Height, RowPitch, Depth, DepthPitch);
219 _getNumMipLevels(UINT Width, UINT Height = 1, UINT Depth = 1) {
226 } while (Width || Height || Depth);
232 _getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags,
233 void * & pMappedData, size_t & MappedSize) {
237 if (!(MapFlags & DXGI_MAP_WRITE)) {
241 DXGI_SURFACE_DESC Desc;
242 HRESULT hr = pResource->GetDesc(&Desc);
247 pMappedData = pLockedRect->pBits;
248 MappedSize = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch);
252 #endif /* _DXGISIZE_HPP_ */