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 * Information about active sub-resource maps
63 _calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
64 if (Width == 0 || Height == 0 || Depth == 0) {
72 case DXGI_FORMAT_UNKNOWN:
74 case DXGI_FORMAT_R32G32B32A32_TYPELESS:
75 case DXGI_FORMAT_R32G32B32A32_FLOAT:
76 case DXGI_FORMAT_R32G32B32A32_UINT:
77 case DXGI_FORMAT_R32G32B32A32_SINT:
80 case DXGI_FORMAT_R32G32B32_TYPELESS:
81 case DXGI_FORMAT_R32G32B32_FLOAT:
82 case DXGI_FORMAT_R32G32B32_UINT:
83 case DXGI_FORMAT_R32G32B32_SINT:
86 case DXGI_FORMAT_R16G16B16A16_TYPELESS:
87 case DXGI_FORMAT_R16G16B16A16_FLOAT:
88 case DXGI_FORMAT_R16G16B16A16_UNORM:
89 case DXGI_FORMAT_R16G16B16A16_UINT:
90 case DXGI_FORMAT_R16G16B16A16_SNORM:
91 case DXGI_FORMAT_R16G16B16A16_SINT:
92 case DXGI_FORMAT_R32G32_TYPELESS:
93 case DXGI_FORMAT_R32G32_FLOAT:
94 case DXGI_FORMAT_R32G32_UINT:
95 case DXGI_FORMAT_R32G32_SINT:
96 case DXGI_FORMAT_R32G8X24_TYPELESS:
97 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
98 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
99 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
102 case DXGI_FORMAT_R10G10B10A2_TYPELESS:
103 case DXGI_FORMAT_R10G10B10A2_UNORM:
104 case DXGI_FORMAT_R10G10B10A2_UINT:
105 case DXGI_FORMAT_R11G11B10_FLOAT:
106 case DXGI_FORMAT_R8G8B8A8_TYPELESS:
107 case DXGI_FORMAT_R8G8B8A8_UNORM:
108 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
109 case DXGI_FORMAT_R8G8B8A8_UINT:
110 case DXGI_FORMAT_R8G8B8A8_SNORM:
111 case DXGI_FORMAT_R8G8B8A8_SINT:
112 case DXGI_FORMAT_R16G16_TYPELESS:
113 case DXGI_FORMAT_R16G16_FLOAT:
114 case DXGI_FORMAT_R16G16_UNORM:
115 case DXGI_FORMAT_R16G16_UINT:
116 case DXGI_FORMAT_R16G16_SNORM:
117 case DXGI_FORMAT_R16G16_SINT:
118 case DXGI_FORMAT_R32_TYPELESS:
119 case DXGI_FORMAT_D32_FLOAT:
120 case DXGI_FORMAT_R32_FLOAT:
121 case DXGI_FORMAT_R32_UINT:
122 case DXGI_FORMAT_R32_SINT:
123 case DXGI_FORMAT_R24G8_TYPELESS:
124 case DXGI_FORMAT_D24_UNORM_S8_UINT:
125 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
126 case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
127 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
128 case DXGI_FORMAT_B8G8R8A8_UNORM:
129 case DXGI_FORMAT_B8G8R8X8_UNORM:
130 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
131 case DXGI_FORMAT_B8G8R8A8_TYPELESS:
132 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
133 case DXGI_FORMAT_B8G8R8X8_TYPELESS:
134 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
137 case DXGI_FORMAT_R8G8_TYPELESS:
138 case DXGI_FORMAT_R8G8_UNORM:
139 case DXGI_FORMAT_R8G8_UINT:
140 case DXGI_FORMAT_R8G8_SNORM:
141 case DXGI_FORMAT_R8G8_SINT:
142 case DXGI_FORMAT_R16_TYPELESS:
143 case DXGI_FORMAT_R16_FLOAT:
144 case DXGI_FORMAT_D16_UNORM:
145 case DXGI_FORMAT_R16_UNORM:
146 case DXGI_FORMAT_R16_UINT:
147 case DXGI_FORMAT_R16_SNORM:
148 case DXGI_FORMAT_R16_SINT:
149 case DXGI_FORMAT_B5G6R5_UNORM:
150 case DXGI_FORMAT_B5G5R5A1_UNORM:
153 case DXGI_FORMAT_R8_TYPELESS:
154 case DXGI_FORMAT_R8_UNORM:
155 case DXGI_FORMAT_R8_UINT:
156 case DXGI_FORMAT_R8_SNORM:
157 case DXGI_FORMAT_R8_SINT:
158 case DXGI_FORMAT_A8_UNORM:
161 case DXGI_FORMAT_R1_UNORM:
164 case DXGI_FORMAT_R8G8_B8G8_UNORM:
165 case DXGI_FORMAT_G8R8_G8B8_UNORM:
169 case DXGI_FORMAT_BC1_TYPELESS:
170 case DXGI_FORMAT_BC1_UNORM:
171 case DXGI_FORMAT_BC1_UNORM_SRGB:
172 case DXGI_FORMAT_BC4_TYPELESS:
173 case DXGI_FORMAT_BC4_UNORM:
174 case DXGI_FORMAT_BC4_SNORM:
179 case DXGI_FORMAT_BC2_TYPELESS:
180 case DXGI_FORMAT_BC2_UNORM:
181 case DXGI_FORMAT_BC2_UNORM_SRGB:
182 case DXGI_FORMAT_BC3_TYPELESS:
183 case DXGI_FORMAT_BC3_UNORM:
184 case DXGI_FORMAT_BC3_UNORM_SRGB:
185 case DXGI_FORMAT_BC5_TYPELESS:
186 case DXGI_FORMAT_BC5_UNORM:
187 case DXGI_FORMAT_BC5_SNORM:
188 case DXGI_FORMAT_BC6H_TYPELESS:
189 case DXGI_FORMAT_BC6H_UF16:
190 case DXGI_FORMAT_BC6H_SF16:
191 case DXGI_FORMAT_BC7_TYPELESS:
192 case DXGI_FORMAT_BC7_UNORM:
193 case DXGI_FORMAT_BC7_UNORM_SRGB:
199 os::log("apitrace: warning: %s: unknown format 0x%04X\n", __FUNCTION__, Format);
203 Width = (Width + BlockWidth - 1) / BlockWidth;
204 Height = (Height + BlockHeight - 1) / BlockHeight;
206 size_t size = (Width * BlockSize + 7)/ 8;
209 size += (Height - 1) * RowPitch;
213 size += (Depth - 1) * DepthPitch;
220 _calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
221 if (Width == 0 || Height == 0 || Depth == 0) {
225 Width = std::max(Width >> MipLevel, UINT(1));
226 Height = std::max(Height >> MipLevel, UINT(1));
227 Depth = std::max(Depth >> MipLevel, UINT(1));
229 return _calcDataSize(Format, Width, Height, RowPitch, Depth, DepthPitch);
234 _getNumMipLevels(UINT Width, UINT Height = 1, UINT Depth = 1) {
241 } while (Width || Height || Depth);
247 _getMapDesc(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags,
248 _MAP_DESC & MapDesc) {
252 if (!(MapFlags & DXGI_MAP_WRITE)) {
256 DXGI_SURFACE_DESC Desc;
257 HRESULT hr = pResource->GetDesc(&Desc);
262 MapDesc.pData = pLockedRect->pBits;
263 MapDesc.Size = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch);
267 #endif /* _DXGISIZE_HPP_ */