VirtualBox

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

Last change on this file since 86898 was 86838, checked in by vboxsync, 4 years ago

Devices/Graphics: A couple of new commands; a more generic handler for creating a surface; cleaned saved state data for a surface; increased saved state version; possibility to build DX11 backend. bugref:9830

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