VirtualBox

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

Last change on this file since 69859 was 69859, checked in by vboxsync, 7 years ago

Devices/Graphics: VMSVGA: removed sidRenderTarget, because it does not work if the guest uses multiple render targets and render targets are already tracked anyway.

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