VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA-cmd.cpp@ 86855

Last change on this file since 86855 was 86855, checked in by vboxsync, 4 years ago

Devices/Graphics: Monitor the guest access to ObjectTables; use array of OTables; SVGA3D_DEVCAP logging. bugref:9830

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 147.0 KB
Line 
1/* $Id: DevVGA-SVGA-cmd.cpp 86855 2020-11-11 01:03:54Z vboxsync $ */
2/** @file
3 * VMware SVGA device - implementation of VMSVGA commands.
4 */
5
6/*
7 * Copyright (C) 2013-2020 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#ifndef IN_RING3
19# error "DevVGA-SVGA-cmd.cpp is only for ring-3 code"
20#endif
21
22
23#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
24#include <iprt/mem.h>
25#include <VBox/AssertGuest.h>
26#include <VBox/log.h>
27#include <VBox/vmm/pdmdev.h>
28#include <VBoxVideo.h>
29
30/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
31#include "DevVGA.h"
32
33/* Should be included after DevVGA.h/DevVGA-SVGA.h to pick all defines. */
34#include "DevVGA-SVGA-internal.h"
35#ifdef VBOX_WITH_VMSVGA3D
36# include "DevVGA-SVGA3d.h"
37#endif
38
39#ifdef DUMP_BITMAPS
40# include <iprt/formats/bmp.h>
41# include <stdio.h>
42#endif
43
44#if defined(LOG_ENABLED) || defined(VBOX_STRICT)
45# define SVGA_CASE_ID2STR(idx) case idx: return #idx
46/**
47 * FIFO command name lookup
48 *
49 * @returns FIFO command string or "UNKNOWN"
50 * @param u32Cmd FIFO command
51 */
52const char *vmsvgaR3FifoCmdToString(uint32_t u32Cmd)
53{
54 switch (u32Cmd)
55 {
56 SVGA_CASE_ID2STR(SVGA_CMD_INVALID_CMD);
57 SVGA_CASE_ID2STR(SVGA_CMD_UPDATE);
58 SVGA_CASE_ID2STR(SVGA_CMD_RECT_FILL);
59 SVGA_CASE_ID2STR(SVGA_CMD_RECT_COPY);
60 SVGA_CASE_ID2STR(SVGA_CMD_RECT_ROP_COPY);
61 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_CURSOR);
62 SVGA_CASE_ID2STR(SVGA_CMD_DISPLAY_CURSOR);
63 SVGA_CASE_ID2STR(SVGA_CMD_MOVE_CURSOR);
64 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_ALPHA_CURSOR);
65 SVGA_CASE_ID2STR(SVGA_CMD_UPDATE_VERBOSE);
66 SVGA_CASE_ID2STR(SVGA_CMD_FRONT_ROP_FILL);
67 SVGA_CASE_ID2STR(SVGA_CMD_FENCE);
68 SVGA_CASE_ID2STR(SVGA_CMD_ESCAPE);
69 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_SCREEN);
70 SVGA_CASE_ID2STR(SVGA_CMD_DESTROY_SCREEN);
71 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_GMRFB);
72 SVGA_CASE_ID2STR(SVGA_CMD_BLIT_GMRFB_TO_SCREEN);
73 SVGA_CASE_ID2STR(SVGA_CMD_BLIT_SCREEN_TO_GMRFB);
74 SVGA_CASE_ID2STR(SVGA_CMD_ANNOTATION_FILL);
75 SVGA_CASE_ID2STR(SVGA_CMD_ANNOTATION_COPY);
76 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_GMR2);
77 SVGA_CASE_ID2STR(SVGA_CMD_REMAP_GMR2);
78 SVGA_CASE_ID2STR(SVGA_CMD_DEAD);
79 SVGA_CASE_ID2STR(SVGA_CMD_DEAD_2);
80 SVGA_CASE_ID2STR(SVGA_CMD_NOP);
81 SVGA_CASE_ID2STR(SVGA_CMD_NOP_ERROR);
82 SVGA_CASE_ID2STR(SVGA_CMD_MAX);
83 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DEFINE);
84 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DESTROY);
85 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_COPY);
86 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_STRETCHBLT);
87 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DMA);
88 SVGA_CASE_ID2STR(SVGA_3D_CMD_CONTEXT_DEFINE);
89 SVGA_CASE_ID2STR(SVGA_3D_CMD_CONTEXT_DESTROY);
90 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETTRANSFORM);
91 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETZRANGE);
92 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETRENDERSTATE);
93 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETRENDERTARGET);
94 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETTEXTURESTATE);
95 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETMATERIAL);
96 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETLIGHTDATA);
97 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETLIGHTENABLED);
98 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETVIEWPORT);
99 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETCLIPPLANE);
100 SVGA_CASE_ID2STR(SVGA_3D_CMD_CLEAR);
101 SVGA_CASE_ID2STR(SVGA_3D_CMD_PRESENT);
102 SVGA_CASE_ID2STR(SVGA_3D_CMD_SHADER_DEFINE);
103 SVGA_CASE_ID2STR(SVGA_3D_CMD_SHADER_DESTROY);
104 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_SHADER);
105 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_SHADER_CONST);
106 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW_PRIMITIVES);
107 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETSCISSORRECT);
108 SVGA_CASE_ID2STR(SVGA_3D_CMD_BEGIN_QUERY);
109 SVGA_CASE_ID2STR(SVGA_3D_CMD_END_QUERY);
110 SVGA_CASE_ID2STR(SVGA_3D_CMD_WAIT_FOR_QUERY);
111 SVGA_CASE_ID2STR(SVGA_3D_CMD_PRESENT_READBACK);
112 SVGA_CASE_ID2STR(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN);
113 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DEFINE_V2);
114 SVGA_CASE_ID2STR(SVGA_3D_CMD_GENERATE_MIPMAPS);
115 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_CREATE_DECODER);
116 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_DESTROY_DECODER);
117 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_CREATE_PROCESSOR);
118 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_DESTROY_PROCESSOR);
119 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_DECODE_START_FRAME);
120 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_DECODE_RENDER);
121 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_DECODE_END_FRAME);
122 SVGA_CASE_ID2STR(SVGA_3D_CMD_VIDEO_PROCESS_FRAME);
123 SVGA_CASE_ID2STR(SVGA_3D_CMD_ACTIVATE_SURFACE);
124 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEACTIVATE_SURFACE);
125 SVGA_CASE_ID2STR(SVGA_3D_CMD_SCREEN_DMA);
126 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD1);
127 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD2);
128 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_BITBLT);
129 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_TRANSBLT);
130 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_STRETCHBLT);
131 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_COLORFILL);
132 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_ALPHABLEND);
133 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND);
134 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_OTABLE_BASE);
135 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_OTABLE);
136 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_MOB);
137 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_MOB);
138 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD3);
139 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING);
140 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE);
141 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SURFACE);
142 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SURFACE);
143 SVGA_CASE_ID2STR(SVGA_3D_CMD_COND_BIND_GB_SURFACE);
144 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_IMAGE);
145 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_SURFACE);
146 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_IMAGE);
147 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_SURFACE);
148 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_IMAGE);
149 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_SURFACE);
150 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_CONTEXT);
151 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_CONTEXT);
152 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_CONTEXT);
153 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_CONTEXT);
154 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_CONTEXT);
155 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SHADER);
156 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SHADER);
157 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SHADER);
158 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_OTABLE_BASE64);
159 SVGA_CASE_ID2STR(SVGA_3D_CMD_BEGIN_GB_QUERY);
160 SVGA_CASE_ID2STR(SVGA_3D_CMD_END_GB_QUERY);
161 SVGA_CASE_ID2STR(SVGA_3D_CMD_WAIT_FOR_GB_QUERY);
162 SVGA_CASE_ID2STR(SVGA_3D_CMD_NOP);
163 SVGA_CASE_ID2STR(SVGA_3D_CMD_ENABLE_GART);
164 SVGA_CASE_ID2STR(SVGA_3D_CMD_DISABLE_GART);
165 SVGA_CASE_ID2STR(SVGA_3D_CMD_MAP_MOB_INTO_GART);
166 SVGA_CASE_ID2STR(SVGA_3D_CMD_UNMAP_GART_RANGE);
167 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SCREENTARGET);
168 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SCREENTARGET);
169 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SCREENTARGET);
170 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_SCREENTARGET);
171 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL);
172 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL);
173 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE);
174 SVGA_CASE_ID2STR(SVGA_3D_CMD_GB_SCREEN_DMA);
175 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH);
176 SVGA_CASE_ID2STR(SVGA_3D_CMD_GB_MOB_FENCE);
177 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE_V2);
178 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_MOB64);
179 SVGA_CASE_ID2STR(SVGA_3D_CMD_REDEFINE_GB_MOB64);
180 SVGA_CASE_ID2STR(SVGA_3D_CMD_NOP_ERROR);
181 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_STREAMS);
182 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_DECLS);
183 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_DIVISORS);
184 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW);
185 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW_INDEXED);
186 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_CONTEXT);
187 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_CONTEXT);
188 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_CONTEXT);
189 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_CONTEXT);
190 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_INVALIDATE_CONTEXT);
191 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER);
192 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SHADER_RESOURCES);
193 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SHADER);
194 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SAMPLERS);
195 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW);
196 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INDEXED);
197 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INSTANCED);
198 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED);
199 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_AUTO);
200 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_INPUT_LAYOUT);
201 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS);
202 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_INDEX_BUFFER);
203 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_TOPOLOGY);
204 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_RENDERTARGETS);
205 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_BLEND_STATE);
206 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE);
207 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_RASTERIZER_STATE);
208 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_QUERY);
209 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_QUERY);
210 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_QUERY);
211 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_QUERY_OFFSET);
212 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BEGIN_QUERY);
213 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_END_QUERY);
214 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_QUERY);
215 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_PREDICATION);
216 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SOTARGETS);
217 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VIEWPORTS);
218 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SCISSORRECTS);
219 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW);
220 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW);
221 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_COPY_REGION);
222 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_COPY);
223 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_STRETCHBLT);
224 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_GENMIPS);
225 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE);
226 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_SUBRESOURCE);
227 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE);
228 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW);
229 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW);
230 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW);
231 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW);
232 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW);
233 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW);
234 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT);
235 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT);
236 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_BLEND_STATE);
237 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_BLEND_STATE);
238 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE);
239 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE);
240 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE);
241 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE);
242 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE);
243 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE);
244 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SHADER);
245 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SHADER);
246 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_SHADER);
247 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT);
248 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT);
249 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_STREAMOUTPUT);
250 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_COTABLE);
251 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_COTABLE);
252 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BUFFER_COPY);
253 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER);
254 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK);
255 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_MOVE_QUERY);
256 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_ALL_QUERY);
257 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_ALL_QUERY);
258 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER);
259 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_MOB_FENCE_64);
260 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_ALL_SHADER);
261 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_HINT);
262 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BUFFER_UPDATE);
263 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET);
264 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET);
265 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET);
266 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_RESERVED1);
267 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_RESERVED2);
268 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_RESERVED3);
269 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER);
270 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_MAX);
271 default: return "UNKNOWN";
272 }
273}
274# undef SVGA_CASE_ID2STR
275#endif /* LOG_ENABLED || VBOX_STRICT */
276
277
278#if !defined(VMSVGA3D_DX)
279# ifdef VBOX_WITH_VMSVGA3D
280/*
281 * Stubs for old backends.
282 */
283int vmsvga3dScreenTargetBind(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen, uint32_t sid)
284{
285 RT_NOREF(pThisCC, pScreen, sid);
286 return VERR_NOT_IMPLEMENTED;
287}
288
289int vmsvga3dScreenTargetUpdate(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen, SVGA3dRect const *pRect)
290{
291 RT_NOREF(pThisCC, pScreen, pRect);
292 return VERR_NOT_IMPLEMENTED;
293}
294
295int vmsvga3dSurfaceMap(PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pImage, SVGA3dBox const *pBox, VMSVGA3D_SURFACE_MAP enmMapType, VMSVGA3D_MAPPED_SURFACE *pMap)
296{
297 RT_NOREF(pThisCC, pImage, pBox, enmMapType, pMap);
298 return VERR_NOT_IMPLEMENTED;
299}
300
301int vmsvga3dSurfaceUnmap(PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pImage, VMSVGA3D_MAPPED_SURFACE *pMap, bool fWritten)
302{
303 RT_NOREF(pThisCC, pImage, pMap, fWritten);
304 return VERR_NOT_IMPLEMENTED;
305}
306# endif
307#endif
308
309
310/*
311 *
312 * Guest-Backed Objects (GBO).
313 *
314 */
315
316/**
317 * HC access handler for GBOs which require write protection, i.e. OTables, etc.
318 *
319 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
320 * @param pVM VM Handle.
321 * @param pVCpu The cross context CPU structure for the calling EMT.
322 * @param GCPhys The physical address the guest is writing to.
323 * @param pvPhys The HC mapping of that address.
324 * @param pvBuf What the guest is reading/writing.
325 * @param cbBuf How much it's reading/writing.
326 * @param enmAccessType The access type.
327 * @param enmOrigin Who is making the access.
328 * @param pvUser User argument.
329 */
330DECLCALLBACK(VBOXSTRICTRC)
331vmsvgaR3GboAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
332 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
333{
334 RT_NOREF(pVM, pVCpu, pvPhys, enmAccessType);
335
336 if (RT_LIKELY(enmOrigin == PGMACCESSORIGIN_DEVICE || enmOrigin == PGMACCESSORIGIN_DEBUGGER))
337 return VINF_PGM_HANDLER_DO_DEFAULT;
338
339 PPDMDEVINS pDevIns = (PPDMDEVINS)pvUser;
340 PVGASTATE pThis = PDMDEVINS_2_DATA(pDevIns, PVGASTATE);
341 PVGASTATECC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVGASTATECC);
342 PVMSVGAR3STATE pSvgaR3State = pThisCC->svga.pSvgaR3State;
343
344 /*
345 * The guest is not allowed to access the memory.
346 * Set the error condition.
347 */
348 ASMAtomicWriteBool(&pThis->svga.fBadGuest, true);
349
350 /* Try to find the GBO which the guest is accessing. */
351 char const *pszTarget = NULL;
352 for (uint32_t i = 0; i < RT_ELEMENTS(pSvgaR3State->aGboOTables) && !pszTarget; ++i)
353 {
354 PVMSVGAGBO pGbo = &pSvgaR3State->aGboOTables[i];
355 if (pGbo->cDescriptors)
356 {
357 for (uint32_t j = 0; j < pGbo->cDescriptors; ++j)
358 {
359 if ( GCPhys >= pGbo->paDescriptors[j].GCPhys
360 && GCPhys < pGbo->paDescriptors[j].GCPhys + pGbo->paDescriptors[j].cPages * PAGE_SIZE)
361 {
362 switch (i)
363 {
364 case SVGA_OTABLE_MOB: pszTarget = "SVGA_OTABLE_MOB"; break;
365 case SVGA_OTABLE_SURFACE: pszTarget = "SVGA_OTABLE_SURFACE"; break;
366 case SVGA_OTABLE_CONTEXT: pszTarget = "SVGA_OTABLE_CONTEXT"; break;
367 case SVGA_OTABLE_SHADER: pszTarget = "SVGA_OTABLE_SHADER"; break;
368 case SVGA_OTABLE_SCREENTARGET: pszTarget = "SVGA_OTABLE_SCREENTARGET"; break;
369 case SVGA_OTABLE_DXCONTEXT: pszTarget = "SVGA_OTABLE_DXCONTEXT"; break;
370 default: pszTarget = "Unknown OTABLE"; break;
371 }
372 break;
373 }
374 }
375 }
376 }
377
378 LogRelMax(8, ("VMSVGA: invalid guest access to page %RGp, target %s:\n"
379 "%.*Rhxd\n",
380 GCPhys, pszTarget ? pszTarget : "unknown", RT_MIN(cbBuf, 256), pvBuf));
381
382 return VINF_PGM_HANDLER_DO_DEFAULT;
383}
384
385
386static int vmsvgaR3GboCreate(PVMSVGAR3STATE pSvgaR3State, SVGAMobFormat ptDepth, PPN64 baseAddress, uint32_t sizeInBytes, bool fGCPhys64, bool fWriteProtected, PVMSVGAGBO pGbo)
387{
388 ASSERT_GUEST_RETURN(sizeInBytes <= _128M, VERR_INVALID_PARAMETER); /** @todo Less than SVGA_REG_MOB_MAX_SIZE */
389
390 /*
391 * The 'baseAddress' is a page number and points to the 'root page' of the GBO.
392 * Content of the root page depends on the ptDepth value:
393 * SVGA3D_MOBFMT_PTDEPTH[64]_0 - the only data page;
394 * SVGA3D_MOBFMT_PTDEPTH[64]_1 - array of page numbers for data pages;
395 * SVGA3D_MOBFMT_PTDEPTH[64]_2 - array of page numbers for SVGA3D_MOBFMT_PTDEPTH[64]_1 pages.
396 * The code below extracts the page addresses of the GBO.
397 */
398
399 /* Verify and normalize the ptDepth value. */
400 if (RT_LIKELY( ptDepth == SVGA3D_MOBFMT_PTDEPTH64_0
401 || ptDepth == SVGA3D_MOBFMT_PTDEPTH64_1
402 || ptDepth == SVGA3D_MOBFMT_PTDEPTH64_2))
403 ASSERT_GUEST_RETURN(fGCPhys64, VERR_INVALID_PARAMETER);
404 else if ( ptDepth == SVGA3D_MOBFMT_PTDEPTH_0
405 || ptDepth == SVGA3D_MOBFMT_PTDEPTH_1
406 || ptDepth == SVGA3D_MOBFMT_PTDEPTH_2)
407 {
408 ASSERT_GUEST_RETURN(!fGCPhys64, VERR_INVALID_PARAMETER);
409 /* Shift ptDepth to the SVGA3D_MOBFMT_PTDEPTH64_x range. */
410 ptDepth = (SVGAMobFormat)(ptDepth + SVGA3D_MOBFMT_PTDEPTH64_0 - SVGA3D_MOBFMT_PTDEPTH_0);
411 }
412 else if (ptDepth == SVGA3D_MOBFMT_RANGE)
413 { }
414 else
415 ASSERT_GUEST_FAILED_RETURN(VERR_INVALID_PARAMETER);
416
417 uint32_t const cPPNsPerPage = X86_PAGE_SIZE / (fGCPhys64 ? sizeof(PPN64) : sizeof(PPN));
418
419 pGbo->cbTotal = sizeInBytes;
420 pGbo->cTotalPages = (sizeInBytes + X86_PAGE_SIZE - 1) >> X86_PAGE_SHIFT;
421
422 /* Allocate the maximum amount possible (everything non-continuous) */
423 PVMSVGAGBODESCRIPTOR paDescriptors = (PVMSVGAGBODESCRIPTOR)RTMemAlloc(pGbo->cTotalPages * sizeof(VMSVGAGBODESCRIPTOR));
424 AssertReturn(paDescriptors, VERR_NO_MEMORY);
425
426 int rc = VINF_SUCCESS;
427 if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_0)
428 {
429 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages == 1,
430 RTMemFree(paDescriptors),
431 VERR_INVALID_PARAMETER);
432
433 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
434 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
435 paDescriptors[0].GCPhys = GCPhys;
436 paDescriptors[0].cPages = 1;
437 }
438 else if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_1)
439 {
440 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages <= cPPNsPerPage,
441 RTMemFree(paDescriptors),
442 VERR_INVALID_PARAMETER);
443
444 /* Read the root page. */
445 uint8_t au8RootPage[X86_PAGE_SIZE];
446 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
447 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhys, &au8RootPage, sizeof(au8RootPage));
448 if (RT_SUCCESS(rc))
449 {
450 PPN64 *paPPN64 = (PPN64 *)&au8RootPage[0];
451 PPN *paPPN32 = (PPN *)&au8RootPage[0];
452 for (uint32_t iPPN = 0; iPPN < pGbo->cTotalPages; ++iPPN)
453 {
454 GCPhys = (RTGCPHYS)(fGCPhys64 ? paPPN64[iPPN] : paPPN32[iPPN]) << X86_PAGE_SHIFT;
455 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
456 paDescriptors[iPPN].GCPhys = GCPhys;
457 paDescriptors[iPPN].cPages = 1;
458 }
459 }
460 }
461 else if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_2)
462 {
463 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages <= cPPNsPerPage * cPPNsPerPage,
464 RTMemFree(paDescriptors),
465 VERR_INVALID_PARAMETER);
466
467 /* Read the Level2 root page. */
468 uint8_t au8RootPageLevel2[X86_PAGE_SIZE];
469 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
470 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhys, &au8RootPageLevel2, sizeof(au8RootPageLevel2));
471 if (RT_SUCCESS(rc))
472 {
473 uint32_t cPagesLeft = pGbo->cTotalPages;
474
475 PPN64 *paPPN64Level2 = (PPN64 *)&au8RootPageLevel2[0];
476 PPN *paPPN32Level2 = (PPN *)&au8RootPageLevel2[0];
477
478 uint32_t const cPPNsLevel2 = (pGbo->cTotalPages + cPPNsPerPage - 1) / cPPNsPerPage;
479 for (uint32_t iPPNLevel2 = 0; iPPNLevel2 < cPPNsLevel2; ++iPPNLevel2)
480 {
481 /* Read the Level1 root page. */
482 uint8_t au8RootPage[X86_PAGE_SIZE];
483 RTGCPHYS GCPhysLevel1 = (RTGCPHYS)(fGCPhys64 ? paPPN64Level2[iPPNLevel2] : paPPN32Level2[iPPNLevel2]) << X86_PAGE_SHIFT;
484 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
485 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhysLevel1, &au8RootPage, sizeof(au8RootPage));
486 if (RT_SUCCESS(rc))
487 {
488 PPN64 *paPPN64 = (PPN64 *)&au8RootPage[0];
489 PPN *paPPN32 = (PPN *)&au8RootPage[0];
490
491 uint32_t const cPPNs = RT_MIN(cPagesLeft, cPPNsPerPage);
492 for (uint32_t iPPN = 0; iPPN < cPPNs; ++iPPN)
493 {
494 GCPhys = (RTGCPHYS)(fGCPhys64 ? paPPN64[iPPN] : paPPN32[iPPN]) << X86_PAGE_SHIFT;
495 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
496 paDescriptors[iPPN + iPPNLevel2 * cPPNsPerPage].GCPhys = GCPhys;
497 paDescriptors[iPPN + iPPNLevel2 * cPPNsPerPage].cPages = 1;
498 }
499 cPagesLeft -= cPPNs;
500 }
501 }
502 }
503 }
504 else if (ptDepth == SVGA3D_MOBFMT_RANGE)
505 {
506 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
507 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
508 paDescriptors[0].GCPhys = GCPhys;
509 paDescriptors[0].cPages = pGbo->cTotalPages;
510 }
511 else
512 {
513 AssertFailed();
514 return VERR_INTERNAL_ERROR; /* ptDepth should be already verified. */
515 }
516
517 /* Compress the descriptors. */
518 if (ptDepth != SVGA3D_MOBFMT_RANGE)
519 {
520 uint32_t iDescriptor = 0;
521 for (uint32_t i = 1; i < pGbo->cTotalPages; ++i)
522 {
523 /* Continuous physical memory? */
524 if (paDescriptors[i].GCPhys == paDescriptors[iDescriptor].GCPhys + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE)
525 {
526 Assert(paDescriptors[iDescriptor].cPages);
527 paDescriptors[iDescriptor].cPages++;
528 Log5Func(("Page %x GCPhys=%RGp successor\n", i, paDescriptors[i].GCPhys));
529 }
530 else
531 {
532 iDescriptor++;
533 paDescriptors[iDescriptor].GCPhys = paDescriptors[i].GCPhys;
534 paDescriptors[iDescriptor].cPages = 1;
535 Log5Func(("Page %x GCPhys=%RGp\n", i, paDescriptors[iDescriptor].GCPhys));
536 }
537 }
538
539 pGbo->cDescriptors = iDescriptor + 1;
540 Log5Func(("Nr of descriptors %d\n", pGbo->cDescriptors));
541 }
542 else
543 pGbo->cDescriptors = 1;
544
545 if (RT_LIKELY(pGbo->cDescriptors < pGbo->cTotalPages))
546 {
547 pGbo->paDescriptors = (PVMSVGAGBODESCRIPTOR)RTMemRealloc(paDescriptors, pGbo->cDescriptors * sizeof(VMSVGAGBODESCRIPTOR));
548 AssertReturn(pGbo->paDescriptors, VERR_NO_MEMORY);
549 }
550 else
551 pGbo->paDescriptors = paDescriptors;
552
553 if (fWriteProtected)
554 {
555 pGbo->fGboFlags |= VMSVGAGBO_F_WRITE_PROTECTED;
556 for (uint32_t i = 0; i < pGbo->cDescriptors; ++i)
557 {
558 rc = PGMHandlerPhysicalRegister(PDMDevHlpGetVM(pSvgaR3State->pDevIns),
559 pGbo->paDescriptors[i].GCPhys, pGbo->paDescriptors[i].GCPhys + pGbo->paDescriptors[i].cPages * PAGE_SIZE - 1,
560 pSvgaR3State->hGboAccessHandlerType, pSvgaR3State->pDevIns, NIL_RTR0PTR, NIL_RTRCPTR, "VMSVGA GBO");
561 AssertRC(rc);
562 }
563 }
564
565 return VINF_SUCCESS;
566}
567
568
569static void vmsvgaR3GboDestroy(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo)
570{
571 if (RT_LIKELY(VMSVGA_IS_GBO_CREATED(pGbo)))
572 {
573 if (pGbo->fGboFlags & VMSVGAGBO_F_WRITE_PROTECTED)
574 {
575 for (uint32_t i = 0; i < pGbo->cDescriptors; ++i)
576 {
577 int rc = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pSvgaR3State->pDevIns), pGbo->paDescriptors[i].GCPhys);
578 AssertRC(rc);
579 }
580 }
581 RTMemFree(pGbo->paDescriptors);
582 RT_ZERO(pGbo);
583 }
584}
585
586
587typedef enum VMSVGAGboTransferDirection
588{
589 VMSVGAGboTransferDirection_Read,
590 VMSVGAGboTransferDirection_Write,
591} VMSVGAGboTransferDirection;
592
593static int vmsvgaR3GboTransfer(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
594 uint32_t off, void *pvData, uint32_t cbData,
595 VMSVGAGboTransferDirection enmDirection)
596{
597// ASMBreakpoint();
598 int rc = VINF_SUCCESS;
599 uint8_t *pu8CurrentHost = (uint8_t *)pvData;
600
601 /* Find the right descriptor */
602 PCVMSVGAGBODESCRIPTOR const paDescriptors = pGbo->paDescriptors;
603 uint32_t iDescriptor = 0; /* Index in the descriptor array. */
604 uint32_t offDescriptor = 0; /* GMR offset of the current descriptor. */
605 while (offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE <= off)
606 {
607 offDescriptor += paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE;
608 AssertReturn(offDescriptor < pGbo->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
609 ++iDescriptor;
610 AssertReturn(iDescriptor < pGbo->cDescriptors, VERR_INTERNAL_ERROR);
611 }
612
613 while (cbData)
614 {
615 uint32_t cbToCopy;
616 if (off + cbData <= offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE)
617 cbToCopy = cbData;
618 else
619 {
620 cbToCopy = (offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE - off);
621 AssertReturn(cbToCopy <= cbData, VERR_INVALID_PARAMETER);
622 }
623
624 RTGCPHYS const GCPhys = paDescriptors[iDescriptor].GCPhys + off - offDescriptor;
625 Log5Func(("%s phys=%RGp\n", (enmDirection == VMSVGAGboTransferDirection_Read) ? "READ" : "WRITE", GCPhys));
626
627 if (enmDirection == VMSVGAGboTransferDirection_Read)
628 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhys, pu8CurrentHost, cbToCopy);
629 else
630 rc = PDMDevHlpPCIPhysWrite(pSvgaR3State->pDevIns, GCPhys, pu8CurrentHost, cbToCopy);
631 AssertRCBreak(rc);
632
633 cbData -= cbToCopy;
634 off += cbToCopy;
635 pu8CurrentHost += cbToCopy;
636
637 /* Go to the next descriptor if there's anything left. */
638 if (cbData)
639 {
640 offDescriptor += paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE;
641 AssertReturn(offDescriptor < pGbo->cbTotal, VERR_INTERNAL_ERROR);
642 ++iDescriptor;
643 AssertReturn(iDescriptor < pGbo->cDescriptors, VERR_INTERNAL_ERROR);
644 }
645 }
646 return rc;
647}
648
649
650static int vmsvgaR3GboWrite(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
651 uint32_t off, void const *pvData, uint32_t cbData)
652{
653 return vmsvgaR3GboTransfer(pSvgaR3State, pGbo,
654 off, (void *)pvData, cbData,
655 VMSVGAGboTransferDirection_Write);
656}
657
658
659static int vmsvgaR3GboRead(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
660 uint32_t off, void *pvData, uint32_t cbData)
661{
662 return vmsvgaR3GboTransfer(pSvgaR3State, pGbo,
663 off, pvData, cbData,
664 VMSVGAGboTransferDirection_Read);
665}
666
667
668/*
669 *
670 * Object Tables.
671 *
672 */
673
674static int vmsvgaR3OTableVerifyIndex(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
675 uint32_t idx, uint32_t cbEntry)
676{
677 RT_NOREF(pSvgaR3State);
678
679 /* The table must exist and the index must be within the table. */
680 ASSERT_GUEST_RETURN(VMSVGA_IS_GBO_CREATED(pGboOTable), VERR_INVALID_PARAMETER);
681 ASSERT_GUEST_RETURN(idx < pGboOTable->cbTotal / cbEntry, VERR_INVALID_PARAMETER);
682 RT_UNTRUSTED_VALIDATED_FENCE();
683 return VINF_SUCCESS;
684}
685
686
687static int vmsvgaR3OTableRead(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
688 uint32_t idx, uint32_t cbEntry,
689 void *pvData, uint32_t cbData)
690{
691 AssertReturn(cbData <= cbEntry, VERR_INVALID_PARAMETER);
692
693 int rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, pGboOTable, idx, cbEntry);
694 if (RT_SUCCESS(rc))
695 {
696 uint32_t const off = idx * cbEntry;
697 rc = vmsvgaR3GboRead(pSvgaR3State, pGboOTable, off, pvData, cbData);
698 }
699 return rc;
700}
701
702static int vmsvgaR3OTableWrite(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
703 uint32_t idx, uint32_t cbEntry,
704 void const *pvData, uint32_t cbData)
705{
706 AssertReturn(cbData <= cbEntry, VERR_INVALID_PARAMETER);
707
708 int rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, pGboOTable, idx, cbEntry);
709 if (RT_SUCCESS(rc))
710 {
711 uint32_t const off = idx * cbEntry;
712 rc = vmsvgaR3GboWrite(pSvgaR3State, pGboOTable, off, pvData, cbData);
713 }
714 return rc;
715}
716
717
718/*
719 *
720 * The guest's Memory OBjects (MOB).
721 *
722 */
723
724static int vmsvgaR3MobCreate(PVMSVGAR3STATE pSvgaR3State,
725 SVGAMobFormat ptDepth, PPN64 baseAddress, uint32_t sizeInBytes, SVGAMobId mobid,
726 bool fGCPhys64, PVMSVGAMOB pMob)
727{
728 RT_ZERO(*pMob);
729
730 /* Update the entry in the pSvgaR3State->pGboOTableMob. */
731 SVGAOTableMobEntry entry;
732 entry.ptDepth = ptDepth;
733 entry.sizeInBytes = sizeInBytes;
734 entry.base = baseAddress;
735 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
736 mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE, &entry, sizeof(entry));
737 if (RT_SUCCESS(rc))
738 {
739 /* Create the corresponding GBO. */
740 rc = vmsvgaR3GboCreate(pSvgaR3State, ptDepth, baseAddress, sizeInBytes, fGCPhys64, /* fWriteProtected = */ false, &pMob->Gbo);
741 if (RT_SUCCESS(rc))
742 {
743 /* Add to the tree of known GBOs and the LRU list. */
744 pMob->Core.Key = mobid;
745 if (RTAvlU32Insert(&pSvgaR3State->MOBTree, &pMob->Core))
746 {
747 RTListPrepend(&pSvgaR3State->MOBLRUList, &pMob->nodeLRU);
748 return VINF_SUCCESS;
749 }
750
751 vmsvgaR3GboDestroy(pSvgaR3State, &pMob->Gbo);
752 }
753 }
754
755 return rc;
756}
757
758
759static int vmsvgaR3MobDestroy(PVMSVGAR3STATE pSvgaR3State, SVGAMobId mobid)
760{
761 /* Update the entry in the pSvgaR3State->pGboOTableMob. */
762 SVGAOTableMobEntry entry;
763 RT_ZERO(entry);
764 vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
765 mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE, &entry, sizeof(entry));
766
767 PVMSVGAMOB pMob = (PVMSVGAMOB)RTAvlU32Remove(&pSvgaR3State->MOBTree, mobid);
768 if (pMob)
769 {
770 RTListNodeRemove(&pMob->nodeLRU);
771 vmsvgaR3GboDestroy(pSvgaR3State, &pMob->Gbo);
772 RTMemFree(pMob);
773 return VINF_SUCCESS;
774 }
775
776 return VERR_INVALID_PARAMETER;
777}
778
779
780static PVMSVGAMOB vmsvgaR3MobGet(PVMSVGAR3STATE pSvgaR3State, SVGAMobId mobid)
781{
782 PVMSVGAMOB pMob = (PVMSVGAMOB)RTAvlU32Get(&pSvgaR3State->MOBTree, mobid);
783 if (pMob)
784 {
785 /* Move to the head of the LRU list. */
786 RTListNodeRemove(&pMob->nodeLRU);
787 RTListPrepend(&pSvgaR3State->MOBLRUList, &pMob->nodeLRU);
788 }
789
790 return pMob;
791}
792
793/*
794 * Screen objects.
795 */
796VMSVGASCREENOBJECT *vmsvgaR3GetScreenObject(PVGASTATECC pThisCC, uint32_t idScreen)
797{
798 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
799 if ( idScreen < (uint32_t)RT_ELEMENTS(pSVGAState->aScreens)
800 && pSVGAState
801 && pSVGAState->aScreens[idScreen].fDefined)
802 {
803 return &pSVGAState->aScreens[idScreen];
804 }
805 return NULL;
806}
807
808void vmsvgaR3ResetScreens(PVGASTATE pThis, PVGASTATECC pThisCC)
809{
810#ifdef VBOX_WITH_VMSVGA3D
811 if (pThis->svga.f3DEnabled)
812 {
813 for (uint32_t idScreen = 0; idScreen < (uint32_t)RT_ELEMENTS(pThisCC->svga.pSvgaR3State->aScreens); ++idScreen)
814 {
815 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, idScreen);
816 if (pScreen)
817 vmsvga3dDestroyScreen(pThisCC, pScreen);
818 }
819 }
820#else
821 RT_NOREF(pThis, pThisCC);
822#endif
823}
824
825
826/**
827 * Copy a rectangle of pixels within guest VRAM.
828 */
829static void vmsvgaR3RectCopy(PVGASTATECC pThisCC, VMSVGASCREENOBJECT const *pScreen, uint32_t srcX, uint32_t srcY,
830 uint32_t dstX, uint32_t dstY, uint32_t width, uint32_t height, unsigned cbFrameBuffer)
831{
832 if (!width || !height)
833 return; /* Nothing to do, don't even bother. */
834
835 /*
836 * The guest VRAM (aka GFB) is considered to be a bitmap in the format
837 * corresponding to the current display mode.
838 */
839 uint32_t const cbPixel = RT_ALIGN(pScreen->cBpp, 8) / 8;
840 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch : width * cbPixel;
841 uint8_t const *pSrc;
842 uint8_t *pDst;
843 unsigned const cbRectWidth = width * cbPixel;
844 unsigned uMaxOffset;
845
846 uMaxOffset = (RT_MAX(srcY, dstY) + height) * cbScanline + (RT_MAX(srcX, dstX) + width) * cbPixel;
847 if (uMaxOffset >= cbFrameBuffer)
848 {
849 Log(("Max offset (%u) too big for framebuffer (%u bytes), ignoring!\n", uMaxOffset, cbFrameBuffer));
850 return; /* Just don't listen to a bad guest. */
851 }
852
853 pSrc = pDst = pThisCC->pbVRam;
854 pSrc += srcY * cbScanline + srcX * cbPixel;
855 pDst += dstY * cbScanline + dstX * cbPixel;
856
857 if (srcY >= dstY)
858 {
859 /* Source below destination, copy top to bottom. */
860 for (; height > 0; height--)
861 {
862 memmove(pDst, pSrc, cbRectWidth);
863 pSrc += cbScanline;
864 pDst += cbScanline;
865 }
866 }
867 else
868 {
869 /* Source above destination, copy bottom to top. */
870 pSrc += cbScanline * (height - 1);
871 pDst += cbScanline * (height - 1);
872 for (; height > 0; height--)
873 {
874 memmove(pDst, pSrc, cbRectWidth);
875 pSrc -= cbScanline;
876 pDst -= cbScanline;
877 }
878 }
879}
880
881
882/**
883 * Common worker for changing the pointer shape.
884 *
885 * @param pThisCC The VGA/VMSVGA state for ring-3.
886 * @param pSVGAState The VMSVGA ring-3 instance data.
887 * @param fAlpha Whether there is alpha or not.
888 * @param xHot Hotspot x coordinate.
889 * @param yHot Hotspot y coordinate.
890 * @param cx Width.
891 * @param cy Height.
892 * @param pbData Heap copy of the cursor data. Consumed.
893 * @param cbData The size of the data.
894 */
895static void vmsvgaR3InstallNewCursor(PVGASTATECC pThisCC, PVMSVGAR3STATE pSVGAState, bool fAlpha,
896 uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, uint8_t *pbData, uint32_t cbData)
897{
898 LogRel2(("vmsvgaR3InstallNewCursor: cx=%d cy=%d xHot=%d yHot=%d fAlpha=%d cbData=%#x\n", cx, cy, xHot, yHot, fAlpha, cbData));
899#ifdef LOG_ENABLED
900 if (LogIs2Enabled())
901 {
902 uint32_t cbAndLine = RT_ALIGN(cx, 8) / 8;
903 if (!fAlpha)
904 {
905 Log2(("VMSVGA Cursor AND mask (%d,%d):\n", cx, cy));
906 for (uint32_t y = 0; y < cy; y++)
907 {
908 Log2(("%3u:", y));
909 uint8_t const *pbLine = &pbData[y * cbAndLine];
910 for (uint32_t x = 0; x < cx; x += 8)
911 {
912 uint8_t b = pbLine[x / 8];
913 char szByte[12];
914 szByte[0] = b & 0x80 ? '*' : ' '; /* most significant bit first */
915 szByte[1] = b & 0x40 ? '*' : ' ';
916 szByte[2] = b & 0x20 ? '*' : ' ';
917 szByte[3] = b & 0x10 ? '*' : ' ';
918 szByte[4] = b & 0x08 ? '*' : ' ';
919 szByte[5] = b & 0x04 ? '*' : ' ';
920 szByte[6] = b & 0x02 ? '*' : ' ';
921 szByte[7] = b & 0x01 ? '*' : ' ';
922 szByte[8] = '\0';
923 Log2(("%s", szByte));
924 }
925 Log2(("\n"));
926 }
927 }
928
929 Log2(("VMSVGA Cursor XOR mask (%d,%d):\n", cx, cy));
930 uint32_t const *pu32Xor = (uint32_t const *)&pbData[RT_ALIGN_32(cbAndLine * cy, 4)];
931 for (uint32_t y = 0; y < cy; y++)
932 {
933 Log2(("%3u:", y));
934 uint32_t const *pu32Line = &pu32Xor[y * cx];
935 for (uint32_t x = 0; x < cx; x++)
936 Log2((" %08x", pu32Line[x]));
937 Log2(("\n"));
938 }
939 }
940#endif
941
942 int rc = pThisCC->pDrv->pfnVBVAMousePointerShape(pThisCC->pDrv, true /*fVisible*/, fAlpha, xHot, yHot, cx, cy, pbData);
943 AssertRC(rc);
944
945 if (pSVGAState->Cursor.fActive)
946 RTMemFreeZ(pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
947
948 pSVGAState->Cursor.fActive = true;
949 pSVGAState->Cursor.xHotspot = xHot;
950 pSVGAState->Cursor.yHotspot = yHot;
951 pSVGAState->Cursor.width = cx;
952 pSVGAState->Cursor.height = cy;
953 pSVGAState->Cursor.cbData = cbData;
954 pSVGAState->Cursor.pData = pbData;
955}
956
957
958#ifdef VBOX_WITH_VMSVGA3D
959
960/*
961 * SVGA_3D_CMD_* handlers.
962 */
963
964
965/** SVGA_3D_CMD_SURFACE_DEFINE 1040, SVGA_3D_CMD_SURFACE_DEFINE_V2 1070
966 *
967 * @param pThisCC The VGA/VMSVGA state for the current context.
968 * @param pCmd The VMSVGA command.
969 * @param cMipLevelSizes Number of elements in the paMipLevelSizes array.
970 * @param paMipLevelSizes Arrays of surface sizes for each face and miplevel.
971 */
972static void vmsvga3dCmdDefineSurface(PVGASTATECC pThisCC, SVGA3dCmdDefineSurface_v2 const *pCmd,
973 uint32_t cMipLevelSizes, SVGA3dSize *paMipLevelSizes)
974{
975 ASSERT_GUEST_RETURN_VOID(pCmd->sid < SVGA3D_MAX_SURFACE_IDS);
976 ASSERT_GUEST_RETURN_VOID(cMipLevelSizes >= 1);
977 RT_UNTRUSTED_VALIDATED_FENCE();
978
979 /* Number of faces (cFaces) is specified as the number of the first non-zero elements in the 'face' array.
980 * Since only plain surfaces (cFaces == 1) and cubemaps (cFaces == 6) are supported
981 * (see also SVGA3dCmdDefineSurface definition in svga3d_reg.h), we ignore anything else.
982 */
983 uint32_t cRemainingMipLevels = cMipLevelSizes;
984 uint32_t cFaces = 0;
985 for (uint32_t i = 0; i < SVGA3D_MAX_SURFACE_FACES; ++i)
986 {
987 if (pCmd->face[i].numMipLevels == 0)
988 break;
989
990 /* All SVGA3dSurfaceFace structures must have the same value of numMipLevels field */
991 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels == pCmd->face[0].numMipLevels);
992
993 /* numMipLevels value can't be greater than the number of remaining elements in the paMipLevelSizes array. */
994 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels <= cRemainingMipLevels);
995 cRemainingMipLevels -= pCmd->face[i].numMipLevels;
996
997 ++cFaces;
998 }
999 for (uint32_t i = cFaces; i < SVGA3D_MAX_SURFACE_FACES; ++i)
1000 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels == 0);
1001
1002 /* cFaces must be 6 for a cubemap and 1 otherwise. */
1003 ASSERT_GUEST_RETURN_VOID(cFaces == (uint32_t)((pCmd->surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1));
1004
1005 /* Sum of face[i].numMipLevels must be equal to cMipLevels. */
1006 ASSERT_GUEST_RETURN_VOID(cRemainingMipLevels == 0);
1007 RT_UNTRUSTED_VALIDATED_FENCE();
1008
1009 /* Verify paMipLevelSizes */
1010 uint32_t cWidth = paMipLevelSizes[0].width;
1011 uint32_t cHeight = paMipLevelSizes[0].height;
1012 uint32_t cDepth = paMipLevelSizes[0].depth;
1013 for (uint32_t i = 1; i < pCmd->face[0].numMipLevels; ++i)
1014 {
1015 cWidth >>= 1;
1016 if (cWidth == 0) cWidth = 1;
1017 cHeight >>= 1;
1018 if (cHeight == 0) cHeight = 1;
1019 cDepth >>= 1;
1020 if (cDepth == 0) cDepth = 1;
1021 for (uint32_t iFace = 0; iFace < cFaces; ++iFace)
1022 {
1023 uint32_t const iMipLevelSize = iFace * pCmd->face[0].numMipLevels + i;
1024 ASSERT_GUEST_RETURN_VOID( cWidth == paMipLevelSizes[iMipLevelSize].width
1025 && cHeight == paMipLevelSizes[iMipLevelSize].height
1026 && cDepth == paMipLevelSizes[iMipLevelSize].depth);
1027 }
1028 }
1029 RT_UNTRUSTED_VALIDATED_FENCE();
1030
1031 /* Create the surface. */
1032 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
1033 pCmd->multisampleCount, pCmd->autogenFilter,
1034 pCmd->face[0].numMipLevels, &paMipLevelSizes[0]);
1035}
1036
1037
1038/* SVGA_3D_CMD_DEFINE_GB_MOB 1093 */
1039static void vmsvga3dCmdDefineGBMob(PVGASTATECC pThisCC, SVGA3dCmdDefineGBMob const *pCmd)
1040{
1041 ASMBreakpoint();
1042 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1043
1044 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1045
1046 /* Maybe just update the OTable and create Gbo when the MOB is actually accessed? */
1047 /* Allocate a structure for the MOB. */
1048 PVMSVGAMOB pMob = (PVMSVGAMOB)RTMemAllocZ(sizeof(*pMob));
1049 AssertPtrReturnVoid(pMob);
1050
1051 int rc = vmsvgaR3MobCreate(pSvgaR3State, pCmd->ptDepth, pCmd->base, pCmd->sizeInBytes, pCmd->mobid, /*fGCPhys64=*/ false, pMob);
1052 if (RT_SUCCESS(rc))
1053 {
1054 return;
1055 }
1056
1057 AssertFailed();
1058
1059 RTMemFree(pMob);
1060}
1061
1062
1063/* SVGA_3D_CMD_DESTROY_GB_MOB 1094 */
1064static void vmsvga3dCmdDestroyGBMob(PVGASTATECC pThisCC, SVGA3dCmdDestroyGBMob const *pCmd)
1065{
1066// ASMBreakpoint();
1067 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1068
1069 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1070
1071 int rc = vmsvgaR3MobDestroy(pSvgaR3State, pCmd->mobid);
1072 if (RT_SUCCESS(rc))
1073 {
1074 return;
1075 }
1076
1077 AssertFailed();
1078}
1079
1080
1081/* SVGA_3D_CMD_DEFINE_GB_SURFACE 1097 */
1082static void vmsvga3dCmdDefineGBSurface(PVGASTATECC pThisCC, SVGA3dCmdDefineGBSurface const *pCmd)
1083{
1084// ASMBreakpoint();
1085 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1086
1087 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
1088 SVGAOTableSurfaceEntry entry;
1089 RT_ZERO(entry);
1090 entry.format = pCmd->format;
1091 entry.surfaceFlags = pCmd->surfaceFlags;
1092 entry.numMipLevels = pCmd->numMipLevels;
1093 entry.multisampleCount = pCmd->multisampleCount;
1094 entry.autogenFilter = pCmd->autogenFilter;
1095 entry.size = pCmd->size;
1096 entry.mobid = SVGA_ID_INVALID;
1097 // entry.arraySize = 0;
1098 // entry.mobPitch = 0;
1099 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1100 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1101 if (RT_SUCCESS(rc))
1102 {
1103 /* Create the host surface. */
1104 /** @todo fGBO = true flag. */
1105 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
1106 pCmd->multisampleCount, pCmd->autogenFilter,
1107 pCmd->numMipLevels, &pCmd->size);
1108 }
1109}
1110
1111
1112/* SVGA_3D_CMD_DESTROY_GB_SURFACE 1098 */
1113static void vmsvga3dCmdDestroyGBSurface(PVGASTATECC pThisCC, SVGA3dCmdDestroyGBSurface const *pCmd)
1114{
1115// ASMBreakpoint();
1116 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1117
1118 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
1119 SVGAOTableSurfaceEntry entry;
1120 RT_ZERO(entry);
1121 entry.mobid = SVGA_ID_INVALID;
1122 vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1123 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1124
1125 vmsvga3dSurfaceDestroy(pThisCC, pCmd->sid);
1126}
1127
1128
1129/* SVGA_3D_CMD_BIND_GB_SURFACE 1099 */
1130static void vmsvga3dCmdBindGBSurface(PVGASTATECC pThisCC, SVGA3dCmdBindGBSurface const *pCmd)
1131{
1132// ASMBreakpoint();
1133 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1134 RT_NOREF(pCmd, pSvgaR3State);
1135
1136 /* Assign the mobid to the surface. */
1137 int rc = VINF_SUCCESS;
1138 if (pCmd->mobid != SVGA_ID_INVALID)
1139 rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
1140 pCmd->mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE);
1141 if (RT_SUCCESS(rc))
1142 {
1143 SVGAOTableSurfaceEntry entry;
1144 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1145 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1146 if (RT_SUCCESS(rc))
1147 {
1148 entry.mobid = pCmd->mobid;
1149 rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1150 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1151 if (RT_SUCCESS(rc))
1152 {
1153 /* */
1154 }
1155 }
1156 }
1157}
1158
1159
1160#ifdef DUMP_BITMAPS
1161static int vmsvga3dBmpWrite(const char *pszFilename, VMSVGA3D_MAPPED_SURFACE const *pMap)
1162{
1163 if (pMap->cbPixel != 4)
1164 return VERR_NOT_SUPPORTED;
1165
1166 int const w = pMap->box.w;
1167 int const h = pMap->box.h;
1168
1169 const int cbBitmap = w * h * 4;
1170
1171 FILE *f = fopen(pszFilename, "wb");
1172 if (!f)
1173 return VERR_FILE_NOT_FOUND;
1174
1175 {
1176 BMPFILEHDR fileHdr;
1177 RT_ZERO(fileHdr);
1178 fileHdr.uType = BMP_HDR_MAGIC;
1179 fileHdr.cbFileSize = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR) + cbBitmap;
1180 fileHdr.offBits = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR);
1181
1182 BMPWIN3XINFOHDR coreHdr;
1183 RT_ZERO(coreHdr);
1184 coreHdr.cbSize = sizeof(coreHdr);
1185 coreHdr.uWidth = w;
1186 coreHdr.uHeight = -h;
1187 coreHdr.cPlanes = 1;
1188 coreHdr.cBits = 32;
1189 coreHdr.cbSizeImage = cbBitmap;
1190
1191 fwrite(&fileHdr, 1, sizeof(fileHdr), f);
1192 fwrite(&coreHdr, 1, sizeof(coreHdr), f);
1193 }
1194
1195 if (pMap->cbPixel == 4)
1196 {
1197 const uint8_t *s = (uint8_t *)pMap->pvData;
1198 for (int32_t y = 0; y < h; ++y)
1199 {
1200 fwrite(s, 1, w * pMap->cbPixel, f);
1201
1202 s += pMap->cbRowPitch;
1203 }
1204 }
1205
1206 fclose(f);
1207
1208 return VINF_SUCCESS;
1209}
1210
1211
1212void vmsvga3dMapWriteBmpFile(VMSVGA3D_MAPPED_SURFACE const *pMap, char const *pszPrefix)
1213{
1214 static int idxBitmap = 0;
1215 char *pszFilename = RTStrAPrintf2("bmp\\%s%d.bmp", pszPrefix, idxBitmap++);
1216 vmsvga3dBmpWrite(pszFilename, pMap);
1217 RTStrFree(pszFilename);
1218}
1219#endif /* DUMP_BITMAPS */
1220
1221
1222/* SVGA_3D_CMD_UPDATE_GB_IMAGE 1101 */
1223static void vmsvga3dCmdUpdateGBImage(PVGASTATECC pThisCC, SVGA3dCmdUpdateGBImage const *pCmd)
1224{
1225// ASMBreakpoint();
1226 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1227
1228 LogFlowFunc(("sid=%u @%u,%u,%u %ux%ux%u\n",
1229 pCmd->image.sid, pCmd->box.x, pCmd->box.y, pCmd->box.z, pCmd->box.w, pCmd->box.h, pCmd->box.d));
1230
1231 /* "update a surface from its backing MOB." */
1232 SVGAOTableSurfaceEntry entrySurface;
1233 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1234 pCmd->image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1235 if (RT_SUCCESS(rc))
1236 {
1237 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1238 if (pMob)
1239 {
1240 VMSVGA3D_MAPPED_SURFACE map;
1241 rc = vmsvga3dSurfaceMap(pThisCC, &pCmd->image, &pCmd->box, VMSVGA3D_SURFACE_MAP_WRITE_DISCARD, &map);
1242 if (RT_SUCCESS(rc))
1243 {
1244 /* Copy MOB -> mapped surface. */
1245 uint32_t offSrc = pCmd->box.x * map.cbPixel
1246 + pCmd->box.y * entrySurface.size.width * map.cbPixel
1247 + pCmd->box.z * entrySurface.size.height * entrySurface.size.width * map.cbPixel;
1248 uint8_t *pu8Dst = (uint8_t *)map.pvData;
1249 for (uint32_t z = 0; z < pCmd->box.d; ++z)
1250 {
1251 for (uint32_t y = 0; y < pCmd->box.h; ++y)
1252 {
1253 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, offSrc, pu8Dst, pCmd->box.w * map.cbPixel);
1254 if (RT_FAILURE(rc))
1255 break;
1256
1257 pu8Dst += map.cbRowPitch;
1258 offSrc += entrySurface.size.width * map.cbPixel;
1259 }
1260
1261 pu8Dst += map.cbDepthPitch;
1262 offSrc += entrySurface.size.height * entrySurface.size.width * map.cbPixel;
1263 }
1264
1265 // vmsvga3dMapWriteBmpFile(&map, "Dynamic");
1266
1267 vmsvga3dSurfaceUnmap(pThisCC, &pCmd->image, &map, /* fWritten = */true);
1268 }
1269 }
1270 }
1271}
1272
1273
1274/* SVGA_3D_CMD_INVALIDATE_GB_SURFACE 1106 */
1275static void vmsvga3dCmdInvalidateGBSurface(PVGASTATECC pThisCC, SVGA3dCmdInvalidateGBSurface const *pCmd)
1276{
1277// ASMBreakpoint();
1278 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1279 RT_NOREF(pSvgaR3State, pCmd);
1280 /** @todo Implement. */
1281}
1282
1283
1284/* SVGA_3D_CMD_SET_OTABLE_BASE64 1115 */
1285static void vmsvga3dCmdSetOTableBase64(PVGASTATECC pThisCC, SVGA3dCmdSetOTableBase64 const *pCmd)
1286{
1287 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1288
1289 /*
1290 * Create a GBO for the table.
1291 */
1292 PVMSVGAGBO pGbo;
1293 if (pCmd->type <= RT_ELEMENTS(pSvgaR3State->aGboOTables))
1294 {
1295 RT_UNTRUSTED_VALIDATED_FENCE();
1296 pGbo = &pSvgaR3State->aGboOTables[pCmd->type];
1297 }
1298 else
1299 {
1300 ASSERT_GUEST_FAILED();
1301 pGbo = NULL;
1302 }
1303
1304 if (pGbo)
1305 {
1306 /* Recreate. */
1307 vmsvgaR3GboDestroy(pSvgaR3State, pGbo);
1308 int rc = vmsvgaR3GboCreate(pSvgaR3State, pCmd->ptDepth, pCmd->baseAddress, pCmd->sizeInBytes, /*fGCPhys64=*/ true, /* fWriteProtected = */ true, pGbo);
1309 AssertRC(rc);
1310 }
1311}
1312
1313
1314/* SVGA_3D_CMD_DEFINE_GB_SCREENTARGET 1124 */
1315static void vmsvga3dCmdDefineGBScreenTarget(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dCmdDefineGBScreenTarget const *pCmd)
1316{
1317// ASMBreakpoint();
1318 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1319
1320 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1321 ASSERT_GUEST_RETURN_VOID(pCmd->width > 0 && pCmd->width <= pThis->svga.u32MaxWidth); /* SVGA_REG_SCREENTARGET_MAX_WIDTH */
1322 ASSERT_GUEST_RETURN_VOID(pCmd->height > 0 && pCmd->height <= pThis->svga.u32MaxHeight); /* SVGA_REG_SCREENTARGET_MAX_HEIGHT */
1323 RT_UNTRUSTED_VALIDATED_FENCE();
1324
1325 /* Update the entry in the pSvgaR3State->pGboOTableScreenTarget. */
1326 SVGAOTableScreenTargetEntry entry;
1327 RT_ZERO(entry);
1328 entry.image.sid = SVGA_ID_INVALID;
1329 // entry.image.face = 0;
1330 // entry.image.mipmap = 0;
1331 entry.width = pCmd->width;
1332 entry.height = pCmd->height;
1333 entry.xRoot = pCmd->xRoot;
1334 entry.yRoot = pCmd->yRoot;
1335 entry.flags = pCmd->flags;
1336 entry.dpi = pCmd->dpi;
1337 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1338 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1339 if (RT_SUCCESS(rc))
1340 {
1341 /* Screen objects and screen targets are similar, therefore we will use the same for both. */
1342 /** @todo Generic screen object/target interface. */
1343 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1344 pScreen->fDefined = true;
1345 pScreen->fModified = true;
1346 pScreen->fuScreen = SVGA_SCREEN_MUST_BE_SET
1347 | (RT_BOOL(pCmd->flags & SVGA_STFLAG_PRIMARY) ? SVGA_SCREEN_IS_PRIMARY : 0);
1348 pScreen->idScreen = pCmd->stid;
1349
1350 pScreen->xOrigin = pCmd->xRoot;
1351 pScreen->yOrigin = pCmd->yRoot;
1352 pScreen->cWidth = pCmd->width;
1353 pScreen->cHeight = pCmd->height;
1354 pScreen->offVRAM = 0; /* Always for screen targets, they use either a separate memory buffer or a host window. */
1355 pScreen->cbPitch = pCmd->width * 4;
1356 pScreen->cBpp = 32;
1357
1358 if (RT_LIKELY(pThis->svga.f3DEnabled))
1359 vmsvga3dDefineScreen(pThis, pThisCC, pScreen);
1360
1361 if (!pScreen->pHwScreen)
1362 {
1363 /* System memory buffer. */
1364 pScreen->pvScreenBitmap = RTMemAllocZ(pScreen->cHeight * pScreen->cbPitch);
1365 }
1366
1367 pThis->svga.fGFBRegisters = false;
1368 vmsvgaR3ChangeMode(pThis, pThisCC);
1369 }
1370}
1371
1372
1373/* SVGA_3D_CMD_DESTROY_GB_SCREENTARGET 1125 */
1374static void vmsvga3dCmdDestroyGBScreenTarget(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dCmdDestroyGBScreenTarget const *pCmd)
1375{
1376// ASMBreakpoint();
1377 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1378
1379 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1380 RT_UNTRUSTED_VALIDATED_FENCE();
1381
1382 /* Update the entry in the pSvgaR3State->pGboOTableScreenTarget. */
1383 SVGAOTableScreenTargetEntry entry;
1384 RT_ZERO(entry);
1385 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1386 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1387 if (RT_SUCCESS(rc))
1388 {
1389 /* Screen objects and screen targets are similar, therefore we will use the same for both. */
1390 /** @todo Generic screen object/target interface. */
1391 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1392 pScreen->fModified = true;
1393 pScreen->fDefined = false;
1394 pScreen->idScreen = pCmd->stid;
1395
1396 if (RT_LIKELY(pThis->svga.f3DEnabled))
1397 vmsvga3dDestroyScreen(pThisCC, pScreen);
1398
1399 vmsvgaR3ChangeMode(pThis, pThisCC);
1400
1401 RTMemFree(pScreen->pvScreenBitmap);
1402 pScreen->pvScreenBitmap = NULL;
1403 }
1404}
1405
1406
1407/* SVGA_3D_CMD_BIND_GB_SCREENTARGET 1126 */
1408static void vmsvga3dCmdBindGBScreenTarget(PVGASTATECC pThisCC, SVGA3dCmdBindGBScreenTarget const *pCmd)
1409{
1410// ASMBreakpoint();
1411 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1412
1413 /* "Binding a surface to a Screen Target the same as flipping" */
1414
1415 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1416 ASSERT_GUEST_RETURN_VOID(pCmd->image.face == 0 && pCmd->image.mipmap == 0);
1417 RT_UNTRUSTED_VALIDATED_FENCE();
1418
1419 /* Assign the surface to the screen target. */
1420 int rc = VINF_SUCCESS;
1421 if (pCmd->image.sid != SVGA_ID_INVALID)
1422 rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1423 pCmd->image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE);
1424 if (RT_SUCCESS(rc))
1425 {
1426 SVGAOTableScreenTargetEntry entry;
1427 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1428 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1429 if (RT_SUCCESS(rc))
1430 {
1431 entry.image = pCmd->image;
1432 rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1433 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1434 if (RT_SUCCESS(rc))
1435 {
1436 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1437 rc = vmsvga3dScreenTargetBind(pThisCC, pScreen, pCmd->image.sid);
1438 AssertRC(rc);
1439 }
1440 }
1441 }
1442}
1443
1444
1445/* SVGA_3D_CMD_UPDATE_GB_SCREENTARGET 1127 */
1446static void vmsvga3dCmdUpdateGBScreenTarget(PVGASTATECC pThisCC, SVGA3dCmdUpdateGBScreenTarget const *pCmd)
1447{
1448// ASMBreakpoint();
1449 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1450
1451 /* Update the screen target from its backing surface. */
1452 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1453 RT_UNTRUSTED_VALIDATED_FENCE();
1454
1455 /* Get the screen target info. */
1456 SVGAOTableScreenTargetEntry entryScreenTarget;
1457 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1458 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entryScreenTarget, sizeof(entryScreenTarget));
1459 if (RT_SUCCESS(rc))
1460 {
1461 ASSERT_GUEST_RETURN_VOID(entryScreenTarget.image.face == 0 && entryScreenTarget.image.mipmap == 0);
1462 RT_UNTRUSTED_VALIDATED_FENCE();
1463
1464 if (entryScreenTarget.image.sid != SVGA_ID_INVALID)
1465 {
1466 SVGAOTableSurfaceEntry entrySurface;
1467 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1468 entryScreenTarget.image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1469 if (RT_SUCCESS(rc))
1470 {
1471 /* Copy entrySurface.mobid content to the screen target. */
1472 if (entrySurface.mobid != SVGA_ID_INVALID)
1473 {
1474 RT_UNTRUSTED_VALIDATED_FENCE();
1475 SVGA3dRect targetRect = pCmd->rect;
1476
1477 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1478 if (pScreen->pHwScreen)
1479 {
1480 /* Copy the screen target surface to the backend's screen. */
1481 vmsvga3dScreenTargetUpdate(pThisCC, pScreen, &targetRect);
1482 }
1483 else if (pScreen->pvScreenBitmap)
1484 {
1485 /* Copy the screen target surface to the memory buffer. */
1486 VMSVGA3D_MAPPED_SURFACE map;
1487 rc = vmsvga3dSurfaceMap(pThisCC, &entryScreenTarget.image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);
1488 if (RT_SUCCESS(rc))
1489 {
1490 uint8_t const *pu8Src = (uint8_t *)map.pvData
1491 + targetRect.x * map.cbPixel
1492 + targetRect.y * map.cbRowPitch;
1493 uint8_t *pu8Dst = (uint8_t *)pScreen->pvScreenBitmap
1494 + targetRect.x * map.cbPixel
1495 + targetRect.y * map.box.w * map.cbPixel;
1496 for (uint32_t y = 0; y < targetRect.h; ++y)
1497 {
1498 memcpy(pu8Dst, pu8Src, targetRect.w * map.cbPixel);
1499
1500 pu8Src += map.cbRowPitch;
1501 pu8Dst += map.box.w * map.cbPixel;
1502 }
1503
1504 vmsvga3dSurfaceUnmap(pThisCC, &entryScreenTarget.image, &map, /* fWritten = */ false);
1505
1506 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->rect.x, pCmd->rect.y, pCmd->rect.w, pCmd->rect.h);
1507 }
1508 else
1509 AssertFailed();
1510 }
1511 }
1512 }
1513 }
1514 }
1515}
1516
1517
1518/* SVGA_3D_CMD_DEFINE_GB_MOB64 1135 */
1519static void vmsvga3dCmdDefineGBMob64(PVGASTATECC pThisCC, SVGA3dCmdDefineGBMob64 const *pCmd)
1520{
1521// ASMBreakpoint();
1522 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1523
1524 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1525
1526 /* Maybe just update the OTable and create Gbo when the MOB is actually accessed? */
1527 /* Allocate a structure for the MOB. */
1528 PVMSVGAMOB pMob = (PVMSVGAMOB)RTMemAllocZ(sizeof(*pMob));
1529 AssertPtrReturnVoid(pMob);
1530
1531 int rc = vmsvgaR3MobCreate(pSvgaR3State, pCmd->ptDepth, pCmd->base, pCmd->sizeInBytes, pCmd->mobid, /*fGCPhys64=*/ true, pMob);
1532 if (RT_SUCCESS(rc))
1533 {
1534 return;
1535 }
1536
1537 RTMemFree(pMob);
1538}
1539
1540
1541/** @def VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
1542 * Check that the 3D command has at least a_cbMin of payload bytes after the
1543 * header. Will break out of the switch if it doesn't.
1544 */
1545# define VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(a_cbMin) \
1546 if (1) { \
1547 AssertMsgBreak(cbCmd >= (a_cbMin), ("size=%#x a_cbMin=%#zx\n", cbCmd, (size_t)(a_cbMin))); \
1548 RT_UNTRUSTED_VALIDATED_FENCE(); \
1549 } else do {} while (0)
1550
1551# define VMSVGA_3D_CMD_NOTIMPL() \
1552 if (1) { \
1553 AssertMsgFailed(("Not implemented %d %s\n", enmCmdId, vmsvgaR3FifoCmdToString(enmCmdId))); \
1554 } else do {} while (0)
1555
1556/** SVGA_3D_CMD_* handler.
1557 * This function parses the command and calls the corresponding command handler.
1558 *
1559 * @param pThis The shared VGA/VMSVGA state.
1560 * @param pThisCC The VGA/VMSVGA state for the current context.
1561 * @param enmCmdId SVGA_3D_CMD_* command identifier.
1562 * @param cbCmd Size of the command in bytes.
1563 * @param pvCmd Pointer to the command.
1564 * @returns VBox status code if an error was detected parsing a command.
1565 */
1566int vmsvgaR3Process3dCmd(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifo3dCmdId enmCmdId, uint32_t cbCmd, void const *pvCmd)
1567{
1568 int rcParse = VINF_SUCCESS;
1569 PVMSVGAR3STATE pSvgaR3State = pThisCC->svga.pSvgaR3State;
1570
1571 switch (enmCmdId)
1572 {
1573 case SVGA_3D_CMD_SURFACE_DEFINE:
1574 {
1575 SVGA3dCmdDefineSurface *pCmd = (SVGA3dCmdDefineSurface *)pvCmd;
1576 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1577 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefine);
1578
1579 SVGA3dCmdDefineSurface_v2 cmd;
1580 cmd.sid = pCmd->sid;
1581 cmd.surfaceFlags = pCmd->surfaceFlags;
1582 cmd.format = pCmd->format;
1583 memcpy(cmd.face, pCmd->face, sizeof(cmd.face));
1584 cmd.multisampleCount = 0;
1585 cmd.autogenFilter = SVGA3D_TEX_FILTER_NONE;
1586
1587 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
1588 vmsvga3dCmdDefineSurface(pThisCC, &cmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
1589# ifdef DEBUG_GMR_ACCESS
1590 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
1591# endif
1592 break;
1593 }
1594
1595 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
1596 {
1597 SVGA3dCmdDefineSurface_v2 *pCmd = (SVGA3dCmdDefineSurface_v2 *)pvCmd;
1598 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1599 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefineV2);
1600
1601 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
1602 vmsvga3dCmdDefineSurface(pThisCC, pCmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
1603# ifdef DEBUG_GMR_ACCESS
1604 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
1605# endif
1606 break;
1607 }
1608
1609 case SVGA_3D_CMD_SURFACE_DESTROY:
1610 {
1611 SVGA3dCmdDestroySurface *pCmd = (SVGA3dCmdDestroySurface *)pvCmd;
1612 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1613 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDestroy);
1614
1615 vmsvga3dSurfaceDestroy(pThisCC, pCmd->sid);
1616 break;
1617 }
1618
1619 case SVGA_3D_CMD_SURFACE_COPY:
1620 {
1621 SVGA3dCmdSurfaceCopy *pCmd = (SVGA3dCmdSurfaceCopy *)pvCmd;
1622 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1623 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceCopy);
1624
1625 uint32_t const cCopyBoxes = (cbCmd - sizeof(pCmd)) / sizeof(SVGA3dCopyBox);
1626 vmsvga3dSurfaceCopy(pThisCC, pCmd->dest, pCmd->src, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
1627 break;
1628 }
1629
1630 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
1631 {
1632 SVGA3dCmdSurfaceStretchBlt *pCmd = (SVGA3dCmdSurfaceStretchBlt *)pvCmd;
1633 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1634 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceStretchBlt);
1635
1636 vmsvga3dSurfaceStretchBlt(pThis, pThisCC, &pCmd->dest, &pCmd->boxDest,
1637 &pCmd->src, &pCmd->boxSrc, pCmd->mode);
1638 break;
1639 }
1640
1641 case SVGA_3D_CMD_SURFACE_DMA:
1642 {
1643 SVGA3dCmdSurfaceDMA *pCmd = (SVGA3dCmdSurfaceDMA *)pvCmd;
1644 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1645 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDma);
1646
1647 uint64_t u64NanoTS = 0;
1648 if (LogRelIs3Enabled())
1649 u64NanoTS = RTTimeNanoTS();
1650 uint32_t const cCopyBoxes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyBox);
1651 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
1652 vmsvga3dSurfaceDMA(pThis, pThisCC, pCmd->guest, pCmd->host, pCmd->transfer,
1653 cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
1654 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
1655 if (LogRelIs3Enabled())
1656 {
1657 if (cCopyBoxes)
1658 {
1659 SVGA3dCopyBox *pFirstBox = (SVGA3dCopyBox *)(pCmd + 1);
1660 LogRel3(("VMSVGA: SURFACE_DMA: %d us %d boxes %d,%d %dx%d%s\n",
1661 (RTTimeNanoTS() - u64NanoTS) / 1000ULL, cCopyBoxes,
1662 pFirstBox->x, pFirstBox->y, pFirstBox->w, pFirstBox->h,
1663 pCmd->transfer == SVGA3D_READ_HOST_VRAM ? " readback!!!" : ""));
1664 }
1665 }
1666 break;
1667 }
1668
1669 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
1670 {
1671 SVGA3dCmdBlitSurfaceToScreen *pCmd = (SVGA3dCmdBlitSurfaceToScreen *)pvCmd;
1672 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1673 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceScreen);
1674
1675 static uint64_t u64FrameStartNanoTS = 0;
1676 static uint64_t u64ElapsedPerSecNano = 0;
1677 static int cFrames = 0;
1678 uint64_t u64NanoTS = 0;
1679 if (LogRelIs3Enabled())
1680 u64NanoTS = RTTimeNanoTS();
1681 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGASignedRect);
1682 STAM_REL_PROFILE_START(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
1683 vmsvga3dSurfaceBlitToScreen(pThis, pThisCC, pCmd->destScreenId, pCmd->destRect, pCmd->srcImage,
1684 pCmd->srcRect, cRects, (SVGASignedRect *)(pCmd + 1));
1685 STAM_REL_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
1686 if (LogRelIs3Enabled())
1687 {
1688 uint64_t u64ElapsedNano = RTTimeNanoTS() - u64NanoTS;
1689 u64ElapsedPerSecNano += u64ElapsedNano;
1690
1691 SVGASignedRect *pFirstRect = cRects ? (SVGASignedRect *)(pCmd + 1) : &pCmd->destRect;
1692 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: %d us %d rects %d,%d %dx%d\n",
1693 (u64ElapsedNano) / 1000ULL, cRects,
1694 pFirstRect->left, pFirstRect->top,
1695 pFirstRect->right - pFirstRect->left, pFirstRect->bottom - pFirstRect->top));
1696
1697 ++cFrames;
1698 if (u64NanoTS - u64FrameStartNanoTS >= UINT64_C(1000000000))
1699 {
1700 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: FPS %d, elapsed %llu us\n",
1701 cFrames, u64ElapsedPerSecNano / 1000ULL));
1702 u64FrameStartNanoTS = u64NanoTS;
1703 cFrames = 0;
1704 u64ElapsedPerSecNano = 0;
1705 }
1706 }
1707 break;
1708 }
1709
1710 case SVGA_3D_CMD_CONTEXT_DEFINE:
1711 {
1712 SVGA3dCmdDefineContext *pCmd = (SVGA3dCmdDefineContext *)pvCmd;
1713 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1714 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDefine);
1715
1716 vmsvga3dContextDefine(pThisCC, pCmd->cid);
1717 break;
1718 }
1719
1720 case SVGA_3D_CMD_CONTEXT_DESTROY:
1721 {
1722 SVGA3dCmdDestroyContext *pCmd = (SVGA3dCmdDestroyContext *)pvCmd;
1723 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1724 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDestroy);
1725
1726 vmsvga3dContextDestroy(pThisCC, pCmd->cid);
1727 break;
1728 }
1729
1730 case SVGA_3D_CMD_SETTRANSFORM:
1731 {
1732 SVGA3dCmdSetTransform *pCmd = (SVGA3dCmdSetTransform *)pvCmd;
1733 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1734 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTransform);
1735
1736 vmsvga3dSetTransform(pThisCC, pCmd->cid, pCmd->type, pCmd->matrix);
1737 break;
1738 }
1739
1740 case SVGA_3D_CMD_SETZRANGE:
1741 {
1742 SVGA3dCmdSetZRange *pCmd = (SVGA3dCmdSetZRange *)pvCmd;
1743 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1744 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetZRange);
1745
1746 vmsvga3dSetZRange(pThisCC, pCmd->cid, pCmd->zRange);
1747 break;
1748 }
1749
1750 case SVGA_3D_CMD_SETRENDERSTATE:
1751 {
1752 SVGA3dCmdSetRenderState *pCmd = (SVGA3dCmdSetRenderState *)pvCmd;
1753 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1754 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderState);
1755
1756 uint32_t const cRenderStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRenderState);
1757 vmsvga3dSetRenderState(pThisCC, pCmd->cid, cRenderStates, (SVGA3dRenderState *)(pCmd + 1));
1758 break;
1759 }
1760
1761 case SVGA_3D_CMD_SETRENDERTARGET:
1762 {
1763 SVGA3dCmdSetRenderTarget *pCmd = (SVGA3dCmdSetRenderTarget *)pvCmd;
1764 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1765 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderTarget);
1766
1767 vmsvga3dSetRenderTarget(pThisCC, pCmd->cid, pCmd->type, pCmd->target);
1768 break;
1769 }
1770
1771 case SVGA_3D_CMD_SETTEXTURESTATE:
1772 {
1773 SVGA3dCmdSetTextureState *pCmd = (SVGA3dCmdSetTextureState *)pvCmd;
1774 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1775 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTextureState);
1776
1777 uint32_t const cTextureStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dTextureState);
1778 vmsvga3dSetTextureState(pThisCC, pCmd->cid, cTextureStates, (SVGA3dTextureState *)(pCmd + 1));
1779 break;
1780 }
1781
1782 case SVGA_3D_CMD_SETMATERIAL:
1783 {
1784 SVGA3dCmdSetMaterial *pCmd = (SVGA3dCmdSetMaterial *)pvCmd;
1785 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1786 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetMaterial);
1787
1788 vmsvga3dSetMaterial(pThisCC, pCmd->cid, pCmd->face, &pCmd->material);
1789 break;
1790 }
1791
1792 case SVGA_3D_CMD_SETLIGHTDATA:
1793 {
1794 SVGA3dCmdSetLightData *pCmd = (SVGA3dCmdSetLightData *)pvCmd;
1795 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1796 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightData);
1797
1798 vmsvga3dSetLightData(pThisCC, pCmd->cid, pCmd->index, &pCmd->data);
1799 break;
1800 }
1801
1802 case SVGA_3D_CMD_SETLIGHTENABLED:
1803 {
1804 SVGA3dCmdSetLightEnabled *pCmd = (SVGA3dCmdSetLightEnabled *)pvCmd;
1805 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1806 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightEnable);
1807
1808 vmsvga3dSetLightEnabled(pThisCC, pCmd->cid, pCmd->index, pCmd->enabled);
1809 break;
1810 }
1811
1812 case SVGA_3D_CMD_SETVIEWPORT:
1813 {
1814 SVGA3dCmdSetViewport *pCmd = (SVGA3dCmdSetViewport *)pvCmd;
1815 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1816 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetViewPort);
1817
1818 vmsvga3dSetViewPort(pThisCC, pCmd->cid, &pCmd->rect);
1819 break;
1820 }
1821
1822 case SVGA_3D_CMD_SETCLIPPLANE:
1823 {
1824 SVGA3dCmdSetClipPlane *pCmd = (SVGA3dCmdSetClipPlane *)pvCmd;
1825 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1826 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetClipPlane);
1827
1828 vmsvga3dSetClipPlane(pThisCC, pCmd->cid, pCmd->index, pCmd->plane);
1829 break;
1830 }
1831
1832 case SVGA_3D_CMD_CLEAR:
1833 {
1834 SVGA3dCmdClear *pCmd = (SVGA3dCmdClear *)pvCmd;
1835 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1836 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dClear);
1837
1838 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRect);
1839 vmsvga3dCommandClear(pThisCC, pCmd->cid, pCmd->clearFlag, pCmd->color, pCmd->depth, pCmd->stencil, cRects, (SVGA3dRect *)(pCmd + 1));
1840 break;
1841 }
1842
1843 case SVGA_3D_CMD_PRESENT:
1844 case SVGA_3D_CMD_PRESENT_READBACK: /** @todo SVGA_3D_CMD_PRESENT_READBACK isn't quite the same as present... */
1845 {
1846 SVGA3dCmdPresent *pCmd = (SVGA3dCmdPresent *)pvCmd;
1847 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1848 if (enmCmdId == SVGA_3D_CMD_PRESENT)
1849 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresent);
1850 else
1851 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresentReadBack);
1852
1853 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyRect);
1854 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
1855 vmsvga3dCommandPresent(pThis, pThisCC, pCmd->sid, cRects, (SVGA3dCopyRect *)(pCmd + 1));
1856 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
1857 break;
1858 }
1859
1860 case SVGA_3D_CMD_SHADER_DEFINE:
1861 {
1862 SVGA3dCmdDefineShader *pCmd = (SVGA3dCmdDefineShader *)pvCmd;
1863 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1864 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDefine);
1865
1866 uint32_t const cbData = (cbCmd - sizeof(*pCmd));
1867 vmsvga3dShaderDefine(pThisCC, pCmd->cid, pCmd->shid, pCmd->type, cbData, (uint32_t *)(pCmd + 1));
1868 break;
1869 }
1870
1871 case SVGA_3D_CMD_SHADER_DESTROY:
1872 {
1873 SVGA3dCmdDestroyShader *pCmd = (SVGA3dCmdDestroyShader *)pvCmd;
1874 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1875 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDestroy);
1876
1877 vmsvga3dShaderDestroy(pThisCC, pCmd->cid, pCmd->shid, pCmd->type);
1878 break;
1879 }
1880
1881 case SVGA_3D_CMD_SET_SHADER:
1882 {
1883 SVGA3dCmdSetShader *pCmd = (SVGA3dCmdSetShader *)pvCmd;
1884 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1885 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShader);
1886
1887 vmsvga3dShaderSet(pThisCC, NULL, pCmd->cid, pCmd->type, pCmd->shid);
1888 break;
1889 }
1890
1891 case SVGA_3D_CMD_SET_SHADER_CONST:
1892 {
1893 SVGA3dCmdSetShaderConst *pCmd = (SVGA3dCmdSetShaderConst *)pvCmd;
1894 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1895 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShaderConst);
1896
1897 uint32_t const cRegisters = (cbCmd - sizeof(*pCmd)) / sizeof(pCmd->values) + 1;
1898 vmsvga3dShaderSetConst(pThisCC, pCmd->cid, pCmd->reg, pCmd->type, pCmd->ctype, cRegisters, pCmd->values);
1899 break;
1900 }
1901
1902 case SVGA_3D_CMD_DRAW_PRIMITIVES:
1903 {
1904 SVGA3dCmdDrawPrimitives *pCmd = (SVGA3dCmdDrawPrimitives *)pvCmd;
1905 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1906 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDrawPrimitives);
1907
1908 ASSERT_GUEST_STMT_BREAK(pCmd->numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES, rcParse = VERR_INVALID_PARAMETER);
1909 ASSERT_GUEST_STMT_BREAK(pCmd->numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, rcParse = VERR_INVALID_PARAMETER);
1910 uint32_t const cbRangesAndVertexDecls = pCmd->numVertexDecls * sizeof(SVGA3dVertexDecl)
1911 + pCmd->numRanges * sizeof(SVGA3dPrimitiveRange);
1912 ASSERT_GUEST_STMT_BREAK(cbRangesAndVertexDecls <= cbCmd - sizeof(*pCmd), rcParse = VERR_INVALID_PARAMETER);
1913
1914 uint32_t const cVertexDivisor = (cbCmd - sizeof(*pCmd) - cbRangesAndVertexDecls) / sizeof(uint32_t);
1915 ASSERT_GUEST_STMT_BREAK(!cVertexDivisor || cVertexDivisor == pCmd->numVertexDecls, rcParse = VERR_INVALID_PARAMETER);
1916 RT_UNTRUSTED_VALIDATED_FENCE();
1917
1918 SVGA3dVertexDecl *pVertexDecl = (SVGA3dVertexDecl *)(pCmd + 1);
1919 SVGA3dPrimitiveRange *pNumRange = (SVGA3dPrimitiveRange *)&pVertexDecl[pCmd->numVertexDecls];
1920 SVGA3dVertexDivisor *pVertexDivisor = cVertexDivisor ? (SVGA3dVertexDivisor *)&pNumRange[pCmd->numRanges] : NULL;
1921
1922 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
1923 vmsvga3dDrawPrimitives(pThisCC, pCmd->cid, pCmd->numVertexDecls, pVertexDecl, pCmd->numRanges,
1924 pNumRange, cVertexDivisor, pVertexDivisor);
1925 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
1926 break;
1927 }
1928
1929 case SVGA_3D_CMD_SETSCISSORRECT:
1930 {
1931 SVGA3dCmdSetScissorRect *pCmd = (SVGA3dCmdSetScissorRect *)pvCmd;
1932 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1933 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetScissorRect);
1934
1935 vmsvga3dSetScissorRect(pThisCC, pCmd->cid, &pCmd->rect);
1936 break;
1937 }
1938
1939 case SVGA_3D_CMD_BEGIN_QUERY:
1940 {
1941 SVGA3dCmdBeginQuery *pCmd = (SVGA3dCmdBeginQuery *)pvCmd;
1942 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1943 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dBeginQuery);
1944
1945 vmsvga3dQueryBegin(pThisCC, pCmd->cid, pCmd->type);
1946 break;
1947 }
1948
1949 case SVGA_3D_CMD_END_QUERY:
1950 {
1951 SVGA3dCmdEndQuery *pCmd = (SVGA3dCmdEndQuery *)pvCmd;
1952 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1953 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dEndQuery);
1954
1955 vmsvga3dQueryEnd(pThisCC, pCmd->cid, pCmd->type, pCmd->guestResult);
1956 break;
1957 }
1958
1959 case SVGA_3D_CMD_WAIT_FOR_QUERY:
1960 {
1961 SVGA3dCmdWaitForQuery *pCmd = (SVGA3dCmdWaitForQuery *)pvCmd;
1962 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1963 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dWaitForQuery);
1964
1965 vmsvga3dQueryWait(pThis, pThisCC, pCmd->cid, pCmd->type, pCmd->guestResult);
1966 break;
1967 }
1968
1969 case SVGA_3D_CMD_GENERATE_MIPMAPS:
1970 {
1971 SVGA3dCmdGenerateMipmaps *pCmd = (SVGA3dCmdGenerateMipmaps *)pvCmd;
1972 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1973 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dGenerateMipmaps);
1974
1975 vmsvga3dGenerateMipmaps(pThisCC, pCmd->sid, pCmd->filter);
1976 break;
1977 }
1978
1979 case SVGA_3D_CMD_ACTIVATE_SURFACE:
1980 /* context id + surface id? */
1981 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dActivateSurface);
1982 break;
1983
1984 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
1985 /* context id + surface id? */
1986 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDeactivateSurface);
1987 break;
1988
1989 /*
1990 *
1991 * VPGU10: SVGA_CAP_GBOBJECTS+ commands.
1992 *
1993 */
1994 case SVGA_3D_CMD_SCREEN_DMA:
1995 {
1996 SVGA3dCmdScreenDMA *pCmd = (SVGA3dCmdScreenDMA *)pvCmd;
1997 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
1998 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
1999 break;
2000 }
2001
2002 case SVGA_3D_CMD_DEAD1:
2003 case SVGA_3D_CMD_DEAD2:
2004 {
2005 VMSVGA_3D_CMD_NOTIMPL();
2006 break;
2007 }
2008
2009 case SVGA_3D_CMD_LOGICOPS_BITBLT:
2010 {
2011 SVGA3dCmdLogicOpsBitBlt *pCmd = (SVGA3dCmdLogicOpsBitBlt *)pvCmd;
2012 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2013 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2014 break;
2015 }
2016
2017 case SVGA_3D_CMD_LOGICOPS_TRANSBLT:
2018 {
2019 SVGA3dCmdLogicOpsTransBlt *pCmd = (SVGA3dCmdLogicOpsTransBlt *)pvCmd;
2020 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2021 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2022 break;
2023 }
2024
2025 case SVGA_3D_CMD_LOGICOPS_STRETCHBLT:
2026 {
2027 SVGA3dCmdLogicOpsStretchBlt *pCmd = (SVGA3dCmdLogicOpsStretchBlt *)pvCmd;
2028 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2029 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2030 break;
2031 }
2032
2033 case SVGA_3D_CMD_LOGICOPS_COLORFILL:
2034 {
2035 SVGA3dCmdLogicOpsColorFill *pCmd = (SVGA3dCmdLogicOpsColorFill *)pvCmd;
2036 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2037 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2038 break;
2039 }
2040
2041 case SVGA_3D_CMD_LOGICOPS_ALPHABLEND:
2042 {
2043 SVGA3dCmdLogicOpsAlphaBlend *pCmd = (SVGA3dCmdLogicOpsAlphaBlend *)pvCmd;
2044 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2045 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2046 break;
2047 }
2048
2049 case SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND:
2050 {
2051 SVGA3dCmdLogicOpsClearTypeBlend *pCmd = (SVGA3dCmdLogicOpsClearTypeBlend *)pvCmd;
2052 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2053 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2054 break;
2055 }
2056
2057 case SVGA_3D_CMD_SET_OTABLE_BASE:
2058 {
2059 SVGA3dCmdSetOTableBase *pCmd = (SVGA3dCmdSetOTableBase *)pvCmd;
2060 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2061 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2062 break;
2063 }
2064
2065 case SVGA_3D_CMD_READBACK_OTABLE:
2066 {
2067 SVGA3dCmdReadbackOTable *pCmd = (SVGA3dCmdReadbackOTable *)pvCmd;
2068 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2069 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2070 break;
2071 }
2072
2073 case SVGA_3D_CMD_DEFINE_GB_MOB:
2074 {
2075 SVGA3dCmdDefineGBMob *pCmd = (SVGA3dCmdDefineGBMob *)pvCmd;
2076 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2077 vmsvga3dCmdDefineGBMob(pThisCC, pCmd);
2078 break;
2079 }
2080
2081 case SVGA_3D_CMD_DESTROY_GB_MOB:
2082 {
2083 SVGA3dCmdDestroyGBMob *pCmd = (SVGA3dCmdDestroyGBMob *)pvCmd;
2084 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2085 vmsvga3dCmdDestroyGBMob(pThisCC, pCmd);
2086 break;
2087 }
2088
2089 case SVGA_3D_CMD_DEAD3:
2090 {
2091 VMSVGA_3D_CMD_NOTIMPL();
2092 break;
2093 }
2094
2095 case SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING:
2096 {
2097 SVGA3dCmdUpdateGBMobMapping *pCmd = (SVGA3dCmdUpdateGBMobMapping *)pvCmd;
2098 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2099 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2100 break;
2101 }
2102
2103 case SVGA_3D_CMD_DEFINE_GB_SURFACE:
2104 {
2105 SVGA3dCmdDefineGBSurface *pCmd = (SVGA3dCmdDefineGBSurface *)pvCmd;
2106 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2107 vmsvga3dCmdDefineGBSurface(pThisCC, pCmd);
2108 break;
2109 }
2110
2111 case SVGA_3D_CMD_DESTROY_GB_SURFACE:
2112 {
2113 SVGA3dCmdDestroyGBSurface *pCmd = (SVGA3dCmdDestroyGBSurface *)pvCmd;
2114 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2115 vmsvga3dCmdDestroyGBSurface(pThisCC, pCmd);
2116 break;
2117 }
2118
2119 case SVGA_3D_CMD_BIND_GB_SURFACE:
2120 {
2121 SVGA3dCmdBindGBSurface *pCmd = (SVGA3dCmdBindGBSurface *)pvCmd;
2122 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2123 vmsvga3dCmdBindGBSurface(pThisCC, pCmd);
2124 break;
2125 }
2126
2127 case SVGA_3D_CMD_COND_BIND_GB_SURFACE:
2128 {
2129 SVGA3dCmdCondBindGBSurface *pCmd = (SVGA3dCmdCondBindGBSurface *)pvCmd;
2130 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2131 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2132 break;
2133 }
2134
2135 case SVGA_3D_CMD_UPDATE_GB_IMAGE:
2136 {
2137 SVGA3dCmdUpdateGBImage *pCmd = (SVGA3dCmdUpdateGBImage *)pvCmd;
2138 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2139 vmsvga3dCmdUpdateGBImage(pThisCC, pCmd);
2140 break;
2141 }
2142
2143 case SVGA_3D_CMD_UPDATE_GB_SURFACE:
2144 {
2145 SVGA3dCmdUpdateGBSurface *pCmd = (SVGA3dCmdUpdateGBSurface *)pvCmd;
2146 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2147 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2148 break;
2149 }
2150
2151 case SVGA_3D_CMD_READBACK_GB_IMAGE:
2152 {
2153 SVGA3dCmdReadbackGBImage *pCmd = (SVGA3dCmdReadbackGBImage *)pvCmd;
2154 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2155 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2156 break;
2157 }
2158
2159 case SVGA_3D_CMD_READBACK_GB_SURFACE:
2160 {
2161 SVGA3dCmdReadbackGBSurface *pCmd = (SVGA3dCmdReadbackGBSurface *)pvCmd;
2162 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2163 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2164 break;
2165 }
2166
2167 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE:
2168 {
2169 SVGA3dCmdInvalidateGBImage *pCmd = (SVGA3dCmdInvalidateGBImage *)pvCmd;
2170 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2171 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2172 break;
2173 }
2174
2175 case SVGA_3D_CMD_INVALIDATE_GB_SURFACE:
2176 {
2177 SVGA3dCmdInvalidateGBSurface *pCmd = (SVGA3dCmdInvalidateGBSurface *)pvCmd;
2178 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2179 vmsvga3dCmdInvalidateGBSurface(pThisCC, pCmd);
2180 break;
2181 }
2182
2183 case SVGA_3D_CMD_DEFINE_GB_CONTEXT:
2184 {
2185 SVGA3dCmdDefineGBContext *pCmd = (SVGA3dCmdDefineGBContext *)pvCmd;
2186 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2187 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2188 break;
2189 }
2190
2191 case SVGA_3D_CMD_DESTROY_GB_CONTEXT:
2192 {
2193 SVGA3dCmdDestroyGBContext *pCmd = (SVGA3dCmdDestroyGBContext *)pvCmd;
2194 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2195 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2196 break;
2197 }
2198
2199 case SVGA_3D_CMD_BIND_GB_CONTEXT:
2200 {
2201 SVGA3dCmdBindGBContext *pCmd = (SVGA3dCmdBindGBContext *)pvCmd;
2202 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2203 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2204 break;
2205 }
2206
2207 case SVGA_3D_CMD_READBACK_GB_CONTEXT:
2208 {
2209 SVGA3dCmdReadbackGBContext *pCmd = (SVGA3dCmdReadbackGBContext *)pvCmd;
2210 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2211 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2212 break;
2213 }
2214
2215 case SVGA_3D_CMD_INVALIDATE_GB_CONTEXT:
2216 {
2217 SVGA3dCmdInvalidateGBContext *pCmd = (SVGA3dCmdInvalidateGBContext *)pvCmd;
2218 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2219 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2220 break;
2221 }
2222
2223 case SVGA_3D_CMD_DEFINE_GB_SHADER:
2224 {
2225 SVGA3dCmdDefineGBShader *pCmd = (SVGA3dCmdDefineGBShader *)pvCmd;
2226 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2227 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2228 break;
2229 }
2230
2231 case SVGA_3D_CMD_DESTROY_GB_SHADER:
2232 {
2233 SVGA3dCmdDestroyGBShader *pCmd = (SVGA3dCmdDestroyGBShader *)pvCmd;
2234 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2235 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2236 break;
2237 }
2238
2239 case SVGA_3D_CMD_BIND_GB_SHADER:
2240 {
2241 SVGA3dCmdBindGBShader *pCmd = (SVGA3dCmdBindGBShader *)pvCmd;
2242 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2243 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2244 break;
2245 }
2246
2247 case SVGA_3D_CMD_SET_OTABLE_BASE64:
2248 {
2249 SVGA3dCmdSetOTableBase64 *pCmd = (SVGA3dCmdSetOTableBase64 *)pvCmd;
2250 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2251 vmsvga3dCmdSetOTableBase64(pThisCC, pCmd);
2252 break;
2253 }
2254
2255 case SVGA_3D_CMD_BEGIN_GB_QUERY:
2256 {
2257 SVGA3dCmdBeginGBQuery *pCmd = (SVGA3dCmdBeginGBQuery *)pvCmd;
2258 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2259 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2260 break;
2261 }
2262
2263 case SVGA_3D_CMD_END_GB_QUERY:
2264 {
2265 SVGA3dCmdEndGBQuery *pCmd = (SVGA3dCmdEndGBQuery *)pvCmd;
2266 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2267 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2268 break;
2269 }
2270
2271 case SVGA_3D_CMD_WAIT_FOR_GB_QUERY:
2272 {
2273 SVGA3dCmdWaitForGBQuery *pCmd = (SVGA3dCmdWaitForGBQuery *)pvCmd;
2274 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2275 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2276 break;
2277 }
2278
2279 case SVGA_3D_CMD_NOP:
2280 {
2281 /* Apparently there is nothing to do. */
2282 break;
2283 }
2284
2285 case SVGA_3D_CMD_ENABLE_GART:
2286 {
2287 SVGA3dCmdEnableGart *pCmd = (SVGA3dCmdEnableGart *)pvCmd;
2288 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2289 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2290 break;
2291 }
2292
2293 case SVGA_3D_CMD_DISABLE_GART:
2294 {
2295 /* No corresponding SVGA3dCmd structure. */
2296 VMSVGA_3D_CMD_NOTIMPL();
2297 break;
2298 }
2299
2300 case SVGA_3D_CMD_MAP_MOB_INTO_GART:
2301 {
2302 SVGA3dCmdMapMobIntoGart *pCmd = (SVGA3dCmdMapMobIntoGart *)pvCmd;
2303 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2304 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2305 break;
2306 }
2307
2308 case SVGA_3D_CMD_UNMAP_GART_RANGE:
2309 {
2310 SVGA3dCmdUnmapGartRange *pCmd = (SVGA3dCmdUnmapGartRange *)pvCmd;
2311 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2312 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2313 break;
2314 }
2315
2316 case SVGA_3D_CMD_DEFINE_GB_SCREENTARGET:
2317 {
2318 SVGA3dCmdDefineGBScreenTarget *pCmd = (SVGA3dCmdDefineGBScreenTarget *)pvCmd;
2319 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2320 vmsvga3dCmdDefineGBScreenTarget(pThis, pThisCC, pCmd);
2321 break;
2322 }
2323
2324 case SVGA_3D_CMD_DESTROY_GB_SCREENTARGET:
2325 {
2326 SVGA3dCmdDestroyGBScreenTarget *pCmd = (SVGA3dCmdDestroyGBScreenTarget *)pvCmd;
2327 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2328 vmsvga3dCmdDestroyGBScreenTarget(pThis, pThisCC, pCmd);
2329 break;
2330 }
2331
2332 case SVGA_3D_CMD_BIND_GB_SCREENTARGET:
2333 {
2334 SVGA3dCmdBindGBScreenTarget *pCmd = (SVGA3dCmdBindGBScreenTarget *)pvCmd;
2335 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2336 vmsvga3dCmdBindGBScreenTarget(pThisCC, pCmd);
2337 break;
2338 }
2339
2340 case SVGA_3D_CMD_UPDATE_GB_SCREENTARGET:
2341 {
2342 SVGA3dCmdUpdateGBScreenTarget *pCmd = (SVGA3dCmdUpdateGBScreenTarget *)pvCmd;
2343 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2344 vmsvga3dCmdUpdateGBScreenTarget(pThisCC, pCmd);
2345 break;
2346 }
2347
2348 case SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL:
2349 {
2350 SVGA3dCmdReadbackGBImagePartial *pCmd = (SVGA3dCmdReadbackGBImagePartial *)pvCmd;
2351 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2352 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2353 break;
2354 }
2355
2356 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL:
2357 {
2358 SVGA3dCmdInvalidateGBImagePartial *pCmd = (SVGA3dCmdInvalidateGBImagePartial *)pvCmd;
2359 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2360 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2361 break;
2362 }
2363
2364 case SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE:
2365 {
2366 SVGA3dCmdSetGBShaderConstInline *pCmd = (SVGA3dCmdSetGBShaderConstInline *)pvCmd;
2367 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2368 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2369 break;
2370 }
2371
2372 case SVGA_3D_CMD_GB_SCREEN_DMA:
2373 {
2374 SVGA3dCmdGBScreenDMA *pCmd = (SVGA3dCmdGBScreenDMA *)pvCmd;
2375 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2376 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2377 break;
2378 }
2379
2380 case SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH:
2381 {
2382 SVGA3dCmdBindGBSurfaceWithPitch *pCmd = (SVGA3dCmdBindGBSurfaceWithPitch *)pvCmd;
2383 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2384 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2385 break;
2386 }
2387
2388 case SVGA_3D_CMD_GB_MOB_FENCE:
2389 {
2390 SVGA3dCmdGBMobFence *pCmd = (SVGA3dCmdGBMobFence *)pvCmd;
2391 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2392 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2393 break;
2394 }
2395
2396 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V2:
2397 {
2398 /// @todo SVGA3dCmdDefineGBSurface_v2 is not defined in Mesa 17 header. Mesa 20 has it.
2399 //SVGA3dCmdDefineGBSurface_v2 *pCmd = (SVGA3dCmdDefineGBSurface_v2 *)pvCmd;
2400 //VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2401 VMSVGA_3D_CMD_NOTIMPL();
2402 break;
2403 }
2404
2405 case SVGA_3D_CMD_DEFINE_GB_MOB64:
2406 {
2407 SVGA3dCmdDefineGBMob64 *pCmd = (SVGA3dCmdDefineGBMob64 *)pvCmd;
2408 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2409 vmsvga3dCmdDefineGBMob64(pThisCC, pCmd);
2410 break;
2411 }
2412
2413 case SVGA_3D_CMD_REDEFINE_GB_MOB64:
2414 {
2415 SVGA3dCmdRedefineGBMob64 *pCmd = (SVGA3dCmdRedefineGBMob64 *)pvCmd;
2416 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2417 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2418 break;
2419 }
2420
2421 case SVGA_3D_CMD_NOP_ERROR:
2422 {
2423 /* Apparently there is nothing to do. */
2424 break;
2425 }
2426
2427 case SVGA_3D_CMD_SET_VERTEX_STREAMS:
2428 {
2429 SVGA3dCmdSetVertexStreams *pCmd = (SVGA3dCmdSetVertexStreams *)pvCmd;
2430 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2431 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2432 break;
2433 }
2434
2435 case SVGA_3D_CMD_SET_VERTEX_DECLS:
2436 {
2437 SVGA3dCmdSetVertexDecls *pCmd = (SVGA3dCmdSetVertexDecls *)pvCmd;
2438 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2439 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2440 break;
2441 }
2442
2443 case SVGA_3D_CMD_SET_VERTEX_DIVISORS:
2444 {
2445 SVGA3dCmdSetVertexDivisors *pCmd = (SVGA3dCmdSetVertexDivisors *)pvCmd;
2446 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2447 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
2448 break;
2449 }
2450
2451 case SVGA_3D_CMD_DRAW:
2452 {
2453 /* No corresponding SVGA3dCmd structure. */
2454 VMSVGA_3D_CMD_NOTIMPL();
2455 break;
2456 }
2457
2458 case SVGA_3D_CMD_DRAW_INDEXED:
2459 {
2460 /* No corresponding SVGA3dCmd structure. */
2461 VMSVGA_3D_CMD_NOTIMPL();
2462 break;
2463 }
2464
2465 default:
2466 STAM_REL_COUNTER_INC(&pSvgaR3State->StatFifoUnkCmds);
2467 ASSERT_GUEST_MSG_FAILED(("enmCmdId=%d\n", enmCmdId));
2468 rcParse = VERR_NOT_IMPLEMENTED;
2469 break;
2470 }
2471
2472 return rcParse;
2473}
2474# undef VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
2475#endif /* VBOX_WITH_VMSVGA3D */
2476
2477
2478/*
2479 *
2480 * Handlers for FIFO commands.
2481 *
2482 * Every handler takes the following parameters:
2483 *
2484 * pThis The shared VGA/VMSVGA state.
2485 * pThisCC The VGA/VMSVGA state for ring-3.
2486 * pCmd The command data.
2487 */
2488
2489
2490/* SVGA_CMD_UPDATE */
2491void vmsvgaR3CmdUpdate(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdate const *pCmd)
2492{
2493 RT_NOREF(pThis);
2494 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2495
2496 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdate);
2497 Log(("SVGA_CMD_UPDATE %d,%d %dx%d\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height));
2498
2499 /** @todo Multiple screens? */
2500 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
2501 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
2502 return;
2503
2504 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
2505}
2506
2507
2508/* SVGA_CMD_UPDATE_VERBOSE */
2509void vmsvgaR3CmdUpdateVerbose(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdateVerbose const *pCmd)
2510{
2511 RT_NOREF(pThis);
2512 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2513
2514 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdateVerbose);
2515 Log(("SVGA_CMD_UPDATE_VERBOSE %d,%d %dx%d reason %#x\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height, pCmd->reason));
2516
2517 /** @todo Multiple screens? */
2518 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
2519 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
2520 return;
2521
2522 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
2523}
2524
2525
2526/* SVGA_CMD_RECT_FILL */
2527void vmsvgaR3CmdRectFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectFill const *pCmd)
2528{
2529 RT_NOREF(pThis, pCmd);
2530 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2531
2532 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectFill);
2533 Log(("SVGA_CMD_RECT_FILL %08X @ %d,%d (%dx%d)\n", pCmd->pixel, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
2534 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_RECT_FILL command ignored.\n"));
2535}
2536
2537
2538/* SVGA_CMD_RECT_COPY */
2539void vmsvgaR3CmdRectCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectCopy const *pCmd)
2540{
2541 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2542
2543 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectCopy);
2544 Log(("SVGA_CMD_RECT_COPY %d,%d -> %d,%d %dx%d\n", pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
2545
2546 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
2547 AssertPtrReturnVoid(pScreen);
2548
2549 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
2550 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
2551 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
2552 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
2553 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
2554 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
2555 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
2556
2557 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
2558 pCmd->width, pCmd->height, pThis->vram_size);
2559 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
2560}
2561
2562
2563/* SVGA_CMD_RECT_ROP_COPY */
2564void vmsvgaR3CmdRectRopCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectRopCopy const *pCmd)
2565{
2566 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2567
2568 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectRopCopy);
2569 Log(("SVGA_CMD_RECT_ROP_COPY %d,%d -> %d,%d %dx%d ROP %#X\n", pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height, pCmd->rop));
2570
2571 if (pCmd->rop != SVGA_ROP_COPY)
2572 {
2573 /* We only support the plain copy ROP which makes SVGA_CMD_RECT_ROP_COPY exactly the same
2574 * as SVGA_CMD_RECT_COPY. XFree86 4.1.0 and 4.2.0 drivers (driver version 10.4.0 and 10.7.0,
2575 * respectively) issue SVGA_CMD_RECT_ROP_COPY when SVGA_CAP_RECT_COPY is present even when
2576 * SVGA_CAP_RASTER_OP is not. However, the ROP will always be SVGA_ROP_COPY.
2577 */
2578 LogRelMax(4, ("VMSVGA: SVGA_CMD_RECT_ROP_COPY %d,%d -> %d,%d (%dx%d) ROP %X unsupported\n",
2579 pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height, pCmd->rop));
2580 return;
2581 }
2582
2583 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
2584 AssertPtrReturnVoid(pScreen);
2585
2586 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
2587 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
2588 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
2589 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
2590 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
2591 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
2592 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
2593
2594 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
2595 pCmd->width, pCmd->height, pThis->vram_size);
2596 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
2597}
2598
2599
2600/* SVGA_CMD_DISPLAY_CURSOR */
2601void vmsvgaR3CmdDisplayCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDisplayCursor const *pCmd)
2602{
2603 RT_NOREF(pThis, pCmd);
2604 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2605
2606 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDisplayCursor);
2607 Log(("SVGA_CMD_DISPLAY_CURSOR id=%d state=%d\n", pCmd->id, pCmd->state));
2608 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_DISPLAY_CURSOR command ignored.\n"));
2609}
2610
2611
2612/* SVGA_CMD_MOVE_CURSOR */
2613void vmsvgaR3CmdMoveCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdMoveCursor const *pCmd)
2614{
2615 RT_NOREF(pThis, pCmd);
2616 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2617
2618 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdMoveCursor);
2619 Log(("SVGA_CMD_MOVE_CURSOR to %d,%d\n", pCmd->pos.x, pCmd->pos.y));
2620 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_MOVE_CURSOR command ignored.\n"));
2621}
2622
2623
2624/* SVGA_CMD_DEFINE_CURSOR */
2625void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineCursor const *pCmd)
2626{
2627 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2628
2629 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineCursor);
2630 Log(("SVGA_CMD_DEFINE_CURSOR id=%d size (%dx%d) hotspot (%d,%d) andMaskDepth=%d xorMaskDepth=%d\n",
2631 pCmd->id, pCmd->width, pCmd->height, pCmd->hotspotX, pCmd->hotspotY, pCmd->andMaskDepth, pCmd->xorMaskDepth));
2632
2633 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
2634 ASSERT_GUEST_RETURN_VOID(pCmd->andMaskDepth <= 32);
2635 ASSERT_GUEST_RETURN_VOID(pCmd->xorMaskDepth <= 32);
2636 RT_UNTRUSTED_VALIDATED_FENCE();
2637
2638 uint32_t const cbSrcAndLine = RT_ALIGN_32(pCmd->width * (pCmd->andMaskDepth + (pCmd->andMaskDepth == 15)), 32) / 8;
2639 uint32_t const cbSrcAndMask = cbSrcAndLine * pCmd->height;
2640 uint32_t const cbSrcXorLine = RT_ALIGN_32(pCmd->width * (pCmd->xorMaskDepth + (pCmd->xorMaskDepth == 15)), 32) / 8;
2641
2642 uint8_t const *pbSrcAndMask = (uint8_t const *)(pCmd + 1);
2643 uint8_t const *pbSrcXorMask = (uint8_t const *)(pCmd + 1) + cbSrcAndMask;
2644
2645 uint32_t const cx = pCmd->width;
2646 uint32_t const cy = pCmd->height;
2647
2648 /*
2649 * Convert the input to 1-bit AND mask and a 32-bit BRGA XOR mask.
2650 * The AND data uses 8-bit aligned scanlines.
2651 * The XOR data must be starting on a 32-bit boundrary.
2652 */
2653 uint32_t cbDstAndLine = RT_ALIGN_32(cx, 8) / 8;
2654 uint32_t cbDstAndMask = cbDstAndLine * cy;
2655 uint32_t cbDstXorMask = cx * sizeof(uint32_t) * cy;
2656 uint32_t cbCopy = RT_ALIGN_32(cbDstAndMask, 4) + cbDstXorMask;
2657
2658 uint8_t *pbCopy = (uint8_t *)RTMemAlloc(cbCopy);
2659 AssertReturnVoid(pbCopy);
2660
2661 /* Convert the AND mask. */
2662 uint8_t *pbDst = pbCopy;
2663 uint8_t const *pbSrc = pbSrcAndMask;
2664 switch (pCmd->andMaskDepth)
2665 {
2666 case 1:
2667 if (cbSrcAndLine == cbDstAndLine)
2668 memcpy(pbDst, pbSrc, cbSrcAndLine * cy);
2669 else
2670 {
2671 Assert(cbSrcAndLine > cbDstAndLine); /* lines are dword alined in source, but only byte in destination. */
2672 for (uint32_t y = 0; y < cy; y++)
2673 {
2674 memcpy(pbDst, pbSrc, cbDstAndLine);
2675 pbDst += cbDstAndLine;
2676 pbSrc += cbSrcAndLine;
2677 }
2678 }
2679 break;
2680 /* Should take the XOR mask into account for the multi-bit AND mask. */
2681 case 8:
2682 for (uint32_t y = 0; y < cy; y++)
2683 {
2684 for (uint32_t x = 0; x < cx; )
2685 {
2686 uint8_t bDst = 0;
2687 uint8_t fBit = 0x80;
2688 do
2689 {
2690 uintptr_t const idxPal = pbSrc[x] * 3;
2691 if ((( pThis->last_palette[idxPal]
2692 | (pThis->last_palette[idxPal] >> 8)
2693 | (pThis->last_palette[idxPal] >> 16)) & 0xff) > 0xfc)
2694 bDst |= fBit;
2695 fBit >>= 1;
2696 x++;
2697 } while (x < cx && (x & 7));
2698 pbDst[(x - 1) / 8] = bDst;
2699 }
2700 pbDst += cbDstAndLine;
2701 pbSrc += cbSrcAndLine;
2702 }
2703 break;
2704 case 15:
2705 for (uint32_t y = 0; y < cy; y++)
2706 {
2707 for (uint32_t x = 0; x < cx; )
2708 {
2709 uint8_t bDst = 0;
2710 uint8_t fBit = 0x80;
2711 do
2712 {
2713 if ((pbSrc[x * 2] | (pbSrc[x * 2 + 1] & 0x7f)) >= 0xfc)
2714 bDst |= fBit;
2715 fBit >>= 1;
2716 x++;
2717 } while (x < cx && (x & 7));
2718 pbDst[(x - 1) / 8] = bDst;
2719 }
2720 pbDst += cbDstAndLine;
2721 pbSrc += cbSrcAndLine;
2722 }
2723 break;
2724 case 16:
2725 for (uint32_t y = 0; y < cy; y++)
2726 {
2727 for (uint32_t x = 0; x < cx; )
2728 {
2729 uint8_t bDst = 0;
2730 uint8_t fBit = 0x80;
2731 do
2732 {
2733 if ((pbSrc[x * 2] | pbSrc[x * 2 + 1]) >= 0xfc)
2734 bDst |= fBit;
2735 fBit >>= 1;
2736 x++;
2737 } while (x < cx && (x & 7));
2738 pbDst[(x - 1) / 8] = bDst;
2739 }
2740 pbDst += cbDstAndLine;
2741 pbSrc += cbSrcAndLine;
2742 }
2743 break;
2744 case 24:
2745 for (uint32_t y = 0; y < cy; y++)
2746 {
2747 for (uint32_t x = 0; x < cx; )
2748 {
2749 uint8_t bDst = 0;
2750 uint8_t fBit = 0x80;
2751 do
2752 {
2753 if ((pbSrc[x * 3] | pbSrc[x * 3 + 1] | pbSrc[x * 3 + 2]) >= 0xfc)
2754 bDst |= fBit;
2755 fBit >>= 1;
2756 x++;
2757 } while (x < cx && (x & 7));
2758 pbDst[(x - 1) / 8] = bDst;
2759 }
2760 pbDst += cbDstAndLine;
2761 pbSrc += cbSrcAndLine;
2762 }
2763 break;
2764 case 32:
2765 for (uint32_t y = 0; y < cy; y++)
2766 {
2767 for (uint32_t x = 0; x < cx; )
2768 {
2769 uint8_t bDst = 0;
2770 uint8_t fBit = 0x80;
2771 do
2772 {
2773 if ((pbSrc[x * 4] | pbSrc[x * 4 + 1] | pbSrc[x * 4 + 2] | pbSrc[x * 4 + 3]) >= 0xfc)
2774 bDst |= fBit;
2775 fBit >>= 1;
2776 x++;
2777 } while (x < cx && (x & 7));
2778 pbDst[(x - 1) / 8] = bDst;
2779 }
2780 pbDst += cbDstAndLine;
2781 pbSrc += cbSrcAndLine;
2782 }
2783 break;
2784 default:
2785 RTMemFreeZ(pbCopy, cbCopy);
2786 AssertFailedReturnVoid();
2787 }
2788
2789 /* Convert the XOR mask. */
2790 uint32_t *pu32Dst = (uint32_t *)(pbCopy + RT_ALIGN_32(cbDstAndMask, 4));
2791 pbSrc = pbSrcXorMask;
2792 switch (pCmd->xorMaskDepth)
2793 {
2794 case 1:
2795 for (uint32_t y = 0; y < cy; y++)
2796 {
2797 for (uint32_t x = 0; x < cx; )
2798 {
2799 /* most significant bit is the left most one. */
2800 uint8_t bSrc = pbSrc[x / 8];
2801 do
2802 {
2803 *pu32Dst++ = bSrc & 0x80 ? UINT32_C(0x00ffffff) : 0;
2804 bSrc <<= 1;
2805 x++;
2806 } while ((x & 7) && x < cx);
2807 }
2808 pbSrc += cbSrcXorLine;
2809 }
2810 break;
2811 case 8:
2812 for (uint32_t y = 0; y < cy; y++)
2813 {
2814 for (uint32_t x = 0; x < cx; x++)
2815 {
2816 uint32_t u = pThis->last_palette[pbSrc[x]];
2817 *pu32Dst++ = u;//RT_MAKE_U32_FROM_U8(RT_BYTE1(u), RT_BYTE2(u), RT_BYTE3(u), 0);
2818 }
2819 pbSrc += cbSrcXorLine;
2820 }
2821 break;
2822 case 15: /* Src: RGB-5-5-5 */
2823 for (uint32_t y = 0; y < cy; y++)
2824 {
2825 for (uint32_t x = 0; x < cx; x++)
2826 {
2827 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
2828 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
2829 ((uValue >> 5) & 0x1f) << 3,
2830 ((uValue >> 10) & 0x1f) << 3, 0);
2831 }
2832 pbSrc += cbSrcXorLine;
2833 }
2834 break;
2835 case 16: /* Src: RGB-5-6-5 */
2836 for (uint32_t y = 0; y < cy; y++)
2837 {
2838 for (uint32_t x = 0; x < cx; x++)
2839 {
2840 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
2841 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
2842 ((uValue >> 5) & 0x3f) << 2,
2843 ((uValue >> 11) & 0x1f) << 3, 0);
2844 }
2845 pbSrc += cbSrcXorLine;
2846 }
2847 break;
2848 case 24:
2849 for (uint32_t y = 0; y < cy; y++)
2850 {
2851 for (uint32_t x = 0; x < cx; x++)
2852 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*3], pbSrc[x*3 + 1], pbSrc[x*3 + 2], 0);
2853 pbSrc += cbSrcXorLine;
2854 }
2855 break;
2856 case 32:
2857 for (uint32_t y = 0; y < cy; y++)
2858 {
2859 for (uint32_t x = 0; x < cx; x++)
2860 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*4], pbSrc[x*4 + 1], pbSrc[x*4 + 2], 0);
2861 pbSrc += cbSrcXorLine;
2862 }
2863 break;
2864 default:
2865 RTMemFreeZ(pbCopy, cbCopy);
2866 AssertFailedReturnVoid();
2867 }
2868
2869 /*
2870 * Pass it to the frontend/whatever.
2871 */
2872 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, false /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
2873 cx, cy, pbCopy, cbCopy);
2874}
2875
2876
2877/* SVGA_CMD_DEFINE_ALPHA_CURSOR */
2878void vmsvgaR3CmdDefineAlphaCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineAlphaCursor const *pCmd)
2879{
2880 RT_NOREF(pThis);
2881 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2882
2883 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineAlphaCursor);
2884 Log(("VMSVGA cmd: SVGA_CMD_DEFINE_ALPHA_CURSOR id=%d size (%dx%d) hotspot (%d,%d)\n", pCmd->id, pCmd->width, pCmd->height, pCmd->hotspotX, pCmd->hotspotY));
2885
2886 /* Check against a reasonable upper limit to prevent integer overflows in the sanity checks below. */
2887 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
2888 RT_UNTRUSTED_VALIDATED_FENCE();
2889
2890 /* The mouse pointer interface always expects an AND mask followed by the color data (XOR mask). */
2891 uint32_t cbAndMask = (pCmd->width + 7) / 8 * pCmd->height; /* size of the AND mask */
2892 cbAndMask = ((cbAndMask + 3) & ~3); /* + gap for alignment */
2893 uint32_t cbXorMask = pCmd->width * sizeof(uint32_t) * pCmd->height; /* + size of the XOR mask (32-bit BRGA format) */
2894 uint32_t cbCursorShape = cbAndMask + cbXorMask;
2895
2896 uint8_t *pCursorCopy = (uint8_t *)RTMemAlloc(cbCursorShape);
2897 AssertPtrReturnVoid(pCursorCopy);
2898
2899 /* Transparency is defined by the alpha bytes, so make the whole bitmap visible. */
2900 memset(pCursorCopy, 0xff, cbAndMask);
2901 /* Colour data */
2902 memcpy(pCursorCopy + cbAndMask, pCmd + 1, cbXorMask);
2903
2904 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, true /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
2905 pCmd->width, pCmd->height, pCursorCopy, cbCursorShape);
2906}
2907
2908
2909/* SVGA_CMD_ESCAPE */
2910void vmsvgaR3CmdEscape(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdEscape const *pCmd)
2911{
2912 RT_NOREF(pThis);
2913 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2914
2915 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdEscape);
2916
2917 if (pCmd->nsid == SVGA_ESCAPE_NSID_VMWARE)
2918 {
2919 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(uint32_t));
2920 RT_UNTRUSTED_VALIDATED_FENCE();
2921
2922 uint32_t const cmd = *(uint32_t *)(pCmd + 1);
2923 Log(("SVGA_CMD_ESCAPE (%#x %#x) VMWARE cmd=%#x\n", pCmd->nsid, pCmd->size, cmd));
2924
2925 switch (cmd)
2926 {
2927 case SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS:
2928 {
2929 SVGAEscapeVideoSetRegs *pVideoCmd = (SVGAEscapeVideoSetRegs *)(pCmd + 1);
2930 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(pVideoCmd->header));
2931 RT_UNTRUSTED_VALIDATED_FENCE();
2932
2933 uint32_t const cRegs = (pCmd->size - sizeof(pVideoCmd->header)) / sizeof(pVideoCmd->items[0]);
2934
2935 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: stream %#x\n", pVideoCmd->header.streamId));
2936 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
2937 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: reg %#x val %#x\n", pVideoCmd->items[iReg].registerId, pVideoCmd->items[iReg].value));
2938 RT_NOREF_PV(pVideoCmd);
2939 break;
2940 }
2941
2942 case SVGA_ESCAPE_VMWARE_VIDEO_FLUSH:
2943 {
2944 SVGAEscapeVideoFlush *pVideoCmd = (SVGAEscapeVideoFlush *)(pCmd + 1);
2945 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(*pVideoCmd));
2946 Log(("SVGA_ESCAPE_VMWARE_VIDEO_FLUSH: stream %#x\n", pVideoCmd->streamId));
2947 RT_NOREF_PV(pVideoCmd);
2948 break;
2949 }
2950
2951 default:
2952 Log(("SVGA_CMD_ESCAPE: Unknown vmware escape: %#x\n", cmd));
2953 break;
2954 }
2955 }
2956 else
2957 Log(("SVGA_CMD_ESCAPE %#x %#x\n", pCmd->nsid, pCmd->size));
2958}
2959
2960
2961/* SVGA_CMD_DEFINE_SCREEN */
2962void vmsvgaR3CmdDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineScreen const *pCmd)
2963{
2964 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2965
2966 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineScreen);
2967 Log(("SVGA_CMD_DEFINE_SCREEN id=%x flags=%x size=(%d,%d) root=(%d,%d) %d:0x%x 0x%x\n",
2968 pCmd->screen.id, pCmd->screen.flags, pCmd->screen.size.width, pCmd->screen.size.height, pCmd->screen.root.x, pCmd->screen.root.y,
2969 pCmd->screen.backingStore.ptr.gmrId, pCmd->screen.backingStore.ptr.offset, pCmd->screen.backingStore.pitch));
2970
2971 uint32_t const idScreen = pCmd->screen.id;
2972 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
2973
2974 uint32_t const uWidth = pCmd->screen.size.width;
2975 ASSERT_GUEST_RETURN_VOID(uWidth <= pThis->svga.u32MaxWidth);
2976
2977 uint32_t const uHeight = pCmd->screen.size.height;
2978 ASSERT_GUEST_RETURN_VOID(uHeight <= pThis->svga.u32MaxHeight);
2979
2980 uint32_t const cbWidth = uWidth * ((32 + 7) / 8); /** @todo 32? */
2981 uint32_t const cbPitch = pCmd->screen.backingStore.pitch ? pCmd->screen.backingStore.pitch : cbWidth;
2982 ASSERT_GUEST_RETURN_VOID(cbWidth <= cbPitch);
2983
2984 uint32_t const uScreenOffset = pCmd->screen.backingStore.ptr.offset;
2985 ASSERT_GUEST_RETURN_VOID(uScreenOffset < pThis->vram_size);
2986
2987 uint32_t const cbVram = pThis->vram_size - uScreenOffset;
2988 /* If we have a not zero pitch, then height can't exceed the available VRAM. */
2989 ASSERT_GUEST_RETURN_VOID( (uHeight == 0 && cbPitch == 0)
2990 || (cbPitch > 0 && uHeight <= cbVram / cbPitch));
2991 RT_UNTRUSTED_VALIDATED_FENCE();
2992
2993 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
2994 pScreen->fDefined = true;
2995 pScreen->fModified = true;
2996 pScreen->fuScreen = pCmd->screen.flags;
2997 pScreen->idScreen = idScreen;
2998 if (!RT_BOOL(pCmd->screen.flags & (SVGA_SCREEN_DEACTIVATE | SVGA_SCREEN_BLANKING)))
2999 {
3000 /* Not blanked. */
3001 ASSERT_GUEST_RETURN_VOID(uWidth > 0 && uHeight > 0);
3002 RT_UNTRUSTED_VALIDATED_FENCE();
3003
3004 pScreen->xOrigin = pCmd->screen.root.x;
3005 pScreen->yOrigin = pCmd->screen.root.y;
3006 pScreen->cWidth = uWidth;
3007 pScreen->cHeight = uHeight;
3008 pScreen->offVRAM = uScreenOffset;
3009 pScreen->cbPitch = cbPitch;
3010 pScreen->cBpp = 32;
3011 }
3012 else
3013 {
3014 /* Screen blanked. Keep old values. */
3015 }
3016
3017 pThis->svga.fGFBRegisters = false;
3018 vmsvgaR3ChangeMode(pThis, pThisCC);
3019
3020#ifdef VBOX_WITH_VMSVGA3D
3021 if (RT_LIKELY(pThis->svga.f3DEnabled))
3022 vmsvga3dDefineScreen(pThis, pThisCC, pScreen);
3023#endif
3024}
3025
3026
3027/* SVGA_CMD_DESTROY_SCREEN */
3028void vmsvgaR3CmdDestroyScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDestroyScreen const *pCmd)
3029{
3030 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3031
3032 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDestroyScreen);
3033 Log(("SVGA_CMD_DESTROY_SCREEN id=%x\n", pCmd->screenId));
3034
3035 uint32_t const idScreen = pCmd->screenId;
3036 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
3037 RT_UNTRUSTED_VALIDATED_FENCE();
3038
3039 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
3040 pScreen->fModified = true;
3041 pScreen->fDefined = false;
3042 pScreen->idScreen = idScreen;
3043
3044#ifdef VBOX_WITH_VMSVGA3D
3045 if (RT_LIKELY(pThis->svga.f3DEnabled))
3046 vmsvga3dDestroyScreen(pThisCC, pScreen);
3047#endif
3048 vmsvgaR3ChangeMode(pThis, pThisCC);
3049}
3050
3051
3052/* SVGA_CMD_DEFINE_GMRFB */
3053void vmsvgaR3CmdDefineGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMRFB const *pCmd)
3054{
3055 RT_NOREF(pThis);
3056 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3057
3058 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmrFb);
3059 Log(("SVGA_CMD_DEFINE_GMRFB gmr=%x offset=%x bytesPerLine=%x bpp=%d color depth=%d\n",
3060 pCmd->ptr.gmrId, pCmd->ptr.offset, pCmd->bytesPerLine, pCmd->format.bitsPerPixel, pCmd->format.colorDepth));
3061
3062 pSvgaR3State->GMRFB.ptr = pCmd->ptr;
3063 pSvgaR3State->GMRFB.bytesPerLine = pCmd->bytesPerLine;
3064 pSvgaR3State->GMRFB.format = pCmd->format;
3065}
3066
3067
3068/* SVGA_CMD_BLIT_GMRFB_TO_SCREEN */
3069void vmsvgaR3CmdBlitGMRFBToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitGMRFBToScreen const *pCmd)
3070{
3071 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3072
3073 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitGmrFbToScreen);
3074 Log(("SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n",
3075 pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
3076
3077 ASSERT_GUEST_RETURN_VOID(pCmd->destScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
3078 RT_UNTRUSTED_VALIDATED_FENCE();
3079
3080 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->destScreenId);
3081 AssertPtrReturnVoid(pScreen);
3082
3083 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp ? */
3084 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
3085
3086 /* Clip destRect to the screen dimensions. */
3087 SVGASignedRect screenRect;
3088 screenRect.left = 0;
3089 screenRect.top = 0;
3090 screenRect.right = pScreen->cWidth;
3091 screenRect.bottom = pScreen->cHeight;
3092 SVGASignedRect clipRect = pCmd->destRect;
3093 vmsvgaR3ClipRect(&screenRect, &clipRect);
3094 RT_UNTRUSTED_VALIDATED_FENCE();
3095
3096 uint32_t const width = clipRect.right - clipRect.left;
3097 uint32_t const height = clipRect.bottom - clipRect.top;
3098
3099 if ( width == 0
3100 || height == 0)
3101 return; /* Nothing to do. */
3102
3103 int32_t const srcx = pCmd->srcOrigin.x + (clipRect.left - pCmd->destRect.left);
3104 int32_t const srcy = pCmd->srcOrigin.y + (clipRect.top - pCmd->destRect.top);
3105
3106 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
3107 * Prepare parameters for vmsvgaR3GmrTransfer.
3108 */
3109 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
3110
3111 /* Destination: host buffer which describes the screen 0 VRAM.
3112 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
3113 */
3114 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
3115 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
3116 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
3117 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
3118 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
3119 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
3120 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
3121 + cbScanline * clipRect.top;
3122 int32_t const cbHstPitch = cbScanline;
3123
3124 /* Source: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
3125 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
3126 uint32_t const offGst = (srcx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
3127 + pSvgaR3State->GMRFB.bytesPerLine * srcy;
3128 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
3129
3130 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_WRITE_HOST_VRAM,
3131 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
3132 gstPtr, offGst, cbGstPitch,
3133 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
3134 AssertRC(rc);
3135 vmsvgaR3UpdateScreen(pThisCC, pScreen, clipRect.left, clipRect.top, width, height);
3136}
3137
3138
3139/* SVGA_CMD_BLIT_SCREEN_TO_GMRFB */
3140void vmsvgaR3CmdBlitScreenToGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitScreenToGMRFB const *pCmd)
3141{
3142 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3143
3144 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitScreentoGmrFb);
3145 /* Note! This can fetch 3d render results as well!! */
3146 Log(("SVGA_CMD_BLIT_SCREEN_TO_GMRFB dest=(%d,%d) src id=%d (%d,%d)(%d,%d)\n",
3147 pCmd->destOrigin.x, pCmd->destOrigin.y, pCmd->srcScreenId, pCmd->srcRect.left, pCmd->srcRect.top, pCmd->srcRect.right, pCmd->srcRect.bottom));
3148
3149 ASSERT_GUEST_RETURN_VOID(pCmd->srcScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
3150 RT_UNTRUSTED_VALIDATED_FENCE();
3151
3152 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->srcScreenId);
3153 AssertPtrReturnVoid(pScreen);
3154
3155 /** @todo Support GMRFB.format.bitsPerPixel != pThis->svga.uBpp ? */
3156 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
3157
3158 /* Clip destRect to the screen dimensions. */
3159 SVGASignedRect screenRect;
3160 screenRect.left = 0;
3161 screenRect.top = 0;
3162 screenRect.right = pScreen->cWidth;
3163 screenRect.bottom = pScreen->cHeight;
3164 SVGASignedRect clipRect = pCmd->srcRect;
3165 vmsvgaR3ClipRect(&screenRect, &clipRect);
3166 RT_UNTRUSTED_VALIDATED_FENCE();
3167
3168 uint32_t const width = clipRect.right - clipRect.left;
3169 uint32_t const height = clipRect.bottom - clipRect.top;
3170
3171 if ( width == 0
3172 || height == 0)
3173 return; /* Nothing to do. */
3174
3175 int32_t const dstx = pCmd->destOrigin.x + (clipRect.left - pCmd->srcRect.left);
3176 int32_t const dsty = pCmd->destOrigin.y + (clipRect.top - pCmd->srcRect.top);
3177
3178 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
3179 * Prepare parameters for vmsvgaR3GmrTransfer.
3180 */
3181 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
3182
3183 /* Source: host buffer which describes the screen 0 VRAM.
3184 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
3185 */
3186 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
3187 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
3188 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
3189 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
3190 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
3191 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
3192 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
3193 + cbScanline * clipRect.top;
3194 int32_t const cbHstPitch = cbScanline;
3195
3196 /* Destination: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
3197 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
3198 uint32_t const offGst = (dstx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
3199 + pSvgaR3State->GMRFB.bytesPerLine * dsty;
3200 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
3201
3202 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_READ_HOST_VRAM,
3203 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
3204 gstPtr, offGst, cbGstPitch,
3205 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
3206 AssertRC(rc);
3207}
3208
3209
3210/* SVGA_CMD_ANNOTATION_FILL */
3211void vmsvgaR3CmdAnnotationFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationFill const *pCmd)
3212{
3213 RT_NOREF(pThis);
3214 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3215
3216 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationFill);
3217 Log(("SVGA_CMD_ANNOTATION_FILL red=%x green=%x blue=%x\n", pCmd->color.r, pCmd->color.g, pCmd->color.b));
3218
3219 pSvgaR3State->colorAnnotation = pCmd->color;
3220}
3221
3222
3223/* SVGA_CMD_ANNOTATION_COPY */
3224void vmsvgaR3CmdAnnotationCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationCopy const *pCmd)
3225{
3226 RT_NOREF(pThis, pCmd);
3227 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3228
3229 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationCopy);
3230 Log(("SVGA_CMD_ANNOTATION_COPY srcOrigin %d,%d, srcScreenId %u\n", pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->srcScreenId));
3231
3232 AssertFailed();
3233}
3234
3235
3236#ifdef VBOX_WITH_VMSVGA3D
3237/* SVGA_CMD_DEFINE_GMR2 */
3238void vmsvgaR3CmdDefineGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMR2 const *pCmd)
3239{
3240 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3241
3242 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2);
3243 Log(("SVGA_CMD_DEFINE_GMR2 id=%#x %#x pages\n", pCmd->gmrId, pCmd->numPages));
3244
3245 /* Validate current GMR id. */
3246 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
3247 ASSERT_GUEST_RETURN_VOID(pCmd->numPages <= VMSVGA_MAX_GMR_PAGES);
3248 RT_UNTRUSTED_VALIDATED_FENCE();
3249
3250 if (!pCmd->numPages)
3251 {
3252 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Free);
3253 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
3254 }
3255 else
3256 {
3257 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
3258 if (pGMR->cMaxPages)
3259 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Modify);
3260
3261 /* Not sure if we should always free the descriptor, but for simplicity
3262 we do so if the new size is smaller than the current. */
3263 /** @todo always free the descriptor in SVGA_CMD_DEFINE_GMR2? */
3264 if (pGMR->cbTotal / X86_PAGE_SIZE > pGMR->cMaxPages)
3265 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
3266
3267 pGMR->cMaxPages = pCmd->numPages;
3268 /* The rest is done by the REMAP_GMR2 command. */
3269 }
3270}
3271
3272
3273/* SVGA_CMD_REMAP_GMR2 */
3274void vmsvgaR3CmdRemapGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRemapGMR2 const *pCmd)
3275{
3276 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3277
3278 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2);
3279 Log(("SVGA_CMD_REMAP_GMR2 id=%#x flags=%#x offset=%#x npages=%#x\n", pCmd->gmrId, pCmd->flags, pCmd->offsetPages, pCmd->numPages));
3280
3281 /* Validate current GMR id and size. */
3282 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
3283 RT_UNTRUSTED_VALIDATED_FENCE();
3284 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
3285 ASSERT_GUEST_RETURN_VOID( (uint64_t)pCmd->offsetPages + pCmd->numPages
3286 <= RT_MIN(pGMR->cMaxPages, RT_MIN(VMSVGA_MAX_GMR_PAGES, UINT32_MAX / X86_PAGE_SIZE)));
3287 ASSERT_GUEST_RETURN_VOID(!pCmd->offsetPages || pGMR->paDesc); /** @todo */
3288
3289 if (pCmd->numPages == 0)
3290 return;
3291 RT_UNTRUSTED_VALIDATED_FENCE();
3292
3293 /* Calc new total page count so we can use it instead of cMaxPages for allocations below. */
3294 uint32_t const cNewTotalPages = RT_MAX(pGMR->cbTotal >> X86_PAGE_SHIFT, pCmd->offsetPages + pCmd->numPages);
3295
3296 /*
3297 * We flatten the existing descriptors into a page array, overwrite the
3298 * pages specified in this command and then recompress the descriptor.
3299 */
3300 /** @todo Optimize the GMR remap algorithm! */
3301
3302 /* Save the old page descriptors as an array of page frame numbers (address >> X86_PAGE_SHIFT) */
3303 uint64_t *paNewPage64 = NULL;
3304 if (pGMR->paDesc)
3305 {
3306 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2Modify);
3307
3308 paNewPage64 = (uint64_t *)RTMemAllocZ(cNewTotalPages * sizeof(uint64_t));
3309 AssertPtrReturnVoid(paNewPage64);
3310
3311 uint32_t idxPage = 0;
3312 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
3313 for (uint32_t j = 0; j < pGMR->paDesc[i].numPages; j++)
3314 paNewPage64[idxPage++] = (pGMR->paDesc[i].GCPhys + j * X86_PAGE_SIZE) >> X86_PAGE_SHIFT;
3315 AssertReturnVoidStmt(idxPage == pGMR->cbTotal >> X86_PAGE_SHIFT, RTMemFree(paNewPage64));
3316 RT_UNTRUSTED_VALIDATED_FENCE();
3317 }
3318
3319 /* Free the old GMR if present. */
3320 if (pGMR->paDesc)
3321 RTMemFree(pGMR->paDesc);
3322
3323 /* Allocate the maximum amount possible (everything non-continuous) */
3324 PVMSVGAGMRDESCRIPTOR paDescs;
3325 pGMR->paDesc = paDescs = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(cNewTotalPages * sizeof(VMSVGAGMRDESCRIPTOR));
3326 AssertReturnVoidStmt(paDescs, RTMemFree(paNewPage64));
3327
3328 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
3329 {
3330 /** @todo */
3331 AssertFailed();
3332 pGMR->numDescriptors = 0;
3333 }
3334 else
3335 {
3336 uint32_t *paPages32 = (uint32_t *)(pCmd + 1);
3337 uint64_t *paPages64 = (uint64_t *)(pCmd + 1);
3338 bool fGCPhys64 = RT_BOOL(pCmd->flags & SVGA_REMAP_GMR2_PPN64);
3339
3340 uint32_t cPages;
3341 if (paNewPage64)
3342 {
3343 /* Overwrite the old page array with the new page values. */
3344 if (fGCPhys64)
3345 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
3346 paNewPage64[i] = paPages64[i - pCmd->offsetPages];
3347 else
3348 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
3349 paNewPage64[i] = paPages32[i - pCmd->offsetPages];
3350
3351 /* Use the updated page array instead of the command data. */
3352 fGCPhys64 = true;
3353 paPages64 = paNewPage64;
3354 cPages = cNewTotalPages;
3355 }
3356 else
3357 cPages = pCmd->numPages;
3358
3359 /* The first page. */
3360 /** @todo The 0x00000FFFFFFFFFFF mask limits to 44 bits and should not be
3361 * applied to paNewPage64. */
3362 RTGCPHYS GCPhys;
3363 if (fGCPhys64)
3364 GCPhys = (paPages64[0] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
3365 else
3366 GCPhys = (RTGCPHYS)paPages32[0] << PAGE_SHIFT;
3367 paDescs[0].GCPhys = GCPhys;
3368 paDescs[0].numPages = 1;
3369
3370 /* Subsequent pages. */
3371 uint32_t iDescriptor = 0;
3372 for (uint32_t i = 1; i < cPages; i++)
3373 {
3374 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
3375 GCPhys = (paPages64[i] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
3376 else
3377 GCPhys = (RTGCPHYS)paPages32[i] << X86_PAGE_SHIFT;
3378
3379 /* Continuous physical memory? */
3380 if (GCPhys == paDescs[iDescriptor].GCPhys + paDescs[iDescriptor].numPages * X86_PAGE_SIZE)
3381 {
3382 Assert(paDescs[iDescriptor].numPages);
3383 paDescs[iDescriptor].numPages++;
3384 Log5Func(("Page %x GCPhys=%RGp successor\n", i, GCPhys));
3385 }
3386 else
3387 {
3388 iDescriptor++;
3389 paDescs[iDescriptor].GCPhys = GCPhys;
3390 paDescs[iDescriptor].numPages = 1;
3391 Log5Func(("Page %x GCPhys=%RGp\n", i, paDescs[iDescriptor].GCPhys));
3392 }
3393 }
3394
3395 pGMR->cbTotal = cNewTotalPages << X86_PAGE_SHIFT;
3396 Log5Func(("Nr of descriptors %x; cbTotal=%#x\n", iDescriptor + 1, cNewTotalPages));
3397 pGMR->numDescriptors = iDescriptor + 1;
3398 }
3399
3400 if (paNewPage64)
3401 RTMemFree(paNewPage64);
3402}
3403
3404
3405/**
3406 * Free the specified GMR
3407 *
3408 * @param pThisCC The VGA/VMSVGA state for ring-3.
3409 * @param idGMR GMR id
3410 */
3411void vmsvgaR3GmrFree(PVGASTATECC pThisCC, uint32_t idGMR)
3412{
3413 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
3414
3415 /* Free the old descriptor if present. */
3416 PGMR pGMR = &pSVGAState->paGMR[idGMR];
3417 if ( pGMR->numDescriptors
3418 || pGMR->paDesc /* needed till we implement SVGA_REMAP_GMR2_VIA_GMR */)
3419 {
3420# ifdef DEBUG_GMR_ACCESS
3421 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThisCC->pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3DeregisterGmr, 2, pDevIns, idGMR);
3422# endif
3423
3424 Assert(pGMR->paDesc);
3425 RTMemFree(pGMR->paDesc);
3426 pGMR->paDesc = NULL;
3427 pGMR->numDescriptors = 0;
3428 pGMR->cbTotal = 0;
3429 pGMR->cMaxPages = 0;
3430 }
3431 Assert(!pGMR->cMaxPages);
3432 Assert(!pGMR->cbTotal);
3433}
3434#endif /* VBOX_WITH_VMSVGA3D */
3435
3436
3437/**
3438 * Copy between a GMR and a host memory buffer.
3439 *
3440 * @returns VBox status code.
3441 * @param pThis The shared VGA/VMSVGA instance data.
3442 * @param pThisCC The VGA/VMSVGA state for ring-3.
3443 * @param enmTransferType Transfer type (read/write)
3444 * @param pbHstBuf Host buffer pointer (valid)
3445 * @param cbHstBuf Size of host buffer (valid)
3446 * @param offHst Host buffer offset of the first scanline
3447 * @param cbHstPitch Destination buffer pitch
3448 * @param gstPtr GMR description
3449 * @param offGst Guest buffer offset of the first scanline
3450 * @param cbGstPitch Guest buffer pitch
3451 * @param cbWidth Width in bytes to copy
3452 * @param cHeight Number of scanllines to copy
3453 */
3454int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
3455 uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
3456 SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
3457 uint32_t cbWidth, uint32_t cHeight)
3458{
3459 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
3460 PPDMDEVINS pDevIns = pThisCC->pDevIns; /* simpler */
3461 int rc;
3462
3463 LogFunc(("%s host %p size=%d offset %d pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
3464 enmTransferType == SVGA3D_READ_HOST_VRAM ? "WRITE" : "READ", /* GMR op: READ host VRAM means WRITE GMR */
3465 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
3466 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cbWidth, cHeight));
3467 AssertReturn(cbWidth && cHeight, VERR_INVALID_PARAMETER);
3468
3469 PGMR pGMR;
3470 uint32_t cbGmr; /* The GMR size in bytes. */
3471 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
3472 {
3473 pGMR = NULL;
3474 cbGmr = pThis->vram_size;
3475 }
3476 else
3477 {
3478 AssertReturn(gstPtr.gmrId < pThis->svga.cGMR, VERR_INVALID_PARAMETER);
3479 RT_UNTRUSTED_VALIDATED_FENCE();
3480 pGMR = &pSVGAState->paGMR[gstPtr.gmrId];
3481 cbGmr = pGMR->cbTotal;
3482 }
3483
3484 /*
3485 * GMR
3486 */
3487 /* Calculate GMR offset of the data to be copied. */
3488 AssertMsgReturn(gstPtr.offset < cbGmr,
3489 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3490 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3491 VERR_INVALID_PARAMETER);
3492 RT_UNTRUSTED_VALIDATED_FENCE();
3493 AssertMsgReturn(offGst < cbGmr - gstPtr.offset,
3494 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3495 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3496 VERR_INVALID_PARAMETER);
3497 RT_UNTRUSTED_VALIDATED_FENCE();
3498 uint32_t const offGmr = offGst + gstPtr.offset; /* Offset in the GMR, where the first scanline is located. */
3499
3500 /* Verify that cbWidth is less than scanline and fits into the GMR. */
3501 uint32_t const cbGmrScanline = cbGstPitch > 0 ? cbGstPitch : -cbGstPitch;
3502 AssertMsgReturn(cbGmrScanline != 0,
3503 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3504 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3505 VERR_INVALID_PARAMETER);
3506 RT_UNTRUSTED_VALIDATED_FENCE();
3507 AssertMsgReturn(cbWidth <= cbGmrScanline,
3508 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3509 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3510 VERR_INVALID_PARAMETER);
3511 AssertMsgReturn(cbWidth <= cbGmr - offGmr,
3512 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3513 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3514 VERR_INVALID_PARAMETER);
3515 RT_UNTRUSTED_VALIDATED_FENCE();
3516
3517 /* How many bytes are available for the data in the GMR. */
3518 uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmr - offGmr : offGmr + cbWidth;
3519
3520 /* How many scanlines would fit into the available data. */
3521 uint32_t cGmrScanlines = cbGmrLeft / cbGmrScanline;
3522 uint32_t const cbGmrLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
3523 if (cbWidth <= cbGmrLastScanline)
3524 ++cGmrScanlines;
3525
3526 if (cHeight > cGmrScanlines)
3527 cHeight = cGmrScanlines;
3528
3529 AssertMsgReturn(cHeight > 0,
3530 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
3531 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
3532 VERR_INVALID_PARAMETER);
3533 RT_UNTRUSTED_VALIDATED_FENCE();
3534
3535 /*
3536 * Host buffer.
3537 */
3538 AssertMsgReturn(offHst < cbHstBuf,
3539 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
3540 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
3541 VERR_INVALID_PARAMETER);
3542
3543 /* Verify that cbWidth is less than scanline and fits into the buffer. */
3544 uint32_t const cbHstScanline = cbHstPitch > 0 ? cbHstPitch : -cbHstPitch;
3545 AssertMsgReturn(cbHstScanline != 0,
3546 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
3547 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
3548 VERR_INVALID_PARAMETER);
3549 AssertMsgReturn(cbWidth <= cbHstScanline,
3550 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
3551 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
3552 VERR_INVALID_PARAMETER);
3553 AssertMsgReturn(cbWidth <= cbHstBuf - offHst,
3554 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
3555 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
3556 VERR_INVALID_PARAMETER);
3557
3558 /* How many bytes are available for the data in the buffer. */
3559 uint32_t const cbHstLeft = cbHstPitch > 0 ? cbHstBuf - offHst : offHst + cbWidth;
3560
3561 /* How many scanlines would fit into the available data. */
3562 uint32_t cHstScanlines = cbHstLeft / cbHstScanline;
3563 uint32_t const cbHstLastScanline = cbHstLeft - cHstScanlines * cbHstScanline; /* Slack space. */
3564 if (cbWidth <= cbHstLastScanline)
3565 ++cHstScanlines;
3566
3567 if (cHeight > cHstScanlines)
3568 cHeight = cHstScanlines;
3569
3570 AssertMsgReturn(cHeight > 0,
3571 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
3572 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
3573 VERR_INVALID_PARAMETER);
3574
3575 uint8_t *pbHst = pbHstBuf + offHst;
3576
3577 /* Shortcut for the framebuffer. */
3578 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
3579 {
3580 uint8_t *pbGst = pThisCC->pbVRam + offGmr;
3581
3582 uint8_t const *pbSrc;
3583 int32_t cbSrcPitch;
3584 uint8_t *pbDst;
3585 int32_t cbDstPitch;
3586
3587 if (enmTransferType == SVGA3D_READ_HOST_VRAM)
3588 {
3589 pbSrc = pbHst;
3590 cbSrcPitch = cbHstPitch;
3591 pbDst = pbGst;
3592 cbDstPitch = cbGstPitch;
3593 }
3594 else
3595 {
3596 pbSrc = pbGst;
3597 cbSrcPitch = cbGstPitch;
3598 pbDst = pbHst;
3599 cbDstPitch = cbHstPitch;
3600 }
3601
3602 if ( cbWidth == (uint32_t)cbGstPitch
3603 && cbGstPitch == cbHstPitch)
3604 {
3605 /* Entire scanlines, positive pitch. */
3606 memcpy(pbDst, pbSrc, cbWidth * cHeight);
3607 }
3608 else
3609 {
3610 for (uint32_t i = 0; i < cHeight; ++i)
3611 {
3612 memcpy(pbDst, pbSrc, cbWidth);
3613
3614 pbDst += cbDstPitch;
3615 pbSrc += cbSrcPitch;
3616 }
3617 }
3618 return VINF_SUCCESS;
3619 }
3620
3621 AssertPtrReturn(pGMR, VERR_INVALID_PARAMETER);
3622 AssertReturn(pGMR->numDescriptors > 0, VERR_INVALID_PARAMETER);
3623
3624 PVMSVGAGMRDESCRIPTOR const paDesc = pGMR->paDesc; /* Local copy of the pointer. */
3625 uint32_t iDesc = 0; /* Index in the descriptor array. */
3626 uint32_t offDesc = 0; /* GMR offset of the current descriptor. */
3627 uint32_t offGmrScanline = offGmr; /* GMR offset of the scanline which is being copied. */
3628 uint8_t *pbHstScanline = pbHst; /* Host address of the scanline which is being copied. */
3629 for (uint32_t i = 0; i < cHeight; ++i)
3630 {
3631 uint32_t cbCurrentWidth = cbWidth;
3632 uint32_t offGmrCurrent = offGmrScanline;
3633 uint8_t *pbCurrentHost = pbHstScanline;
3634
3635 /* Find the right descriptor */
3636 while (offDesc + paDesc[iDesc].numPages * PAGE_SIZE <= offGmrCurrent)
3637 {
3638 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
3639 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
3640 ++iDesc;
3641 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
3642 }
3643
3644 while (cbCurrentWidth)
3645 {
3646 uint32_t cbToCopy;
3647
3648 if (offGmrCurrent + cbCurrentWidth <= offDesc + paDesc[iDesc].numPages * PAGE_SIZE)
3649 {
3650 cbToCopy = cbCurrentWidth;
3651 }
3652 else
3653 {
3654 cbToCopy = (offDesc + paDesc[iDesc].numPages * PAGE_SIZE - offGmrCurrent);
3655 AssertReturn(cbToCopy <= cbCurrentWidth, VERR_INVALID_PARAMETER);
3656 }
3657
3658 RTGCPHYS const GCPhys = paDesc[iDesc].GCPhys + offGmrCurrent - offDesc;
3659
3660 Log5Func(("%s phys=%RGp\n", (enmTransferType == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", GCPhys));
3661
3662 if (enmTransferType == SVGA3D_WRITE_HOST_VRAM)
3663 rc = PDMDevHlpPCIPhysRead(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
3664 else
3665 rc = PDMDevHlpPCIPhysWrite(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
3666 AssertRCBreak(rc);
3667
3668 cbCurrentWidth -= cbToCopy;
3669 offGmrCurrent += cbToCopy;
3670 pbCurrentHost += cbToCopy;
3671
3672 /* Go to the next descriptor if there's anything left. */
3673 if (cbCurrentWidth)
3674 {
3675 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
3676 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR);
3677 ++iDesc;
3678 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
3679 }
3680 }
3681
3682 offGmrScanline += cbGstPitch;
3683 pbHstScanline += cbHstPitch;
3684 }
3685
3686 return VINF_SUCCESS;
3687}
3688
3689
3690/**
3691 * Unsigned coordinates in pBox. Clip to [0; pSizeSrc), [0; pSizeDest).
3692 *
3693 * @param pSizeSrc Source surface dimensions.
3694 * @param pSizeDest Destination surface dimensions.
3695 * @param pBox Coordinates to be clipped.
3696 */
3697void vmsvgaR3ClipCopyBox(const SVGA3dSize *pSizeSrc, const SVGA3dSize *pSizeDest, SVGA3dCopyBox *pBox)
3698{
3699 /* Src x, w */
3700 if (pBox->srcx > pSizeSrc->width)
3701 pBox->srcx = pSizeSrc->width;
3702 if (pBox->w > pSizeSrc->width - pBox->srcx)
3703 pBox->w = pSizeSrc->width - pBox->srcx;
3704
3705 /* Src y, h */
3706 if (pBox->srcy > pSizeSrc->height)
3707 pBox->srcy = pSizeSrc->height;
3708 if (pBox->h > pSizeSrc->height - pBox->srcy)
3709 pBox->h = pSizeSrc->height - pBox->srcy;
3710
3711 /* Src z, d */
3712 if (pBox->srcz > pSizeSrc->depth)
3713 pBox->srcz = pSizeSrc->depth;
3714 if (pBox->d > pSizeSrc->depth - pBox->srcz)
3715 pBox->d = pSizeSrc->depth - pBox->srcz;
3716
3717 /* Dest x, w */
3718 if (pBox->x > pSizeDest->width)
3719 pBox->x = pSizeDest->width;
3720 if (pBox->w > pSizeDest->width - pBox->x)
3721 pBox->w = pSizeDest->width - pBox->x;
3722
3723 /* Dest y, h */
3724 if (pBox->y > pSizeDest->height)
3725 pBox->y = pSizeDest->height;
3726 if (pBox->h > pSizeDest->height - pBox->y)
3727 pBox->h = pSizeDest->height - pBox->y;
3728
3729 /* Dest z, d */
3730 if (pBox->z > pSizeDest->depth)
3731 pBox->z = pSizeDest->depth;
3732 if (pBox->d > pSizeDest->depth - pBox->z)
3733 pBox->d = pSizeDest->depth - pBox->z;
3734}
3735
3736
3737/**
3738 * Unsigned coordinates in pBox. Clip to [0; pSize).
3739 *
3740 * @param pSize Source surface dimensions.
3741 * @param pBox Coordinates to be clipped.
3742 */
3743void vmsvgaR3ClipBox(const SVGA3dSize *pSize, SVGA3dBox *pBox)
3744{
3745 /* x, w */
3746 if (pBox->x > pSize->width)
3747 pBox->x = pSize->width;
3748 if (pBox->w > pSize->width - pBox->x)
3749 pBox->w = pSize->width - pBox->x;
3750
3751 /* y, h */
3752 if (pBox->y > pSize->height)
3753 pBox->y = pSize->height;
3754 if (pBox->h > pSize->height - pBox->y)
3755 pBox->h = pSize->height - pBox->y;
3756
3757 /* z, d */
3758 if (pBox->z > pSize->depth)
3759 pBox->z = pSize->depth;
3760 if (pBox->d > pSize->depth - pBox->z)
3761 pBox->d = pSize->depth - pBox->z;
3762}
3763
3764
3765/**
3766 * Clip.
3767 *
3768 * @param pBound Bounding rectangle.
3769 * @param pRect Rectangle to be clipped.
3770 */
3771void vmsvgaR3ClipRect(SVGASignedRect const *pBound, SVGASignedRect *pRect)
3772{
3773 int32_t left;
3774 int32_t top;
3775 int32_t right;
3776 int32_t bottom;
3777
3778 /* Right order. */
3779 Assert(pBound->left <= pBound->right && pBound->top <= pBound->bottom);
3780 if (pRect->left < pRect->right)
3781 {
3782 left = pRect->left;
3783 right = pRect->right;
3784 }
3785 else
3786 {
3787 left = pRect->right;
3788 right = pRect->left;
3789 }
3790 if (pRect->top < pRect->bottom)
3791 {
3792 top = pRect->top;
3793 bottom = pRect->bottom;
3794 }
3795 else
3796 {
3797 top = pRect->bottom;
3798 bottom = pRect->top;
3799 }
3800
3801 if (left < pBound->left)
3802 left = pBound->left;
3803 if (right < pBound->left)
3804 right = pBound->left;
3805
3806 if (left > pBound->right)
3807 left = pBound->right;
3808 if (right > pBound->right)
3809 right = pBound->right;
3810
3811 if (top < pBound->top)
3812 top = pBound->top;
3813 if (bottom < pBound->top)
3814 bottom = pBound->top;
3815
3816 if (top > pBound->bottom)
3817 top = pBound->bottom;
3818 if (bottom > pBound->bottom)
3819 bottom = pBound->bottom;
3820
3821 pRect->left = left;
3822 pRect->right = right;
3823 pRect->top = top;
3824 pRect->bottom = bottom;
3825}
3826
3827
3828/**
3829 * Clip.
3830 *
3831 * @param pBound Bounding rectangle.
3832 * @param pRect Rectangle to be clipped.
3833 */
3834void vmsvgaR3Clip3dRect(SVGA3dRect const *pBound, SVGA3dRect RT_UNTRUSTED_GUEST *pRect)
3835{
3836 uint32_t const leftBound = pBound->x;
3837 uint32_t const rightBound = pBound->x + pBound->w;
3838 uint32_t const topBound = pBound->y;
3839 uint32_t const bottomBound = pBound->y + pBound->h;
3840
3841 uint32_t x = pRect->x;
3842 uint32_t y = pRect->y;
3843 uint32_t w = pRect->w;
3844 uint32_t h = pRect->h;
3845
3846 /* Make sure that right and bottom coordinates can be safely computed. */
3847 if (x > rightBound)
3848 x = rightBound;
3849 if (w > rightBound - x)
3850 w = rightBound - x;
3851 if (y > bottomBound)
3852 y = bottomBound;
3853 if (h > bottomBound - y)
3854 h = bottomBound - y;
3855
3856 /* Switch from x, y, w, h to left, top, right, bottom. */
3857 uint32_t left = x;
3858 uint32_t right = x + w;
3859 uint32_t top = y;
3860 uint32_t bottom = y + h;
3861
3862 /* A standard left, right, bottom, top clipping. */
3863 if (left < leftBound)
3864 left = leftBound;
3865 if (right < leftBound)
3866 right = leftBound;
3867
3868 if (left > rightBound)
3869 left = rightBound;
3870 if (right > rightBound)
3871 right = rightBound;
3872
3873 if (top < topBound)
3874 top = topBound;
3875 if (bottom < topBound)
3876 bottom = topBound;
3877
3878 if (top > bottomBound)
3879 top = bottomBound;
3880 if (bottom > bottomBound)
3881 bottom = bottomBound;
3882
3883 /* Back to x, y, w, h representation. */
3884 pRect->x = left;
3885 pRect->y = top;
3886 pRect->w = right - left;
3887 pRect->h = bottom - top;
3888}
3889
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