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"
30 #include "wined3d_gl.h"
31 #include "wined3d_vk.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
35 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
39 enum wined3d_format_id id
;
42 format_index_remap
[] =
44 {WINED3DFMT_UYVY
, WINED3D_FORMAT_FOURCC_BASE
},
45 {WINED3DFMT_YUY2
, WINED3D_FORMAT_FOURCC_BASE
+ 1},
46 {WINED3DFMT_YV12
, WINED3D_FORMAT_FOURCC_BASE
+ 2},
47 {WINED3DFMT_DXT1
, WINED3D_FORMAT_FOURCC_BASE
+ 3},
48 {WINED3DFMT_DXT2
, WINED3D_FORMAT_FOURCC_BASE
+ 4},
49 {WINED3DFMT_DXT3
, WINED3D_FORMAT_FOURCC_BASE
+ 5},
50 {WINED3DFMT_DXT4
, WINED3D_FORMAT_FOURCC_BASE
+ 6},
51 {WINED3DFMT_DXT5
, WINED3D_FORMAT_FOURCC_BASE
+ 7},
52 {WINED3DFMT_MULTI2_ARGB8
, WINED3D_FORMAT_FOURCC_BASE
+ 8},
53 {WINED3DFMT_G8R8_G8B8
, WINED3D_FORMAT_FOURCC_BASE
+ 9},
54 {WINED3DFMT_R8G8_B8G8
, WINED3D_FORMAT_FOURCC_BASE
+ 10},
55 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_FOURCC_BASE
+ 11},
56 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_FOURCC_BASE
+ 12},
57 {WINED3DFMT_INST
, WINED3D_FORMAT_FOURCC_BASE
+ 13},
58 {WINED3DFMT_NVDB
, WINED3D_FORMAT_FOURCC_BASE
+ 14},
59 {WINED3DFMT_NVHU
, WINED3D_FORMAT_FOURCC_BASE
+ 15},
60 {WINED3DFMT_NVHS
, WINED3D_FORMAT_FOURCC_BASE
+ 16},
61 {WINED3DFMT_INTZ
, WINED3D_FORMAT_FOURCC_BASE
+ 17},
62 {WINED3DFMT_RESZ
, WINED3D_FORMAT_FOURCC_BASE
+ 18},
63 {WINED3DFMT_NULL
, WINED3D_FORMAT_FOURCC_BASE
+ 19},
64 {WINED3DFMT_R16
, WINED3D_FORMAT_FOURCC_BASE
+ 20},
65 {WINED3DFMT_AL16
, WINED3D_FORMAT_FOURCC_BASE
+ 21},
66 {WINED3DFMT_NV12
, WINED3D_FORMAT_FOURCC_BASE
+ 22},
67 {WINED3DFMT_ATOC
, WINED3D_FORMAT_FOURCC_BASE
+ 23},
70 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
72 struct wined3d_format_channels
74 enum wined3d_format_id id
;
75 DWORD red_size
, green_size
, blue_size
, alpha_size
;
76 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
78 BYTE depth_size
, stencil_size
;
82 static const struct wined3d_format_channels formats
[] =
85 * format id r g b a r g b a bpp z s channels */
86 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
89 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
90 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
99 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
101 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
102 {WINED3DFMT_R11G11B10_FLOAT
, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0, "FFF"},
103 /* Palettized formats */
104 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
105 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
106 /* Standard ARGB formats. */
107 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0, "uuu"},
108 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0, "uuu"},
109 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0, "uuuX"},
110 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0, "uuuu"},
111 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0, "uuuu"},
112 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0, "uuu"},
113 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0, "u"},
114 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0, "uuuu"},
115 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0, "uuuX"},
116 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0, "uuuX"},
117 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0, "uuuu"},
119 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
120 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
121 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
122 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
123 /* Bump mapping stuff */
124 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
125 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
126 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0, "iii"},
127 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0, "iiiu"},
128 /* Depth stencil formats */
129 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0, "D"},
130 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0, "D"},
131 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1, "SD"},
132 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0, "XD"},
133 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4, "SXD"},
134 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8, "SD"},
135 /* Vendor-specific formats */
136 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
137 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
138 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_ATOC
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
140 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
141 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
142 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
143 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
145 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
146 /* Unsure about them, could not find a Windows driver that supports them */
147 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
149 /* DirectX 10 HDR formats */
150 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
152 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
153 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
154 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
155 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
156 {WINED3DFMT_R32G8X24_TYPELESS
, 32, 8, 0, 0, 0, 0, 0, 0, 8, 0, 0},
157 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
158 {WINED3DFMT_R10G10B10X2_TYPELESS
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
159 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
160 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R24G8_TYPELESS
, 24, 8, 0, 0, 0, 0, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
164 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
165 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
174 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
177 struct wined3d_typed_format_info
179 enum wined3d_format_id id
;
180 enum wined3d_format_id typeless_id
;
181 const char *channels
;
185 * The last entry for a given typeless format defines its internal format.
187 * u - WINED3D_CHANNEL_TYPE_UNORM
188 * i - WINED3D_CHANNEL_TYPE_SNORM
189 * U - WINED3D_CHANNEL_TYPE_UINT
190 * I - WINED3D_CHANNEL_TYPE_SINT
191 * F - WINED3D_CHANNEL_TYPE_FLOAT
192 * D - WINED3D_CHANNEL_TYPE_DEPTH
193 * S - WINED3D_CHANNEL_TYPE_STENCIL
194 * X - WINED3D_CHANNEL_TYPE_UNUSED
196 static const struct wined3d_typed_format_info typed_formats
[] =
198 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
199 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
200 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
201 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
202 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
203 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
204 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
205 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
206 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
207 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
208 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
209 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
210 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
211 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
212 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "FXX"},
213 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XUX"},
214 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DSX"},
215 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
216 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
217 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
218 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3DFMT_R10G10B10X2_TYPELESS
, "iiiX"},
219 {WINED3DFMT_R10G10B10X2_UINT
, WINED3DFMT_R10G10B10X2_TYPELESS
, "UUUX"},
220 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
221 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
222 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "iiii"},
223 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
224 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
225 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
226 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
227 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
228 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
229 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
230 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
231 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
232 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
233 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
234 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "uX"},
235 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XU"},
236 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
237 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
238 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
239 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
240 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
241 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
242 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
243 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
244 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
245 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
246 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
247 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
248 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
249 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
250 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
251 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
252 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
253 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
254 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
255 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
256 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
257 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
258 {WINED3DFMT_BC4_SNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
259 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
260 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
261 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
262 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
263 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
264 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
265 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
266 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
267 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
268 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
271 struct wined3d_typeless_format_depth_stencil_info
273 enum wined3d_format_id typeless_id
;
274 enum wined3d_format_id depth_stencil_id
;
275 enum wined3d_format_id depth_view_id
;
276 enum wined3d_format_id stencil_view_id
;
277 BOOL separate_depth_view_format
;
280 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
282 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
283 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
, TRUE
},
284 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
285 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
, TRUE
},
286 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_FLOAT
},
287 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_UNORM
},
290 struct wined3d_format_ddi_info
292 enum wined3d_format_id id
;
293 D3DDDIFORMAT ddi_format
;
296 static const struct wined3d_format_ddi_info ddi_formats
[] =
298 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
299 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
300 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
301 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
302 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
303 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
304 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
305 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
306 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
309 struct wined3d_format_base_flags
311 enum wined3d_format_id id
;
316 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
317 * still needs to use the correct block based calculation for e.g. the
319 static const struct wined3d_format_base_flags format_base_flags
[] =
321 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_ATTR_MAPPABLE
| WINED3D_FORMAT_ATTR_BROKEN_PITCH
},
322 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_ATTR_MAPPABLE
| WINED3D_FORMAT_ATTR_BROKEN_PITCH
},
323 {WINED3DFMT_D16_LOCKABLE
, WINED3D_FORMAT_ATTR_MAPPABLE
},
324 {WINED3DFMT_INTZ
, WINED3D_FORMAT_ATTR_MAPPABLE
},
325 {WINED3DFMT_D32_FLOAT
, WINED3D_FORMAT_ATTR_FLOAT
},
326 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3D_FORMAT_ATTR_FLOAT
},
327 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3D_FORMAT_ATTR_FLOAT
},
328 {WINED3DFMT_INST
, WINED3D_FORMAT_ATTR_EXTENSION
},
329 {WINED3DFMT_NULL
, WINED3D_FORMAT_ATTR_EXTENSION
},
330 {WINED3DFMT_NVDB
, WINED3D_FORMAT_ATTR_EXTENSION
},
331 {WINED3DFMT_ATOC
, WINED3D_FORMAT_ATTR_EXTENSION
},
332 {WINED3DFMT_RESZ
, WINED3D_FORMAT_ATTR_EXTENSION
},
333 {WINED3DFMT_R32G32B32A32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
334 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
335 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
336 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
337 {WINED3DFMT_R16G16B16A16_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
338 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
339 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
340 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
341 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
342 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
343 {WINED3DFMT_R32G32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
344 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
345 {WINED3DFMT_R32G32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
346 {WINED3DFMT_R32G32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
347 {WINED3DFMT_R32_TYPELESS
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
348 {WINED3DFMT_R32_FLOAT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
349 {WINED3DFMT_R32_UINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
,
350 WINED3D_FORMAT_CAP_INDEX_BUFFER
},
351 {WINED3DFMT_R32_SINT
, WINED3D_FORMAT_ATTR_CAST_TO_BLOCK
},
352 {WINED3DFMT_R16_UINT
, 0,
353 WINED3D_FORMAT_CAP_INDEX_BUFFER
},
354 {WINED3DFMT_R8G8_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
355 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
356 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
357 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
358 {WINED3DFMT_R16G16_SNORM
, WINED3D_FORMAT_ATTR_BUMPMAP
},
361 static void rgb888_from_rgb565(WORD rgb565
, BYTE
*r
, BYTE
*g
, BYTE
*b
)
365 /* (2⁸ - 1) / (2⁵ - 1) ≈ 2⁸ / 2⁵ + 2⁸ / 2¹⁰
366 * (2⁸ - 1) / (2⁶ - 1) ≈ 2⁸ / 2⁶ + 2⁸ / 2¹² */
368 *r
= (c
<< 3) + (c
>> 2);
369 c
= (rgb565
>> 5) & 0x3f;
370 *g
= (c
<< 2) + (c
>> 4);
372 *b
= (c
<< 3) + (c
>> 2);
375 static void build_dxtn_colour_table(WORD colour0
, WORD colour1
,
376 DWORD colour_table
[4], enum wined3d_format_id format_id
)
384 rgb888_from_rgb565(colour0
, &c
[0].r
, &c
[0].g
, &c
[0].b
);
385 rgb888_from_rgb565(colour1
, &c
[1].r
, &c
[1].g
, &c
[1].b
);
387 if (format_id
== WINED3DFMT_BC1_UNORM
&& colour0
<= colour1
)
389 c
[2].r
= (c
[0].r
+ c
[1].r
) / 2;
390 c
[2].g
= (c
[0].g
+ c
[1].g
) / 2;
391 c
[2].b
= (c
[0].b
+ c
[1].b
) / 2;
399 for (i
= 0; i
< 2; ++i
)
401 c
[i
+ 2].r
= (2 * c
[i
].r
+ c
[1 - i
].r
) / 3;
402 c
[i
+ 2].g
= (2 * c
[i
].g
+ c
[1 - i
].g
) / 3;
403 c
[i
+ 2].b
= (2 * c
[i
].b
+ c
[1 - i
].b
) / 3;
407 for (i
= 0; i
< 4; ++i
)
409 colour_table
[i
] = (c
[i
].r
<< 16) | (c
[i
].g
<< 8) | c
[i
].b
;
413 static void build_bc3_alpha_table(BYTE alpha0
, BYTE alpha1
, BYTE alpha_table
[8])
417 alpha_table
[0] = alpha0
;
418 alpha_table
[1] = alpha1
;
422 for (i
= 0; i
< 6; ++i
)
424 alpha_table
[2 + i
] = ((6 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 7;
430 for (i
= 0; i
< 4; ++i
)
432 alpha_table
[2 + i
] = ((4 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 5;
434 alpha_table
[6] = 0x00;
435 alpha_table
[7] = 0xff;
439 static void decompress_dxtn_block(const BYTE
*src
, BYTE
*dst
, unsigned int width
,
440 unsigned int height
, unsigned int dst_row_pitch
, enum wined3d_format_id format_id
)
442 const UINT64
*s
= (const UINT64
*)src
;
443 BOOL bc1_alpha
= FALSE
;
444 DWORD colour_table
[4];
453 if (format_id
== WINED3DFMT_BC1_UNORM
)
455 WORD colour0
, colour1
;
459 colour0
= s
[0] & 0xffff;
460 colour1
= (s
[0] >> 16) & 0xffff;
461 colour_bits
= (s
[0] >> 32) & 0xffffffff;
462 build_dxtn_colour_table(colour0
, colour1
, colour_table
, format_id
);
463 if (colour0
<= colour1
)
469 if (format_id
== WINED3DFMT_BC3_UNORM
)
471 build_bc3_alpha_table(alpha_bits
& 0xff, (alpha_bits
>> 8) & 0xff, alpha_table
);
475 colour_bits
= (s
[1] >> 32) & 0xffffffff;
476 build_dxtn_colour_table(s
[1] & 0xffff, (s
[1] >> 16) & 0xffff, colour_table
, format_id
);
479 for (y
= 0; y
< height
; ++y
)
481 dst_row
= (DWORD
*)&dst
[y
* dst_row_pitch
];
482 for (x
= 0; x
< width
; ++x
)
484 colour_idx
= (colour_bits
>> (y
* 8 + x
* 2)) & 0x3;
487 case WINED3DFMT_BC1_UNORM
:
488 alpha
= bc1_alpha
&& colour_idx
== 3 ? 0x00 : 0xff;
491 case WINED3DFMT_BC2_UNORM
:
492 alpha
= (alpha_bits
>> (y
* 16 + x
* 4)) & 0xf;
493 /* (2⁸ - 1) / (2⁴ - 1) ≈ 2⁸ / 2⁴ + 2⁸ / 2⁸ */
497 case WINED3DFMT_BC3_UNORM
:
498 alpha
= alpha_table
[(alpha_bits
>> (y
* 12 + x
* 3)) & 0x7];
505 dst_row
[x
] = (alpha
<< 24) | colour_table
[colour_idx
];
510 static void decompress_dxtn(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
511 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
512 unsigned int width
, unsigned int height
, unsigned int depth
, enum wined3d_format_id format_id
)
514 unsigned int block_byte_count
, block_w
, block_h
;
515 const BYTE
*src_row
, *src_slice
= src
;
516 BYTE
*dst_row
, *dst_slice
= dst
;
517 unsigned int x
, y
, z
;
519 block_byte_count
= format_id
== WINED3DFMT_BC1_UNORM
? 8 : 16;
521 for (z
= 0; z
< depth
; ++z
)
525 for (y
= 0; y
< height
; y
+= 4)
527 for (x
= 0; x
< width
; x
+= 4)
529 block_w
= min(width
- x
, 4);
530 block_h
= min(height
- y
, 4);
531 decompress_dxtn_block(&src_row
[x
* (block_byte_count
/ 4)],
532 &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
, format_id
);
534 src_row
+= src_row_pitch
;
535 dst_row
+= dst_row_pitch
* 4;
537 src_slice
+= src_slice_pitch
;
538 dst_slice
+= dst_slice_pitch
;
542 static void decompress_bc3(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
543 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
544 unsigned int width
, unsigned int height
, unsigned int depth
)
546 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
547 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC3_UNORM
);
550 static void decompress_bc2(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
551 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
552 unsigned int width
, unsigned int height
, unsigned int depth
)
554 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
555 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC2_UNORM
);
558 static void decompress_bc1(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
559 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
560 unsigned int width
, unsigned int height
, unsigned int depth
)
562 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
563 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC1_UNORM
);
566 static void build_rgtc_colour_table(uint8_t red0
, uint8_t red1
, uint8_t colour_table
[8])
570 colour_table
[0] = red0
;
571 colour_table
[1] = red1
;
574 for (i
= 0; i
< 4; ++i
)
576 colour_table
[i
+ 2] = ((8 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 5) / 10;
578 colour_table
[6] = 0x00;
579 colour_table
[7] = 0xff;
583 for (i
= 0; i
< 6; ++i
)
585 colour_table
[i
+ 2] = ((12 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 7) / 14;
590 static void decompress_rgtc_block(const uint8_t *src
, uint8_t *dst
,
591 unsigned int width
, unsigned int height
, unsigned int dst_row_pitch
)
593 const uint64_t *s
= (const uint64_t *)src
;
594 uint8_t red0
, red1
, red_idx
;
595 uint8_t colour_table
[8];
601 red1
= (s
[0] >> 8) & 0xff;
603 build_rgtc_colour_table(red0
, red1
, colour_table
);
605 for (y
= 0; y
< height
; ++y
)
607 dst_row
= (uint32_t *)&dst
[y
* dst_row_pitch
];
608 for (x
= 0; x
< width
; ++x
)
610 red_idx
= (bits
>> (y
* 12 + x
* 3)) & 0x7;
611 /* Decompressing to bgra32 is perhaps not ideal for RGTC formats.
612 * It's convenient though. */
613 dst_row
[x
] = 0xff000000 | (colour_table
[red_idx
] << 16);
618 static void decompress_bc4(const uint8_t *src
, uint8_t *dst
, unsigned int src_row_pitch
,
619 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
620 unsigned int width
, unsigned int height
, unsigned int depth
)
622 unsigned int block_w
, block_h
, x
, y
, z
;
623 const uint8_t *src_row
, *src_slice
;
624 uint8_t *dst_row
, *dst_slice
;
626 for (z
= 0; z
< depth
; ++z
)
628 src_slice
= &src
[z
* src_slice_pitch
];
629 dst_slice
= &dst
[z
* dst_slice_pitch
];
630 for (y
= 0; y
< height
; y
+= 4)
632 src_row
= &src_slice
[(y
/ 4) * src_row_pitch
];
633 dst_row
= &dst_slice
[y
* dst_row_pitch
];
634 for (x
= 0; x
< width
; x
+= 4)
636 block_w
= min(width
- x
, 4);
637 block_h
= min(height
- y
, 4);
638 decompress_rgtc_block(&src_row
[(x
/ 4) * 8], &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
);
644 static const struct wined3d_format_decompress_info
646 enum wined3d_format_id id
;
647 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
648 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
649 unsigned int width
, unsigned int height
, unsigned int depth
);
651 format_decompress_info
[] =
653 {WINED3DFMT_DXT1
, decompress_bc1
},
654 {WINED3DFMT_DXT2
, decompress_bc2
},
655 {WINED3DFMT_DXT3
, decompress_bc2
},
656 {WINED3DFMT_DXT4
, decompress_bc3
},
657 {WINED3DFMT_DXT5
, decompress_bc3
},
658 {WINED3DFMT_BC1_UNORM
, decompress_bc1
},
659 {WINED3DFMT_BC2_UNORM
, decompress_bc2
},
660 {WINED3DFMT_BC3_UNORM
, decompress_bc3
},
661 {WINED3DFMT_BC4_UNORM
, decompress_bc4
},
664 struct wined3d_format_block_info
666 enum wined3d_format_id id
;
669 UINT block_byte_count
;
673 static const struct wined3d_format_block_info format_block_info
[] =
675 {WINED3DFMT_DXT1
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
676 {WINED3DFMT_DXT2
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
677 {WINED3DFMT_DXT3
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
678 {WINED3DFMT_DXT4
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
679 {WINED3DFMT_DXT5
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
680 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
681 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
682 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
683 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
684 {WINED3DFMT_BC4_SNORM
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
},
685 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
686 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
687 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
688 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
689 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
},
690 {WINED3DFMT_ATI1N
, 4, 4, 8, WINED3D_FORMAT_ATTR_COMPRESSED
| WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
691 {WINED3DFMT_ATI2N
, 4, 4, 16, WINED3D_FORMAT_ATTR_COMPRESSED
| WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
692 {WINED3DFMT_YUY2
, 2, 1, 4, WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
693 {WINED3DFMT_UYVY
, 2, 1, 4, WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
},
694 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 1, 1, 4},
697 struct wined3d_format_vertex_info
699 enum wined3d_format_id id
;
700 enum wined3d_ffp_emit_idx emit_idx
;
702 enum wined3d_gl_extension extension
;
705 static const struct wined3d_format_vertex_info format_vertex_info
[] =
707 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, GL_FLOAT
},
708 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, GL_FLOAT
},
709 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, GL_FLOAT
},
710 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, GL_FLOAT
},
711 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, GL_UNSIGNED_BYTE
},
712 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, GL_UNSIGNED_BYTE
},
713 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
714 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, GL_SHORT
},
715 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, GL_SHORT
},
716 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, GL_UNSIGNED_BYTE
},
717 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, GL_SHORT
},
718 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, GL_SHORT
},
719 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, GL_UNSIGNED_SHORT
},
720 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, GL_UNSIGNED_SHORT
},
721 {WINED3DFMT_R11G11B10_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_10F_11F_11F_REV
,
722 ARB_VERTEX_TYPE_10F_11F_11F_REV
},
723 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, GL_UNSIGNED_SHORT
},
724 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, GL_SHORT
},
725 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_2_10_10_10_REV
,
726 ARB_VERTEX_TYPE_2_10_10_10_REV
},
727 /* Without ARB_half_float_vertex we convert these on upload. */
728 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_FLOAT
},
729 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
730 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_FLOAT
},
731 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
732 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
733 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
734 {WINED3DFMT_R8G8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
735 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
736 {WINED3DFMT_R8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
737 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
738 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
739 {WINED3DFMT_R8G8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
740 {WINED3DFMT_R16_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
741 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
742 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_SHORT
},
743 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
744 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
745 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
746 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
747 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
748 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
749 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
752 struct wined3d_format_texture_info
754 enum wined3d_format_id id
;
756 GLint gl_srgb_internal
;
757 GLint gl_rt_internal
;
760 unsigned int conv_byte_count
;
762 enum wined3d_gl_extension extension
;
763 void (*upload
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
764 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
765 unsigned int width
, unsigned int height
, unsigned int depth
);
766 void (*download
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
767 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
768 unsigned int width
, unsigned int height
, unsigned int depth
);
769 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
770 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
771 unsigned int width
, unsigned int height
, unsigned int depth
);
774 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
775 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
777 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
778 * format+type combination to load it. Thus convert it to A8L8, then load it
779 * with A4L4 internal, but A8L8 format+type
781 unsigned int x
, y
, z
;
782 const unsigned char *Source
;
785 for (z
= 0; z
< depth
; z
++)
787 for (y
= 0; y
< height
; y
++)
789 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
790 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
791 for (x
= 0; x
< width
; x
++ )
793 unsigned char color
= (*Source
++);
794 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
795 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
802 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
803 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
805 unsigned int x
, y
, z
;
806 unsigned char r_in
, g_in
, l_in
;
807 const unsigned short *texel_in
;
808 unsigned short *texel_out
;
810 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
811 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
812 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
813 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
814 for (z
= 0; z
< depth
; z
++)
816 for (y
= 0; y
< height
; y
++)
818 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
819 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
820 for (x
= 0; x
< width
; x
++ )
822 l_in
= (*texel_in
& 0xfc00u
) >> 10;
823 g_in
= (*texel_in
& 0x03e0u
) >> 5;
824 r_in
= *texel_in
& 0x001fu
;
826 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
834 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
835 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
837 unsigned int x
, y
, z
;
838 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
839 const unsigned short *texel_in
;
841 for (z
= 0; z
< depth
; z
++)
843 for (y
= 0; y
< height
; y
++)
845 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
846 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
847 for (x
= 0; x
< width
; x
++ )
849 l_in
= (*texel_in
& 0xfc00u
) >> 10;
850 g_in
= (*texel_in
& 0x03e0u
) >> 5;
851 r_in
= *texel_in
& 0x001fu
;
854 if (!(r_in
& 0x10)) /* r > 0 */
858 if (!(g_in
& 0x10)) /* g > 0 */
861 texel_out
[0] = r_out
;
862 texel_out
[1] = g_out
;
863 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
873 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
874 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
876 unsigned int x
, y
, z
;
877 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
878 const unsigned short *texel_in
;
880 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
881 * fixed function and shaders without further conversion once the surface is
884 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
885 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
886 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
887 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
888 for (z
= 0; z
< depth
; z
++)
890 for (y
= 0; y
< height
; y
++)
892 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
893 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
894 for (x
= 0; x
< width
; x
++ )
896 l_in
= (*texel_in
& 0xfc00u
) >> 10;
897 g_in
= (*texel_in
& 0x03e0u
) >> 5;
898 r_in
= *texel_in
& 0x001fu
;
901 if (!(r_in
& 0x10)) /* r > 0 */
905 if (!(g_in
& 0x10)) /* g > 0 */
908 texel_out
[0] = ds_out
;
909 texel_out
[1] = dt_out
;
910 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
919 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
920 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
922 unsigned int x
, y
, z
;
926 for (z
= 0; z
< depth
; z
++)
928 for (y
= 0; y
< height
; y
++)
930 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
931 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
932 for (x
= 0; x
< width
; x
++ )
934 const short color
= (*Source
++);
935 /* B */ Dest
[0] = 0xff;
936 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
937 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
944 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
945 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
947 unsigned int x
, y
, z
;
951 /* Doesn't work correctly with the fixed function pipeline, but can work in
952 * shaders if the shader is adjusted. (There's no use for this format in gl's
953 * standard fixed function pipeline anyway).
955 for (z
= 0; z
< depth
; z
++)
957 for (y
= 0; y
< height
; y
++)
959 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
960 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
961 for (x
= 0; x
< width
; x
++ )
963 LONG color
= (*Source
++);
964 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
965 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
966 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
973 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
974 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
976 unsigned int x
, y
, z
;
980 /* This implementation works with the fixed function pipeline and shaders
981 * without further modification after converting the surface.
983 for (z
= 0; z
< depth
; z
++)
985 for (y
= 0; y
< height
; y
++)
987 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
988 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
989 for (x
= 0; x
< width
; x
++ )
991 LONG color
= (*Source
++);
992 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
993 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
994 /* U */ Dest
[0] = (color
& 0xff); /* U */
995 /* I */ Dest
[3] = 255; /* X */
1002 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1003 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1005 unsigned int x
, y
, z
;
1006 const DWORD
*Source
;
1007 unsigned char *Dest
;
1009 for (z
= 0; z
< depth
; z
++)
1011 for (y
= 0; y
< height
; y
++)
1013 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1014 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
1015 for (x
= 0; x
< width
; x
++ )
1017 LONG color
= (*Source
++);
1018 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
1019 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
1020 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
1021 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
1028 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1029 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1031 unsigned int x
, y
, z
;
1032 const DWORD
*Source
;
1033 unsigned short *Dest
;
1035 for (z
= 0; z
< depth
; z
++)
1037 for (y
= 0; y
< height
; y
++)
1039 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1040 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1041 for (x
= 0; x
< width
; x
++ )
1043 const DWORD color
= (*Source
++);
1044 /* B */ Dest
[0] = 0xffff;
1045 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
1046 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
1053 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1054 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1056 unsigned int x
, y
, z
;
1060 for (z
= 0; z
< depth
; z
++)
1062 for (y
= 0; y
< height
; y
++)
1064 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1065 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1066 for (x
= 0; x
< width
; x
++ )
1068 WORD green
= (*Source
++);
1069 WORD red
= (*Source
++);
1072 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
1073 * shader overwrites it anyway */
1081 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1082 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1084 unsigned int x
, y
, z
;
1085 const float *Source
;
1088 for (z
= 0; z
< depth
; z
++)
1090 for (y
= 0; y
< height
; y
++)
1092 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1093 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1094 for (x
= 0; x
< width
; x
++ )
1096 float green
= (*Source
++);
1097 float red
= (*Source
++);
1107 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1108 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1110 unsigned int x
, y
, z
;
1112 for (z
= 0; z
< depth
; z
++)
1114 for (y
= 0; y
< height
; ++y
)
1116 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1117 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1118 DWORD
*dest_s
= (DWORD
*)dest_f
;
1120 for (x
= 0; x
< width
; ++x
)
1122 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
1123 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
1129 static void x8_d24_unorm_upload(const BYTE
*src
, BYTE
*dst
,
1130 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1131 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1132 unsigned int width
, unsigned int height
, unsigned int depth
)
1134 unsigned int x
, y
, z
;
1136 for (z
= 0; z
< depth
; ++z
)
1138 for (y
= 0; y
< height
; ++y
)
1140 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1141 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1143 for (x
= 0; x
< width
; ++x
)
1145 dest
[x
] = source
[x
] << 8 | ((source
[x
] >> 16) & 0xff);
1151 static void x8_d24_unorm_download(const BYTE
*src
, BYTE
*dst
,
1152 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1153 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1154 unsigned int width
, unsigned int height
, unsigned int depth
)
1156 unsigned int x
, y
, z
;
1158 for (z
= 0; z
< depth
; ++z
)
1160 for (y
= 0; y
< height
; ++y
)
1162 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1163 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1165 for (x
= 0; x
< width
; ++x
)
1167 dest
[x
] = source
[x
] >> 8;
1173 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
1175 /* FIXME: Is this really how color keys are supposed to work? I think it
1176 * makes more sense to compare the individual channels. */
1177 return color
>= color_key
->color_space_low_value
1178 && color
<= color_key
->color_space_high_value
;
1181 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1182 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1183 const struct wined3d_color_key
*color_key
)
1185 const WORD
*src_row
;
1189 for (y
= 0; y
< height
; ++y
)
1191 src_row
= (WORD
*)&src
[src_pitch
* y
];
1192 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1193 for (x
= 0; x
< width
; ++x
)
1195 WORD src_color
= src_row
[x
];
1196 if (!color_in_range(color_key
, src_color
))
1197 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1199 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1204 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1205 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1206 const struct wined3d_color_key
*color_key
)
1208 const WORD
*src_row
;
1212 for (y
= 0; y
< height
; ++y
)
1214 src_row
= (WORD
*)&src
[src_pitch
* y
];
1215 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1216 for (x
= 0; x
< width
; ++x
)
1218 WORD src_color
= src_row
[x
];
1219 if (color_in_range(color_key
, src_color
))
1220 dst_row
[x
] = src_color
& ~0x8000;
1222 dst_row
[x
] = src_color
| 0x8000;
1227 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1228 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1229 const struct wined3d_color_key
*color_key
)
1231 const BYTE
*src_row
;
1235 for (y
= 0; y
< height
; ++y
)
1237 src_row
= &src
[src_pitch
* y
];
1238 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1239 for (x
= 0; x
< width
; ++x
)
1241 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
1242 if (!color_in_range(color_key
, src_color
))
1243 dst_row
[x
] = src_color
| 0xff000000;
1248 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1249 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1250 const struct wined3d_color_key
*color_key
)
1252 const DWORD
*src_row
;
1256 for (y
= 0; y
< height
; ++y
)
1258 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1259 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1260 for (x
= 0; x
< width
; ++x
)
1262 DWORD src_color
= src_row
[x
];
1263 if (color_in_range(color_key
, src_color
))
1264 dst_row
[x
] = src_color
& ~0xff000000;
1266 dst_row
[x
] = src_color
| 0xff000000;
1271 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1272 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1273 const struct wined3d_color_key
*color_key
)
1275 const DWORD
*src_row
;
1279 for (y
= 0; y
< height
; ++y
)
1281 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1282 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1283 for (x
= 0; x
< width
; ++x
)
1285 DWORD src_color
= src_row
[x
];
1286 if (color_in_range(color_key
, src_color
))
1287 src_color
&= ~0xff000000;
1288 dst_row
[x
] = src_color
;
1293 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
1294 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
1296 const struct wined3d_format
*format
= texture
->resource
.format
;
1301 enum wined3d_format_id src_format
;
1302 struct wined3d_color_key_conversion conversion
;
1306 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1307 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1308 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1309 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1310 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1313 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1315 for (i
= 0; i
< ARRAY_SIZE(color_key_info
); ++i
)
1317 if (color_key_info
[i
].src_format
== format
->id
)
1318 return &color_key_info
[i
].conversion
;
1321 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1327 /* We intentionally don't support WINED3DFMT_D32_UNORM. No hardware driver
1328 * supports it, and applications get confused when we do.
1330 * The following formats explicitly don't have WINED3D_FORMAT_CAP_TEXTURE set:
1332 * These are never supported on native.
1333 * WINED3DFMT_B8G8R8_UNORM
1334 * WINED3DFMT_B2G3R3_UNORM
1335 * WINED3DFMT_L4A4_UNORM
1336 * WINED3DFMT_S1_UINT_D15_UNORM
1337 * WINED3DFMT_S4X4_UINT_D24_UNORM
1339 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1340 * Since it is not widely available, don't offer it. Further no Windows driver
1341 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1342 * WINED3DFMT_P8_UINT
1343 * WINED3DFMT_P8_UINT_A8_UNORM
1345 * These formats seem to be similar to the HILO formats in
1346 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1347 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1348 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1349 * refused to support formats which can easily be emulated with pixel shaders,
1350 * so applications have to deal with not having NVHS and NVHU.
1352 * WINED3DFMT_NVHS */
1353 static const struct wined3d_format_texture_info format_texture_info
[] =
1355 /* format id gl_internal gl_srgb_internal gl_rt_internal
1356 gl_format gl_type conv_byte_count
1358 extension upload download */
1359 /* FourCC formats */
1360 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1361 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1362 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1363 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1366 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1367 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1368 WINED3D_FORMAT_CAP_FILTERING
,
1369 ARB_TEXTURE_RG
, NULL
},
1370 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1371 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1372 WINED3D_FORMAT_CAP_FILTERING
,
1373 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1374 {WINED3DFMT_UYVY
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1375 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1376 WINED3D_FORMAT_CAP_FILTERING
,
1377 APPLE_RGB_422
, NULL
},
1378 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1379 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1380 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_FILTERING
,
1381 APPLE_YCBCR_422
, NULL
},
1382 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1383 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1384 WINED3D_FORMAT_CAP_FILTERING
,
1385 ARB_TEXTURE_RG
, NULL
},
1386 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1387 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1388 WINED3D_FORMAT_CAP_FILTERING
,
1389 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1390 {WINED3DFMT_YUY2
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1391 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1392 WINED3D_FORMAT_CAP_FILTERING
,
1393 APPLE_RGB_422
, NULL
},
1394 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1395 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1396 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_FILTERING
,
1397 APPLE_YCBCR_422
, NULL
},
1398 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1399 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1400 WINED3D_FORMAT_CAP_FILTERING
,
1401 ARB_TEXTURE_RG
, NULL
},
1402 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1403 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1404 WINED3D_FORMAT_CAP_FILTERING
,
1405 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1406 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1407 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1408 WINED3D_FORMAT_CAP_FILTERING
,
1409 ARB_TEXTURE_RG
, NULL
},
1410 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1411 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1412 WINED3D_FORMAT_CAP_FILTERING
,
1413 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1414 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1415 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1416 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1417 | WINED3D_FORMAT_CAP_SRGB_READ
,
1418 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1419 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1420 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1421 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1422 | WINED3D_FORMAT_CAP_SRGB_READ
,
1423 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1424 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1425 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1426 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1427 | WINED3D_FORMAT_CAP_SRGB_READ
,
1428 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1429 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1430 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1431 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1432 | WINED3D_FORMAT_CAP_SRGB_READ
,
1433 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1434 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1435 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1436 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1437 | WINED3D_FORMAT_CAP_SRGB_READ
,
1438 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1439 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1440 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1441 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1442 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1443 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1444 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1445 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1446 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1447 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1448 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1449 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1450 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1451 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1452 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1453 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1454 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1455 {WINED3DFMT_BC4_SNORM
, GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_COMPRESSED_SIGNED_RED_RGTC1
, 0,
1456 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1457 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1458 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1459 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1460 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1461 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1462 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1463 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1464 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1465 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1466 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1467 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1468 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1469 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1470 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1471 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1472 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1473 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1474 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1475 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1476 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1477 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1478 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1480 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1481 GL_RED
, GL_FLOAT
, 0,
1482 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1483 ARB_TEXTURE_FLOAT
, NULL
},
1484 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1485 GL_RED
, GL_FLOAT
, 0,
1486 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1487 ARB_TEXTURE_RG
, NULL
},
1488 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1489 GL_RGB
, GL_FLOAT
, 12,
1490 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1491 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1492 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1494 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1495 ARB_TEXTURE_RG
, NULL
},
1496 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1497 GL_RGB
, GL_FLOAT
, 0,
1498 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1499 ARB_TEXTURE_FLOAT
, NULL
},
1500 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1501 GL_RGBA
, GL_FLOAT
, 0,
1502 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1503 ARB_TEXTURE_FLOAT
, NULL
},
1505 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1506 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1507 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1508 ARB_TEXTURE_FLOAT
, NULL
},
1509 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1510 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1511 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1512 ARB_TEXTURE_RG
, NULL
},
1513 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1514 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1515 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1516 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1517 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1518 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1519 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1520 ARB_TEXTURE_RG
, NULL
},
1521 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1522 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1523 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_RENDERTARGET
1524 | WINED3D_FORMAT_CAP_VTF
,
1525 ARB_TEXTURE_FLOAT
, NULL
},
1526 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1527 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1528 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1530 /* Palettized formats */
1531 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1532 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1534 ARB_TEXTURE_RG
, NULL
},
1535 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1536 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1538 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1539 /* Standard ARGB formats */
1540 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1541 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1542 WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1543 WINED3D_GL_EXT_NONE
, NULL
},
1544 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1545 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1546 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1547 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
1548 | WINED3D_FORMAT_CAP_VTF
,
1549 WINED3D_GL_EXT_NONE
, NULL
},
1550 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1551 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1552 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1553 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
,
1554 WINED3D_GL_EXT_NONE
, NULL
},
1555 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_SRGB8_EXT
, GL_RGB8
,
1556 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1557 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1558 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
,
1559 WINED3D_GL_EXT_NONE
, NULL
},
1560 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_SRGB8_EXT
, GL_RGB8
,
1561 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1562 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1563 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
,
1564 ARB_ES2_COMPATIBILITY
, NULL
},
1565 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1566 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1567 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1568 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1569 WINED3D_GL_EXT_NONE
, NULL
},
1570 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1571 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1572 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1573 WINED3D_GL_EXT_NONE
, NULL
},
1574 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1575 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1576 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1577 | WINED3D_FORMAT_CAP_SRGB_READ
,
1578 WINED3D_GL_EXT_NONE
, NULL
},
1579 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1580 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1581 WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1582 WINED3D_GL_EXT_NONE
, NULL
},
1583 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1584 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1585 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1586 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_VTF
,
1587 ARB_TEXTURE_RG
, NULL
},
1588 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1589 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1590 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1591 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1592 ARB_TEXTURE_RG
, NULL
},
1593 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1594 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1595 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1596 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1597 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1598 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1599 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1600 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1601 WINED3D_GL_EXT_NONE
, NULL
},
1602 {WINED3DFMT_R10G10B10A2_UINT
, GL_RGB10_A2UI
, GL_RGB10_A2UI
, 0,
1603 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1604 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1605 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1606 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1607 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1608 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1609 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1610 WINED3D_GL_EXT_NONE
, NULL
},
1611 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1612 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1613 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1614 | WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
1615 | WINED3D_FORMAT_CAP_VTF
,
1616 WINED3D_GL_EXT_NONE
, NULL
},
1617 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1618 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1619 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1620 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1621 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1622 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1623 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1624 EXT_TEXTURE_INTEGER
, NULL
},
1625 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1626 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1627 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1628 WINED3D_GL_EXT_NONE
, NULL
},
1629 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1630 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1631 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1632 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1633 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1634 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1635 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1636 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1637 ARB_TEXTURE_RG
, NULL
},
1638 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1639 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1640 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1641 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1642 WINED3D_GL_EXT_NONE
, NULL
},
1643 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1644 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1645 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1646 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1647 WINED3D_GL_EXT_NONE
, NULL
},
1648 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1649 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1650 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1651 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1652 ARB_TEXTURE_RG
, NULL
},
1653 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1654 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1655 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1656 ARB_TEXTURE_RG
, NULL
},
1657 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1658 GL_RG_INTEGER
, GL_BYTE
, 0,
1659 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1660 ARB_TEXTURE_RG
, NULL
},
1661 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1662 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1663 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1664 EXT_TEXTURE_INTEGER
, NULL
},
1665 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1666 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1667 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1668 EXT_TEXTURE_INTEGER
, NULL
},
1669 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1670 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1671 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1672 ARB_TEXTURE_RG
, NULL
},
1673 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1674 GL_RG_INTEGER
, GL_INT
, 0,
1675 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1676 ARB_TEXTURE_RG
, NULL
},
1677 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1678 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1679 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1680 ARB_TEXTURE_RG
, NULL
},
1681 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1682 GL_RG_INTEGER
, GL_SHORT
, 0,
1683 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1684 ARB_TEXTURE_RG
, NULL
},
1685 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1686 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1687 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1688 ARB_TEXTURE_RG
, NULL
},
1689 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1690 GL_RED_INTEGER
, GL_INT
, 0,
1691 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1692 ARB_TEXTURE_RG
, NULL
},
1693 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1694 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1695 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1696 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1697 ARB_TEXTURE_RG
, NULL
},
1698 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1699 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1700 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1701 ARB_TEXTURE_RG
, NULL
},
1702 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1703 GL_RED_INTEGER
, GL_SHORT
, 0,
1704 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1705 ARB_TEXTURE_RG
, NULL
},
1706 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1707 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1708 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1709 ARB_TEXTURE_RG
, NULL
},
1710 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1711 GL_RED_INTEGER
, GL_BYTE
, 0,
1712 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1713 ARB_TEXTURE_RG
, NULL
},
1715 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1716 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1717 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1718 | WINED3D_FORMAT_CAP_SRGB_READ
,
1719 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1720 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1721 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1722 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1723 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1724 ARB_TEXTURE_RG
, NULL
},
1725 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1726 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1727 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1728 ARB_TEXTURE_RG
, NULL
},
1729 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1730 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1731 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1732 | WINED3D_FORMAT_CAP_SRGB_READ
,
1733 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1734 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1735 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1736 WINED3D_FORMAT_CAP_FILTERING
,
1737 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1738 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1739 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1740 WINED3D_FORMAT_CAP_FILTERING
,
1741 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1742 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1743 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1744 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1745 ARB_TEXTURE_RG
, NULL
},
1746 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1747 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1748 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1749 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1750 /* Bump mapping stuff */
1751 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1752 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1753 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1754 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1755 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1756 GL_DSDT_NV
, GL_BYTE
, 0,
1757 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1758 NV_TEXTURE_SHADER
, NULL
},
1759 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1761 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1762 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1763 EXT_TEXTURE_SNORM
, NULL
},
1764 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1765 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1766 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1767 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1768 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1769 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1770 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1771 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1772 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1773 GL_RGBA
, GL_BYTE
, 4,
1774 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1775 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1776 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1777 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1778 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1779 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1780 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1781 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1782 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1783 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1784 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1785 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1786 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1787 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1788 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1789 GL_RGBA
, GL_BYTE
, 0,
1790 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1791 NV_TEXTURE_SHADER
, NULL
},
1792 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1793 GL_RGBA
, GL_BYTE
, 0,
1794 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1795 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1796 EXT_TEXTURE_SNORM
, NULL
},
1797 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1798 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1799 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1800 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1801 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1802 GL_HILO_NV
, GL_SHORT
, 0,
1803 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1804 NV_TEXTURE_SHADER
, NULL
},
1805 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1807 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1808 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1809 EXT_TEXTURE_SNORM
, NULL
},
1810 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1811 GL_RGBA
, GL_SHORT
, 0,
1812 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1813 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1814 EXT_TEXTURE_SNORM
, NULL
},
1815 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1816 GL_RED
, GL_SHORT
, 0,
1817 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1818 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1819 EXT_TEXTURE_SNORM
, NULL
},
1820 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1822 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1823 | WINED3D_FORMAT_CAP_RENDERTARGET
,
1824 EXT_TEXTURE_SNORM
, NULL
},
1825 /* Depth stencil formats */
1826 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1827 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1828 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1829 WINED3D_GL_EXT_NONE
, NULL
},
1830 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1831 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1832 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1833 ARB_DEPTH_TEXTURE
, NULL
},
1834 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1835 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1836 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1837 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1838 ARB_DEPTH_TEXTURE
, NULL
},
1839 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1840 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1841 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1842 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1843 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1844 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1845 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1846 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1847 WINED3D_GL_EXT_NONE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1848 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1849 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1850 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1851 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1852 ARB_DEPTH_TEXTURE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1853 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1854 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1855 WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1856 WINED3D_GL_EXT_NONE
, NULL
},
1857 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1858 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1859 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1860 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1861 ARB_DEPTH_TEXTURE
, NULL
},
1862 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1863 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1864 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1865 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1866 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1867 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1868 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1869 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1870 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1871 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1872 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
| WINED3D_FORMAT_CAP_SHADOW
,
1873 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1874 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1875 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1876 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1877 EXT_TEXTURE_INTEGER
, NULL
},
1878 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1879 GL_RGBA_INTEGER
, GL_INT
, 0,
1880 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
,
1881 EXT_TEXTURE_INTEGER
, NULL
},
1882 /* Vendor-specific formats */
1883 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1884 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1885 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1886 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1887 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1888 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1889 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1890 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1891 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1892 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1893 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1894 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1895 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1896 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1897 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1898 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1899 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1900 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1901 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
1902 | WINED3D_FORMAT_CAP_DEPTH_STENCIL
,
1903 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1904 {WINED3DFMT_NULL
, 0, 0, 0,
1905 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1906 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE
,
1907 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1908 /* DirectX 10 HDR formats */
1909 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, GL_RGB9_E5_EXT
, GL_RGB9_E5_EXT
, 0,
1910 GL_RGB
, GL_UNSIGNED_INT_5_9_9_9_REV_EXT
, 0,
1911 WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
| WINED3D_FORMAT_CAP_FILTERING
,
1912 EXT_TEXTURE_SHARED_EXPONENT
, NULL
},
1915 struct wined3d_format_srgb_info
1917 enum wined3d_format_id srgb_format_id
;
1918 enum wined3d_format_id base_format_id
;
1921 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1923 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1924 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1925 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1926 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1927 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1928 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1929 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1932 static inline int get_format_idx(enum wined3d_format_id format_id
)
1936 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1939 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1941 if (format_index_remap
[i
].id
== format_id
)
1942 return format_index_remap
[i
].idx
;
1948 static struct wined3d_format_gl
*wined3d_format_gl_mutable(struct wined3d_format
*format
)
1950 return CONTAINING_RECORD(format
, struct wined3d_format_gl
, f
);
1953 static struct wined3d_format_vk
*wined3d_format_vk_mutable(struct wined3d_format
*format
)
1955 return CONTAINING_RECORD(format
, struct wined3d_format_vk
, f
);
1958 static struct wined3d_format
*get_format_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1960 return (struct wined3d_format
*)((BYTE
*)adapter
->formats
+ fmt_idx
* adapter
->format_size
);
1963 static struct wined3d_format_gl
*get_format_gl_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1965 return wined3d_format_gl_mutable(get_format_by_idx(adapter
, fmt_idx
));
1968 static struct wined3d_format
*get_format_internal(const struct wined3d_adapter
*adapter
,
1969 enum wined3d_format_id format_id
)
1973 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1975 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1979 return get_format_by_idx(adapter
, fmt_idx
);
1982 static struct wined3d_format_gl
*get_format_gl_internal(const struct wined3d_adapter
*adapter
,
1983 enum wined3d_format_id format_id
)
1985 struct wined3d_format
*format
;
1987 if ((format
= get_format_internal(adapter
, format_id
)))
1988 return wined3d_format_gl_mutable(format
);
1993 static void copy_format(const struct wined3d_adapter
*adapter
,
1994 struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1996 enum wined3d_format_id id
= dst_format
->id
;
1997 memcpy(dst_format
, src_format
, adapter
->format_size
);
1998 dst_format
->id
= id
;
2001 static void format_set_caps(struct wined3d_format
*format
, unsigned int caps
)
2005 for (i
= 0; i
< ARRAY_SIZE(format
->caps
); ++i
)
2006 format
->caps
[i
] |= caps
;
2009 static void format_clear_caps(struct wined3d_format
*format
, unsigned int caps
)
2013 for (i
= 0; i
< ARRAY_SIZE(format
->caps
); ++i
)
2014 format
->caps
[i
] &= ~caps
;
2017 static enum wined3d_channel_type
map_channel_type(char t
)
2022 return WINED3D_CHANNEL_TYPE_UNORM
;
2024 return WINED3D_CHANNEL_TYPE_SNORM
;
2026 return WINED3D_CHANNEL_TYPE_UINT
;
2028 return WINED3D_CHANNEL_TYPE_SINT
;
2030 return WINED3D_CHANNEL_TYPE_FLOAT
;
2032 return WINED3D_CHANNEL_TYPE_DEPTH
;
2034 return WINED3D_CHANNEL_TYPE_STENCIL
;
2036 return WINED3D_CHANNEL_TYPE_UNUSED
;
2038 ERR("Invalid channel type '%c'.\n", t
);
2039 return WINED3D_CHANNEL_TYPE_NONE
;
2043 static void parse_channel_desc(struct wined3d_format
*format
, const char *channel_desc
)
2045 unsigned int component_count
= 0;
2046 unsigned int attrs
= 0;
2049 for (j
= 0; j
< strlen(channel_desc
); ++j
)
2051 enum wined3d_channel_type channel_type
= map_channel_type(channel_desc
[j
]);
2053 if (channel_type
== WINED3D_CHANNEL_TYPE_UNORM
|| channel_type
== WINED3D_CHANNEL_TYPE_SNORM
)
2054 attrs
|= WINED3D_FORMAT_ATTR_NORMALISED
;
2055 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
2056 attrs
|= WINED3D_FORMAT_ATTR_INTEGER
;
2057 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
2058 attrs
|= WINED3D_FORMAT_ATTR_FLOAT
;
2059 if (channel_type
!= WINED3D_CHANNEL_TYPE_UNUSED
)
2062 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
2064 format
->depth_size
= format
->red_size
;
2065 format
->red_size
= format
->red_offset
= 0;
2068 if (channel_type
== WINED3D_CHANNEL_TYPE_STENCIL
&& !format
->stencil_size
)
2070 format
->stencil_size
= format
->green_size
;
2071 format
->green_size
= format
->green_offset
= 0;
2075 format
->attrs
|= attrs
;
2076 format
->component_count
= component_count
;
2079 static BOOL
init_format_base_info(struct wined3d_adapter
*adapter
)
2081 struct wined3d_format
*format
;
2084 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
2086 if (!(format
= get_format_internal(adapter
, formats
[i
].id
)))
2089 format
->id
= formats
[i
].id
;
2090 format
->red_size
= formats
[i
].red_size
;
2091 format
->green_size
= formats
[i
].green_size
;
2092 format
->blue_size
= formats
[i
].blue_size
;
2093 format
->alpha_size
= formats
[i
].alpha_size
;
2094 format
->red_offset
= formats
[i
].red_offset
;
2095 format
->green_offset
= formats
[i
].green_offset
;
2096 format
->blue_offset
= formats
[i
].blue_offset
;
2097 format
->alpha_offset
= formats
[i
].alpha_offset
;
2098 format
->byte_count
= formats
[i
].bpp
;
2099 format
->depth_size
= formats
[i
].depth_size
;
2100 format
->stencil_size
= formats
[i
].stencil_size
;
2101 format
->block_width
= 1;
2102 format
->block_height
= 1;
2103 format
->block_byte_count
= formats
[i
].bpp
;
2105 if (formats
[i
].channels
)
2106 parse_channel_desc(format
, formats
[i
].channels
);
2109 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
2111 struct wined3d_format
*typeless_format
;
2113 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
2116 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
2119 format
->id
= typed_formats
[i
].id
;
2120 format
->red_size
= typeless_format
->red_size
;
2121 format
->green_size
= typeless_format
->green_size
;
2122 format
->blue_size
= typeless_format
->blue_size
;
2123 format
->alpha_size
= typeless_format
->alpha_size
;
2124 format
->red_offset
= typeless_format
->red_offset
;
2125 format
->green_offset
= typeless_format
->green_offset
;
2126 format
->blue_offset
= typeless_format
->blue_offset
;
2127 format
->alpha_offset
= typeless_format
->alpha_offset
;
2128 format
->byte_count
= typeless_format
->byte_count
;
2129 format
->depth_size
= typeless_format
->depth_size
;
2130 format
->stencil_size
= typeless_format
->stencil_size
;
2131 format
->block_width
= typeless_format
->block_width
;
2132 format
->block_height
= typeless_format
->block_height
;
2133 format
->block_byte_count
= typeless_format
->block_byte_count
;
2134 format
->typeless_id
= typeless_format
->id
;
2136 typeless_format
->typeless_id
= typeless_format
->id
;
2138 parse_channel_desc(format
, typed_formats
[i
].channels
);
2141 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
2143 if (!(format
= get_format_internal(adapter
, ddi_formats
[i
].id
)))
2146 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
2149 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
2151 if (!(format
= get_format_internal(adapter
, format_base_flags
[i
].id
)))
2154 format
->attrs
|= format_base_flags
[i
].attrs
;
2155 format_set_caps(format
, format_base_flags
[i
].caps
);
2161 static BOOL
init_format_block_info(struct wined3d_adapter
*adapter
)
2163 struct wined3d_format
*format
;
2166 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
2168 if (!(format
= get_format_internal(adapter
, format_block_info
[i
].id
)))
2171 format
->block_width
= format_block_info
[i
].block_width
;
2172 format
->block_height
= format_block_info
[i
].block_height
;
2173 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
2174 format
->attrs
|= WINED3D_FORMAT_ATTR_BLOCKS
| format_block_info
[i
].attrs
;
2180 /* Most compressed formats are not supported for 3D textures by OpenGL.
2182 * In the case of the S3TC/DXTn formats, NV_texture_compression_vtc provides
2183 * these formats for 3D textures, but unfortunately the block layout is
2184 * different from the one used by Direct3D.
2186 * Since applications either don't check format availability at all before
2187 * using these, or refuse to run without them, we decompress them on upload.
2189 * Affected applications include "Heroes VI", "From Dust", "Halo Online" and
2191 static BOOL
init_format_decompress_info(struct wined3d_adapter
*adapter
)
2193 struct wined3d_format
*format
;
2196 for (i
= 0; i
< ARRAY_SIZE(format_decompress_info
); ++i
)
2198 if (!(format
= get_format_internal(adapter
, format_decompress_info
[i
].id
)))
2201 format
->caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= WINED3D_FORMAT_CAP_DECOMPRESS
;
2202 format
->decompress
= format_decompress_info
[i
].decompress
;
2208 static BOOL
init_srgb_formats(struct wined3d_adapter
*adapter
)
2210 struct wined3d_format
*format
, *srgb_format
;
2213 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
2215 if (!(srgb_format
= get_format_internal(adapter
, format_srgb_info
[i
].srgb_format_id
)))
2217 if (!(format
= get_format_internal(adapter
, format_srgb_info
[i
].base_format_id
)))
2220 copy_format(adapter
, srgb_format
, format
);
2226 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
2230 case WINED3D_GL_RES_TYPE_TEX_1D
:
2231 return GL_TEXTURE_1D
;
2232 case WINED3D_GL_RES_TYPE_TEX_2D
:
2233 return GL_TEXTURE_2D
;
2234 case WINED3D_GL_RES_TYPE_TEX_3D
:
2235 return GL_TEXTURE_3D
;
2236 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2237 return GL_TEXTURE_CUBE_MAP_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_3D
:
2257 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2258 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
2261 case WINED3D_GL_RES_TYPE_RB
:
2262 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
2265 case WINED3D_GL_RES_TYPE_BUFFER
:
2266 case WINED3D_GL_RES_TYPE_COUNT
:
2271 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2272 const struct wined3d_format_gl
*format_gl
,
2273 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
)
2275 GLenum format
= format_gl
->format
;
2276 GLenum type
= format_gl
->type
;
2279 attach_type
= format_gl
->f
.depth_size
? GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
2282 case WINED3D_GL_RES_TYPE_TEX_1D
:
2283 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2284 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
2285 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
2286 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2287 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2289 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
, *object
, 0);
2290 if (format_gl
->f
.stencil_size
)
2291 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
,
2292 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
, *object
, 0);
2295 case WINED3D_GL_RES_TYPE_TEX_2D
:
2296 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2297 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
2298 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
2299 format
, type
, NULL
);
2300 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2301 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2303 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2304 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2305 if (format_gl
->f
.stencil_size
)
2306 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2307 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2310 case WINED3D_GL_RES_TYPE_TEX_3D
:
2311 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2312 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
2313 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
2314 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2315 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2317 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_3D
, *object
, 0, 0);
2318 if (format_gl
->f
.stencil_size
)
2319 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
,
2320 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_3D
, *object
, 0, 0);
2323 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2324 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2325 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
2326 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
2327 format
, type
, NULL
);
2328 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
2329 format
, type
, NULL
);
2330 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2331 format
, type
, NULL
);
2332 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2333 format
, type
, NULL
);
2334 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2335 format
, type
, NULL
);
2336 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2337 format
, type
, NULL
);
2338 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2339 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2341 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2342 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2343 if (format_gl
->f
.stencil_size
)
2344 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2345 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2348 case WINED3D_GL_RES_TYPE_RB
:
2349 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2350 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2351 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2352 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
, *object
);
2353 if (format_gl
->f
.stencil_size
)
2354 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2355 GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, *object
);
2358 case WINED3D_GL_RES_TYPE_BUFFER
:
2359 case WINED3D_GL_RES_TYPE_COUNT
:
2363 /* Ideally we'd skip all formats already known not to work on textures
2364 * by checking for WINED3D_FORMAT_CAP_TEXTURE here. However, we want to
2365 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2366 * format never has WINED3D_FORMAT_CAP_TEXTURE set. Instead, swallow GL
2367 * errors generated by invalid formats. */
2368 while (gl_info
->gl_ops
.gl
.p_glGetError());
2371 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2372 const struct wined3d_color
*color
)
2374 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2375 static const struct wined3d_vec3 default_geometry
[] =
2377 {-1.0f
, -1.0f
, 0.0f
},
2378 { 1.0f
, -1.0f
, 0.0f
},
2379 {-1.0f
, 1.0f
, 0.0f
},
2380 { 1.0f
, 1.0f
, 0.0f
},
2382 static const char vs_core_header
[] =
2386 "out vec4 out_color;\n"
2388 static const char vs_legacy_header
[] =
2390 "attribute vec4 pos;\n"
2391 "attribute vec4 color;\n"
2392 "varying vec4 out_color;\n"
2394 static const char vs_body
[] =
2397 " gl_Position = pos;\n"
2398 " out_color = color;\n"
2400 static const char fs_core
[] =
2402 "in vec4 out_color;\n"
2403 "out vec4 fragment_color;\n"
2407 " fragment_color = out_color;\n"
2409 static const char fs_legacy
[] =
2411 "varying vec4 out_color;\n"
2415 " gl_FragData[0] = out_color;\n"
2417 const char *source
[2];
2418 GLuint vs_id
, fs_id
;
2422 geometry
= default_geometry
;
2424 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2425 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2427 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2428 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2429 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2430 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2431 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2433 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2434 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2435 for (i
= 0; i
< 4; ++i
)
2436 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2437 gl_info
->gl_ops
.gl
.p_glEnd();
2438 checkGLcall("draw quad");
2443 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2444 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2445 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2446 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2447 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2448 GL_EXTCALL(glEnableVertexAttribArray(0));
2449 GL_EXTCALL(glDisableVertexAttribArray(1));
2451 if (!ctx
->test_program_id
)
2453 BOOL use_glsl_150
= gl_info
->glsl_version
>= MAKEDWORD_VERSION(1, 50);
2455 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2457 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2458 source
[0] = use_glsl_150
? vs_core_header
: vs_legacy_header
;
2459 source
[1] = vs_body
;
2460 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2461 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2462 GL_EXTCALL(glDeleteShader(vs_id
));
2464 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2465 source
[0] = use_glsl_150
? fs_core
: fs_legacy
;
2466 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2467 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2468 GL_EXTCALL(glDeleteShader(fs_id
));
2470 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2471 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2474 GL_EXTCALL(glBindFragDataLocation(ctx
->test_program_id
, 0, "fragment_color"));
2476 GL_EXTCALL(glCompileShader(vs_id
));
2477 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2478 GL_EXTCALL(glCompileShader(fs_id
));
2479 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2480 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2481 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2483 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2485 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2487 GL_EXTCALL(glUseProgram(0));
2488 GL_EXTCALL(glDisableVertexAttribArray(0));
2489 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2490 checkGLcall("draw quad");
2493 /* Context activation is done by the caller. */
2494 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format_gl
*format
)
2496 /* Check if the default internal format is supported as a frame buffer
2497 * target, otherwise fall back to the render target internal.
2499 * Try to stick to the standard format if possible, this limits precision differences. */
2500 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2501 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2502 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2503 GLenum status
, rt_internal
= format
->rt_internal
;
2504 GLuint object
, color_rb
;
2505 enum wined3d_gl_resource_type type
;
2506 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2508 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2510 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2512 const char *type_string
= "color";
2514 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2517 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->internal
);
2519 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
2521 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2522 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2523 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2524 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2526 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2528 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2529 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2530 checkGLcall("Create and attach color rb attachment");
2531 type_string
= "depth / stencil";
2534 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2535 checkGLcall("Framebuffer format check");
2537 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2539 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2540 debug_d3dformat(format
->f
.id
), type_string
, type
);
2541 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE
;
2542 format
->rt_internal
= format
->internal
;
2543 regular_fmt_used
= TRUE
;
2549 if (format
->f
.caps
[type
] & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
2551 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2552 " and no fallback specified.\n", debug_d3dformat(format
->f
.id
), type
);
2553 format
->f
.caps
[type
] &= ~(WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
);
2557 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2558 debug_d3dformat(format
->f
.id
), type_string
, type
);
2560 format
->rt_internal
= format
->internal
;
2564 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2565 " trying rtInternal format as fallback.\n",
2566 debug_d3dformat(format
->f
.id
), type_string
, type
);
2568 while (gl_info
->gl_ops
.gl
.p_glGetError());
2570 delete_fbo_attachment(gl_info
, type
, object
);
2571 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->rt_internal
);
2573 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2574 checkGLcall("Framebuffer format check");
2576 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2578 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2579 debug_d3dformat(format
->f
.id
), type_string
, type
);
2580 fallback_fmt_used
= TRUE
;
2584 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2585 debug_d3dformat(format
->f
.id
), type_string
, type
);
2586 format
->f
.caps
[type
] &= ~(WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
);
2591 if (status
== GL_FRAMEBUFFER_COMPLETE
2592 && ((format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
)
2593 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2594 && !(format
->f
.attrs
& WINED3D_FORMAT_ATTR_INTEGER
)
2595 && format
->f
.id
!= WINED3DFMT_NULL
&& format
->f
.id
!= WINED3DFMT_P8_UINT
2596 && format
->format
!= GL_LUMINANCE
&& format
->format
!= GL_LUMINANCE_ALPHA
2597 && (format
->f
.red_size
|| format
->f
.alpha_size
))
2599 uint32_t readback
[16 * 16 * 16], color
= 0;
2600 unsigned int r_range
, a_range
;
2605 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2607 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2608 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2609 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2610 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2612 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2613 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2614 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2615 checkGLcall("RB attachment");
2618 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2619 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2620 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2621 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2623 while (gl_info
->gl_ops
.gl
.p_glGetError());
2624 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2625 debug_d3dformat(format
->f
.id
), type
);
2626 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2630 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2631 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2632 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2634 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2635 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2637 draw_test_quad(ctx
, NULL
, &black
);
2639 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2641 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2643 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2647 case WINED3D_GL_RES_TYPE_TEX_1D
:
2648 /* Rebinding texture to workaround a fglrx bug. */
2649 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2650 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2651 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2652 color
= readback
[7];
2655 case WINED3D_GL_RES_TYPE_TEX_2D
:
2656 case WINED3D_GL_RES_TYPE_TEX_3D
:
2657 /* Rebinding texture to workaround a fglrx bug. */
2658 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2659 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2660 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2661 color
= readback
[7 * 16 + 7];
2664 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2665 /* Rebinding texture to workaround a fglrx bug. */
2666 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2667 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2668 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2669 color
= readback
[7 * 16 + 7];
2672 case WINED3D_GL_RES_TYPE_RB
:
2673 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2674 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2675 color
= readback
[7 * 16 + 7];
2678 case WINED3D_GL_RES_TYPE_BUFFER
:
2679 case WINED3D_GL_RES_TYPE_COUNT
:
2683 checkGLcall("Post-pixelshader blending check");
2686 r
= (color
& 0x00ff0000u
) >> 16;
2688 r_range
= format
->f
.red_size
< 8 ? 1u << (8 - format
->f
.red_size
) : 1;
2689 a_range
= format
->f
.alpha_size
< 8 ? 1u << (8 - format
->f
.alpha_size
) : 1;
2690 if (format
->f
.red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2692 else if (format
->f
.alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2696 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2697 debug_d3dformat(format
->f
.id
), type
);
2698 TRACE("Color output: %#x\n", color
);
2699 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2703 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2704 debug_d3dformat(format
->f
.id
), type
);
2705 TRACE("Color output: %#x\n", color
);
2706 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2710 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2712 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2713 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2714 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2715 checkGLcall("RB cleanup");
2719 if (format
->internal
!= format
->srgb_internal
)
2721 delete_fbo_attachment(gl_info
, type
, object
);
2722 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->srgb_internal
);
2724 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2725 checkGLcall("Framebuffer format check");
2727 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2729 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2730 debug_d3dformat(format
->f
.id
), type
);
2731 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2732 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2733 format
->internal
= format
->srgb_internal
;
2737 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2738 debug_d3dformat(format
->f
.id
), type
);
2739 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
2742 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2743 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2745 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
2747 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2748 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2751 delete_fbo_attachment(gl_info
, type
, object
);
2752 checkGLcall("Framebuffer format check cleanup");
2755 if (fallback_fmt_used
&& regular_fmt_used
)
2757 FIXME("Format %s needs different render target formats for different resource types.\n",
2758 debug_d3dformat(format
->f
.id
));
2759 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
2760 | WINED3D_FORMAT_CAP_FBO_ATTACHABLE
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
2761 | WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
);
2765 static void query_format_cap(struct wined3d_gl_info
*gl_info
, struct wined3d_format_gl
*format
,
2766 GLint internal
, GLenum pname
, unsigned int cap
, const char *string
)
2769 enum wined3d_gl_resource_type type
;
2771 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2773 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2774 if (value
== GL_FULL_SUPPORT
)
2776 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2777 format
->f
.caps
[type
] |= cap
;
2781 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2782 format
->f
.caps
[type
] &= ~cap
;
2787 /* Context activation is done by the caller. */
2788 static void init_format_fbo_compat_info(const struct wined3d_adapter
*adapter
,
2789 struct wined3d_caps_gl_ctx
*ctx
)
2791 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2792 unsigned int i
, type
;
2795 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2797 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2799 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2800 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2801 GLenum rt_internal
= format
->rt_internal
;
2804 if (!format
->internal
)
2807 for (type
= 0; type
< ARRAY_SIZE(format
->f
.caps
); ++type
)
2809 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2810 format
->internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2811 if (value
== GL_FULL_SUPPORT
)
2813 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2814 debug_d3dformat(format
->f
.id
), type
);
2815 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE
;
2816 format
->rt_internal
= format
->internal
;
2817 regular_fmt_used
= TRUE
;
2819 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2820 format
->internal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2821 if (value
== GL_FULL_SUPPORT
)
2823 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2824 debug_d3dformat(format
->f
.id
), type
);
2825 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2829 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2830 debug_d3dformat(format
->f
.id
), type
);
2831 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
2838 if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_RENDERTARGET
)
2840 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2841 " and no fallback specified, resource type %u.\n",
2842 debug_d3dformat(format
->f
.id
), type
);
2843 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_RENDERTARGET
;
2846 TRACE("Format %s is not supported as FBO color attachment,"
2847 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2848 format
->rt_internal
= format
->internal
;
2852 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2853 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2854 if (value
== GL_FULL_SUPPORT
)
2856 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2857 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2858 fallback_fmt_used
= TRUE
;
2862 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2863 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2864 format
->f
.caps
[type
] &= ~WINED3D_FORMAT_CAP_RENDERTARGET
;
2869 if (format
->internal
!= format
->srgb_internal
)
2871 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2872 format
->srgb_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2873 if (value
== GL_FULL_SUPPORT
)
2875 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2876 debug_d3dformat(format
->f
.id
), type
);
2877 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2878 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2879 format
->internal
= format
->srgb_internal
;
2883 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2884 debug_d3dformat(format
->f
.id
), type
);
2885 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_WRITE
);
2888 else if (format
->f
.caps
[type
] & WINED3D_FORMAT_CAP_FBO_ATTACHABLE
)
2889 format
->f
.caps
[type
] |= WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
;
2892 if (fallback_fmt_used
&& regular_fmt_used
)
2894 FIXME("Format %s needs different render target formats for different resource types.\n",
2895 debug_d3dformat(format
->f
.id
));
2896 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FBO_ATTACHABLE
2897 | WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB
| WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
);
2903 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2904 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2905 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2906 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2908 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2910 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2912 if (!format
->internal
)
2915 if (format
->f
.attrs
& WINED3D_FORMAT_ATTR_COMPRESSED
)
2917 TRACE("Skipping format %s because it's a compressed format.\n",
2918 debug_d3dformat(format
->f
.id
));
2922 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->f
.id
));
2923 check_fbo_compat(ctx
, format
);
2926 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2929 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2933 GLenum internal_format
;
2939 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2940 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2941 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2943 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2944 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2945 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2947 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2948 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2949 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2950 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2951 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2952 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2953 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2954 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2956 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2957 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2958 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2959 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2960 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2962 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2963 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2964 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2965 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2966 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2967 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2968 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2969 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2970 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2971 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2972 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2973 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2974 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2975 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2976 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2977 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2978 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2980 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2981 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2982 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2983 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2984 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2986 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2987 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2988 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2989 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2990 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2991 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2992 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
2993 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
2994 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
2996 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
2997 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
2998 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
2999 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
3002 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3003 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3005 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3006 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3009 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3010 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3012 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3013 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3016 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3017 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3019 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3020 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3022 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3023 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3025 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3026 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3031 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
3033 if (view_classes
[i
].internal_format
== internal_format
)
3034 return view_classes
[i
].view_class
;
3040 static void query_view_class(struct wined3d_format_gl
*format
)
3042 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
3044 internal_view_class
= lookup_gl_view_class(format
->internal
);
3045 gamma_view_class
= lookup_gl_view_class(format
->srgb_internal
);
3046 rt_view_class
= lookup_gl_view_class(format
->rt_internal
);
3048 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
3050 format
->view_class
= internal_view_class
;
3051 TRACE("Format %s is member of GL view class %#x.\n",
3052 debug_d3dformat(format
->f
.id
), format
->view_class
);
3056 format
->view_class
= GL_NONE
;
3060 static void query_internal_format(struct wined3d_adapter
*adapter
,
3061 struct wined3d_format_gl
*format
, const struct wined3d_format_texture_info
*texture_info
,
3062 struct wined3d_gl_info
*gl_info
, BOOL srgb_format
)
3064 GLint count
, multisample_types
[8];
3065 unsigned int i
, max_log2
;
3068 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3070 query_format_cap(gl_info
, format
, format
->internal
, GL_VERTEX_TEXTURE
,
3071 WINED3D_FORMAT_CAP_VTF
, "vertex texture usage");
3072 query_format_cap(gl_info
, format
, format
->internal
, GL_FILTER
,
3073 WINED3D_FORMAT_CAP_FILTERING
, "filtering");
3074 query_format_cap(gl_info
, format
, format
->internal
, GL_SHADER_IMAGE_STORE
,
3075 WINED3D_FORMAT_CAP_UNORDERED_ACCESS
, "unordered access");
3077 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3079 query_format_cap(gl_info
, format
, format
->srgb_internal
, GL_SRGB_READ
,
3080 WINED3D_FORMAT_CAP_SRGB_READ
, "sRGB read");
3081 query_format_cap(gl_info
, format
, format
->srgb_internal
, GL_SRGB_WRITE
,
3082 WINED3D_FORMAT_CAP_SRGB_WRITE
, "sRGB write");
3084 if (!(format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
]
3085 & (WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
)))
3086 format
->srgb_internal
= format
->internal
;
3087 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3088 format
->internal
= format
->srgb_internal
;
3093 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
3094 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_VTF
);
3096 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
3097 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3098 else if (format
->f
.id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->f
.id
!= WINED3DFMT_R32_FLOAT
)
3099 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_VTF
);
3101 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3103 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
3104 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
3106 format
->srgb_internal
= format
->internal
;
3107 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3109 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3111 format
->internal
= format
->srgb_internal
;
3116 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
] && (format
->f
.depth_size
|| format
->f
.stencil_size
))
3118 TRACE("Disabling texturing support for depth / stencil format %s.\n", debug_d3dformat(format
->f
.id
));
3119 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3120 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3121 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3122 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3125 query_view_class(format
);
3127 if (format
->internal
&& format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
]
3128 & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_DEPTH_STENCIL
)
3129 && (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
] || gl_info
->supported
[EXT_FRAMEBUFFER_MULTISAMPLE
]))
3131 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
3133 target
= gl_info
->supported
[ARB_TEXTURE_MULTISAMPLE
] ? GL_TEXTURE_2D_MULTISAMPLE
: GL_RENDERBUFFER
;
3135 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3136 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
3137 if (count
> ARRAY_SIZE(multisample_types
))
3138 FIXME("Unexpectedly high number of multisample types %d.\n", count
);
3139 count
= min(count
, ARRAY_SIZE(multisample_types
));
3140 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3141 GL_SAMPLES
, count
, multisample_types
));
3142 checkGLcall("query sample counts");
3143 for (i
= 0; i
< count
; ++i
)
3145 if (multisample_types
[i
] > sizeof(format
->f
.multisample_types
) * CHAR_BIT
)
3147 format
->f
.multisample_types
|= 1u << (multisample_types
[i
] - 1);
3152 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
3153 sizeof(format
->f
.multisample_types
) * CHAR_BIT
));
3154 for (i
= 1; i
<= max_log2
; ++i
)
3155 format
->f
.multisample_types
|= 1u << ((1u << i
) - 1);
3160 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3162 struct wined3d_format_gl
*format
, *srgb_format
;
3163 struct fragment_caps fragment_caps
;
3164 struct shader_caps shader_caps
;
3167 adapter
->fragment_pipe
->get_caps(adapter
, &fragment_caps
);
3168 adapter
->shader_backend
->shader_get_caps(adapter
, &shader_caps
);
3170 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
3172 if (!(format
= get_format_gl_internal(adapter
, format_texture_info
[i
].id
)))
3175 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
3178 /* ARB_texture_rg defines floating point formats, but only if
3179 * ARB_texture_float is also supported. */
3180 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
3181 && (format
->f
.attrs
& WINED3D_FORMAT_ATTR_FLOAT
))
3184 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
3185 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
3186 && (format
->f
.attrs
& WINED3D_FORMAT_ATTR_INTEGER
))
3189 format
->internal
= format_texture_info
[i
].gl_internal
;
3190 format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3191 format
->rt_internal
= format_texture_info
[i
].gl_rt_internal
;
3192 format
->format
= format_texture_info
[i
].gl_format
;
3193 format
->type
= format_texture_info
[i
].gl_type
;
3194 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
3195 format
->f
.height_scale
.numerator
= 1;
3196 format
->f
.height_scale
.denominator
= 1;
3198 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3199 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3200 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3202 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
3203 * problematic", but doesn't explicitly mandate that an error is generated. */
3204 if (gl_info
->supported
[EXT_TEXTURE3D
] && !(format_texture_info
[i
].caps
& WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
3205 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3207 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
3208 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3210 format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].caps
| WINED3D_FORMAT_CAP_BLIT
;
3211 format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3213 if (format
->srgb_internal
!= format
->internal
3214 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3216 format
->srgb_internal
= format
->internal
;
3217 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3220 if (!gl_info
->supported
[ARB_SHADOW
] && (format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3D_FORMAT_CAP_SHADOW
))
3221 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3223 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, FALSE
);
3225 /* Texture conversion stuff */
3226 format
->f
.conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
3227 format
->f
.upload
= format_texture_info
[i
].upload
;
3228 format
->f
.download
= format_texture_info
[i
].download
;
3231 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
3233 if (format_srgb_info
[j
].base_format_id
== format
->f
.id
)
3235 if (!(srgb_format
= get_format_gl_internal(adapter
, format_srgb_info
[j
].srgb_format_id
)))
3243 copy_format(adapter
, &srgb_format
->f
, &format
->f
);
3245 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
3246 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3248 srgb_format
->internal
= format_texture_info
[i
].gl_srgb_internal
;
3249 srgb_format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3250 format_set_caps(&srgb_format
->f
, WINED3D_FORMAT_CAP_SRGB_READ
| WINED3D_FORMAT_CAP_SRGB_WRITE
);
3251 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, TRUE
);
3258 static BOOL
compare_uint(unsigned int x
, unsigned int y
, unsigned int max_diff
)
3260 unsigned int diff
= x
> y
? x
- y
: y
- x
;
3262 return diff
<= max_diff
;
3265 static BOOL
compare_colour(DWORD c1
, DWORD c2
, BYTE max_diff
)
3267 return compare_uint(c1
& 0xff, c2
& 0xff, max_diff
)
3268 && compare_uint((c1
>> 8) & 0xff, (c2
>> 8) & 0xff, max_diff
)
3269 && compare_uint((c1
>> 16) & 0xff, (c2
>> 16) & 0xff, max_diff
)
3270 && compare_uint((c1
>> 24) & 0xff, (c2
>> 24) & 0xff, max_diff
);
3273 /* A context is provided by the caller */
3274 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
3276 static const DWORD data
[] = {0x00000000, 0xffffffff};
3277 GLuint tex
, fbo
, buffer
;
3278 uint32_t readback
[16 * 1];
3281 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3282 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3283 * falling back to software. If this changes in the future this code will get fooled and
3284 * apps might hit the software path due to incorrectly advertised caps.
3286 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3287 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3288 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3291 while (gl_info
->gl_ops
.gl
.p_glGetError());
3293 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
3294 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3295 memset(readback
, 0x7e, sizeof(readback
));
3296 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
3297 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
3298 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
3299 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
3300 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3301 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3302 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3304 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
3305 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
3306 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
3307 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
3308 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
3309 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
3310 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3311 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3312 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3313 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
3315 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3316 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3317 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
3318 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
3320 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
3321 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
3322 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
3323 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3324 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
3325 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3327 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
3328 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3330 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3331 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3332 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3333 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3334 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3335 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3336 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3337 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3338 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3339 gl_info
->gl_ops
.gl
.p_glEnd();
3341 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3342 memset(readback
, 0x7f, sizeof(readback
));
3343 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3344 if (compare_colour(readback
[6], 0xffffffff, 5) || compare_colour(readback
[6], 0x00000000, 5)
3345 || compare_colour(readback
[9], 0xffffffff, 5) || compare_colour(readback
[9], 0x00000000, 5))
3347 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3348 readback
[6], readback
[9]);
3353 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3354 readback
[6], readback
[9]);
3358 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3359 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3360 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3361 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3362 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3364 if (gl_info
->gl_ops
.gl
.p_glGetError())
3366 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3373 static void init_format_filter_info(struct wined3d_adapter
*adapter
,
3374 struct wined3d_gl_info
*gl_info
)
3376 enum wined3d_pci_vendor vendor
= adapter
->driver_info
.vendor
;
3377 struct wined3d_format_gl
*format
;
3379 static const enum wined3d_format_id fmts16
[] =
3381 WINED3DFMT_R16_FLOAT
,
3382 WINED3DFMT_R16G16_FLOAT
,
3383 WINED3DFMT_R16G16B16A16_FLOAT
,
3387 /* This was already handled by init_format_texture_info(). */
3388 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3391 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3393 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3395 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3398 else if (gl_info
->limits
.glsl_varyings
> 44)
3400 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3405 TRACE("Assuming no float16 blending\n");
3411 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3413 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3414 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3420 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3422 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3423 if (!format
->internal
)
3424 continue; /* Not supported by GL */
3426 filtered
= check_filter(gl_info
, format
->internal
);
3429 TRACE("Format %s supports filtering.\n", debug_d3dformat(format
->f
.id
));
3430 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_FILTERING
);
3434 TRACE("Format %s does not support filtering.\n", debug_d3dformat(format
->f
.id
));
3439 static enum fixup_channel_source
fixup_source_from_char(char c
)
3445 return CHANNEL_SOURCE_ZERO
;
3447 return CHANNEL_SOURCE_ONE
;
3450 return CHANNEL_SOURCE_X
;
3453 return CHANNEL_SOURCE_Y
;
3456 return CHANNEL_SOURCE_Z
;
3459 return CHANNEL_SOURCE_W
;
3463 static unsigned int fixup_sign_from_char(char c
)
3465 if (c
== 'x' || c
== 'y' || c
== 'z' || c
== 'w')
3470 static struct color_fixup_desc
create_color_fixup_desc_from_string(const char *s
)
3472 struct color_fixup_desc fixup
;
3476 ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s
));
3477 return COLOR_FIXUP_IDENTITY
;
3480 fixup
.x_sign_fixup
= fixup_sign_from_char(s
[0]);
3481 fixup
.x_source
= fixup_source_from_char(s
[0]);
3482 fixup
.y_sign_fixup
= fixup_sign_from_char(s
[1]);
3483 fixup
.y_source
= fixup_source_from_char(s
[1]);
3484 fixup
.z_sign_fixup
= fixup_sign_from_char(s
[2]);
3485 fixup
.z_source
= fixup_source_from_char(s
[2]);
3486 fixup
.w_sign_fixup
= fixup_sign_from_char(s
[3]);
3487 fixup
.w_source
= fixup_source_from_char(s
[3]);
3492 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3494 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
3495 struct wined3d_format_gl
*format
;
3496 BOOL use_legacy_fixups
;
3501 enum wined3d_format_id id
;
3504 enum wined3d_gl_extension extension
;
3508 {WINED3DFMT_R16_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3509 {WINED3DFMT_R32_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3510 {WINED3DFMT_R16G16_UNORM
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3511 {WINED3DFMT_R16G16_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3512 {WINED3DFMT_R32G32_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3514 {WINED3DFMT_R8G8_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3515 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3516 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3518 {WINED3DFMT_R16G16_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3519 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3520 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3522 {WINED3DFMT_R8G8B8A8_SNORM
, "xyzw", FALSE
, WINED3D_GL_EXT_NONE
},
3523 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3524 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3526 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "xzY1", FALSE
, WINED3D_GL_EXT_NONE
},
3527 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3528 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3530 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "xyZW", FALSE
, WINED3D_GL_EXT_NONE
},
3531 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3533 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3534 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3536 {WINED3DFMT_ATI2N
, "XW11", FALSE
, ATI_TEXTURE_COMPRESSION_3DC
},
3537 {WINED3DFMT_ATI2N
, "YX11", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3538 {WINED3DFMT_ATI2N
, "YX11", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3540 {WINED3DFMT_A8_UNORM
, "000X", FALSE
, WINED3D_GL_EXT_NONE
},
3541 {WINED3DFMT_A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3543 {WINED3DFMT_L8A8_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3544 {WINED3DFMT_L8A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3546 {WINED3DFMT_L4A4_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3547 {WINED3DFMT_L4A4_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3549 {WINED3DFMT_L16_UNORM
, "XXX1", FALSE
, WINED3D_GL_EXT_NONE
},
3550 {WINED3DFMT_L16_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3552 {WINED3DFMT_INTZ
, "XXXX", FALSE
, WINED3D_GL_EXT_NONE
},
3553 {WINED3DFMT_INTZ
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3555 {WINED3DFMT_L8_UNORM
, "XXX1", FALSE
, ARB_TEXTURE_RG
},
3558 use_legacy_fixups
= d3d_info
->wined3d_creation_flags
& WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
;
3559 for (i
= 0; i
< ARRAY_SIZE(fixups
); ++i
)
3561 if (fixups
[i
].legacy
&& !use_legacy_fixups
)
3564 if (!gl_info
->supported
[fixups
[i
].extension
])
3567 format
= get_format_gl_internal(adapter
, fixups
[i
].id
);
3568 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixups
[i
].fixup
);
3571 if (!gl_info
->supported
[APPLE_YCBCR_422
] && !gl_info
->supported
[APPLE_RGB_422
]
3572 && (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3573 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
])))
3575 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3576 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3578 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3579 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3581 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && gl_info
->supported
[APPLE_RGB_422
])
3583 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3584 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3586 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3587 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3589 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && (!gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3590 && (!gl_info
->supported
[ARB_FRAGMENT_SHADER
] || !gl_info
->supported
[ARB_VERTEX_SHADER
])))
3592 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3593 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3594 format
->internal
= 0;
3596 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3597 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3598 format
->internal
= 0;
3601 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3602 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
]))
3604 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3605 format
->f
.attrs
|= WINED3D_FORMAT_ATTR_HEIGHT_SCALE
;
3606 format
->f
.height_scale
.numerator
= 3;
3607 format
->f
.height_scale
.denominator
= 2;
3608 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3610 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3611 format
->f
.attrs
|= WINED3D_FORMAT_ATTR_HEIGHT_SCALE
;
3612 format
->f
.height_scale
.numerator
= 3;
3613 format
->f
.height_scale
.denominator
= 2;
3614 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3618 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3619 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3620 format
->internal
= 0;
3622 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3623 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_BLIT
);
3624 format
->internal
= 0;
3627 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
] || gl_info
->supported
[ARB_FRAGMENT_SHADER
])
3629 format
= get_format_gl_internal(adapter
, WINED3DFMT_P8_UINT
);
3630 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3633 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3635 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16_FLOAT
);
3636 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3638 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16_FLOAT
);
3639 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3641 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_FLOAT
);
3642 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3645 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3647 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_UNORM
);
3648 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3651 /* ATI instancing hack: Although ATI cards do not support Shader Model
3652 * 3.0, they support instancing. To query if the card supports instancing
3653 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3654 * is used. Should an application check for this, provide a proper return
3655 * value. We can do instancing with all shader versions, but we need
3658 * Additionally applications have to set the D3DRS_POINTSIZE render state
3659 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3660 * doesn't need that and just ignores it.
3662 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3663 /* FIXME: This should just check the shader backend caps. */
3664 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3666 format
= get_format_gl_internal(adapter
, WINED3DFMT_INST
);
3667 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3670 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3671 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3672 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3673 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3674 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3676 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3678 format
= get_format_gl_internal(adapter
, WINED3DFMT_NVDB
);
3679 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3682 if (gl_info
->supported
[ARB_MULTISAMPLE
])
3684 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATOC
);
3685 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3688 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3689 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3690 * RENDERTARGET usage. */
3691 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3693 format
= get_format_gl_internal(adapter
, WINED3DFMT_RESZ
);
3694 format_set_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_RENDERTARGET
);
3697 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3699 format
= get_format_gl_by_idx(adapter
, i
);
3701 if (!(format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3D_FORMAT_CAP_TEXTURE
))
3704 if (is_identity_fixup(format
->f
.color_fixup
))
3707 TRACE("Checking support for fixup:\n");
3708 dump_color_fixup_desc(format
->f
.color_fixup
);
3709 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->f
.color_fixup
)
3710 || !adapter
->fragment_pipe
->color_fixup_supported(format
->f
.color_fixup
))
3712 TRACE("[FAILED]\n");
3713 format_clear_caps(&format
->f
, WINED3D_FORMAT_CAP_TEXTURE
);
3721 /* These formats are not supported for 3D textures. See also
3722 * WINED3D_FORMAT_CAP_DECOMPRESS. */
3723 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI1N
);
3724 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3725 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI2N
);
3726 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3727 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC4_SNORM
);
3728 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3729 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_UNORM
);
3730 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3731 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_SNORM
);
3732 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3D_FORMAT_CAP_TEXTURE
;
3735 static BOOL
init_format_vertex_info(const struct wined3d_adapter
*adapter
,
3736 struct wined3d_gl_info
*gl_info
)
3738 struct wined3d_format_gl
*format
;
3741 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3743 if (!(format
= get_format_gl_internal(adapter
, format_vertex_info
[i
].id
)))
3746 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3749 format
->f
.emit_idx
= format_vertex_info
[i
].emit_idx
;
3750 format
->vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3751 format
->vtx_format
= format
->f
.component_count
;
3752 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE
;
3755 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3757 format
= get_format_gl_internal(adapter
, WINED3DFMT_B8G8R8A8_UNORM
);
3758 format
->vtx_format
= GL_BGRA
;
3764 static BOOL
init_typeless_formats(const struct wined3d_adapter
*adapter
)
3766 unsigned int caps
[WINED3D_GL_RES_TYPE_COUNT
];
3767 unsigned int attrs
, i
, j
;
3769 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3771 struct wined3d_format
*format
, *typeless_format
;
3773 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
3775 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
3778 attrs
= typeless_format
->attrs
;
3779 memcpy(caps
, typeless_format
->caps
, sizeof(caps
));
3780 copy_format(adapter
, typeless_format
, format
);
3781 typeless_format
->attrs
|= attrs
;
3782 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->caps
); ++j
)
3783 typeless_format
->caps
[j
] |= caps
[j
];
3786 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3788 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3789 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3790 enum wined3d_format_id format_id
;
3792 if (!(typeless_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3794 if (!(ds_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3797 typeless_ds_format
= get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
3798 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3799 copy_format(adapter
, typeless_ds_format
, ds_format
);
3800 typeless_ds_format
->attrs
= typeless_format
->attrs
;
3801 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->caps
); ++j
)
3803 typeless_ds_format
->caps
[j
] = typeless_format
->caps
[j
];
3804 typeless_format
->caps
[j
] &= ~WINED3D_FORMAT_CAP_DEPTH_STENCIL
;
3807 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
)
3808 && typeless_depth_stencil_formats
[i
].separate_depth_view_format
)
3810 if (!(depth_view_format
= get_format_internal(adapter
, format_id
)))
3812 copy_format(adapter
, depth_view_format
, ds_format
);
3813 depth_view_format
->red_size
= depth_view_format
->depth_size
;
3814 depth_view_format
->depth_size
= 0;
3815 depth_view_format
->stencil_size
= 0;
3817 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3819 if (!(stencil_view_format
= get_format_internal(adapter
, format_id
)))
3821 copy_format(adapter
, stencil_view_format
, ds_format
);
3822 stencil_view_format
->green_size
= stencil_view_format
->stencil_size
;
3823 stencil_view_format
->depth_size
= 0;
3824 stencil_view_format
->stencil_size
= 0;
3831 static void init_format_gen_mipmap_info(const struct wined3d_adapter
*adapter
,
3832 struct wined3d_gl_info
*gl_info
)
3836 if (!gl_info
->fbo_ops
.glGenerateMipmap
)
3839 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3841 struct wined3d_format
*format
= get_format_by_idx(adapter
, i
);
3843 for (j
= 0; j
< ARRAY_SIZE(format
->caps
); ++j
)
3844 if (!(~format
->caps
[j
] & (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FILTERING
)))
3845 format
->caps
[j
] |= WINED3D_FORMAT_CAP_GEN_MIPMAP
;
3849 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3851 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3852 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3853 static const float offset
= -63.0f
/ 128.0f
;
3854 GLuint texture
, fbo
;
3855 uint32_t readback
[4];
3858 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3859 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3860 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3861 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3862 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3863 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3864 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3865 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3866 GL_TEXTURE_2D
, texture
, 0);
3867 checkGLcall("create resources");
3869 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3870 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3871 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3872 draw_test_quad(ctx
, NULL
, &red
);
3873 checkGLcall("draw");
3875 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3876 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3877 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3878 checkGLcall("readback");
3880 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3881 readback
[0], readback
[1], readback
[2], readback
[3]);
3883 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3884 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3885 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3886 checkGLcall("delete resources");
3888 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3890 if (readback
[i
] != 0xffff0000)
3896 bool wined3d_caps_gl_ctx_test_filling_convention(struct wined3d_caps_gl_ctx
*ctx
, float offset
)
3898 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3899 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3900 unsigned int x
, y
, clear
= 0, draw
= 0;
3901 GLuint texture
, fbo
;
3902 uint32_t readback
[8][8];
3904 /* This is a very simple test to find out how GL handles polygon edges:
3905 * Draw a 1x1 quad exactly through 4 adjacent pixel centers in an 8x8
3906 * viewport and see which pixel it ends up in. So far we've seen top left
3907 * and bottom left conventions. This test may produce unexpected results
3908 * if the driver forces multisampling on us.
3910 * If we find a bottom-left filling behavior we also move the x-axis
3911 * by the same amount. This is necessary to keep diagonals that go
3912 * through the pixel center intact.
3914 * Note that we are ignoring some settings that might influence the
3915 * driver: How we switch GL to an upper-left coordinate system,
3916 * shaders vs fixed function GL. Testing these isn't possible with
3917 * the current draw_test_quad() infrastructure. Also the test is
3918 * skipped if we are not using FBOs. Drawing into the onscreen
3919 * frame buffer may also yield different driver behavior.
3921 * The minimum offset also depends on the viewport size, although
3922 * the relation between those two is GPU dependent and not exactly
3923 * sensible. E.g. a 8192x8192 viewport on a GeForce 9 needs at
3924 * least an offset of 1/240.9, whereas a 8x8 one needs 1/255.982;
3925 * 32x32 needs 1/255.935. 4x4 and lower are happy with something
3926 * below 1/256. The 8x8 size below has been arbitrarily chosen to
3927 * get a useful result out of that card and avoid allocating a
3928 * gigantic texture during library init.
3930 * Newer cards usually do the right thing anyway. In cases where
3931 * they do not (e.g. Radeon GPUs in a macbookpro14,3 running MacOS)
3932 * an offset of 1/2^20 is enough. */
3933 const struct wined3d_vec3 edge_geometry
[] =
3935 {(-1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3936 {( 1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3937 {(-1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3938 {( 1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3941 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3942 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3943 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3944 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 8, 8, 0,
3945 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3946 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3947 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3948 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3949 GL_TEXTURE_2D
, texture
, 0);
3950 checkGLcall("create resources");
3952 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 8, 8);
3953 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 1.0f
, 1.0f
);
3954 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3956 draw_test_quad(ctx
, edge_geometry
, &red
);
3957 checkGLcall("draw");
3959 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3960 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3961 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3962 checkGLcall("readback");
3964 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3965 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3966 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3967 checkGLcall("delete resources");
3969 /* We expect that exactly one fragment is generated. */
3970 for (y
= 0; y
< ARRAY_SIZE(readback
); ++y
)
3972 for (x
= 0; x
< ARRAY_SIZE(readback
[0]); ++x
)
3974 if (readback
[y
][x
] == 0xff0000ff)
3976 else if (readback
[y
][x
] == 0xffff0000)
3981 if (clear
!= 63 || draw
!= 1)
3983 FIXME("Unexpected filling convention test result.\n");
3987 /* One pixel was drawn, check if it is the expected one */
3988 return readback
[3][3] == 0xffff0000;
3990 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3992 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3993 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3994 GLuint fbo
, color
, depth
;
3995 unsigned int low
= 0, high
= 32, cur
;
3996 uint32_t readback
[256];
3997 static const struct wined3d_vec3 geometry
[] =
3999 {-1.0f
, -1.0f
, -1.0f
},
4000 { 1.0f
, -1.0f
, 0.0f
},
4001 {-1.0f
, 1.0f
, -1.0f
},
4002 { 1.0f
, 1.0f
, 0.0f
},
4005 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
4006 * Nvidia. Use this as a fallback if the detection fails. */
4007 unsigned int fallback
= 23;
4009 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
4010 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4011 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
4012 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);
4014 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
4015 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
4016 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
4018 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
4019 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
4020 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
4021 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
4022 checkGLcall("Setup framebuffer");
4024 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
4025 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
4026 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
4027 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
4028 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
4029 checkGLcall("Misc parameters");
4033 if (high
- low
<= 1)
4035 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
4039 cur
= (low
+ high
) / 2;
4041 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
4042 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
4043 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
4044 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
4045 draw_test_quad(ctx
, geometry
, &blue
);
4046 checkGLcall("Test draw");
4048 /* Rebinding texture to workaround a fglrx bug. */
4049 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4050 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
4051 checkGLcall("readback");
4053 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
4054 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
4056 if ((readback
[125] & 0xff) < 0xa0)
4058 else if ((readback
[131] & 0xff) > 0xa0)
4062 TRACE("Found scale factor 2^%u for format %x.\n", cur
, format
);
4067 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
4068 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
4069 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
4070 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
4071 checkGLcall("Delete framebuffer");
4073 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
4074 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
4075 return (float)(1u << cur
);
4078 static void init_format_depth_bias_scale(struct wined3d_adapter
*adapter
,
4079 struct wined3d_caps_gl_ctx
*ctx
)
4081 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
4084 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4086 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
4088 if (format
->f
.depth_size
&& (format
->f
.caps
[WINED3D_GL_RES_TYPE_RB
] & WINED3D_FORMAT_CAP_DEPTH_STENCIL
))
4090 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format
->f
.id
));
4091 format
->f
.depth_bias_scale
= wined3d_adapter_find_polyoffset_scale(ctx
, format
->internal
);
4093 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_NORMALIZED_DEPTH_BIAS
))
4095 /* The single-precision binary floating-point format has
4096 * a significand precision of 24 bits.
4098 if (format
->f
.attrs
& WINED3D_FORMAT_ATTR_FLOAT
)
4099 format
->f
.depth_bias_scale
/= 1u << 24;
4101 format
->f
.depth_bias_scale
/= 1u << format
->f
.depth_size
;
4107 static BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, size_t format_size
)
4109 unsigned int count
= WINED3D_FORMAT_COUNT
+ ARRAY_SIZE(typeless_depth_stencil_formats
);
4111 if (!(adapter
->formats
= calloc(count
, format_size
)))
4113 ERR("Failed to allocate memory.\n");
4116 adapter
->format_size
= format_size
;
4118 if (!init_format_base_info(adapter
))
4120 if (!init_format_block_info(adapter
))
4122 if (!init_format_decompress_info(adapter
))
4124 if (!init_srgb_formats(adapter
))
4130 free(adapter
->formats
);
4131 adapter
->formats
= NULL
;
4135 BOOL
wined3d_adapter_no3d_init_format_info(struct wined3d_adapter
*adapter
)
4137 struct wined3d_format
*format
;
4140 static const enum wined3d_format_id blit_formats
[] =
4142 WINED3DFMT_B8G8R8A8_UNORM
,
4143 WINED3DFMT_B8G8R8X8_UNORM
,
4144 WINED3DFMT_B5G6R5_UNORM
,
4145 WINED3DFMT_B5G5R5X1_UNORM
,
4146 WINED3DFMT_B5G5R5A1_UNORM
,
4147 WINED3DFMT_B4G4R4A4_UNORM
,
4148 WINED3DFMT_B2G3R3_UNORM
,
4149 WINED3DFMT_A8_UNORM
,
4150 WINED3DFMT_B2G3R3A8_UNORM
,
4151 WINED3DFMT_B4G4R4X4_UNORM
,
4152 WINED3DFMT_R10G10B10A2_UNORM
,
4153 WINED3DFMT_R8G8B8A8_UNORM
,
4154 WINED3DFMT_R8G8B8X8_UNORM
,
4155 WINED3DFMT_R16G16_UNORM
,
4156 WINED3DFMT_B10G10R10A2_UNORM
,
4157 WINED3DFMT_R16G16B16A16_UNORM
,
4161 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format
)))
4164 for (i
= 0; i
< ARRAY_SIZE(blit_formats
); ++i
)
4166 if (!(format
= get_format_internal(adapter
, blit_formats
[i
])))
4169 format
->caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= WINED3D_FORMAT_CAP_BLIT
;
4170 format
->caps
[WINED3D_GL_RES_TYPE_RB
] |= WINED3D_FORMAT_CAP_BLIT
;
4176 /* Context activation is done by the caller. */
4177 BOOL
wined3d_adapter_gl_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
4179 struct wined3d_gl_info
*gl_info
= &wined3d_adapter_gl(adapter
)->gl_info
;
4181 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format_gl
)))
4184 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
4185 if (!init_format_vertex_info(adapter
, gl_info
)) goto fail
;
4187 apply_format_fixups(adapter
, gl_info
);
4188 init_format_fbo_compat_info(adapter
, ctx
);
4189 init_format_filter_info(adapter
, gl_info
);
4190 init_format_gen_mipmap_info(adapter
, gl_info
);
4191 init_format_depth_bias_scale(adapter
, ctx
);
4193 if (!init_typeless_formats(adapter
)) goto fail
;
4198 free(adapter
->formats
);
4199 adapter
->formats
= NULL
;
4203 static void init_vulkan_format_info(struct wined3d_format_vk
*format
,
4204 const struct wined3d_vk_info
*vk_info
, VkPhysicalDevice vk_physical_device
)
4208 enum wined3d_format_id id
;
4214 {WINED3DFMT_R32G32B32A32_FLOAT
, VK_FORMAT_R32G32B32A32_SFLOAT
, },
4215 {WINED3DFMT_R32G32B32A32_UINT
, VK_FORMAT_R32G32B32A32_UINT
, },
4216 {WINED3DFMT_R32G32B32A32_SINT
, VK_FORMAT_R32G32B32A32_SINT
, },
4217 {WINED3DFMT_R32G32B32_FLOAT
, VK_FORMAT_R32G32B32_SFLOAT
, },
4218 {WINED3DFMT_R32G32B32_UINT
, VK_FORMAT_R32G32B32_UINT
, },
4219 {WINED3DFMT_R32G32B32_SINT
, VK_FORMAT_R32G32B32_SINT
, },
4220 {WINED3DFMT_R16G16B16A16_FLOAT
, VK_FORMAT_R16G16B16A16_SFLOAT
, },
4221 {WINED3DFMT_R16G16B16A16_UNORM
, VK_FORMAT_R16G16B16A16_UNORM
, },
4222 {WINED3DFMT_R16G16B16A16_UINT
, VK_FORMAT_R16G16B16A16_UINT
, },
4223 {WINED3DFMT_R16G16B16A16_SNORM
, VK_FORMAT_R16G16B16A16_SNORM
, },
4224 {WINED3DFMT_R16G16B16A16_SINT
, VK_FORMAT_R16G16B16A16_SINT
, },
4225 {WINED3DFMT_R32G32_FLOAT
, VK_FORMAT_R32G32_SFLOAT
, },
4226 {WINED3DFMT_R32G32_UINT
, VK_FORMAT_R32G32_UINT
, },
4227 {WINED3DFMT_R32G32_SINT
, VK_FORMAT_R32G32_SINT
, },
4228 {WINED3DFMT_R10G10B10A2_UNORM
, VK_FORMAT_A2B10G10R10_UNORM_PACK32
,},
4229 {WINED3DFMT_R11G11B10_FLOAT
, VK_FORMAT_B10G11R11_UFLOAT_PACK32
, },
4230 {WINED3DFMT_R8G8_UNORM
, VK_FORMAT_R8G8_UNORM
, },
4231 {WINED3DFMT_R8G8_UINT
, VK_FORMAT_R8G8_UINT
, },
4232 {WINED3DFMT_R8G8_SNORM
, VK_FORMAT_R8G8_SNORM
, },
4233 {WINED3DFMT_R8G8_SINT
, VK_FORMAT_R8G8_SINT
, },
4234 {WINED3DFMT_R8G8B8A8_UNORM
, VK_FORMAT_R8G8B8A8_UNORM
, },
4235 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, VK_FORMAT_R8G8B8A8_SRGB
, },
4236 {WINED3DFMT_R8G8B8A8_UINT
, VK_FORMAT_R8G8B8A8_UINT
, },
4237 {WINED3DFMT_R8G8B8A8_SNORM
, VK_FORMAT_R8G8B8A8_SNORM
, },
4238 {WINED3DFMT_R8G8B8A8_SINT
, VK_FORMAT_R8G8B8A8_SINT
, },
4239 {WINED3DFMT_R16G16_FLOAT
, VK_FORMAT_R16G16_SFLOAT
, },
4240 {WINED3DFMT_R16G16_UNORM
, VK_FORMAT_R16G16_UNORM
, },
4241 {WINED3DFMT_R16G16_UINT
, VK_FORMAT_R16G16_UINT
, },
4242 {WINED3DFMT_R16G16_SNORM
, VK_FORMAT_R16G16_SNORM
, },
4243 {WINED3DFMT_R16G16_SINT
, VK_FORMAT_R16G16_SINT
, },
4244 {WINED3DFMT_D32_FLOAT
, VK_FORMAT_D32_SFLOAT
, },
4245 {WINED3DFMT_R32_FLOAT
, VK_FORMAT_R32_SFLOAT
, },
4246 {WINED3DFMT_R32_UINT
, VK_FORMAT_R32_UINT
, },
4247 {WINED3DFMT_R32_SINT
, VK_FORMAT_R32_SINT
, },
4248 {WINED3DFMT_R16_FLOAT
, VK_FORMAT_R16_SFLOAT
, },
4249 {WINED3DFMT_D16_UNORM
, VK_FORMAT_D16_UNORM
, },
4250 {WINED3DFMT_R16_UNORM
, VK_FORMAT_R16_UNORM
, },
4251 {WINED3DFMT_R16_UINT
, VK_FORMAT_R16_UINT
, },
4252 {WINED3DFMT_R16_SNORM
, VK_FORMAT_R16_SNORM
, },
4253 {WINED3DFMT_R16_SINT
, VK_FORMAT_R16_SINT
, },
4254 {WINED3DFMT_R8_UNORM
, VK_FORMAT_R8_UNORM
, },
4255 {WINED3DFMT_R8_UINT
, VK_FORMAT_R8_UINT
, },
4256 {WINED3DFMT_R8_SNORM
, VK_FORMAT_R8_SNORM
, },
4257 {WINED3DFMT_R8_SINT
, VK_FORMAT_R8_SINT
, },
4258 {WINED3DFMT_A8_UNORM
, VK_FORMAT_R8_UNORM
, "000X"},
4259 {WINED3DFMT_B8G8R8A8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, },
4260 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, },
4261 {WINED3DFMT_B8G8R8X8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, "XYZ1"},
4262 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, "XYZ1"},
4263 {WINED3DFMT_B5G6R5_UNORM
, VK_FORMAT_R5G6B5_UNORM_PACK16
, },
4264 {WINED3DFMT_BC1_UNORM
, VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, },
4265 {WINED3DFMT_BC1_UNORM_SRGB
, VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, },
4266 {WINED3DFMT_BC2_UNORM
, VK_FORMAT_BC2_UNORM_BLOCK
, },
4267 {WINED3DFMT_BC2_UNORM_SRGB
, VK_FORMAT_BC2_SRGB_BLOCK
, },
4268 {WINED3DFMT_BC3_UNORM
, VK_FORMAT_BC3_UNORM_BLOCK
, },
4269 {WINED3DFMT_BC3_UNORM_SRGB
, VK_FORMAT_BC3_SRGB_BLOCK
, },
4270 {WINED3DFMT_BC4_UNORM
, VK_FORMAT_BC4_UNORM_BLOCK
, },
4271 {WINED3DFMT_BC4_SNORM
, VK_FORMAT_BC4_SNORM_BLOCK
, },
4272 {WINED3DFMT_BC5_UNORM
, VK_FORMAT_BC5_UNORM_BLOCK
, },
4273 {WINED3DFMT_BC5_SNORM
, VK_FORMAT_BC5_SNORM_BLOCK
, },
4274 {WINED3DFMT_BC6H_UF16
, VK_FORMAT_BC6H_UFLOAT_BLOCK
, },
4275 {WINED3DFMT_BC6H_SF16
, VK_FORMAT_BC6H_SFLOAT_BLOCK
, },
4276 {WINED3DFMT_BC7_UNORM
, VK_FORMAT_BC7_UNORM_BLOCK
, },
4277 {WINED3DFMT_BC7_UNORM_SRGB
, VK_FORMAT_BC7_SRGB_BLOCK
, },
4278 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, },
4279 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4280 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4281 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4282 {WINED3DFMT_D24_UNORM_S8_UINT
, VK_FORMAT_D24_UNORM_S8_UINT
, },
4284 VkFormat vk_format
= VK_FORMAT_UNDEFINED
;
4285 VkImageFormatProperties image_properties
;
4286 VkFormatFeatureFlags texture_flags
;
4287 VkFormatProperties properties
;
4288 VkImageUsageFlags vk_usage
;
4295 for (i
= 0; i
< ARRAY_SIZE(vulkan_formats
); ++i
)
4297 if (vulkan_formats
[i
].id
== format
->f
.id
)
4299 vk_format
= vulkan_formats
[i
].vk_format
;
4300 fixup
= vulkan_formats
[i
].fixup
;
4306 WARN("Unsupported format %s.\n", debug_d3dformat(format
->f
.id
));
4310 format
->vk_format
= vk_format
;
4312 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixup
);
4314 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
4316 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4317 if (vk_format
== VK_FORMAT_D24_UNORM_S8_UINT
)
4319 if (~properties
.optimalTilingFeatures
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4321 /* AMD doesn't support VK_FORMAT_D24_UNORM_S8_UINT. */
4322 WARN("Mapping VK_FORMAT_D24_UNORM_S8_UINT to VK_FORMAT_D32_SFLOAT_S8_UINT.\n");
4324 format
->vk_format
= vk_format
= VK_FORMAT_D32_SFLOAT_S8_UINT
;
4325 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4329 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
)
4330 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE
;
4331 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
)
4332 format
->f
.caps
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3D_FORMAT_CAP_TEXTURE
;
4335 texture_flags
= properties
.linearTilingFeatures
| properties
.optimalTilingFeatures
;
4336 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)
4338 caps
|= WINED3D_FORMAT_CAP_TEXTURE
| WINED3D_FORMAT_CAP_VTF
;
4340 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4342 caps
|= WINED3D_FORMAT_CAP_RENDERTARGET
;
4344 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
)
4346 caps
|= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING
;
4348 if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4350 caps
|= WINED3D_FORMAT_CAP_DEPTH_STENCIL
;
4352 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
)
4354 caps
|= WINED3D_FORMAT_CAP_FILTERING
;
4356 if (texture_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)
4358 caps
|= WINED3D_FORMAT_CAP_UNORDERED_ACCESS
;
4360 if ((texture_flags
& VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
)
4361 && (texture_flags
& VK_FORMAT_FEATURE_TRANSFER_DST_BIT
))
4363 caps
|= WINED3D_FORMAT_CAP_BLIT
;
4366 if (!(~caps
& (WINED3D_FORMAT_CAP_RENDERTARGET
| WINED3D_FORMAT_CAP_FILTERING
)))
4367 caps
|= WINED3D_FORMAT_CAP_GEN_MIPMAP
;
4369 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_1D
] |= caps
;
4370 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_2D
] |= caps
;
4371 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_3D
] |= caps
;
4372 format
->f
.caps
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= caps
;
4375 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4376 vk_usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
4377 else if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4378 vk_usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
4381 if ((vr
= VK_CALL(vkGetPhysicalDeviceImageFormatProperties(vk_physical_device
, vk_format
,
4382 VK_IMAGE_TYPE_2D
, VK_IMAGE_TILING_OPTIMAL
, vk_usage
, 0, &image_properties
))) < 0)
4384 ERR("Failed to get image format properties, vr %s.\n", wined3d_debug_vkresult(vr
));
4388 mask
= image_properties
.sampleCounts
& 0x3f;
4391 i
= (1u << wined3d_bit_scan(&mask
)) - 1;
4392 format
->f
.multisample_types
|= 1u << i
;
4397 BOOL
wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk
*adapter_vk
,
4398 const struct wined3d_vk_info
*vk_info
)
4400 VkPhysicalDevice vk_physical_device
= adapter_vk
->physical_device
;
4401 struct wined3d_adapter
*adapter
= &adapter_vk
->a
;
4402 struct wined3d_format_vk
*format
;
4405 if (!wined3d_adapter_init_format_info(adapter
, sizeof(*format
)))
4408 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4410 format
= wined3d_format_vk_mutable(get_format_by_idx(adapter
, i
));
4413 init_vulkan_format_info(format
, vk_info
, vk_physical_device
);
4416 if (!init_typeless_formats(adapter
)) goto fail
;
4421 free(adapter
->formats
);
4422 adapter
->formats
= NULL
;
4426 const struct wined3d_format
*wined3d_get_format(const struct wined3d_adapter
*adapter
,
4427 enum wined3d_format_id format_id
, unsigned int bind_flags
)
4429 const struct wined3d_format
*format
;
4430 int idx
= get_format_idx(format_id
);
4435 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
4436 debug_d3dformat(format_id
), format_id
);
4437 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4440 format
= get_format_by_idx(adapter
, idx
);
4442 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
&& wined3d_format_is_typeless(format
))
4444 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4446 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
4447 return get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
4450 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
4451 debug_d3dformat(format_id
), format_id
);
4452 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4458 enum wined3d_format_id
wined3d_get_typed_format_id(const struct wined3d_adapter
*adapter
,
4459 const struct wined3d_format
*format
, enum wined3d_channel_type channel_type
)
4461 const struct wined3d_typed_format_info
*info
;
4464 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
4466 info
= &typed_formats
[i
];
4467 if (info
->typeless_id
== format
->typeless_id
&& map_channel_type(info
->channels
[0]) == channel_type
)
4471 return WINED3DFMT_UNKNOWN
;
4474 BOOL
wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id
,
4475 enum wined3d_format_id view_format_id
)
4479 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4481 if (typeless_depth_stencil_formats
[i
].typeless_id
== resource_format_id
)
4482 return typeless_depth_stencil_formats
[i
].depth_view_id
== view_format_id
;
4487 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
4488 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
4490 /* For block based formats, pitch means the amount of bytes to the next
4491 * row of blocks rather than the next row of pixels. */
4492 if (format
->attrs
& WINED3D_FORMAT_ATTR_BLOCKS
)
4494 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
4495 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
4496 *row_pitch
= row_block_count
* format
->block_byte_count
;
4497 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4498 *slice_pitch
= *row_pitch
* slice_block_count
;
4502 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
4503 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4504 *slice_pitch
= *row_pitch
* height
;
4507 if (format
->attrs
& WINED3D_FORMAT_ATTR_HEIGHT_SCALE
)
4509 /* The D3D format requirements make sure that the resulting format is an integer again */
4510 *slice_pitch
*= format
->height_scale
.numerator
;
4511 *slice_pitch
/= format
->height_scale
.denominator
;
4514 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
4517 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
4518 UINT width
, UINT height
, UINT depth
)
4520 unsigned int row_pitch
, slice_pitch
;
4522 if (format
->id
== WINED3DFMT_UNKNOWN
)
4525 if (format
->attrs
& WINED3D_FORMAT_ATTR_BROKEN_PITCH
)
4526 return width
* height
* depth
* format
->byte_count
;
4528 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
4530 return slice_pitch
* depth
;
4533 BOOL
wined3d_formats_are_srgb_variants(enum wined3d_format_id format1
, enum wined3d_format_id format2
)
4537 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
4539 if (format1
== format_srgb_info
[i
].srgb_format_id
)
4540 return format2
== format_srgb_info
[i
].base_format_id
;
4541 if (format1
== format_srgb_info
[i
].base_format_id
)
4542 return format2
== format_srgb_info
[i
].srgb_format_id
;
4547 /*****************************************************************************
4548 * Trace formatting of useful values
4550 const char *debug_box(const struct wined3d_box
*box
)
4554 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
4555 box
->left
, box
->top
, box
->front
,
4556 box
->right
, box
->bottom
, box
->back
);
4559 const char *debug_color(const struct wined3d_color
*color
)
4563 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4564 color
->r
, color
->g
, color
->b
, color
->a
);
4567 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
4571 return wine_dbg_sprintf("{%d, %d, %d, %d}",
4572 v
->x
, v
->y
, v
->z
, v
->w
);
4575 const char *debug_uvec4(const struct wined3d_uvec4
*v
)
4579 return wine_dbg_sprintf("{%u, %u, %u, %u}",
4580 v
->x
, v
->y
, v
->z
, v
->w
);
4583 const char *debug_vec4(const struct wined3d_vec4
*v
)
4587 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4588 v
->x
, v
->y
, v
->z
, v
->w
);
4591 const char *debug_const_bo_address(const struct wined3d_const_bo_address
*address
)
4595 return wine_dbg_sprintf("{%p:%p}", address
->buffer_object
, address
->addr
);
4598 const char *debug_bo_address(const struct wined3d_bo_address
*address
)
4600 return debug_const_bo_address((const struct wined3d_const_bo_address
*)address
);
4603 const char *debug_d3dformat(enum wined3d_format_id format_id
)
4607 #define FMT_TO_STR(format_id) case format_id: return #format_id
4608 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
4609 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
4610 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
4611 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
4612 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
4613 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
4614 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
4615 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
4616 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
4617 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
4618 FMT_TO_STR(WINED3DFMT_P8_UINT
);
4619 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
4620 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
4621 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
4622 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
4623 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
4624 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
4625 FMT_TO_STR(WINED3DFMT_R10G10B10X2_TYPELESS
);
4626 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
4627 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
4628 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
4629 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
4630 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
4631 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
4632 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
4633 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
4634 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
4635 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
4636 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
4637 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
4638 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
4639 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
4640 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
4641 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
4642 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
4643 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
4644 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
4645 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
4646 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
4647 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
4648 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
4649 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
4650 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
4651 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
4652 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
4653 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
4654 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
4655 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
4656 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
4657 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
4658 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
4659 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
4660 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
4661 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
4662 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
4663 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
4664 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
4665 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
4666 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
4667 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
4668 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
4669 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
4670 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
4671 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
4672 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
4673 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
4674 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
4675 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
4676 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
4677 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
4678 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
4679 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
4680 FMT_TO_STR(WINED3DFMT_R32_UINT
);
4681 FMT_TO_STR(WINED3DFMT_R32_SINT
);
4682 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
4683 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
4684 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
4685 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
4686 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
4687 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
4688 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
4689 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
4690 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
4691 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
4692 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
4693 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
4694 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
4695 FMT_TO_STR(WINED3DFMT_R16_UINT
);
4696 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
4697 FMT_TO_STR(WINED3DFMT_R16_SINT
);
4698 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
4699 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
4700 FMT_TO_STR(WINED3DFMT_R8_UINT
);
4701 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
4702 FMT_TO_STR(WINED3DFMT_R8_SINT
);
4703 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
4704 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
4705 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
4706 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
4707 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
4708 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
4709 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
4710 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
4711 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
4712 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
4713 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
4714 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
4715 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
4716 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
4717 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
4718 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
4719 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
4720 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
4721 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
4722 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
4723 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
4724 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
4725 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
4726 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
4727 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
4728 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
4729 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
4730 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
4731 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
4732 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
4733 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
4734 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
4735 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
4736 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
4737 FMT_TO_STR(WINED3DFMT_UYVY
);
4738 FMT_TO_STR(WINED3DFMT_YUY2
);
4739 FMT_TO_STR(WINED3DFMT_YV12
);
4740 FMT_TO_STR(WINED3DFMT_DXT1
);
4741 FMT_TO_STR(WINED3DFMT_DXT2
);
4742 FMT_TO_STR(WINED3DFMT_DXT3
);
4743 FMT_TO_STR(WINED3DFMT_DXT4
);
4744 FMT_TO_STR(WINED3DFMT_DXT5
);
4745 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
4746 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
4747 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
4748 FMT_TO_STR(WINED3DFMT_ATI1N
);
4749 FMT_TO_STR(WINED3DFMT_ATI2N
);
4750 FMT_TO_STR(WINED3DFMT_INST
);
4751 FMT_TO_STR(WINED3DFMT_NVDB
);
4752 FMT_TO_STR(WINED3DFMT_NVHU
);
4753 FMT_TO_STR(WINED3DFMT_NVHS
);
4754 FMT_TO_STR(WINED3DFMT_INTZ
);
4755 FMT_TO_STR(WINED3DFMT_RESZ
);
4756 FMT_TO_STR(WINED3DFMT_NULL
);
4757 FMT_TO_STR(WINED3DFMT_R16
);
4758 FMT_TO_STR(WINED3DFMT_AL16
);
4759 FMT_TO_STR(WINED3DFMT_NV12
);
4760 FMT_TO_STR(WINED3DFMT_ATOC
);
4765 fourcc
[0] = (char)(format_id
);
4766 fourcc
[1] = (char)(format_id
>> 8);
4767 fourcc
[2] = (char)(format_id
>> 16);
4768 fourcc
[3] = (char)(format_id
>> 24);
4770 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
4771 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
4773 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
4775 return "unrecognized";
4779 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
4781 switch (device_type
)
4783 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4784 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
4785 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
4786 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
4787 #undef DEVTYPE_TO_STR
4789 FIXME("Unrecognized device type %#x.\n", device_type
);
4790 return "unrecognized";
4796 char str
[200]; /* wine_dbg_sprintf() limits string size to 200 */
4801 static void init_debug_buffer(struct debug_buffer
*buffer
, const char *default_string
)
4803 snprintf(buffer
->str
, sizeof(buffer
->str
), "%s", default_string
);
4804 buffer
->ptr
= buffer
->str
;
4805 buffer
->size
= sizeof(buffer
->str
);
4808 static void debug_append(struct debug_buffer
*buffer
, const char *str
, const char *separator
)
4812 if (!separator
|| buffer
->ptr
== buffer
->str
)
4814 size
= snprintf(buffer
->ptr
, buffer
->size
, "%s%s", separator
, str
);
4815 if (size
== -1 || size
>= buffer
->size
)
4818 strcpy(&buffer
->str
[sizeof(buffer
->str
) - 4], "...");
4822 buffer
->ptr
+= size
;
4823 buffer
->size
-= size
;
4826 const char *wined3d_debug_resource_access(uint32_t access
)
4828 struct debug_buffer buffer
;
4830 init_debug_buffer(&buffer
, "0");
4831 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4832 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU
);
4833 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU
);
4834 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R
);
4835 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W
);
4836 #undef ACCESS_TO_STR
4838 FIXME("Unrecognised access flag(s) %#x.\n", access
);
4840 return wine_dbg_sprintf("%s", buffer
.str
);
4843 const char *wined3d_debug_bind_flags(uint32_t bind_flags
)
4845 struct debug_buffer buffer
;
4847 init_debug_buffer(&buffer
, "0");
4848 #define BIND_FLAG_TO_STR(x) if (bind_flags & x) { debug_append(&buffer, #x, " | "); bind_flags &= ~x; }
4849 BIND_FLAG_TO_STR(WINED3D_BIND_VERTEX_BUFFER
);
4850 BIND_FLAG_TO_STR(WINED3D_BIND_INDEX_BUFFER
);
4851 BIND_FLAG_TO_STR(WINED3D_BIND_CONSTANT_BUFFER
);
4852 BIND_FLAG_TO_STR(WINED3D_BIND_SHADER_RESOURCE
);
4853 BIND_FLAG_TO_STR(WINED3D_BIND_STREAM_OUTPUT
);
4854 BIND_FLAG_TO_STR(WINED3D_BIND_RENDER_TARGET
);
4855 BIND_FLAG_TO_STR(WINED3D_BIND_DEPTH_STENCIL
);
4856 BIND_FLAG_TO_STR(WINED3D_BIND_UNORDERED_ACCESS
);
4857 BIND_FLAG_TO_STR(WINED3D_BIND_INDIRECT_BUFFER
);
4858 #undef BIND_FLAG_TO_STR
4860 FIXME("Unrecognised bind flag(s) %#x.\n", bind_flags
);
4862 return wine_dbg_sprintf("%s", buffer
.str
);
4865 const char *wined3d_debug_view_desc(const struct wined3d_view_desc
*d
, const struct wined3d_resource
*resource
)
4867 struct debug_buffer buffer
;
4868 unsigned int flags
= d
->flags
;
4870 init_debug_buffer(&buffer
, "0");
4871 #define VIEW_FLAG_TO_STR(x) if (flags & x) { debug_append(&buffer, #x, " | "); flags &= ~x; }
4872 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_RAW
);
4873 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_APPEND
);
4874 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_COUNTER
);
4875 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_CUBE
);
4876 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_ARRAY
);
4877 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_DEPTH
);
4878 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_STENCIL
);
4879 VIEW_FLAG_TO_STR(WINED3D_VIEW_FORWARD_REFERENCE
);
4880 #undef VIEW_FLAG_TO_STR
4882 FIXME("Unrecognised view flag(s) %#x.\n", flags
);
4884 if (resource
->type
== WINED3D_RTYPE_BUFFER
)
4885 return wine_dbg_sprintf("format %s, flags %s, start_idx %u, count %u",
4886 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.buffer
.start_idx
, d
->u
.buffer
.count
);
4888 return wine_dbg_sprintf("format %s, flags %s, level_idx %u, level_count %u, layer_idx %u, layer_count %u",
4889 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.texture
.level_idx
, d
->u
.texture
.level_count
,
4890 d
->u
.texture
.layer_idx
, d
->u
.texture
.layer_count
);
4893 const char *debug_d3dusage(uint32_t usage
)
4895 struct debug_buffer buffer
;
4897 init_debug_buffer(&buffer
, "0");
4898 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4899 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
4900 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
4901 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
4902 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
4903 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
4904 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
4905 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
4906 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
4907 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
4908 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
4909 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
4910 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
4911 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
4912 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
4913 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
4914 WINED3DUSAGE_TO_STR(WINED3DUSAGE_MANAGED
);
4915 WINED3DUSAGE_TO_STR(WINED3DUSAGE_VIDMEM_ACCOUNTING
);
4916 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
4917 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP
);
4918 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
4919 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
4920 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
4921 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
4922 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
4923 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4924 #undef WINED3DUSAGE_TO_STR
4926 FIXME("Unrecognized usage flag(s) %#x.\n", usage
);
4928 return wine_dbg_sprintf("%s", buffer
.str
);
4931 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4935 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4936 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4937 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4938 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4939 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4940 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4941 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4942 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4943 #undef WINED3DDECLMETHOD_TO_STR
4945 FIXME("Unrecognized declaration method %#x.\n", method
);
4946 return "unrecognized";
4950 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4954 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4955 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4956 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4957 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4958 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4959 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
4960 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
4961 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
4962 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
4963 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
4964 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
4965 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
4966 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
4967 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
4968 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
4969 #undef WINED3DDECLUSAGE_TO_STR
4971 FIXME("Unrecognized %u declaration usage!\n", usage
);
4972 return "unrecognized";
4976 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
4978 switch (classification
)
4980 #define WINED3D_TO_STR(x) case x: return #x
4981 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
4982 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
4983 #undef WINED3D_TO_STR
4985 FIXME("Unrecognized input classification %#x.\n", classification
);
4986 return "unrecognized";
4990 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
4992 switch (resource_type
)
4994 #define WINED3D_TO_STR(x) case x: return #x
4995 WINED3D_TO_STR(WINED3D_RTYPE_NONE
);
4996 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
4997 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D
);
4998 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
4999 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
5000 #undef WINED3D_TO_STR
5002 FIXME("Unrecognized resource type %#x.\n", resource_type
);
5003 return "unrecognized";
5007 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
5009 switch (primitive_type
)
5011 #define PRIM_TO_STR(prim) case prim: return #prim
5012 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
5013 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
5014 PRIM_TO_STR(WINED3D_PT_LINELIST
);
5015 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
5016 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
5017 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
5018 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
5019 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
5020 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
5021 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
5022 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
5023 PRIM_TO_STR(WINED3D_PT_PATCH
);
5026 FIXME("Unrecognized primitive type %#x.\n", primitive_type
);
5027 return "unrecognized";
5031 const char *debug_d3drenderstate(enum wined3d_render_state state
)
5035 #define D3DSTATE_TO_STR(u) case u: return #u
5036 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
5037 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
5038 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
5039 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
5040 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
5041 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
5042 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
5043 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
5044 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
5045 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
5046 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
5047 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
5048 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
5049 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
5050 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
5051 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
5052 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
5053 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
5054 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
5055 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
5056 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
5057 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
5058 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
5059 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
5060 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
5061 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
5062 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
5063 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
5064 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
5065 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
5066 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
5067 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
5068 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
5069 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
5070 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
5071 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
5072 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
5073 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
5074 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
5075 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
5076 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
5077 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
5078 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
5079 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
5080 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
5081 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
5082 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
5083 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
5084 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
5085 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
5086 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
5087 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
5088 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
5089 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
5090 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
5091 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
5092 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
5093 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
5094 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
5095 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
5096 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
5097 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
5098 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
5099 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
5100 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
5101 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
5102 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
5103 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
5104 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
5105 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
5106 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
5107 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
5108 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
5109 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
5110 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
5111 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
5112 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
5113 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
5114 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
5115 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
5116 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
5117 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
5118 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
5119 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
5120 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
5121 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
5122 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
5123 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
5124 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
5125 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
5126 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
5127 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
5128 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
5129 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
5130 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
5131 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
5132 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
5133 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
5134 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
5135 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
5136 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
5137 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
5138 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
5139 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
5140 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
5141 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
5142 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
5143 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
5144 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
5145 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
5146 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
5147 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
5148 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
5149 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
5150 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
5151 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
5152 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
5153 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
5154 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
5155 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
5156 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
5157 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
5158 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
5159 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
5160 #undef D3DSTATE_TO_STR
5162 FIXME("Unrecognized %u render state!\n", state
);
5163 return "unrecognized";
5167 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
5171 #define D3DSTATE_TO_STR(u) case u: return #u
5172 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
5173 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
5174 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
5175 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
5176 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
5177 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
5178 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
5179 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
5180 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
5181 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
5182 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
5183 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
5184 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
5185 #undef D3DSTATE_TO_STR
5187 FIXME("Unrecognized %u sampler state!\n", state
);
5188 return "unrecognized";
5192 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
5194 switch (filter_type
)
5196 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
5197 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
5198 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
5199 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
5200 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
5201 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
5202 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
5203 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
5204 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
5205 #undef D3DTEXTUREFILTERTYPE_TO_STR
5207 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
5208 return "unrecognized";
5212 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
5216 #define D3DSTATE_TO_STR(u) case u: return #u
5217 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
5218 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
5219 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
5220 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
5221 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
5222 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
5223 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
5224 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
5225 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
5226 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
5227 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
5228 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
5229 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
5230 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
5231 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
5232 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
5233 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
5234 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
5235 #undef D3DSTATE_TO_STR
5237 FIXME("Unrecognized %u texture state!\n", state
);
5238 return "unrecognized";
5242 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
5246 #define D3DTOP_TO_STR(u) case u: return #u
5247 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
5248 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
5249 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
5250 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
5251 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
5252 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
5253 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
5254 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
5255 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
5256 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
5257 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
5258 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
5259 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
5260 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
5261 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
5262 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
5263 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
5264 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
5265 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
5266 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
5267 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
5268 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
5269 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
5270 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
5271 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
5272 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
5273 #undef D3DTOP_TO_STR
5275 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
5276 return "unrecognized";
5280 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
5284 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
5285 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
5286 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
5287 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
5288 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
5289 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
5290 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
5291 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
5292 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
5293 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
5294 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
5295 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
5296 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
5297 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
5298 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
5299 #undef TSTYPE_TO_STR
5301 if (tstype
> 256 && tstype
< 512)
5303 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
5304 return ("WINED3D_TS_WORLD_MATRIX > 0");
5306 FIXME("Unrecognized transform state %#x.\n", tstype
);
5307 return "unrecognized";
5311 const char *debug_shader_type(enum wined3d_shader_type type
)
5315 #define WINED3D_TO_STR(type) case type: return #type
5316 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
5317 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
5318 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
5319 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
5320 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
5321 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
5322 #undef WINED3D_TO_STR
5324 FIXME("Unrecognized shader type %#x.\n", type
);
5325 return "unrecognized";
5329 const char *debug_d3dstate(uint32_t state
)
5331 if (STATE_IS_RENDER(state
))
5332 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
5333 if (STATE_IS_TEXTURESTAGE(state
))
5335 unsigned int texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
5336 uint32_t texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
5337 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
5338 texture_stage
, debug_d3dtexturestate(texture_state
));
5340 if (STATE_IS_COMPUTE_SHADER(state
))
5341 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5342 if (STATE_IS_GRAPHICS_SHADER(state
))
5343 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
5344 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
5345 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5346 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
5347 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
5348 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
5349 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
5350 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
5351 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
5352 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
5353 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
5354 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
5355 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
5356 if (STATE_IS_TRANSFORM(state
))
5357 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
5358 if (STATE_IS_STREAMSRC(state
))
5359 return "STATE_STREAMSRC";
5360 if (STATE_IS_INDEXBUFFER(state
))
5361 return "STATE_INDEXBUFFER";
5362 if (STATE_IS_VDECL(state
))
5363 return "STATE_VDECL";
5364 if (STATE_IS_VIEWPORT(state
))
5365 return "STATE_VIEWPORT";
5366 if (STATE_IS_LIGHT_TYPE(state
))
5367 return "STATE_LIGHT_TYPE";
5368 if (STATE_IS_ACTIVELIGHT(state
))
5369 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
5370 if (STATE_IS_SCISSORRECT(state
))
5371 return "STATE_SCISSORRECT";
5372 if (STATE_IS_CLIPPLANE(state
))
5373 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
5374 if (STATE_IS_MATERIAL(state
))
5375 return "STATE_MATERIAL";
5376 if (STATE_IS_RASTERIZER(state
))
5377 return "STATE_RASTERIZER";
5378 if (STATE_IS_DEPTH_BOUNDS(state
))
5379 return "STATE_DEPTH_BOUNDS";
5380 if (STATE_IS_BASEVERTEXINDEX(state
))
5381 return "STATE_BASEVERTEXINDEX";
5382 if (STATE_IS_FRAMEBUFFER(state
))
5383 return "STATE_FRAMEBUFFER";
5384 if (STATE_IS_POINT_ENABLE(state
))
5385 return "STATE_POINT_ENABLE";
5386 if (STATE_IS_COLOR_KEY(state
))
5387 return "STATE_COLOR_KEY";
5388 if (STATE_IS_STREAM_OUTPUT(state
))
5389 return "STATE_STREAM_OUTPUT";
5390 if (STATE_IS_BLEND(state
))
5391 return "STATE_BLEND";
5392 if (STATE_IS_BLEND_FACTOR(state
))
5393 return "STATE_BLEND_FACTOR";
5394 if (STATE_IS_SAMPLE_MASK(state
))
5395 return "STATE_SAMPLE_MASK";
5396 if (STATE_IS_DEPTH_STENCIL(state
))
5397 return "STATE_DEPTH_STENCIL";
5398 if (STATE_IS_STENCIL_REF(state
))
5399 return "STATE_STENCIL_REF";
5401 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
5404 const char *debug_fboattachment(GLenum attachment
)
5408 #define WINED3D_TO_STR(x) case x: return #x
5409 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
5410 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
5411 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
5412 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
5413 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
5414 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
5415 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
5416 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
5417 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
5418 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
5419 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
5420 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
5421 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
5422 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
5423 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
5424 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
5425 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
5426 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
5427 #undef WINED3D_TO_STR
5429 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
5433 const char *debug_fbostatus(GLenum status
) {
5435 #define FBOSTATUS_TO_STR(u) case u: return #u
5436 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
5437 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
5438 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
5439 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
5440 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
5441 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
5442 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
5443 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
5444 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
5445 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
5446 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
5447 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
5448 #undef FBOSTATUS_TO_STR
5450 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
5451 return "unrecognized";
5455 const char *debug_glerror(GLenum error
) {
5457 #define GLERROR_TO_STR(u) case u: return #u
5458 GLERROR_TO_STR(GL_NO_ERROR
);
5459 GLERROR_TO_STR(GL_INVALID_ENUM
);
5460 GLERROR_TO_STR(GL_INVALID_VALUE
);
5461 GLERROR_TO_STR(GL_INVALID_OPERATION
);
5462 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
5463 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
5464 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
5465 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
5466 #undef GLERROR_TO_STR
5468 FIXME("Unrecognized GL error 0x%08x.\n", error
);
5469 return "unrecognized";
5473 const char *wined3d_debug_vkresult(VkResult vr
)
5477 #define WINED3D_TO_STR(x) case x: return #x
5478 WINED3D_TO_STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR
);
5479 WINED3D_TO_STR(VK_ERROR_NOT_PERMITTED_EXT
);
5480 WINED3D_TO_STR(VK_ERROR_FRAGMENTATION_EXT
);
5481 WINED3D_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5482 WINED3D_TO_STR(VK_ERROR_OUT_OF_POOL_MEMORY
);
5483 WINED3D_TO_STR(VK_ERROR_INVALID_SHADER_NV
);
5484 WINED3D_TO_STR(VK_ERROR_OUT_OF_DATE_KHR
);
5485 WINED3D_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
);
5486 WINED3D_TO_STR(VK_ERROR_SURFACE_LOST_KHR
);
5487 WINED3D_TO_STR(VK_ERROR_FRAGMENTED_POOL
);
5488 WINED3D_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED
);
5489 WINED3D_TO_STR(VK_ERROR_TOO_MANY_OBJECTS
);
5490 WINED3D_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER
);
5491 WINED3D_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT
);
5492 WINED3D_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT
);
5493 WINED3D_TO_STR(VK_ERROR_LAYER_NOT_PRESENT
);
5494 WINED3D_TO_STR(VK_ERROR_MEMORY_MAP_FAILED
);
5495 WINED3D_TO_STR(VK_ERROR_DEVICE_LOST
);
5496 WINED3D_TO_STR(VK_ERROR_INITIALIZATION_FAILED
);
5497 WINED3D_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5498 WINED3D_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY
);
5499 WINED3D_TO_STR(VK_SUCCESS
);
5500 WINED3D_TO_STR(VK_NOT_READY
);
5501 WINED3D_TO_STR(VK_TIMEOUT
);
5502 WINED3D_TO_STR(VK_EVENT_SET
);
5503 WINED3D_TO_STR(VK_EVENT_RESET
);
5504 WINED3D_TO_STR(VK_INCOMPLETE
);
5505 WINED3D_TO_STR(VK_SUBOPTIMAL_KHR
);
5506 #undef WINED3D_TO_STR
5508 return wine_dbg_sprintf("unrecognised(%d)", vr
);
5512 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
5516 #define WINED3D_TO_STR(x) case x: return #x
5517 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
5518 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
5519 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
5520 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
5521 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
5522 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
5523 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
5524 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
5525 #undef WINED3D_TO_STR
5527 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
5528 return "unrecognized";
5532 static const char *debug_complex_fixup(enum complex_fixup fixup
)
5536 #define WINED3D_TO_STR(x) case x: return #x
5537 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
5538 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
5539 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
5540 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
5541 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
5542 WINED3D_TO_STR(COMPLEX_FIXUP_YUV
);
5543 #undef WINED3D_TO_STR
5545 FIXME("Unrecognized complex fixup %#x\n", fixup
);
5546 return "unrecognized";
5550 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
5552 if (is_complex_fixup(fixup
))
5554 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
5558 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
5559 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
5560 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
5561 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
5564 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
5565 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
5567 if (op
== WINED3D_TOP_DISABLE
)
5569 if (wined3d_state_get_ffp_texture(state
, stage
))
5572 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5573 && op
!= WINED3D_TOP_SELECT_ARG2
)
5575 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5576 && op
!= WINED3D_TOP_SELECT_ARG1
)
5578 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5579 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
5585 void get_identity_matrix(struct wined3d_matrix
*mat
)
5587 static const struct wined3d_matrix identity
=
5589 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5590 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5591 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5592 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5598 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5599 unsigned int index
, struct wined3d_matrix
*mat
)
5601 if (context
->stream_info
.position_transformed
)
5602 get_identity_matrix(mat
);
5604 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
5607 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5608 struct wined3d_matrix
*mat
)
5610 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5611 BOOL clip_control
, flip
;
5612 float center_offset
;
5614 /* There are a couple of additional things we have to take into account
5615 * here besides the projection transformation itself:
5616 * - We need to flip along the y-axis in case of offscreen rendering.
5617 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
5618 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
5619 * refer to pixel corners. D3D10 fixed this particular oddity.
5620 * - D3D has a top-left filling convention while GL does not specify
5621 * a particular behavior, other than that that the GL implementation
5622 * needs to be consistent.
5624 * In order to handle the pixel center, we translate by 0.5 / VPw and
5625 * 0.5 / VPh. We test the filling convention during adapter init and
5626 * add a small offset to correct it if necessary. See
5627 * wined3d_caps_gl_ctx_test_filling_convention() for more details on how
5628 * we test GL and considerations regarding the added offset value.
5630 * If we have GL_ARB_clip_control we take care of all this through
5631 * viewport properties and don't have to translate geometry. */
5633 /* Projection matrices are <= d3d9, which all have integer pixel centers. */
5634 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
))
5635 ERR("Did not expect to enter this codepath without WINED3D_PIXEL_CENTER_INTEGER.\n");
5637 clip_control
= d3d_info
->clip_control
;
5638 flip
= !clip_control
;
5640 center_offset
= 1.0f
+ d3d_info
->filling_convention_offset
;
5642 center_offset
= 0.0f
;
5644 if (context
->stream_info
.position_transformed
)
5646 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
5647 float x
= state
->viewports
[0].x
;
5648 float y
= state
->viewports
[0].y
;
5649 float w
= state
->viewports
[0].width
;
5650 float h
= state
->viewports
[0].height
;
5651 float x_scale
= 2.0f
/ w
;
5652 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
5653 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
5654 float y_offset
= flip
5655 ? (center_offset
- (2.0f
* y
) - h
) / h
5656 : (center_offset
- (2.0f
* y
) - h
) / -h
;
5657 bool zenable
= state
->fb
.depth_stencil
?
5658 (state
->depth_stencil_state
? state
->depth_stencil_state
->desc
.depth
: true) : false;
5659 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
5660 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
5661 const struct wined3d_matrix projection
=
5663 x_scale
, 0.0f
, 0.0f
, 0.0f
,
5664 0.0f
, y_scale
, 0.0f
, 0.0f
,
5665 0.0f
, 0.0f
, z_scale
, 0.0f
,
5666 x_offset
, y_offset
, z_offset
, 1.0f
,
5673 float y_scale
= flip
? -1.0f
: 1.0f
;
5674 float x_offset
= center_offset
/ state
->viewports
[0].width
;
5675 float y_offset
= flip
5676 ? center_offset
/ state
->viewports
[0].height
5677 : -center_offset
/ state
->viewports
[0].height
;
5678 float z_scale
= clip_control
? 1.0f
: 2.0f
;
5679 float z_offset
= clip_control
? 0.0f
: -1.0f
;
5680 const struct wined3d_matrix projection
=
5682 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5683 0.0f
, y_scale
, 0.0f
, 0.0f
,
5684 0.0f
, 0.0f
, z_scale
, 0.0f
,
5685 x_offset
, y_offset
, z_offset
, 1.0f
,
5688 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
5692 /* Setup this textures matrix according to the texture flags. */
5693 static void compute_texture_matrix(const struct wined3d_matrix
*matrix
, uint32_t flags
, BOOL calculated_coords
,
5694 BOOL transformed
, enum wined3d_format_id format_id
, struct wined3d_matrix
*out_matrix
)
5696 struct wined3d_matrix mat
;
5698 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
5700 get_identity_matrix(out_matrix
);
5704 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
5706 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
5712 /* Under Direct3D the R/Z coord can be used for translation, under
5713 * OpenGL we use the Q coord instead. */
5714 if (!(flags
& WINED3D_TTFF_PROJECTED
) && !calculated_coords
)
5718 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5719 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5720 * store the value of mat._41 in mat._21 because the input
5721 * value to the transformation will be 0, so the matrix value
5723 case WINED3DFMT_R32_FLOAT
:
5729 /* See above, just 3rd and 4th coord. */
5730 case WINED3DFMT_R32G32_FLOAT
:
5736 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
5737 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
5739 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5740 * into a bad place. The division elimination below will apply to make sure the
5741 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5743 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
5746 FIXME("Unexpected fixed function texture coord input\n");
5753 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5754 const unsigned int tex
, struct wined3d_matrix
*mat
)
5756 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
5757 != WINED3DTSS_TCI_PASSTHRU
;
5758 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0x0000ffff,
5759 WINED3D_MAX_FFP_TEXTURES
- 1);
5761 compute_texture_matrix(&state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
5762 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
5763 generated
, context
->stream_info
.position_transformed
,
5764 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
5765 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
5766 : WINED3DFMT_UNKNOWN
, mat
);
5769 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5770 float *out_min
, float *out_max
)
5778 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
5779 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
5788 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5789 float *out_pointsize
, float *out_att
)
5791 /* POINTSCALEENABLE controls how point size value is treated. If set to
5792 * true, the point size is scaled with respect to height of viewport.
5793 * When set to false point size is in pixels. */
5798 } pointsize
, a
, b
, c
;
5804 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
5805 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
5806 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
5807 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
5809 /* Always use first viewport, this path does not apply to d3d10/11 multiple viewports case. */
5810 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
5812 float scale_factor
= state
->viewports
[0].height
* state
->viewports
[0].height
;
5814 out_att
[0] = a
.f
/ scale_factor
;
5815 out_att
[1] = b
.f
/ scale_factor
;
5816 out_att
[2] = c
.f
/ scale_factor
;
5818 *out_pointsize
= pointsize
.f
;
5821 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5822 float *start
, float *end
)
5830 switch (context
->fog_source
)
5837 case FOGSOURCE_COORD
:
5843 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
5844 *start
= tmpvalue
.f
;
5845 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
5847 /* Special handling for fog_start == fog_end. In d3d with vertex
5848 * fog, everything is fogged. With table fog, everything with
5849 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5850 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5851 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
5859 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5860 ERR("Unexpected fog coordinate source.\n");
5866 static BOOL
wined3d_get_primary_display(WCHAR
*display
)
5868 DISPLAY_DEVICEW display_device
;
5869 DWORD device_idx
= 0;
5871 display_device
.cb
= sizeof(display_device
);
5872 while (EnumDisplayDevicesW(NULL
, device_idx
++, &display_device
, 0))
5874 if (display_device
.StateFlags
& DISPLAY_DEVICE_PRIMARY_DEVICE
)
5876 lstrcpyW(display
, display_device
.DeviceName
);
5884 BOOL
wined3d_get_primary_adapter_luid(LUID
*luid
)
5886 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param
;
5887 D3DKMT_CLOSEADAPTER close_adapter_param
;
5889 if (!wined3d_get_primary_display(open_adapter_param
.DeviceName
))
5892 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param
))
5895 *luid
= open_adapter_param
.AdapterLuid
;
5896 close_adapter_param
.hAdapter
= open_adapter_param
.hAdapter
;
5897 D3DKMTCloseAdapter(&close_adapter_param
);
5901 uint32_t wined3d_format_pack(const struct wined3d_format
*format
, const struct wined3d_uvec4
*value
)
5905 p
|= (value
->x
& wined3d_mask_from_size(format
->red_size
)) << format
->red_offset
;
5906 p
|= (value
->y
& wined3d_mask_from_size(format
->green_size
)) << format
->green_offset
;
5907 p
|= (value
->z
& wined3d_mask_from_size(format
->blue_size
)) << format
->blue_offset
;
5908 p
|= (value
->w
& wined3d_mask_from_size(format
->alpha_size
)) << format
->alpha_offset
;
5913 void wined3d_format_colour_to_vk(const struct wined3d_format
*format
, const struct wined3d_color
*c
,
5914 VkClearColorValue
*retval
)
5916 if (format
->attrs
& WINED3D_FORMAT_ATTR_INTEGER
)
5918 retval
->int32
[0] = c
->r
;
5919 retval
->int32
[1] = c
->g
;
5920 retval
->int32
[2] = c
->b
;
5921 retval
->int32
[3] = c
->a
;
5925 retval
->float32
[0] = c
->r
;
5926 retval
->float32
[1] = c
->g
;
5927 retval
->float32
[2] = c
->b
;
5928 retval
->float32
[3] = c
->a
;
5932 /* Note: It's the caller's responsibility to ensure values can be expressed
5933 * in the requested format. UNORM formats for example can only express values
5934 * in the range 0.0f -> 1.0f.
5936 * The code below assumes that no component crosses the 32 bit boundary (like
5937 * e.g. a hypothetical, and totally braindead, B30G30R4 format would).
5938 * This function writes at least sizeof(uint32_t) bytes, or format->byte_count,
5939 * whichever is larger. */
5940 void wined3d_format_convert_from_float(const struct wined3d_format
*format
,
5941 const struct wined3d_color
*color
, void *ret
)
5945 enum wined3d_format_id format_id
;
5946 struct wined3d_vec4 mul
;
5947 struct wined3d_uvec4 shift
;
5951 {WINED3DFMT_P8_UINT
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
5952 {WINED3DFMT_S1_UINT_D15_UNORM
, { 32767.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5953 {WINED3DFMT_D16_UNORM
, { 65535.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5957 enum wined3d_format_id format_id
;
5958 struct wined3d_dvec4 mul
;
5959 struct wined3d_uvec4 shift
;
5963 {WINED3DFMT_D24_UNORM_S8_UINT
, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
5964 {WINED3DFMT_X8D24_UNORM
, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5965 {WINED3DFMT_D32_UNORM
, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5967 enum wined3d_format_id format_id
= format
->id
;
5968 struct wined3d_color colour_srgb
;
5969 struct wined3d_uvec4 idx
, shift
;
5972 TRACE("Converting colour %s to format %s.\n", debug_color(color
), debug_d3dformat(format_id
));
5973 memset(ret
, 0, max(sizeof(uint32_t), format
->byte_count
));
5975 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
5977 if (format_id
!= format_srgb_info
[i
].srgb_format_id
)
5980 wined3d_colour_srgb_from_linear(&colour_srgb
, color
);
5981 format_id
= format_srgb_info
[i
].base_format_id
;
5982 color
= &colour_srgb
;
5986 for (i
= 0; i
< ARRAY_SIZE(float_conv
); ++i
)
5988 uint32_t *ret_i
= ret
;
5990 if (format_id
!= float_conv
[i
].format_id
)
5993 idx
.x
= float_conv
[i
].shift
.x
/ 32;
5994 idx
.y
= float_conv
[i
].shift
.y
/ 32;
5995 idx
.z
= float_conv
[i
].shift
.z
/ 32;
5996 idx
.w
= float_conv
[i
].shift
.w
/ 32;
5997 shift
.x
= float_conv
[i
].shift
.x
% 32;
5998 shift
.y
= float_conv
[i
].shift
.y
% 32;
5999 shift
.z
= float_conv
[i
].shift
.z
% 32;
6000 shift
.w
= float_conv
[i
].shift
.w
% 32;
6002 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* float_conv
[i
].mul
.x
) + 0.5f
)) << shift
.x
;
6003 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* float_conv
[i
].mul
.y
) + 0.5f
)) << shift
.y
;
6004 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* float_conv
[i
].mul
.z
) + 0.5f
)) << shift
.z
;
6005 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* float_conv
[i
].mul
.w
) + 0.5f
)) << shift
.w
;
6010 for (i
= 0; i
< ARRAY_SIZE(double_conv
); ++i
)
6014 if (format_id
!= double_conv
[i
].format_id
)
6017 idx
.x
= double_conv
[i
].shift
.x
/ 32;
6018 idx
.y
= double_conv
[i
].shift
.y
/ 32;
6019 idx
.z
= double_conv
[i
].shift
.z
/ 32;
6020 idx
.w
= double_conv
[i
].shift
.w
/ 32;
6021 shift
.x
= double_conv
[i
].shift
.x
% 32;
6022 shift
.y
= double_conv
[i
].shift
.y
% 32;
6023 shift
.z
= double_conv
[i
].shift
.z
% 32;
6024 shift
.w
= double_conv
[i
].shift
.w
% 32;
6027 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* double_conv
[i
].mul
.x
) + 0.5)) << shift
.x
;
6028 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* double_conv
[i
].mul
.y
) + 0.5)) << shift
.y
;
6029 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* double_conv
[i
].mul
.z
) + 0.5)) << shift
.z
;
6030 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* double_conv
[i
].mul
.w
) + 0.5)) << shift
.w
;
6035 if (format
->attrs
& WINED3D_FORMAT_ATTR_NORMALISED
)
6037 uint32_t *ret_i
= ret
;
6039 idx
.x
= format
->red_offset
/ 32;
6040 idx
.y
= format
->green_offset
/ 32;
6041 idx
.z
= format
->blue_offset
/ 32;
6042 idx
.w
= format
->alpha_offset
/ 32;
6043 shift
.x
= format
->red_offset
% 32;
6044 shift
.y
= format
->green_offset
% 32;
6045 shift
.z
= format
->blue_offset
% 32;
6046 shift
.w
= format
->alpha_offset
% 32;
6048 ret_i
[idx
.x
] = ((uint32_t)((color
->r
* wined3d_mask_from_size(format
->red_size
)) + 0.5f
)) << shift
.x
;
6049 ret_i
[idx
.y
] |= ((uint32_t)((color
->g
* wined3d_mask_from_size(format
->green_size
)) + 0.5f
)) << shift
.y
;
6050 ret_i
[idx
.z
] |= ((uint32_t)((color
->b
* wined3d_mask_from_size(format
->blue_size
)) + 0.5f
)) << shift
.z
;
6051 ret_i
[idx
.w
] |= ((uint32_t)((color
->a
* wined3d_mask_from_size(format
->alpha_size
)) + 0.5f
)) << shift
.w
;
6056 /* 32 bit float formats. We don't handle D32_FLOAT_S8X24_UINT for now. */
6057 if ((format
->attrs
& WINED3D_FORMAT_ATTR_FLOAT
)
6058 && (format
->red_size
== 32 || format
->depth_size
== 32)
6059 && !format
->stencil_size
)
6063 switch (format
->byte_count
)
6065 case 16: ret_f
[3] = color
->a
;
6066 case 12: ret_f
[2] = color
->b
;
6067 case 8: ret_f
[1] = color
->g
;
6068 case 4: ret_f
[0] = color
->r
;
6072 ERR("Unexpected byte count %u, format %s.\n", format
->byte_count
, debug_d3dformat(format_id
));
6079 if ((format
->attrs
& WINED3D_FORMAT_ATTR_FLOAT
) && format
->red_size
== 16)
6081 uint16_t *ret_s
= ret
;
6083 switch (format
->byte_count
)
6086 ret_s
[3] = float_32_to_16(&color
->a
);
6087 ret_s
[2] = float_32_to_16(&color
->b
);
6090 ret_s
[1] = float_32_to_16(&color
->g
);
6093 ret_s
[0] = float_32_to_16(&color
->r
);
6097 ERR("Unexpected byte count %u, format %s.\n", format
->byte_count
, debug_d3dformat(format_id
));
6104 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id
));
6107 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
6109 uint32_t mask
= wined3d_mask_from_size(size
);
6117 return (float)color
/ (float)mask
;
6120 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
6121 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
6123 struct wined3d_color slop
;
6127 case WINED3DFMT_B8G8R8_UNORM
:
6128 case WINED3DFMT_B8G8R8A8_UNORM
:
6129 case WINED3DFMT_B8G8R8X8_UNORM
:
6130 case WINED3DFMT_B5G6R5_UNORM
:
6131 case WINED3DFMT_B5G5R5X1_UNORM
:
6132 case WINED3DFMT_B5G5R5A1_UNORM
:
6133 case WINED3DFMT_B4G4R4A4_UNORM
:
6134 case WINED3DFMT_B2G3R3_UNORM
:
6135 case WINED3DFMT_R8_UNORM
:
6136 case WINED3DFMT_A8_UNORM
:
6137 case WINED3DFMT_B2G3R3A8_UNORM
:
6138 case WINED3DFMT_B4G4R4X4_UNORM
:
6139 case WINED3DFMT_R10G10B10A2_UNORM
:
6140 case WINED3DFMT_R10G10B10A2_SNORM
:
6141 case WINED3DFMT_R8G8B8A8_UNORM
:
6142 case WINED3DFMT_R8G8B8X8_UNORM
:
6143 case WINED3DFMT_R16G16_UNORM
:
6144 case WINED3DFMT_B10G10R10A2_UNORM
:
6145 slop
.r
= 0.5f
/ wined3d_mask_from_size(format
->red_size
);
6146 slop
.g
= 0.5f
/ wined3d_mask_from_size(format
->green_size
);
6147 slop
.b
= 0.5f
/ wined3d_mask_from_size(format
->blue_size
);
6148 slop
.a
= 0.5f
/ wined3d_mask_from_size(format
->alpha_size
);
6150 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
6152 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
6154 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
6156 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
6159 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
6161 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
6163 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
6165 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
6169 case WINED3DFMT_P8_UINT
:
6170 float_colors
[0].r
= 0.0f
;
6171 float_colors
[0].g
= 0.0f
;
6172 float_colors
[0].b
= 0.0f
;
6173 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
6175 float_colors
[1].r
= 0.0f
;
6176 float_colors
[1].g
= 0.0f
;
6177 float_colors
[1].b
= 0.0f
;
6178 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
6182 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
6186 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
6190 case 8: return WINED3DFMT_P8_UINT
;
6191 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
6192 case 16: return WINED3DFMT_B5G6R5_UNORM
;
6193 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
6194 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
6195 default: return WINED3DFMT_UNKNOWN
;
6199 void wined3d_format_copy_data(const struct wined3d_format
*format
, const uint8_t *src
,
6200 unsigned int src_row_pitch
, unsigned int src_slice_pitch
, uint8_t *dst
, unsigned int dst_row_pitch
,
6201 unsigned int dst_slice_pitch
, unsigned int w
, unsigned int h
, unsigned int d
)
6203 unsigned int row_block_count
, row_count
, row_size
, slice
, row
;
6204 unsigned int slice_count
= d
, slice_size
;
6205 const uint8_t *src_row
;
6208 row_block_count
= (w
+ format
->block_width
- 1) / format
->block_width
;
6209 row_count
= (h
+ format
->block_height
- 1) / format
->block_height
;
6210 row_size
= row_block_count
* format
->block_byte_count
;
6211 slice_size
= row_size
* row_count
;
6213 if (src_row_pitch
== row_size
&& dst_row_pitch
== row_size
6214 && ((src_slice_pitch
== slice_size
&& dst_slice_pitch
== slice_size
) || slice_count
== 1))
6216 memcpy(dst
, src
, slice_count
* slice_size
);
6220 for (slice
= 0; slice
< slice_count
; ++slice
)
6222 for (row
= 0; row
< row_count
; ++row
)
6224 src_row
= &src
[slice
* src_slice_pitch
+ row
* src_row_pitch
];
6225 dst_row
= &dst
[slice
* dst_slice_pitch
+ row
* dst_row_pitch
];
6226 memcpy(dst_row
, src_row
, row_size
);
6231 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
6233 struct wined3d_matrix tmp
;
6235 /* Now do the multiplication 'by hand'.
6236 I know that all this could be optimised, but this will be done later :-) */
6237 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
6238 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
6239 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
6240 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
6242 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
6243 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
6244 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
6245 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
6247 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
6248 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
6249 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
6250 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
6252 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
6253 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
6254 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
6255 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
6260 void wined3d_ffp_get_fs_settings(const struct wined3d_context
*context
,
6261 const struct wined3d_state
*state
, struct ffp_frag_settings
*settings
)
6266 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
6269 /* D3DTOP_DISABLE */ 0,
6270 /* D3DTOP_SELECTARG1 */ ARG1
,
6271 /* D3DTOP_SELECTARG2 */ ARG2
,
6272 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
6273 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
6274 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
6275 /* D3DTOP_ADD */ ARG1
| ARG2
,
6276 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
6277 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
6278 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
6279 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
6280 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
6281 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
6282 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
6283 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
6284 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
6285 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
6286 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
6287 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
6288 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
6289 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
6290 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
6291 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
6292 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
6293 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
6294 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
6298 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
6299 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6300 struct wined3d_texture
*texture
;
6302 settings
->padding
= 0;
6304 for (i
= 0; i
< d3d_info
->ffp_fragment_caps
.max_blend_stages
; ++i
)
6306 settings
->op
[i
].padding
= 0;
6307 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
6309 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
6310 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
6311 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
6312 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
6313 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6314 settings
->op
[i
].tmp_dst
= 0;
6315 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6316 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6321 if ((texture
= wined3d_state_get_ffp_texture(state
, i
)))
6323 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
6324 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6326 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
6327 settings
->op
[i
].tex_type
= texture
->resource
.gl_type
;
6329 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6330 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6333 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
6334 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
6336 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
6337 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
6338 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
6340 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
6344 carg1
= WINED3DTA_CURRENT
;
6345 cop
= WINED3D_TOP_SELECT_ARG1
;
6348 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
6350 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
6351 * the color result to the alpha component of the destination
6360 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
6361 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
6362 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
6365 if (!i
&& state
->render_states
[WINED3D_RS_COLORKEYENABLE
]
6366 && texture
&& !(texture
->resource
.usage
& WINED3DUSAGE_LEGACY_CUBEMAP
)
6367 && (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
) && !texture
->resource
.format
->alpha_size
)
6369 if (aop
== WINED3D_TOP_DISABLE
)
6371 aarg1
= WINED3DTA_TEXTURE
;
6372 aop
= WINED3D_TOP_SELECT_ARG1
;
6374 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
6376 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6378 aarg2
= WINED3DTA_TEXTURE
;
6379 aop
= WINED3D_TOP_MODULATE
;
6383 aarg1
= WINED3DTA_TEXTURE
;
6386 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
6388 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6390 aarg1
= WINED3DTA_TEXTURE
;
6391 aop
= WINED3D_TOP_MODULATE
;
6395 aarg2
= WINED3DTA_TEXTURE
;
6400 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
6404 aarg1
= WINED3DTA_CURRENT
;
6405 aop
= WINED3D_TOP_SELECT_ARG1
;
6408 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
6409 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
6411 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
6412 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
6413 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT3
;
6414 else if (ttff
& WINED3D_TTFF_PROJECTED
)
6415 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT4
;
6417 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6421 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6424 settings
->op
[i
].cop
= cop
;
6425 settings
->op
[i
].aop
= aop
;
6426 settings
->op
[i
].carg0
= carg0
;
6427 settings
->op
[i
].carg1
= carg1
;
6428 settings
->op
[i
].carg2
= carg2
;
6429 settings
->op
[i
].aarg0
= aarg0
;
6430 settings
->op
[i
].aarg1
= aarg1
;
6431 settings
->op
[i
].aarg2
= aarg2
;
6432 settings
->op
[i
].tmp_dst
= state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
;
6435 /* Clear unsupported stages */
6436 for (; i
< WINED3D_MAX_FFP_TEXTURES
; ++i
)
6437 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
6439 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6441 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
6443 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
6445 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
6447 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6451 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
6453 case WINED3D_FOG_NONE
:
6454 case WINED3D_FOG_LINEAR
:
6455 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6457 case WINED3D_FOG_EXP
:
6458 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6460 case WINED3D_FOG_EXP2
:
6461 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6468 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
6470 case WINED3D_FOG_LINEAR
:
6471 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6473 case WINED3D_FOG_EXP
:
6474 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6476 case WINED3D_FOG_EXP2
:
6477 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6481 settings
->sRGB_write
= !d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
);
6483 texture
= wined3d_state_get_ffp_texture(state
, 0);
6484 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
]
6485 && texture
&& (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
)
6486 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
6487 settings
->color_key_enabled
= 1;
6489 settings
->color_key_enabled
= 0;
6491 /* texcoords_initialized is set to meaningful values only when GL doesn't
6492 * support enough varyings to always pass around all the possible texture
6494 * This is used to avoid reading a varying not written by the vertex shader.
6495 * Reading uninitialized varyings on core profile contexts results in an
6496 * error while with builtin varyings on legacy contexts you get undefined
6498 if (d3d_info
->limits
.varying_count
&& !d3d_info
->full_ffp_varyings
)
6500 settings
->texcoords_initialized
= 0;
6501 for (i
= 0; i
< WINED3D_MAX_FFP_TEXTURES
; ++i
)
6505 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
6506 settings
->texcoords_initialized
|= 1u << i
;
6510 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6511 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6512 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
6513 & WINED3D_FFP_TCI_MASK
6514 || (coord_idx
< WINED3D_MAX_FFP_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
6515 settings
->texcoords_initialized
|= 1u << i
;
6521 settings
->texcoords_initialized
= wined3d_mask_from_size(WINED3D_MAX_FFP_TEXTURES
);
6524 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
6525 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
6527 if (d3d_info
->ffp_alpha_test
)
6528 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
6530 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
6531 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
6532 : WINED3D_CMP_ALWAYS
) - 1;
6534 if (d3d_info
->emulated_flatshading
)
6535 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6537 settings
->flatshading
= FALSE
;
6540 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
6541 const struct ffp_frag_settings
*settings
)
6543 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
6544 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
6547 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
6549 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
6550 * whereas desc points to an extended structure with implementation specific parts. */
6551 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
6553 ERR("Failed to insert ffp frag shader.\n");
6557 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6559 const struct ffp_frag_settings
*ka
= key
;
6560 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
6562 return memcmp(ka
, kb
, sizeof(*ka
));
6565 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
6566 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
6568 enum wined3d_material_color_source diffuse_source
, emissive_source
, ambient_source
, specular_source
;
6569 const struct wined3d_vertex_declaration
*vdecl
= state
->vertex_declaration
;
6570 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6571 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6572 unsigned int coord_idx
, i
;
6574 memset(settings
, 0, sizeof(*settings
));
6576 if (si
->position_transformed
)
6578 settings
->transformed
= 1;
6579 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6580 settings
->per_vertex_point_size
= vdecl
->point_size
;
6581 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6582 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6583 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6584 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6586 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6588 for (i
= 0; i
< WINED3D_MAX_FFP_TEXTURES
; ++i
)
6590 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6591 if (coord_idx
< WINED3D_MAX_FFP_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6592 settings
->texcoords
|= 1u << i
;
6593 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6595 if (d3d_info
->full_ffp_varyings
)
6596 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_FFP_TEXTURES
);
6598 if (d3d_info
->emulated_flatshading
)
6599 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6601 settings
->flatshading
= FALSE
;
6603 settings
->swizzle_map
= si
->swizzle_map
;
6608 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
6610 case WINED3D_VBF_DISABLE
:
6611 case WINED3D_VBF_1WEIGHTS
:
6612 case WINED3D_VBF_2WEIGHTS
:
6613 case WINED3D_VBF_3WEIGHTS
:
6614 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
6617 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
6621 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
6622 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
6623 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
6624 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
6625 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
6626 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
6627 settings
->specular_enable
= !!state
->render_states
[WINED3D_RS_SPECULARENABLE
];
6628 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6629 settings
->per_vertex_point_size
= vdecl
->point_size
;
6631 wined3d_get_material_colour_source(&diffuse_source
, &emissive_source
,
6632 &ambient_source
, &specular_source
, state
);
6633 settings
->diffuse_source
= diffuse_source
;
6634 settings
->emissive_source
= emissive_source
;
6635 settings
->ambient_source
= ambient_source
;
6636 settings
->specular_source
= specular_source
;
6638 for (i
= 0; i
< WINED3D_MAX_FFP_TEXTURES
; ++i
)
6640 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6641 if (coord_idx
< WINED3D_MAX_FFP_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6642 settings
->texcoords
|= 1u << i
;
6643 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6645 if (d3d_info
->full_ffp_varyings
)
6646 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_FFP_TEXTURES
);
6648 for (i
= 0; i
< WINED3D_MAX_ACTIVE_LIGHTS
; ++i
)
6650 if (!state
->light_state
.lights
[i
])
6653 switch (state
->light_state
.lights
[i
]->OriginalParms
.type
)
6655 case WINED3D_LIGHT_POINT
:
6656 ++settings
->point_light_count
;
6658 case WINED3D_LIGHT_SPOT
:
6659 ++settings
->spot_light_count
;
6661 case WINED3D_LIGHT_DIRECTIONAL
:
6662 ++settings
->directional_light_count
;
6664 case WINED3D_LIGHT_PARALLELPOINT
:
6665 ++settings
->parallel_point_light_count
;
6668 FIXME("Unhandled light type %#x.\n", state
->light_state
.lights
[i
]->OriginalParms
.type
);
6673 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6674 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6675 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6677 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6679 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
6680 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
6681 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
6682 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
6683 settings
->ortho_fog
= 1;
6685 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
6686 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6687 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
6688 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
6690 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6692 if (d3d_info
->emulated_flatshading
)
6693 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6695 settings
->flatshading
= FALSE
;
6697 settings
->swizzle_map
= si
->swizzle_map
;
6700 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6702 const struct wined3d_ffp_vs_settings
*ka
= key
;
6703 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
6704 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
6706 return memcmp(ka
, kb
, sizeof(*ka
));
6709 const char *wined3d_debug_location(uint32_t location
)
6711 struct debug_buffer buffer
;
6712 const char *prefix
= "";
6713 const char *suffix
= "";
6715 if (wined3d_popcount(location
) > 16)
6718 location
= ~location
;
6722 init_debug_buffer(&buffer
, "0");
6723 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6724 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
6725 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
6726 LOCATION_TO_STR(WINED3D_LOCATION_CLEARED
);
6727 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
6728 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
6729 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
6730 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
6731 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
6732 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
6733 #undef LOCATION_TO_STR
6735 FIXME("Unrecognized location flag(s) %#x.\n", location
);
6737 return wine_dbg_sprintf("%s%s%s", prefix
, buffer
.str
, suffix
);
6740 const char *wined3d_debug_feature_level(enum wined3d_feature_level level
)
6744 #define LEVEL_TO_STR(level) case level: return #level
6745 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_5
);
6746 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_6
);
6747 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_7
);
6748 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_8
);
6749 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_1
);
6750 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_2
);
6751 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_3
);
6752 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10
);
6753 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10_1
);
6754 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11
);
6755 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11_1
);
6758 return wine_dbg_sprintf("%#x", level
);
6762 /* Print a floating point value with the %.8e format specifier, always using
6763 * '.' as decimal separator. */
6764 void wined3d_ftoa(float value
, char *s
)
6768 if (copysignf(1.0f
, value
) < 0.0f
)
6771 /* Be sure to allocate a buffer of at least 17 characters for the result
6772 as sprintf may return a 3 digit exponent when using the MSVC runtime
6773 instead of a 2 digit exponent. */
6774 sprintf(s
, "%.8e", value
);
6775 if (isfinite(value
))
6779 void wined3d_release_dc(HWND window
, HDC dc
)
6781 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
6782 * However, that's not what actually happens, and there are user32 tests
6783 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
6784 * So explicitly check that the DC belongs to the window, since we want to
6785 * avoid releasing a DC that belongs to some other window if the original
6786 * window was already destroyed. */
6787 if (WindowFromDC(dc
) != window
)
6788 WARN("DC %p does not belong to window %p.\n", dc
, window
);
6789 else if (!ReleaseDC(window
, dc
))
6790 ERR("Failed to release device context %p, last error %#lx.\n", dc
, GetLastError());
6793 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
6795 RECT orig
= *clipped
;
6796 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
6797 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
6799 IntersectRect(clipped
, clipped
, clip_rect
);
6801 if (IsRectEmpty(clipped
))
6803 SetRectEmpty(other
);
6807 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
6808 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
6809 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
6810 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
6815 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
6816 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6821 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
6823 *count
= gl_limits
->uniform_blocks
[i
];
6824 if (i
== shader_type
)
6829 ERR("Unrecognized shader type %#x.\n", shader_type
);
6833 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
6834 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6838 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
6840 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
6843 *base
= gl_limits
->graphics_samplers
;
6844 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
6849 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
6851 *count
= gl_limits
->samplers
[i
];
6852 if (i
== shader_type
)
6857 ERR("Unrecognized shader type %#x.\n", shader_type
);
6861 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
6863 SIZE_T max_capacity
, new_capacity
;
6866 if (count
<= *capacity
)
6869 max_capacity
= ~(SIZE_T
)0 / size
;
6870 if (count
> max_capacity
)
6873 new_capacity
= max(1, *capacity
);
6874 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
6876 if (new_capacity
< count
)
6877 new_capacity
= count
;
6879 new_elements
= _recalloc(*elements
, new_capacity
, size
);
6883 *elements
= new_elements
;
6884 *capacity
= new_capacity
;
6888 static void swap_rows(float **a
, float **b
)
6896 BOOL
invert_matrix(struct wined3d_matrix
*out
, const struct wined3d_matrix
*m
)
6899 float m0
, m1
, m2
, m3
, s
;
6900 float *r0
, *r1
, *r2
, *r3
;
6912 r0
[5] = r0
[6] = r0
[7] = 0.0f
;
6919 r1
[4] = r1
[6] = r1
[7] = 0.0f
;
6926 r2
[4] = r2
[5] = r2
[7] = 0.0f
;
6933 r3
[4] = r3
[5] = r3
[6] = 0.0f
;
6935 /* Choose pivot - or die. */
6936 if (fabsf(r3
[0]) > fabsf(r2
[0]))
6937 swap_rows(&r3
, &r2
);
6938 if (fabsf(r2
[0]) > fabsf(r1
[0]))
6939 swap_rows(&r2
, &r1
);
6940 if (fabsf(r1
[0]) > fabsf(r0
[0]))
6941 swap_rows(&r1
, &r0
);
6945 /* Eliminate first variable. */
6946 m1
= r1
[0] / r0
[0]; m2
= r2
[0] / r0
[0]; m3
= r3
[0] / r0
[0];
6947 s
= r0
[1]; r1
[1] -= m1
* s
; r2
[1] -= m2
* s
; r3
[1] -= m3
* s
;
6948 s
= r0
[2]; r1
[2] -= m1
* s
; r2
[2] -= m2
* s
; r3
[2] -= m3
* s
;
6949 s
= r0
[3]; r1
[3] -= m1
* s
; r2
[3] -= m2
* s
; r3
[3] -= m3
* s
;
6979 /* Choose pivot - or die. */
6980 if (fabsf(r3
[1]) > fabsf(r2
[1]))
6981 swap_rows(&r3
, &r2
);
6982 if (fabsf(r2
[1]) > fabsf(r1
[1]))
6983 swap_rows(&r2
, &r1
);
6987 /* Eliminate second variable. */
6988 m2
= r2
[1] / r1
[1]; m3
= r3
[1] / r1
[1];
6989 r2
[2] -= m2
* r1
[2]; r3
[2] -= m3
* r1
[2];
6990 r2
[3] -= m2
* r1
[3]; r3
[3] -= m3
* r1
[3];
7016 /* Choose pivot - or die. */
7017 if (fabsf(r3
[2]) > fabsf(r2
[2]))
7018 swap_rows(&r3
, &r2
);
7022 /* Eliminate third variable. */
7024 r3
[3] -= m3
* r2
[3];
7025 r3
[4] -= m3
* r2
[4];
7026 r3
[5] -= m3
* r2
[5];
7027 r3
[6] -= m3
* r2
[6];
7028 r3
[7] -= m3
* r2
[7];
7034 /* Back substitute row 3. */
7041 /* Back substitute row 2. */
7044 r2
[4] = s
* (r2
[4] - r3
[4] * m2
);
7045 r2
[5] = s
* (r2
[5] - r3
[5] * m2
);
7046 r2
[6] = s
* (r2
[6] - r3
[6] * m2
);
7047 r2
[7] = s
* (r2
[7] - r3
[7] * m2
);
7049 r1
[4] -= r3
[4] * m1
;
7050 r1
[5] -= r3
[5] * m1
;
7051 r1
[6] -= r3
[6] * m1
;
7052 r1
[7] -= r3
[7] * m1
;
7054 r0
[4] -= r3
[4] * m0
;
7055 r0
[5] -= r3
[5] * m0
;
7056 r0
[6] -= r3
[6] * m0
;
7057 r0
[7] -= r3
[7] * m0
;
7059 /* Back substitute row 1. */
7062 r1
[4] = s
* (r1
[4] - r2
[4] * m1
);
7063 r1
[5] = s
* (r1
[5] - r2
[5] * m1
);
7064 r1
[6] = s
* (r1
[6] - r2
[6] * m1
);
7065 r1
[7] = s
* (r1
[7] - r2
[7] * m1
);
7067 r0
[4] -= r2
[4] * m0
;
7068 r0
[5] -= r2
[5] * m0
;
7069 r0
[6] -= r2
[6] * m0
;
7070 r0
[7] -= r2
[7] * m0
;
7072 /* Back substitute row 0. */
7075 r0
[4] = s
* (r0
[4] - r1
[4] * m0
);
7076 r0
[5] = s
* (r0
[5] - r1
[5] * m0
);
7077 r0
[6] = s
* (r0
[6] - r1
[6] * m0
);
7078 r0
[7] = s
* (r0
[7] - r1
[7] * m0
);
7100 /* Taken and adapted from Mesa. */
7101 static BOOL
invert_matrix_3d(struct wined3d_matrix
*out
, const struct wined3d_matrix
*in
)
7103 float pos
, neg
, t
, det
;
7104 struct wined3d_matrix temp
;
7106 /* Calculate the determinant of upper left 3x3 submatrix and
7107 * determine if the matrix is singular. */
7109 t
= in
->_11
* in
->_22
* in
->_33
;
7115 t
= in
->_21
* in
->_32
* in
->_13
;
7120 t
= in
->_31
* in
->_12
* in
->_23
;
7126 t
= -in
->_31
* in
->_22
* in
->_13
;
7131 t
= -in
->_21
* in
->_12
* in
->_33
;
7137 t
= -in
->_11
* in
->_32
* in
->_23
;
7145 if (fabsf(det
) < 1e-25f
)
7149 temp
._11
= (in
->_22
* in
->_33
- in
->_32
* in
->_23
) * det
;
7150 temp
._12
= -(in
->_12
* in
->_33
- in
->_32
* in
->_13
) * det
;
7151 temp
._13
= (in
->_12
* in
->_23
- in
->_22
* in
->_13
) * det
;
7152 temp
._21
= -(in
->_21
* in
->_33
- in
->_31
* in
->_23
) * det
;
7153 temp
._22
= (in
->_11
* in
->_33
- in
->_31
* in
->_13
) * det
;
7154 temp
._23
= -(in
->_11
* in
->_23
- in
->_21
* in
->_13
) * det
;
7155 temp
._31
= (in
->_21
* in
->_32
- in
->_31
* in
->_22
) * det
;
7156 temp
._32
= -(in
->_11
* in
->_32
- in
->_31
* in
->_12
) * det
;
7157 temp
._33
= (in
->_11
* in
->_22
- in
->_21
* in
->_12
) * det
;
7163 void compute_normal_matrix(float *normal_matrix
, BOOL legacy_lighting
,
7164 const struct wined3d_matrix
*modelview
)
7166 struct wined3d_matrix mv
;
7170 if (legacy_lighting
)
7171 invert_matrix_3d(&mv
, &mv
);
7173 invert_matrix(&mv
, &mv
);
7174 /* Tests show that singular modelview matrices are used unchanged as normal
7175 * matrices on D3D3 and older. There seems to be no clearly consistent
7176 * behavior on newer D3D versions so always follow older ddraw behavior. */
7177 for (i
= 0; i
< 3; ++i
)
7178 for (j
= 0; j
< 3; ++j
)
7179 normal_matrix
[i
* 3 + j
] = (&mv
._11
)[j
* 4 + i
];
7182 static void wined3d_allocator_release_block(struct wined3d_allocator
*allocator
,
7183 struct wined3d_allocator_block
*block
)
7185 block
->parent
= allocator
->free
;
7186 allocator
->free
= block
;
7189 static struct wined3d_allocator_block
*wined3d_allocator_acquire_block(struct wined3d_allocator
*allocator
)
7191 struct wined3d_allocator_block
*block
;
7193 if (!allocator
->free
)
7194 return malloc(sizeof(*block
));
7196 block
= allocator
->free
;
7197 allocator
->free
= block
->parent
;
7202 void wined3d_allocator_block_free(struct wined3d_allocator_block
*block
)
7204 struct wined3d_allocator
*allocator
= block
->chunk
->allocator
;
7205 struct wined3d_allocator_block
*parent
;
7207 while ((parent
= block
->parent
) && block
->sibling
->free
)
7209 list_remove(&block
->sibling
->entry
);
7210 wined3d_allocator_release_block(allocator
, block
->sibling
);
7211 wined3d_allocator_release_block(allocator
, block
);
7216 list_add_head(&block
->chunk
->available
[block
->order
], &block
->entry
);
7219 static void wined3d_allocator_block_init(struct wined3d_allocator_block
*block
,
7220 struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator_block
*parent
,
7221 struct wined3d_allocator_block
*sibling
, unsigned int order
, size_t offset
, bool free
)
7223 list_init(&block
->entry
);
7224 block
->chunk
= chunk
;
7225 block
->parent
= parent
;
7226 block
->sibling
= sibling
;
7227 block
->order
= order
;
7228 block
->offset
= offset
;
7232 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk
*chunk
)
7234 struct wined3d_allocator_block
*block
;
7237 if (list_empty(&chunk
->available
[0]))
7239 ERR("Chunk %p is not empty.\n", chunk
);
7243 for (i
= 1; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7245 if (!list_empty(&chunk
->available
[i
]))
7247 ERR("Chunk %p is not empty.\n", chunk
);
7252 block
= LIST_ENTRY(list_head(&chunk
->available
[0]), struct wined3d_allocator_block
, entry
);
7253 wined3d_allocator_release_block(chunk
->allocator
, block
);
7256 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator
*allocator
)
7258 struct wined3d_allocator_block
*block
;
7261 if (!(block
= wined3d_allocator_acquire_block(allocator
)))
7263 wined3d_allocator_block_init(block
, chunk
, NULL
, NULL
, 0, 0, true);
7265 list_init(&chunk
->entry
);
7266 for (i
= 0; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7268 list_init(&chunk
->available
[i
]);
7270 list_add_head(&chunk
->available
[0], &block
->entry
);
7271 chunk
->allocator
= allocator
;
7272 chunk
->map_count
= 0;
7273 chunk
->map_ptr
= NULL
;
7278 void wined3d_allocator_cleanup(struct wined3d_allocator
*allocator
)
7280 struct wined3d_allocator_chunk
*chunk
, *chunk2
;
7281 struct wined3d_allocator_block
*block
, *next
;
7284 for (i
= 0; i
< allocator
->pool_count
; ++i
)
7286 LIST_FOR_EACH_ENTRY_SAFE(chunk
, chunk2
, &allocator
->pools
[i
].chunks
, struct wined3d_allocator_chunk
, entry
)
7288 list_remove(&chunk
->entry
);
7289 allocator
->ops
->allocator_destroy_chunk(chunk
);
7292 free(allocator
->pools
);
7294 next
= allocator
->free
;
7295 while ((block
= next
))
7297 next
= block
->parent
;
7302 static struct wined3d_allocator_block
*wined3d_allocator_chunk_allocate(struct wined3d_allocator_chunk
*chunk
,
7305 struct wined3d_allocator_block
*block
, *left
, *right
;
7306 unsigned int i
= order
;
7310 if (!list_empty(&chunk
->available
[i
]))
7315 if (list_empty(&chunk
->available
[i
]))
7318 block
= LIST_ENTRY(list_head(&chunk
->available
[i
]), struct wined3d_allocator_block
, entry
);
7319 list_remove(&block
->entry
);
7320 block
->free
= false;
7324 if (!(left
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7326 ERR("Failed to allocate left.\n");
7330 if (!(right
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7332 ERR("Failed to allocate right.\n");
7333 wined3d_allocator_release_block(chunk
->allocator
, left
);
7337 wined3d_allocator_block_init(left
, chunk
, block
, right
, block
->order
+ 1, block
->offset
, false);
7338 wined3d_allocator_block_init(right
, chunk
, block
, left
, block
->order
+ 1,
7339 block
->offset
+ (WINED3D_ALLOCATOR_CHUNK_SIZE
>> left
->order
), true);
7340 list_add_head(&chunk
->available
[right
->order
], &right
->entry
);
7349 struct wined3d_allocator_block
*wined3d_allocator_allocate(struct wined3d_allocator
*allocator
,
7350 struct wined3d_context
*context
, unsigned int memory_type
, size_t size
)
7352 struct wined3d_allocator_chunk
*chunk
;
7353 struct wined3d_allocator_block
*block
;
7356 if (size
> WINED3D_ALLOCATOR_CHUNK_SIZE
/ 2)
7359 if (size
< WINED3D_ALLOCATOR_MIN_BLOCK_SIZE
)
7360 order
= WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT
- 1;
7362 order
= wined3d_log2i(WINED3D_ALLOCATOR_CHUNK_SIZE
/ size
);
7364 LIST_FOR_EACH_ENTRY(chunk
, &allocator
->pools
[memory_type
].chunks
, struct wined3d_allocator_chunk
, entry
)
7366 if ((block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7370 if (!(chunk
= allocator
->ops
->allocator_create_chunk(allocator
,
7371 context
, memory_type
, WINED3D_ALLOCATOR_CHUNK_SIZE
)))
7374 if (!(block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7380 bool wined3d_allocator_init(struct wined3d_allocator
*allocator
,
7381 size_t pool_count
, const struct wined3d_allocator_ops
*allocator_ops
)
7385 allocator
->ops
= allocator_ops
;
7386 allocator
->pool_count
= pool_count
;
7387 if (!(allocator
->pools
= calloc(pool_count
, sizeof(*allocator
->pools
))))
7389 for (i
= 0; i
< pool_count
; ++i
)
7391 list_init(&allocator
->pools
[i
].chunks
);
7394 allocator
->free
= NULL
;