2 * Utility functions for the WineD3D Library
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006-2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wined3d_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
33 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
37 enum wined3d_format_id id
;
40 format_index_remap
[] =
42 {WINED3DFMT_UYVY
, WINED3D_FORMAT_FOURCC_BASE
},
43 {WINED3DFMT_YUY2
, WINED3D_FORMAT_FOURCC_BASE
+ 1},
44 {WINED3DFMT_YV12
, WINED3D_FORMAT_FOURCC_BASE
+ 2},
45 {WINED3DFMT_DXT1
, WINED3D_FORMAT_FOURCC_BASE
+ 3},
46 {WINED3DFMT_DXT2
, WINED3D_FORMAT_FOURCC_BASE
+ 4},
47 {WINED3DFMT_DXT3
, WINED3D_FORMAT_FOURCC_BASE
+ 5},
48 {WINED3DFMT_DXT4
, WINED3D_FORMAT_FOURCC_BASE
+ 6},
49 {WINED3DFMT_DXT5
, WINED3D_FORMAT_FOURCC_BASE
+ 7},
50 {WINED3DFMT_MULTI2_ARGB8
, WINED3D_FORMAT_FOURCC_BASE
+ 8},
51 {WINED3DFMT_G8R8_G8B8
, WINED3D_FORMAT_FOURCC_BASE
+ 9},
52 {WINED3DFMT_R8G8_B8G8
, WINED3D_FORMAT_FOURCC_BASE
+ 10},
53 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_FOURCC_BASE
+ 11},
54 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_FOURCC_BASE
+ 12},
55 {WINED3DFMT_INST
, WINED3D_FORMAT_FOURCC_BASE
+ 13},
56 {WINED3DFMT_NVDB
, WINED3D_FORMAT_FOURCC_BASE
+ 14},
57 {WINED3DFMT_NVHU
, WINED3D_FORMAT_FOURCC_BASE
+ 15},
58 {WINED3DFMT_NVHS
, WINED3D_FORMAT_FOURCC_BASE
+ 16},
59 {WINED3DFMT_INTZ
, WINED3D_FORMAT_FOURCC_BASE
+ 17},
60 {WINED3DFMT_RESZ
, WINED3D_FORMAT_FOURCC_BASE
+ 18},
61 {WINED3DFMT_NULL
, WINED3D_FORMAT_FOURCC_BASE
+ 19},
62 {WINED3DFMT_R16
, WINED3D_FORMAT_FOURCC_BASE
+ 20},
63 {WINED3DFMT_AL16
, WINED3D_FORMAT_FOURCC_BASE
+ 21},
64 {WINED3DFMT_NV12
, WINED3D_FORMAT_FOURCC_BASE
+ 22},
65 {WINED3DFMT_ATOC
, WINED3D_FORMAT_FOURCC_BASE
+ 23},
68 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
70 struct wined3d_format_channels
72 enum wined3d_format_id id
;
73 DWORD red_size
, green_size
, blue_size
, alpha_size
;
74 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
76 BYTE depth_size
, stencil_size
;
80 static const struct wined3d_format_channels formats
[] =
83 * format id r g b a r g b a bpp z s channels */
84 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
87 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
88 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
89 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
90 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
99 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
100 {WINED3DFMT_R11G11B10_FLOAT
, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0, "FFF"},
101 /* Palettized formats */
102 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
103 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
104 /* Standard ARGB formats. */
105 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0, "uuu"},
106 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0, "uuu"},
107 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0, "uuuX"},
108 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0, "uuuu"},
109 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0, "uuuu"},
110 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0, "uuu"},
111 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0, "u"},
112 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0, "uuuu"},
113 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0, "uuuX"},
114 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0, "uuuX"},
115 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0, "uuuu"},
117 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
118 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
119 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
120 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
121 /* Bump mapping stuff */
122 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
123 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
124 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0, "iii"},
125 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0, "iiiu"},
126 /* Depth stencil formats */
127 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0, "D"},
128 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0, "D"},
129 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1, "SD"},
130 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0, "XD"},
131 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4, "SXD"},
132 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8, "SD"},
133 /* Vendor-specific formats */
134 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
135 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
136 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
137 {WINED3DFMT_ATOC
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
138 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
140 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
141 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
142 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
143 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
144 /* Unsure about them, could not find a Windows driver that supports them */
145 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
146 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
147 /* DirectX 10 HDR formats */
148 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
150 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
151 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
152 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
153 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
154 {WINED3DFMT_R32G8X24_TYPELESS
, 32, 8, 0, 0, 0, 0, 0, 0, 8, 0, 0},
155 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
156 {WINED3DFMT_R10G10B10X2_TYPELESS
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
157 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
158 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
159 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
160 {WINED3DFMT_R24G8_TYPELESS
, 24, 8, 0, 0, 0, 0, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
162 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
163 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
164 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
165 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
172 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
175 struct wined3d_typed_format_info
177 enum wined3d_format_id id
;
178 enum wined3d_format_id typeless_id
;
179 const char *channels
;
183 * The last entry for a given typeless format defines its internal format.
185 * u - WINED3D_CHANNEL_TYPE_UNORM
186 * i - WINED3D_CHANNEL_TYPE_SNORM
187 * U - WINED3D_CHANNEL_TYPE_UINT
188 * I - WINED3D_CHANNEL_TYPE_SINT
189 * F - WINED3D_CHANNEL_TYPE_FLOAT
190 * D - WINED3D_CHANNEL_TYPE_DEPTH
191 * S - WINED3D_CHANNEL_TYPE_STENCIL
192 * X - WINED3D_CHANNEL_TYPE_UNUSED
194 static const struct wined3d_typed_format_info typed_formats
[] =
196 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
197 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
198 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
199 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
200 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
201 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
202 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
203 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
204 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
205 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
206 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
207 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
208 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
209 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
210 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "FXX"},
211 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XUX"},
212 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DSX"},
213 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
214 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
215 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
216 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3DFMT_R10G10B10X2_TYPELESS
, "iiiX"},
217 {WINED3DFMT_R10G10B10X2_UINT
, WINED3DFMT_R10G10B10X2_TYPELESS
, "UUUX"},
218 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
219 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
220 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "iiii"},
221 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
222 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
223 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
224 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
225 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
226 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
227 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
228 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
229 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
230 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
231 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
232 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "uX"},
233 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XU"},
234 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
235 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
236 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
237 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
238 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
239 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
240 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
241 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
242 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
243 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
244 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
245 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
246 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
247 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
248 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
249 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
250 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
251 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
252 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
253 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
254 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
255 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
256 {WINED3DFMT_BC4_SNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
257 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
258 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
259 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
260 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
261 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
262 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
263 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
264 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
265 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
266 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
269 struct wined3d_typeless_format_depth_stencil_info
271 enum wined3d_format_id typeless_id
;
272 enum wined3d_format_id depth_stencil_id
;
273 enum wined3d_format_id depth_view_id
;
274 enum wined3d_format_id stencil_view_id
;
275 BOOL separate_depth_view_format
;
278 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
280 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
281 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
, TRUE
},
282 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
283 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
, TRUE
},
284 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_FLOAT
},
285 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_UNORM
},
288 struct wined3d_format_ddi_info
290 enum wined3d_format_id id
;
291 D3DDDIFORMAT ddi_format
;
294 static const struct wined3d_format_ddi_info ddi_formats
[] =
296 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
297 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
298 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
299 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
300 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
301 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
302 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
303 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
304 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
307 struct wined3d_format_base_flags
309 enum wined3d_format_id id
;
314 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
315 * still needs to use the correct block based calculation for e.g. the
317 static const struct wined3d_format_base_flags format_base_flags
[] =
319 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_ATTR_MAPPABLE
| WINED3D_FORMAT_ATTR_BROKEN_PITCH
},
320 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_ATTR_MAPPABLE
| WINED3D_FORMAT_ATTR_BROKEN_PITCH
},
321 {WINED3DFMT_D16_LOCKABLE
, WINED3D_FORMAT_ATTR_MAPPABLE
},
322 {WINED3DFMT_INTZ
, WINED3D_FORMAT_ATTR_MAPPABLE
},
323 {WINED3DFMT_D32_FLOAT
, WINED3D_FORMAT_ATTR_FLOAT
},
324 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3D_FORMAT_ATTR_FLOAT
},
325 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3D_FORMAT_ATTR_FLOAT
},
326 {WINED3DFMT_INST
, WINED3D_FORMAT_ATTR_EXTENSION
},
327 {WINED3DFMT_NULL
, WINED3D_FORMAT_ATTR_EXTENSION
},
328 {WINED3DFMT_NVDB
, WINED3D_FORMAT_ATTR_EXTENSION
},
329 {WINED3DFMT_ATOC
, WINED3D_FORMAT_ATTR_EXTENSION
},
330 {WINED3DFMT_RESZ
, WINED3D_FORMAT_ATTR_EXTENSION
},
331 {WINED3DFMT_R32G32B32A32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
332 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
333 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
334 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
335 {WINED3DFMT_R16G16B16A16_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
336 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
337 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
338 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
339 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
340 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
341 {WINED3DFMT_R32G32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
342 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
343 {WINED3DFMT_R32G32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
344 {WINED3DFMT_R32G32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
345 {WINED3DFMT_R32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
346 {WINED3DFMT_R32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
347 {WINED3DFMT_R32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
,
348 WINED3D_FORMAT_CAP_INDEX_BUFFER
},
349 {WINED3DFMT_R32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
350 {WINED3DFMT_R16_UINT
, 0,
351 WINED3D_FORMAT_CAP_INDEX_BUFFER
},
352 {WINED3DFMT_R8G8_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
353 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
354 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
355 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
356 {WINED3DFMT_R16G16_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
359 static void rgb888_from_rgb565(WORD rgb565
, BYTE
*r
, BYTE
*g
, BYTE
*b
)
363 /* (2⁸ - 1) / (2⁵ - 1) ≈ 2⁸ / 2⁵ + 2⁸ / 2¹⁰
364 * (2⁸ - 1) / (2⁶ - 1) ≈ 2⁸ / 2⁶ + 2⁸ / 2¹² */
366 *r
= (c
<< 3) + (c
>> 2);
367 c
= (rgb565
>> 5) & 0x3f;
368 *g
= (c
<< 2) + (c
>> 4);
370 *b
= (c
<< 3) + (c
>> 2);
373 static void build_dxtn_colour_table(WORD colour0
, WORD colour1
,
374 DWORD colour_table
[4], enum wined3d_format_id format_id
)
382 rgb888_from_rgb565(colour0
, &c
[0].r
, &c
[0].g
, &c
[0].b
);
383 rgb888_from_rgb565(colour1
, &c
[1].r
, &c
[1].g
, &c
[1].b
);
385 if (format_id
== WINED3DFMT_BC1_UNORM
&& colour0
<= colour1
)
387 c
[2].r
= (c
[0].r
+ c
[1].r
) / 2;
388 c
[2].g
= (c
[0].g
+ c
[1].g
) / 2;
389 c
[2].b
= (c
[0].b
+ c
[1].b
) / 2;
397 for (i
= 0; i
< 2; ++i
)
399 c
[i
+ 2].r
= (2 * c
[i
].r
+ c
[1 - i
].r
) / 3;
400 c
[i
+ 2].g
= (2 * c
[i
].g
+ c
[1 - i
].g
) / 3;
401 c
[i
+ 2].b
= (2 * c
[i
].b
+ c
[1 - i
].b
) / 3;
405 for (i
= 0; i
< 4; ++i
)
407 colour_table
[i
] = (c
[i
].r
<< 16) | (c
[i
].g
<< 8) | c
[i
].b
;
411 static void build_bc3_alpha_table(BYTE alpha0
, BYTE alpha1
, BYTE alpha_table
[8])
415 alpha_table
[0] = alpha0
;
416 alpha_table
[1] = alpha1
;
420 for (i
= 0; i
< 6; ++i
)
422 alpha_table
[2 + i
] = ((6 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 7;
428 for (i
= 0; i
< 4; ++i
)
430 alpha_table
[2 + i
] = ((4 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 5;
432 alpha_table
[6] = 0x00;
433 alpha_table
[7] = 0xff;
437 static void decompress_dxtn_block(const BYTE
*src
, BYTE
*dst
, unsigned int width
,
438 unsigned int height
, unsigned int dst_row_pitch
, enum wined3d_format_id format_id
)
440 const UINT64
*s
= (const UINT64
*)src
;
441 BOOL bc1_alpha
= FALSE
;
442 DWORD colour_table
[4];
451 if (format_id
== WINED3DFMT_BC1_UNORM
)
453 WORD colour0
, colour1
;
457 colour0
= s
[0] & 0xffff;
458 colour1
= (s
[0] >> 16) & 0xffff;
459 colour_bits
= (s
[0] >> 32) & 0xffffffff;
460 build_dxtn_colour_table(colour0
, colour1
, colour_table
, format_id
);
461 if (colour0
<= colour1
)
467 if (format_id
== WINED3DFMT_BC3_UNORM
)
469 build_bc3_alpha_table(alpha_bits
& 0xff, (alpha_bits
>> 8) & 0xff, alpha_table
);
473 colour_bits
= (s
[1] >> 32) & 0xffffffff;
474 build_dxtn_colour_table(s
[1] & 0xffff, (s
[1] >> 16) & 0xffff, colour_table
, format_id
);
477 for (y
= 0; y
< height
; ++y
)
479 dst_row
= (DWORD
*)&dst
[y
* dst_row_pitch
];
480 for (x
= 0; x
< width
; ++x
)
482 colour_idx
= (colour_bits
>> (y
* 8 + x
* 2)) & 0x3;
485 case WINED3DFMT_BC1_UNORM
:
486 alpha
= bc1_alpha
&& colour_idx
== 3 ? 0x00 : 0xff;
489 case WINED3DFMT_BC2_UNORM
:
490 alpha
= (alpha_bits
>> (y
* 16 + x
* 4)) & 0xf;
491 /* (2⁸ - 1) / (2⁴ - 1) ≈ 2⁸ / 2⁴ + 2⁸ / 2⁸ */
495 case WINED3DFMT_BC3_UNORM
:
496 alpha
= alpha_table
[(alpha_bits
>> (y
* 12 + x
* 3)) & 0x7];
503 dst_row
[x
] = (alpha
<< 24) | colour_table
[colour_idx
];
508 static void decompress_dxtn(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
509 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
510 unsigned int width
, unsigned int height
, unsigned int depth
, enum wined3d_format_id format_id
)
512 unsigned int block_byte_count
, block_w
, block_h
;
513 const BYTE
*src_row
, *src_slice
= src
;
514 BYTE
*dst_row
, *dst_slice
= dst
;
515 unsigned int x
, y
, z
;
517 block_byte_count
= format_id
== WINED3DFMT_BC1_UNORM
? 8 : 16;
519 for (z
= 0; z
< depth
; ++z
)
523 for (y
= 0; y
< height
; y
+= 4)
525 for (x
= 0; x
< width
; x
+= 4)
527 block_w
= min(width
- x
, 4);
528 block_h
= min(height
- y
, 4);
529 decompress_dxtn_block(&src_row
[x
* (block_byte_count
/ 4)],
530 &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
, format_id
);
532 src_row
+= src_row_pitch
;
533 dst_row
+= dst_row_pitch
* 4;
535 src_slice
+= src_slice_pitch
;
536 dst_slice
+= dst_slice_pitch
;
540 static void decompress_bc3(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
541 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
542 unsigned int width
, unsigned int height
, unsigned int depth
)
544 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
545 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC3_UNORM
);
548 static void decompress_bc2(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
549 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
550 unsigned int width
, unsigned int height
, unsigned int depth
)
552 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
553 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC2_UNORM
);
556 static void decompress_bc1(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
557 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
558 unsigned int width
, unsigned int height
, unsigned int depth
)
560 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
561 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC1_UNORM
);
564 static void build_rgtc_colour_table(uint8_t red0
, uint8_t red1
, uint8_t colour_table
[8])
568 colour_table
[0] = red0
;
569 colour_table
[1] = red1
;
572 for (i
= 0; i
< 4; ++i
)
574 colour_table
[i
+ 2] = ((8 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 5) / 10;
576 colour_table
[6] = 0x00;
577 colour_table
[7] = 0xff;
581 for (i
= 0; i
< 6; ++i
)
583 colour_table
[i
+ 2] = ((12 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 7) / 14;
588 static void decompress_rgtc_block(const uint8_t *src
, uint8_t *dst
,
589 unsigned int width
, unsigned int height
, unsigned int dst_row_pitch
)
591 const uint64_t *s
= (const uint64_t *)src
;
592 uint8_t red0
, red1
, red_idx
;
593 uint8_t colour_table
[8];
599 red1
= (s
[0] >> 8) & 0xff;
601 build_rgtc_colour_table(red0
, red1
, colour_table
);
603 for (y
= 0; y
< height
; ++y
)
605 dst_row
= (uint32_t *)&dst
[y
* dst_row_pitch
];
606 for (x
= 0; x
< width
; ++x
)
608 red_idx
= (bits
>> (y
* 12 + x
* 3)) & 0x7;
609 /* Decompressing to bgra32 is perhaps not ideal for RGTC formats.
610 * It's convenient though. */
611 dst_row
[x
] = 0xff000000 | (colour_table
[red_idx
] << 16);
616 static void decompress_bc4(const uint8_t *src
, uint8_t *dst
, unsigned int src_row_pitch
,
617 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
618 unsigned int width
, unsigned int height
, unsigned int depth
)
620 unsigned int block_w
, block_h
, x
, y
, z
;
621 const uint8_t *src_row
, *src_slice
;
622 uint8_t *dst_row
, *dst_slice
;
624 for (z
= 0; z
< depth
; ++z
)
626 src_slice
= &src
[z
* src_slice_pitch
];
627 dst_slice
= &dst
[z
* dst_slice_pitch
];
628 for (y
= 0; y
< height
; y
+= 4)
630 src_row
= &src_slice
[(y
/ 4) * src_row_pitch
];
631 dst_row
= &dst_slice
[y
* dst_row_pitch
];
632 for (x
= 0; x
< width
; x
+= 4)
634 block_w
= min(width
- x
, 4);
635 block_h
= min(height
- y
, 4);
636 decompress_rgtc_block(&src_row
[(x
/ 4) * 8], &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
);
642 static const struct wined3d_format_decompress_info
644 enum wined3d_format_id id
;
645 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
646 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
647 unsigned int width
, unsigned int height
, unsigned int depth
);
649 format_decompress_info
[] =
651 {WINED3DFMT_DXT1
, decompress_bc1
},
652 {WINED3DFMT_DXT2
, decompress_bc2
},
653 {WINED3DFMT_DXT3
, decompress_bc2
},
654 {WINED3DFMT_DXT4
, decompress_bc3
},
655 {WINED3DFMT_DXT5
, decompress_bc3
},
656 {WINED3DFMT_BC1_UNORM
, decompress_bc1
},
657 {WINED3DFMT_BC2_UNORM
, decompress_bc2
},
658 {WINED3DFMT_BC3_UNORM
, decompress_bc3
},
659 {WINED3DFMT_BC4_UNORM
, decompress_bc4
},
662 struct wined3d_format_block_info
664 enum wined3d_format_id id
;
667 UINT block_byte_count
;
671 static const struct wined3d_format_block_info format_block_info
[] =
673 {WINED3DFMT_DXT1
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
674 {WINED3DFMT_DXT2
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
675 {WINED3DFMT_DXT3
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
676 {WINED3DFMT_DXT4
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
677 {WINED3DFMT_DXT5
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
678 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
679 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
680 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
681 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
682 {WINED3DFMT_BC4_SNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
683 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
684 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
685 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
686 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
687 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
688 {WINED3DFMT_ATI1N
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
| WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
689 {WINED3DFMT_ATI2N
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
| WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
690 {WINED3DFMT_YUY2
, 2, 1, 4, WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
691 {WINED3DFMT_UYVY
, 2, 1, 4, WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
692 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 1, 1, 4},
695 struct wined3d_format_vertex_info
697 enum wined3d_format_id id
;
698 enum wined3d_ffp_emit_idx emit_idx
;
700 enum wined3d_gl_extension extension
;
703 static const struct wined3d_format_vertex_info format_vertex_info
[] =
705 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, GL_FLOAT
},
706 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, GL_FLOAT
},
707 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, GL_FLOAT
},
708 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, GL_FLOAT
},
709 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, GL_UNSIGNED_BYTE
},
710 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, GL_UNSIGNED_BYTE
},
711 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
712 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, GL_SHORT
},
713 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, GL_SHORT
},
714 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, GL_UNSIGNED_BYTE
},
715 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, GL_SHORT
},
716 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, GL_SHORT
},
717 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, GL_UNSIGNED_SHORT
},
718 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, GL_UNSIGNED_SHORT
},
719 {WINED3DFMT_R11G11B10_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_10F_11F_11F_REV
,
720 ARB_VERTEX_TYPE_10F_11F_11F_REV
},
721 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, GL_UNSIGNED_SHORT
},
722 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, GL_SHORT
},
723 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_2_10_10_10_REV
,
724 ARB_VERTEX_TYPE_2_10_10_10_REV
},
725 /* Without ARB_half_float_vertex we convert these on upload. */
726 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_FLOAT
},
727 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
728 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_FLOAT
},
729 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
730 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
731 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
732 {WINED3DFMT_R8G8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
733 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
734 {WINED3DFMT_R8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
735 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
736 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
737 {WINED3DFMT_R8G8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
738 {WINED3DFMT_R16_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
739 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
740 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_SHORT
},
741 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
742 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
743 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
744 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
745 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
746 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
747 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
750 struct wined3d_format_texture_info
752 enum wined3d_format_id id
;
754 GLint gl_srgb_internal
;
755 GLint gl_rt_internal
;
758 unsigned int conv_byte_count
;
760 enum wined3d_gl_extension extension
;
761 void (*upload
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
762 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
763 unsigned int width
, unsigned int height
, unsigned int depth
);
764 void (*download
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
765 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
766 unsigned int width
, unsigned int height
, unsigned int depth
);
767 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
768 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
769 unsigned int width
, unsigned int height
, unsigned int depth
);
772 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
773 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
775 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
776 * format+type combination to load it. Thus convert it to A8L8, then load it
777 * with A4L4 internal, but A8L8 format+type
779 unsigned int x
, y
, z
;
780 const unsigned char *Source
;
783 for (z
= 0; z
< depth
; z
++)
785 for (y
= 0; y
< height
; y
++)
787 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
788 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
789 for (x
= 0; x
< width
; x
++ )
791 unsigned char color
= (*Source
++);
792 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
793 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
800 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
801 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
803 unsigned int x
, y
, z
;
804 unsigned char r_in
, g_in
, l_in
;
805 const unsigned short *texel_in
;
806 unsigned short *texel_out
;
808 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
809 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
810 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
811 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
812 for (z
= 0; z
< depth
; z
++)
814 for (y
= 0; y
< height
; y
++)
816 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
817 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
818 for (x
= 0; x
< width
; x
++ )
820 l_in
= (*texel_in
& 0xfc00u
) >> 10;
821 g_in
= (*texel_in
& 0x03e0u
) >> 5;
822 r_in
= *texel_in
& 0x001fu
;
824 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
832 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
833 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
835 unsigned int x
, y
, z
;
836 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
837 const unsigned short *texel_in
;
839 for (z
= 0; z
< depth
; z
++)
841 for (y
= 0; y
< height
; y
++)
843 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
844 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
845 for (x
= 0; x
< width
; x
++ )
847 l_in
= (*texel_in
& 0xfc00u
) >> 10;
848 g_in
= (*texel_in
& 0x03e0u
) >> 5;
849 r_in
= *texel_in
& 0x001fu
;
852 if (!(r_in
& 0x10)) /* r > 0 */
856 if (!(g_in
& 0x10)) /* g > 0 */
859 texel_out
[0] = r_out
;
860 texel_out
[1] = g_out
;
861 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
871 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
872 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
874 unsigned int x
, y
, z
;
875 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
876 const unsigned short *texel_in
;
878 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
879 * fixed function and shaders without further conversion once the surface is
882 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
883 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
884 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
885 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
886 for (z
= 0; z
< depth
; z
++)
888 for (y
= 0; y
< height
; y
++)
890 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
891 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
892 for (x
= 0; x
< width
; x
++ )
894 l_in
= (*texel_in
& 0xfc00u
) >> 10;
895 g_in
= (*texel_in
& 0x03e0u
) >> 5;
896 r_in
= *texel_in
& 0x001fu
;
899 if (!(r_in
& 0x10)) /* r > 0 */
903 if (!(g_in
& 0x10)) /* g > 0 */
906 texel_out
[0] = ds_out
;
907 texel_out
[1] = dt_out
;
908 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
917 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
918 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
920 unsigned int x
, y
, z
;
924 for (z
= 0; z
< depth
; z
++)
926 for (y
= 0; y
< height
; y
++)
928 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
929 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
930 for (x
= 0; x
< width
; x
++ )
932 const short color
= (*Source
++);
933 /* B */ Dest
[0] = 0xff;
934 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
935 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
942 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
943 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
945 unsigned int x
, y
, z
;
949 /* Doesn't work correctly with the fixed function pipeline, but can work in
950 * shaders if the shader is adjusted. (There's no use for this format in gl's
951 * standard fixed function pipeline anyway).
953 for (z
= 0; z
< depth
; z
++)
955 for (y
= 0; y
< height
; y
++)
957 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
958 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
959 for (x
= 0; x
< width
; x
++ )
961 LONG color
= (*Source
++);
962 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
963 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
964 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
971 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
972 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
974 unsigned int x
, y
, z
;
978 /* This implementation works with the fixed function pipeline and shaders
979 * without further modification after converting the surface.
981 for (z
= 0; z
< depth
; z
++)
983 for (y
= 0; y
< height
; y
++)
985 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
986 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
987 for (x
= 0; x
< width
; x
++ )
989 LONG color
= (*Source
++);
990 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
991 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
992 /* U */ Dest
[0] = (color
& 0xff); /* U */
993 /* I */ Dest
[3] = 255; /* X */
1000 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1001 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1003 unsigned int x
, y
, z
;
1004 const DWORD
*Source
;
1005 unsigned char *Dest
;
1007 for (z
= 0; z
< depth
; z
++)
1009 for (y
= 0; y
< height
; y
++)
1011 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1012 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
1013 for (x
= 0; x
< width
; x
++ )
1015 LONG color
= (*Source
++);
1016 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
1017 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
1018 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
1019 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
1026 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1027 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1029 unsigned int x
, y
, z
;
1030 const DWORD
*Source
;
1031 unsigned short *Dest
;
1033 for (z
= 0; z
< depth
; z
++)
1035 for (y
= 0; y
< height
; y
++)
1037 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1038 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1039 for (x
= 0; x
< width
; x
++ )
1041 const DWORD color
= (*Source
++);
1042 /* B */ Dest
[0] = 0xffff;
1043 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
1044 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
1051 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1052 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1054 unsigned int x
, y
, z
;
1058 for (z
= 0; z
< depth
; z
++)
1060 for (y
= 0; y
< height
; y
++)
1062 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1063 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1064 for (x
= 0; x
< width
; x
++ )
1066 WORD green
= (*Source
++);
1067 WORD red
= (*Source
++);
1070 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
1071 * shader overwrites it anyway */
1079 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1080 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1082 unsigned int x
, y
, z
;
1083 const float *Source
;
1086 for (z
= 0; z
< depth
; z
++)
1088 for (y
= 0; y
< height
; y
++)
1090 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1091 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1092 for (x
= 0; x
< width
; x
++ )
1094 float green
= (*Source
++);
1095 float red
= (*Source
++);
1105 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1106 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1108 unsigned int x
, y
, z
;
1110 for (z
= 0; z
< depth
; z
++)
1112 for (y
= 0; y
< height
; ++y
)
1114 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1115 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1116 DWORD
*dest_s
= (DWORD
*)dest_f
;
1118 for (x
= 0; x
< width
; ++x
)
1120 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
1121 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
1127 static void x8_d24_unorm_upload(const BYTE
*src
, BYTE
*dst
,
1128 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1129 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1130 unsigned int width
, unsigned int height
, unsigned int depth
)
1132 unsigned int x
, y
, z
;
1134 for (z
= 0; z
< depth
; ++z
)
1136 for (y
= 0; y
< height
; ++y
)
1138 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1139 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1141 for (x
= 0; x
< width
; ++x
)
1143 dest
[x
] = source
[x
] << 8 | ((source
[x
] >> 16) & 0xff);
1149 static void x8_d24_unorm_download(const BYTE
*src
, BYTE
*dst
,
1150 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1151 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1152 unsigned int width
, unsigned int height
, unsigned int depth
)
1154 unsigned int x
, y
, z
;
1156 for (z
= 0; z
< depth
; ++z
)
1158 for (y
= 0; y
< height
; ++y
)
1160 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1161 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1163 for (x
= 0; x
< width
; ++x
)
1165 dest
[x
] = source
[x
] >> 8;
1171 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
1173 /* FIXME: Is this really how color keys are supposed to work? I think it
1174 * makes more sense to compare the individual channels. */
1175 return color
>= color_key
->color_space_low_value
1176 && color
<= color_key
->color_space_high_value
;
1179 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1180 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1181 const struct wined3d_color_key
*color_key
)
1183 const WORD
*src_row
;
1187 for (y
= 0; y
< height
; ++y
)
1189 src_row
= (WORD
*)&src
[src_pitch
* y
];
1190 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1191 for (x
= 0; x
< width
; ++x
)
1193 WORD src_color
= src_row
[x
];
1194 if (!color_in_range(color_key
, src_color
))
1195 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1197 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1202 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1203 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1204 const struct wined3d_color_key
*color_key
)
1206 const WORD
*src_row
;
1210 for (y
= 0; y
< height
; ++y
)
1212 src_row
= (WORD
*)&src
[src_pitch
* y
];
1213 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1214 for (x
= 0; x
< width
; ++x
)
1216 WORD src_color
= src_row
[x
];
1217 if (color_in_range(color_key
, src_color
))
1218 dst_row
[x
] = src_color
& ~0x8000;
1220 dst_row
[x
] = src_color
| 0x8000;
1225 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1226 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1227 const struct wined3d_color_key
*color_key
)
1229 const BYTE
*src_row
;
1233 for (y
= 0; y
< height
; ++y
)
1235 src_row
= &src
[src_pitch
* y
];
1236 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1237 for (x
= 0; x
< width
; ++x
)
1239 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
1240 if (!color_in_range(color_key
, src_color
))
1241 dst_row
[x
] = src_color
| 0xff000000;
1246 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1247 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1248 const struct wined3d_color_key
*color_key
)
1250 const DWORD
*src_row
;
1254 for (y
= 0; y
< height
; ++y
)
1256 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1257 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1258 for (x
= 0; x
< width
; ++x
)
1260 DWORD src_color
= src_row
[x
];
1261 if (color_in_range(color_key
, src_color
))
1262 dst_row
[x
] = src_color
& ~0xff000000;
1264 dst_row
[x
] = src_color
| 0xff000000;
1269 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1270 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1271 const struct wined3d_color_key
*color_key
)
1273 const DWORD
*src_row
;
1277 for (y
= 0; y
< height
; ++y
)
1279 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1280 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1281 for (x
= 0; x
< width
; ++x
)
1283 DWORD src_color
= src_row
[x
];
1284 if (color_in_range(color_key
, src_color
))
1285 src_color
&= ~0xff000000;
1286 dst_row
[x
] = src_color
;
1291 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
1292 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
1294 const struct wined3d_format
*format
= texture
->resource
.format
;
1299 enum wined3d_format_id src_format
;
1300 struct wined3d_color_key_conversion conversion
;
1304 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1305 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1306 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1307 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1308 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1311 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1313 for (i
= 0; i
< ARRAY_SIZE(color_key_info
); ++i
)
1315 if (color_key_info
[i
].src_format
== format
->id
)
1316 return &color_key_info
[i
].conversion
;
1319 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1325 /* We intentionally don't support WINED3DFMT_D32_UNORM. No hardware driver
1326 * supports it, and applications get confused when we do.
1328 * The following formats explicitly don't have WINED3D_FORMAT_CAP_TEXTURE set:
1330 * These are never supported on native.
1331 * WINED3DFMT_B8G8R8_UNORM
1332 * WINED3DFMT_B2G3R3_UNORM
1333 * WINED3DFMT_L4A4_UNORM
1334 * WINED3DFMT_S1_UINT_D15_UNORM
1335 * WINED3DFMT_S4X4_UINT_D24_UNORM
1337 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1338 * Since it is not widely available, don't offer it. Further no Windows driver
1339 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1340 * WINED3DFMT_P8_UINT
1341 * WINED3DFMT_P8_UINT_A8_UNORM
1343 * These formats seem to be similar to the HILO formats in
1344 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1345 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1346 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1347 * refused to support formats which can easily be emulated with pixel shaders,
1348 * so applications have to deal with not having NVHS and NVHU.
1350 * WINED3DFMT_NVHS */
1351 static const struct wined3d_format_texture_info format_texture_info
[] =
1353 /* format id gl_internal gl_srgb_internal gl_rt_internal
1354 gl_format gl_type conv_byte_count
1356 extension upload download */
1357 /* FourCC formats */
1358 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1359 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1360 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1361 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1364 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1365 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1366 WINED3D_FORMAT_CAP_FILTERING
,
1367 ARB_TEXTURE_RG
, NULL
},
1368 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1369 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1370 WINED3D_FORMAT_CAP_FILTERING
,
1371 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1372 {WINED3DFMT_UYVY
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1373 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1374 WINED3D_FORMAT_CAP_FILTERING
,
1375 APPLE_RGB_422
, NULL
},
1376 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1377 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1378 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_FILTERING
,
1379 APPLE_YCBCR_422
, NULL
},
1380 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1381 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1382 WINED3D_FORMAT_CAP_FILTERING
,
1383 ARB_TEXTURE_RG
, NULL
},
1384 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1385 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1386 WINED3D_FORMAT_CAP_FILTERING
,
1387 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1388 {WINED3DFMT_YUY2
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1389 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1390 WINED3D_FORMAT_CAP_FILTERING
,
1391 APPLE_RGB_422
, NULL
},
1392 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1393 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1394 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_FILTERING
,
1395 APPLE_YCBCR_422
, NULL
},
1396 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1397 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1398 WINED3D_FORMAT_CAP_FILTERING
,
1399 ARB_TEXTURE_RG
, NULL
},
1400 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1401 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1402 WINED3D_FORMAT_CAP_FILTERING
,
1403 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1404 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1405 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1406 WINED3D_FORMAT_CAP_FILTERING
,
1407 ARB_TEXTURE_RG
, NULL
},
1408 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1409 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1410 WINED3D_FORMAT_CAP_FILTERING
,
1411 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1412 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1413 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1414 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1415 | WINED3D_FORMAT_CAP_SRGB_READ
,
1416 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1417 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1418 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1419 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1420 | WINED3D_FORMAT_CAP_SRGB_READ
,
1421 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1422 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1423 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1424 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1425 | WINED3D_FORMAT_CAP_SRGB_READ
,
1426 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1427 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1428 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1429 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1430 | WINED3D_FORMAT_CAP_SRGB_READ
,
1431 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1432 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1433 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1434 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1435 | WINED3D_FORMAT_CAP_SRGB_READ
,
1436 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1437 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1438 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1439 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1440 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1441 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1442 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1443 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1444 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1445 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1446 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1447 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1448 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1449 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1450 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1451 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1452 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1453 {WINED3DFMT_BC4_SNORM
, GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_COMPRESSED_SIGNED_RED_RGTC1
, 0,
1454 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1455 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1456 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1457 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1458 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1459 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1460 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1461 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1462 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1463 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1464 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1465 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1466 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1467 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1468 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1469 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1470 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1471 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1472 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1473 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1474 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1475 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1476 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1478 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1479 GL_RED
, GL_FLOAT
, 0,
1480 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1481 ARB_TEXTURE_FLOAT
, NULL
},
1482 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1483 GL_RED
, GL_FLOAT
, 0,
1484 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1485 ARB_TEXTURE_RG
, NULL
},
1486 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1487 GL_RGB
, GL_FLOAT
, 12,
1488 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1489 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1490 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1492 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1493 ARB_TEXTURE_RG
, NULL
},
1494 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1495 GL_RGB
, GL_FLOAT
, 0,
1496 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1497 ARB_TEXTURE_FLOAT
, NULL
},
1498 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1499 GL_RGBA
, GL_FLOAT
, 0,
1500 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1501 ARB_TEXTURE_FLOAT
, NULL
},
1503 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1504 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1505 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1506 ARB_TEXTURE_FLOAT
, NULL
},
1507 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1508 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1509 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1510 ARB_TEXTURE_RG
, NULL
},
1511 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1512 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1513 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1514 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1515 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1516 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1517 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1518 ARB_TEXTURE_RG
, NULL
},
1519 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1520 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1521 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_RENDERTARGET
1522 | WINED3D_FORMAT_CAP_VTF
,
1523 ARB_TEXTURE_FLOAT
, NULL
},
1524 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1525 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1526 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1528 /* Palettized formats */
1529 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1530 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1532 ARB_TEXTURE_RG
, NULL
},
1533 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1534 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1536 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1537 /* Standard ARGB formats */
1538 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1539 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1540 WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1541 WINED3D_GL_EXT_NONE
, NULL
},
1542 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1543 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1544 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1545 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
1546 | WINED3D_FORMAT_CAP_VTF
,
1547 WINED3D_GL_EXT_NONE
, NULL
},
1548 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1549 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1550 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1551 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
,
1552 WINED3D_GL_EXT_NONE
, NULL
},
1553 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_SRGB8_EXT
, GL_RGB8
,
1554 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1555 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1556 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
,
1557 WINED3D_GL_EXT_NONE
, NULL
},
1558 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_SRGB8_EXT
, GL_RGB8
,
1559 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1560 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1561 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
,
1562 ARB_ES2_COMPATIBILITY
, NULL
},
1563 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1564 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1565 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1566 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1567 WINED3D_GL_EXT_NONE
, NULL
},
1568 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1569 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1570 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1571 WINED3D_GL_EXT_NONE
, NULL
},
1572 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1573 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1574 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1575 | WINED3D_FORMAT_CAP_SRGB_READ
,
1576 WINED3D_GL_EXT_NONE
, NULL
},
1577 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1578 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1579 WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1580 WINED3D_GL_EXT_NONE
, NULL
},
1581 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1582 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1583 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1584 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1585 ARB_TEXTURE_RG
, NULL
},
1586 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1587 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1588 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1589 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1590 ARB_TEXTURE_RG
, NULL
},
1591 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1592 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1593 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1594 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1595 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1596 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1597 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1598 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1599 WINED3D_GL_EXT_NONE
, NULL
},
1600 {WINED3DFMT_R10G10B10A2_UINT
, GL_RGB10_A2UI
, GL_RGB10_A2UI
, 0,
1601 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1602 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1603 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1604 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1605 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1606 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1607 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1608 WINED3D_GL_EXT_NONE
, NULL
},
1609 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1610 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1611 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1612 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
1613 | WINED3D_FORMAT_CAP_VTF
,
1614 WINED3D_GL_EXT_NONE
, NULL
},
1615 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1616 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1617 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1618 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1619 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1620 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1621 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1622 EXT_TEXTURE_INTEGER
, NULL
},
1623 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1624 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1625 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1626 WINED3D_GL_EXT_NONE
, NULL
},
1627 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1628 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1629 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1630 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1631 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1632 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1633 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1634 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1635 ARB_TEXTURE_RG
, NULL
},
1636 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1637 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1638 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1639 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1640 WINED3D_GL_EXT_NONE
, NULL
},
1641 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1642 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1643 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1644 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1645 WINED3D_GL_EXT_NONE
, NULL
},
1646 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1647 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1648 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1649 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1650 ARB_TEXTURE_RG
, NULL
},
1651 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1652 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1653 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1654 ARB_TEXTURE_RG
, NULL
},
1655 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1656 GL_RG_INTEGER
, GL_BYTE
, 0,
1657 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1658 ARB_TEXTURE_RG
, NULL
},
1659 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1660 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1661 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1662 EXT_TEXTURE_INTEGER
, NULL
},
1663 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1664 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1665 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1666 EXT_TEXTURE_INTEGER
, NULL
},
1667 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1668 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1669 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1670 ARB_TEXTURE_RG
, NULL
},
1671 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1672 GL_RG_INTEGER
, GL_INT
, 0,
1673 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1674 ARB_TEXTURE_RG
, NULL
},
1675 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1676 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1677 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1678 ARB_TEXTURE_RG
, NULL
},
1679 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1680 GL_RG_INTEGER
, GL_SHORT
, 0,
1681 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1682 ARB_TEXTURE_RG
, NULL
},
1683 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1684 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1685 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1686 ARB_TEXTURE_RG
, NULL
},
1687 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1688 GL_RED_INTEGER
, GL_INT
, 0,
1689 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1690 ARB_TEXTURE_RG
, NULL
},
1691 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1692 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1693 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1694 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1695 ARB_TEXTURE_RG
, NULL
},
1696 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1697 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1698 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1699 ARB_TEXTURE_RG
, NULL
},
1700 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1701 GL_RED_INTEGER
, GL_SHORT
, 0,
1702 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1703 ARB_TEXTURE_RG
, NULL
},
1704 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1705 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1706 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1707 ARB_TEXTURE_RG
, NULL
},
1708 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1709 GL_RED_INTEGER
, GL_BYTE
, 0,
1710 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1711 ARB_TEXTURE_RG
, NULL
},
1713 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1714 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1715 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1716 | WINED3D_FORMAT_CAP_SRGB_READ
,
1717 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1718 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1719 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1720 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1721 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1722 ARB_TEXTURE_RG
, NULL
},
1723 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1724 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1725 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1726 ARB_TEXTURE_RG
, NULL
},
1727 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1728 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1729 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1730 | WINED3D_FORMAT_CAP_SRGB_READ
,
1731 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1732 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1733 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1734 WINED3D_FORMAT_CAP_FILTERING
,
1735 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1736 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1737 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1738 WINED3D_FORMAT_CAP_FILTERING
,
1739 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1740 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1741 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1742 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1743 ARB_TEXTURE_RG
, NULL
},
1744 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1745 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1746 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1747 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1748 /* Bump mapping stuff */
1749 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1750 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1751 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1752 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1753 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1754 GL_DSDT_NV
, GL_BYTE
, 0,
1755 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1756 NV_TEXTURE_SHADER
, NULL
},
1757 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1759 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1760 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1761 EXT_TEXTURE_SNORM
, NULL
},
1762 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1763 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1764 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1765 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1766 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1767 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1768 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1769 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1770 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1771 GL_RGBA
, GL_BYTE
, 4,
1772 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1773 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1774 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1775 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1776 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1777 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1778 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1779 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1780 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1781 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1782 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1783 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1784 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1785 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1786 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1787 GL_RGBA
, GL_BYTE
, 0,
1788 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1789 NV_TEXTURE_SHADER
, NULL
},
1790 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1791 GL_RGBA
, GL_BYTE
, 0,
1792 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1793 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1794 EXT_TEXTURE_SNORM
, NULL
},
1795 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1796 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1797 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1798 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1799 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1800 GL_HILO_NV
, GL_SHORT
, 0,
1801 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1802 NV_TEXTURE_SHADER
, NULL
},
1803 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1805 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1806 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1807 EXT_TEXTURE_SNORM
, NULL
},
1808 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1809 GL_RGBA
, GL_SHORT
, 0,
1810 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1811 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1812 EXT_TEXTURE_SNORM
, NULL
},
1813 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1814 GL_RED
, GL_SHORT
, 0,
1815 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1816 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1817 EXT_TEXTURE_SNORM
, NULL
},
1818 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1820 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1821 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1822 EXT_TEXTURE_SNORM
, NULL
},
1823 /* Depth stencil formats */
1824 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1825 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1826 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1827 WINED3D_GL_EXT_NONE
, NULL
},
1828 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1829 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1830 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1831 ARB_DEPTH_TEXTURE
, NULL
},
1832 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1833 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1834 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1835 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1836 ARB_DEPTH_TEXTURE
, NULL
},
1837 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1838 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1839 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1840 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1841 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1842 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1843 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1844 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1845 WINED3D_GL_EXT_NONE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1846 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1847 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1848 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1849 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1850 ARB_DEPTH_TEXTURE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1851 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1852 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1853 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1854 WINED3D_GL_EXT_NONE
, NULL
},
1855 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1856 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1857 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1858 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1859 ARB_DEPTH_TEXTURE
, NULL
},
1860 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1861 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1862 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1863 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1864 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1865 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1866 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1867 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1868 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1869 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1870 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1871 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1872 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1873 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1874 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1875 EXT_TEXTURE_INTEGER
, NULL
},
1876 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1877 GL_RGBA_INTEGER
, GL_INT
, 0,
1878 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1879 EXT_TEXTURE_INTEGER
, NULL
},
1880 /* Vendor-specific formats */
1881 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1882 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1883 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1884 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1885 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1886 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1887 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1888 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1889 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1890 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1891 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1892 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1893 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1894 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1895 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1896 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1897 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1898 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1899 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1900 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1901 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1902 {WINED3DFMT_NULL
, 0, 0, 0,
1903 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1904 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE
,
1905 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1906 /* DirectX 10 HDR formats */
1907 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, GL_RGB9_E5_EXT
, GL_RGB9_E5_EXT
, 0,
1908 GL_RGB
, GL_UNSIGNED_INT_5_9_9_9_REV_EXT
, 0,
1909 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1910 EXT_TEXTURE_SHARED_EXPONENT
, NULL
},
1913 struct wined3d_format_srgb_info
1915 enum wined3d_format_id srgb_format_id
;
1916 enum wined3d_format_id base_format_id
;
1919 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1921 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1922 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1923 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1924 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1925 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1926 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1927 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1930 static inline int get_format_idx(enum wined3d_format_id format_id
)
1934 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1937 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1939 if (format_index_remap
[i
].id
== format_id
)
1940 return format_index_remap
[i
].idx
;
1946 static struct wined3d_format_gl
*wined3d_format_gl_mutable(struct wined3d_format
*format
)
1948 return CONTAINING_RECORD(format
, struct wined3d_format_gl
, f
);
1951 static struct wined3d_format_vk
*wined3d_format_vk_mutable(struct wined3d_format
*format
)
1953 return CONTAINING_RECORD(format
, struct wined3d_format_vk
, f
);
1956 static struct wined3d_format
*get_format_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1958 return (struct wined3d_format
*)((BYTE
*)adapter
->formats
+ fmt_idx
* adapter
->format_size
);
1961 static struct wined3d_format_gl
*get_format_gl_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1963 return wined3d_format_gl_mutable(get_format_by_idx(adapter
, fmt_idx
));
1966 static struct wined3d_format
*get_format_internal(const struct wined3d_adapter
*adapter
,
1967 enum wined3d_format_id format_id
)
1971 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1973 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1977 return get_format_by_idx(adapter
, fmt_idx
);
1980 static struct wined3d_format_gl
*get_format_gl_internal(const struct wined3d_adapter
*adapter
,
1981 enum wined3d_format_id format_id
)
1983 struct wined3d_format
*format
;
1985 if ((format
= get_format_internal(adapter
, format_id
)))
1986 return wined3d_format_gl_mutable(format
);
1991 static void copy_format(const struct wined3d_adapter
*adapter
,
1992 struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1994 enum wined3d_format_id id
= dst_format
->id
;
1995 memcpy(dst_format
, src_format
, adapter
->format_size
);
1996 dst_format
->id
= id
;
1999 static void format_set_caps(struct wined3d_format
*format
, unsigned int caps
)
2003 for (i
= 0; i
< ARRAY_SIZE(format
->caps
); ++i
)
2004 format
->caps
[i
] |= caps
;
2007 static void format_clear_caps(struct wined3d_format
*format
, unsigned int caps
)
2011 for (i
= 0; i
< ARRAY_SIZE(format
->caps
); ++i
)
2012 format
->caps
[i
] &= ~caps
;
2015 static enum wined3d_channel_type
map_channel_type(char t
)
2020 return WINED3D_CHANNEL_TYPE_UNORM
;
2022 return WINED3D_CHANNEL_TYPE_SNORM
;
2024 return WINED3D_CHANNEL_TYPE_UINT
;
2026 return WINED3D_CHANNEL_TYPE_SINT
;
2028 return WINED3D_CHANNEL_TYPE_FLOAT
;
2030 return WINED3D_CHANNEL_TYPE_DEPTH
;
2032 return WINED3D_CHANNEL_TYPE_STENCIL
;
2034 return WINED3D_CHANNEL_TYPE_UNUSED
;
2036 ERR("Invalid channel type '%c'.\n", t
);
2037 return WINED3D_CHANNEL_TYPE_NONE
;
2041 static void parse_channel_desc(struct wined3d_format
*format
, const char *channel_desc
)
2043 unsigned int component_count
= 0;
2044 unsigned int attrs
= 0;
2047 for (j
= 0; j
< strlen(channel_desc
); ++j
)
2049 enum wined3d_channel_type channel_type
= map_channel_type(channel_desc
[j
]);
2051 if (channel_type
== WINED3D_CHANNEL_TYPE_UNORM
|| channel_type
== WINED3D_CHANNEL_TYPE_SNORM
)
2052 attrs
|= WINED3D_FORMAT_ATTR_NORMALISED
;
2053 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
2054 attrs
|= WINED3D_FORMAT_ATTR_INTEGER
;
2055 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
2056 attrs
|= WINED3D_FORMAT_ATTR_FLOAT
;
2057 if (channel_type
!= WINED3D_CHANNEL_TYPE_UNUSED
)
2060 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
2062 format
->depth_size
= format
->red_size
;
2063 format
->red_size
= format
->red_offset
= 0;
2066 if (channel_type
== WINED3D_CHANNEL_TYPE_STENCIL
&& !format
->stencil_size
)
2068 format
->stencil_size
= format
->green_size
;
2069 format
->green_size
= format
->green_offset
= 0;
2073 format
->attrs
|= attrs
;
2074 format
->component_count
= component_count
;
2077 static BOOL
init_format_base_info(struct wined3d_adapter
*adapter
)
2079 struct wined3d_format
*format
;
2082 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
2084 if (!(format
= get_format_internal(adapter
, formats
[i
].id
)))
2087 format
->id
= formats
[i
].id
;
2088 format
->red_size
= formats
[i
].red_size
;
2089 format
->green_size
= formats
[i
].green_size
;
2090 format
->blue_size
= formats
[i
].blue_size
;
2091 format
->alpha_size
= formats
[i
].alpha_size
;
2092 format
->red_offset
= formats
[i
].red_offset
;
2093 format
->green_offset
= formats
[i
].green_offset
;
2094 format
->blue_offset
= formats
[i
].blue_offset
;
2095 format
->alpha_offset
= formats
[i
].alpha_offset
;
2096 format
->byte_count
= formats
[i
].bpp
;
2097 format
->depth_size
= formats
[i
].depth_size
;
2098 format
->stencil_size
= formats
[i
].stencil_size
;
2099 format
->block_width
= 1;
2100 format
->block_height
= 1;
2101 format
->block_byte_count
= formats
[i
].bpp
;
2103 if (formats
[i
].channels
)
2104 parse_channel_desc(format
, formats
[i
].channels
);
2107 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
2109 struct wined3d_format
*typeless_format
;
2111 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
2114 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
2117 format
->id
= typed_formats
[i
].id
;
2118 format
->red_size
= typeless_format
->red_size
;
2119 format
->green_size
= typeless_format
->green_size
;
2120 format
->blue_size
= typeless_format
->blue_size
;
2121 format
->alpha_size
= typeless_format
->alpha_size
;
2122 format
->red_offset
= typeless_format
->red_offset
;
2123 format
->green_offset
= typeless_format
->green_offset
;
2124 format
->blue_offset
= typeless_format
->blue_offset
;
2125 format
->alpha_offset
= typeless_format
->alpha_offset
;
2126 format
->byte_count
= typeless_format
->byte_count
;
2127 format
->depth_size
= typeless_format
->depth_size
;
2128 format
->stencil_size
= typeless_format
->stencil_size
;
2129 format
->block_width
= typeless_format
->block_width
;
2130 format
->block_height
= typeless_format
->block_height
;
2131 format
->block_byte_count
= typeless_format
->block_byte_count
;
2132 format
->typeless_id
= typeless_format
->id
;
2134 typeless_format
->typeless_id
= typeless_format
->id
;
2136 parse_channel_desc(format
, typed_formats
[i
].channels
);
2139 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
2141 if (!(format
= get_format_internal(adapter
, ddi_formats
[i
].id
)))
2144 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
2147 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
2149 if (!(format
= get_format_internal(adapter
, format_base_flags
[i
].id
)))
2152 format
->attrs
|= format_base_flags
[i
].attrs
;
2153 format_set_caps(format
, format_base_flags
[i
].caps
);
2159 static BOOL
init_format_block_info(struct wined3d_adapter
*adapter
)
2161 struct wined3d_format
*format
;
2164 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
2166 if (!(format
= get_format_internal(adapter
, format_block_info
[i
].id
)))
2169 format
->block_width
= format_block_info
[i
].block_width
;
2170 format
->block_height
= format_block_info
[i
].block_height
;
2171 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
2172 format
->attrs
|= WINED3D_FORMAT_ATTR_BLOCKS
| format_block_info
[i
].attrs
;
2178 /* Most compressed formats are not supported for 3D textures by OpenGL.
2180 * In the case of the S3TC/DXTn formats, NV_texture_compression_vtc provides
2181 * these formats for 3D textures, but unfortunately the block layout is
2182 * different from the one used by Direct3D.
2184 * Since applications either don't check format availability at all before
2185 * using these, or refuse to run without them, we decompress them on upload.
2187 * Affected applications include "Heroes VI", "From Dust", "Halo Online" and
2189 static BOOL
init_format_decompress_info(struct wined3d_adapter
*adapter
)
2191 struct wined3d_format
*format
;
2194 for (i
= 0; i
< ARRAY_SIZE(format_decompress_info
); ++i
)
2196 if (!(format
= get_format_internal(adapter
, format_decompress_info
[i
].id
)))
2199 format
->caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= WINED3D_FORMAT_CAP_DECOMPRESS
;
2200 format
->decompress
= format_decompress_info
[i
].decompress
;
2206 static BOOL
init_srgb_formats(struct wined3d_adapter
*adapter
)
2208 struct wined3d_format
*format
, *srgb_format
;
2211 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
2213 if (!(srgb_format
= get_format_internal(adapter
, format_srgb_info
[i
].srgb_format_id
)))
2215 if (!(format
= get_format_internal(adapter
, format_srgb_info
[i
].base_format_id
)))
2218 copy_format(adapter
, srgb_format
, format
);
2224 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
2228 case WINED3D_GL_RES_TYPE_TEX_1D
:
2229 return GL_TEXTURE_1D
;
2230 case WINED3D_GL_RES_TYPE_TEX_2D
:
2231 return GL_TEXTURE_2D
;
2232 case WINED3D_GL_RES_TYPE_TEX_3D
:
2233 return GL_TEXTURE_3D
;
2234 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2235 return GL_TEXTURE_CUBE_MAP_ARB
;
2236 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2237 return GL_TEXTURE_RECTANGLE_ARB
;
2238 case WINED3D_GL_RES_TYPE_BUFFER
:
2239 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
2240 case WINED3D_GL_RES_TYPE_RB
:
2241 return GL_RENDERBUFFER
;
2242 case WINED3D_GL_RES_TYPE_COUNT
:
2245 ERR("Unexpected GL resource type %u.\n", type
);
2249 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2250 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
2254 case WINED3D_GL_RES_TYPE_TEX_1D
:
2255 case WINED3D_GL_RES_TYPE_TEX_2D
:
2256 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2257 case WINED3D_GL_RES_TYPE_TEX_3D
:
2258 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2259 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
2262 case WINED3D_GL_RES_TYPE_RB
:
2263 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
2266 case WINED3D_GL_RES_TYPE_BUFFER
:
2267 case WINED3D_GL_RES_TYPE_COUNT
:
2272 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2273 const struct wined3d_format_gl
*format_gl
,
2274 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
)
2276 GLenum format
= format_gl
->format
;
2277 GLenum type
= format_gl
->type
;
2280 attach_type
= format_gl
->f
.depth_size
? GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
2283 case WINED3D_GL_RES_TYPE_TEX_1D
:
2284 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2285 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
2286 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
2287 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2288 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2290 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
, *object
, 0);
2291 if (format_gl
->f
.stencil_size
)
2292 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
,
2293 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
, *object
, 0);
2296 case WINED3D_GL_RES_TYPE_TEX_2D
:
2297 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2298 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2299 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
2300 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
2301 format
, type
, NULL
);
2302 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2303 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2305 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2306 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2307 if (format_gl
->f
.stencil_size
)
2308 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2309 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2312 case WINED3D_GL_RES_TYPE_TEX_3D
:
2313 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2314 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
2315 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
2316 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2317 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2319 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_3D
, *object
, 0, 0);
2320 if (format_gl
->f
.stencil_size
)
2321 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
,
2322 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_3D
, *object
, 0, 0);
2325 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2326 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2327 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
2328 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
2329 format
, type
, NULL
);
2330 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
2331 format
, type
, NULL
);
2332 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2333 format
, type
, NULL
);
2334 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2335 format
, type
, NULL
);
2336 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2337 format
, type
, NULL
);
2338 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2339 format
, type
, NULL
);
2340 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2341 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2343 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2344 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2345 if (format_gl
->f
.stencil_size
)
2346 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2347 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2350 case WINED3D_GL_RES_TYPE_RB
:
2351 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2352 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2353 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2354 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
, *object
);
2355 if (format_gl
->f
.stencil_size
)
2356 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2357 GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, *object
);
2360 case WINED3D_GL_RES_TYPE_BUFFER
:
2361 case WINED3D_GL_RES_TYPE_COUNT
:
2365 /* Ideally we'd skip all formats already known not to work on textures
2366 * by checking for WINED3D_FORMAT_CAP_TEXTURE here. However, we want to
2367 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2368 * format never has WINED3D_FORMAT_CAP_TEXTURE set. Instead, swallow GL
2369 * errors generated by invalid formats. */
2370 while (gl_info
->gl_ops
.gl
.p_glGetError());
2373 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2374 const struct wined3d_color
*color
)
2376 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2377 static const struct wined3d_vec3 default_geometry
[] =
2379 {-1.0f
, -1.0f
, 0.0f
},
2380 { 1.0f
, -1.0f
, 0.0f
},
2381 {-1.0f
, 1.0f
, 0.0f
},
2382 { 1.0f
, 1.0f
, 0.0f
},
2384 static const char vs_core_header
[] =
2388 "out vec4 out_color;\n"
2390 static const char vs_legacy_header
[] =
2392 "attribute vec4 pos;\n"
2393 "attribute vec4 color;\n"
2394 "varying vec4 out_color;\n"
2396 static const char vs_body
[] =
2399 " gl_Position = pos;\n"
2400 " out_color = color;\n"
2402 static const char fs_core
[] =
2404 "in vec4 out_color;\n"
2405 "out vec4 fragment_color;\n"
2409 " fragment_color = out_color;\n"
2411 static const char fs_legacy
[] =
2413 "varying vec4 out_color;\n"
2417 " gl_FragData[0] = out_color;\n"
2419 const char *source
[2];
2420 GLuint vs_id
, fs_id
;
2424 geometry
= default_geometry
;
2426 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2427 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2429 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2430 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2431 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2432 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2433 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2435 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2436 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2437 for (i
= 0; i
< 4; ++i
)
2438 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2439 gl_info
->gl_ops
.gl
.p_glEnd();
2440 checkGLcall("draw quad");
2445 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2446 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2447 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2448 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2449 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2450 GL_EXTCALL(glEnableVertexAttribArray(0));
2451 GL_EXTCALL(glDisableVertexAttribArray(1));
2453 if (!ctx
->test_program_id
)
2455 BOOL use_glsl_150
= gl_info
->glsl_version
>= MAKEDWORD_VERSION(1, 50);
2457 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2459 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2460 source
[0] = use_glsl_150
? vs_core_header
: vs_legacy_header
;
2461 source
[1] = vs_body
;
2462 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2463 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2464 GL_EXTCALL(glDeleteShader(vs_id
));
2466 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2467 source
[0] = use_glsl_150
? fs_core
: fs_legacy
;
2468 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2469 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2470 GL_EXTCALL(glDeleteShader(fs_id
));
2472 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2473 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2476 GL_EXTCALL(glBindFragDataLocation(ctx
->test_program_id
, 0, "fragment_color"));
2478 GL_EXTCALL(glCompileShader(vs_id
));
2479 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2480 GL_EXTCALL(glCompileShader(fs_id
));
2481 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2482 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2483 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2485 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2487 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2489 GL_EXTCALL(glUseProgram(0));
2490 GL_EXTCALL(glDisableVertexAttribArray(0));
2491 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2492 checkGLcall("draw quad");
2495 /* Context activation is done by the caller. */
2496 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format_gl
*format
)
2498 /* Check if the default internal format is supported as a frame buffer
2499 * target, otherwise fall back to the render target internal.
2501 * Try to stick to the standard format if possible, this limits precision differences. */
2502 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2503 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2504 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2505 GLenum status
, rt_internal
= format
->rt_internal
;
2506 GLuint object
, color_rb
;
2507 enum wined3d_gl_resource_type type
;
2508 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2510 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2512 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2514 const char *type_string
= "color";
2516 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2519 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->internal
);
2521 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
2523 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2524 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2525 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2526 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2528 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2530 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2531 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2532 checkGLcall("Create and attach color rb attachment");
2533 type_string
= "depth / stencil";
2536 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2537 checkGLcall("Framebuffer format check");
2539 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2541 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2542 debug_d3dformat(format
->f
.id
), type_string
, type
);
2543 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE
;
2544 format
->rt_internal
= format
->internal
;
2545 regular_fmt_used
= TRUE
;
2551 if (format
->f
.caps
[type
] & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
2553 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2554 " and no fallback specified.\n", debug_d3dformat(format
->f
.id
), type
);
2555 format
->f
.caps
[type
] &= ~(WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
);
2559 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2560 debug_d3dformat(format
->f
.id
), type_string
, type
);
2562 format
->rt_internal
= format
->internal
;
2566 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2567 " trying rtInternal format as fallback.\n",
2568 debug_d3dformat(format
->f
.id
), type_string
, type
);
2570 while (gl_info
->gl_ops
.gl
.p_glGetError());
2572 delete_fbo_attachment(gl_info
, type
, object
);
2573 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->rt_internal
);
2575 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2576 checkGLcall("Framebuffer format check");
2578 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2580 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2581 debug_d3dformat(format
->f
.id
), type_string
, type
);
2582 fallback_fmt_used
= TRUE
;
2586 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2587 debug_d3dformat(format
->f
.id
), type_string
, type
);
2588 format
->f
.caps
[type
] &= ~(WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
);
2593 if (status
== GL_FRAMEBUFFER_COMPLETE
2594 && ((format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
)
2595 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2596 && !(format
->f
.attrs
& WINED3D_FORMAT_ATTR_INTEGER
)
2597 && format
->f
.id
!= WINED3DFMT_NULL
&& format
->f
.id
!= WINED3DFMT_P8_UINT
2598 && format
->format
!= GL_LUMINANCE
&& format
->format
!= GL_LUMINANCE_ALPHA
2599 && (format
->f
.red_size
|| format
->f
.alpha_size
))
2601 uint32_t readback
[16 * 16 * 16], color
= 0;
2602 unsigned int r_range
, a_range
;
2607 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2609 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2610 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2611 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2612 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2614 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2615 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2616 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2617 checkGLcall("RB attachment");
2620 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2621 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2622 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2623 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2625 while (gl_info
->gl_ops
.gl
.p_glGetError());
2626 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2627 debug_d3dformat(format
->f
.id
), type
);
2628 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2632 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2633 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2634 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2636 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2637 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2639 draw_test_quad(ctx
, NULL
, &black
);
2641 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2643 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2645 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2649 case WINED3D_GL_RES_TYPE_TEX_1D
:
2650 /* Rebinding texture to workaround a fglrx bug. */
2651 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2652 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2653 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2654 color
= readback
[7];
2657 case WINED3D_GL_RES_TYPE_TEX_2D
:
2658 case WINED3D_GL_RES_TYPE_TEX_3D
:
2659 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2660 /* Rebinding texture to workaround a fglrx bug. */
2661 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2662 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2663 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2664 color
= readback
[7 * 16 + 7];
2667 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2668 /* Rebinding texture to workaround a fglrx bug. */
2669 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2670 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2671 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2672 color
= readback
[7 * 16 + 7];
2675 case WINED3D_GL_RES_TYPE_RB
:
2676 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2677 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2678 color
= readback
[7 * 16 + 7];
2681 case WINED3D_GL_RES_TYPE_BUFFER
:
2682 case WINED3D_GL_RES_TYPE_COUNT
:
2686 checkGLcall("Post-pixelshader blending check");
2689 r
= (color
& 0x00ff0000u
) >> 16;
2691 r_range
= format
->f
.red_size
< 8 ? 1u << (8 - format
->f
.red_size
) : 1;
2692 a_range
= format
->f
.alpha_size
< 8 ? 1u << (8 - format
->f
.alpha_size
) : 1;
2693 if (format
->f
.red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2695 else if (format
->f
.alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2699 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2700 debug_d3dformat(format
->f
.id
), type
);
2701 TRACE("Color output: %#x\n", color
);
2702 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2706 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2707 debug_d3dformat(format
->f
.id
), type
);
2708 TRACE("Color output: %#x\n", color
);
2709 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2713 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2715 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2716 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2717 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2718 checkGLcall("RB cleanup");
2722 if (format
->internal
!= format
->srgb_internal
)
2724 delete_fbo_attachment(gl_info
, type
, object
);
2725 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->srgb_internal
);
2727 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2728 checkGLcall("Framebuffer format check");
2730 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2732 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2733 debug_d3dformat(format
->f
.id
), type
);
2734 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2735 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2736 format
->internal
= format
->srgb_internal
;
2740 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2741 debug_d3dformat(format
->f
.id
), type
);
2742 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
2745 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2746 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2748 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
2750 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2751 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2754 delete_fbo_attachment(gl_info
, type
, object
);
2755 checkGLcall("Framebuffer format check cleanup");
2758 if (fallback_fmt_used
&& regular_fmt_used
)
2760 FIXME("Format %s needs different render target formats for different resource types.\n",
2761 debug_d3dformat(format
->f
.id
));
2762 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
2763 | WINED3D_FORMAT_CAP_FBO_ATTACHABLE
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
2764 | WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
);
2768 static void query_format_cap(struct wined3d_gl_info
*gl_info
, struct wined3d_format_gl
*format
,
2769 GLint internal
, GLenum pname
, unsigned int cap
, const char *string
)
2772 enum wined3d_gl_resource_type type
;
2774 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2776 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2777 if (value
== GL_FULL_SUPPORT
)
2779 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2780 format
->f
.caps
[type
] |= cap
;
2784 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2785 format
->f
.caps
[type
] &= ~cap
;
2790 /* Context activation is done by the caller. */
2791 static void init_format_fbo_compat_info(const struct wined3d_adapter
*adapter
,
2792 struct wined3d_caps_gl_ctx
*ctx
)
2794 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2795 unsigned int i
, type
;
2798 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2800 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2802 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2803 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2804 GLenum rt_internal
= format
->rt_internal
;
2807 if (!format
->internal
)
2810 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2812 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2813 format
->internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2814 if (value
== GL_FULL_SUPPORT
)
2816 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2817 debug_d3dformat(format
->f
.id
), type
);
2818 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE
;
2819 format
->rt_internal
= format
->internal
;
2820 regular_fmt_used
= TRUE
;
2822 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2823 format
->internal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2824 if (value
== GL_FULL_SUPPORT
)
2826 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2827 debug_d3dformat(format
->f
.id
), type
);
2828 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2832 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2833 debug_d3dformat(format
->f
.id
), type
);
2834 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2841 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_RENDERTARGET
)
2843 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2844 " and no fallback specified, resource type %u.\n",
2845 debug_d3dformat(format
->f
.id
), type
);
2846 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_RENDERTARGET
;
2849 TRACE("Format %s is not supported as FBO color attachment,"
2850 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2851 format
->rt_internal
= format
->internal
;
2855 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2856 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2857 if (value
== GL_FULL_SUPPORT
)
2859 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2860 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2861 fallback_fmt_used
= TRUE
;
2865 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2866 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2867 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_RENDERTARGET
;
2872 if (format
->internal
!= format
->srgb_internal
)
2874 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2875 format
->srgb_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2876 if (value
== GL_FULL_SUPPORT
)
2878 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2879 debug_d3dformat(format
->f
.id
), type
);
2880 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2881 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2882 format
->internal
= format
->srgb_internal
;
2886 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2887 debug_d3dformat(format
->f
.id
), type
);
2888 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
2891 else if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_FBO_ATTACHABLE
)
2892 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2895 if (fallback_fmt_used
&& regular_fmt_used
)
2897 FIXME("Format %s needs different render target formats for different resource types.\n",
2898 debug_d3dformat(format
->f
.id
));
2899 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE
2900 | WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
);
2906 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2908 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2909 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2910 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2911 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2914 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2916 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2918 if (!format
->internal
)
2921 if (format
->f
.attrs
& WINED3D_FORMAT_ATTR_COMPRESSED
)
2923 TRACE("Skipping format %s because it's a compressed format.\n",
2924 debug_d3dformat(format
->f
.id
));
2928 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2930 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->f
.id
));
2931 check_fbo_compat(ctx
, format
);
2935 format
->rt_internal
= format
->internal
;
2939 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2940 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2943 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2947 GLenum internal_format
;
2953 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2954 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2955 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2957 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2958 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2959 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2961 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2962 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2963 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2964 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2965 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2966 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2967 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2968 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2970 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2971 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2972 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2973 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2974 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2976 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2977 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2978 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2979 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2980 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2981 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2982 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2983 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2984 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2985 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2986 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2987 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2988 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2989 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2990 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2991 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2992 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2994 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2995 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2996 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2997 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2998 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
3000 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
3001 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
3002 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
3003 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
3004 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
3005 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
3006 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
3007 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
3008 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
3010 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
3011 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
3012 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
3013 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
3016 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3017 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3019 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3020 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3023 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3024 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3026 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3027 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3030 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3031 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3033 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3034 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3036 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3037 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3039 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3040 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3045 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
3047 if (view_classes
[i
].internal_format
== internal_format
)
3048 return view_classes
[i
].view_class
;
3054 static void query_view_class(struct wined3d_format_gl
*format
)
3056 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
3058 internal_view_class
= lookup_gl_view_class(format
->internal
);
3059 gamma_view_class
= lookup_gl_view_class(format
->srgb_internal
);
3060 rt_view_class
= lookup_gl_view_class(format
->rt_internal
);
3062 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
3064 format
->view_class
= internal_view_class
;
3065 TRACE("Format %s is member of GL view class %#x.\n",
3066 debug_d3dformat(format
->f
.id
), format
->view_class
);
3070 format
->view_class
= GL_NONE
;
3074 static void query_internal_format(struct wined3d_adapter
*adapter
,
3075 struct wined3d_format_gl
*format
, const struct wined3d_format_texture_info
*texture_info
,
3076 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
3078 GLint count
, multisample_types
[8];
3079 unsigned int i
, max_log2
;
3082 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3084 query_format_cap(gl_info
, format
, format
->internal
, GL_VERTEX_TEXTURE
,
3085 WINED3D_FORMAT_CAP_VTF
, "vertex texture usage");
3086 query_format_cap(gl_info
, format
, format
->internal
, GL_FILTER
,
3087 WINED3D_FORMAT_CAP_FILTERING
, "filtering");
3088 query_format_cap(gl_info
, format
, format
->internal
, GL_SHADER_IMAGE_STORE
,
3089 WINED3D_FORMAT_CAP_UNORDERED_ACCESS
, "unordered access");
3091 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3093 query_format_cap(gl_info
, format
, format
->srgb_internal
, GL_SRGB_READ
,
3094 WINED3D_FORMAT_CAP_SRGB_READ
, "sRGB read");
3096 if (srgb_write_supported
)
3097 query_format_cap(gl_info
, format
, format
->srgb_internal
, GL_SRGB_WRITE
,
3098 WINED3D_FORMAT_CAP_SRGB_WRITE
, "sRGB write");
3100 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
3102 if (!(format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
]
3103 & (WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
)))
3104 format
->srgb_internal
= format
->internal
;
3105 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3106 format
->internal
= format
->srgb_internal
;
3111 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
3112 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_VTF
);
3114 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
3115 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3116 else if (format
->f
.id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->f
.id
!= WINED3DFMT_R32_FLOAT
)
3117 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_VTF
);
3119 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3121 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
3122 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
3124 format
->srgb_internal
= format
->internal
;
3125 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3127 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3129 format
->internal
= format
->srgb_internal
;
3133 if ((format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3D_FORMAT_CAP_SRGB_WRITE
) && !srgb_write_supported
)
3134 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
3137 if ((!gl_info
->supported
[ARB_DEPTH_TEXTURE
] || wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3138 && (format
->f
.depth_size
|| format
->f
.stencil_size
))
3140 TRACE("Disabling texturing support for depth / stencil format %s.\n", debug_d3dformat(format
->f
.id
));
3141 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3142 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3143 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3144 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3145 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3148 query_view_class(format
);
3150 if (format
->internal
&& format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
]
3151 & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
3152 && (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
] || gl_info
->supported
[EXT_FRAMEBUFFER_MULTISAMPLE
])
3153 && wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
3155 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
3157 target
= gl_info
->supported
[ARB_TEXTURE_MULTISAMPLE
] ? GL_TEXTURE_2D_MULTISAMPLE
: GL_RENDERBUFFER
;
3159 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3160 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
3161 if (count
> ARRAY_SIZE(multisample_types
))
3162 FIXME("Unexpectedly high number of multisample types %d.\n", count
);
3163 count
= min(count
, ARRAY_SIZE(multisample_types
));
3164 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3165 GL_SAMPLES
, count
, multisample_types
));
3166 checkGLcall("query sample counts");
3167 for (i
= 0; i
< count
; ++i
)
3169 if (multisample_types
[i
] > sizeof(format
->f
.multisample_types
) * CHAR_BIT
)
3171 format
->f
.multisample_types
|= 1u << (multisample_types
[i
] - 1);
3176 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
3177 sizeof(format
->f
.multisample_types
) * CHAR_BIT
));
3178 for (i
= 1; i
<= max_log2
; ++i
)
3179 format
->f
.multisample_types
|= 1u << ((1u << i
) - 1);
3184 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3186 struct wined3d_format_gl
*format
, *srgb_format
;
3187 struct fragment_caps fragment_caps
;
3188 struct shader_caps shader_caps
;
3192 adapter
->fragment_pipe
->get_caps(adapter
, &fragment_caps
);
3193 adapter
->shader_backend
->shader_get_caps(adapter
, &shader_caps
);
3194 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
3195 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
3197 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
3199 if (!(format
= get_format_gl_internal(adapter
, format_texture_info
[i
].id
)))
3202 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
3205 /* ARB_texture_rg defines floating point formats, but only if
3206 * ARB_texture_float is also supported. */
3207 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
3208 && (format
->f
.attrs
& WINED3D_FORMAT_ATTR_FLOAT
))
3211 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
3212 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
3213 && (format
->f
.attrs
& WINED3D_FORMAT_ATTR_INTEGER
))
3216 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3217 && (format
->f
.id
== WINED3DFMT_D16_LOCKABLE
|| format
->f
.id
== WINED3DFMT_NULL
))
3220 format
->internal
= format_texture_info
[i
].gl_internal
;
3221 format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3222 format
->rt_internal
= format_texture_info
[i
].gl_rt_internal
;
3223 format
->format
= format_texture_info
[i
].gl_format
;
3224 format
->type
= format_texture_info
[i
].gl_type
;
3225 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
3226 format
->f
.height_scale
.numerator
= 1;
3227 format
->f
.height_scale
.denominator
= 1;
3229 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3230 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3231 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3233 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
3234 * problematic", but doesn't explicitly mandate that an error is generated. */
3235 if (gl_info
->supported
[EXT_TEXTURE3D
] && !(format_texture_info
[i
].caps
& WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
3236 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3238 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
3239 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3241 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
3242 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3244 format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3245 format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3247 if (format
->srgb_internal
!= format
->internal
3248 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3250 format
->srgb_internal
= format
->internal
;
3251 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3254 if (!gl_info
->supported
[ARB_SHADOW
] && (format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3D_FORMAT_CAP_SHADOW
))
3255 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3257 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
3259 /* Texture conversion stuff */
3260 format
->f
.conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
3261 format
->f
.upload
= format_texture_info
[i
].upload
;
3262 format
->f
.download
= format_texture_info
[i
].download
;
3265 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
3267 if (format_srgb_info
[j
].base_format_id
== format
->f
.id
)
3269 if (!(srgb_format
= get_format_gl_internal(adapter
, format_srgb_info
[j
].srgb_format_id
)))
3277 copy_format(adapter
, &srgb_format
->f
, &format
->f
);
3279 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
3280 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3282 srgb_format
->internal
= format_texture_info
[i
].gl_srgb_internal
;
3283 srgb_format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3284 format_set_caps(&srgb_format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3285 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
3292 static BOOL
compare_uint(unsigned int x
, unsigned int y
, unsigned int max_diff
)
3294 unsigned int diff
= x
> y
? x
- y
: y
- x
;
3296 return diff
<= max_diff
;
3299 static BOOL
compare_colour(DWORD c1
, DWORD c2
, BYTE max_diff
)
3301 return compare_uint(c1
& 0xff, c2
& 0xff, max_diff
)
3302 && compare_uint((c1
>> 8) & 0xff, (c2
>> 8) & 0xff, max_diff
)
3303 && compare_uint((c1
>> 16) & 0xff, (c2
>> 16) & 0xff, max_diff
)
3304 && compare_uint((c1
>> 24) & 0xff, (c2
>> 24) & 0xff, max_diff
);
3307 /* A context is provided by the caller */
3308 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
3310 static const DWORD data
[] = {0x00000000, 0xffffffff};
3311 GLuint tex
, fbo
, buffer
;
3312 uint32_t readback
[16 * 1];
3315 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3316 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3317 * falling back to software. If this changes in the future this code will get fooled and
3318 * apps might hit the software path due to incorrectly advertised caps.
3320 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3321 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3322 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3325 while (gl_info
->gl_ops
.gl
.p_glGetError());
3327 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
3328 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3329 memset(readback
, 0x7e, sizeof(readback
));
3330 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
3331 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
3332 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
3333 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
3334 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3335 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3336 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3338 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
3339 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
3340 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
3341 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
3342 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
3343 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
3344 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3345 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3346 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3347 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
3349 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3350 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3351 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
3352 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
3354 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
3355 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
3356 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
3357 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3358 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
3359 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3361 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
3362 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3364 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3365 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3366 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3367 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3368 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3369 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3370 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3371 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3372 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3373 gl_info
->gl_ops
.gl
.p_glEnd();
3375 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3376 memset(readback
, 0x7f, sizeof(readback
));
3377 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3378 if (compare_colour(readback
[6], 0xffffffff, 5) || compare_colour(readback
[6], 0x00000000, 5)
3379 || compare_colour(readback
[9], 0xffffffff, 5) || compare_colour(readback
[9], 0x00000000, 5))
3381 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3382 readback
[6], readback
[9]);
3387 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3388 readback
[6], readback
[9]);
3392 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3393 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3394 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3395 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3396 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3398 if (gl_info
->gl_ops
.gl
.p_glGetError())
3400 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3407 static void init_format_filter_info(struct wined3d_adapter
*adapter
,
3408 struct wined3d_gl_info
*gl_info
)
3410 enum wined3d_pci_vendor vendor
= adapter
->driver_info
.vendor
;
3411 struct wined3d_format_gl
*format
;
3413 static const enum wined3d_format_id fmts16
[] =
3415 WINED3DFMT_R16_FLOAT
,
3416 WINED3DFMT_R16G16_FLOAT
,
3417 WINED3DFMT_R16G16B16A16_FLOAT
,
3421 /* This was already handled by init_format_texture_info(). */
3422 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3425 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3426 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3428 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3430 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3433 else if (gl_info
->limits
.glsl_varyings
> 44)
3435 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3440 TRACE("Assuming no float16 blending\n");
3446 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3448 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3449 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3455 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3457 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3458 if (!format
->internal
)
3459 continue; /* Not supported by GL */
3461 filtered
= check_filter(gl_info
, format
->internal
);
3464 TRACE("Format %s supports filtering.\n", debug_d3dformat(format
->f
.id
));
3465 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3469 TRACE("Format %s does not support filtering.\n", debug_d3dformat(format
->f
.id
));
3474 static enum fixup_channel_source
fixup_source_from_char(char c
)
3480 return CHANNEL_SOURCE_ZERO
;
3482 return CHANNEL_SOURCE_ONE
;
3485 return CHANNEL_SOURCE_X
;
3488 return CHANNEL_SOURCE_Y
;
3491 return CHANNEL_SOURCE_Z
;
3494 return CHANNEL_SOURCE_W
;
3498 static unsigned int fixup_sign_from_char(char c
)
3500 if (c
== 'x' || c
== 'y' || c
== 'z' || c
== 'w')
3505 static struct color_fixup_desc
create_color_fixup_desc_from_string(const char *s
)
3507 struct color_fixup_desc fixup
;
3511 ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s
));
3512 return COLOR_FIXUP_IDENTITY
;
3515 fixup
.x_sign_fixup
= fixup_sign_from_char(s
[0]);
3516 fixup
.x_source
= fixup_source_from_char(s
[0]);
3517 fixup
.y_sign_fixup
= fixup_sign_from_char(s
[1]);
3518 fixup
.y_source
= fixup_source_from_char(s
[1]);
3519 fixup
.z_sign_fixup
= fixup_sign_from_char(s
[2]);
3520 fixup
.z_source
= fixup_source_from_char(s
[2]);
3521 fixup
.w_sign_fixup
= fixup_sign_from_char(s
[3]);
3522 fixup
.w_source
= fixup_source_from_char(s
[3]);
3527 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3529 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
3530 struct wined3d_format_gl
*format
;
3531 BOOL use_legacy_fixups
;
3536 enum wined3d_format_id id
;
3539 enum wined3d_gl_extension extension
;
3543 {WINED3DFMT_R16_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3544 {WINED3DFMT_R32_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3545 {WINED3DFMT_R16G16_UNORM
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3546 {WINED3DFMT_R16G16_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3547 {WINED3DFMT_R32G32_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3549 {WINED3DFMT_R8G8_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3550 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3551 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3553 {WINED3DFMT_R16G16_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3554 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3555 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3557 {WINED3DFMT_R8G8B8A8_SNORM
, "xyzw", FALSE
, WINED3D_GL_EXT_NONE
},
3558 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3559 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3561 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "xzY1", FALSE
, WINED3D_GL_EXT_NONE
},
3562 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3563 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3565 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "xyZW", FALSE
, WINED3D_GL_EXT_NONE
},
3566 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3568 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3569 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3571 {WINED3DFMT_ATI2N
, "XW11", FALSE
, ATI_TEXTURE_COMPRESSION_3DC
},
3572 {WINED3DFMT_ATI2N
, "YX11", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3573 {WINED3DFMT_ATI2N
, "YX11", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3575 {WINED3DFMT_A8_UNORM
, "000X", FALSE
, WINED3D_GL_EXT_NONE
},
3576 {WINED3DFMT_A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3578 {WINED3DFMT_L8A8_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3579 {WINED3DFMT_L8A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3581 {WINED3DFMT_L4A4_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3582 {WINED3DFMT_L4A4_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3584 {WINED3DFMT_L16_UNORM
, "XXX1", FALSE
, WINED3D_GL_EXT_NONE
},
3585 {WINED3DFMT_L16_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3587 {WINED3DFMT_INTZ
, "XXXX", FALSE
, WINED3D_GL_EXT_NONE
},
3588 {WINED3DFMT_INTZ
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3590 {WINED3DFMT_L8_UNORM
, "XXX1", FALSE
, ARB_TEXTURE_RG
},
3593 use_legacy_fixups
= d3d_info
->wined3d_creation_flags
& WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
;
3594 for (i
= 0; i
< ARRAY_SIZE(fixups
); ++i
)
3596 if (fixups
[i
].legacy
&& !use_legacy_fixups
)
3599 if (!gl_info
->supported
[fixups
[i
].extension
])
3602 format
= get_format_gl_internal(adapter
, fixups
[i
].id
);
3603 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixups
[i
].fixup
);
3606 if (!gl_info
->supported
[APPLE_YCBCR_422
] && !gl_info
->supported
[APPLE_RGB_422
]
3607 && (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3608 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
])))
3610 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3611 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3613 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3614 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3616 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && gl_info
->supported
[APPLE_RGB_422
])
3618 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3619 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3621 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3622 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3624 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && (!gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3625 && (!gl_info
->supported
[ARB_FRAGMENT_SHADER
] || !gl_info
->supported
[ARB_VERTEX_SHADER
])))
3627 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3628 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3629 format
->internal
= 0;
3631 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3632 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3633 format
->internal
= 0;
3636 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3637 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
]))
3639 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3640 format
->f
.attrs
|= WINED3D_FORMAT_ATTR_HEIGHT_SCALE
;
3641 format
->f
.height_scale
.numerator
= 3;
3642 format
->f
.height_scale
.denominator
= 2;
3643 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3645 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3646 format
->f
.attrs
|= WINED3D_FORMAT_ATTR_HEIGHT_SCALE
;
3647 format
->f
.height_scale
.numerator
= 3;
3648 format
->f
.height_scale
.denominator
= 2;
3649 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3653 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3654 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3655 format
->internal
= 0;
3657 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3658 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3659 format
->internal
= 0;
3662 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
] || gl_info
->supported
[ARB_FRAGMENT_SHADER
])
3664 format
= get_format_gl_internal(adapter
, WINED3DFMT_P8_UINT
);
3665 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3668 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3670 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16_FLOAT
);
3671 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3673 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16_FLOAT
);
3674 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3676 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_FLOAT
);
3677 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3680 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3682 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_UNORM
);
3683 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3686 /* ATI instancing hack: Although ATI cards do not support Shader Model
3687 * 3.0, they support instancing. To query if the card supports instancing
3688 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3689 * is used. Should an application check for this, provide a proper return
3690 * value. We can do instancing with all shader versions, but we need
3693 * Additionally applications have to set the D3DRS_POINTSIZE render state
3694 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3695 * doesn't need that and just ignores it.
3697 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3698 /* FIXME: This should just check the shader backend caps. */
3699 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3701 format
= get_format_gl_internal(adapter
, WINED3DFMT_INST
);
3702 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3705 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3706 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3707 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3708 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3709 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3711 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3713 format
= get_format_gl_internal(adapter
, WINED3DFMT_NVDB
);
3714 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3717 if (gl_info
->supported
[ARB_MULTISAMPLE
])
3719 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATOC
);
3720 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3723 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3724 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3725 * RENDERTARGET usage. */
3726 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3728 format
= get_format_gl_internal(adapter
, WINED3DFMT_RESZ
);
3729 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
);
3732 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3734 format
= get_format_gl_by_idx(adapter
, i
);
3736 if (!(format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3D_FORMAT_CAP_TEXTURE
))
3739 if (is_identity_fixup(format
->f
.color_fixup
))
3742 TRACE("Checking support for fixup:\n");
3743 dump_color_fixup_desc(format
->f
.color_fixup
);
3744 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->f
.color_fixup
)
3745 || !adapter
->fragment_pipe
->color_fixup_supported(format
->f
.color_fixup
))
3747 TRACE("[FAILED]\n");
3748 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3756 /* These formats are not supported for 3D textures. See also
3757 * WINED3D_FORMAT_CAP_DECOMPRESS. */
3758 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI1N
);
3759 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3760 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI2N
);
3761 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3762 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC4_SNORM
);
3763 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3764 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_UNORM
);
3765 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3766 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_SNORM
);
3767 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3770 static BOOL
init_format_vertex_info(const struct wined3d_adapter
*adapter
,
3771 struct wined3d_gl_info
*gl_info
)
3773 struct wined3d_format_gl
*format
;
3776 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3778 if (!(format
= get_format_gl_internal(adapter
, format_vertex_info
[i
].id
)))
3781 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3784 format
->f
.emit_idx
= format_vertex_info
[i
].emit_idx
;
3785 format
->vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3786 format
->vtx_format
= format
->f
.component_count
;
3787 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE
;
3790 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3792 format
= get_format_gl_internal(adapter
, WINED3DFMT_B8G8R8A8_UNORM
);
3793 format
->vtx_format
= GL_BGRA
;
3799 static BOOL
init_typeless_formats(const struct wined3d_adapter
*adapter
)
3801 unsigned int caps
[WINED3D_GL_RES_TYPE_COUNT
];
3802 unsigned int attrs
, i
, j
;
3804 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3806 struct wined3d_format
*format
, *typeless_format
;
3808 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
3810 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
3813 attrs
= typeless_format
->attrs
;
3814 memcpy(caps
, typeless_format
->caps
, sizeof(caps
));
3815 copy_format(adapter
, typeless_format
, format
);
3816 typeless_format
->attrs
|= attrs
;
3817 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->caps
); ++j
)
3818 typeless_format
->caps
[j
] |= caps
[j
];
3821 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3823 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3824 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3825 enum wined3d_format_id format_id
;
3827 if (!(typeless_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3829 if (!(ds_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3832 typeless_ds_format
= get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
3833 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3834 copy_format(adapter
, typeless_ds_format
, ds_format
);
3835 typeless_ds_format
->attrs
= typeless_format
->attrs
;
3836 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->caps
); ++j
)
3838 typeless_ds_format
->caps
[j
] = typeless_format
->caps
[j
];
3839 typeless_format
->caps
[j
] &= ~WINED3D_FORMAT_CAP_DEPTH_STENCIL
;
3842 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
)
3843 && typeless_depth_stencil_formats
[i
].separate_depth_view_format
)
3845 if (!(depth_view_format
= get_format_internal(adapter
, format_id
)))
3847 copy_format(adapter
, depth_view_format
, ds_format
);
3848 depth_view_format
->red_size
= depth_view_format
->depth_size
;
3849 depth_view_format
->depth_size
= 0;
3850 depth_view_format
->stencil_size
= 0;
3852 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3854 if (!(stencil_view_format
= get_format_internal(adapter
, format_id
)))
3856 copy_format(adapter
, stencil_view_format
, ds_format
);
3857 stencil_view_format
->green_size
= stencil_view_format
->stencil_size
;
3858 stencil_view_format
->depth_size
= 0;
3859 stencil_view_format
->stencil_size
= 0;
3866 static void init_format_gen_mipmap_info(const struct wined3d_adapter
*adapter
,
3867 struct wined3d_gl_info
*gl_info
)
3871 if (!gl_info
->fbo_ops
.glGenerateMipmap
)
3874 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3876 struct wined3d_format
*format
= get_format_by_idx(adapter
, i
);
3878 for (j
= 0; j
< ARRAY_SIZE(format
->caps
); ++j
)
3879 if (!(~format
->caps
[j
] & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FILTERING
)))
3880 format
->caps
[j
] |= WINED3D_FORMAT_CAP_GEN_MIPMAP
;
3884 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3886 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3887 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3888 static const float offset
= -63.0f
/ 128.0f
;
3889 GLuint texture
, fbo
;
3890 uint32_t readback
[4];
3893 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3894 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3895 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3896 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3897 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3898 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3899 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3900 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3901 GL_TEXTURE_2D
, texture
, 0);
3902 checkGLcall("create resources");
3904 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3905 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3906 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3907 draw_test_quad(ctx
, NULL
, &red
);
3908 checkGLcall("draw");
3910 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3911 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3912 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3913 checkGLcall("readback");
3915 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3916 readback
[0], readback
[1], readback
[2], readback
[3]);
3918 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3919 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3920 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3921 checkGLcall("delete resources");
3923 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3925 if (readback
[i
] != 0xffff0000)
3931 bool wined3d_caps_gl_ctx_test_filling_convention(struct wined3d_caps_gl_ctx
*ctx
, float offset
)
3933 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3934 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3935 unsigned int x
, y
, clear
= 0, draw
= 0;
3936 GLuint texture
, fbo
;
3937 uint32_t readback
[8][8];
3939 /* This is a very simple test to find out how GL handles polygon edges:
3940 * Draw a 1x1 quad exactly through 4 adjacent pixel centers in an 8x8
3941 * viewport and see which pixel it ends up in. So far we've seen top left
3942 * and bottom left conventions. This test may produce unexpected results
3943 * if the driver forces multisampling on us.
3945 * If we find a bottom-left filling behavior we also move the x-axis
3946 * by the same amount. This is necessary to keep diagonals that go
3947 * through the pixel center intact.
3949 * Note that we are ignoring some settings that might influence the
3950 * driver: How we switch GL to an upper-left coordinate system,
3951 * shaders vs fixed function GL. Testing these isn't possible with
3952 * the current draw_test_quad() infrastructure. Also the test is
3953 * skipped if we are not using FBOs. Drawing into the onscreen
3954 * frame buffer may also yield different driver behavior.
3956 * The minimum offset also depends on the viewport size, although
3957 * the relation between those two is GPU dependent and not exactly
3958 * sensible. E.g. a 8192x8192 viewport on a GeForce 9 needs at
3959 * least an offset of 1/240.9, whereas a 8x8 one needs 1/255.982;
3960 * 32x32 needs 1/255.935. 4x4 and lower are happy with something
3961 * below 1/256. The 8x8 size below has been arbitrarily chosen to
3962 * get a useful result out of that card and avoid allocating a
3963 * gigantic texture during library init.
3965 * Newer cards usually do the right thing anyway. In cases where
3966 * they do not (e.g. Radeon GPUs in a macbookpro14,3 running MacOS)
3967 * an offset of 1/2^20 is enough. */
3968 const struct wined3d_vec3 edge_geometry
[] =
3970 {(-1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3971 {( 1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3972 {(-1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3973 {( 1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3976 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3977 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3978 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3979 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 8, 8, 0,
3980 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3981 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3982 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3983 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3984 GL_TEXTURE_2D
, texture
, 0);
3985 checkGLcall("create resources");
3987 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 8, 8);
3988 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 1.0f
, 1.0f
);
3989 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3991 draw_test_quad(ctx
, edge_geometry
, &red
);
3992 checkGLcall("draw");
3994 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3995 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3996 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3997 checkGLcall("readback");
3999 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
4000 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
4001 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
4002 checkGLcall("delete resources");
4004 /* We expect that exactly one fragment is generated. */
4005 for (y
= 0; y
< ARRAY_SIZE(readback
); ++y
)
4007 for (x
= 0; x
< ARRAY_SIZE(readback
[0]); ++x
)
4009 if (readback
[y
][x
] == 0xff0000ff)
4011 else if (readback
[y
][x
] == 0xffff0000)
4016 if (clear
!= 63 || draw
!= 1)
4018 FIXME("Unexpected filling convention test result.\n");
4022 /* One pixel was drawn, check if it is the expected one */
4023 return readback
[3][3] == 0xffff0000;
4025 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
4027 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
4028 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
4029 GLuint fbo
, color
, depth
;
4030 unsigned int low
= 0, high
= 32, cur
;
4031 uint32_t readback
[256];
4032 static const struct wined3d_vec3 geometry
[] =
4034 {-1.0f
, -1.0f
, -1.0f
},
4035 { 1.0f
, -1.0f
, 0.0f
},
4036 {-1.0f
, 1.0f
, -1.0f
},
4037 { 1.0f
, 1.0f
, 0.0f
},
4040 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
4041 * Nvidia. Use this as a fallback if the detection fails. */
4042 unsigned int fallback
= 23;
4044 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
4046 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
4047 return (float)(1u << fallback
);
4050 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
4051 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4052 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
4053 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 256, 1, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0);
4055 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
4056 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
4057 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
4059 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
4060 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
4061 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
4062 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
4063 checkGLcall("Setup framebuffer");
4065 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
4066 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
4067 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
4068 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
4069 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
4070 checkGLcall("Misc parameters");
4074 if (high
- low
<= 1)
4076 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
4080 cur
= (low
+ high
) / 2;
4082 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
4083 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
4084 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
4085 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
4086 draw_test_quad(ctx
, geometry
, &blue
);
4087 checkGLcall("Test draw");
4089 /* Rebinding texture to workaround a fglrx bug. */
4090 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4091 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
4092 checkGLcall("readback");
4094 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
4095 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
4097 if ((readback
[125] & 0xff) < 0xa0)
4099 else if ((readback
[131] & 0xff) > 0xa0)
4103 TRACE("Found scale factor 2^%u for format %x.\n", cur
, format
);
4108 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
4109 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
4110 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
4111 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
4112 checkGLcall("Delete framebuffer");
4114 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
4115 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
4116 return (float)(1u << cur
);
4119 static void init_format_depth_bias_scale(struct wined3d_adapter
*adapter
,
4120 struct wined3d_caps_gl_ctx
*ctx
)
4122 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
4125 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4127 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
4129 if (format
->f
.depth_size
&& (format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
4131 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format
->f
.id
));
4132 format
->f
.depth_bias_scale
= wined3d_adapter_find_polyoffset_scale(ctx
, format
->internal
);
4134 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_NORMALIZED_DEPTH_BIAS
))
4136 /* The single-precision binary floating-point format has
4137 * a significand precision of 24 bits.
4139 if (format
->f
.attrs
& WINED3D_FORMAT_ATTR_FLOAT
)
4140 format
->f
.depth_bias_scale
/= 1u << 24;
4142 format
->f
.depth_bias_scale
/= 1u << format
->f
.depth_size
;
4148 static BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, size_t format_size
)
4150 unsigned int count
= WINED3D_FORMAT_COUNT
+ ARRAY_SIZE(typeless_depth_stencil_formats
);
4152 if (!(adapter
->formats
= heap_calloc(count
, format_size
)))
4154 ERR("Failed to allocate memory.\n");
4157 adapter
->format_size
= format_size
;
4159 if (!init_format_base_info(adapter
))
4161 if (!init_format_block_info(adapter
))
4163 if (!init_format_decompress_info(adapter
))
4165 if (!init_srgb_formats(adapter
))
4171 heap_free(adapter
->formats
);
4172 adapter
->formats
= NULL
;
4176 BOOL
wined3d_adapter_no3d_init_format_info(struct wined3d_adapter
*adapter
)
4178 struct wined3d_format
*format
;
4181 static const enum wined3d_format_id blit_formats
[] =
4183 WINED3DFMT_B8G8R8A8_UNORM
,
4184 WINED3DFMT_B8G8R8X8_UNORM
,
4185 WINED3DFMT_B5G6R5_UNORM
,
4186 WINED3DFMT_B5G5R5X1_UNORM
,
4187 WINED3DFMT_B5G5R5A1_UNORM
,
4188 WINED3DFMT_B4G4R4A4_UNORM
,
4189 WINED3DFMT_B2G3R3_UNORM
,
4190 WINED3DFMT_A8_UNORM
,
4191 WINED3DFMT_B2G3R3A8_UNORM
,
4192 WINED3DFMT_B4G4R4X4_UNORM
,
4193 WINED3DFMT_R10G10B10A2_UNORM
,
4194 WINED3DFMT_R8G8B8A8_UNORM
,
4195 WINED3DFMT_R8G8B8X8_UNORM
,
4196 WINED3DFMT_R16G16_UNORM
,
4197 WINED3DFMT_B10G10R10A2_UNORM
,
4198 WINED3DFMT_R16G16B16A16_UNORM
,
4202 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format
)))
4205 for (i
= 0; i
< ARRAY_SIZE(blit_formats
); ++i
)
4207 if (!(format
= get_format_internal(adapter
, blit_formats
[i
])))
4210 format
->caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= WINED3D_FORMAT_CAP_BLIT
;
4211 format
->caps
[WINED3D_GL_RES_TYPE_RB
] |= WINED3D_FORMAT_CAP_BLIT
;
4217 /* Context activation is done by the caller. */
4218 BOOL
wined3d_adapter_gl_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
4220 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
4222 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format_gl
)))
4225 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
4226 if (!init_format_vertex_info(adapter
, gl_info
)) goto fail
;
4228 apply_format_fixups(adapter
, gl_info
);
4229 init_format_fbo_compat_info(adapter
, ctx
);
4230 init_format_filter_info(adapter
, gl_info
);
4231 init_format_gen_mipmap_info(adapter
, gl_info
);
4232 init_format_depth_bias_scale(adapter
, ctx
);
4234 if (!init_typeless_formats(adapter
)) goto fail
;
4239 heap_free(adapter
->formats
);
4240 adapter
->formats
= NULL
;
4244 static void init_vulkan_format_info(struct wined3d_format_vk
*format
,
4245 const struct wined3d_vk_info
*vk_info
, VkPhysicalDevice vk_physical_device
)
4249 enum wined3d_format_id id
;
4255 {WINED3DFMT_R32G32B32A32_FLOAT
, VK_FORMAT_R32G32B32A32_SFLOAT
, },
4256 {WINED3DFMT_R32G32B32A32_UINT
, VK_FORMAT_R32G32B32A32_UINT
, },
4257 {WINED3DFMT_R32G32B32A32_SINT
, VK_FORMAT_R32G32B32A32_SINT
, },
4258 {WINED3DFMT_R32G32B32_FLOAT
, VK_FORMAT_R32G32B32_SFLOAT
, },
4259 {WINED3DFMT_R32G32B32_UINT
, VK_FORMAT_R32G32B32_UINT
, },
4260 {WINED3DFMT_R32G32B32_SINT
, VK_FORMAT_R32G32B32_SINT
, },
4261 {WINED3DFMT_R16G16B16A16_FLOAT
, VK_FORMAT_R16G16B16A16_SFLOAT
, },
4262 {WINED3DFMT_R16G16B16A16_UNORM
, VK_FORMAT_R16G16B16A16_UNORM
, },
4263 {WINED3DFMT_R16G16B16A16_UINT
, VK_FORMAT_R16G16B16A16_UINT
, },
4264 {WINED3DFMT_R16G16B16A16_SNORM
, VK_FORMAT_R16G16B16A16_SNORM
, },
4265 {WINED3DFMT_R16G16B16A16_SINT
, VK_FORMAT_R16G16B16A16_SINT
, },
4266 {WINED3DFMT_R32G32_FLOAT
, VK_FORMAT_R32G32_SFLOAT
, },
4267 {WINED3DFMT_R32G32_UINT
, VK_FORMAT_R32G32_UINT
, },
4268 {WINED3DFMT_R32G32_SINT
, VK_FORMAT_R32G32_SINT
, },
4269 {WINED3DFMT_R10G10B10A2_UNORM
, VK_FORMAT_A2B10G10R10_UNORM_PACK32
,},
4270 {WINED3DFMT_R11G11B10_FLOAT
, VK_FORMAT_B10G11R11_UFLOAT_PACK32
, },
4271 {WINED3DFMT_R8G8_UNORM
, VK_FORMAT_R8G8_UNORM
, },
4272 {WINED3DFMT_R8G8_UINT
, VK_FORMAT_R8G8_UINT
, },
4273 {WINED3DFMT_R8G8_SNORM
, VK_FORMAT_R8G8_SNORM
, },
4274 {WINED3DFMT_R8G8_SINT
, VK_FORMAT_R8G8_SINT
, },
4275 {WINED3DFMT_R8G8B8A8_UNORM
, VK_FORMAT_R8G8B8A8_UNORM
, },
4276 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, VK_FORMAT_R8G8B8A8_SRGB
, },
4277 {WINED3DFMT_R8G8B8A8_UINT
, VK_FORMAT_R8G8B8A8_UINT
, },
4278 {WINED3DFMT_R8G8B8A8_SNORM
, VK_FORMAT_R8G8B8A8_SNORM
, },
4279 {WINED3DFMT_R8G8B8A8_SINT
, VK_FORMAT_R8G8B8A8_SINT
, },
4280 {WINED3DFMT_R16G16_FLOAT
, VK_FORMAT_R16G16_SFLOAT
, },
4281 {WINED3DFMT_R16G16_UNORM
, VK_FORMAT_R16G16_UNORM
, },
4282 {WINED3DFMT_R16G16_UINT
, VK_FORMAT_R16G16_UINT
, },
4283 {WINED3DFMT_R16G16_SNORM
, VK_FORMAT_R16G16_SNORM
, },
4284 {WINED3DFMT_R16G16_SINT
, VK_FORMAT_R16G16_SINT
, },
4285 {WINED3DFMT_D32_FLOAT
, VK_FORMAT_D32_SFLOAT
, },
4286 {WINED3DFMT_R32_FLOAT
, VK_FORMAT_R32_SFLOAT
, },
4287 {WINED3DFMT_R32_UINT
, VK_FORMAT_R32_UINT
, },
4288 {WINED3DFMT_R32_SINT
, VK_FORMAT_R32_SINT
, },
4289 {WINED3DFMT_R16_FLOAT
, VK_FORMAT_R16_SFLOAT
, },
4290 {WINED3DFMT_D16_UNORM
, VK_FORMAT_D16_UNORM
, },
4291 {WINED3DFMT_R16_UNORM
, VK_FORMAT_R16_UNORM
, },
4292 {WINED3DFMT_R16_UINT
, VK_FORMAT_R16_UINT
, },
4293 {WINED3DFMT_R16_SNORM
, VK_FORMAT_R16_SNORM
, },
4294 {WINED3DFMT_R16_SINT
, VK_FORMAT_R16_SINT
, },
4295 {WINED3DFMT_R8_UNORM
, VK_FORMAT_R8_UNORM
, },
4296 {WINED3DFMT_R8_UINT
, VK_FORMAT_R8_UINT
, },
4297 {WINED3DFMT_R8_SNORM
, VK_FORMAT_R8_SNORM
, },
4298 {WINED3DFMT_R8_SINT
, VK_FORMAT_R8_SINT
, },
4299 {WINED3DFMT_A8_UNORM
, VK_FORMAT_R8_UNORM
, "000X"},
4300 {WINED3DFMT_B8G8R8A8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, },
4301 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, },
4302 {WINED3DFMT_B8G8R8X8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, "XYZ1"},
4303 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, "XYZ1"},
4304 {WINED3DFMT_B5G6R5_UNORM
, VK_FORMAT_R5G6B5_UNORM_PACK16
, },
4305 {WINED3DFMT_BC1_UNORM
, VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, },
4306 {WINED3DFMT_BC1_UNORM_SRGB
, VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, },
4307 {WINED3DFMT_BC2_UNORM
, VK_FORMAT_BC2_UNORM_BLOCK
, },
4308 {WINED3DFMT_BC2_UNORM_SRGB
, VK_FORMAT_BC2_SRGB_BLOCK
, },
4309 {WINED3DFMT_BC3_UNORM
, VK_FORMAT_BC3_UNORM_BLOCK
, },
4310 {WINED3DFMT_BC3_UNORM_SRGB
, VK_FORMAT_BC3_SRGB_BLOCK
, },
4311 {WINED3DFMT_BC4_UNORM
, VK_FORMAT_BC4_UNORM_BLOCK
, },
4312 {WINED3DFMT_BC4_SNORM
, VK_FORMAT_BC4_SNORM_BLOCK
, },
4313 {WINED3DFMT_BC5_UNORM
, VK_FORMAT_BC5_UNORM_BLOCK
, },
4314 {WINED3DFMT_BC5_SNORM
, VK_FORMAT_BC5_SNORM_BLOCK
, },
4315 {WINED3DFMT_BC6H_UF16
, VK_FORMAT_BC6H_UFLOAT_BLOCK
, },
4316 {WINED3DFMT_BC6H_SF16
, VK_FORMAT_BC6H_SFLOAT_BLOCK
, },
4317 {WINED3DFMT_BC7_UNORM
, VK_FORMAT_BC7_UNORM_BLOCK
, },
4318 {WINED3DFMT_BC7_UNORM_SRGB
, VK_FORMAT_BC7_SRGB_BLOCK
, },
4319 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, },
4320 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4321 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4322 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4323 {WINED3DFMT_D24_UNORM_S8_UINT
, VK_FORMAT_D24_UNORM_S8_UINT
, },
4325 VkFormat vk_format
= VK_FORMAT_UNDEFINED
;
4326 VkImageFormatProperties image_properties
;
4327 VkFormatFeatureFlags texture_flags
;
4328 VkFormatProperties properties
;
4329 VkImageUsageFlags vk_usage
;
4336 for (i
= 0; i
< ARRAY_SIZE(vulkan_formats
); ++i
)
4338 if (vulkan_formats
[i
].id
== format
->f
.id
)
4340 vk_format
= vulkan_formats
[i
].vk_format
;
4341 fixup
= vulkan_formats
[i
].fixup
;
4347 WARN("Unsupported format %s.\n", debug_d3dformat(format
->f
.id
));
4351 format
->vk_format
= vk_format
;
4353 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixup
);
4355 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
4357 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4358 if (vk_format
== VK_FORMAT_D24_UNORM_S8_UINT
)
4360 if (~properties
.optimalTilingFeatures
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4362 /* AMD doesn't support VK_FORMAT_D24_UNORM_S8_UINT. */
4363 WARN("Mapping VK_FORMAT_D24_UNORM_S8_UINT to VK_FORMAT_D32_SFLOAT_S8_UINT.\n");
4365 format
->vk_format
= vk_format
= VK_FORMAT_D32_SFLOAT_S8_UINT
;
4366 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4370 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
)
4371 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE
;
4372 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
)
4373 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_TEXTURE
;
4376 texture_flags
= properties
.linearTilingFeatures
| properties
.optimalTilingFeatures
;
4377 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)
4379 caps
|= WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_VTF
;
4381 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4383 caps
|= WINED3D_FORMAT_CAP_RENDERTARGET
;
4385 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
)
4387 caps
|= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
4389 if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4391 caps
|= WINED3D_FORMAT_CAP_DEPTH_STENCIL
;
4393 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
)
4395 caps
|= WINED3D_FORMAT_CAP_FILTERING
;
4397 if (texture_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)
4399 caps
|= WINED3D_FORMAT_CAP_UNORDERED_ACCESS
;
4401 if ((texture_flags
& VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
)
4402 && (texture_flags
& VK_FORMAT_FEATURE_TRANSFER_DST_BIT
))
4404 caps
|= WINED3D_FORMAT_CAP_BLIT
;
4407 if (!(~caps
& (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FILTERING
)))
4408 caps
|= WINED3D_FORMAT_CAP_GEN_MIPMAP
;
4410 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] |= caps
;
4411 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= caps
;
4412 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= caps
;
4413 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= caps
;
4416 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4417 vk_usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
4418 else if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4419 vk_usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
4422 if ((vr
= VK_CALL(vkGetPhysicalDeviceImageFormatProperties(vk_physical_device
, vk_format
,
4423 VK_IMAGE_TYPE_2D
, VK_IMAGE_TILING_OPTIMAL
, vk_usage
, 0, &image_properties
))) < 0)
4425 ERR("Failed to get image format properties, vr %s.\n", wined3d_debug_vkresult(vr
));
4429 mask
= image_properties
.sampleCounts
& 0x3f;
4432 i
= (1u << wined3d_bit_scan(&mask
)) - 1;
4433 format
->f
.multisample_types
|= 1u << i
;
4438 BOOL
wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk
*adapter_vk
,
4439 const struct wined3d_vk_info
*vk_info
)
4441 VkPhysicalDevice vk_physical_device
= adapter_vk
->physical_device
;
4442 struct wined3d_adapter
*adapter
= &adapter_vk
->a
;
4443 struct wined3d_format_vk
*format
;
4446 if (!wined3d_adapter_init_format_info(adapter
, sizeof(*format
)))
4449 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4451 format
= wined3d_format_vk_mutable(get_format_by_idx(adapter
, i
));
4454 init_vulkan_format_info(format
, vk_info
, vk_physical_device
);
4457 if (!init_typeless_formats(adapter
)) goto fail
;
4462 heap_free(adapter
->formats
);
4463 adapter
->formats
= NULL
;
4467 const struct wined3d_format
*wined3d_get_format(const struct wined3d_adapter
*adapter
,
4468 enum wined3d_format_id format_id
, unsigned int bind_flags
)
4470 const struct wined3d_format
*format
;
4471 int idx
= get_format_idx(format_id
);
4476 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
4477 debug_d3dformat(format_id
), format_id
);
4478 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4481 format
= get_format_by_idx(adapter
, idx
);
4483 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
&& wined3d_format_is_typeless(format
))
4485 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4487 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
4488 return get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
4491 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
4492 debug_d3dformat(format_id
), format_id
);
4493 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4499 enum wined3d_format_id
wined3d_get_typed_format_id(const struct wined3d_adapter
*adapter
,
4500 const struct wined3d_format
*format
, enum wined3d_channel_type channel_type
)
4502 const struct wined3d_typed_format_info
*info
;
4505 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
4507 info
= &typed_formats
[i
];
4508 if (info
->typeless_id
== format
->typeless_id
&& map_channel_type(info
->channels
[0]) == channel_type
)
4512 return WINED3DFMT_UNKNOWN
;
4515 BOOL
wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id
,
4516 enum wined3d_format_id view_format_id
)
4520 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4522 if (typeless_depth_stencil_formats
[i
].typeless_id
== resource_format_id
)
4523 return typeless_depth_stencil_formats
[i
].depth_view_id
== view_format_id
;
4528 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
4529 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
4531 /* For block based formats, pitch means the amount of bytes to the next
4532 * row of blocks rather than the next row of pixels. */
4533 if (format
->attrs
& WINED3D_FORMAT_ATTR_BLOCKS
)
4535 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
4536 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
4537 *row_pitch
= row_block_count
* format
->block_byte_count
;
4538 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4539 *slice_pitch
= *row_pitch
* slice_block_count
;
4543 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
4544 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4545 *slice_pitch
= *row_pitch
* height
;
4548 if (format
->attrs
& WINED3D_FORMAT_ATTR_HEIGHT_SCALE
)
4550 /* The D3D format requirements make sure that the resulting format is an integer again */
4551 *slice_pitch
*= format
->height_scale
.numerator
;
4552 *slice_pitch
/= format
->height_scale
.denominator
;
4555 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
4558 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
4559 UINT width
, UINT height
, UINT depth
)
4561 unsigned int row_pitch
, slice_pitch
;
4563 if (format
->id
== WINED3DFMT_UNKNOWN
)
4566 if (format
->attrs
& WINED3D_FORMAT_ATTR_BROKEN_PITCH
)
4567 return width
* height
* depth
* format
->byte_count
;
4569 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
4571 return slice_pitch
* depth
;
4574 BOOL
wined3d_formats_are_srgb_variants(enum wined3d_format_id format1
, enum wined3d_format_id format2
)
4578 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
4580 if (format1
== format_srgb_info
[i
].srgb_format_id
)
4581 return format2
== format_srgb_info
[i
].base_format_id
;
4582 if (format1
== format_srgb_info
[i
].base_format_id
)
4583 return format2
== format_srgb_info
[i
].srgb_format_id
;
4588 /*****************************************************************************
4589 * Trace formatting of useful values
4591 const char *debug_box(const struct wined3d_box
*box
)
4595 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
4596 box
->left
, box
->top
, box
->front
,
4597 box
->right
, box
->bottom
, box
->back
);
4600 const char *debug_color(const struct wined3d_color
*color
)
4604 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4605 color
->r
, color
->g
, color
->b
, color
->a
);
4608 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
4612 return wine_dbg_sprintf("{%d, %d, %d, %d}",
4613 v
->x
, v
->y
, v
->z
, v
->w
);
4616 const char *debug_uvec4(const struct wined3d_uvec4
*v
)
4620 return wine_dbg_sprintf("{%u, %u, %u, %u}",
4621 v
->x
, v
->y
, v
->z
, v
->w
);
4624 const char *debug_vec4(const struct wined3d_vec4
*v
)
4628 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4629 v
->x
, v
->y
, v
->z
, v
->w
);
4632 const char *debug_const_bo_address(const struct wined3d_const_bo_address
*address
)
4636 return wine_dbg_sprintf("{%p:%p}", address
->buffer_object
, address
->addr
);
4639 const char *debug_bo_address(const struct wined3d_bo_address
*address
)
4641 return debug_const_bo_address((const struct wined3d_const_bo_address
*)address
);
4644 const char *debug_d3dformat(enum wined3d_format_id format_id
)
4648 #define FMT_TO_STR(format_id) case format_id: return #format_id
4649 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
4650 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
4651 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
4652 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
4653 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
4654 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
4655 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
4656 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
4657 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
4658 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
4659 FMT_TO_STR(WINED3DFMT_P8_UINT
);
4660 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
4661 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
4662 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
4663 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
4664 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
4665 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
4666 FMT_TO_STR(WINED3DFMT_R10G10B10X2_TYPELESS
);
4667 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
4668 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
4669 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
4670 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
4671 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
4672 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
4673 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
4674 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
4675 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
4676 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
4677 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
4678 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
4679 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
4680 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
4681 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
4682 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
4683 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
4684 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
4685 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
4686 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
4687 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
4688 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
4689 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
4690 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
4691 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
4692 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
4693 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
4694 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
4695 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
4696 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
4697 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
4698 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
4699 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
4700 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
4701 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
4702 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
4703 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
4704 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
4705 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
4706 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
4707 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
4708 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
4709 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
4710 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
4711 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
4712 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
4713 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
4714 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
4715 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
4716 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
4717 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
4718 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
4719 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
4720 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
4721 FMT_TO_STR(WINED3DFMT_R32_UINT
);
4722 FMT_TO_STR(WINED3DFMT_R32_SINT
);
4723 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
4724 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
4725 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
4726 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
4727 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
4728 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
4729 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
4730 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
4731 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
4732 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
4733 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
4734 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
4735 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
4736 FMT_TO_STR(WINED3DFMT_R16_UINT
);
4737 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
4738 FMT_TO_STR(WINED3DFMT_R16_SINT
);
4739 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
4740 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
4741 FMT_TO_STR(WINED3DFMT_R8_UINT
);
4742 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
4743 FMT_TO_STR(WINED3DFMT_R8_SINT
);
4744 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
4745 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
4746 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
4747 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
4748 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
4749 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
4750 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
4751 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
4752 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
4753 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
4754 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
4755 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
4756 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
4757 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
4758 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
4759 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
4760 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
4761 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
4762 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
4763 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
4764 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
4765 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
4766 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
4767 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
4768 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
4769 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
4770 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
4771 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
4772 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
4773 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
4774 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
4775 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
4776 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
4777 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
4778 FMT_TO_STR(WINED3DFMT_UYVY
);
4779 FMT_TO_STR(WINED3DFMT_YUY2
);
4780 FMT_TO_STR(WINED3DFMT_YV12
);
4781 FMT_TO_STR(WINED3DFMT_DXT1
);
4782 FMT_TO_STR(WINED3DFMT_DXT2
);
4783 FMT_TO_STR(WINED3DFMT_DXT3
);
4784 FMT_TO_STR(WINED3DFMT_DXT4
);
4785 FMT_TO_STR(WINED3DFMT_DXT5
);
4786 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
4787 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
4788 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
4789 FMT_TO_STR(WINED3DFMT_ATI1N
);
4790 FMT_TO_STR(WINED3DFMT_ATI2N
);
4791 FMT_TO_STR(WINED3DFMT_INST
);
4792 FMT_TO_STR(WINED3DFMT_NVDB
);
4793 FMT_TO_STR(WINED3DFMT_NVHU
);
4794 FMT_TO_STR(WINED3DFMT_NVHS
);
4795 FMT_TO_STR(WINED3DFMT_INTZ
);
4796 FMT_TO_STR(WINED3DFMT_RESZ
);
4797 FMT_TO_STR(WINED3DFMT_NULL
);
4798 FMT_TO_STR(WINED3DFMT_R16
);
4799 FMT_TO_STR(WINED3DFMT_AL16
);
4800 FMT_TO_STR(WINED3DFMT_NV12
);
4801 FMT_TO_STR(WINED3DFMT_ATOC
);
4806 fourcc
[0] = (char)(format_id
);
4807 fourcc
[1] = (char)(format_id
>> 8);
4808 fourcc
[2] = (char)(format_id
>> 16);
4809 fourcc
[3] = (char)(format_id
>> 24);
4811 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
4812 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
4814 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
4816 return "unrecognized";
4820 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
4822 switch (device_type
)
4824 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4825 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
4826 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
4827 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
4828 #undef DEVTYPE_TO_STR
4830 FIXME("Unrecognized device type %#x.\n", device_type
);
4831 return "unrecognized";
4837 char str
[200]; /* wine_dbg_sprintf() limits string size to 200 */
4842 static void init_debug_buffer(struct debug_buffer
*buffer
, const char *default_string
)
4844 snprintf(buffer
->str
, sizeof(buffer
->str
), "%s", default_string
);
4845 buffer
->ptr
= buffer
->str
;
4846 buffer
->size
= sizeof(buffer
->str
);
4849 static void debug_append(struct debug_buffer
*buffer
, const char *str
, const char *separator
)
4853 if (!separator
|| buffer
->ptr
== buffer
->str
)
4855 size
= snprintf(buffer
->ptr
, buffer
->size
, "%s%s", separator
, str
);
4856 if (size
== -1 || size
>= buffer
->size
)
4859 strcpy(&buffer
->str
[sizeof(buffer
->str
) - 4], "...");
4863 buffer
->ptr
+= size
;
4864 buffer
->size
-= size
;
4867 const char *wined3d_debug_resource_access(uint32_t access
)
4869 struct debug_buffer buffer
;
4871 init_debug_buffer(&buffer
, "0");
4872 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4873 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU
);
4874 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU
);
4875 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R
);
4876 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W
);
4877 #undef ACCESS_TO_STR
4879 FIXME("Unrecognised access flag(s) %#x.\n", access
);
4881 return wine_dbg_sprintf("%s", buffer
.str
);
4884 const char *wined3d_debug_bind_flags(uint32_t bind_flags
)
4886 struct debug_buffer buffer
;
4888 init_debug_buffer(&buffer
, "0");
4889 #define BIND_FLAG_TO_STR(x) if (bind_flags & x) { debug_append(&buffer, #x, " | "); bind_flags &= ~x; }
4890 BIND_FLAG_TO_STR(WINED3D_BIND_VERTEX_BUFFER
);
4891 BIND_FLAG_TO_STR(WINED3D_BIND_INDEX_BUFFER
);
4892 BIND_FLAG_TO_STR(WINED3D_BIND_CONSTANT_BUFFER
);
4893 BIND_FLAG_TO_STR(WINED3D_BIND_SHADER_RESOURCE
);
4894 BIND_FLAG_TO_STR(WINED3D_BIND_STREAM_OUTPUT
);
4895 BIND_FLAG_TO_STR(WINED3D_BIND_RENDER_TARGET
);
4896 BIND_FLAG_TO_STR(WINED3D_BIND_DEPTH_STENCIL
);
4897 BIND_FLAG_TO_STR(WINED3D_BIND_UNORDERED_ACCESS
);
4898 BIND_FLAG_TO_STR(WINED3D_BIND_INDIRECT_BUFFER
);
4899 #undef BIND_FLAG_TO_STR
4901 FIXME("Unrecognised bind flag(s) %#x.\n", bind_flags
);
4903 return wine_dbg_sprintf("%s", buffer
.str
);
4906 const char *wined3d_debug_view_desc(const struct wined3d_view_desc
*d
, const struct wined3d_resource
*resource
)
4908 struct debug_buffer buffer
;
4909 unsigned int flags
= d
->flags
;
4911 init_debug_buffer(&buffer
, "0");
4912 #define VIEW_FLAG_TO_STR(x) if (flags & x) { debug_append(&buffer, #x, " | "); flags &= ~x; }
4913 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_RAW
);
4914 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_APPEND
);
4915 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_COUNTER
);
4916 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_CUBE
);
4917 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_ARRAY
);
4918 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_DEPTH
);
4919 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_STENCIL
);
4920 #undef VIEW_FLAG_TO_STR
4922 FIXME("Unrecognised view flag(s) %#x.\n", flags
);
4924 if (resource
->type
== WINED3D_RTYPE_BUFFER
)
4925 return wine_dbg_sprintf("format %s, flags %s, start_idx %u, count %u",
4926 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.buffer
.start_idx
, d
->u
.buffer
.count
);
4928 return wine_dbg_sprintf("format %s, flags %s, level_idx %u, level_count %u, layer_idx %u, layer_count %u",
4929 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.texture
.level_idx
, d
->u
.texture
.level_count
,
4930 d
->u
.texture
.layer_idx
, d
->u
.texture
.layer_count
);
4933 const char *debug_d3dusage(uint32_t usage
)
4935 struct debug_buffer buffer
;
4937 init_debug_buffer(&buffer
, "0");
4938 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4939 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
4940 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
4941 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
4942 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
4943 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
4944 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
4945 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
4946 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
4947 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
4948 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
4949 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
4950 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
4951 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
4952 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
4953 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
4954 WINED3DUSAGE_TO_STR(WINED3DUSAGE_MANAGED
);
4955 WINED3DUSAGE_TO_STR(WINED3DUSAGE_VIDMEM_ACCOUNTING
);
4956 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
4957 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP
);
4958 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
4959 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
4960 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
4961 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
4962 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
4963 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4964 #undef WINED3DUSAGE_TO_STR
4966 FIXME("Unrecognized usage flag(s) %#x.\n", usage
);
4968 return wine_dbg_sprintf("%s", buffer
.str
);
4971 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4975 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4976 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4977 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4978 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4979 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4980 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4981 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4982 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4983 #undef WINED3DDECLMETHOD_TO_STR
4985 FIXME("Unrecognized declaration method %#x.\n", method
);
4986 return "unrecognized";
4990 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4994 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4995 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4996 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4997 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4998 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4999 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
5000 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
5001 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
5002 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
5003 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
5004 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
5005 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
5006 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
5007 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
5008 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
5009 #undef WINED3DDECLUSAGE_TO_STR
5011 FIXME("Unrecognized %u declaration usage!\n", usage
);
5012 return "unrecognized";
5016 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
5018 switch (classification
)
5020 #define WINED3D_TO_STR(x) case x: return #x
5021 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
5022 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
5023 #undef WINED3D_TO_STR
5025 FIXME("Unrecognized input classification %#x.\n", classification
);
5026 return "unrecognized";
5030 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
5032 switch (resource_type
)
5034 #define WINED3D_TO_STR(x) case x: return #x
5035 WINED3D_TO_STR(WINED3D_RTYPE_NONE
);
5036 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
5037 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D
);
5038 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
5039 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
5040 #undef WINED3D_TO_STR
5042 FIXME("Unrecognized resource type %#x.\n", resource_type
);
5043 return "unrecognized";
5047 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
5049 switch (primitive_type
)
5051 #define PRIM_TO_STR(prim) case prim: return #prim
5052 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
5053 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
5054 PRIM_TO_STR(WINED3D_PT_LINELIST
);
5055 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
5056 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
5057 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
5058 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
5059 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
5060 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
5061 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
5062 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
5063 PRIM_TO_STR(WINED3D_PT_PATCH
);
5066 FIXME("Unrecognized primitive type %#x.\n", primitive_type
);
5067 return "unrecognized";
5071 const char *debug_d3drenderstate(enum wined3d_render_state state
)
5075 #define D3DSTATE_TO_STR(u) case u: return #u
5076 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
5077 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
5078 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
5079 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
5080 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
5081 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
5082 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
5083 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
5084 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
5085 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
5086 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
5087 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
5088 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
5089 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
5090 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
5091 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
5092 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
5093 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
5094 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
5095 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
5096 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
5097 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
5098 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
5099 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
5100 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
5101 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
5102 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
5103 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
5104 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
5105 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
5106 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
5107 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
5108 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
5109 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
5110 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
5111 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
5112 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
5113 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
5114 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
5115 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
5116 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
5117 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
5118 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
5119 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
5120 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
5121 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
5122 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
5123 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
5124 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
5125 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
5126 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
5127 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
5128 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
5129 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
5130 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
5131 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
5132 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
5133 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
5134 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
5135 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
5136 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
5137 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
5138 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
5139 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
5140 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
5141 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
5142 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
5143 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
5144 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
5145 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
5146 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
5147 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
5148 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
5149 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
5150 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
5151 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
5152 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
5153 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
5154 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
5155 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
5156 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
5157 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
5158 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
5159 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
5160 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
5161 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
5162 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
5163 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
5164 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
5165 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
5166 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
5167 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
5168 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
5169 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
5170 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
5171 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
5172 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
5173 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
5174 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
5175 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
5176 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
5177 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
5178 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
5179 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
5180 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
5181 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
5182 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
5183 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
5184 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
5185 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
5186 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
5187 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
5188 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
5189 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
5190 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
5191 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
5192 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
5193 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
5194 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
5195 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
5196 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
5197 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
5198 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
5199 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
5200 #undef D3DSTATE_TO_STR
5202 FIXME("Unrecognized %u render state!\n", state
);
5203 return "unrecognized";
5207 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
5211 #define D3DSTATE_TO_STR(u) case u: return #u
5212 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
5213 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
5214 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
5215 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
5216 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
5217 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
5218 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
5219 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
5220 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
5221 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
5222 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
5223 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
5224 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
5225 #undef D3DSTATE_TO_STR
5227 FIXME("Unrecognized %u sampler state!\n", state
);
5228 return "unrecognized";
5232 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
5234 switch (filter_type
)
5236 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
5237 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
5238 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
5239 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
5240 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
5241 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
5242 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
5243 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
5244 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
5245 #undef D3DTEXTUREFILTERTYPE_TO_STR
5247 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
5248 return "unrecognized";
5252 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
5256 #define D3DSTATE_TO_STR(u) case u: return #u
5257 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
5258 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
5259 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
5260 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
5261 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
5262 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
5263 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
5264 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
5265 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
5266 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
5267 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
5268 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
5269 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
5270 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
5271 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
5272 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
5273 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
5274 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
5275 #undef D3DSTATE_TO_STR
5277 FIXME("Unrecognized %u texture state!\n", state
);
5278 return "unrecognized";
5282 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
5286 #define D3DTOP_TO_STR(u) case u: return #u
5287 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
5288 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
5289 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
5290 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
5291 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
5292 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
5293 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
5294 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
5295 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
5296 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
5297 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
5298 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
5299 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
5300 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
5301 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
5302 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
5303 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
5304 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
5305 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
5306 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
5307 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
5308 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
5309 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
5310 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
5311 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
5312 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
5313 #undef D3DTOP_TO_STR
5315 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
5316 return "unrecognized";
5320 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
5324 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
5325 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
5326 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
5327 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
5328 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
5329 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
5330 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
5331 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
5332 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
5333 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
5334 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
5335 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
5336 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
5337 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
5338 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
5339 #undef TSTYPE_TO_STR
5341 if (tstype
> 256 && tstype
< 512)
5343 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
5344 return ("WINED3D_TS_WORLD_MATRIX > 0");
5346 FIXME("Unrecognized transform state %#x.\n", tstype
);
5347 return "unrecognized";
5351 const char *debug_shader_type(enum wined3d_shader_type type
)
5355 #define WINED3D_TO_STR(type) case type: return #type
5356 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
5357 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
5358 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
5359 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
5360 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
5361 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
5362 #undef WINED3D_TO_STR
5364 FIXME("Unrecognized shader type %#x.\n", type
);
5365 return "unrecognized";
5369 const char *debug_d3dstate(uint32_t state
)
5371 if (STATE_IS_RENDER(state
))
5372 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
5373 if (STATE_IS_TEXTURESTAGE(state
))
5375 unsigned int texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
5376 uint32_t texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
5377 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
5378 texture_stage
, debug_d3dtexturestate(texture_state
));
5380 if (STATE_IS_SAMPLER(state
))
5381 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
5382 if (STATE_IS_COMPUTE_SHADER(state
))
5383 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5384 if (STATE_IS_GRAPHICS_SHADER(state
))
5385 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
5386 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
5387 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5388 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
5389 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
5390 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
5391 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
5392 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
5393 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
5394 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
5395 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
5396 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
5397 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
5398 if (STATE_IS_TRANSFORM(state
))
5399 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
5400 if (STATE_IS_STREAMSRC(state
))
5401 return "STATE_STREAMSRC";
5402 if (STATE_IS_INDEXBUFFER(state
))
5403 return "STATE_INDEXBUFFER";
5404 if (STATE_IS_VDECL(state
))
5405 return "STATE_VDECL";
5406 if (STATE_IS_VIEWPORT(state
))
5407 return "STATE_VIEWPORT";
5408 if (STATE_IS_LIGHT_TYPE(state
))
5409 return "STATE_LIGHT_TYPE";
5410 if (STATE_IS_ACTIVELIGHT(state
))
5411 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
5412 if (STATE_IS_SCISSORRECT(state
))
5413 return "STATE_SCISSORRECT";
5414 if (STATE_IS_CLIPPLANE(state
))
5415 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
5416 if (STATE_IS_MATERIAL(state
))
5417 return "STATE_MATERIAL";
5418 if (STATE_IS_RASTERIZER(state
))
5419 return "STATE_RASTERIZER";
5420 if (STATE_IS_DEPTH_BOUNDS(state
))
5421 return "STATE_DEPTH_BOUNDS";
5422 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
5423 return "STATE_POINTSPRITECOORDORIGIN";
5424 if (STATE_IS_BASEVERTEXINDEX(state
))
5425 return "STATE_BASEVERTEXINDEX";
5426 if (STATE_IS_FRAMEBUFFER(state
))
5427 return "STATE_FRAMEBUFFER";
5428 if (STATE_IS_POINT_ENABLE(state
))
5429 return "STATE_POINT_ENABLE";
5430 if (STATE_IS_COLOR_KEY(state
))
5431 return "STATE_COLOR_KEY";
5432 if (STATE_IS_STREAM_OUTPUT(state
))
5433 return "STATE_STREAM_OUTPUT";
5434 if (STATE_IS_BLEND(state
))
5435 return "STATE_BLEND";
5436 if (STATE_IS_BLEND_FACTOR(state
))
5437 return "STATE_BLEND_FACTOR";
5438 if (STATE_IS_SAMPLE_MASK(state
))
5439 return "STATE_SAMPLE_MASK";
5440 if (STATE_IS_DEPTH_STENCIL(state
))
5441 return "STATE_DEPTH_STENCIL";
5442 if (STATE_IS_STENCIL_REF(state
))
5443 return "STATE_STENCIL_REF";
5445 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
5448 const char *debug_fboattachment(GLenum attachment
)
5452 #define WINED3D_TO_STR(x) case x: return #x
5453 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
5454 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
5455 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
5456 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
5457 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
5458 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
5459 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
5460 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
5461 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
5462 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
5463 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
5464 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
5465 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
5466 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
5467 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
5468 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
5469 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
5470 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
5471 #undef WINED3D_TO_STR
5473 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
5477 const char *debug_fbostatus(GLenum status
) {
5479 #define FBOSTATUS_TO_STR(u) case u: return #u
5480 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
5481 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
5482 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
5483 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
5484 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
5485 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
5486 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
5487 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
5488 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
5489 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
5490 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
5491 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
5492 #undef FBOSTATUS_TO_STR
5494 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
5495 return "unrecognized";
5499 const char *debug_glerror(GLenum error
) {
5501 #define GLERROR_TO_STR(u) case u: return #u
5502 GLERROR_TO_STR(GL_NO_ERROR
);
5503 GLERROR_TO_STR(GL_INVALID_ENUM
);
5504 GLERROR_TO_STR(GL_INVALID_VALUE
);
5505 GLERROR_TO_STR(GL_INVALID_OPERATION
);
5506 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
5507 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
5508 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
5509 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
5510 #undef GLERROR_TO_STR
5512 FIXME("Unrecognized GL error 0x%08x.\n", error
);
5513 return "unrecognized";
5517 const char *wined3d_debug_vkresult(VkResult vr
)
5521 #define WINED3D_TO_STR(x) case x: return #x
5522 WINED3D_TO_STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR
);
5523 WINED3D_TO_STR(VK_ERROR_NOT_PERMITTED_EXT
);
5524 WINED3D_TO_STR(VK_ERROR_FRAGMENTATION_EXT
);
5525 WINED3D_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5526 WINED3D_TO_STR(VK_ERROR_OUT_OF_POOL_MEMORY
);
5527 WINED3D_TO_STR(VK_ERROR_INVALID_SHADER_NV
);
5528 WINED3D_TO_STR(VK_ERROR_OUT_OF_DATE_KHR
);
5529 WINED3D_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
);
5530 WINED3D_TO_STR(VK_ERROR_SURFACE_LOST_KHR
);
5531 WINED3D_TO_STR(VK_ERROR_FRAGMENTED_POOL
);
5532 WINED3D_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED
);
5533 WINED3D_TO_STR(VK_ERROR_TOO_MANY_OBJECTS
);
5534 WINED3D_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER
);
5535 WINED3D_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT
);
5536 WINED3D_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT
);
5537 WINED3D_TO_STR(VK_ERROR_LAYER_NOT_PRESENT
);
5538 WINED3D_TO_STR(VK_ERROR_MEMORY_MAP_FAILED
);
5539 WINED3D_TO_STR(VK_ERROR_DEVICE_LOST
);
5540 WINED3D_TO_STR(VK_ERROR_INITIALIZATION_FAILED
);
5541 WINED3D_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5542 WINED3D_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY
);
5543 WINED3D_TO_STR(VK_SUCCESS
);
5544 WINED3D_TO_STR(VK_NOT_READY
);
5545 WINED3D_TO_STR(VK_TIMEOUT
);
5546 WINED3D_TO_STR(VK_EVENT_SET
);
5547 WINED3D_TO_STR(VK_EVENT_RESET
);
5548 WINED3D_TO_STR(VK_INCOMPLETE
);
5549 WINED3D_TO_STR(VK_SUBOPTIMAL_KHR
);
5550 #undef WINED3D_TO_STR
5552 return wine_dbg_sprintf("unrecognised(%d)", vr
);
5556 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
5560 #define WINED3D_TO_STR(x) case x: return #x
5561 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
5562 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
5563 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
5564 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
5565 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
5566 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
5567 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
5568 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
5569 #undef WINED3D_TO_STR
5571 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
5572 return "unrecognized";
5576 static const char *debug_complex_fixup(enum complex_fixup fixup
)
5580 #define WINED3D_TO_STR(x) case x: return #x
5581 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
5582 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
5583 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
5584 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
5585 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
5586 WINED3D_TO_STR(COMPLEX_FIXUP_YUV
);
5587 #undef WINED3D_TO_STR
5589 FIXME("Unrecognized complex fixup %#x\n", fixup
);
5590 return "unrecognized";
5594 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
5596 if (is_complex_fixup(fixup
))
5598 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
5602 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
5603 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
5604 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
5605 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
5608 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
5609 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
5611 if (op
== WINED3D_TOP_DISABLE
)
5613 if (state
->textures
[stage
])
5616 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5617 && op
!= WINED3D_TOP_SELECT_ARG2
)
5619 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5620 && op
!= WINED3D_TOP_SELECT_ARG1
)
5622 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5623 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
5629 void get_identity_matrix(struct wined3d_matrix
*mat
)
5631 static const struct wined3d_matrix identity
=
5633 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5634 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5635 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5636 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5642 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5643 unsigned int index
, struct wined3d_matrix
*mat
)
5645 if (context
->last_was_rhw
)
5646 get_identity_matrix(mat
);
5648 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
5651 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5652 struct wined3d_matrix
*mat
)
5654 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5655 BOOL clip_control
, flip
;
5656 float center_offset
;
5658 /* There are a couple of additional things we have to take into account
5659 * here besides the projection transformation itself:
5660 * - We need to flip along the y-axis in case of offscreen rendering.
5661 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
5662 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
5663 * refer to pixel corners. D3D10 fixed this particular oddity.
5664 * - D3D has a top-left filling convention while GL does not specify
5665 * a particular behavior, other than that that the GL implementation
5666 * needs to be consistent.
5668 * In order to handle the pixel center, we translate by 0.5 / VPw and
5669 * 0.5 / VPh. We test the filling convention during adapter init and
5670 * add a small offset to correct it if necessary. See
5671 * wined3d_caps_gl_ctx_test_filling_convention() for more details on how
5672 * we test GL and considerations regarding the added offset value.
5674 * If we have GL_ARB_clip_control we take care of all this through
5675 * viewport properties and don't have to translate geometry. */
5677 /* Projection matrices are <= d3d9, which all have integer pixel centers. */
5678 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
))
5679 ERR("Did not expect to enter this codepath without WINED3D_PIXEL_CENTER_INTEGER.\n");
5681 clip_control
= d3d_info
->clip_control
;
5682 flip
= !clip_control
&& context
->render_offscreen
;
5684 center_offset
= 1.0f
+ d3d_info
->filling_convention_offset
;
5686 center_offset
= 0.0f
;
5688 if (context
->last_was_rhw
)
5690 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
5691 float x
= state
->viewports
[0].x
;
5692 float y
= state
->viewports
[0].y
;
5693 float w
= state
->viewports
[0].width
;
5694 float h
= state
->viewports
[0].height
;
5695 float x_scale
= 2.0f
/ w
;
5696 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
5697 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
5698 float y_offset
= flip
5699 ? (center_offset
- (2.0f
* y
) - h
) / h
5700 : (center_offset
- (2.0f
* y
) - h
) / -h
;
5701 bool zenable
= state
->fb
.depth_stencil
?
5702 (state
->depth_stencil_state
? state
->depth_stencil_state
->desc
.depth
: true) : false;
5703 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
5704 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
5705 const struct wined3d_matrix projection
=
5707 x_scale
, 0.0f
, 0.0f
, 0.0f
,
5708 0.0f
, y_scale
, 0.0f
, 0.0f
,
5709 0.0f
, 0.0f
, z_scale
, 0.0f
,
5710 x_offset
, y_offset
, z_offset
, 1.0f
,
5717 float y_scale
= flip
? -1.0f
: 1.0f
;
5718 float x_offset
= center_offset
/ state
->viewports
[0].width
;
5719 float y_offset
= flip
5720 ? center_offset
/ state
->viewports
[0].height
5721 : -center_offset
/ state
->viewports
[0].height
;
5722 float z_scale
= clip_control
? 1.0f
: 2.0f
;
5723 float z_offset
= clip_control
? 0.0f
: -1.0f
;
5724 const struct wined3d_matrix projection
=
5726 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5727 0.0f
, y_scale
, 0.0f
, 0.0f
,
5728 0.0f
, 0.0f
, z_scale
, 0.0f
,
5729 x_offset
, y_offset
, z_offset
, 1.0f
,
5732 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
5736 /* Setup this textures matrix according to the texture flags. */
5737 static void compute_texture_matrix(const struct wined3d_matrix
*matrix
, uint32_t flags
, BOOL calculated_coords
,
5738 BOOL transformed
, enum wined3d_format_id format_id
, BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
5740 struct wined3d_matrix mat
;
5742 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
5744 get_identity_matrix(out_matrix
);
5748 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
5750 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
5756 if (flags
& WINED3D_TTFF_PROJECTED
)
5758 if (!ffp_proj_control
)
5760 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5762 case WINED3D_TTFF_COUNT2
:
5767 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
5769 case WINED3D_TTFF_COUNT3
:
5774 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5781 /* Under Direct3D the R/Z coord can be used for translation, under
5782 * OpenGL we use the Q coord instead. */
5783 if (!calculated_coords
)
5787 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5788 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5789 * store the value of mat._41 in mat._21 because the input
5790 * value to the transformation will be 0, so the matrix value
5792 case WINED3DFMT_R32_FLOAT
:
5798 /* See above, just 3rd and 4th coord. */
5799 case WINED3DFMT_R32G32_FLOAT
:
5805 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
5806 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
5808 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5809 * into a bad place. The division elimination below will apply to make sure the
5810 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5812 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
5815 FIXME("Unexpected fixed function texture coord input\n");
5818 if (!ffp_proj_control
)
5820 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5822 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
5823 case WINED3D_TTFF_COUNT2
:
5824 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5825 /* OpenGL divides the first 3 vertex coordinates by the 4th by
5826 * default, which is essentially the same as D3DTTFF_PROJECTED.
5827 * Make sure that the 4th coordinate evaluates to 1.0 to
5830 * If the fixed function pipeline is used, the 4th value
5831 * remains unused, so there is no danger in doing this. With
5832 * vertex shaders we have a problem. Should an application hit
5833 * that problem, the code here would have to check for pixel
5834 * shaders, and the shader has to undo the default GL divide.
5836 * A more serious problem occurs if the application passes 4
5837 * coordinates in, and the 4th is != 1.0 (OpenGL default).
5838 * This would have to be fixed with immediate mode draws. */
5840 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
5848 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5849 unsigned int tex
, struct wined3d_matrix
*mat
)
5851 const struct wined3d_device
*device
= context
->device
;
5852 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
5853 != WINED3DTSS_TCI_PASSTHRU
;
5854 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
5855 WINED3D_MAX_TEXTURES
- 1);
5857 compute_texture_matrix(&state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
5858 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
5859 generated
, context
->last_was_rhw
,
5860 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
5861 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
5862 : WINED3DFMT_UNKNOWN
,
5863 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
5865 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
5868 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
5869 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
5870 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
5873 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
5874 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
5879 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5880 float *out_min
, float *out_max
)
5888 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
5889 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
5898 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5899 float *out_pointsize
, float *out_att
)
5901 /* POINTSCALEENABLE controls how point size value is treated. If set to
5902 * true, the point size is scaled with respect to height of viewport.
5903 * When set to false point size is in pixels. */
5908 } pointsize
, a
, b
, c
;
5914 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
5915 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
5916 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
5917 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
5919 /* Always use first viewport, this path does not apply to d3d10/11 multiple viewports case. */
5920 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
5922 float scale_factor
= state
->viewports
[0].height
* state
->viewports
[0].height
;
5924 out_att
[0] = a
.f
/ scale_factor
;
5925 out_att
[1] = b
.f
/ scale_factor
;
5926 out_att
[2] = c
.f
/ scale_factor
;
5928 *out_pointsize
= pointsize
.f
;
5931 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5932 float *start
, float *end
)
5940 switch (context
->fog_source
)
5947 case FOGSOURCE_COORD
:
5953 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
5954 *start
= tmpvalue
.f
;
5955 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
5957 /* Special handling for fog_start == fog_end. In d3d with vertex
5958 * fog, everything is fogged. With table fog, everything with
5959 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5960 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5961 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
5969 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5970 ERR("Unexpected fog coordinate source.\n");
5976 static BOOL
wined3d_get_primary_display(WCHAR
*display
)
5978 DISPLAY_DEVICEW display_device
;
5979 DWORD device_idx
= 0;
5981 display_device
.cb
= sizeof(display_device
);
5982 while (EnumDisplayDevicesW(NULL
, device_idx
++, &display_device
, 0))
5984 if (display_device
.StateFlags
& DISPLAY_DEVICE_PRIMARY_DEVICE
)
5986 lstrcpyW(display
, display_device
.DeviceName
);
5994 BOOL
wined3d_get_primary_adapter_luid(LUID
*luid
)
5996 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param
;
5997 D3DKMT_CLOSEADAPTER close_adapter_param
;
5999 if (!wined3d_get_primary_display(open_adapter_param
.DeviceName
))
6002 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param
))
6005 *luid
= open_adapter_param
.AdapterLuid
;
6006 close_adapter_param
.hAdapter
= open_adapter_param
.hAdapter
;
6007 D3DKMTCloseAdapter(&close_adapter_param
);
6011 uint32_t wined3d_format_pack(const struct wined3d_format
*format
, const struct wined3d_uvec4
*value
)
6015 p
|= (value
->x
& wined3d_mask_from_size(format
->red_size
)) << format
->red_offset
;
6016 p
|= (value
->y
& wined3d_mask_from_size(format
->green_size
)) << format
->green_offset
;
6017 p
|= (value
->z
& wined3d_mask_from_size(format
->blue_size
)) << format
->blue_offset
;
6018 p
|= (value
->w
& wined3d_mask_from_size(format
->alpha_size
)) << format
->alpha_offset
;
6023 void wined3d_format_colour_to_vk(const struct wined3d_format
*format
, const struct wined3d_color
*c
,
6024 VkClearColorValue
*retval
)
6026 if (format
->attrs
& WINED3D_FORMAT_ATTR_INTEGER
)
6028 retval
->int32
[0] = c
->r
;
6029 retval
->int32
[1] = c
->g
;
6030 retval
->int32
[2] = c
->b
;
6031 retval
->int32
[3] = c
->a
;
6035 retval
->float32
[0] = c
->r
;
6036 retval
->float32
[1] = c
->g
;
6037 retval
->float32
[2] = c
->b
;
6038 retval
->float32
[3] = c
->a
;
6042 /* Note: It's the caller's responsibility to ensure values can be expressed
6043 * in the requested format. UNORM formats for example can only express values
6044 * in the range 0.0f -> 1.0f.
6046 * The code below assumes that no component crosses the 32 bit boundary (like
6047 * e.g. a hypothetical, and totally braindead, B30G30R4 format would).
6048 * This function writes at least sizeof(uint32_t) bytes, or format->byte_count,
6049 * whichever is larger. */
6050 void wined3d_format_convert_from_float(const struct wined3d_format
*format
,
6051 const struct wined3d_color
*color
, void *ret
)
6055 enum wined3d_format_id format_id
;
6056 struct wined3d_vec4 mul
;
6057 struct wined3d_uvec4 shift
;
6061 {WINED3DFMT_P8_UINT
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
6062 {WINED3DFMT_S1_UINT_D15_UNORM
, { 32767.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
6063 {WINED3DFMT_D16_UNORM
, { 65535.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
6067 enum wined3d_format_id format_id
;
6068 struct wined3d_dvec4 mul
;
6069 struct wined3d_uvec4 shift
;
6073 {WINED3DFMT_D24_UNORM_S8_UINT
, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
6074 {WINED3DFMT_X8D24_UNORM
, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
6075 {WINED3DFMT_D32_UNORM
, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
6077 enum wined3d_format_id format_id
= format
->id
;
6078 struct wined3d_color colour_srgb
;
6079 struct wined3d_uvec4 idx
, shift
;
6082 TRACE("Converting colour %s to format %s.\n", debug_color(color
), debug_d3dformat(format_id
));
6083 memset(ret
, 0, max(sizeof(uint32_t), format
->byte_count
));
6085 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
6087 if (format_id
!= format_srgb_info
[i
].srgb_format_id
)
6090 wined3d_colour_srgb_from_linear(&colour_srgb
, color
);
6091 format_id
= format_srgb_info
[i
].base_format_id
;
6092 color
= &colour_srgb
;
6096 for (i
= 0; i
< ARRAY_SIZE(float_conv
); ++i
)
6098 uint32_t *ret_i
= ret
;
6100 if (format_id
!= float_conv
[i
].format_id
)
6103 idx
.x
= float_conv
[i
].shift
.x
/ 32;
6104 idx
.y
= float_conv
[i
].shift
.y
/ 32;
6105 idx
.z
= float_conv
[i
].shift
.z
/ 32;
6106 idx
.w
= float_conv
[i
].shift
.w
/ 32;
6107 shift
.x
= float_conv
[i
].shift
.x
% 32;
6108 shift
.y
= float_conv
[i
].shift
.y
% 32;
6109 shift
.z
= float_conv
[i
].shift
.z
% 32;
6110 shift
.w
= float_conv
[i
].shift
.w
% 32;
6112 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* float_conv
[i
].mul
.x
) + 0.5f
)) << shift
.x
;
6113 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* float_conv
[i
].mul
.y
) + 0.5f
)) << shift
.y
;
6114 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* float_conv
[i
].mul
.z
) + 0.5f
)) << shift
.z
;
6115 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* float_conv
[i
].mul
.w
) + 0.5f
)) << shift
.w
;
6120 for (i
= 0; i
< ARRAY_SIZE(double_conv
); ++i
)
6124 if (format_id
!= double_conv
[i
].format_id
)
6127 idx
.x
= double_conv
[i
].shift
.x
/ 32;
6128 idx
.y
= double_conv
[i
].shift
.y
/ 32;
6129 idx
.z
= double_conv
[i
].shift
.z
/ 32;
6130 idx
.w
= double_conv
[i
].shift
.w
/ 32;
6131 shift
.x
= double_conv
[i
].shift
.x
% 32;
6132 shift
.y
= double_conv
[i
].shift
.y
% 32;
6133 shift
.z
= double_conv
[i
].shift
.z
% 32;
6134 shift
.w
= double_conv
[i
].shift
.w
% 32;
6137 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* double_conv
[i
].mul
.x
) + 0.5)) << shift
.x
;
6138 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* double_conv
[i
].mul
.y
) + 0.5)) << shift
.y
;
6139 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* double_conv
[i
].mul
.z
) + 0.5)) << shift
.z
;
6140 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* double_conv
[i
].mul
.w
) + 0.5)) << shift
.w
;
6145 if (format
->attrs
& WINED3D_FORMAT_ATTR_NORMALISED
)
6147 uint32_t *ret_i
= ret
;
6149 idx
.x
= format
->red_offset
/ 32;
6150 idx
.y
= format
->green_offset
/ 32;
6151 idx
.z
= format
->blue_offset
/ 32;
6152 idx
.w
= format
->alpha_offset
/ 32;
6153 shift
.x
= format
->red_offset
% 32;
6154 shift
.y
= format
->green_offset
% 32;
6155 shift
.z
= format
->blue_offset
% 32;
6156 shift
.w
= format
->alpha_offset
% 32;
6158 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* wined3d_mask_from_size(format
->red_size
)) + 0.5f
)) << shift
.x
;
6159 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* wined3d_mask_from_size(format
->green_size
)) + 0.5f
)) << shift
.y
;
6160 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* wined3d_mask_from_size(format
->blue_size
)) + 0.5f
)) << shift
.z
;
6161 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* wined3d_mask_from_size(format
->alpha_size
)) + 0.5f
)) << shift
.w
;
6166 /* 32 bit float formats. We don't handle D32_FLOAT_S8X24_UINT for now. */
6167 if ((format
->attrs
& WINED3D_FORMAT_ATTR_FLOAT
)
6168 && (format
->red_size
== 32 || format
->depth_size
== 32)
6169 && !format
->stencil_size
)
6173 switch (format
->byte_count
)
6175 case 16: ret_f
[3] = color
->a
;
6176 case 12: ret_f
[2] = color
->b
;
6177 case 8: ret_f
[1] = color
->g
;
6178 case 4: ret_f
[0] = color
->r
;
6182 ERR("Unexpected byte count %u, format %s.\n", format
->byte_count
, debug_d3dformat(format_id
));
6189 if ((format
->attrs
& WINED3D_FORMAT_ATTR_FLOAT
) && format
->red_size
== 16)
6191 uint16_t *ret_s
= ret
;
6193 switch (format
->byte_count
)
6196 ret_s
[3] = float_32_to_16(&color
->a
);
6197 ret_s
[2] = float_32_to_16(&color
->b
);
6200 ret_s
[1] = float_32_to_16(&color
->g
);
6203 ret_s
[0] = float_32_to_16(&color
->r
);
6207 ERR("Unexpected byte count %u, format %s.\n", format
->byte_count
, debug_d3dformat(format_id
));
6214 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id
));
6217 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
6219 uint32_t mask
= wined3d_mask_from_size(size
);
6227 return (float)color
/ (float)mask
;
6230 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
6231 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
6233 struct wined3d_color slop
;
6237 case WINED3DFMT_B8G8R8_UNORM
:
6238 case WINED3DFMT_B8G8R8A8_UNORM
:
6239 case WINED3DFMT_B8G8R8X8_UNORM
:
6240 case WINED3DFMT_B5G6R5_UNORM
:
6241 case WINED3DFMT_B5G5R5X1_UNORM
:
6242 case WINED3DFMT_B5G5R5A1_UNORM
:
6243 case WINED3DFMT_B4G4R4A4_UNORM
:
6244 case WINED3DFMT_B2G3R3_UNORM
:
6245 case WINED3DFMT_R8_UNORM
:
6246 case WINED3DFMT_A8_UNORM
:
6247 case WINED3DFMT_B2G3R3A8_UNORM
:
6248 case WINED3DFMT_B4G4R4X4_UNORM
:
6249 case WINED3DFMT_R10G10B10A2_UNORM
:
6250 case WINED3DFMT_R10G10B10A2_SNORM
:
6251 case WINED3DFMT_R8G8B8A8_UNORM
:
6252 case WINED3DFMT_R8G8B8X8_UNORM
:
6253 case WINED3DFMT_R16G16_UNORM
:
6254 case WINED3DFMT_B10G10R10A2_UNORM
:
6255 slop
.r
= 0.5f
/ wined3d_mask_from_size(format
->red_size
);
6256 slop
.g
= 0.5f
/ wined3d_mask_from_size(format
->green_size
);
6257 slop
.b
= 0.5f
/ wined3d_mask_from_size(format
->blue_size
);
6258 slop
.a
= 0.5f
/ wined3d_mask_from_size(format
->alpha_size
);
6260 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
6262 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
6264 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
6266 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
6269 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
6271 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
6273 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
6275 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
6279 case WINED3DFMT_P8_UINT
:
6280 float_colors
[0].r
= 0.0f
;
6281 float_colors
[0].g
= 0.0f
;
6282 float_colors
[0].b
= 0.0f
;
6283 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
6285 float_colors
[1].r
= 0.0f
;
6286 float_colors
[1].g
= 0.0f
;
6287 float_colors
[1].b
= 0.0f
;
6288 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
6292 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
6296 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
6300 case 8: return WINED3DFMT_P8_UINT
;
6301 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
6302 case 16: return WINED3DFMT_B5G6R5_UNORM
;
6303 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
6304 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
6305 default: return WINED3DFMT_UNKNOWN
;
6309 void wined3d_format_copy_data(const struct wined3d_format
*format
, const uint8_t *src
,
6310 unsigned int src_row_pitch
, unsigned int src_slice_pitch
, uint8_t *dst
, unsigned int dst_row_pitch
,
6311 unsigned int dst_slice_pitch
, unsigned int w
, unsigned int h
, unsigned int d
)
6313 unsigned int row_block_count
, row_count
, row_size
, slice
, row
;
6314 unsigned int slice_count
= d
, slice_size
;
6315 const uint8_t *src_row
;
6318 row_block_count
= (w
+ format
->block_width
- 1) / format
->block_width
;
6319 row_count
= (h
+ format
->block_height
- 1) / format
->block_height
;
6320 row_size
= row_block_count
* format
->block_byte_count
;
6321 slice_size
= row_size
* row_count
;
6323 if (src_row_pitch
== row_size
&& dst_row_pitch
== row_size
6324 && ((src_slice_pitch
== slice_size
&& dst_slice_pitch
== slice_size
) || slice_count
== 1))
6326 memcpy(dst
, src
, slice_count
* slice_size
);
6330 for (slice
= 0; slice
< slice_count
; ++slice
)
6332 for (row
= 0; row
< row_count
; ++row
)
6334 src_row
= &src
[slice
* src_slice_pitch
+ row
* src_row_pitch
];
6335 dst_row
= &dst
[slice
* dst_slice_pitch
+ row
* dst_row_pitch
];
6336 memcpy(dst_row
, src_row
, row_size
);
6341 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
6343 struct wined3d_matrix tmp
;
6345 /* Now do the multiplication 'by hand'.
6346 I know that all this could be optimised, but this will be done later :-) */
6347 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
6348 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
6349 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
6350 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
6352 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
6353 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
6354 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
6355 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
6357 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
6358 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
6359 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
6360 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
6362 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
6363 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
6364 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
6365 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
6370 void wined3d_ffp_get_fs_settings(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
6371 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
6376 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
6379 /* D3DTOP_DISABLE */ 0,
6380 /* D3DTOP_SELECTARG1 */ ARG1
,
6381 /* D3DTOP_SELECTARG2 */ ARG2
,
6382 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
6383 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
6384 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
6385 /* D3DTOP_ADD */ ARG1
| ARG2
,
6386 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
6387 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
6388 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
6389 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
6390 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
6391 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
6392 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
6393 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
6394 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
6395 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
6396 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
6397 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
6398 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
6399 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
6400 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
6401 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
6402 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
6403 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
6404 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
6408 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
6409 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6411 settings
->padding
= 0;
6413 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
6415 struct wined3d_texture
*texture
;
6417 settings
->op
[i
].padding
= 0;
6418 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
6420 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
6421 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
6422 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
6423 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
6424 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6425 settings
->op
[i
].tmp_dst
= 0;
6426 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6427 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6432 if ((texture
= state
->textures
[i
]))
6434 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
6435 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6437 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
6440 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6444 switch (wined3d_texture_gl(texture
)->target
)
6447 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6450 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
6453 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
6455 case GL_TEXTURE_CUBE_MAP_ARB
:
6456 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
6458 case GL_TEXTURE_RECTANGLE_ARB
:
6459 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
6464 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6465 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6468 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
6469 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
6471 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
6472 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
6473 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
6475 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
6479 carg1
= WINED3DTA_CURRENT
;
6480 cop
= WINED3D_TOP_SELECT_ARG1
;
6483 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
6485 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
6486 * the color result to the alpha component of the destination
6495 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
6496 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
6497 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
6500 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
6502 GLenum texture_dimensions
;
6504 texture
= state
->textures
[0];
6505 texture_dimensions
= wined3d_texture_gl(texture
)->target
;
6507 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
6509 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
6511 if (aop
== WINED3D_TOP_DISABLE
)
6513 aarg1
= WINED3DTA_TEXTURE
;
6514 aop
= WINED3D_TOP_SELECT_ARG1
;
6516 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
6518 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6520 aarg2
= WINED3DTA_TEXTURE
;
6521 aop
= WINED3D_TOP_MODULATE
;
6523 else aarg1
= WINED3DTA_TEXTURE
;
6525 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
6527 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6529 aarg1
= WINED3DTA_TEXTURE
;
6530 aop
= WINED3D_TOP_MODULATE
;
6532 else aarg2
= WINED3DTA_TEXTURE
;
6538 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
6542 aarg1
= WINED3DTA_CURRENT
;
6543 aop
= WINED3D_TOP_SELECT_ARG1
;
6546 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
6547 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
6549 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
6550 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
6551 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT3
;
6552 else if (ttff
& WINED3D_TTFF_PROJECTED
)
6553 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT4
;
6555 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6559 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6562 settings
->op
[i
].cop
= cop
;
6563 settings
->op
[i
].aop
= aop
;
6564 settings
->op
[i
].carg0
= carg0
;
6565 settings
->op
[i
].carg1
= carg1
;
6566 settings
->op
[i
].carg2
= carg2
;
6567 settings
->op
[i
].aarg0
= aarg0
;
6568 settings
->op
[i
].aarg1
= aarg1
;
6569 settings
->op
[i
].aarg2
= aarg2
;
6570 settings
->op
[i
].tmp_dst
= state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
;
6573 /* Clear unsupported stages */
6574 for(; i
< WINED3D_MAX_TEXTURES
; i
++) {
6575 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
6578 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6580 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
6582 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
6584 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
6586 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6590 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
6592 case WINED3D_FOG_NONE
:
6593 case WINED3D_FOG_LINEAR
:
6594 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6596 case WINED3D_FOG_EXP
:
6597 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6599 case WINED3D_FOG_EXP2
:
6600 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6607 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
6609 case WINED3D_FOG_LINEAR
:
6610 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6612 case WINED3D_FOG_EXP
:
6613 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6615 case WINED3D_FOG_EXP2
:
6616 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6620 settings
->sRGB_write
= !d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
);
6621 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
6622 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
6624 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
6625 * the fixed function vertex pipeline is used(which always supports clipplanes), or
6626 * if no clipplane is enabled
6628 settings
->emul_clipplanes
= 0;
6630 settings
->emul_clipplanes
= 1;
6633 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
6634 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
6635 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
6636 settings
->color_key_enabled
= 1;
6638 settings
->color_key_enabled
= 0;
6640 /* texcoords_initialized is set to meaningful values only when GL doesn't
6641 * support enough varyings to always pass around all the possible texture
6643 * This is used to avoid reading a varying not written by the vertex shader.
6644 * Reading uninitialized varyings on core profile contexts results in an
6645 * error while with builtin varyings on legacy contexts you get undefined
6647 if (d3d_info
->limits
.varying_count
&& !d3d_info
->full_ffp_varyings
)
6649 settings
->texcoords_initialized
= 0;
6650 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6654 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
6655 settings
->texcoords_initialized
|= 1u << i
;
6659 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6660 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6661 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
6662 & WINED3D_FFP_TCI_MASK
6663 || (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
6664 settings
->texcoords_initialized
|= 1u << i
;
6670 settings
->texcoords_initialized
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6673 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
6674 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
6676 if (d3d_info
->ffp_alpha_test
)
6677 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
6679 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
6680 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
6681 : WINED3D_CMP_ALWAYS
) - 1;
6683 if (d3d_info
->emulated_flatshading
)
6684 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6686 settings
->flatshading
= FALSE
;
6689 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
6690 const struct ffp_frag_settings
*settings
)
6692 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
6693 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
6696 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
6698 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
6699 * whereas desc points to an extended structure with implementation specific parts. */
6700 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
6702 ERR("Failed to insert ffp frag shader.\n");
6706 /* Activates the texture dimension according to the bound D3D texture. Does
6707 * not care for the colorop or correct gl texture unit (when using nvrc).
6708 * Requires the caller to activate the correct unit. */
6709 /* Context activation is done by the caller (state handler). */
6710 void texture_activate_dimensions(struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
6714 switch (wined3d_texture_gl(texture
)->target
)
6717 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6718 checkGLcall("glDisable(GL_TEXTURE_3D)");
6719 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6721 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6722 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6724 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6726 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6727 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6729 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6730 checkGLcall("glEnable(GL_TEXTURE_2D)");
6732 case GL_TEXTURE_RECTANGLE_ARB
:
6733 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6734 checkGLcall("glDisable(GL_TEXTURE_2D)");
6735 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6736 checkGLcall("glDisable(GL_TEXTURE_3D)");
6737 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6739 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6740 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6742 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
6743 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
6746 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6748 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6749 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6751 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6753 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6754 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6756 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6757 checkGLcall("glDisable(GL_TEXTURE_2D)");
6758 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
6759 checkGLcall("glEnable(GL_TEXTURE_3D)");
6761 case GL_TEXTURE_CUBE_MAP_ARB
:
6762 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6763 checkGLcall("glDisable(GL_TEXTURE_2D)");
6764 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6765 checkGLcall("glDisable(GL_TEXTURE_3D)");
6766 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6768 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6769 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6771 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
6772 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
6778 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6779 checkGLcall("glEnable(GL_TEXTURE_2D)");
6780 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6781 checkGLcall("glDisable(GL_TEXTURE_3D)");
6782 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6784 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6785 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6787 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6789 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6790 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6792 /* Binding textures is done by samplers. A dummy texture will be bound */
6796 /* Context activation is done by the caller (state handler). */
6797 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
6799 struct wined3d_context_gl
*context_gl
= wined3d_context_gl(context
);
6800 unsigned int sampler
= state_id
- STATE_SAMPLER(0);
6801 unsigned int mapped_stage
;
6803 /* No need to enable / disable anything here for unused samplers. The
6804 * tex_colorop handler takes care. Also no action is needed with pixel
6805 * shaders, or if tex_colorop will take care of this business. */
6806 mapped_stage
= context_gl
->tex_unit_map
[sampler
];
6807 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context_gl
->gl_info
->limits
.textures
)
6809 if (sampler
>= context
->lowest_disabled_stage
)
6811 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
6814 texture_activate_dimensions(state
->textures
[sampler
], context_gl
->gl_info
);
6817 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6819 const struct ffp_frag_settings
*ka
= key
;
6820 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
6822 return memcmp(ka
, kb
, sizeof(*ka
));
6825 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
6826 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
6828 enum wined3d_material_color_source diffuse_source
, emissive_source
, ambient_source
, specular_source
;
6829 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6830 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6831 unsigned int coord_idx
, i
;
6833 memset(settings
, 0, sizeof(*settings
));
6835 if (si
->position_transformed
)
6837 settings
->transformed
= 1;
6838 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6839 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6840 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6841 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6842 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6843 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6845 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6847 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6849 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6850 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6851 settings
->texcoords
|= 1u << i
;
6852 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6854 if (d3d_info
->full_ffp_varyings
)
6855 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6857 if (d3d_info
->emulated_flatshading
)
6858 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6860 settings
->flatshading
= FALSE
;
6862 settings
->swizzle_map
= si
->swizzle_map
;
6867 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
6869 case WINED3D_VBF_DISABLE
:
6870 case WINED3D_VBF_1WEIGHTS
:
6871 case WINED3D_VBF_2WEIGHTS
:
6872 case WINED3D_VBF_3WEIGHTS
:
6873 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
6876 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
6880 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
6881 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
6882 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
6883 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
6884 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
6885 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
6886 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6887 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6889 wined3d_get_material_colour_source(&diffuse_source
, &emissive_source
,
6890 &ambient_source
, &specular_source
, state
, si
);
6891 settings
->diffuse_source
= diffuse_source
;
6892 settings
->emissive_source
= emissive_source
;
6893 settings
->ambient_source
= ambient_source
;
6894 settings
->specular_source
= specular_source
;
6896 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6898 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6899 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6900 settings
->texcoords
|= 1u << i
;
6901 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6903 if (d3d_info
->full_ffp_varyings
)
6904 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6906 for (i
= 0; i
< WINED3D_MAX_ACTIVE_LIGHTS
; ++i
)
6908 if (!state
->light_state
.lights
[i
])
6911 switch (state
->light_state
.lights
[i
]->OriginalParms
.type
)
6913 case WINED3D_LIGHT_POINT
:
6914 ++settings
->point_light_count
;
6916 case WINED3D_LIGHT_SPOT
:
6917 ++settings
->spot_light_count
;
6919 case WINED3D_LIGHT_DIRECTIONAL
:
6920 ++settings
->directional_light_count
;
6922 case WINED3D_LIGHT_PARALLELPOINT
:
6923 ++settings
->parallel_point_light_count
;
6926 FIXME("Unhandled light type %#x.\n", state
->light_state
.lights
[i
]->OriginalParms
.type
);
6931 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6932 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6933 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6935 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6937 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
6938 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
6939 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
6940 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
6941 settings
->ortho_fog
= 1;
6943 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
6944 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6945 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
6946 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
6948 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6950 if (d3d_info
->emulated_flatshading
)
6951 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6953 settings
->flatshading
= FALSE
;
6955 settings
->swizzle_map
= si
->swizzle_map
;
6958 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6960 const struct wined3d_ffp_vs_settings
*ka
= key
;
6961 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
6962 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
6964 return memcmp(ka
, kb
, sizeof(*ka
));
6967 const char *wined3d_debug_location(uint32_t location
)
6969 struct debug_buffer buffer
;
6970 const char *prefix
= "";
6971 const char *suffix
= "";
6973 if (wined3d_popcount(location
) > 16)
6976 location
= ~location
;
6980 init_debug_buffer(&buffer
, "0");
6981 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6982 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
6983 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
6984 LOCATION_TO_STR(WINED3D_LOCATION_CLEARED
);
6985 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
6986 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
6987 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
6988 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
6989 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
6990 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
6991 #undef LOCATION_TO_STR
6993 FIXME("Unrecognized location flag(s) %#x.\n", location
);
6995 return wine_dbg_sprintf("%s%s%s", prefix
, buffer
.str
, suffix
);
6998 const char *wined3d_debug_feature_level(enum wined3d_feature_level level
)
7002 #define LEVEL_TO_STR(level) case level: return #level
7003 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_5
);
7004 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_6
);
7005 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_7
);
7006 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_8
);
7007 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_1
);
7008 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_2
);
7009 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_3
);
7010 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10
);
7011 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10_1
);
7012 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11
);
7013 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11_1
);
7016 return wine_dbg_sprintf("%#x", level
);
7020 /* Print a floating point value with the %.8e format specifier, always using
7021 * '.' as decimal separator. */
7022 void wined3d_ftoa(float value
, char *s
)
7026 if (copysignf(1.0f
, value
) < 0.0f
)
7029 /* Be sure to allocate a buffer of at least 17 characters for the result
7030 as sprintf may return a 3 digit exponent when using the MSVC runtime
7031 instead of a 2 digit exponent. */
7032 sprintf(s
, "%.8e", value
);
7033 if (isfinite(value
))
7037 void wined3d_release_dc(HWND window
, HDC dc
)
7039 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
7040 * However, that's not what actually happens, and there are user32 tests
7041 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
7042 * So explicitly check that the DC belongs to the window, since we want to
7043 * avoid releasing a DC that belongs to some other window if the original
7044 * window was already destroyed. */
7045 if (WindowFromDC(dc
) != window
)
7046 WARN("DC %p does not belong to window %p.\n", dc
, window
);
7047 else if (!ReleaseDC(window
, dc
))
7048 ERR("Failed to release device context %p, last error %#lx.\n", dc
, GetLastError());
7051 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
7053 RECT orig
= *clipped
;
7054 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
7055 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
7057 IntersectRect(clipped
, clipped
, clip_rect
);
7059 if (IsRectEmpty(clipped
))
7061 SetRectEmpty(other
);
7065 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
7066 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
7067 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
7068 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
7073 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
7074 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
7079 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
7081 *count
= gl_limits
->uniform_blocks
[i
];
7082 if (i
== shader_type
)
7087 ERR("Unrecognized shader type %#x.\n", shader_type
);
7091 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
7092 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
7096 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
7098 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
7101 *base
= gl_limits
->graphics_samplers
;
7102 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
7107 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
7109 *count
= gl_limits
->samplers
[i
];
7110 if (i
== shader_type
)
7115 ERR("Unrecognized shader type %#x.\n", shader_type
);
7119 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
7121 SIZE_T max_capacity
, new_capacity
;
7124 if (count
<= *capacity
)
7127 max_capacity
= ~(SIZE_T
)0 / size
;
7128 if (count
> max_capacity
)
7131 new_capacity
= max(1, *capacity
);
7132 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
7134 if (new_capacity
< count
)
7135 new_capacity
= count
;
7138 new_elements
= heap_alloc_zero(new_capacity
* size
);
7140 new_elements
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *elements
, new_capacity
* size
);
7144 *elements
= new_elements
;
7145 *capacity
= new_capacity
;
7149 static void swap_rows(float **a
, float **b
)
7157 BOOL
invert_matrix(struct wined3d_matrix
*out
, const struct wined3d_matrix
*m
)
7160 float m0
, m1
, m2
, m3
, s
;
7161 float *r0
, *r1
, *r2
, *r3
;
7173 r0
[5] = r0
[6] = r0
[7] = 0.0f
;
7180 r1
[4] = r1
[6] = r1
[7] = 0.0f
;
7187 r2
[4] = r2
[5] = r2
[7] = 0.0f
;
7194 r3
[4] = r3
[5] = r3
[6] = 0.0f
;
7196 /* Choose pivot - or die. */
7197 if (fabsf(r3
[0]) > fabsf(r2
[0]))
7198 swap_rows(&r3
, &r2
);
7199 if (fabsf(r2
[0]) > fabsf(r1
[0]))
7200 swap_rows(&r2
, &r1
);
7201 if (fabsf(r1
[0]) > fabsf(r0
[0]))
7202 swap_rows(&r1
, &r0
);
7206 /* Eliminate first variable. */
7207 m1
= r1
[0] / r0
[0]; m2
= r2
[0] / r0
[0]; m3
= r3
[0] / r0
[0];
7208 s
= r0
[1]; r1
[1] -= m1
* s
; r2
[1] -= m2
* s
; r3
[1] -= m3
* s
;
7209 s
= r0
[2]; r1
[2] -= m1
* s
; r2
[2] -= m2
* s
; r3
[2] -= m3
* s
;
7210 s
= r0
[3]; r1
[3] -= m1
* s
; r2
[3] -= m2
* s
; r3
[3] -= m3
* s
;
7240 /* Choose pivot - or die. */
7241 if (fabsf(r3
[1]) > fabsf(r2
[1]))
7242 swap_rows(&r3
, &r2
);
7243 if (fabsf(r2
[1]) > fabsf(r1
[1]))
7244 swap_rows(&r2
, &r1
);
7248 /* Eliminate second variable. */
7249 m2
= r2
[1] / r1
[1]; m3
= r3
[1] / r1
[1];
7250 r2
[2] -= m2
* r1
[2]; r3
[2] -= m3
* r1
[2];
7251 r2
[3] -= m2
* r1
[3]; r3
[3] -= m3
* r1
[3];
7277 /* Choose pivot - or die. */
7278 if (fabsf(r3
[2]) > fabsf(r2
[2]))
7279 swap_rows(&r3
, &r2
);
7283 /* Eliminate third variable. */
7285 r3
[3] -= m3
* r2
[3];
7286 r3
[4] -= m3
* r2
[4];
7287 r3
[5] -= m3
* r2
[5];
7288 r3
[6] -= m3
* r2
[6];
7289 r3
[7] -= m3
* r2
[7];
7295 /* Back substitute row 3. */
7302 /* Back substitute row 2. */
7305 r2
[4] = s
* (r2
[4] - r3
[4] * m2
);
7306 r2
[5] = s
* (r2
[5] - r3
[5] * m2
);
7307 r2
[6] = s
* (r2
[6] - r3
[6] * m2
);
7308 r2
[7] = s
* (r2
[7] - r3
[7] * m2
);
7310 r1
[4] -= r3
[4] * m1
;
7311 r1
[5] -= r3
[5] * m1
;
7312 r1
[6] -= r3
[6] * m1
;
7313 r1
[7] -= r3
[7] * m1
;
7315 r0
[4] -= r3
[4] * m0
;
7316 r0
[5] -= r3
[5] * m0
;
7317 r0
[6] -= r3
[6] * m0
;
7318 r0
[7] -= r3
[7] * m0
;
7320 /* Back substitute row 1. */
7323 r1
[4] = s
* (r1
[4] - r2
[4] * m1
);
7324 r1
[5] = s
* (r1
[5] - r2
[5] * m1
);
7325 r1
[6] = s
* (r1
[6] - r2
[6] * m1
);
7326 r1
[7] = s
* (r1
[7] - r2
[7] * m1
);
7328 r0
[4] -= r2
[4] * m0
;
7329 r0
[5] -= r2
[5] * m0
;
7330 r0
[6] -= r2
[6] * m0
;
7331 r0
[7] -= r2
[7] * m0
;
7333 /* Back substitute row 0. */
7336 r0
[4] = s
* (r0
[4] - r1
[4] * m0
);
7337 r0
[5] = s
* (r0
[5] - r1
[5] * m0
);
7338 r0
[6] = s
* (r0
[6] - r1
[6] * m0
);
7339 r0
[7] = s
* (r0
[7] - r1
[7] * m0
);
7361 /* Taken and adapted from Mesa. */
7362 static BOOL
invert_matrix_3d(struct wined3d_matrix
*out
, const struct wined3d_matrix
*in
)
7364 float pos
, neg
, t
, det
;
7365 struct wined3d_matrix temp
;
7367 /* Calculate the determinant of upper left 3x3 submatrix and
7368 * determine if the matrix is singular. */
7370 t
= in
->_11
* in
->_22
* in
->_33
;
7376 t
= in
->_21
* in
->_32
* in
->_13
;
7381 t
= in
->_31
* in
->_12
* in
->_23
;
7387 t
= -in
->_31
* in
->_22
* in
->_13
;
7392 t
= -in
->_21
* in
->_12
* in
->_33
;
7398 t
= -in
->_11
* in
->_32
* in
->_23
;
7406 if (fabsf(det
) < 1e-25f
)
7410 temp
._11
= (in
->_22
* in
->_33
- in
->_32
* in
->_23
) * det
;
7411 temp
._12
= -(in
->_12
* in
->_33
- in
->_32
* in
->_13
) * det
;
7412 temp
._13
= (in
->_12
* in
->_23
- in
->_22
* in
->_13
) * det
;
7413 temp
._21
= -(in
->_21
* in
->_33
- in
->_31
* in
->_23
) * det
;
7414 temp
._22
= (in
->_11
* in
->_33
- in
->_31
* in
->_13
) * det
;
7415 temp
._23
= -(in
->_11
* in
->_23
- in
->_21
* in
->_13
) * det
;
7416 temp
._31
= (in
->_21
* in
->_32
- in
->_31
* in
->_22
) * det
;
7417 temp
._32
= -(in
->_11
* in
->_32
- in
->_31
* in
->_12
) * det
;
7418 temp
._33
= (in
->_11
* in
->_22
- in
->_21
* in
->_12
) * det
;
7424 void compute_normal_matrix(float *normal_matrix
, BOOL legacy_lighting
,
7425 const struct wined3d_matrix
*modelview
)
7427 struct wined3d_matrix mv
;
7431 if (legacy_lighting
)
7432 invert_matrix_3d(&mv
, &mv
);
7434 invert_matrix(&mv
, &mv
);
7435 /* Tests show that singular modelview matrices are used unchanged as normal
7436 * matrices on D3D3 and older. There seems to be no clearly consistent
7437 * behavior on newer D3D versions so always follow older ddraw behavior. */
7438 for (i
= 0; i
< 3; ++i
)
7439 for (j
= 0; j
< 3; ++j
)
7440 normal_matrix
[i
* 3 + j
] = (&mv
._11
)[j
* 4 + i
];
7443 static void wined3d_allocator_release_block(struct wined3d_allocator
*allocator
,
7444 struct wined3d_allocator_block
*block
)
7446 block
->parent
= allocator
->free
;
7447 allocator
->free
= block
;
7450 static struct wined3d_allocator_block
*wined3d_allocator_acquire_block(struct wined3d_allocator
*allocator
)
7452 struct wined3d_allocator_block
*block
;
7454 if (!allocator
->free
)
7455 return heap_alloc(sizeof(*block
));
7457 block
= allocator
->free
;
7458 allocator
->free
= block
->parent
;
7463 void wined3d_allocator_block_free(struct wined3d_allocator_block
*block
)
7465 struct wined3d_allocator
*allocator
= block
->chunk
->allocator
;
7466 struct wined3d_allocator_block
*parent
;
7468 while ((parent
= block
->parent
) && block
->sibling
->free
)
7470 list_remove(&block
->sibling
->entry
);
7471 wined3d_allocator_release_block(allocator
, block
->sibling
);
7472 wined3d_allocator_release_block(allocator
, block
);
7477 list_add_head(&block
->chunk
->available
[block
->order
], &block
->entry
);
7480 static void wined3d_allocator_block_init(struct wined3d_allocator_block
*block
,
7481 struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator_block
*parent
,
7482 struct wined3d_allocator_block
*sibling
, unsigned int order
, size_t offset
, bool free
)
7484 list_init(&block
->entry
);
7485 block
->chunk
= chunk
;
7486 block
->parent
= parent
;
7487 block
->sibling
= sibling
;
7488 block
->order
= order
;
7489 block
->offset
= offset
;
7493 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk
*chunk
)
7495 struct wined3d_allocator_block
*block
;
7498 if (list_empty(&chunk
->available
[0]))
7500 ERR("Chunk %p is not empty.\n", chunk
);
7504 for (i
= 1; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7506 if (!list_empty(&chunk
->available
[i
]))
7508 ERR("Chunk %p is not empty.\n", chunk
);
7513 block
= LIST_ENTRY(list_head(&chunk
->available
[0]), struct wined3d_allocator_block
, entry
);
7514 wined3d_allocator_release_block(chunk
->allocator
, block
);
7517 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator
*allocator
)
7519 struct wined3d_allocator_block
*block
;
7522 if (!(block
= wined3d_allocator_acquire_block(allocator
)))
7524 wined3d_allocator_block_init(block
, chunk
, NULL
, NULL
, 0, 0, true);
7526 list_init(&chunk
->entry
);
7527 for (i
= 0; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7529 list_init(&chunk
->available
[i
]);
7531 list_add_head(&chunk
->available
[0], &block
->entry
);
7532 chunk
->allocator
= allocator
;
7533 chunk
->map_count
= 0;
7534 chunk
->map_ptr
= NULL
;
7539 void wined3d_allocator_cleanup(struct wined3d_allocator
*allocator
)
7541 struct wined3d_allocator_chunk
*chunk
, *chunk2
;
7542 struct wined3d_allocator_block
*block
, *next
;
7545 for (i
= 0; i
< allocator
->pool_count
; ++i
)
7547 LIST_FOR_EACH_ENTRY_SAFE(chunk
, chunk2
, &allocator
->pools
[i
].chunks
, struct wined3d_allocator_chunk
, entry
)
7549 list_remove(&chunk
->entry
);
7550 allocator
->ops
->allocator_destroy_chunk(chunk
);
7553 heap_free(allocator
->pools
);
7555 next
= allocator
->free
;
7556 while ((block
= next
))
7558 next
= block
->parent
;
7563 static struct wined3d_allocator_block
*wined3d_allocator_chunk_allocate(struct wined3d_allocator_chunk
*chunk
,
7566 struct wined3d_allocator_block
*block
, *left
, *right
;
7567 unsigned int i
= order
;
7571 if (!list_empty(&chunk
->available
[i
]))
7576 if (list_empty(&chunk
->available
[i
]))
7579 block
= LIST_ENTRY(list_head(&chunk
->available
[i
]), struct wined3d_allocator_block
, entry
);
7580 list_remove(&block
->entry
);
7581 block
->free
= false;
7585 if (!(left
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7587 ERR("Failed to allocate left.\n");
7591 if (!(right
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7593 ERR("Failed to allocate right.\n");
7594 wined3d_allocator_release_block(chunk
->allocator
, left
);
7598 wined3d_allocator_block_init(left
, chunk
, block
, right
, block
->order
+ 1, block
->offset
, false);
7599 wined3d_allocator_block_init(right
, chunk
, block
, left
, block
->order
+ 1,
7600 block
->offset
+ (WINED3D_ALLOCATOR_CHUNK_SIZE
>> left
->order
), true);
7601 list_add_head(&chunk
->available
[right
->order
], &right
->entry
);
7610 struct wined3d_allocator_block
*wined3d_allocator_allocate(struct wined3d_allocator
*allocator
,
7611 struct wined3d_context
*context
, unsigned int memory_type
, size_t size
)
7613 struct wined3d_allocator_chunk
*chunk
;
7614 struct wined3d_allocator_block
*block
;
7617 if (size
> WINED3D_ALLOCATOR_CHUNK_SIZE
/ 2)
7620 if (size
< WINED3D_ALLOCATOR_MIN_BLOCK_SIZE
)
7621 order
= WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT
- 1;
7623 order
= wined3d_log2i(WINED3D_ALLOCATOR_CHUNK_SIZE
/ size
);
7625 LIST_FOR_EACH_ENTRY(chunk
, &allocator
->pools
[memory_type
].chunks
, struct wined3d_allocator_chunk
, entry
)
7627 if ((block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7631 if (!(chunk
= allocator
->ops
->allocator_create_chunk(allocator
,
7632 context
, memory_type
, WINED3D_ALLOCATOR_CHUNK_SIZE
)))
7635 if (!(block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7641 bool wined3d_allocator_init(struct wined3d_allocator
*allocator
,
7642 size_t pool_count
, const struct wined3d_allocator_ops
*allocator_ops
)
7646 allocator
->ops
= allocator_ops
;
7647 allocator
->pool_count
= pool_count
;
7648 if (!(allocator
->pools
= heap_calloc(pool_count
, sizeof(*allocator
->pools
))))
7650 for (i
= 0; i
< pool_count
; ++i
)
7652 list_init(&allocator
->pools
[i
].chunks
);
7655 allocator
->free
= NULL
;