VirtualBox

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

Last change on this file since 82088 was 82053, checked in by vboxsync, 5 years ago

DevVGA: PDMR3Thread -> PDMDevHlpThread. bugref:9218

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

© 2023 Oracle
ContactPrivacy policyTerms of Use