VirtualBox

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

Last change on this file since 78293 was 77114, checked in by vboxsync, 6 years ago

DevVGA-SVGA3d-ogl: remember type of created resource; CopySurface/StretchBlt fixes; vmsvga3dBackSurfaceDMACopyBox support for 3D textures; occlusion query functions should set current context.

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