VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-info.cpp@ 97405

Last change on this file since 97405 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 87.9 KB
Line 
1/* $Id: DevVGA-SVGA3d-info.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * DevSVGA3d - VMWare SVGA device, 3D parts - Introspection and debugging.
4 */
5
6/*
7 * Copyright (C) 2013-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <stdio.h>
33#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
34#include <VBox/vmm/pdmdev.h>
35#include <VBox/err.h>
36#include <VBox/log.h>
37
38#include <iprt/assert.h>
39#include <iprt/mem.h>
40#include <iprt/path.h>
41
42#include <iprt/formats/bmp.h>
43
44#include <VBox/vmm/pgm.h> /* required by DevVGA.h */
45#include <VBoxVideo.h> /* required by DevVGA.h */
46
47/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
48#include "DevVGA.h"
49
50#include "DevVGA-SVGA.h"
51#include "DevVGA-SVGA3d.h"
52#define VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
53#include "DevVGA-SVGA3d-internal.h"
54
55
56/*********************************************************************************************************************************
57* Global Variables *
58*********************************************************************************************************************************/
59/** Enum value to string mappings for SVGA3dSurfaceFormat, prefix "SVGA3D_". */
60static const VMSVGAINFOENUM g_aSVGA3dSurfaceFormats[] =
61{
62 { SVGA3D_FORMAT_INVALID , "FORMAT_INVALID" },
63 { SVGA3D_X8R8G8B8 , "X8R8G8B8" },
64 { SVGA3D_A8R8G8B8 , "A8R8G8B8" },
65 { SVGA3D_R5G6B5 , "R5G6B5" },
66 { SVGA3D_X1R5G5B5 , "X1R5G5B5" },
67 { SVGA3D_A1R5G5B5 , "A1R5G5B5" },
68 { SVGA3D_A4R4G4B4 , "A4R4G4B4" },
69 { SVGA3D_Z_D32 , "Z_D32" },
70 { SVGA3D_Z_D16 , "Z_D16" },
71 { SVGA3D_Z_D24S8 , "Z_D24S8" },
72 { SVGA3D_Z_D15S1 , "Z_D15S1" },
73 { SVGA3D_LUMINANCE8 , "LUMINANCE8" },
74 { SVGA3D_LUMINANCE4_ALPHA4 , "LUMINANCE4_ALPHA4" },
75 { SVGA3D_LUMINANCE16 , "LUMINANCE16" },
76 { SVGA3D_LUMINANCE8_ALPHA8 , "LUMINANCE8_ALPHA8" },
77 { SVGA3D_DXT1 , "DXT1" },
78 { SVGA3D_DXT2 , "DXT2" },
79 { SVGA3D_DXT3 , "DXT3" },
80 { SVGA3D_DXT4 , "DXT4" },
81 { SVGA3D_DXT5 , "DXT5" },
82 { SVGA3D_BUMPU8V8 , "BUMPU8V8" },
83 { SVGA3D_BUMPL6V5U5 , "BUMPL6V5U5" },
84 { SVGA3D_BUMPX8L8V8U8 , "BUMPX8L8V8U8" },
85 { SVGA3D_FORMAT_DEAD1 , "FORMAT_DEAD1" },
86 { SVGA3D_ARGB_S10E5 , "ARGB_S10E5" },
87 { SVGA3D_ARGB_S23E8 , "ARGB_S23E8" },
88 { SVGA3D_A2R10G10B10 , "A2R10G10B10" },
89 { SVGA3D_V8U8 , "V8U8" },
90 { SVGA3D_Q8W8V8U8 , "Q8W8V8U8" },
91 { SVGA3D_CxV8U8 , "CxV8U8" },
92 { SVGA3D_X8L8V8U8 , "X8L8V8U8" },
93 { SVGA3D_A2W10V10U10 , "A2W10V10U10" },
94 { SVGA3D_ALPHA8 , "ALPHA8" },
95 { SVGA3D_R_S10E5 , "R_S10E5" },
96 { SVGA3D_R_S23E8 , "R_S23E8" },
97 { SVGA3D_RG_S10E5 , "RG_S10E5" },
98 { SVGA3D_RG_S23E8 , "RG_S23E8" },
99 { SVGA3D_BUFFER , "BUFFER" },
100 { SVGA3D_Z_D24X8 , "Z_D24X8" },
101 { SVGA3D_V16U16 , "V16U16" },
102 { SVGA3D_G16R16 , "G16R16" },
103 { SVGA3D_A16B16G16R16 , "A16B16G16R16" },
104 { SVGA3D_UYVY , "UYVY" },
105 { SVGA3D_YUY2 , "YUY2" },
106 { SVGA3D_NV12 , "NV12" },
107 { SVGA3D_FORMAT_DEAD2 , "FORMAT_DEAD2" },
108 { SVGA3D_R32G32B32A32_TYPELESS , "R32G32B32A32_TYPELESS" },
109 { SVGA3D_R32G32B32A32_UINT , "R32G32B32A32_UINT" },
110 { SVGA3D_R32G32B32A32_SINT , "R32G32B32A32_SINT" },
111 { SVGA3D_R32G32B32_TYPELESS , "R32G32B32_TYPELESS" },
112 { SVGA3D_R32G32B32_FLOAT , "R32G32B32_FLOAT" },
113 { SVGA3D_R32G32B32_UINT , "R32G32B32_UINT" },
114 { SVGA3D_R32G32B32_SINT , "R32G32B32_SINT" },
115 { SVGA3D_R16G16B16A16_TYPELESS , "R16G16B16A16_TYPELESS" },
116 { SVGA3D_R16G16B16A16_UINT , "R16G16B16A16_UINT" },
117 { SVGA3D_R16G16B16A16_SNORM , "R16G16B16A16_SNORM" },
118 { SVGA3D_R16G16B16A16_SINT , "R16G16B16A16_SINT" },
119 { SVGA3D_R32G32_TYPELESS , "R32G32_TYPELESS" },
120 { SVGA3D_R32G32_UINT , "R32G32_UINT" },
121 { SVGA3D_R32G32_SINT , "R32G32_SINT" },
122 { SVGA3D_R32G8X24_TYPELESS , "R32G8X24_TYPELESS" },
123 { SVGA3D_D32_FLOAT_S8X24_UINT , "D32_FLOAT_S8X24_UINT" },
124 { SVGA3D_R32_FLOAT_X8X24 , "R32_FLOAT_X8X24" },
125 { SVGA3D_X32_G8X24_UINT , "X32_G8X24_UINT" },
126 { SVGA3D_R10G10B10A2_TYPELESS , "R10G10B10A2_TYPELESS" },
127 { SVGA3D_R10G10B10A2_UINT , "R10G10B10A2_UINT" },
128 { SVGA3D_R11G11B10_FLOAT , "R11G11B10_FLOAT" },
129 { SVGA3D_R8G8B8A8_TYPELESS , "R8G8B8A8_TYPELESS" },
130 { SVGA3D_R8G8B8A8_UNORM , "R8G8B8A8_UNORM" },
131 { SVGA3D_R8G8B8A8_UNORM_SRGB , "R8G8B8A8_UNORM_SRGB" },
132 { SVGA3D_R8G8B8A8_UINT , "R8G8B8A8_UINT" },
133 { SVGA3D_R8G8B8A8_SINT , "R8G8B8A8_SINT" },
134 { SVGA3D_R16G16_TYPELESS , "R16G16_TYPELESS" },
135 { SVGA3D_R16G16_UINT , "R16G16_UINT" },
136 { SVGA3D_R16G16_SINT , "R16G16_SINT" },
137 { SVGA3D_R32_TYPELESS , "R32_TYPELESS" },
138 { SVGA3D_D32_FLOAT , "D32_FLOAT" },
139 { SVGA3D_R32_UINT , "R32_UINT" },
140 { SVGA3D_R32_SINT , "R32_SINT" },
141 { SVGA3D_R24G8_TYPELESS , "R24G8_TYPELESS" },
142 { SVGA3D_D24_UNORM_S8_UINT , "D24_UNORM_S8_UINT" },
143 { SVGA3D_R24_UNORM_X8 , "R24_UNORM_X8" },
144 { SVGA3D_X24_G8_UINT , "X24_G8_UINT" },
145 { SVGA3D_R8G8_TYPELESS , "R8G8_TYPELESS" },
146 { SVGA3D_R8G8_UNORM , "R8G8_UNORM" },
147 { SVGA3D_R8G8_UINT , "R8G8_UINT" },
148 { SVGA3D_R8G8_SINT , "R8G8_SINT" },
149 { SVGA3D_R16_TYPELESS , "R16_TYPELESS" },
150 { SVGA3D_R16_UNORM , "R16_UNORM" },
151 { SVGA3D_R16_UINT , "R16_UINT" },
152 { SVGA3D_R16_SNORM , "R16_SNORM" },
153 { SVGA3D_R16_SINT , "R16_SINT" },
154 { SVGA3D_R8_TYPELESS , "R8_TYPELESS" },
155 { SVGA3D_R8_UNORM , "R8_UNORM" },
156 { SVGA3D_R8_UINT , "R8_UINT" },
157 { SVGA3D_R8_SNORM , "R8_SNORM" },
158 { SVGA3D_R8_SINT , "R8_SINT" },
159 { SVGA3D_P8 , "P8" },
160 { SVGA3D_R9G9B9E5_SHAREDEXP , "R9G9B9E5_SHAREDEXP" },
161 { SVGA3D_R8G8_B8G8_UNORM , "R8G8_B8G8_UNORM" },
162 { SVGA3D_G8R8_G8B8_UNORM , "G8R8_G8B8_UNORM" },
163 { SVGA3D_BC1_TYPELESS , "BC1_TYPELESS" },
164 { SVGA3D_BC1_UNORM_SRGB , "BC1_UNORM_SRGB" },
165 { SVGA3D_BC2_TYPELESS , "BC2_TYPELESS" },
166 { SVGA3D_BC2_UNORM_SRGB , "BC2_UNORM_SRGB" },
167 { SVGA3D_BC3_TYPELESS , "BC3_TYPELESS" },
168 { SVGA3D_BC3_UNORM_SRGB , "BC3_UNORM_SRGB" },
169 { SVGA3D_BC4_TYPELESS , "BC4_TYPELESS" },
170 { SVGA3D_ATI1 , "ATI1" },
171 { SVGA3D_BC4_SNORM , "BC4_SNORM" },
172 { SVGA3D_BC5_TYPELESS , "BC5_TYPELESS" },
173 { SVGA3D_ATI2 , "ATI2" },
174 { SVGA3D_BC5_SNORM , "BC5_SNORM" },
175 { SVGA3D_R10G10B10_XR_BIAS_A2_UNORM , "R10G10B10_XR_BIAS_A2_UNORM" },
176 { SVGA3D_B8G8R8A8_TYPELESS , "B8G8R8A8_TYPELESS" },
177 { SVGA3D_B8G8R8A8_UNORM_SRGB , "B8G8R8A8_UNORM_SRGB" },
178 { SVGA3D_B8G8R8X8_TYPELESS , "B8G8R8X8_TYPELESS" },
179 { SVGA3D_B8G8R8X8_UNORM_SRGB , "B8G8R8X8_UNORM_SRGB" },
180 { SVGA3D_Z_DF16 , "Z_DF16" },
181 { SVGA3D_Z_DF24 , "Z_DF24" },
182 { SVGA3D_Z_D24S8_INT , "Z_D24S8_INT" },
183 { SVGA3D_YV12 , "YV12" },
184 { SVGA3D_R32G32B32A32_FLOAT , "R32G32B32A32_FLOAT" },
185 { SVGA3D_R16G16B16A16_FLOAT , "R16G16B16A16_FLOAT" },
186 { SVGA3D_R16G16B16A16_UNORM , "R16G16B16A16_UNORM" },
187 { SVGA3D_R32G32_FLOAT , "R32G32_FLOAT" },
188 { SVGA3D_R10G10B10A2_UNORM , "R10G10B10A2_UNORM" },
189 { SVGA3D_R8G8B8A8_SNORM , "R8G8B8A8_SNORM" },
190 { SVGA3D_R16G16_FLOAT , "R16G16_FLOAT" },
191 { SVGA3D_R16G16_UNORM , "R16G16_UNORM" },
192 { SVGA3D_R16G16_SNORM , "R16G16_SNORM" },
193 { SVGA3D_R32_FLOAT , "R32_FLOAT" },
194 { SVGA3D_R8G8_SNORM , "R8G8_SNORM" },
195 { SVGA3D_R16_FLOAT , "R16_FLOAT" },
196 { SVGA3D_D16_UNORM , "D16_UNORM" },
197 { SVGA3D_A8_UNORM , "A8_UNORM" },
198 { SVGA3D_BC1_UNORM , "BC1_UNORM" },
199 { SVGA3D_BC2_UNORM , "BC2_UNORM" },
200 { SVGA3D_BC3_UNORM , "BC3_UNORM" },
201 { SVGA3D_B5G6R5_UNORM , "B5G6R5_UNORM" },
202 { SVGA3D_B5G5R5A1_UNORM , "B5G5R5A1_UNORM" },
203 { SVGA3D_B8G8R8A8_UNORM , "B8G8R8A8_UNORM" },
204 { SVGA3D_B8G8R8X8_UNORM , "B8G8R8X8_UNORM" },
205 { SVGA3D_BC4_UNORM , "BC4_UNORM" },
206 { SVGA3D_BC5_UNORM , "BC5_UNORM" },
207 { SVGA3D_B4G4R4A4_UNORM , "B4G4R4A4_UNORM" },
208 { SVGA3D_BC6H_TYPELESS , "BC6H_TYPELESS" },
209 { SVGA3D_BC6H_UF16 , "BC6H_UF16" },
210 { SVGA3D_BC6H_SF16 , "BC6H_SF16" },
211 { SVGA3D_BC7_TYPELESS , "BC7_TYPELESS" },
212 { SVGA3D_BC7_UNORM , "BC7_UNORM" },
213 { SVGA3D_BC7_UNORM_SRGB , "BC7_UNORM_SRGB" },
214 { SVGA3D_AYUV , "AYUV" },
215};
216VMSVGAINFOENUMMAP_MAKE(RT_NOTHING, g_SVGA3dSurfaceFormat2String, g_aSVGA3dSurfaceFormats, "SVGA3D_");
217
218/** Values for SVGA3dTextureFilter, prefix SVGA3D_TEX_FILTER_. */
219static const char * const g_apszTexureFilters[] =
220{
221 "NONE",
222 "NEAREST",
223 "LINEAR",
224 "ANISOTROPIC",
225 "FLATCUBIC",
226 "GAUSSIANCUBIC",
227 "PYRAMIDALQUAD",
228 "GAUSSIANQUAD",
229};
230
231/** SVGA3dSurface1Flags values, prefix SVGA3D_SURFACE_. */
232static VMSVGAINFOFLAGS32 const g_aSvga3DSurfaceFlags[] =
233{
234 { SVGA3D_SURFACE_CUBEMAP , "CUBEMAP" },
235 { SVGA3D_SURFACE_HINT_STATIC , "HINT_STATIC" },
236 { SVGA3D_SURFACE_HINT_DYNAMIC , "HINT_DYNAMIC" },
237 { SVGA3D_SURFACE_HINT_INDEXBUFFER , "HINT_INDEXBUFFER" },
238 { SVGA3D_SURFACE_HINT_VERTEXBUFFER , "HINT_VERTEXBUFFER" },
239 { SVGA3D_SURFACE_HINT_TEXTURE , "HINT_TEXTURE" },
240 { SVGA3D_SURFACE_HINT_RENDERTARGET , "HINT_RENDERTARGET" },
241 { SVGA3D_SURFACE_HINT_DEPTHSTENCIL , "HINT_DEPTHSTENCIL" },
242 { SVGA3D_SURFACE_HINT_WRITEONLY , "HINT_WRITEONLY" },
243 { SVGA3D_SURFACE_DEAD2 , "MASKABLE_ANTIALIAS" }, /* SVGA3D_SURFACE_MASKABLE_ANTIALIAS */
244 { SVGA3D_SURFACE_AUTOGENMIPMAPS , "AUTOGENMIPMAPS" },
245};
246
247
248#ifdef VMSVGA3D_DIRECT3D
249
250/** Values for D3DFORMAT, prefix D3DFMT_. */
251static VMSVGAINFOENUM const g_aD3DFormats[] =
252{
253 { D3DFMT_UNKNOWN , "UNKNOWN" },
254 { D3DFMT_R8G8B8 , "R8G8B8" },
255 { D3DFMT_A8R8G8B8 , "A8R8G8B8" },
256 { D3DFMT_X8R8G8B8 , "X8R8G8B8" },
257 { D3DFMT_R5G6B5 , "R5G6B5" },
258 { D3DFMT_X1R5G5B5 , "X1R5G5B5" },
259 { D3DFMT_A1R5G5B5 , "A1R5G5B5" },
260 { D3DFMT_A4R4G4B4 , "A4R4G4B4" },
261 { D3DFMT_R3G3B2 , "R3G3B2" },
262 { D3DFMT_A8 , "A8" },
263 { D3DFMT_A8R3G3B2 , "A8R3G3B2" },
264 { D3DFMT_X4R4G4B4 , "X4R4G4B4" },
265 { D3DFMT_A2B10G10R10 , "A2B10G10R10" },
266 { D3DFMT_A8B8G8R8 , "A8B8G8R8" },
267 { D3DFMT_X8B8G8R8 , "X8B8G8R8" },
268 { D3DFMT_G16R16 , "G16R16" },
269 { D3DFMT_A2R10G10B10 , "A2R10G10B10" },
270 { D3DFMT_A16B16G16R16 , "A16B16G16R16" },
271 { D3DFMT_A8P8 , "A8P8" },
272 { D3DFMT_P8 , "P8" },
273 { D3DFMT_L8 , "L8" },
274 { D3DFMT_A8L8 , "A8L8" },
275 { D3DFMT_A4L4 , "A4L4" },
276 { D3DFMT_V8U8 , "V8U8" },
277 { D3DFMT_L6V5U5 , "L6V5U5" },
278 { D3DFMT_X8L8V8U8 , "X8L8V8U8" },
279 { D3DFMT_Q8W8V8U8 , "Q8W8V8U8" },
280 { D3DFMT_V16U16 , "V16U16" },
281 { D3DFMT_A2W10V10U10 , "A2W10V10U10" },
282 { D3DFMT_D16_LOCKABLE , "D16_LOCKABLE" },
283 { D3DFMT_D32 , "D32" },
284 { D3DFMT_D15S1 , "D15S1" },
285 { D3DFMT_D24S8 , "D24S8" },
286 { D3DFMT_D24X8 , "D24X8" },
287 { D3DFMT_D24X4S4 , "D24X4S4" },
288 { D3DFMT_D16 , "D16" },
289 { D3DFMT_L16 , "L16" },
290 { D3DFMT_D32F_LOCKABLE , "D32F_LOCKABLE" },
291 { D3DFMT_D24FS8 , "D24FS8" },
292 { D3DFMT_VERTEXDATA , "VERTEXDATA" },
293 { D3DFMT_INDEX16 , "INDEX16" },
294 { D3DFMT_INDEX32 , "INDEX32" },
295 { D3DFMT_Q16W16V16U16 , "Q16W16V16U16" },
296 { D3DFMT_R16F , "R16F" },
297 { D3DFMT_G16R16F , "G16R16F" },
298 { D3DFMT_A16B16G16R16F , "A16B16G16R16F" },
299 { D3DFMT_R32F , "R32F" },
300 { D3DFMT_G32R32F , "G32R32F" },
301 { D3DFMT_A32B32G32R32F , "A32B32G32R32F" },
302 { D3DFMT_CxV8U8 , "CxV8U8" },
303 /* Fourcc values, MSB is in the right most char: */
304 { D3DFMT_MULTI2_ARGB8 , "MULTI2_ARGB8" },
305 { D3DFMT_DXT1 , "DXT1" },
306 { D3DFMT_DXT2 , "DXT2" },
307 { D3DFMT_YUY2 , "YUY2" },
308 { D3DFMT_DXT3 , "DXT3" },
309 { D3DFMT_DXT4 , "DXT4" },
310 { D3DFMT_DXT5 , "DXT5" },
311 { D3DFMT_G8R8_G8B8 , "G8R8_G8B8" },
312 { D3DFMT_R8G8_B8G8 , "R8G8_B8G8" },
313 { D3DFMT_UYVY , "UYVY" },
314 { D3DFMT_FORCE_DWORD , "FORCE_DWORD" }, /* UINT32_MAX */
315};
316VMSVGAINFOENUMMAP_MAKE(static, g_D3DFormat2String, g_aD3DFormats, "D3DFMT_");
317
318/** Values for D3DMULTISAMPLE_TYPE, prefix D3DMULTISAMPLE_. */
319static VMSVGAINFOENUM const g_aD3DMultiSampleTypes[] =
320{
321 { D3DMULTISAMPLE_NONE , "NONE" },
322 { D3DMULTISAMPLE_NONMASKABLE , "NONMASKABLE" },
323 { D3DMULTISAMPLE_2_SAMPLES , "2_SAMPLES" },
324 { D3DMULTISAMPLE_3_SAMPLES , "3_SAMPLES" },
325 { D3DMULTISAMPLE_4_SAMPLES , "4_SAMPLES" },
326 { D3DMULTISAMPLE_5_SAMPLES , "5_SAMPLES" },
327 { D3DMULTISAMPLE_6_SAMPLES , "6_SAMPLES" },
328 { D3DMULTISAMPLE_7_SAMPLES , "7_SAMPLES" },
329 { D3DMULTISAMPLE_8_SAMPLES , "8_SAMPLES" },
330 { D3DMULTISAMPLE_9_SAMPLES , "9_SAMPLES" },
331 { D3DMULTISAMPLE_10_SAMPLES , "10_SAMPLES" },
332 { D3DMULTISAMPLE_11_SAMPLES , "11_SAMPLES" },
333 { D3DMULTISAMPLE_12_SAMPLES , "12_SAMPLES" },
334 { D3DMULTISAMPLE_13_SAMPLES , "13_SAMPLES" },
335 { D3DMULTISAMPLE_14_SAMPLES , "14_SAMPLES" },
336 { D3DMULTISAMPLE_15_SAMPLES , "15_SAMPLES" },
337 { D3DMULTISAMPLE_16_SAMPLES , "16_SAMPLES" },
338 { D3DMULTISAMPLE_FORCE_DWORD , "FORCE_DWORD" },
339};
340VMSVGAINFOENUMMAP_MAKE(static, g_D3DMultiSampleType2String, g_aD3DMultiSampleTypes, "D3DMULTISAMPLE_");
341
342/** D3DUSAGE_XXX flag value, prefix D3DUSAGE_. */
343static VMSVGAINFOFLAGS32 const g_aD3DUsageFlags[] =
344{
345 { D3DUSAGE_RENDERTARGET , "RENDERTARGET" },
346 { D3DUSAGE_DEPTHSTENCIL , "DEPTHSTENCIL" },
347 { D3DUSAGE_WRITEONLY , "WRITEONLY" },
348 { D3DUSAGE_SOFTWAREPROCESSING , "SOFTWAREPROCESSING" },
349 { D3DUSAGE_DONOTCLIP , "DONOTCLIP" },
350 { D3DUSAGE_POINTS , "POINTS" },
351 { D3DUSAGE_RTPATCHES , "RTPATCHES" },
352 { D3DUSAGE_NPATCHES , "NPATCHES" },
353 { D3DUSAGE_DYNAMIC , "DYNAMIC" },
354 { D3DUSAGE_AUTOGENMIPMAP , "AUTOGENMIPMAP" },
355 { D3DUSAGE_RESTRICTED_CONTENT , "RESTRICTED_CONTENT" },
356 { D3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER , "RESTRICT_SHARED_RESOURCE_DRIVER" },
357 { D3DUSAGE_RESTRICT_SHARED_RESOURCE , "RESTRICT_SHARED_RESOURCE" },
358 { D3DUSAGE_DMAP , "DMAP" },
359 { D3DUSAGE_NONSECURE , "NONSECURE" },
360 { D3DUSAGE_TEXTAPI , "TEXTAPI" },
361};
362
363#endif /* VMSVGA3D_DIRECT3D */
364
365
366void vmsvga3dInfoU32Flags(PCDBGFINFOHLP pHlp, uint32_t fFlags, const char *pszPrefix, PCVMSVGAINFOFLAGS32 paFlags, uint32_t cFlags)
367{
368 for (uint32_t i = 0; i < cFlags; i++)
369 if ((paFlags[i].fFlags & fFlags) == paFlags[i].fFlags)
370 {
371 Assert(paFlags[i].fFlags);
372 pHlp->pfnPrintf(pHlp, " %s%s", pszPrefix, paFlags[i].pszJohnny);
373 fFlags &= ~paFlags[i].fFlags;
374 if (!fFlags)
375 return;
376 }
377 if (fFlags)
378 pHlp->pfnPrintf(pHlp, " UNKNOWN_%#x", fFlags);
379}
380
381
382/**
383 * Worker for vmsvgaR3Info that display details of a host window.
384 *
385 * @param pHlp The output methods.
386 * @param idHostWindow The host window handle/id/whatever.
387 */
388void vmsvga3dInfoHostWindow(PCDBGFINFOHLP pHlp, uint64_t idHostWindow)
389{
390#ifdef RT_OS_WINDOWS
391 HWND hwnd = (HWND)(uintptr_t)idHostWindow;
392 Assert((uintptr_t)hwnd == idHostWindow);
393 if (hwnd != NULL)
394 {
395 WINDOWINFO Info;
396 RT_ZERO(Info);
397 Info.cbSize = sizeof(Info);
398 if (GetWindowInfo(hwnd, &Info))
399 {
400 pHlp->pfnPrintf(pHlp, " Window rect: xLeft=%d, yTop=%d, xRight=%d, yBottom=%d (cx=%d, cy=%d)\n",
401 Info.rcWindow.left, Info.rcWindow.top, Info.rcWindow.right, Info.rcWindow.bottom,
402 Info.rcWindow.right - Info.rcWindow.left, Info.rcWindow.bottom - Info.rcWindow.top);
403 pHlp->pfnPrintf(pHlp, " Client rect: xLeft=%d, yTop=%d, xRight=%d, yBottom=%d (cx=%d, cy=%d)\n",
404 Info.rcClient.left, Info.rcClient.top, Info.rcClient.right, Info.rcClient.bottom,
405 Info.rcClient.right - Info.rcClient.left, Info.rcClient.bottom - Info.rcClient.top);
406 pHlp->pfnPrintf(pHlp, " Style: %#x", Info.dwStyle);
407 static const VMSVGAINFOFLAGS32 g_aStyles[] =
408 {
409 { WS_POPUP , "POPUP" },
410 { WS_CHILD , "CHILD" },
411 { WS_MINIMIZE , "MINIMIZE" },
412 { WS_VISIBLE , "VISIBLE" },
413 { WS_DISABLED , "DISABLED" },
414 { WS_CLIPSIBLINGS , "CLIPSIBLINGS" },
415 { WS_CLIPCHILDREN , "CLIPCHILDREN" },
416 { WS_MAXIMIZE , "MAXIMIZE" },
417 { WS_BORDER , "BORDER" },
418 { WS_DLGFRAME , "DLGFRAME" },
419 { WS_VSCROLL , "VSCROLL" },
420 { WS_HSCROLL , "HSCROLL" },
421 { WS_SYSMENU , "SYSMENU" },
422 { WS_THICKFRAME , "THICKFRAME" },
423 { WS_GROUP , "GROUP" },
424 { WS_TABSTOP , "TABSTOP" },
425 };
426 vmsvga3dInfoU32Flags(pHlp, Info.dwStyle, "", g_aStyles, RT_ELEMENTS(g_aStyles));
427 pHlp->pfnPrintf(pHlp, "\n");
428
429 pHlp->pfnPrintf(pHlp, " ExStyle: %#x", Info.dwExStyle);
430 static const VMSVGAINFOFLAGS32 g_aExStyles[] =
431 {
432 { WS_EX_DLGMODALFRAME, "DLGMODALFRAME" },
433 { 0x00000002, "DRAGDETECT" },
434 { WS_EX_NOPARENTNOTIFY, "NOPARENTNOTIFY" },
435 { WS_EX_TOPMOST, "TOPMOST" },
436 { WS_EX_ACCEPTFILES, "ACCEPTFILES" },
437 { WS_EX_TRANSPARENT, "TRANSPARENT" },
438 { WS_EX_MDICHILD, "MDICHILD" },
439 { WS_EX_TOOLWINDOW, "TOOLWINDOW" },
440 { WS_EX_WINDOWEDGE, "WINDOWEDGE" },
441 { WS_EX_CLIENTEDGE, "CLIENTEDGE" },
442 { WS_EX_CONTEXTHELP, "CONTEXTHELP" },
443 { WS_EX_RIGHT, "RIGHT" },
444 /*{ WS_EX_LEFT, "LEFT" }, = 0 */
445 { WS_EX_RTLREADING, "RTLREADING" },
446 /*{ WS_EX_LTRREADING, "LTRREADING" }, = 0 */
447 { WS_EX_LEFTSCROLLBAR, "LEFTSCROLLBAR" },
448 /*{ WS_EX_RIGHTSCROLLBAR, "RIGHTSCROLLBAR" }, = 0 */
449 { WS_EX_CONTROLPARENT, "CONTROLPARENT" },
450 { WS_EX_STATICEDGE, "STATICEDGE" },
451 { WS_EX_APPWINDOW, "APPWINDOW" },
452 { WS_EX_LAYERED, "LAYERED" },
453 { WS_EX_NOINHERITLAYOUT, "NOINHERITLAYOUT" },
454 { WS_EX_LAYOUTRTL, "LAYOUTRTL" },
455 { WS_EX_COMPOSITED, "COMPOSITED" },
456 { WS_EX_NOACTIVATE, "NOACTIVATE" },
457 };
458 vmsvga3dInfoU32Flags(pHlp, Info.dwExStyle, "", g_aExStyles, RT_ELEMENTS(g_aExStyles));
459 pHlp->pfnPrintf(pHlp, "\n");
460
461 pHlp->pfnPrintf(pHlp, " Window Status: %#x\n", Info.dwWindowStatus);
462 if (Info.cxWindowBorders || Info.cyWindowBorders)
463 pHlp->pfnPrintf(pHlp, " Borders: cx=%u, cy=%u\n", Info.cxWindowBorders, Info.cyWindowBorders);
464 pHlp->pfnPrintf(pHlp, " Window Type: %#x\n", Info.atomWindowType);
465 pHlp->pfnPrintf(pHlp, " Creator Ver: %#x\n", Info.wCreatorVersion);
466 }
467 else
468 pHlp->pfnPrintf(pHlp, " GetWindowInfo: last error %d\n", GetLastError());
469 }
470
471#elif defined(RT_OS_DARWIN)
472 int rc = ExplicitlyLoadVBoxSVGA3DObjC(false /*fResolveAllImports*/, NULL /*pErrInfo*/);
473 if (RT_SUCCESS(rc))
474 vmsvga3dCocoaViewInfo(pHlp, (NativeNSViewRef)(uintptr_t)idHostWindow);
475 else
476 pHlp->pfnPrintf(pHlp, " Windows info: vmsvga3dCocoaViewInfo failed to load (%Rrc)\n", rc);
477
478#else
479 RT_NOREF(idHostWindow);
480 pHlp->pfnPrintf(pHlp, " Windows info: Not implemented on this platform\n");
481#endif
482}
483
484
485/**
486 * Looks up an enum value in a translation table.
487 *
488 * @returns The value name.
489 * @param iValue The value to name.
490 * @param pEnumMap Enum value to string mapping.
491 */
492const char *vmsvgaLookupEnum(int32_t iValue, PCVMSVGAINFOENUMMAP pEnumMap)
493{
494 PCVMSVGAINFOENUM paValues = pEnumMap->paValues;
495
496#ifdef VBOX_STRICT
497 /*
498 * Check that it's really sorted, or the binary lookup won't work right.
499 */
500 if (!*pEnumMap->pfAsserted)
501 {
502 *pEnumMap->pfAsserted = true;
503 for (uint32_t i = 1; i < pEnumMap->cValues; i++)
504 AssertMsg(paValues[i - 1].iValue <= paValues[i].iValue,
505 ("i = %d: %d followed by %d", i, paValues[i - 1].iValue, paValues[i].iValue));
506 }
507#endif
508
509 /*
510 * Binary search
511 */
512 uint32_t iStart = 0;
513 uint32_t iEnd = (uint32_t)pEnumMap->cValues;
514 for (;;)
515 {
516 uint32_t i = iStart + (iEnd - iStart) / 2;
517 if (iValue < paValues[i].iValue)
518 {
519 if (i > iStart)
520 iEnd = i;
521 else
522 break;
523 }
524 else if (iValue > paValues[i].iValue)
525 {
526 i++;
527 if (i < iEnd)
528 iStart = i;
529 else
530 break;
531 }
532 else
533 return paValues[i].pszName;
534 }
535 return NULL;
536}
537
538
539/**
540 * Formats an enum value as a string, sparse mapping table.
541 *
542 * @returns pszBuffer.
543 * @param pszBuffer The output buffer.
544 * @param cbBuffer The size of the output buffer.
545 * @param pszName The variable name, optional.
546 * @param iValue The enum value.
547 * @param fPrefix Whether to prepend the prefix or not.
548 * @param pEnumMap Enum value to string mapping.
549 */
550char *vmsvgaFormatEnumValueEx(char *pszBuffer, size_t cbBuffer, const char *pszName, int32_t iValue,
551 bool fPrefix, PCVMSVGAINFOENUMMAP pEnumMap)
552{
553 const char *pszValueName = vmsvgaLookupEnum(iValue, pEnumMap);
554 const char *pszPrefix = fPrefix ? pEnumMap->pszPrefix : "";
555 if (pszValueName)
556 {
557 if (pszName)
558 RTStrPrintf(pszBuffer, cbBuffer, "%s = %s%s (%#x)", pszName, pszPrefix, pszValueName, iValue);
559 else
560 RTStrPrintf(pszBuffer, cbBuffer, "%s%s (%#x)", pszPrefix, pszValueName, iValue);
561 return pszBuffer;
562 }
563
564 if (pszName)
565 RTStrPrintf(pszBuffer, cbBuffer, "%s = %sUNKNOWN_%d (%#x)", pszName, pszPrefix, iValue, iValue);
566 else
567 RTStrPrintf(pszBuffer, cbBuffer, "%sUNKNOWN_%d (%#x)", pszPrefix, iValue, iValue);
568 return pszBuffer;
569}
570
571
572/**
573 * Formats an enum value as a string.
574 *
575 * @returns pszBuffer.
576 * @param pszBuffer The output buffer.
577 * @param cbBuffer The size of the output buffer.
578 * @param pszName The variable name, optional.
579 * @param uValue The enum value.
580 * @param pszPrefix The prefix of the enum values. Empty string if
581 * none. This helps reduce the memory footprint
582 * as well as the source code size.
583 * @param papszValues One to one string mapping of the enum values.
584 * @param cValues The number of values in the mapping.
585 */
586char *vmsvgaFormatEnumValue(char *pszBuffer, size_t cbBuffer, const char *pszName, uint32_t uValue,
587 const char *pszPrefix, const char * const *papszValues, size_t cValues)
588{
589 if (uValue < cValues)
590 {
591 if (pszName)
592 RTStrPrintf(pszBuffer, cbBuffer, "%s = %s%s (%#x)", pszName, pszPrefix, papszValues[uValue], uValue);
593 else
594 RTStrPrintf(pszBuffer, cbBuffer, "%s%s (%#x)", pszPrefix, papszValues[uValue], uValue);
595 }
596 else
597 {
598 if (pszName)
599 RTStrPrintf(pszBuffer, cbBuffer, "%s = %sUNKNOWN_%d (%#x)", pszName, pszPrefix, uValue, uValue);
600 else
601 RTStrPrintf(pszBuffer, cbBuffer, "%sUNKNOWN_%d (%#x)", pszPrefix, uValue, uValue);
602 }
603 return pszBuffer;
604}
605
606
607/**
608 * DBGF info printer for vmsvga3dAsciiPrint.
609 *
610 * @param pszLine The line to print.
611 * @param pvUser The debug info helpers.
612 */
613DECLCALLBACK(void) vmsvga3dAsciiPrintlnInfo(const char *pszLine, void *pvUser)
614{
615 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
616 pHlp->pfnPrintf(pHlp, ">%s<\n", pszLine);
617}
618
619
620/**
621 * Log printer for vmsvga3dAsciiPrint.
622 *
623 * @param pszLine The line to print.
624 * @param pvUser Ignored.
625 */
626DECLCALLBACK(void) vmsvga3dAsciiPrintlnLog(const char *pszLine, void *pvUser)
627{
628 size_t cch = strlen(pszLine);
629 while (cch > 0 && pszLine[cch - 1] == ' ')
630 cch--;
631 RTLogPrintf("%.*s\n", cch, pszLine);
632 NOREF(pvUser);
633}
634
635
636void vmsvga3dAsciiPrint(PFNVMSVGAASCIIPRINTLN pfnPrintLine, void *pvUser, void const *pvImage, size_t cbImage,
637 uint32_t cx, uint32_t cy, uint32_t cbScanline, SVGA3dSurfaceFormat enmFormat, bool fInvY,
638 uint32_t cchMaxX, uint32_t cchMaxY)
639{
640 RT_NOREF(cbImage);
641
642 /*
643 * Skip stuff we can't or won't need to handle.
644 */
645 if (!cx || !cy || !cchMaxX || !cchMaxY)
646 return;
647 switch (enmFormat)
648 {
649 /* Compressed. */
650 case SVGA3D_DXT1:
651 case SVGA3D_DXT2:
652 case SVGA3D_DXT3:
653 case SVGA3D_DXT4:
654 case SVGA3D_DXT5:
655 return;
656 /* Generic. */
657 case SVGA3D_BUFFER:
658 return;
659 default:
660 break; /* ok */
661 }
662
663 /*
664 * Figure the pixel conversion factors.
665 */
666 uint32_t cxPerChar = cx / cchMaxX + 1;
667 uint32_t cyPerChar = cy / cchMaxY + 1;
668 /** @todo try keep aspect... */
669 uint32_t const cchLine = (cx + cxPerChar - 1) / cxPerChar;
670 uint32_t const cbSrcPixel = vmsvga3dSurfaceFormatSize(enmFormat, NULL, NULL);
671
672 /*
673 * The very simple conversion we're doing in this function is based on
674 * mapping a block of converted pixels to an ASCII character of similar
675 * weigth. We do that by summing up all the 8-bit gray scale pixels in
676 * that block, applying a conversion factor and getting an index into an
677 * array of increasingly weighty characters.
678 */
679 static const char s_szPalette[] = " ..`',:;icodxkO08XNWM";
680 static const uint32_t s_cchPalette = sizeof(s_szPalette) - 1;
681 uint32_t const cPixelsWeightPerChar = cxPerChar * cyPerChar * 256;
682
683 /*
684 * Do the work
685 */
686 uint32_t *pauScanline = (uint32_t *)RTMemTmpAllocZ(sizeof(pauScanline[0]) * cchLine + cchLine + 1);
687 if (!pauScanline)
688 return;
689 char *pszLine = (char *)&pauScanline[cchLine];
690 RTCPTRUNION uSrc;
691 uSrc.pv = pvImage;
692 if (fInvY)
693 uSrc.pu8 += (cy - 1) * cbScanline;
694 uint32_t cyLeft = cy;
695 uint32_t cyLeftInScanline = cyPerChar;
696 bool fHitFormatAssert = false;
697 for (;;)
698 {
699 /*
700 * Process the scanline. This is tedious because of all the
701 * different formats. We generally ignore alpha, unless it's
702 * all we've got to work with.
703 * Color to 8-bit grayscale conversion is done by averaging.
704 */
705#define CONVERT_SCANLINE(a_RdExpr, a_AddExpr) \
706 do { \
707 for (uint32_t xSrc = 0, xDst = 0, cxLeftInChar = cxPerChar; xSrc < cx; xSrc++) \
708 { \
709 a_RdExpr; \
710 pauScanline[xDst] += (a_AddExpr) & 0xff; \
711 Assert(pauScanline[xDst] <= cPixelsWeightPerChar); \
712 if (--cxLeftInChar == 0) \
713 { \
714 xDst++; \
715 cxLeftInChar = cxPerChar; \
716 } \
717 } \
718 } while (0)
719
720 switch (enmFormat)
721 {
722 /* Unsigned RGB and super/subsets. */
723 case SVGA3D_X8R8G8B8:
724 case SVGA3D_A8R8G8B8:
725 CONVERT_SCANLINE(uint32_t const u32Tmp = uSrc.pu32[xSrc],
726 ( ( u32Tmp & 0xff) /* B */
727 + ((u32Tmp >> 8) & 0xff) /* G */
728 + ((u32Tmp >> 16) & 0xff) /* R */) / 3);
729 break;
730 case SVGA3D_R5G6B5:
731 CONVERT_SCANLINE(uint16_t const u16Tmp = uSrc.pu16[xSrc],
732 ( ( u16Tmp & 0x1f) * 8
733 + ((u16Tmp >> 5) & 0x3f) * 4
734 + ( u16Tmp >> 11) * 8 ) / 3 );
735 break;
736 case SVGA3D_X1R5G5B5:
737 case SVGA3D_A1R5G5B5:
738 CONVERT_SCANLINE(uint16_t const u16Tmp = uSrc.pu16[xSrc],
739 ( ( u16Tmp & 0x1f) * 8
740 + ((u16Tmp >> 5) & 0x1f) * 8
741 + ((u16Tmp >> 10) & 0x1f) * 8) / 3 );
742 break;
743 case SVGA3D_A4R4G4B4:
744 CONVERT_SCANLINE(uint16_t const u16Tmp = uSrc.pu16[xSrc],
745 ( ( u16Tmp & 0xf) * 16
746 + ((u16Tmp >> 4) & 0xf) * 16
747 + ((u16Tmp >> 8) & 0xf) * 16) / 3 );
748 break;
749 case SVGA3D_A16B16G16R16:
750 CONVERT_SCANLINE(uint64_t const u64Tmp = uSrc.pu64[xSrc],
751 ( ((u64Tmp >> 8) & 0xff) /* R */
752 + ((u64Tmp >> 24) & 0xff) /* G */
753 + ((u64Tmp >> 40) & 0xff) /* B */ ) / 3);
754 break;
755 case SVGA3D_A2R10G10B10:
756 CONVERT_SCANLINE(uint32_t const u32Tmp = uSrc.pu32[xSrc],
757 ( ( u32Tmp & 0x3ff) /* B */
758 + ((u32Tmp >> 10) & 0x3ff) /* G */
759 + ((u32Tmp >> 20) & 0x3ff) /* R */ ) / (3 * 4));
760 break;
761 case SVGA3D_G16R16:
762 CONVERT_SCANLINE(uint32_t const u32Tmp = uSrc.pu32[xSrc],
763 ( (u32Tmp & 0xffff) /* R */
764 + (u32Tmp >> 16 ) /* G */) / 0x200);
765 break;
766
767 /* Depth. */
768 case SVGA3D_Z_D32:
769 CONVERT_SCANLINE(uint32_t const u32Tmp = ~((uSrc.pu32[xSrc] >> 1) | uSrc.pu32[xSrc]) & UINT32_C(0x44444444),
770 (( u32Tmp >> (2 - 0)) & RT_BIT_32(0))
771 | ((u32Tmp >> ( 6 - 1)) & RT_BIT_32(1))
772 | ((u32Tmp >> (10 - 2)) & RT_BIT_32(2))
773 | ((u32Tmp >> (14 - 3)) & RT_BIT_32(3))
774 | ((u32Tmp >> (18 - 4)) & RT_BIT_32(4))
775 | ((u32Tmp >> (22 - 5)) & RT_BIT_32(5))
776 | ((u32Tmp >> (26 - 6)) & RT_BIT_32(6))
777 | ((u32Tmp >> (30 - 7)) & RT_BIT_32(7)) );
778 break;
779 case SVGA3D_Z_D16:
780 CONVERT_SCANLINE(uint16_t const u16Tmp = ~uSrc.pu16[xSrc],
781 ((u16Tmp >> ( 1 - 0)) & RT_BIT_32(0))
782 | ((u16Tmp >> ( 3 - 1)) & RT_BIT_32(1))
783 | ((u16Tmp >> ( 5 - 2)) & RT_BIT_32(2))
784 | ((u16Tmp >> ( 7 - 3)) & RT_BIT_32(3))
785 | ((u16Tmp >> ( 9 - 4)) & RT_BIT_32(4))
786 | ((u16Tmp >> (11 - 5)) & RT_BIT_32(5))
787 | ((u16Tmp >> (13 - 6)) & RT_BIT_32(6))
788 | ((u16Tmp >> (15 - 7)) & RT_BIT_32(7)) );
789 break;
790 case SVGA3D_Z_D24S8:
791 CONVERT_SCANLINE(uint32_t const u32Tmp = uSrc.pu32[xSrc],
792 ( u32Tmp & 0xff) /* stencile */
793 | ((~u32Tmp >> 18) & 0x3f));
794 break;
795 case SVGA3D_Z_D15S1:
796 CONVERT_SCANLINE(uint16_t const u16Tmp = uSrc.pu16[xSrc],
797 ( (u16Tmp & 0x01) << 7) /* stencile */
798 | ((~u16Tmp >> 8) & 0x7f));
799 break;
800
801 /* Pure alpha. */
802 case SVGA3D_ALPHA8:
803 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu8[xSrc]);
804 break;
805
806 /* Luminance */
807 case SVGA3D_LUMINANCE8:
808 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu8[xSrc]);
809 break;
810 case SVGA3D_LUMINANCE4_ALPHA4:
811 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu8[xSrc] & 0xf0);
812 break;
813 case SVGA3D_LUMINANCE16:
814 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu16[xSrc] >> 8);
815 break;
816 case SVGA3D_LUMINANCE8_ALPHA8:
817 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu16[xSrc] >> 8);
818 break;
819
820 /* Not supported. */
821 case SVGA3D_DXT1:
822 case SVGA3D_DXT2:
823 case SVGA3D_DXT3:
824 case SVGA3D_DXT4:
825 case SVGA3D_DXT5:
826 case SVGA3D_BUFFER:
827 AssertFailedBreak();
828
829 /* Not considered for implementation yet. */
830 case SVGA3D_BUMPU8V8:
831 case SVGA3D_BUMPL6V5U5:
832 case SVGA3D_BUMPX8L8V8U8:
833 case SVGA3D_FORMAT_DEAD1:
834 case SVGA3D_ARGB_S10E5:
835 case SVGA3D_ARGB_S23E8:
836 case SVGA3D_V8U8:
837 case SVGA3D_Q8W8V8U8:
838 case SVGA3D_CxV8U8:
839 case SVGA3D_X8L8V8U8:
840 case SVGA3D_A2W10V10U10:
841 case SVGA3D_R_S10E5:
842 case SVGA3D_R_S23E8:
843 case SVGA3D_RG_S10E5:
844 case SVGA3D_RG_S23E8:
845 case SVGA3D_Z_D24X8:
846 case SVGA3D_V16U16:
847 case SVGA3D_UYVY:
848 case SVGA3D_YUY2:
849 case SVGA3D_NV12:
850 case SVGA3D_FORMAT_DEAD2: /* Old SVGA3D_AYUV */
851 case SVGA3D_ATI1:
852 case SVGA3D_ATI2:
853 case SVGA3D_Z_DF16:
854 case SVGA3D_Z_DF24:
855 case SVGA3D_Z_D24S8_INT:
856 if (!fHitFormatAssert)
857 {
858 AssertMsgFailed(("%s is not implemented\n", vmsvgaLookupEnum((int)enmFormat, &g_SVGA3dSurfaceFormat2String)));
859 fHitFormatAssert = true;
860 }
861 RT_FALL_THRU();
862 default:
863 /* Lazy programmer fallbacks. */
864 if (cbSrcPixel == 4)
865 CONVERT_SCANLINE(uint32_t const u32Tmp = uSrc.pu32[xSrc],
866 ( ( u32Tmp & 0xff)
867 + ((u32Tmp >> 8) & 0xff)
868 + ((u32Tmp >> 16) & 0xff)
869 + ((u32Tmp >> 24) & 0xff) ) / 4);
870 else if (cbSrcPixel == 3)
871 CONVERT_SCANLINE(RT_NOTHING,
872 ( (uint32_t)uSrc.pu8[xSrc * 4]
873 + (uint32_t)uSrc.pu8[xSrc * 4 + 1]
874 + (uint32_t)uSrc.pu8[xSrc * 4 + 2] ) / 3);
875 else if (cbSrcPixel == 2)
876 CONVERT_SCANLINE(uint16_t const u16Tmp = uSrc.pu16[xSrc],
877 ( ( u16Tmp & 0xf)
878 + ((u16Tmp >> 4) & 0xf)
879 + ((u16Tmp >> 8) & 0xf)
880 + ((u16Tmp >> 12) & 0xf) ) * 4 /* mul 16 div 4 */ );
881 else if (cbSrcPixel == 1)
882 CONVERT_SCANLINE(RT_NOTHING, uSrc.pu8[xSrc]);
883 else
884 AssertFailed();
885 break;
886
887 }
888
889 /*
890 * Print we've reached the end of a block in y direction or if we're at
891 * the end of the image.
892 */
893 cyLeft--;
894 if (--cyLeftInScanline == 0 || cyLeft == 0)
895 {
896 for (uint32_t i = 0; i < cchLine; i++)
897 {
898 uint32_t off = pauScanline[i] * s_cchPalette / cPixelsWeightPerChar; Assert(off < s_cchPalette);
899 pszLine[i] = s_szPalette[off < sizeof(s_szPalette) - 1 ? off : sizeof(s_szPalette) - 1];
900 }
901 pszLine[cchLine] = '\0';
902 pfnPrintLine(pszLine, pvUser);
903
904 if (!cyLeft)
905 break;
906 cyLeftInScanline = cyPerChar;
907 RT_BZERO(pauScanline, sizeof(pauScanline[0]) * cchLine);
908 }
909
910 /*
911 * Advance.
912 */
913 if (!fInvY)
914 uSrc.pu8 += cbScanline;
915 else
916 uSrc.pu8 -= cbScanline;
917 }
918}
919
920
921
922/**
923 * Formats a SVGA3dRenderState structure as a string.
924 *
925 * @returns pszBuffer.
926 * @param pszBuffer Output string buffer.
927 * @param cbBuffer Size of output buffer.
928 * @param pRenderState The SVGA3d render state to format.
929 */
930char *vmsvga3dFormatRenderState(char *pszBuffer, size_t cbBuffer, SVGA3dRenderState const *pRenderState)
931{
932 /*
933 * List of render state names with type prefix.
934 *
935 * First char in the name is a type indicator:
936 * - '*' = requires special handling.
937 * - 'f' = SVGA3dbool
938 * - 'd' = uint32_t
939 * - 'r' = float
940 * - 'b' = SVGA3dBlendOp
941 * - 'c' = SVGA3dColor, SVGA3dColorMask
942 * - 'e' = SVGA3dBlendEquation
943 * - 'm' = SVGA3dColorMask
944 * - 'p' = SVGA3dCmpFunc
945 * - 's' = SVGA3dStencilOp
946 * - 'v' = SVGA3dVertexMaterial
947 * - 'w' = SVGA3dWrapFlags
948 */
949 static const char * const s_apszRenderStateNamesAndType[] =
950 {
951 "*" "INVALID", /* invalid */
952 "f" "ZENABLE", /* SVGA3dBool */
953 "f" "ZWRITEENABLE", /* SVGA3dBool */
954 "f" "ALPHATESTENABLE", /* SVGA3dBool */
955 "f" "DITHERENABLE", /* SVGA3dBool */
956 "f" "BLENDENABLE", /* SVGA3dBool */
957 "f" "FOGENABLE", /* SVGA3dBool */
958 "f" "SPECULARENABLE", /* SVGA3dBool */
959 "f" "STENCILENABLE", /* SVGA3dBool */
960 "f" "LIGHTINGENABLE", /* SVGA3dBool */
961 "f" "NORMALIZENORMALS", /* SVGA3dBool */
962 "f" "POINTSPRITEENABLE", /* SVGA3dBool */
963 "f" "POINTSCALEENABLE", /* SVGA3dBool */
964 "x" "STENCILREF", /* uint32_t */
965 "x" "STENCILMASK", /* uint32_t */
966 "x" "STENCILWRITEMASK", /* uint32_t */
967 "r" "FOGSTART", /* float */
968 "r" "FOGEND", /* float */
969 "r" "FOGDENSITY", /* float */
970 "r" "POINTSIZE", /* float */
971 "r" "POINTSIZEMIN", /* float */
972 "r" "POINTSIZEMAX", /* float */
973 "r" "POINTSCALE_A", /* float */
974 "r" "POINTSCALE_B", /* float */
975 "r" "POINTSCALE_C", /* float */
976 "c" "FOGCOLOR", /* SVGA3dColor */
977 "c" "AMBIENT", /* SVGA3dColor */
978 "*" "CLIPPLANEENABLE", /* SVGA3dClipPlanes */
979 "*" "FOGMODE", /* SVGA3dFogMode */
980 "*" "FILLMODE", /* SVGA3dFillMode */
981 "*" "SHADEMODE", /* SVGA3dShadeMode */
982 "*" "LINEPATTERN", /* SVGA3dLinePattern */
983 "b" "SRCBLEND", /* SVGA3dBlendOp */
984 "b" "DSTBLEND", /* SVGA3dBlendOp */
985 "e" "BLENDEQUATION", /* SVGA3dBlendEquation */
986 "*" "CULLMODE", /* SVGA3dFace */
987 "p" "ZFUNC", /* SVGA3dCmpFunc */
988 "p" "ALPHAFUNC", /* SVGA3dCmpFunc */
989 "p" "STENCILFUNC", /* SVGA3dCmpFunc */
990 "s" "STENCILFAIL", /* SVGA3dStencilOp */
991 "s" "STENCILZFAIL", /* SVGA3dStencilOp */
992 "s" "STENCILPASS", /* SVGA3dStencilOp */
993 "r" "ALPHAREF", /* float */
994 "*" "FRONTWINDING", /* SVGA3dFrontWinding */
995 "*" "COORDINATETYPE", /* SVGA3dCoordinateType */
996 "r" "ZBIAS", /* float */
997 "f" "RANGEFOGENABLE", /* SVGA3dBool */
998 "c" "COLORWRITEENABLE", /* SVGA3dColorMask */
999 "f" "VERTEXMATERIALENABLE", /* SVGA3dBool */
1000 "v" "DIFFUSEMATERIALSOURCE", /* SVGA3dVertexMaterial */
1001 "v" "SPECULARMATERIALSOURCE", /* SVGA3dVertexMaterial */
1002 "v" "AMBIENTMATERIALSOURCE", /* SVGA3dVertexMaterial */
1003 "v" "EMISSIVEMATERIALSOURCE", /* SVGA3dVertexMaterial */
1004 "c" "TEXTUREFACTOR", /* SVGA3dColor */
1005 "f" "LOCALVIEWER", /* SVGA3dBool */
1006 "f" "SCISSORTESTENABLE", /* SVGA3dBool */
1007 "c" "BLENDCOLOR", /* SVGA3dColor */
1008 "f" "STENCILENABLE2SIDED", /* SVGA3dBool */
1009 "p" "CCWSTENCILFUNC", /* SVGA3dCmpFunc */
1010 "s" "CCWSTENCILFAIL", /* SVGA3dStencilOp */
1011 "s" "CCWSTENCILZFAIL", /* SVGA3dStencilOp */
1012 "s" "CCWSTENCILPASS", /* SVGA3dStencilOp */
1013 "*" "VERTEXBLEND", /* SVGA3dVertexBlendFlags */
1014 "r" "SLOPESCALEDEPTHBIAS", /* float */
1015 "r" "DEPTHBIAS", /* float */
1016 "r" "OUTPUTGAMMA", /* float */
1017 "f" "ZVISIBLE", /* SVGA3dBool */
1018 "f" "LASTPIXEL", /* SVGA3dBool */
1019 "f" "CLIPPING", /* SVGA3dBool */
1020 "w" "WRAP0", /* SVGA3dWrapFlags */
1021 "w" "WRAP1", /* SVGA3dWrapFlags */
1022 "w" "WRAP2", /* SVGA3dWrapFlags */
1023 "w" "WRAP3", /* SVGA3dWrapFlags */
1024 "w" "WRAP4", /* SVGA3dWrapFlags */
1025 "w" "WRAP5", /* SVGA3dWrapFlags */
1026 "w" "WRAP6", /* SVGA3dWrapFlags */
1027 "w" "WRAP7", /* SVGA3dWrapFlags */
1028 "w" "WRAP8", /* SVGA3dWrapFlags */
1029 "w" "WRAP9", /* SVGA3dWrapFlags */
1030 "w" "WRAP10", /* SVGA3dWrapFlags */
1031 "w" "WRAP11", /* SVGA3dWrapFlags */
1032 "w" "WRAP12", /* SVGA3dWrapFlags */
1033 "w" "WRAP13", /* SVGA3dWrapFlags */
1034 "w" "WRAP14", /* SVGA3dWrapFlags */
1035 "w" "WRAP15", /* SVGA3dWrapFlags */
1036 "f" "MULTISAMPLEANTIALIAS", /* SVGA3dBool */
1037 "x" "MULTISAMPLEMASK", /* uint32_t */
1038 "f" "INDEXEDVERTEXBLENDENABLE", /* SVGA3dBool */
1039 "r" "TWEENFACTOR", /* float */
1040 "f" "ANTIALIASEDLINEENABLE", /* SVGA3dBool */
1041 "c" "COLORWRITEENABLE1", /* SVGA3dColorMask */
1042 "c" "COLORWRITEENABLE2", /* SVGA3dColorMask */
1043 "c" "COLORWRITEENABLE3", /* SVGA3dColorMask */
1044 "f" "SEPARATEALPHABLENDENABLE", /* SVGA3dBool */
1045 "b" "SRCBLENDALPHA", /* SVGA3dBlendOp */
1046 "b" "DSTBLENDALPHA", /* SVGA3dBlendOp */
1047 "e" "BLENDEQUATIONALPHA", /* SVGA3dBlendEquation */
1048 "*" "TRANSPARENCYANTIALIAS", /* SVGA3dTransparencyAntialiasType */
1049 "r" "LINEWIDTH", /* float */
1050 };
1051
1052 uint32_t iState = pRenderState->state;
1053 if (iState != SVGA3D_RS_INVALID)
1054 {
1055 if (iState < RT_ELEMENTS(s_apszRenderStateNamesAndType))
1056 {
1057 const char *pszName = s_apszRenderStateNamesAndType[iState];
1058 char const chType = *pszName++;
1059
1060 union
1061 {
1062 uint32_t u;
1063 float r;
1064 SVGA3dColorMask Color;
1065 } uValue;
1066 uValue.u = pRenderState->uintValue;
1067
1068 switch (chType)
1069 {
1070 case 'f':
1071 if (uValue.u == 0)
1072 RTStrPrintf(pszBuffer, cbBuffer, "%s = false", pszName);
1073 else if (uValue.u == 1)
1074 RTStrPrintf(pszBuffer, cbBuffer, "%s = true", pszName);
1075 else
1076 RTStrPrintf(pszBuffer, cbBuffer, "%s = true (%#x)", pszName, uValue.u);
1077 break;
1078 case 'x':
1079 RTStrPrintf(pszBuffer, cbBuffer, "%s = %#x (%d)", pszName, uValue.u, uValue.u);
1080 break;
1081 case 'r':
1082 RTStrPrintf(pszBuffer, cbBuffer, "%s = %d.%06u (%#x)",
1083 pszName, (int)uValue.r, (unsigned)(uValue.r * 1000000) % 1000000U, uValue.u);
1084 break;
1085 case 'c': //SVGA3dColor, SVGA3dColorMask
1086 RTStrPrintf(pszBuffer, cbBuffer, "%s = RGBA(%d,%d,%d,%d) (%#x)", pszName,
1087 uValue.Color.red, uValue.Color.green, uValue.Color.blue, uValue.Color.alpha, uValue.u);
1088 break;
1089 case 'w': //SVGA3dWrapFlags
1090 RTStrPrintf(pszBuffer, cbBuffer, "%s = %#x%s", pszName, uValue.u,
1091 uValue.u <= SVGA3D_WRAPCOORD_ALL ? " (out of bounds" : "");
1092 break;
1093 default:
1094 AssertFailed(); RT_FALL_THRU();
1095 case 'b': //SVGA3dBlendOp
1096 case 'e': //SVGA3dBlendEquation
1097 case 'p': //SVGA3dCmpFunc
1098 case 's': //SVGA3dStencilOp
1099 case 'v': //SVGA3dVertexMaterial
1100 case '*':
1101 RTStrPrintf(pszBuffer, cbBuffer, "%s = %#x", pszName, uValue.u);
1102 break;
1103 }
1104 }
1105 else
1106 RTStrPrintf(pszBuffer, cbBuffer, "UNKNOWN_%d_%#x = %#x", iState, iState, pRenderState->uintValue);
1107 }
1108 else
1109 RTStrPrintf(pszBuffer, cbBuffer, "INVALID");
1110 return pszBuffer;
1111}
1112
1113
1114/**
1115 * Formats a SVGA3dTextureState structure as a string.
1116 *
1117 * @returns pszBuffer.
1118 * @param pszBuffer Output string buffer.
1119 * @param cbBuffer Size of output buffer.
1120 * @param pTextureState The SVGA3d texture state to format.
1121 */
1122char *vmsvga3dFormatTextureState(char *pszBuffer, size_t cbBuffer, SVGA3dTextureState const *pTextureState)
1123{
1124 static const char * const s_apszTextureStateNamesAndType[] =
1125 {
1126 "*" "INVALID", /* invalid */
1127 "x" "BIND_TEXTURE", /* SVGA3dSurfaceId */
1128 "m" "COLOROP", /* SVGA3dTextureCombiner */
1129 "a" "COLORARG1", /* SVGA3dTextureArgData */
1130 "a" "COLORARG2", /* SVGA3dTextureArgData */
1131 "m" "ALPHAOP", /* SVGA3dTextureCombiner */
1132 "a" "ALPHAARG1", /* SVGA3dTextureArgData */
1133 "a" "ALPHAARG2", /* SVGA3dTextureArgData */
1134 "e" "ADDRESSU", /* SVGA3dTextureAddress */
1135 "e" "ADDRESSV", /* SVGA3dTextureAddress */
1136 "l" "MIPFILTER", /* SVGA3dTextureFilter */
1137 "l" "MAGFILTER", /* SVGA3dTextureFilter */
1138 "m" "MINFILTER", /* SVGA3dTextureFilter */
1139 "c" "BORDERCOLOR", /* SVGA3dColor */
1140 "r" "TEXCOORDINDEX", /* uint32_t */
1141 "t" "TEXTURETRANSFORMFLAGS", /* SVGA3dTexTransformFlags */
1142 "g" "TEXCOORDGEN", /* SVGA3dTextureCoordGen */
1143 "r" "BUMPENVMAT00", /* float */
1144 "r" "BUMPENVMAT01", /* float */
1145 "r" "BUMPENVMAT10", /* float */
1146 "r" "BUMPENVMAT11", /* float */
1147 "x" "TEXTURE_MIPMAP_LEVEL", /* uint32_t */
1148 "r" "TEXTURE_LOD_BIAS", /* float */
1149 "x" "TEXTURE_ANISOTROPIC_LEVEL", /* uint32_t */
1150 "e" "ADDRESSW", /* SVGA3dTextureAddress */
1151 "r" "GAMMA", /* float */
1152 "r" "BUMPENVLSCALE", /* float */
1153 "r" "BUMPENVLOFFSET", /* float */
1154 "a" "COLORARG0", /* SVGA3dTextureArgData */
1155 "a" "ALPHAARG0" /* SVGA3dTextureArgData */
1156 };
1157
1158 /*
1159 * Format the stage first.
1160 */
1161 char *pszRet = pszBuffer;
1162 size_t cchPrefix = RTStrPrintf(pszBuffer, cbBuffer, "[%u] ", pTextureState->stage);
1163 if (cchPrefix < cbBuffer)
1164 {
1165 cbBuffer -= cchPrefix;
1166 pszBuffer += cchPrefix;
1167 }
1168 else
1169 cbBuffer = 0;
1170
1171 /*
1172 * Format the name and value.
1173 */
1174 uint32_t iName = pTextureState->name;
1175 if (iName != SVGA3D_TS_INVALID)
1176 {
1177 if (iName < RT_ELEMENTS(s_apszTextureStateNamesAndType))
1178 {
1179 const char *pszName = s_apszTextureStateNamesAndType[iName];
1180 char chType = *pszName++;
1181
1182 union
1183 {
1184 uint32_t u;
1185 float r;
1186 SVGA3dColorMask Color;
1187 } uValue;
1188 uValue.u = pTextureState->value;
1189
1190 switch (chType)
1191 {
1192 case 'x':
1193 RTStrPrintf(pszBuffer, cbBuffer, "%s = %#x (%d)", pszName, uValue.u, uValue.u);
1194 break;
1195
1196 case 'r':
1197 RTStrPrintf(pszBuffer, cbBuffer, "%s = %d.%06u (%#x)",
1198 pszName, (int)uValue.r, (unsigned)(uValue.r * 1000000) % 1000000U, uValue.u);
1199 break;
1200
1201 case 'a': //SVGA3dTextureArgData
1202 {
1203 static const char * const s_apszValues[] =
1204 {
1205 "INVALID", "CONSTANT", "PREVIOUS", "DIFFUSE", "TEXTURE", "SPECULAR"
1206 };
1207 vmsvgaFormatEnumValue(pszBuffer, cbBuffer, pszName, uValue.u,
1208 "SVGA3D_TA_", s_apszValues, RT_ELEMENTS(s_apszValues));
1209 break;
1210 }
1211
1212 case 'c': //SVGA3dColor, SVGA3dColorMask
1213 RTStrPrintf(pszBuffer, cbBuffer, "%s = RGBA(%d,%d,%d,%d) (%#x)", pszName,
1214 uValue.Color.red, uValue.Color.green, uValue.Color.blue, uValue.Color.alpha, uValue.u);
1215 break;
1216
1217 case 'e': //SVGA3dTextureAddress
1218 {
1219 static const char * const s_apszValues[] =
1220 {
1221 "INVALID", "WRAP", "MIRROR", "CLAMP", "BORDER", "MIRRORONCE", "EDGE",
1222 };
1223 vmsvgaFormatEnumValue(pszBuffer, cbBuffer, pszName, uValue.u,
1224 "SVGA3D_TEX_ADDRESS_", s_apszValues, RT_ELEMENTS(s_apszValues));
1225 break;
1226 }
1227
1228 case 'l': //SVGA3dTextureFilter
1229 {
1230 static const char * const s_apszValues[] =
1231 {
1232 "NONE", "NEAREST", "LINEAR", "ANISOTROPIC", "FLATCUBIC", "GAUSSIANCUBIC", "PYRAMIDALQUAD", "GAUSSIANQUAD",
1233 };
1234 vmsvgaFormatEnumValue(pszBuffer, cbBuffer, pszName, uValue.u,
1235 "SVGA3D_TEX_FILTER_", s_apszValues, RT_ELEMENTS(s_apszValues));
1236 break;
1237 }
1238
1239 case 'g': //SVGA3dTextureCoordGen
1240 {
1241 static const char * const s_apszValues[] =
1242 {
1243 "OFF", "EYE_POSITION", "EYE_NORMAL", "REFLECTIONVECTOR", "SPHERE",
1244 };
1245 vmsvgaFormatEnumValue(pszBuffer, cbBuffer, pszName, uValue.u,
1246 "SVGA3D_TEXCOORD_GEN_", s_apszValues, RT_ELEMENTS(s_apszValues));
1247 break;
1248 }
1249
1250 case 'm': //SVGA3dTextureCombiner
1251 {
1252 static const char * const s_apszValues[] =
1253 {
1254 "INVALID", "DISABLE", "SELECTARG1", "SELECTARG2", "MODULATE", "ADD", "ADDSIGNED", "SUBTRACT",
1255 "BLENDTEXTUREALPHA", "BLENDDIFFUSEALPHA", "BLENDCURRENTALPHA", "BLENDFACTORALPHA", "MODULATE2X",
1256 "MODULATE4X", "DSDT", "DOTPRODUCT3", "BLENDTEXTUREALPHAPM", "ADDSIGNED2X", "ADDSMOOTH", "PREMODULATE",
1257 "MODULATEALPHA_ADDCOLOR", "MODULATECOLOR_ADDALPHA", "MODULATEINVALPHA_ADDCOLOR",
1258 "MODULATEINVCOLOR_ADDALPHA", "BUMPENVMAPLUMINANCE", "MULTIPLYADD", "LERP",
1259 };
1260 vmsvgaFormatEnumValue(pszBuffer, cbBuffer, pszName, uValue.u,
1261 "SVGA3D_TC_", s_apszValues, RT_ELEMENTS(s_apszValues));
1262 break;
1263 }
1264
1265 default:
1266 AssertFailed();
1267 RTStrPrintf(pszBuffer, cbBuffer, "%s = %#x\n", pszName, uValue.u);
1268 break;
1269 }
1270 }
1271 else
1272 RTStrPrintf(pszBuffer, cbBuffer, "UNKNOWN_%d_%#x = %#x\n", iName, iName, pTextureState->value);
1273 }
1274 else
1275 RTStrPrintf(pszBuffer, cbBuffer, "INVALID");
1276 return pszRet;
1277}
1278
1279
1280
1281static const char * const g_apszTransformTypes[] =
1282{
1283 "SVGA3D_TRANSFORM_INVALID",
1284 "SVGA3D_TRANSFORM_WORLD",
1285 "SVGA3D_TRANSFORM_VIEW",
1286 "SVGA3D_TRANSFORM_PROJECTION",
1287 "SVGA3D_TRANSFORM_TEXTURE0",
1288 "SVGA3D_TRANSFORM_TEXTURE1",
1289 "SVGA3D_TRANSFORM_TEXTURE2",
1290 "SVGA3D_TRANSFORM_TEXTURE3",
1291 "SVGA3D_TRANSFORM_TEXTURE4",
1292 "SVGA3D_TRANSFORM_TEXTURE5",
1293 "SVGA3D_TRANSFORM_TEXTURE6",
1294 "SVGA3D_TRANSFORM_TEXTURE7",
1295 "SVGA3D_TRANSFORM_WORLD1",
1296 "SVGA3D_TRANSFORM_WORLD2",
1297 "SVGA3D_TRANSFORM_WORLD3",
1298};
1299
1300static const char * const g_apszFaces[] =
1301{
1302 "SVGA3D_FACE_INVALID",
1303 "SVGA3D_FACE_NONE",
1304 "SVGA3D_FACE_FRONT",
1305 "SVGA3D_FACE_BACK",
1306 "SVGA3D_FACE_FRONT_BACK",
1307};
1308
1309static const char * const g_apszLightTypes[] =
1310{
1311 "SVGA3D_LIGHTTYPE_INVALID",
1312 "SVGA3D_LIGHTTYPE_POINT",
1313 "SVGA3D_LIGHTTYPE_SPOT1",
1314 "SVGA3D_LIGHTTYPE_SPOT2",
1315 "SVGA3D_LIGHTTYPE_DIRECTIONAL",
1316};
1317
1318static const char * const g_apszRenderTargets[] =
1319{
1320 "SVGA3D_RT_DEPTH",
1321 "SVGA3D_RT_STENCIL",
1322 "SVGA3D_RT_COLOR0",
1323 "SVGA3D_RT_COLOR1",
1324 "SVGA3D_RT_COLOR2",
1325 "SVGA3D_RT_COLOR3",
1326 "SVGA3D_RT_COLOR4",
1327 "SVGA3D_RT_COLOR5",
1328 "SVGA3D_RT_COLOR6",
1329 "SVGA3D_RT_COLOR7",
1330};
1331
1332static void vmsvga3dInfoContextWorkerOne(PCDBGFINFOHLP pHlp, PVMSVGA3DCONTEXT pContext, bool fVerbose)
1333{
1334 RT_NOREF(fVerbose);
1335 char szTmp[128];
1336
1337 pHlp->pfnPrintf(pHlp, "*** VMSVGA 3d context %#x (%d) ***\n", pContext->id, pContext->id);
1338#ifdef RT_OS_WINDOWS
1339 pHlp->pfnPrintf(pHlp, "hwnd: %p\n", pContext->hwnd);
1340 if (fVerbose)
1341 vmsvga3dInfoHostWindow(pHlp, (uintptr_t)pContext->hwnd);
1342# ifdef VMSVGA3D_DIRECT3D
1343 pHlp->pfnPrintf(pHlp, "pDevice: %p\n", pContext->pDevice);
1344# else
1345 pHlp->pfnPrintf(pHlp, "hdc: %p\n", pContext->hdc);
1346 pHlp->pfnPrintf(pHlp, "hglrc: %p\n", pContext->hglrc);
1347# endif
1348
1349#elif defined(RT_OS_DARWIN)
1350 pHlp->pfnPrintf(pHlp, "cocoaView: %p\n", pContext->cocoaView);
1351 if (pContext->cocoaView)
1352 vmsvga3dInfoHostWindow(pHlp, (uintptr_t)pContext->cocoaView);
1353 pHlp->pfnPrintf(pHlp, "cocoaContext: %p\n", pContext->cocoaContext);
1354 if (pContext->fOtherProfile)
1355 pHlp->pfnPrintf(pHlp, "fOtherProfile: true\n");
1356
1357#else
1358 pHlp->pfnPrintf(pHlp, "window: %p\n", pContext->window);
1359 if (pContext->window)
1360 vmsvga3dInfoHostWindow(pHlp, (uintptr_t)pContext->window);
1361 pHlp->pfnPrintf(pHlp, "glxContext: %p\n", pContext->glxContext);
1362
1363#endif
1364
1365 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); i++)
1366 if (pContext->aSidActiveTextures[i] != SVGA3D_INVALID_ID)
1367 pHlp->pfnPrintf(pHlp, "aSidActiveTextures[%u]: %#x\n", i, pContext->aSidActiveTextures[i]);
1368
1369 pHlp->pfnPrintf(pHlp, "fUpdateFlags: %#x\n", pContext->state.u32UpdateFlags);
1370
1371 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderState); i++)
1372 if (pContext->state.aRenderState[i].state != SVGA3D_RS_INVALID)
1373 pHlp->pfnPrintf(pHlp, "aRenderState[%3d]: %s\n", i,
1374 vmsvga3dFormatRenderState(szTmp, sizeof(szTmp), &pContext->state.aRenderState[i]));
1375
1376 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aTextureStates); i++)
1377 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTextureStates[i]); j++)
1378 if (pContext->state.aTextureStates[i][j].name != SVGA3D_TS_INVALID)
1379 pHlp->pfnPrintf(pHlp, "aTextureStates[%3d][%3d]: %s\n", i, j,
1380 vmsvga3dFormatTextureState(szTmp, sizeof(szTmp), &pContext->state.aTextureStates[i][j]));
1381
1382 AssertCompile(RT_ELEMENTS(g_apszTransformTypes) == SVGA3D_TRANSFORM_MAX);
1383 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aTransformState); i++)
1384 if (pContext->state.aTransformState[i].fValid)
1385 {
1386 pHlp->pfnPrintf(pHlp, "aTransformState[%s(%u)]:\n", g_apszTransformTypes[i], i);
1387 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState[i].matrix); j++)
1388 pHlp->pfnPrintf(pHlp,
1389 (j % 4) == 0 ? " [ " FLOAT_FMT_STR : (j % 4) < 3 ? ", " FLOAT_FMT_STR : ", " FLOAT_FMT_STR "]\n",
1390 FLOAT_FMT_ARGS(pContext->state.aTransformState[i].matrix[j]));
1391 }
1392
1393 AssertCompile(RT_ELEMENTS(g_apszFaces) == SVGA3D_FACE_MAX);
1394 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aMaterial); i++)
1395 if (pContext->state.aMaterial[i].fValid)
1396 {
1397 pHlp->pfnPrintf(pHlp, "aTransformState[%s(%u)]: shininess=" FLOAT_FMT_STR "\n",
1398 g_apszFaces[i], i, FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.shininess));
1399 pHlp->pfnPrintf(pHlp, " diffuse =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1400 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.diffuse[0]),
1401 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.diffuse[1]),
1402 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.diffuse[2]),
1403 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.diffuse[3]));
1404 pHlp->pfnPrintf(pHlp, " ambient =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1405 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.ambient[0]),
1406 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.ambient[1]),
1407 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.ambient[2]),
1408 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.ambient[3]));
1409 pHlp->pfnPrintf(pHlp, " specular=[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1410 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.specular[0]),
1411 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.specular[1]),
1412 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.specular[2]),
1413 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.specular[3]));
1414 pHlp->pfnPrintf(pHlp, " emissive=[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1415 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.emissive[0]),
1416 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.emissive[1]),
1417 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.emissive[2]),
1418 FLOAT_FMT_ARGS(pContext->state.aMaterial[i].material.emissive[3]));
1419 }
1420
1421 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aClipPlane); i++)
1422 if (pContext->state.aClipPlane[i].fValid)
1423 pHlp->pfnPrintf(pHlp, "aClipPlane[%#04x]: [ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1424 i,
1425 FLOAT_FMT_ARGS(pContext->state.aClipPlane[i].plane[0]),
1426 FLOAT_FMT_ARGS(pContext->state.aClipPlane[i].plane[1]),
1427 FLOAT_FMT_ARGS(pContext->state.aClipPlane[i].plane[2]),
1428 FLOAT_FMT_ARGS(pContext->state.aClipPlane[i].plane[3]));
1429
1430 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aLightData); i++)
1431 if (pContext->state.aLightData[i].fValidData)
1432 {
1433 pHlp->pfnPrintf(pHlp, "aLightData[%#04x]: enabled=%RTbool inWorldSpace=%RTbool type=%s(%u)\n",
1434 i,
1435 pContext->state.aLightData[i].fEnabled,
1436 pContext->state.aLightData[i].data.inWorldSpace,
1437 (uint32_t)pContext->state.aLightData[i].data.type < RT_ELEMENTS(g_apszLightTypes)
1438 ? g_apszLightTypes[pContext->state.aLightData[i].data.type] : "UNKNOWN",
1439 pContext->state.aLightData[i].data.type);
1440 pHlp->pfnPrintf(pHlp, " diffuse =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1441 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.diffuse[0]),
1442 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.diffuse[1]),
1443 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.diffuse[2]),
1444 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.diffuse[3]));
1445 pHlp->pfnPrintf(pHlp, " specular =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1446 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.specular[0]),
1447 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.specular[1]),
1448 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.specular[2]),
1449 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.specular[3]));
1450 pHlp->pfnPrintf(pHlp, " ambient =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1451 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.ambient[0]),
1452 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.ambient[1]),
1453 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.ambient[2]),
1454 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.ambient[3]));
1455 pHlp->pfnPrintf(pHlp, " position =[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1456 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.position[0]),
1457 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.position[1]),
1458 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.position[2]),
1459 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.position[3]));
1460 pHlp->pfnPrintf(pHlp, " direction=[ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " ]\n",
1461 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.direction[0]),
1462 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.direction[1]),
1463 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.direction[2]),
1464 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.direction[3]));
1465 pHlp->pfnPrintf(pHlp, " range=" FLOAT_FMT_STR " falloff=" FLOAT_FMT_STR "\n",
1466 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.range),
1467 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.falloff));
1468 pHlp->pfnPrintf(pHlp, " attenuation0=" FLOAT_FMT_STR " attenuation1=" FLOAT_FMT_STR " attenuation2=" FLOAT_FMT_STR "\n",
1469 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.attenuation0),
1470 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.attenuation1),
1471 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.attenuation2));
1472 pHlp->pfnPrintf(pHlp, " theta=" FLOAT_FMT_STR " phi=" FLOAT_FMT_STR "\n",
1473 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.theta),
1474 FLOAT_FMT_ARGS(pContext->state.aLightData[i].data.phi));
1475 }
1476
1477 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); i++)
1478 if (pContext->state.aRenderTargets[i] != SVGA3D_INVALID_ID)
1479 pHlp->pfnPrintf(pHlp, "aRenderTargets[%s/%u] = %#x (%d)\n",
1480 i < RT_ELEMENTS(g_apszRenderTargets) ? g_apszRenderTargets[i] : "UNKNOWN", i,
1481 pContext->state.aRenderTargets[i], pContext->state.aRenderTargets[i]);
1482
1483 pHlp->pfnPrintf(pHlp, "RectScissor: (x,y,cx,cy)=(%u,%u,%u,%u)\n",
1484 pContext->state.RectViewPort.x, pContext->state.RectViewPort.y,
1485 pContext->state.RectViewPort.w, pContext->state.RectViewPort.h);
1486 pHlp->pfnPrintf(pHlp, "zRange: (min,max)=(" FLOAT_FMT_STR ", " FLOAT_FMT_STR ")\n",
1487 FLOAT_FMT_ARGS(pContext->state.zRange.min),
1488 FLOAT_FMT_ARGS(pContext->state.zRange.max));
1489 pHlp->pfnPrintf(pHlp, "fUpdateFlags: %#x\n", pContext->state.u32UpdateFlags);
1490 pHlp->pfnPrintf(pHlp, "shidPixel: %#x (%d)\n", pContext->state.shidPixel, pContext->state.shidPixel);
1491 pHlp->pfnPrintf(pHlp, "shidVertex: %#x (%d)\n", pContext->state.shidVertex, pContext->state.shidVertex);
1492
1493 for (uint32_t iWhich = 0; iWhich < 2; iWhich++)
1494 {
1495 uint32_t cConsts = iWhich == 0 ? pContext->state.cPixelShaderConst : pContext->state.cVertexShaderConst;
1496 PVMSVGASHADERCONST paConsts = iWhich == 0 ? pContext->state.paPixelShaderConst : pContext->state.paVertexShaderConst;
1497 const char *pszName = iWhich ? "paPixelShaderConst" : "paVertexShaderConst";
1498
1499 for (uint32_t i = 0; i < cConsts; i++)
1500 if (paConsts[i].fValid)
1501 {
1502 if (paConsts[i].ctype == SVGA3D_CONST_TYPE_FLOAT)
1503 pHlp->pfnPrintf(pHlp, "%s[%#x(%u)] = [" FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR "] ctype=FLOAT\n",
1504 pszName, i, i,
1505 FLOAT_FMT_ARGS(*(float *)&paConsts[i].value[0]), FLOAT_FMT_ARGS(*(float *)&paConsts[i].value[1]),
1506 FLOAT_FMT_ARGS(*(float *)&paConsts[i].value[2]), FLOAT_FMT_ARGS(*(float *)&paConsts[i].value[3]));
1507 else
1508 pHlp->pfnPrintf(pHlp, "%s[%#x(%u)] = [%#x, %#x, %#x, %#x] ctype=%s\n",
1509 pszName, i, i,
1510 paConsts[i].value[0], paConsts[i].value[1],
1511 paConsts[i].value[2], paConsts[i].value[3],
1512 paConsts[i].ctype == SVGA3D_CONST_TYPE_INT ? "INT"
1513 : paConsts[i].ctype == SVGA3D_CONST_TYPE_BOOL ? "BOOL" : "UNKNOWN");
1514 }
1515 }
1516
1517 for (uint32_t iWhich = 0; iWhich < 2; iWhich++)
1518 {
1519 uint32_t cShaders = iWhich == 0 ? pContext->cPixelShaders : pContext->cVertexShaders;
1520 PVMSVGA3DSHADER paShaders = iWhich == 0 ? pContext->paPixelShader : pContext->paVertexShader;
1521 const char *pszName = iWhich == 0 ? "paPixelShaders" : "paVertexShaders";
1522 for (uint32_t i = 0; i < cShaders; i++)
1523 if (paShaders[i].id == i)
1524 {
1525 pHlp->pfnPrintf(pHlp, "%s[%u]: id=%#x cid=%#x type=%s(%d) cbData=%#x pvData=%p\n",
1526 pszName, i,
1527 paShaders[i].id,
1528 paShaders[i].cid,
1529 paShaders[i].type == SVGA3D_SHADERTYPE_VS ? "VS"
1530 : paShaders[i].type == SVGA3D_SHADERTYPE_PS ? "PS" : "UNKNOWN",
1531 paShaders[i].type,
1532 paShaders[i].cbData,
1533 paShaders[i].pShaderProgram);
1534 }
1535 }
1536}
1537
1538
1539void vmsvga3dInfoContextWorker(PVGASTATECC pThisCC, PCDBGFINFOHLP pHlp, uint32_t cid, bool fVerbose)
1540{
1541 /* Warning! This code is currently racing papContexts reallocation! */
1542 /* Warning! This code is currently racing papContexts reallocation! */
1543 /* Warning! This code is currently racing papContexts reallocation! */
1544 VMSVGA3DSTATE volatile *pState = pThisCC->svga.p3dState;
1545 if (pState)
1546 {
1547 /*
1548 * Deal with a specific request first.
1549 */
1550 if (cid != UINT32_MAX)
1551 {
1552 if (cid < pState->cContexts)
1553 {
1554 PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
1555 if (pContext && pContext->id == cid)
1556 {
1557 vmsvga3dInfoContextWorkerOne(pHlp, pContext, fVerbose);
1558 return;
1559 }
1560 }
1561#ifdef VMSVGA3D_OPENGL
1562 else if ( cid == VMSVGA3D_SHARED_CTX_ID
1563 && pState->SharedCtx.id == cid)
1564 {
1565 vmsvga3dInfoContextWorkerOne(pHlp, &((PVMSVGA3DSTATE)pState)->SharedCtx, fVerbose);
1566 return;
1567 }
1568#endif
1569 pHlp->pfnPrintf(pHlp, "Context ID %#x not found.\n", cid);
1570 }
1571 else
1572 {
1573#ifdef VMSVGA3D_OPENGL
1574 /*
1575 * Dump the shared context.
1576 */
1577 if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID)
1578 {
1579 pHlp->pfnPrintf(pHlp, "Shared context:\n");
1580 vmsvga3dInfoContextWorkerOne(pHlp, &((PVMSVGA3DSTATE)pState)->SharedCtx, fVerbose);
1581 }
1582#endif
1583
1584 /*
1585 * Dump the per-screen contexts.
1586 */
1587 /** @todo multi screen */
1588
1589 /*
1590 * Dump all.
1591 */
1592 uint32_t cContexts = pState->cContexts;
1593 pHlp->pfnPrintf(pHlp, "cContexts=%d\n", cContexts);
1594 for (cid = 0; cid < cContexts; cid++)
1595 {
1596 PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
1597 if (pContext && pContext->id == cid)
1598 {
1599 pHlp->pfnPrintf(pHlp, "\n");
1600 vmsvga3dInfoContextWorkerOne(pHlp, pContext, fVerbose);
1601 }
1602 }
1603 }
1604 }
1605}
1606
1607
1608#ifdef VMSVGA3D_DIRECT3D
1609/**
1610 * Release all shared surface objects.
1611 */
1612static DECLCALLBACK(int) vmsvga3dInfoSharedObjectCallback(PAVLU32NODECORE pNode, void *pvUser)
1613{
1614 PVMSVGA3DSHAREDSURFACE pSharedSurface = (PVMSVGA3DSHAREDSURFACE)pNode;
1615 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
1616
1617 pHlp->pfnPrintf(pHlp, "Shared surface: %#x pv=%p\n", pSharedSurface->Core.Key, pSharedSurface->u.pCubeTexture);
1618
1619 return 0;
1620}
1621#endif /* VMSVGA3D_DIRECT3D */
1622
1623static int vmsvga3dInfoBmpWrite(const char *pszFilename, const void *pvBits, int w, int h, uint32_t cbPixel, uint32_t u32Mask)
1624{
1625 if ( cbPixel != 4
1626 && cbPixel != 2
1627 && cbPixel != 1)
1628 return VERR_NOT_SUPPORTED;
1629
1630 /* Always write BGRX bitmap for now. */
1631 const int cbBitmap = w * h * 4;
1632
1633 FILE *f = fopen(pszFilename, "wb");
1634 if (!f)
1635 return VERR_FILE_NOT_FOUND;
1636
1637#ifdef RT_OS_WINDOWS
1638 if (cbPixel == 4)
1639 {
1640 BMPFILEHDR fileHdr;
1641 RT_ZERO(fileHdr);
1642 fileHdr.uType = BMP_HDR_MAGIC;
1643 fileHdr.cbFileSize = sizeof(fileHdr) + sizeof(BITMAPV4HEADER) + cbBitmap;
1644 fileHdr.offBits = sizeof(fileHdr) + sizeof(BITMAPV4HEADER);
1645
1646 BITMAPV4HEADER hdrV4;
1647 RT_ZERO(hdrV4);
1648 hdrV4.bV4Size = sizeof(hdrV4);
1649 hdrV4.bV4Width = w;
1650 hdrV4.bV4Height = -h;
1651 hdrV4.bV4Planes = 1;
1652 hdrV4.bV4BitCount = 32;
1653 hdrV4.bV4V4Compression = BI_BITFIELDS;
1654 hdrV4.bV4SizeImage = cbBitmap;
1655 hdrV4.bV4XPelsPerMeter = 2835;
1656 hdrV4.bV4YPelsPerMeter = 2835;
1657 // hdrV4.bV4ClrUsed = 0;
1658 // hdrV4.bV4ClrImportant = 0;
1659 hdrV4.bV4RedMask = 0x00ff0000;
1660 hdrV4.bV4GreenMask = 0x0000ff00;
1661 hdrV4.bV4BlueMask = 0x000000ff;
1662 hdrV4.bV4AlphaMask = 0xff000000;
1663 hdrV4.bV4CSType = LCS_WINDOWS_COLOR_SPACE;
1664 // hdrV4.bV4Endpoints = {0};
1665 // hdrV4.bV4GammaRed = 0;
1666 // hdrV4.bV4GammaGreen = 0;
1667 // hdrV4.bV4GammaBlue = 0;
1668
1669 fwrite(&fileHdr, 1, sizeof(fileHdr), f);
1670 fwrite(&hdrV4, 1, sizeof(hdrV4), f);
1671 }
1672 else
1673#endif
1674 {
1675 BMPFILEHDR fileHdr;
1676 RT_ZERO(fileHdr);
1677 fileHdr.uType = BMP_HDR_MAGIC;
1678 fileHdr.cbFileSize = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR) + cbBitmap;
1679 fileHdr.offBits = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR);
1680
1681 BMPWIN3XINFOHDR coreHdr;
1682 RT_ZERO(coreHdr);
1683 coreHdr.cbSize = sizeof(coreHdr);
1684 coreHdr.uWidth = w;
1685 coreHdr.uHeight = -h;
1686 coreHdr.cPlanes = 1;
1687 coreHdr.cBits = 32;
1688 coreHdr.cbSizeImage = cbBitmap;
1689
1690 fwrite(&fileHdr, 1, sizeof(fileHdr), f);
1691 fwrite(&coreHdr, 1, sizeof(coreHdr), f);
1692 }
1693
1694 if (cbPixel == 4)
1695 {
1696 const uint32_t *s = (uint32_t *)pvBits;
1697 int i;
1698 for (i = 0; i < w * h; ++i)
1699 {
1700 const uint32_t u32 = *s++;
1701 uint32_t u = u32 & u32Mask;
1702 fwrite(&u, 1, 4, f);
1703 }
1704 }
1705 else if (cbPixel == 2)
1706 {
1707 const uint16_t *s = (uint16_t *)pvBits;
1708 int i;
1709 for (i = 0; i < w * h; ++i)
1710 {
1711 const uint16_t u16 = *s++;
1712 uint32_t u32 = u16;
1713 uint32_t u = u32 & u32Mask;
1714 fwrite(&u, 1, 4, f);
1715 }
1716 }
1717 else if (cbPixel == 1)
1718 {
1719 const uint8_t *s = (uint8_t *)pvBits;
1720 int i;
1721 for (i = 0; i < w * h; ++i)
1722 {
1723 const uint8_t u8 = *s++;
1724 uint32_t u32 = u8 * 0x10000 + u8 * 0x100 + u8;
1725 uint32_t u = u32 & u32Mask;
1726 fwrite(&u, 1, 4, f);
1727 }
1728 }
1729
1730 fclose(f);
1731
1732 return VINF_SUCCESS;
1733}
1734
1735void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1736 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix)
1737{
1738 static volatile uint32_t sSeq = 0;
1739 const uint32_t u32Seq = ASMAtomicIncU32(&sSeq);
1740
1741 for (uint32_t i = 0; i < pSurface->cLevels; ++i)
1742 {
1743 if (!pSurface->paMipmapLevels[i].pSurfaceData)
1744 continue;
1745
1746 char szFilepath[4096];
1747 RTStrPrintf(szFilepath, sizeof(szFilepath),
1748 "%s" RTPATH_SLASH_STR "%s-%u-sid%u-%u%s.bmp",
1749 pszPath, pszNamePrefix, u32Seq, pSurface->id, i, pszNameSuffix);
1750
1751 const uint32_t cbPixel = vmsvga3dSurfaceFormatSize(pSurface->format, NULL, NULL);
1752 int rc = vmsvga3dInfoBmpWrite(szFilepath,
1753 pSurface->paMipmapLevels[i].pSurfaceData,
1754 pSurface->paMipmapLevels[i].mipmapSize.width,
1755 pSurface->paMipmapLevels[i].mipmapSize.height,
1756 cbPixel, 0xFFFFFFFF);
1757 if (RT_SUCCESS(rc))
1758 {
1759 Log(("Bitmap: %s\n", szFilepath));
1760 if (pHlp)
1761 pHlp->pfnPrintf(pHlp, "Bitmap: %s\n", szFilepath);
1762 }
1763 else
1764 {
1765 Log(("Bitmap: %s %Rrc\n", szFilepath, rc));
1766 if (pHlp)
1767 pHlp->pfnPrintf(pHlp, "Bitmap: %s %Rrc\n", szFilepath, rc);
1768 }
1769 }
1770
1771#if 0
1772 /* Alpha channel alone. */
1773 RTStrPrintf(szFilepath, sizeof(szFilepath),
1774 "%s\\%s-%u-sid%u%s-a.bmp",
1775 pszPath, pszNamePrefix, u32Seq, pSurface->id, pszNameSuffix);
1776 vmsvga3dInfoBmpWrite(szFilepath,
1777 pSurface->paMipmapLevels[0].pSurfaceData,
1778 pSurface->paMipmapLevels[0].mipmapSize.width,
1779 pSurface->paMipmapLevels[0].mipmapSize.height,
1780 cbPixel, 0xFF000000);
1781#endif
1782}
1783
1784static void vmsvga3dInfoSurfaceWorkerOne(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
1785 bool fVerbose, uint32_t cxAscii, bool fInvY)
1786{
1787 char szTmp[128];
1788
1789 pHlp->pfnPrintf(pHlp, "*** VMSVGA 3d surface %#x (%d)%s ***\n", pSurface->id, pSurface->id, pSurface->fDirty ? " - dirty" : "");
1790 pHlp->pfnPrintf(pHlp, "idAssociatedContext: %#x\n", pSurface->idAssociatedContext);
1791 pHlp->pfnPrintf(pHlp, "Format: %s\n",
1792 vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, (int)pSurface->format, false, &g_SVGA3dSurfaceFormat2String));
1793 pHlp->pfnPrintf(pHlp, "Flags: 0x%RX64", pSurface->f.surfaceFlags);
1794 vmsvga3dInfoU32Flags(pHlp, pSurface->f.s.surface1Flags, "SVGA3D_SURFACE_", g_aSvga3DSurfaceFlags, RT_ELEMENTS(g_aSvga3DSurfaceFlags));
1795 pHlp->pfnPrintf(pHlp, "\n");
1796 if (pSurface->cFaces != 0)
1797 pHlp->pfnPrintf(pHlp, "Faces: %u\n", pSurface->cFaces);
1798 if (pSurface->cLevels != 0)
1799 pHlp->pfnPrintf(pHlp, "Mipmap levels: %u\n", pSurface->cLevels);
1800 for (uint32_t iFace = 0; iFace < pSurface->cFaces; iFace++)
1801 {
1802 uint32_t iMipmap = iFace * pSurface->cLevels;
1803 for (uint32_t iLevel = 0; iLevel < pSurface->cLevels; iLevel++, iMipmap++)
1804 {
1805 pHlp->pfnPrintf(pHlp, "Face #%u, mipmap #%u[%u]:%s cx=%u, cy=%u, cz=%u, cbSurface=%#x, cbPitch=%#x",
1806 iFace, iLevel, iMipmap, iMipmap < 10 ? " " : "",
1807 pSurface->paMipmapLevels[iMipmap].mipmapSize.width,
1808 pSurface->paMipmapLevels[iMipmap].mipmapSize.height,
1809 pSurface->paMipmapLevels[iMipmap].mipmapSize.depth,
1810 pSurface->paMipmapLevels[iMipmap].cbSurface,
1811 pSurface->paMipmapLevels[iMipmap].cbSurfacePitch);
1812 if (pSurface->paMipmapLevels[iMipmap].pSurfaceData)
1813 pHlp->pfnPrintf(pHlp, " pvData=%p", pSurface->paMipmapLevels[iMipmap].pSurfaceData);
1814 if (pSurface->paMipmapLevels[iMipmap].fDirty)
1815 pHlp->pfnPrintf(pHlp, " dirty");
1816 pHlp->pfnPrintf(pHlp, "\n");
1817 }
1818 }
1819
1820 pHlp->pfnPrintf(pHlp, "cbBlock: %u (%#x)\n", pSurface->cbBlock, pSurface->cbBlock);
1821 pHlp->pfnPrintf(pHlp, "Multi-sample count: %u\n", pSurface->multiSampleCount);
1822 pHlp->pfnPrintf(pHlp, "Autogen filter: %s\n",
1823 vmsvgaFormatEnumValue(szTmp, sizeof(szTmp), NULL, pSurface->autogenFilter,
1824 "SVGA3D_TEX_FILTER_", g_apszTexureFilters, RT_ELEMENTS(g_apszTexureFilters)));
1825
1826#ifdef VMSVGA3D_DIRECT3D
1827 pHlp->pfnPrintf(pHlp, "formatD3D: %s\n",
1828 vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, pSurface->formatD3D, true, &g_D3DFormat2String));
1829 pHlp->pfnPrintf(pHlp, "fUsageD3D: %#x", pSurface->fUsageD3D);
1830 vmsvga3dInfoU32Flags(pHlp, pSurface->fUsageD3D, "D3DUSAGE_", g_aD3DUsageFlags, RT_ELEMENTS(g_aD3DUsageFlags));
1831 pHlp->pfnPrintf(pHlp, "\n");
1832 pHlp->pfnPrintf(pHlp, "multiSampleTypeD3D: %s\n",
1833 vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, pSurface->multiSampleTypeD3D,
1834 true, &g_D3DMultiSampleType2String));
1835 if (pSurface->hSharedObject != NULL)
1836 pHlp->pfnPrintf(pHlp, "hSharedObject: %p\n", pSurface->hSharedObject);
1837 if (pSurface->pQuery)
1838 pHlp->pfnPrintf(pHlp, "pQuery: %p\n", pSurface->pQuery);
1839 if (pSurface->u.pSurface)
1840 pHlp->pfnPrintf(pHlp, "u.pXxxx: %p\n", pSurface->u.pSurface);
1841 if (pSurface->bounce.pTexture)
1842 pHlp->pfnPrintf(pHlp, "bounce.pXxxx: %p\n", pSurface->bounce.pTexture);
1843 RTAvlU32DoWithAll(&pSurface->pSharedObjectTree, true /*fFromLeft*/, vmsvga3dInfoSharedObjectCallback, (void *)pHlp);
1844 pHlp->pfnPrintf(pHlp, "fStencilAsTexture: %RTbool\n", pSurface->fStencilAsTexture);
1845
1846#elif defined(VMSVGA3D_OPENGL)
1847 /** @todo */
1848#else
1849# error "Build config error."
1850#endif
1851
1852 if (fVerbose)
1853 for (uint32_t iFace = 0; iFace < pSurface->cFaces; iFace++)
1854 {
1855 uint32_t iMipmap = iFace * pSurface->cLevels;
1856 for (uint32_t iLevel = 0; iLevel < pSurface->cLevels; iLevel++, iMipmap++)
1857 if (pSurface->paMipmapLevels[iMipmap].pSurfaceData)
1858 {
1859 if (ASMMemIsZero(pSurface->paMipmapLevels[iMipmap].pSurfaceData,
1860 pSurface->paMipmapLevels[iMipmap].cbSurface))
1861 pHlp->pfnPrintf(pHlp, "--- Face #%u, mipmap #%u[%u]: all zeros ---\n", iFace, iLevel, iMipmap);
1862 else
1863 {
1864 pHlp->pfnPrintf(pHlp, "--- Face #%u, mipmap #%u[%u]: cx=%u, cy=%u, cz=%u ---\n",
1865 iFace, iLevel, iMipmap,
1866 pSurface->paMipmapLevels[iMipmap].mipmapSize.width,
1867 pSurface->paMipmapLevels[iMipmap].mipmapSize.height,
1868 pSurface->paMipmapLevels[iMipmap].mipmapSize.depth);
1869 vmsvga3dAsciiPrint(vmsvga3dAsciiPrintlnInfo, (void *)pHlp,
1870 pSurface->paMipmapLevels[iMipmap].pSurfaceData,
1871 pSurface->paMipmapLevels[iMipmap].cbSurface,
1872 pSurface->paMipmapLevels[iMipmap].mipmapSize.width,
1873 pSurface->paMipmapLevels[iMipmap].mipmapSize.height,
1874 pSurface->paMipmapLevels[iMipmap].cbSurfacePitch,
1875 pSurface->format,
1876 fInvY,
1877 cxAscii, cxAscii * 3 / 4);
1878 }
1879 }
1880 }
1881}
1882
1883
1884void vmsvga3dInfoSurfaceWorker(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC, PCDBGFINFOHLP pHlp, uint32_t sid,
1885 bool fVerbose, uint32_t cxAscii, bool fInvY, const char *pszBitmapPath)
1886{
1887 /* Warning! This code is currently racing papSurfaces reallocation! */
1888 /* Warning! This code is currently racing papSurfaces reallocation! */
1889 /* Warning! This code is currently racing papSurfaces reallocation! */
1890 VMSVGA3DSTATE volatile *pState = pThisCC->svga.p3dState;
1891 if (pState)
1892 {
1893 /*
1894 * Deal with a specific request first.
1895 */
1896 if (sid != UINT32_MAX)
1897 {
1898 if (sid < pState->cSurfaces)
1899 {
1900 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
1901 if (pSurface && pSurface->id == sid)
1902 {
1903 if (fVerbose)
1904 vmsvgaR33dSurfaceUpdateHeapBuffersOnFifoThread(pDevIns, pThis, pThisCC, sid);
1905 vmsvga3dInfoSurfaceWorkerOne(pHlp, pSurface, fVerbose, cxAscii, fInvY);
1906 if (pszBitmapPath && *pszBitmapPath)
1907 vmsvga3dInfoSurfaceToBitmap(pHlp, pSurface, pszBitmapPath, "info", "");
1908 return;
1909 }
1910 }
1911 pHlp->pfnPrintf(pHlp, "Surface ID %#x not found.\n", sid);
1912 }
1913 else
1914 {
1915 /*
1916 * Dump all.
1917 */
1918 if (fVerbose)
1919 vmsvgaR33dSurfaceUpdateHeapBuffersOnFifoThread(pDevIns, pThis, pThisCC, UINT32_MAX);
1920 uint32_t cSurfaces = pState->cSurfaces;
1921 pHlp->pfnPrintf(pHlp, "cSurfaces=%d\n", cSurfaces);
1922 for (sid = 0; sid < cSurfaces; sid++)
1923 {
1924 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
1925 if (pSurface && pSurface->id == sid)
1926 {
1927 pHlp->pfnPrintf(pHlp, "\n");
1928 vmsvga3dInfoSurfaceWorkerOne(pHlp, pSurface, fVerbose, cxAscii, fInvY);
1929 }
1930 }
1931 }
1932 }
1933
1934}
1935
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette