VirtualBox

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

Last change on this file since 69153 was 69153, checked in by vboxsync, 8 years ago

Devices/Graphics: VMSVGA: Initial support for volume textures. Remember the type of created D3D resource.

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

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