VirtualBox

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

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

DevVGA: Splitting up the VMSVGASTATE structure. bugref:9218

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