VirtualBox

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

Last change on this file since 93674 was 93636, checked in by vboxsync, 3 years ago

VMM/PGM,VMM/PDM,VGA: Consolidate the user parameters of the physical access handlers into a single uint64_t value that shouldn't be a pointer, at least not for ring-0 callbacks. Special hack for devices where it's translated from a ring-0 device instance index into a current context PPDMDEVINS (not really tested yet). [doxygen fix] bugref:10094

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 271.6 KB
Line 
1/* $Id: DevVGA-SVGA-cmd.cpp 93636 2022-02-07 10:50:26Z vboxsync $ */
2/** @file
3 * VMware SVGA device - implementation of VMSVGA commands.
4 */
5
6/*
7 * Copyright (C) 2013-2022 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#ifdef VBOX_WITH_VMSVGA3D
35# include "DevVGA-SVGA3d.h"
36#endif
37#include "DevVGA-SVGA-internal.h"
38
39#include <iprt/formats/bmp.h>
40#include <stdio.h>
41
42#if defined(LOG_ENABLED) || defined(VBOX_STRICT)
43# define SVGA_CASE_ID2STR(idx) case idx: return #idx
44
45static const char *vmsvgaFifo3dCmdToString(SVGAFifo3dCmdId enmCmdId)
46{
47 switch (enmCmdId)
48 {
49 SVGA_CASE_ID2STR(SVGA_3D_CMD_LEGACY_BASE);
50 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DEFINE);
51 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DESTROY);
52 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_COPY);
53 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_STRETCHBLT);
54 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DMA);
55 SVGA_CASE_ID2STR(SVGA_3D_CMD_CONTEXT_DEFINE);
56 SVGA_CASE_ID2STR(SVGA_3D_CMD_CONTEXT_DESTROY);
57 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETTRANSFORM);
58 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETZRANGE);
59 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETRENDERSTATE);
60 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETRENDERTARGET);
61 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETTEXTURESTATE);
62 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETMATERIAL);
63 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETLIGHTDATA);
64 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETLIGHTENABLED);
65 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETVIEWPORT);
66 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETCLIPPLANE);
67 SVGA_CASE_ID2STR(SVGA_3D_CMD_CLEAR);
68 SVGA_CASE_ID2STR(SVGA_3D_CMD_PRESENT);
69 SVGA_CASE_ID2STR(SVGA_3D_CMD_SHADER_DEFINE);
70 SVGA_CASE_ID2STR(SVGA_3D_CMD_SHADER_DESTROY);
71 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_SHADER);
72 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_SHADER_CONST);
73 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW_PRIMITIVES);
74 SVGA_CASE_ID2STR(SVGA_3D_CMD_SETSCISSORRECT);
75 SVGA_CASE_ID2STR(SVGA_3D_CMD_BEGIN_QUERY);
76 SVGA_CASE_ID2STR(SVGA_3D_CMD_END_QUERY);
77 SVGA_CASE_ID2STR(SVGA_3D_CMD_WAIT_FOR_QUERY);
78 SVGA_CASE_ID2STR(SVGA_3D_CMD_PRESENT_READBACK);
79 SVGA_CASE_ID2STR(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN);
80 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_DEFINE_V2);
81 SVGA_CASE_ID2STR(SVGA_3D_CMD_GENERATE_MIPMAPS);
82 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD4); /* SVGA_3D_CMD_VIDEO_CREATE_DECODER */
83 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD5); /* SVGA_3D_CMD_VIDEO_DESTROY_DECODER */
84 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD6); /* SVGA_3D_CMD_VIDEO_CREATE_PROCESSOR */
85 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD7); /* SVGA_3D_CMD_VIDEO_DESTROY_PROCESSOR */
86 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD8); /* SVGA_3D_CMD_VIDEO_DECODE_START_FRAME */
87 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD9); /* SVGA_3D_CMD_VIDEO_DECODE_RENDER */
88 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD10); /* SVGA_3D_CMD_VIDEO_DECODE_END_FRAME */
89 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD11); /* SVGA_3D_CMD_VIDEO_PROCESS_FRAME */
90 SVGA_CASE_ID2STR(SVGA_3D_CMD_ACTIVATE_SURFACE);
91 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEACTIVATE_SURFACE);
92 SVGA_CASE_ID2STR(SVGA_3D_CMD_SCREEN_DMA);
93 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD1);
94 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD2);
95 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD12); /* Old SVGA_3D_CMD_LOGICOPS_BITBLT */
96 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD13); /* Old SVGA_3D_CMD_LOGICOPS_TRANSBLT */
97 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD14); /* Old SVGA_3D_CMD_LOGICOPS_STRETCHBLT */
98 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD15); /* Old SVGA_3D_CMD_LOGICOPS_COLORFILL */
99 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD16); /* Old SVGA_3D_CMD_LOGICOPS_ALPHABLEND */
100 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD17); /* Old SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND */
101 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_OTABLE_BASE);
102 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_OTABLE);
103 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_MOB);
104 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_MOB);
105 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEAD3);
106 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING);
107 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE);
108 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SURFACE);
109 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SURFACE);
110 SVGA_CASE_ID2STR(SVGA_3D_CMD_COND_BIND_GB_SURFACE);
111 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_IMAGE);
112 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_SURFACE);
113 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_IMAGE);
114 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_SURFACE);
115 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_IMAGE);
116 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_SURFACE);
117 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_CONTEXT);
118 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_CONTEXT);
119 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_CONTEXT);
120 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_CONTEXT);
121 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_CONTEXT);
122 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SHADER);
123 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SHADER);
124 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SHADER);
125 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_OTABLE_BASE64);
126 SVGA_CASE_ID2STR(SVGA_3D_CMD_BEGIN_GB_QUERY);
127 SVGA_CASE_ID2STR(SVGA_3D_CMD_END_GB_QUERY);
128 SVGA_CASE_ID2STR(SVGA_3D_CMD_WAIT_FOR_GB_QUERY);
129 SVGA_CASE_ID2STR(SVGA_3D_CMD_NOP);
130 SVGA_CASE_ID2STR(SVGA_3D_CMD_ENABLE_GART);
131 SVGA_CASE_ID2STR(SVGA_3D_CMD_DISABLE_GART);
132 SVGA_CASE_ID2STR(SVGA_3D_CMD_MAP_MOB_INTO_GART);
133 SVGA_CASE_ID2STR(SVGA_3D_CMD_UNMAP_GART_RANGE);
134 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SCREENTARGET);
135 SVGA_CASE_ID2STR(SVGA_3D_CMD_DESTROY_GB_SCREENTARGET);
136 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SCREENTARGET);
137 SVGA_CASE_ID2STR(SVGA_3D_CMD_UPDATE_GB_SCREENTARGET);
138 SVGA_CASE_ID2STR(SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL);
139 SVGA_CASE_ID2STR(SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL);
140 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE);
141 SVGA_CASE_ID2STR(SVGA_3D_CMD_GB_SCREEN_DMA);
142 SVGA_CASE_ID2STR(SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH);
143 SVGA_CASE_ID2STR(SVGA_3D_CMD_GB_MOB_FENCE);
144 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE_V2);
145 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_MOB64);
146 SVGA_CASE_ID2STR(SVGA_3D_CMD_REDEFINE_GB_MOB64);
147 SVGA_CASE_ID2STR(SVGA_3D_CMD_NOP_ERROR);
148 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_STREAMS);
149 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_DECLS);
150 SVGA_CASE_ID2STR(SVGA_3D_CMD_SET_VERTEX_DIVISORS);
151 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW);
152 SVGA_CASE_ID2STR(SVGA_3D_CMD_DRAW_INDEXED);
153 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_CONTEXT);
154 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_CONTEXT);
155 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_CONTEXT);
156 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_CONTEXT);
157 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_INVALIDATE_CONTEXT);
158 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER);
159 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SHADER_RESOURCES);
160 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SHADER);
161 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SAMPLERS);
162 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW);
163 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INDEXED);
164 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INSTANCED);
165 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED);
166 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_AUTO);
167 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_INPUT_LAYOUT);
168 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS);
169 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_INDEX_BUFFER);
170 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_TOPOLOGY);
171 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_RENDERTARGETS);
172 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_BLEND_STATE);
173 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE);
174 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_RASTERIZER_STATE);
175 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_QUERY);
176 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_QUERY);
177 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_QUERY);
178 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_QUERY_OFFSET);
179 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BEGIN_QUERY);
180 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_END_QUERY);
181 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_QUERY);
182 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_PREDICATION);
183 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SOTARGETS);
184 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VIEWPORTS);
185 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SCISSORRECTS);
186 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW);
187 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW);
188 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_COPY_REGION);
189 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_COPY);
190 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRESENTBLT);
191 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_GENMIPS);
192 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE);
193 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_SUBRESOURCE);
194 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE);
195 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW);
196 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW);
197 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW);
198 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW);
199 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW);
200 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW);
201 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT);
202 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT);
203 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_BLEND_STATE);
204 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_BLEND_STATE);
205 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE);
206 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE);
207 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE);
208 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE);
209 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE);
210 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE);
211 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_SHADER);
212 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_SHADER);
213 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_SHADER);
214 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT);
215 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT);
216 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_STREAMOUTPUT);
217 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_COTABLE);
218 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_COTABLE);
219 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BUFFER_COPY);
220 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER);
221 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK);
222 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_MOVE_QUERY);
223 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_ALL_QUERY);
224 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_READBACK_ALL_QUERY);
225 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER);
226 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_MOB_FENCE_64);
227 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_ALL_SHADER);
228 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_HINT);
229 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BUFFER_UPDATE);
230 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET);
231 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET);
232 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET);
233 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_HS_CONSTANT_BUFFER_OFFSET);
234 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_DS_CONSTANT_BUFFER_OFFSET);
235 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_CS_CONSTANT_BUFFER_OFFSET);
236 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER);
237 SVGA_CASE_ID2STR(SVGA_3D_CMD_SCREEN_COPY);
238 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED1);
239 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED2);
240 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED3);
241 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED4);
242 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED5);
243 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED6);
244 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED7);
245 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED8);
246 SVGA_CASE_ID2STR(SVGA_3D_CMD_GROW_OTABLE);
247 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_GROW_COTABLE);
248 SVGA_CASE_ID2STR(SVGA_3D_CMD_INTRA_SURFACE_COPY);
249 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE_V3);
250 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_RESOLVE_COPY);
251 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_RESOLVE_COPY);
252 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_CONVERT_REGION);
253 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_PRED_CONVERT);
254 SVGA_CASE_ID2STR(SVGA_3D_CMD_WHOLE_SURFACE_COPY);
255 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_UA_VIEW);
256 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DESTROY_UA_VIEW);
257 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT);
258 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT);
259 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT);
260 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_UA_VIEWS);
261 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT);
262 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT);
263 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DISPATCH);
264 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DISPATCH_INDIRECT);
265 SVGA_CASE_ID2STR(SVGA_3D_CMD_WRITE_ZERO_SURFACE);
266 SVGA_CASE_ID2STR(SVGA_3D_CMD_HINT_ZERO_SURFACE);
267 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_TRANSFER_TO_BUFFER);
268 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_STRUCTURE_COUNT);
269 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_BITBLT);
270 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_TRANSBLT);
271 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_STRETCHBLT);
272 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_COLORFILL);
273 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_ALPHABLEND);
274 SVGA_CASE_ID2STR(SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND);
275 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED2_1);
276 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED2_2);
277 SVGA_CASE_ID2STR(SVGA_3D_CMD_DEFINE_GB_SURFACE_V4);
278 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_CS_UA_VIEWS);
279 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_MIN_LOD);
280 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED2_3);
281 SVGA_CASE_ID2STR(SVGA_3D_CMD_RESERVED2_4);
282 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2);
283 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB);
284 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_SET_SHADER_IFACE);
285 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_STREAMOUTPUT);
286 SVGA_CASE_ID2STR(SVGA_3D_CMD_SURFACE_STRETCHBLT_NON_MS_TO_MS);
287 SVGA_CASE_ID2STR(SVGA_3D_CMD_DX_BIND_SHADER_IFACE);
288 SVGA_CASE_ID2STR(SVGA_3D_CMD_MAX);
289 SVGA_CASE_ID2STR(SVGA_3D_CMD_FUTURE_MAX);
290 }
291 return "UNKNOWN_3D";
292}
293
294/**
295 * FIFO command name lookup
296 *
297 * @returns FIFO command string or "UNKNOWN"
298 * @param u32Cmd FIFO command
299 */
300const char *vmsvgaR3FifoCmdToString(uint32_t u32Cmd)
301{
302 switch (u32Cmd)
303 {
304 SVGA_CASE_ID2STR(SVGA_CMD_INVALID_CMD);
305 SVGA_CASE_ID2STR(SVGA_CMD_UPDATE);
306 SVGA_CASE_ID2STR(SVGA_CMD_RECT_FILL);
307 SVGA_CASE_ID2STR(SVGA_CMD_RECT_COPY);
308 SVGA_CASE_ID2STR(SVGA_CMD_RECT_ROP_COPY);
309 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_CURSOR);
310 SVGA_CASE_ID2STR(SVGA_CMD_DISPLAY_CURSOR);
311 SVGA_CASE_ID2STR(SVGA_CMD_MOVE_CURSOR);
312 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_ALPHA_CURSOR);
313 SVGA_CASE_ID2STR(SVGA_CMD_UPDATE_VERBOSE);
314 SVGA_CASE_ID2STR(SVGA_CMD_FRONT_ROP_FILL);
315 SVGA_CASE_ID2STR(SVGA_CMD_FENCE);
316 SVGA_CASE_ID2STR(SVGA_CMD_ESCAPE);
317 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_SCREEN);
318 SVGA_CASE_ID2STR(SVGA_CMD_DESTROY_SCREEN);
319 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_GMRFB);
320 SVGA_CASE_ID2STR(SVGA_CMD_BLIT_GMRFB_TO_SCREEN);
321 SVGA_CASE_ID2STR(SVGA_CMD_BLIT_SCREEN_TO_GMRFB);
322 SVGA_CASE_ID2STR(SVGA_CMD_ANNOTATION_FILL);
323 SVGA_CASE_ID2STR(SVGA_CMD_ANNOTATION_COPY);
324 SVGA_CASE_ID2STR(SVGA_CMD_DEFINE_GMR2);
325 SVGA_CASE_ID2STR(SVGA_CMD_REMAP_GMR2);
326 SVGA_CASE_ID2STR(SVGA_CMD_DEAD);
327 SVGA_CASE_ID2STR(SVGA_CMD_DEAD_2);
328 SVGA_CASE_ID2STR(SVGA_CMD_NOP);
329 SVGA_CASE_ID2STR(SVGA_CMD_NOP_ERROR);
330 SVGA_CASE_ID2STR(SVGA_CMD_MAX);
331 default:
332 if ( u32Cmd >= SVGA_3D_CMD_BASE
333 && u32Cmd < SVGA_3D_CMD_MAX)
334 return vmsvgaFifo3dCmdToString((SVGAFifo3dCmdId)u32Cmd);
335 }
336 return "UNKNOWN";
337}
338# undef SVGA_CASE_ID2STR
339#endif /* LOG_ENABLED || VBOX_STRICT */
340
341
342/*
343 *
344 * Guest-Backed Objects (GBO).
345 *
346 */
347
348/**
349 * HC access handler for GBOs which require write protection, i.e. OTables, etc.
350 *
351 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
352 * @param pVM VM Handle.
353 * @param pVCpu The cross context CPU structure for the calling EMT.
354 * @param GCPhys The physical address the guest is writing to.
355 * @param pvPhys The HC mapping of that address.
356 * @param pvBuf What the guest is reading/writing.
357 * @param cbBuf How much it's reading/writing.
358 * @param enmAccessType The access type.
359 * @param enmOrigin Who is making the access.
360 * @param uUser The VMM automatically sets this to the address of
361 * the device instance.
362 */
363DECLCALLBACK(VBOXSTRICTRC)
364vmsvgaR3GboAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
365 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
366{
367 RT_NOREF(pVM, pVCpu, pvPhys, enmAccessType);
368
369 if (RT_LIKELY(enmOrigin == PGMACCESSORIGIN_DEVICE || enmOrigin == PGMACCESSORIGIN_DEBUGGER))
370 return VINF_PGM_HANDLER_DO_DEFAULT;
371
372 PPDMDEVINS pDevIns = (PPDMDEVINS)uUser;
373 AssertPtrReturn(pDevIns, VERR_INTERNAL_ERROR_4);
374 AssertReturn(pDevIns->u32Version == PDM_DEVINSR3_VERSION, VERR_INTERNAL_ERROR_5);
375 PVGASTATE pThis = PDMDEVINS_2_DATA(pDevIns, PVGASTATE);
376 PVGASTATECC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVGASTATECC);
377 PVMSVGAR3STATE pSvgaR3State = pThisCC->svga.pSvgaR3State;
378
379 /*
380 * The guest is not allowed to access the memory.
381 * Set the error condition.
382 */
383 ASMAtomicWriteBool(&pThis->svga.fBadGuest, true);
384
385 /* Try to find the GBO which the guest is accessing. */
386 char const *pszTarget = NULL;
387 for (uint32_t i = 0; i < RT_ELEMENTS(pSvgaR3State->aGboOTables) && !pszTarget; ++i)
388 {
389 PVMSVGAGBO pGbo = &pSvgaR3State->aGboOTables[i];
390 if (pGbo->cDescriptors)
391 {
392 for (uint32_t j = 0; j < pGbo->cDescriptors; ++j)
393 {
394 if ( GCPhys >= pGbo->paDescriptors[j].GCPhys
395 && GCPhys < pGbo->paDescriptors[j].GCPhys + pGbo->paDescriptors[j].cPages * PAGE_SIZE)
396 {
397 switch (i)
398 {
399 case SVGA_OTABLE_MOB: pszTarget = "SVGA_OTABLE_MOB"; break;
400 case SVGA_OTABLE_SURFACE: pszTarget = "SVGA_OTABLE_SURFACE"; break;
401 case SVGA_OTABLE_CONTEXT: pszTarget = "SVGA_OTABLE_CONTEXT"; break;
402 case SVGA_OTABLE_SHADER: pszTarget = "SVGA_OTABLE_SHADER"; break;
403 case SVGA_OTABLE_SCREENTARGET: pszTarget = "SVGA_OTABLE_SCREENTARGET"; break;
404 case SVGA_OTABLE_DXCONTEXT: pszTarget = "SVGA_OTABLE_DXCONTEXT"; break;
405 default: pszTarget = "Unknown OTABLE"; break;
406 }
407 break;
408 }
409 }
410 }
411 }
412
413 LogRelMax(8, ("VMSVGA: invalid guest access to page %RGp, target %s:\n"
414 "%.*Rhxd\n",
415 GCPhys, pszTarget ? pszTarget : "unknown", RT_MIN(cbBuf, 256), pvBuf));
416
417 return VINF_PGM_HANDLER_DO_DEFAULT;
418}
419
420#ifdef VBOX_WITH_VMSVGA3D
421
422static int vmsvgaR3GboCreate(PVMSVGAR3STATE pSvgaR3State, SVGAMobFormat ptDepth, PPN64 baseAddress, uint32_t sizeInBytes, bool fGCPhys64, bool fWriteProtected, PVMSVGAGBO pGbo)
423{
424 ASSERT_GUEST_RETURN(sizeInBytes <= _128M, VERR_INVALID_PARAMETER); /** @todo Less than SVGA_REG_MOB_MAX_SIZE */
425
426 /*
427 * The 'baseAddress' is a page number and points to the 'root page' of the GBO.
428 * Content of the root page depends on the ptDepth value:
429 * SVGA3D_MOBFMT_PTDEPTH[64]_0 - the only data page;
430 * SVGA3D_MOBFMT_PTDEPTH[64]_1 - array of page numbers for data pages;
431 * SVGA3D_MOBFMT_PTDEPTH[64]_2 - array of page numbers for SVGA3D_MOBFMT_PTDEPTH[64]_1 pages.
432 * The code below extracts the page addresses of the GBO.
433 */
434
435 /* Verify and normalize the ptDepth value. */
436 if (RT_LIKELY( ptDepth == SVGA3D_MOBFMT_PTDEPTH64_0
437 || ptDepth == SVGA3D_MOBFMT_PTDEPTH64_1
438 || ptDepth == SVGA3D_MOBFMT_PTDEPTH64_2))
439 ASSERT_GUEST_RETURN(fGCPhys64, VERR_INVALID_PARAMETER);
440 else if ( ptDepth == SVGA3D_MOBFMT_PTDEPTH_0
441 || ptDepth == SVGA3D_MOBFMT_PTDEPTH_1
442 || ptDepth == SVGA3D_MOBFMT_PTDEPTH_2)
443 {
444 ASSERT_GUEST_RETURN(!fGCPhys64, VERR_INVALID_PARAMETER);
445 /* Shift ptDepth to the SVGA3D_MOBFMT_PTDEPTH64_x range. */
446 ptDepth = (SVGAMobFormat)(ptDepth + SVGA3D_MOBFMT_PTDEPTH64_0 - SVGA3D_MOBFMT_PTDEPTH_0);
447 }
448 else if (ptDepth == SVGA3D_MOBFMT_RANGE)
449 { }
450 else
451 ASSERT_GUEST_FAILED_RETURN(VERR_INVALID_PARAMETER);
452
453 uint32_t const cPPNsPerPage = X86_PAGE_SIZE / (fGCPhys64 ? sizeof(PPN64) : sizeof(PPN));
454
455 pGbo->cbTotal = sizeInBytes;
456 pGbo->cTotalPages = (sizeInBytes + X86_PAGE_SIZE - 1) >> X86_PAGE_SHIFT;
457
458 /* Allocate the maximum amount possible (everything non-continuous) */
459 PVMSVGAGBODESCRIPTOR paDescriptors = (PVMSVGAGBODESCRIPTOR)RTMemAlloc(pGbo->cTotalPages * sizeof(VMSVGAGBODESCRIPTOR));
460 AssertReturn(paDescriptors, VERR_NO_MEMORY);
461
462 int rc = VINF_SUCCESS;
463 if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_0)
464 {
465 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages == 1,
466 RTMemFree(paDescriptors),
467 VERR_INVALID_PARAMETER);
468
469 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
470 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
471 paDescriptors[0].GCPhys = GCPhys;
472 paDescriptors[0].cPages = 1;
473 }
474 else if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_1)
475 {
476 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages <= cPPNsPerPage,
477 RTMemFree(paDescriptors),
478 VERR_INVALID_PARAMETER);
479
480 /* Read the root page. */
481 uint8_t au8RootPage[X86_PAGE_SIZE];
482 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
483 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhys, &au8RootPage, sizeof(au8RootPage));
484 if (RT_SUCCESS(rc))
485 {
486 PPN64 *paPPN64 = (PPN64 *)&au8RootPage[0];
487 PPN *paPPN32 = (PPN *)&au8RootPage[0];
488 for (uint32_t iPPN = 0; iPPN < pGbo->cTotalPages; ++iPPN)
489 {
490 GCPhys = (RTGCPHYS)(fGCPhys64 ? paPPN64[iPPN] : paPPN32[iPPN]) << X86_PAGE_SHIFT;
491 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
492 paDescriptors[iPPN].GCPhys = GCPhys;
493 paDescriptors[iPPN].cPages = 1;
494 }
495 }
496 }
497 else if (ptDepth == SVGA3D_MOBFMT_PTDEPTH64_2)
498 {
499 ASSERT_GUEST_STMT_RETURN(pGbo->cTotalPages <= cPPNsPerPage * cPPNsPerPage,
500 RTMemFree(paDescriptors),
501 VERR_INVALID_PARAMETER);
502
503 /* Read the Level2 root page. */
504 uint8_t au8RootPageLevel2[X86_PAGE_SIZE];
505 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
506 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhys, &au8RootPageLevel2, sizeof(au8RootPageLevel2));
507 if (RT_SUCCESS(rc))
508 {
509 uint32_t cPagesLeft = pGbo->cTotalPages;
510
511 PPN64 *paPPN64Level2 = (PPN64 *)&au8RootPageLevel2[0];
512 PPN *paPPN32Level2 = (PPN *)&au8RootPageLevel2[0];
513
514 uint32_t const cPPNsLevel2 = (pGbo->cTotalPages + cPPNsPerPage - 1) / cPPNsPerPage;
515 for (uint32_t iPPNLevel2 = 0; iPPNLevel2 < cPPNsLevel2; ++iPPNLevel2)
516 {
517 /* Read the Level1 root page. */
518 uint8_t au8RootPage[X86_PAGE_SIZE];
519 RTGCPHYS GCPhysLevel1 = (RTGCPHYS)(fGCPhys64 ? paPPN64Level2[iPPNLevel2] : paPPN32Level2[iPPNLevel2]) << X86_PAGE_SHIFT;
520 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
521 rc = PDMDevHlpPCIPhysRead(pSvgaR3State->pDevIns, GCPhysLevel1, &au8RootPage, sizeof(au8RootPage));
522 if (RT_SUCCESS(rc))
523 {
524 PPN64 *paPPN64 = (PPN64 *)&au8RootPage[0];
525 PPN *paPPN32 = (PPN *)&au8RootPage[0];
526
527 uint32_t const cPPNs = RT_MIN(cPagesLeft, cPPNsPerPage);
528 for (uint32_t iPPN = 0; iPPN < cPPNs; ++iPPN)
529 {
530 GCPhys = (RTGCPHYS)(fGCPhys64 ? paPPN64[iPPN] : paPPN32[iPPN]) << X86_PAGE_SHIFT;
531 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
532 paDescriptors[iPPN + iPPNLevel2 * cPPNsPerPage].GCPhys = GCPhys;
533 paDescriptors[iPPN + iPPNLevel2 * cPPNsPerPage].cPages = 1;
534 }
535 cPagesLeft -= cPPNs;
536 }
537 }
538 }
539 }
540 else if (ptDepth == SVGA3D_MOBFMT_RANGE)
541 {
542 RTGCPHYS GCPhys = (RTGCPHYS)baseAddress << X86_PAGE_SHIFT;
543 GCPhys &= UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
544 paDescriptors[0].GCPhys = GCPhys;
545 paDescriptors[0].cPages = pGbo->cTotalPages;
546 }
547 else
548 {
549 AssertFailed();
550 return VERR_INTERNAL_ERROR; /* ptDepth should be already verified. */
551 }
552
553 /* Compress the descriptors. */
554 if (ptDepth != SVGA3D_MOBFMT_RANGE)
555 {
556 uint32_t iDescriptor = 0;
557 for (uint32_t i = 1; i < pGbo->cTotalPages; ++i)
558 {
559 /* Continuous physical memory? */
560 if (paDescriptors[i].GCPhys == paDescriptors[iDescriptor].GCPhys + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE)
561 {
562 Assert(paDescriptors[iDescriptor].cPages);
563 paDescriptors[iDescriptor].cPages++;
564 Log5Func(("Page %x GCPhys=%RGp successor\n", i, paDescriptors[i].GCPhys));
565 }
566 else
567 {
568 iDescriptor++;
569 paDescriptors[iDescriptor].GCPhys = paDescriptors[i].GCPhys;
570 paDescriptors[iDescriptor].cPages = 1;
571 Log5Func(("Page %x GCPhys=%RGp\n", i, paDescriptors[iDescriptor].GCPhys));
572 }
573 }
574
575 pGbo->cDescriptors = iDescriptor + 1;
576 Log5Func(("Nr of descriptors %d\n", pGbo->cDescriptors));
577 }
578 else
579 pGbo->cDescriptors = 1;
580
581 if (RT_LIKELY(pGbo->cDescriptors < pGbo->cTotalPages))
582 {
583 pGbo->paDescriptors = (PVMSVGAGBODESCRIPTOR)RTMemRealloc(paDescriptors, pGbo->cDescriptors * sizeof(VMSVGAGBODESCRIPTOR));
584 AssertReturn(pGbo->paDescriptors, VERR_NO_MEMORY);
585 }
586 else
587 pGbo->paDescriptors = paDescriptors;
588
589#if 1 /// @todo PGMHandlerPhysicalRegister asserts deep in PGM code with enmKind of a page being out of range.
590fWriteProtected = false;
591#endif
592 if (fWriteProtected)
593 {
594 pGbo->fGboFlags |= VMSVGAGBO_F_WRITE_PROTECTED;
595 for (uint32_t i = 0; i < pGbo->cDescriptors; ++i)
596 {
597 rc = PDMDevHlpPGMHandlerPhysicalRegister(pSvgaR3State->pDevIns, pGbo->paDescriptors[i].GCPhys,
598 pGbo->paDescriptors[i].GCPhys + pGbo->paDescriptors[i].cPages * PAGE_SIZE - 1,
599 pSvgaR3State->hGboAccessHandlerType, "VMSVGA GBO");
600 AssertRC(rc);
601 }
602 }
603
604 return VINF_SUCCESS;
605}
606
607
608static void vmsvgaR3GboDestroy(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo)
609{
610 if (RT_LIKELY(VMSVGA_IS_GBO_CREATED(pGbo)))
611 {
612 if (pGbo->fGboFlags & VMSVGAGBO_F_WRITE_PROTECTED)
613 {
614 for (uint32_t i = 0; i < pGbo->cDescriptors; ++i)
615 {
616 int rc = PDMDevHlpPGMHandlerPhysicalDeregister(pSvgaR3State->pDevIns, pGbo->paDescriptors[i].GCPhys);
617 AssertRC(rc);
618 }
619 }
620 RTMemFree(pGbo->paDescriptors);
621 RT_ZERO(pGbo);
622 }
623}
624
625/** @todo static void vmsvgaR3GboWriteProtect(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo, bool fWriteProtect) */
626
627typedef enum VMSVGAGboTransferDirection
628{
629 VMSVGAGboTransferDirection_Read,
630 VMSVGAGboTransferDirection_Write,
631} VMSVGAGboTransferDirection;
632
633static int vmsvgaR3GboTransfer(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
634 uint32_t off, void *pvData, uint32_t cbData,
635 VMSVGAGboTransferDirection enmDirection)
636{
637 //DEBUG_BREAKPOINT_TEST();
638 int rc = VINF_SUCCESS;
639 uint8_t *pu8CurrentHost = (uint8_t *)pvData;
640
641 /* Find the right descriptor */
642 PCVMSVGAGBODESCRIPTOR const paDescriptors = pGbo->paDescriptors;
643 uint32_t iDescriptor = 0; /* Index in the descriptor array. */
644 uint32_t offDescriptor = 0; /* GMR offset of the current descriptor. */
645 while (offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE <= off)
646 {
647 offDescriptor += paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE;
648 AssertReturn(offDescriptor < pGbo->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
649 ++iDescriptor;
650 AssertReturn(iDescriptor < pGbo->cDescriptors, VERR_INTERNAL_ERROR);
651 }
652
653 while (cbData)
654 {
655 uint32_t cbToCopy;
656 if (off + cbData <= offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE)
657 cbToCopy = cbData;
658 else
659 {
660 cbToCopy = (offDescriptor + paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE - off);
661 AssertReturn(cbToCopy <= cbData, VERR_INVALID_PARAMETER);
662 }
663
664 RTGCPHYS const GCPhys = paDescriptors[iDescriptor].GCPhys + off - offDescriptor;
665 Log5Func(("%s phys=%RGp\n", (enmDirection == VMSVGAGboTransferDirection_Read) ? "READ" : "WRITE", GCPhys));
666
667 /*
668 * We are deliberately using the non-PCI version of PDMDevHlpPCIPhys[Read|Write] as the
669 * guest-side VMSVGA driver seems to allocate non-DMA (regular physical) addresses,
670 * see @bugref{9654#c75}.
671 */
672 if (enmDirection == VMSVGAGboTransferDirection_Read)
673 rc = PDMDevHlpPhysRead(pSvgaR3State->pDevIns, GCPhys, pu8CurrentHost, cbToCopy);
674 else
675 rc = PDMDevHlpPhysWrite(pSvgaR3State->pDevIns, GCPhys, pu8CurrentHost, cbToCopy);
676 AssertRCBreak(rc);
677
678 cbData -= cbToCopy;
679 off += cbToCopy;
680 pu8CurrentHost += cbToCopy;
681
682 /* Go to the next descriptor if there's anything left. */
683 if (cbData)
684 {
685 offDescriptor += paDescriptors[iDescriptor].cPages * X86_PAGE_SIZE;
686 AssertReturn(offDescriptor < pGbo->cbTotal, VERR_INTERNAL_ERROR);
687 ++iDescriptor;
688 AssertReturn(iDescriptor < pGbo->cDescriptors, VERR_INTERNAL_ERROR);
689 }
690 }
691 return rc;
692}
693
694
695static int vmsvgaR3GboWrite(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
696 uint32_t off, void const *pvData, uint32_t cbData)
697{
698 return vmsvgaR3GboTransfer(pSvgaR3State, pGbo,
699 off, (void *)pvData, cbData,
700 VMSVGAGboTransferDirection_Write);
701}
702
703
704static int vmsvgaR3GboRead(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo,
705 uint32_t off, void *pvData, uint32_t cbData)
706{
707 return vmsvgaR3GboTransfer(pSvgaR3State, pGbo,
708 off, pvData, cbData,
709 VMSVGAGboTransferDirection_Read);
710}
711
712
713static int vmsvgaR3GboBackingStoreCreate(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo, uint32_t cbValid)
714{
715 int rc;
716
717 /* Just reread the data if pvHost has been allocated already. */
718 if (!(pGbo->fGboFlags & VMSVGAGBO_F_HOST_BACKED))
719 pGbo->pvHost = RTMemAllocZ(pGbo->cbTotal);
720
721 if (pGbo->pvHost)
722 {
723 cbValid = RT_MIN(cbValid, pGbo->cbTotal);
724 rc = vmsvgaR3GboRead(pSvgaR3State, pGbo, 0, pGbo->pvHost, cbValid);
725 }
726 else
727 rc = VERR_NO_MEMORY;
728
729 if (RT_SUCCESS(rc))
730 pGbo->fGboFlags |= VMSVGAGBO_F_HOST_BACKED;
731 else
732 {
733 RTMemFree(pGbo->pvHost);
734 pGbo->pvHost = NULL;
735 }
736 return rc;
737}
738
739
740static void vmsvgaR3GboBackingStoreDelete(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo)
741{
742 RT_NOREF(pSvgaR3State);
743 AssertReturnVoid(pGbo->fGboFlags & VMSVGAGBO_F_HOST_BACKED);
744 RTMemFree(pGbo->pvHost);
745 pGbo->pvHost = NULL;
746 pGbo->fGboFlags &= ~VMSVGAGBO_F_HOST_BACKED;
747}
748
749
750static int vmsvgaR3GboBackingStoreWriteToGuest(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo)
751{
752 AssertReturn(pGbo->fGboFlags & VMSVGAGBO_F_HOST_BACKED, VERR_INVALID_STATE);
753 return vmsvgaR3GboWrite(pSvgaR3State, pGbo, 0, pGbo->pvHost, pGbo->cbTotal);
754}
755
756
757static int vmsvgaR3GboBackingStoreReadFromGuest(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGbo)
758{
759 AssertReturn(pGbo->fGboFlags & VMSVGAGBO_F_HOST_BACKED, VERR_INVALID_STATE);
760 return vmsvgaR3GboRead(pSvgaR3State, pGbo, 0, pGbo->pvHost, pGbo->cbTotal);
761}
762
763
764
765/*
766 *
767 * Object Tables.
768 *
769 */
770
771static int vmsvgaR3OTableVerifyIndex(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
772 uint32_t idx, uint32_t cbEntry)
773{
774 RT_NOREF(pSvgaR3State);
775
776 /* The table must exist and the index must be within the table. */
777 ASSERT_GUEST_RETURN(VMSVGA_IS_GBO_CREATED(pGboOTable), VERR_INVALID_PARAMETER);
778 ASSERT_GUEST_RETURN(idx < pGboOTable->cbTotal / cbEntry, VERR_INVALID_PARAMETER);
779 RT_UNTRUSTED_VALIDATED_FENCE();
780 return VINF_SUCCESS;
781}
782
783
784static int vmsvgaR3OTableRead(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
785 uint32_t idx, uint32_t cbEntry,
786 void *pvData, uint32_t cbData)
787{
788 AssertReturn(cbData <= cbEntry, VERR_INVALID_PARAMETER);
789
790 int rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, pGboOTable, idx, cbEntry);
791 if (RT_SUCCESS(rc))
792 {
793 uint32_t const off = idx * cbEntry;
794 rc = vmsvgaR3GboRead(pSvgaR3State, pGboOTable, off, pvData, cbData);
795 }
796 return rc;
797}
798
799static int vmsvgaR3OTableWrite(PVMSVGAR3STATE pSvgaR3State, PVMSVGAGBO pGboOTable,
800 uint32_t idx, uint32_t cbEntry,
801 void const *pvData, uint32_t cbData)
802{
803 AssertReturn(cbData <= cbEntry, VERR_INVALID_PARAMETER);
804
805 int rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, pGboOTable, idx, cbEntry);
806 if (RT_SUCCESS(rc))
807 {
808 uint32_t const off = idx * cbEntry;
809 rc = vmsvgaR3GboWrite(pSvgaR3State, pGboOTable, off, pvData, cbData);
810 }
811 return rc;
812}
813
814
815/*
816 *
817 * The guest's Memory OBjects (MOB).
818 *
819 */
820
821static int vmsvgaR3MobCreate(PVMSVGAR3STATE pSvgaR3State,
822 SVGAMobFormat ptDepth, PPN64 baseAddress, uint32_t sizeInBytes, SVGAMobId mobid,
823 bool fGCPhys64, PVMSVGAMOB pMob)
824{
825 RT_ZERO(*pMob);
826
827 /* Update the entry in the pSvgaR3State->pGboOTableMob. */
828 SVGAOTableMobEntry entry;
829 entry.ptDepth = ptDepth;
830 entry.sizeInBytes = sizeInBytes;
831 entry.base = baseAddress;
832 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
833 mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE, &entry, sizeof(entry));
834 if (RT_SUCCESS(rc))
835 {
836 /* Create the corresponding GBO. */
837 rc = vmsvgaR3GboCreate(pSvgaR3State, ptDepth, baseAddress, sizeInBytes, fGCPhys64, /* fWriteProtected = */ false, &pMob->Gbo);
838 if (RT_SUCCESS(rc))
839 {
840 /* Add to the tree of known GBOs and the LRU list. */
841 pMob->Core.Key = mobid;
842 if (RTAvlU32Insert(&pSvgaR3State->MOBTree, &pMob->Core))
843 {
844 RTListPrepend(&pSvgaR3State->MOBLRUList, &pMob->nodeLRU);
845 return VINF_SUCCESS;
846 }
847
848 vmsvgaR3GboDestroy(pSvgaR3State, &pMob->Gbo);
849 }
850 }
851
852 return rc;
853}
854
855
856static int vmsvgaR3MobDestroy(PVMSVGAR3STATE pSvgaR3State, SVGAMobId mobid)
857{
858 /* Update the entry in the pSvgaR3State->pGboOTableMob. */
859 SVGAOTableMobEntry entry;
860 RT_ZERO(entry);
861 vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
862 mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE, &entry, sizeof(entry));
863
864 PVMSVGAMOB pMob = (PVMSVGAMOB)RTAvlU32Remove(&pSvgaR3State->MOBTree, mobid);
865 if (pMob)
866 {
867 RTListNodeRemove(&pMob->nodeLRU);
868 vmsvgaR3GboDestroy(pSvgaR3State, &pMob->Gbo);
869 RTMemFree(pMob);
870 return VINF_SUCCESS;
871 }
872
873 return VERR_INVALID_PARAMETER;
874}
875
876
877static PVMSVGAMOB vmsvgaR3MobGet(PVMSVGAR3STATE pSvgaR3State, SVGAMobId RT_UNTRUSTED_GUEST mobid)
878{
879 if (mobid == SVGA_ID_INVALID)
880 return NULL;
881
882 PVMSVGAMOB pMob = (PVMSVGAMOB)RTAvlU32Get(&pSvgaR3State->MOBTree, mobid);
883 if (pMob)
884 {
885 /* Move to the head of the LRU list. */
886 RTListNodeRemove(&pMob->nodeLRU);
887 RTListPrepend(&pSvgaR3State->MOBLRUList, &pMob->nodeLRU);
888 }
889 else
890 ASSERT_GUEST_FAILED();
891
892 return pMob;
893}
894
895
896/** Create a host ring-3 pointer to the MOB data.
897 * Current approach is to allocate a host memory buffer and copy the guest MOB data if necessary.
898 * @param pSvgaR3State R3 device state.
899 * @param pMob The MOB.
900 * @param cbValid How many bytes of the guest backing memory contain valid data.
901 * @return VBox status.
902 */
903/** @todo uint32_t cbValid -> uint32_t offStart, uint32_t cbData */
904int vmsvgaR3MobBackingStoreCreate(PVMSVGAR3STATE pSvgaR3State, PVMSVGAMOB pMob, uint32_t cbValid)
905{
906 AssertReturn(pMob, VERR_INVALID_PARAMETER);
907 return vmsvgaR3GboBackingStoreCreate(pSvgaR3State, &pMob->Gbo, cbValid);
908}
909
910
911void vmsvgaR3MobBackingStoreDelete(PVMSVGAR3STATE pSvgaR3State, PVMSVGAMOB pMob)
912{
913 if (pMob)
914 vmsvgaR3GboBackingStoreDelete(pSvgaR3State, &pMob->Gbo);
915}
916
917
918int vmsvgaR3MobBackingStoreWriteToGuest(PVMSVGAR3STATE pSvgaR3State, PVMSVGAMOB pMob)
919{
920 if (pMob)
921 return vmsvgaR3GboBackingStoreWriteToGuest(pSvgaR3State, &pMob->Gbo);
922 return VERR_INVALID_PARAMETER;
923}
924
925
926int vmsvgaR3MobBackingStoreReadFromGuest(PVMSVGAR3STATE pSvgaR3State, PVMSVGAMOB pMob)
927{
928 if (pMob)
929 return vmsvgaR3GboBackingStoreReadFromGuest(pSvgaR3State, &pMob->Gbo);
930 return VERR_INVALID_PARAMETER;
931}
932
933
934void *vmsvgaR3MobBackingStorePtr(PVMSVGAMOB pMob, uint32_t off)
935{
936 if (pMob && (pMob->Gbo.fGboFlags & VMSVGAGBO_F_HOST_BACKED))
937 {
938 if (off <= pMob->Gbo.cbTotal)
939 return (uint8_t *)pMob->Gbo.pvHost + off;
940 }
941 return NULL;
942}
943
944
945int vmsvgaR3UpdateGBSurface(PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pImageId, SVGA3dBox const *pBox)
946{
947 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
948
949 SVGAOTableSurfaceEntry entrySurface;
950 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
951 pImageId->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
952 if (RT_SUCCESS(rc))
953 {
954 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
955 if (pMob)
956 {
957 VMSVGA3D_MAPPED_SURFACE map;
958 rc = vmsvga3dSurfaceMap(pThisCC, pImageId, pBox, VMSVGA3D_SURFACE_MAP_WRITE, &map);
959 if (RT_SUCCESS(rc))
960 {
961 /* Copy MOB -> mapped surface. */
962 uint32_t offSrc = pBox->x * map.cbPixel
963 + pBox->y * entrySurface.size.width * map.cbPixel
964 + pBox->z * entrySurface.size.height * entrySurface.size.width * map.cbPixel;
965 uint8_t *pu8Dst = (uint8_t *)map.pvData;
966 for (uint32_t z = 0; z < pBox->d; ++z)
967 {
968 for (uint32_t y = 0; y < pBox->h; ++y)
969 {
970 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, offSrc, pu8Dst, pBox->w * map.cbPixel);
971 if (RT_FAILURE(rc))
972 break;
973
974 pu8Dst += map.cbRowPitch;
975 offSrc += entrySurface.size.width * map.cbPixel;
976 }
977
978 pu8Dst += map.cbDepthPitch;
979 offSrc += entrySurface.size.height * entrySurface.size.width * map.cbPixel;
980 }
981
982 vmsvga3dSurfaceUnmap(pThisCC, pImageId, &map, /* fWritten= */ true);
983 }
984 }
985 else
986 rc = VERR_INVALID_STATE;
987 }
988
989 return rc;
990}
991
992
993int vmsvgaR3UpdateGBSurfaceEx(PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pImageId, SVGA3dBox const *pBoxDst, SVGA3dPoint const *pPtSrc)
994{
995 /* pPtSrc must be verified by the caller. */
996 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
997
998 SVGAOTableSurfaceEntry entrySurface;
999 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1000 pImageId->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1001 if (RT_SUCCESS(rc))
1002 {
1003 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1004 if (pMob)
1005 {
1006 VMSVGA3D_MAPPED_SURFACE map;
1007 rc = vmsvga3dSurfaceMap(pThisCC, pImageId, pBoxDst, VMSVGA3D_SURFACE_MAP_WRITE, &map);
1008 if (RT_SUCCESS(rc))
1009 {
1010 /* Copy MOB -> mapped surface. */
1011 uint32_t offSrc = pPtSrc->x * map.cbPixel
1012 + pPtSrc->y * entrySurface.size.width * map.cbPixel
1013 + pPtSrc->z * entrySurface.size.height * entrySurface.size.width * map.cbPixel;
1014 uint8_t *pu8Dst = (uint8_t *)map.pvData;
1015 for (uint32_t z = 0; z < pBoxDst->d; ++z)
1016 {
1017 for (uint32_t y = 0; y < pBoxDst->h; ++y)
1018 {
1019 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, offSrc, pu8Dst, pBoxDst->w * map.cbPixel);
1020 if (RT_FAILURE(rc))
1021 break;
1022
1023 pu8Dst += map.cbRowPitch;
1024 offSrc += entrySurface.size.width * map.cbPixel;
1025 }
1026
1027 pu8Dst += map.cbDepthPitch;
1028 offSrc += entrySurface.size.height * entrySurface.size.width * map.cbPixel;
1029 }
1030
1031 vmsvga3dSurfaceUnmap(pThisCC, pImageId, &map, /* fWritten= */ true);
1032 }
1033 }
1034 else
1035 rc = VERR_INVALID_STATE;
1036 }
1037
1038 return rc;
1039}
1040
1041#endif /* VBOX_WITH_VMSVGA3D */
1042
1043/*
1044 * Screen objects.
1045 */
1046VMSVGASCREENOBJECT *vmsvgaR3GetScreenObject(PVGASTATECC pThisCC, uint32_t idScreen)
1047{
1048 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
1049 if ( idScreen < (uint32_t)RT_ELEMENTS(pSVGAState->aScreens)
1050 && pSVGAState
1051 && pSVGAState->aScreens[idScreen].fDefined)
1052 {
1053 return &pSVGAState->aScreens[idScreen];
1054 }
1055 return NULL;
1056}
1057
1058void vmsvgaR3ResetScreens(PVGASTATE pThis, PVGASTATECC pThisCC)
1059{
1060#ifdef VBOX_WITH_VMSVGA3D
1061 if (pThis->svga.f3DEnabled)
1062 {
1063 for (uint32_t idScreen = 0; idScreen < (uint32_t)RT_ELEMENTS(pThisCC->svga.pSvgaR3State->aScreens); ++idScreen)
1064 {
1065 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, idScreen);
1066 if (pScreen)
1067 vmsvga3dDestroyScreen(pThisCC, pScreen);
1068 }
1069 }
1070#else
1071 RT_NOREF(pThis, pThisCC);
1072#endif
1073}
1074
1075
1076/**
1077 * Copy a rectangle of pixels within guest VRAM.
1078 */
1079static void vmsvgaR3RectCopy(PVGASTATECC pThisCC, VMSVGASCREENOBJECT const *pScreen, uint32_t srcX, uint32_t srcY,
1080 uint32_t dstX, uint32_t dstY, uint32_t width, uint32_t height, unsigned cbFrameBuffer)
1081{
1082 if (!width || !height)
1083 return; /* Nothing to do, don't even bother. */
1084
1085 /*
1086 * The guest VRAM (aka GFB) is considered to be a bitmap in the format
1087 * corresponding to the current display mode.
1088 */
1089 uint32_t const cbPixel = RT_ALIGN(pScreen->cBpp, 8) / 8;
1090 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch : width * cbPixel;
1091 uint8_t const *pSrc;
1092 uint8_t *pDst;
1093 unsigned const cbRectWidth = width * cbPixel;
1094 unsigned uMaxOffset;
1095
1096 uMaxOffset = (RT_MAX(srcY, dstY) + height) * cbScanline + (RT_MAX(srcX, dstX) + width) * cbPixel;
1097 if (uMaxOffset >= cbFrameBuffer)
1098 {
1099 Log(("Max offset (%u) too big for framebuffer (%u bytes), ignoring!\n", uMaxOffset, cbFrameBuffer));
1100 return; /* Just don't listen to a bad guest. */
1101 }
1102
1103 pSrc = pDst = pThisCC->pbVRam;
1104 pSrc += srcY * cbScanline + srcX * cbPixel;
1105 pDst += dstY * cbScanline + dstX * cbPixel;
1106
1107 if (srcY >= dstY)
1108 {
1109 /* Source below destination, copy top to bottom. */
1110 for (; height > 0; height--)
1111 {
1112 memmove(pDst, pSrc, cbRectWidth);
1113 pSrc += cbScanline;
1114 pDst += cbScanline;
1115 }
1116 }
1117 else
1118 {
1119 /* Source above destination, copy bottom to top. */
1120 pSrc += cbScanline * (height - 1);
1121 pDst += cbScanline * (height - 1);
1122 for (; height > 0; height--)
1123 {
1124 memmove(pDst, pSrc, cbRectWidth);
1125 pSrc -= cbScanline;
1126 pDst -= cbScanline;
1127 }
1128 }
1129}
1130
1131
1132/**
1133 * Common worker for changing the pointer shape.
1134 *
1135 * @param pThisCC The VGA/VMSVGA state for ring-3.
1136 * @param pSVGAState The VMSVGA ring-3 instance data.
1137 * @param fAlpha Whether there is alpha or not.
1138 * @param xHot Hotspot x coordinate.
1139 * @param yHot Hotspot y coordinate.
1140 * @param cx Width.
1141 * @param cy Height.
1142 * @param pbData Heap copy of the cursor data. Consumed.
1143 * @param cbData The size of the data.
1144 */
1145static void vmsvgaR3InstallNewCursor(PVGASTATECC pThisCC, PVMSVGAR3STATE pSVGAState, bool fAlpha,
1146 uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, uint8_t *pbData, uint32_t cbData)
1147{
1148 LogRel2(("vmsvgaR3InstallNewCursor: cx=%d cy=%d xHot=%d yHot=%d fAlpha=%d cbData=%#x\n", cx, cy, xHot, yHot, fAlpha, cbData));
1149#ifdef LOG_ENABLED
1150 if (LogIs2Enabled())
1151 {
1152 uint32_t cbAndLine = RT_ALIGN(cx, 8) / 8;
1153 if (!fAlpha)
1154 {
1155 Log2(("VMSVGA Cursor AND mask (%d,%d):\n", cx, cy));
1156 for (uint32_t y = 0; y < cy; y++)
1157 {
1158 Log2(("%3u:", y));
1159 uint8_t const *pbLine = &pbData[y * cbAndLine];
1160 for (uint32_t x = 0; x < cx; x += 8)
1161 {
1162 uint8_t b = pbLine[x / 8];
1163 char szByte[12];
1164 szByte[0] = b & 0x80 ? '*' : ' '; /* most significant bit first */
1165 szByte[1] = b & 0x40 ? '*' : ' ';
1166 szByte[2] = b & 0x20 ? '*' : ' ';
1167 szByte[3] = b & 0x10 ? '*' : ' ';
1168 szByte[4] = b & 0x08 ? '*' : ' ';
1169 szByte[5] = b & 0x04 ? '*' : ' ';
1170 szByte[6] = b & 0x02 ? '*' : ' ';
1171 szByte[7] = b & 0x01 ? '*' : ' ';
1172 szByte[8] = '\0';
1173 Log2(("%s", szByte));
1174 }
1175 Log2(("\n"));
1176 }
1177 }
1178
1179 Log2(("VMSVGA Cursor XOR mask (%d,%d):\n", cx, cy));
1180 uint32_t const *pu32Xor = (uint32_t const *)&pbData[RT_ALIGN_32(cbAndLine * cy, 4)];
1181 for (uint32_t y = 0; y < cy; y++)
1182 {
1183 Log2(("%3u:", y));
1184 uint32_t const *pu32Line = &pu32Xor[y * cx];
1185 for (uint32_t x = 0; x < cx; x++)
1186 Log2((" %08x", pu32Line[x]));
1187 Log2(("\n"));
1188 }
1189 }
1190#endif
1191
1192 int rc = pThisCC->pDrv->pfnVBVAMousePointerShape(pThisCC->pDrv, true /*fVisible*/, fAlpha, xHot, yHot, cx, cy, pbData);
1193 AssertRC(rc);
1194
1195 if (pSVGAState->Cursor.fActive)
1196 RTMemFreeZ(pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
1197
1198 pSVGAState->Cursor.fActive = true;
1199 pSVGAState->Cursor.xHotspot = xHot;
1200 pSVGAState->Cursor.yHotspot = yHot;
1201 pSVGAState->Cursor.width = cx;
1202 pSVGAState->Cursor.height = cy;
1203 pSVGAState->Cursor.cbData = cbData;
1204 pSVGAState->Cursor.pData = pbData;
1205}
1206
1207
1208#ifdef VBOX_WITH_VMSVGA3D
1209
1210/*
1211 * SVGA_3D_CMD_* handlers.
1212 */
1213
1214
1215/** SVGA_3D_CMD_SURFACE_DEFINE 1040, SVGA_3D_CMD_SURFACE_DEFINE_V2 1070
1216 *
1217 * @param pThisCC The VGA/VMSVGA state for the current context.
1218 * @param pCmd The VMSVGA command.
1219 * @param cMipLevelSizes Number of elements in the paMipLevelSizes array.
1220 * @param paMipLevelSizes Arrays of surface sizes for each face and miplevel.
1221 */
1222static void vmsvga3dCmdDefineSurface(PVGASTATECC pThisCC, SVGA3dCmdDefineSurface_v2 const *pCmd,
1223 uint32_t cMipLevelSizes, SVGA3dSize *paMipLevelSizes)
1224{
1225 ASSERT_GUEST_RETURN_VOID(pCmd->sid < SVGA3D_MAX_SURFACE_IDS);
1226 ASSERT_GUEST_RETURN_VOID(cMipLevelSizes >= 1);
1227 RT_UNTRUSTED_VALIDATED_FENCE();
1228
1229 /* Number of faces (cFaces) is specified as the number of the first non-zero elements in the 'face' array.
1230 * Since only plain surfaces (cFaces == 1) and cubemaps (cFaces == 6) are supported
1231 * (see also SVGA3dCmdDefineSurface definition in svga3d_reg.h), we ignore anything else.
1232 */
1233 uint32_t cRemainingMipLevels = cMipLevelSizes;
1234 uint32_t cFaces = 0;
1235 for (uint32_t i = 0; i < SVGA3D_MAX_SURFACE_FACES; ++i)
1236 {
1237 if (pCmd->face[i].numMipLevels == 0)
1238 break;
1239
1240 /* All SVGA3dSurfaceFace structures must have the same value of numMipLevels field */
1241 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels == pCmd->face[0].numMipLevels);
1242
1243 /* numMipLevels value can't be greater than the number of remaining elements in the paMipLevelSizes array. */
1244 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels <= cRemainingMipLevels);
1245 cRemainingMipLevels -= pCmd->face[i].numMipLevels;
1246
1247 ++cFaces;
1248 }
1249 for (uint32_t i = cFaces; i < SVGA3D_MAX_SURFACE_FACES; ++i)
1250 ASSERT_GUEST_RETURN_VOID(pCmd->face[i].numMipLevels == 0);
1251
1252 /* cFaces must be 6 for a cubemap and 1 otherwise. */
1253 ASSERT_GUEST_RETURN_VOID(cFaces == (uint32_t)((pCmd->surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1));
1254
1255 /* Sum of face[i].numMipLevels must be equal to cMipLevels. */
1256 ASSERT_GUEST_RETURN_VOID(cRemainingMipLevels == 0);
1257 RT_UNTRUSTED_VALIDATED_FENCE();
1258
1259 /* Verify paMipLevelSizes */
1260 uint32_t cWidth = paMipLevelSizes[0].width;
1261 uint32_t cHeight = paMipLevelSizes[0].height;
1262 uint32_t cDepth = paMipLevelSizes[0].depth;
1263 for (uint32_t i = 1; i < pCmd->face[0].numMipLevels; ++i)
1264 {
1265 cWidth >>= 1;
1266 if (cWidth == 0) cWidth = 1;
1267 cHeight >>= 1;
1268 if (cHeight == 0) cHeight = 1;
1269 cDepth >>= 1;
1270 if (cDepth == 0) cDepth = 1;
1271 for (uint32_t iFace = 0; iFace < cFaces; ++iFace)
1272 {
1273 uint32_t const iMipLevelSize = iFace * pCmd->face[0].numMipLevels + i;
1274 ASSERT_GUEST_RETURN_VOID( cWidth == paMipLevelSizes[iMipLevelSize].width
1275 && cHeight == paMipLevelSizes[iMipLevelSize].height
1276 && cDepth == paMipLevelSizes[iMipLevelSize].depth);
1277 }
1278 }
1279 RT_UNTRUSTED_VALIDATED_FENCE();
1280
1281 /* Create the surface. */
1282 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
1283 pCmd->multisampleCount, pCmd->autogenFilter,
1284 pCmd->face[0].numMipLevels, &paMipLevelSizes[0], /* fAllocMipLevels = */ true);
1285}
1286
1287
1288/* SVGA_3D_CMD_DEFINE_GB_MOB 1093 */
1289static void vmsvga3dCmdDefineGBMob(PVGASTATECC pThisCC, SVGA3dCmdDefineGBMob const *pCmd)
1290{
1291 DEBUG_BREAKPOINT_TEST();
1292 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1293
1294 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1295
1296 /* Maybe just update the OTable and create Gbo when the MOB is actually accessed? */
1297 /* Allocate a structure for the MOB. */
1298 PVMSVGAMOB pMob = (PVMSVGAMOB)RTMemAllocZ(sizeof(*pMob));
1299 AssertPtrReturnVoid(pMob);
1300
1301 int rc = vmsvgaR3MobCreate(pSvgaR3State, pCmd->ptDepth, pCmd->base, pCmd->sizeInBytes, pCmd->mobid, /*fGCPhys64=*/ false, pMob);
1302 if (RT_SUCCESS(rc))
1303 {
1304 return;
1305 }
1306
1307 AssertFailed();
1308
1309 RTMemFree(pMob);
1310}
1311
1312
1313/* SVGA_3D_CMD_DESTROY_GB_MOB 1094 */
1314static void vmsvga3dCmdDestroyGBMob(PVGASTATECC pThisCC, SVGA3dCmdDestroyGBMob const *pCmd)
1315{
1316 //DEBUG_BREAKPOINT_TEST();
1317 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1318
1319 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1320
1321 int rc = vmsvgaR3MobDestroy(pSvgaR3State, pCmd->mobid);
1322 if (RT_SUCCESS(rc))
1323 {
1324 return;
1325 }
1326
1327 AssertFailed();
1328}
1329
1330
1331/* SVGA_3D_CMD_DEFINE_GB_SURFACE 1097 */
1332static void vmsvga3dCmdDefineGBSurface(PVGASTATECC pThisCC, SVGA3dCmdDefineGBSurface const *pCmd)
1333{
1334 //DEBUG_BREAKPOINT_TEST();
1335 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1336
1337 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
1338 SVGAOTableSurfaceEntry entry;
1339 RT_ZERO(entry);
1340 entry.format = pCmd->format;
1341 entry.surface1Flags = pCmd->surfaceFlags;
1342 entry.numMipLevels = pCmd->numMipLevels;
1343 entry.multisampleCount = pCmd->multisampleCount;
1344 entry.autogenFilter = pCmd->autogenFilter;
1345 entry.size = pCmd->size;
1346 entry.mobid = SVGA_ID_INVALID;
1347 // entry.arraySize = 0;
1348 // entry.mobPitch = 0;
1349 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1350 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1351 if (RT_SUCCESS(rc))
1352 {
1353 /* Create the host surface. */
1354 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
1355 pCmd->multisampleCount, pCmd->autogenFilter,
1356 pCmd->numMipLevels, &pCmd->size, /* fAllocMipLevels = */ false);
1357 }
1358}
1359
1360
1361/* SVGA_3D_CMD_DESTROY_GB_SURFACE 1098 */
1362static void vmsvga3dCmdDestroyGBSurface(PVGASTATECC pThisCC, SVGA3dCmdDestroyGBSurface const *pCmd)
1363{
1364 //DEBUG_BREAKPOINT_TEST();
1365 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1366
1367 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
1368 SVGAOTableSurfaceEntry entry;
1369 RT_ZERO(entry);
1370 entry.mobid = SVGA_ID_INVALID;
1371 vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1372 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1373
1374 vmsvga3dSurfaceDestroy(pThisCC, pCmd->sid);
1375}
1376
1377
1378/* SVGA_3D_CMD_BIND_GB_SURFACE 1099 */
1379static void vmsvga3dCmdBindGBSurface(PVGASTATECC pThisCC, SVGA3dCmdBindGBSurface const *pCmd)
1380{
1381 //DEBUG_BREAKPOINT_TEST();
1382 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1383
1384 /* Assign the mobid to the surface. */
1385 int rc = VINF_SUCCESS;
1386 if (pCmd->mobid != SVGA_ID_INVALID)
1387 rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
1388 pCmd->mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE);
1389 if (RT_SUCCESS(rc))
1390 {
1391 SVGAOTableSurfaceEntry entry;
1392 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1393 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1394 if (RT_SUCCESS(rc))
1395 {
1396 entry.mobid = pCmd->mobid;
1397 rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1398 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1399 if (RT_SUCCESS(rc))
1400 {
1401 /* */
1402 }
1403 }
1404 }
1405}
1406
1407
1408static int vmsvga3dBmpWrite(const char *pszFilename, VMSVGA3D_MAPPED_SURFACE const *pMap)
1409{
1410 if (pMap->cbPixel != 4)
1411 return VERR_NOT_SUPPORTED;
1412
1413 int const w = pMap->box.w;
1414 int const h = pMap->box.h;
1415
1416 const int cbBitmap = w * h * 4;
1417
1418 FILE *f = fopen(pszFilename, "wb");
1419 if (!f)
1420 return VERR_FILE_NOT_FOUND;
1421
1422 {
1423 BMPFILEHDR fileHdr;
1424 RT_ZERO(fileHdr);
1425 fileHdr.uType = BMP_HDR_MAGIC;
1426 fileHdr.cbFileSize = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR) + cbBitmap;
1427 fileHdr.offBits = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR);
1428
1429 BMPWIN3XINFOHDR coreHdr;
1430 RT_ZERO(coreHdr);
1431 coreHdr.cbSize = sizeof(coreHdr);
1432 coreHdr.uWidth = w;
1433 coreHdr.uHeight = -h;
1434 coreHdr.cPlanes = 1;
1435 coreHdr.cBits = 32;
1436 coreHdr.cbSizeImage = cbBitmap;
1437
1438 fwrite(&fileHdr, 1, sizeof(fileHdr), f);
1439 fwrite(&coreHdr, 1, sizeof(coreHdr), f);
1440 }
1441
1442 if (pMap->cbPixel == 4)
1443 {
1444 const uint8_t *s = (uint8_t *)pMap->pvData;
1445 for (int32_t y = 0; y < h; ++y)
1446 {
1447 fwrite(s, 1, w * pMap->cbPixel, f);
1448
1449 s += pMap->cbRowPitch;
1450 }
1451 }
1452
1453 fclose(f);
1454
1455 return VINF_SUCCESS;
1456}
1457
1458
1459void vmsvga3dMapWriteBmpFile(VMSVGA3D_MAPPED_SURFACE const *pMap, char const *pszPrefix)
1460{
1461 static int idxBitmap = 0;
1462 char *pszFilename = RTStrAPrintf2("bmp\\%s%d.bmp", pszPrefix, idxBitmap++);
1463 int rc = vmsvga3dBmpWrite(pszFilename, pMap);
1464 Log(("WriteBmpFile %s %Rrc\n", pszFilename, rc)); RT_NOREF(rc);
1465 RTStrFree(pszFilename);
1466}
1467
1468
1469static int vmsvgaR3TransferSurfaceLevel(PVGASTATECC pThisCC,
1470 PVMSVGAMOB pMob,
1471 SVGA3dSurfaceImageId const *pImage,
1472 SVGA3dBox const *pBox,
1473 SVGA3dTransferType enmTransfer)
1474{
1475 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1476
1477 VMSVGA3D_SURFACE_MAP enmMapType;
1478 if (enmTransfer == SVGA3D_WRITE_HOST_VRAM)
1479 enmMapType = pBox
1480 ? VMSVGA3D_SURFACE_MAP_WRITE
1481 : VMSVGA3D_SURFACE_MAP_WRITE_DISCARD;
1482 else if (enmTransfer == SVGA3D_READ_HOST_VRAM)
1483 enmMapType = VMSVGA3D_SURFACE_MAP_READ;
1484 else
1485 AssertFailedReturn(VERR_INVALID_PARAMETER);
1486
1487 VMSGA3D_BOX_DIMENSIONS dims;
1488 int rc = vmsvga3dGetBoxDimensions(pThisCC, pImage, pBox, &dims);
1489 AssertRCReturn(rc, rc);
1490
1491 VMSVGA3D_MAPPED_SURFACE map;
1492 rc = vmsvga3dSurfaceMap(pThisCC, pImage, pBox, enmMapType, &map);
1493 if (RT_SUCCESS(rc))
1494 {
1495 /* Copy mapped surface <-> MOB. */
1496 uint8_t *pu8Map = (uint8_t *)map.pvData;
1497 uint32_t offMob = dims.offSubresource + dims.offBox;
1498 for (uint32_t z = 0; z < dims.cDepth; ++z)
1499 {
1500 for (uint32_t y = 0; y < dims.cyBlocks; ++y)
1501 {
1502 if (enmTransfer == SVGA3D_READ_HOST_VRAM)
1503 rc = vmsvgaR3GboWrite(pSvgaR3State, &pMob->Gbo, offMob, pu8Map, dims.cbRow);
1504 else
1505 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, offMob, pu8Map, dims.cbRow);
1506 if (RT_FAILURE(rc))
1507 break;
1508
1509 pu8Map += map.cbRowPitch;
1510 offMob += dims.cbPitch;
1511 }
1512 }
1513
1514 // vmsvga3dMapWriteBmpFile(&map, "Dynamic");
1515
1516 bool const fWritten = (enmTransfer == SVGA3D_WRITE_HOST_VRAM);
1517 vmsvga3dSurfaceUnmap(pThisCC, pImage, &map, fWritten);
1518 }
1519
1520 return rc;
1521}
1522
1523
1524/* SVGA_3D_CMD_UPDATE_GB_IMAGE 1101 */
1525static void vmsvga3dCmdUpdateGBImage(PVGASTATECC pThisCC, SVGA3dCmdUpdateGBImage const *pCmd)
1526{
1527 //DEBUG_BREAKPOINT_TEST();
1528 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1529
1530 LogFlowFunc(("sid=%u @%u,%u,%u %ux%ux%u\n",
1531 pCmd->image.sid, pCmd->box.x, pCmd->box.y, pCmd->box.z, pCmd->box.w, pCmd->box.h, pCmd->box.d));
1532
1533/*
1534 SVGA3dSurfaceFormat format;
1535 SVGA3dSurface1Flags surface1Flags;
1536 uint32 numMipLevels;
1537 uint32 multisampleCount;
1538 SVGA3dTextureFilter autogenFilter;
1539 SVGA3dSize size;
1540 SVGAMobId mobid;
1541 uint32 arraySize;
1542 uint32 mobPitch;
1543 SVGA3dSurface2Flags surface2Flags;
1544 uint8 multisamplePattern;
1545 uint8 qualityLevel;
1546 uint16 bufferByteStride;
1547 float minLOD;
1548*/
1549
1550 /* "update a surface from its backing MOB." */
1551 SVGAOTableSurfaceEntry entrySurface;
1552 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1553 pCmd->image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1554 if (RT_SUCCESS(rc))
1555 {
1556 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1557 if (pMob)
1558 {
1559 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &pCmd->image, &pCmd->box, SVGA3D_WRITE_HOST_VRAM);
1560 AssertRC(rc);
1561 }
1562 }
1563}
1564
1565
1566/* SVGA_3D_CMD_UPDATE_GB_SURFACE 1102 */
1567static void vmsvga3dCmdUpdateGBSurface(PVGASTATECC pThisCC, SVGA3dCmdUpdateGBSurface const *pCmd)
1568{
1569 //DEBUG_BREAKPOINT_TEST();
1570 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1571
1572 LogFlowFunc(("sid=%u\n",
1573 pCmd->sid));
1574
1575 /* "update a surface from its backing MOB." */
1576 SVGAOTableSurfaceEntry entrySurface;
1577 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1578 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1579 if (RT_SUCCESS(rc))
1580 {
1581 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1582 if (pMob)
1583 {
1584 uint32 const arraySize = (entrySurface.surface1Flags & SVGA3D_SURFACE_CUBEMAP)
1585 ? SVGA3D_MAX_SURFACE_FACES
1586 : RT_MAX(entrySurface.arraySize, 1);
1587 for (uint32_t iArray = 0; iArray < arraySize; ++iArray)
1588 {
1589 for (uint32_t iMipmap = 0; iMipmap < entrySurface.numMipLevels; ++iMipmap)
1590 {
1591 SVGA3dSurfaceImageId image;
1592 image.sid = pCmd->sid;
1593 image.face = iArray;
1594 image.mipmap = iMipmap;
1595
1596 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, /* all pBox = */ NULL, SVGA3D_WRITE_HOST_VRAM);
1597 AssertRCBreak(rc);
1598 }
1599 }
1600 }
1601 }
1602}
1603
1604
1605/* SVGA_3D_CMD_READBACK_GB_IMAGE 1103 */
1606static void vmsvga3dCmdReadbackGBImage(PVGASTATECC pThisCC, SVGA3dCmdReadbackGBImage const *pCmd)
1607{
1608 //DEBUG_BREAKPOINT_TEST();
1609 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1610
1611 LogFlowFunc(("sid=%u, face=%u, mipmap=%u\n",
1612 pCmd->image.sid, pCmd->image.face, pCmd->image.mipmap));
1613
1614 /* Read a surface to its backing MOB. */
1615 SVGAOTableSurfaceEntry entrySurface;
1616 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1617 pCmd->image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1618 if (RT_SUCCESS(rc))
1619 {
1620 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1621 if (pMob)
1622 {
1623 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &pCmd->image, /* all pBox = */ NULL, SVGA3D_READ_HOST_VRAM);
1624 AssertRC(rc);
1625 }
1626 }
1627}
1628
1629
1630/* SVGA_3D_CMD_READBACK_GB_SURFACE 1104 */
1631static void vmsvga3dCmdReadbackGBSurface(PVGASTATECC pThisCC, SVGA3dCmdReadbackGBSurface const *pCmd)
1632{
1633 //DEBUG_BREAKPOINT_TEST();
1634 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1635
1636 LogFlowFunc(("sid=%u\n",
1637 pCmd->sid));
1638
1639 /* Read a surface to its backing MOB. */
1640 SVGAOTableSurfaceEntry entrySurface;
1641 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1642 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1643 if (RT_SUCCESS(rc))
1644 {
1645 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
1646 if (pMob)
1647 {
1648 uint32 const arraySize = (entrySurface.surface1Flags & SVGA3D_SURFACE_CUBEMAP)
1649 ? SVGA3D_MAX_SURFACE_FACES
1650 : RT_MAX(entrySurface.arraySize, 1);
1651 for (uint32_t iArray = 0; iArray < arraySize; ++iArray)
1652 {
1653 for (uint32_t iMipmap = 0; iMipmap < entrySurface.numMipLevels; ++iMipmap)
1654 {
1655 SVGA3dSurfaceImageId image;
1656 image.sid = pCmd->sid;
1657 image.face = iArray;
1658 image.mipmap = iMipmap;
1659
1660 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, /* all pBox = */ NULL, SVGA3D_READ_HOST_VRAM);
1661 AssertRCBreak(rc);
1662 }
1663 }
1664 }
1665 }
1666}
1667
1668
1669/* SVGA_3D_CMD_INVALIDATE_GB_IMAGE 1105 */
1670static void vmsvga3dCmdInvalidateGBImage(PVGASTATECC pThisCC, SVGA3dCmdInvalidateGBImage const *pCmd)
1671{
1672 //DEBUG_BREAKPOINT_TEST();
1673 vmsvga3dSurfaceInvalidate(pThisCC, pCmd->image.sid, pCmd->image.face, pCmd->image.mipmap);
1674}
1675
1676
1677/* SVGA_3D_CMD_INVALIDATE_GB_SURFACE 1106 */
1678static void vmsvga3dCmdInvalidateGBSurface(PVGASTATECC pThisCC, SVGA3dCmdInvalidateGBSurface const *pCmd)
1679{
1680 //DEBUG_BREAKPOINT_TEST();
1681 vmsvga3dSurfaceInvalidate(pThisCC, pCmd->sid, SVGA_ID_INVALID, SVGA_ID_INVALID);
1682}
1683
1684
1685/* SVGA_3D_CMD_SET_OTABLE_BASE64 1115 */
1686static void vmsvga3dCmdSetOTableBase64(PVGASTATECC pThisCC, SVGA3dCmdSetOTableBase64 const *pCmd)
1687{
1688 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1689
1690 /*
1691 * Create a GBO for the table.
1692 */
1693 PVMSVGAGBO pGbo;
1694 if (pCmd->type <= RT_ELEMENTS(pSvgaR3State->aGboOTables))
1695 {
1696 RT_UNTRUSTED_VALIDATED_FENCE();
1697 pGbo = &pSvgaR3State->aGboOTables[pCmd->type];
1698 }
1699 else
1700 {
1701 ASSERT_GUEST_FAILED();
1702 pGbo = NULL;
1703 }
1704
1705 if (pGbo)
1706 {
1707 /* Recreate. */
1708 vmsvgaR3GboDestroy(pSvgaR3State, pGbo);
1709 int rc = vmsvgaR3GboCreate(pSvgaR3State, pCmd->ptDepth, pCmd->baseAddress, pCmd->sizeInBytes, /*fGCPhys64=*/ true, /* fWriteProtected = */ true, pGbo);
1710 AssertRC(rc);
1711 }
1712}
1713
1714
1715/* SVGA_3D_CMD_DEFINE_GB_SCREENTARGET 1124 */
1716static void vmsvga3dCmdDefineGBScreenTarget(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dCmdDefineGBScreenTarget const *pCmd)
1717{
1718 //DEBUG_BREAKPOINT_TEST();
1719 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1720
1721 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1722 ASSERT_GUEST_RETURN_VOID(pCmd->width > 0 && pCmd->width <= pThis->svga.u32MaxWidth); /* SVGA_REG_SCREENTARGET_MAX_WIDTH */
1723 ASSERT_GUEST_RETURN_VOID(pCmd->height > 0 && pCmd->height <= pThis->svga.u32MaxHeight); /* SVGA_REG_SCREENTARGET_MAX_HEIGHT */
1724 RT_UNTRUSTED_VALIDATED_FENCE();
1725
1726 /* Update the entry in the pSvgaR3State->pGboOTableScreenTarget. */
1727 SVGAOTableScreenTargetEntry entry;
1728 RT_ZERO(entry);
1729 entry.image.sid = SVGA_ID_INVALID;
1730 // entry.image.face = 0;
1731 // entry.image.mipmap = 0;
1732 entry.width = pCmd->width;
1733 entry.height = pCmd->height;
1734 entry.xRoot = pCmd->xRoot;
1735 entry.yRoot = pCmd->yRoot;
1736 entry.flags = pCmd->flags;
1737 entry.dpi = pCmd->dpi;
1738
1739 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1740 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1741 if (RT_SUCCESS(rc))
1742 {
1743 /* Screen objects and screen targets are similar, therefore we will use the same for both. */
1744 /** @todo Generic screen object/target interface. */
1745 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1746 pScreen->fDefined = true;
1747 pScreen->fModified = true;
1748 pScreen->fuScreen = SVGA_SCREEN_MUST_BE_SET
1749 | (RT_BOOL(pCmd->flags & SVGA_STFLAG_PRIMARY) ? SVGA_SCREEN_IS_PRIMARY : 0);
1750 pScreen->idScreen = pCmd->stid;
1751
1752 pScreen->xOrigin = pCmd->xRoot;
1753 pScreen->yOrigin = pCmd->yRoot;
1754 pScreen->cWidth = pCmd->width;
1755 pScreen->cHeight = pCmd->height;
1756 pScreen->offVRAM = 0; /* Not applicable for screen targets, they use either a separate memory buffer or a host window. */
1757 pScreen->cbPitch = pCmd->width * 4;
1758 pScreen->cBpp = 32;
1759
1760 if (RT_LIKELY(pThis->svga.f3DEnabled))
1761 vmsvga3dDefineScreen(pThis, pThisCC, pScreen);
1762
1763 if (!pScreen->pHwScreen)
1764 {
1765 /* System memory buffer. */
1766 pScreen->pvScreenBitmap = RTMemAllocZ(pScreen->cHeight * pScreen->cbPitch);
1767 }
1768
1769 pThis->svga.fGFBRegisters = false;
1770 vmsvgaR3ChangeMode(pThis, pThisCC);
1771 }
1772}
1773
1774
1775/* SVGA_3D_CMD_DESTROY_GB_SCREENTARGET 1125 */
1776static void vmsvga3dCmdDestroyGBScreenTarget(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dCmdDestroyGBScreenTarget const *pCmd)
1777{
1778 //DEBUG_BREAKPOINT_TEST();
1779 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1780
1781 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1782 RT_UNTRUSTED_VALIDATED_FENCE();
1783
1784 /* Update the entry in the pSvgaR3State->pGboOTableScreenTarget. */
1785 SVGAOTableScreenTargetEntry entry;
1786 RT_ZERO(entry);
1787 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1788 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1789 if (RT_SUCCESS(rc))
1790 {
1791 /* Screen objects and screen targets are similar, therefore we will use the same for both. */
1792 /** @todo Generic screen object/target interface. */
1793 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1794 pScreen->fModified = true;
1795 pScreen->fDefined = false;
1796 pScreen->idScreen = pCmd->stid;
1797
1798 if (RT_LIKELY(pThis->svga.f3DEnabled))
1799 vmsvga3dDestroyScreen(pThisCC, pScreen);
1800
1801 vmsvgaR3ChangeMode(pThis, pThisCC);
1802
1803 RTMemFree(pScreen->pvScreenBitmap);
1804 pScreen->pvScreenBitmap = NULL;
1805 }
1806}
1807
1808
1809/* SVGA_3D_CMD_BIND_GB_SCREENTARGET 1126 */
1810static void vmsvga3dCmdBindGBScreenTarget(PVGASTATECC pThisCC, SVGA3dCmdBindGBScreenTarget const *pCmd)
1811{
1812 //DEBUG_BREAKPOINT_TEST();
1813 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1814
1815 /* "Binding a surface to a Screen Target the same as flipping" */
1816
1817 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1818 ASSERT_GUEST_RETURN_VOID(pCmd->image.face == 0 && pCmd->image.mipmap == 0);
1819 RT_UNTRUSTED_VALIDATED_FENCE();
1820
1821 /* Assign the surface to the screen target. */
1822 int rc = VINF_SUCCESS;
1823 if (pCmd->image.sid != SVGA_ID_INVALID)
1824 rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1825 pCmd->image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE);
1826 if (RT_SUCCESS(rc))
1827 {
1828 SVGAOTableScreenTargetEntry entry;
1829 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1830 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1831 if (RT_SUCCESS(rc))
1832 {
1833 entry.image = pCmd->image;
1834 rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1835 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entry, sizeof(entry));
1836 if (RT_SUCCESS(rc))
1837 {
1838 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1839 rc = pSvgaR3State->pFuncsGBO->pfnScreenTargetBind(pThisCC, pScreen, pCmd->image.sid);
1840 AssertRC(rc);
1841 }
1842 }
1843 }
1844}
1845
1846
1847/* SVGA_3D_CMD_UPDATE_GB_SCREENTARGET 1127 */
1848static void vmsvga3dCmdUpdateGBScreenTarget(PVGASTATECC pThisCC, SVGA3dCmdUpdateGBScreenTarget const *pCmd)
1849{
1850 //DEBUG_BREAKPOINT_TEST();
1851 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1852
1853 /* Update the screen target from its backing surface. */
1854 ASSERT_GUEST_RETURN_VOID(pCmd->stid < RT_ELEMENTS(pSvgaR3State->aScreens));
1855 RT_UNTRUSTED_VALIDATED_FENCE();
1856
1857 /* Get the screen target info. */
1858 SVGAOTableScreenTargetEntry entryScreenTarget;
1859 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SCREENTARGET],
1860 pCmd->stid, SVGA3D_OTABLE_SCREEN_TARGET_ENTRY_SIZE, &entryScreenTarget, sizeof(entryScreenTarget));
1861 if (RT_SUCCESS(rc))
1862 {
1863 ASSERT_GUEST_RETURN_VOID(entryScreenTarget.image.face == 0 && entryScreenTarget.image.mipmap == 0);
1864 RT_UNTRUSTED_VALIDATED_FENCE();
1865
1866 if (entryScreenTarget.image.sid != SVGA_ID_INVALID)
1867 {
1868 SVGAOTableSurfaceEntry entrySurface;
1869 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1870 entryScreenTarget.image.sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
1871 if (RT_SUCCESS(rc))
1872 {
1873 /* Copy entrySurface.mobid content to the screen target. */
1874 if (entrySurface.mobid != SVGA_ID_INVALID)
1875 {
1876 RT_UNTRUSTED_VALIDATED_FENCE();
1877 SVGA3dRect targetRect = pCmd->rect;
1878
1879 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[pCmd->stid];
1880 if (pScreen->pHwScreen)
1881 {
1882 /* Copy the screen target surface to the backend's screen. */
1883 pSvgaR3State->pFuncsGBO->pfnScreenTargetUpdate(pThisCC, pScreen, &targetRect);
1884 }
1885 else if (pScreen->pvScreenBitmap)
1886 {
1887 /* Copy the screen target surface to the memory buffer. */
1888 VMSVGA3D_MAPPED_SURFACE map;
1889 rc = vmsvga3dSurfaceMap(pThisCC, &entryScreenTarget.image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);
1890 if (RT_SUCCESS(rc))
1891 {
1892 uint8_t const *pu8Src = (uint8_t *)map.pvData
1893 + targetRect.x * map.cbPixel
1894 + targetRect.y * map.cbRowPitch;
1895 uint8_t *pu8Dst = (uint8_t *)pScreen->pvScreenBitmap
1896 + targetRect.x * map.cbPixel
1897 + targetRect.y * map.box.w * map.cbPixel;
1898 for (uint32_t y = 0; y < targetRect.h; ++y)
1899 {
1900 memcpy(pu8Dst, pu8Src, targetRect.w * map.cbPixel);
1901
1902 pu8Src += map.cbRowPitch;
1903 pu8Dst += map.box.w * map.cbPixel;
1904 }
1905
1906 vmsvga3dSurfaceUnmap(pThisCC, &entryScreenTarget.image, &map, /* fWritten = */ false);
1907
1908 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->rect.x, pCmd->rect.y, pCmd->rect.w, pCmd->rect.h);
1909 }
1910 else
1911 AssertFailed();
1912 }
1913 }
1914 }
1915 }
1916 }
1917}
1918
1919
1920/* SVGA_3D_CMD_DEFINE_GB_SURFACE_V2 1134 */
1921static void vmsvga3dCmdDefineGBSurface_v2(PVGASTATECC pThisCC, SVGA3dCmdDefineGBSurface_v2 const *pCmd)
1922{
1923 //DEBUG_BREAKPOINT_TEST();
1924 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1925
1926 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
1927 SVGAOTableSurfaceEntry entry;
1928 RT_ZERO(entry);
1929 entry.format = pCmd->format;
1930 entry.surface1Flags = pCmd->surfaceFlags;
1931 entry.numMipLevels = pCmd->numMipLevels;
1932 entry.multisampleCount = pCmd->multisampleCount;
1933 entry.autogenFilter = pCmd->autogenFilter;
1934 entry.size = pCmd->size;
1935 entry.mobid = SVGA_ID_INVALID;
1936 entry.arraySize = pCmd->arraySize;
1937 // entry.mobPitch = 0;
1938 // ...
1939Assert( pCmd->arraySize == 0
1940 || pCmd->arraySize == 1
1941 || (pCmd->arraySize == 6 && (pCmd->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)));
1942 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
1943 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
1944 if (RT_SUCCESS(rc))
1945 {
1946 /* Create the host surface. */
1947 /** @todo SVGAOTableSurfaceEntry as input parameter? */
1948 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
1949 pCmd->multisampleCount, pCmd->autogenFilter,
1950 pCmd->numMipLevels, &pCmd->size, /* fAllocMipLevels = */ false);
1951 }
1952}
1953
1954
1955/* SVGA_3D_CMD_DEFINE_GB_MOB64 1135 */
1956static void vmsvga3dCmdDefineGBMob64(PVGASTATECC pThisCC, SVGA3dCmdDefineGBMob64 const *pCmd)
1957{
1958 //DEBUG_BREAKPOINT_TEST();
1959 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1960
1961 ASSERT_GUEST_RETURN_VOID(pCmd->mobid != SVGA_ID_INVALID); /* The guest should not use this id. */
1962
1963 /* Maybe just update the OTable and create Gbo when the MOB is actually accessed? */
1964 /* Allocate a structure for the MOB. */
1965 PVMSVGAMOB pMob = (PVMSVGAMOB)RTMemAllocZ(sizeof(*pMob));
1966 AssertPtrReturnVoid(pMob);
1967
1968 int rc = vmsvgaR3MobCreate(pSvgaR3State, pCmd->ptDepth, pCmd->base, pCmd->sizeInBytes, pCmd->mobid, /*fGCPhys64=*/ true, pMob);
1969 if (RT_SUCCESS(rc))
1970 {
1971 return;
1972 }
1973
1974 RTMemFree(pMob);
1975}
1976
1977
1978/* SVGA_3D_CMD_DX_DEFINE_CONTEXT 1143 */
1979static int vmsvga3dCmdDXDefineContext(PVGASTATECC pThisCC, SVGA3dCmdDXDefineContext const *pCmd, uint32_t cbCmd)
1980{
1981#ifdef VMSVGA3D_DX
1982 //DEBUG_BREAKPOINT_TEST();
1983 RT_NOREF(cbCmd);
1984
1985 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
1986
1987 /* Update the entry in the pSvgaR3State->pGboOTable[SVGA_OTABLE_DXCONTEXT]. */
1988 SVGAOTableDXContextEntry entry;
1989 RT_ZERO(entry);
1990 entry.cid = pCmd->cid;
1991 entry.mobid = SVGA_ID_INVALID;
1992 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_DXCONTEXT],
1993 pCmd->cid, sizeof(SVGAOTableDXContextEntry), &entry, sizeof(entry));
1994 if (RT_SUCCESS(rc))
1995 {
1996 /* Create the host context. */
1997 rc = vmsvga3dDXDefineContext(pThisCC, pCmd->cid);
1998 }
1999
2000 return rc;
2001#else
2002 RT_NOREF(pThisCC, pCmd, cbCmd);
2003 return VERR_NOT_SUPPORTED;
2004#endif
2005}
2006
2007
2008/* SVGA_3D_CMD_DX_DESTROY_CONTEXT 1144 */
2009static int vmsvga3dCmdDXDestroyContext(PVGASTATECC pThisCC, SVGA3dCmdDXDestroyContext const *pCmd, uint32_t cbCmd)
2010{
2011#ifdef VMSVGA3D_DX
2012 //DEBUG_BREAKPOINT_TEST();
2013 RT_NOREF(cbCmd);
2014
2015 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2016
2017 /* Update the entry in the pSvgaR3State->pGboOTable[SVGA_OTABLE_DXCONTEXT]. */
2018 SVGAOTableDXContextEntry entry;
2019 RT_ZERO(entry);
2020 vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_DXCONTEXT],
2021 pCmd->cid, sizeof(SVGAOTableDXContextEntry), &entry, sizeof(entry));
2022
2023 return vmsvga3dDXDestroyContext(pThisCC, pCmd->cid);
2024#else
2025 RT_NOREF(pThisCC, pCmd, cbCmd);
2026 return VERR_NOT_SUPPORTED;
2027#endif
2028}
2029
2030
2031/* SVGA_3D_CMD_DX_BIND_CONTEXT 1145 */
2032static int vmsvga3dCmdDXBindContext(PVGASTATECC pThisCC, SVGA3dCmdDXBindContext const *pCmd, uint32_t cbCmd)
2033{
2034#ifdef VMSVGA3D_DX
2035 //DEBUG_BREAKPOINT_TEST();
2036 RT_NOREF(cbCmd);
2037
2038 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2039
2040 /* Assign a mobid to a cid. */
2041 int rc = VINF_SUCCESS;
2042 if (pCmd->mobid != SVGA_ID_INVALID)
2043 rc = vmsvgaR3OTableVerifyIndex(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_MOB],
2044 pCmd->mobid, SVGA3D_OTABLE_MOB_ENTRY_SIZE);
2045 if (RT_SUCCESS(rc))
2046 {
2047 SVGAOTableDXContextEntry entry;
2048 rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_DXCONTEXT],
2049 pCmd->cid, sizeof(SVGAOTableDXContextEntry), &entry, sizeof(entry));
2050 if (RT_SUCCESS(rc))
2051 {
2052 SVGADXContextMobFormat *pSvgaDXContext = NULL;
2053 if (pCmd->mobid != entry.mobid && entry.mobid != SVGA_ID_INVALID)
2054 {
2055 /* Unbind notification to the DX backend. Copy the context data to the guest backing memory. */
2056 pSvgaDXContext = (SVGADXContextMobFormat *)RTMemAlloc(sizeof(SVGADXContextMobFormat));
2057 if (pSvgaDXContext)
2058 {
2059 rc = vmsvga3dDXUnbindContext(pThisCC, pCmd->cid, pSvgaDXContext);
2060 if (RT_SUCCESS(rc))
2061 {
2062 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entry.mobid);
2063 if (pMob)
2064 {
2065 rc = vmsvgaR3GboWrite(pSvgaR3State, &pMob->Gbo, 0, pSvgaDXContext, sizeof(SVGADXContextMobFormat));
2066 }
2067 }
2068
2069 RTMemFree(pSvgaDXContext);
2070 pSvgaDXContext = NULL;
2071 }
2072 }
2073
2074 if (pCmd->mobid != SVGA_ID_INVALID)
2075 {
2076 /* Bind a new context. Copy existing data from the guest backing memory. */
2077 if (pCmd->validContents)
2078 {
2079 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobid);
2080 if (pMob)
2081 {
2082 pSvgaDXContext = (SVGADXContextMobFormat *)RTMemAlloc(sizeof(SVGADXContextMobFormat));
2083 if (pSvgaDXContext)
2084 {
2085 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, 0, pSvgaDXContext, sizeof(SVGADXContextMobFormat));
2086 if (RT_FAILURE(rc))
2087 {
2088 RTMemFree(pSvgaDXContext);
2089 pSvgaDXContext = NULL;
2090 }
2091 }
2092 }
2093 }
2094
2095 rc = vmsvga3dDXBindContext(pThisCC, pCmd->cid, pSvgaDXContext);
2096
2097 RTMemFree(pSvgaDXContext);
2098 }
2099
2100 /* Update the object table. */
2101 entry.mobid = pCmd->mobid;
2102 rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_DXCONTEXT],
2103 pCmd->cid, sizeof(SVGAOTableDXContextEntry), &entry, sizeof(entry));
2104 }
2105 }
2106
2107 return rc;
2108#else
2109 RT_NOREF(pThisCC, pCmd, cbCmd);
2110 return VERR_NOT_SUPPORTED;
2111#endif
2112}
2113
2114
2115/* SVGA_3D_CMD_DX_READBACK_CONTEXT 1146 */
2116static int vmsvga3dCmdDXReadbackContext(PVGASTATECC pThisCC, SVGA3dCmdDXReadbackContext const *pCmd, uint32_t cbCmd)
2117{
2118#ifdef VMSVGA3D_DX
2119 //DEBUG_BREAKPOINT_TEST();
2120 RT_NOREF(cbCmd);
2121
2122 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2123
2124 /* "Request that the device flush the contents back into guest memory." */
2125 SVGAOTableDXContextEntry entry;
2126 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_DXCONTEXT],
2127 pCmd->cid, sizeof(SVGAOTableDXContextEntry), &entry, sizeof(entry));
2128 if (RT_SUCCESS(rc))
2129 {
2130 if (entry.mobid != SVGA_ID_INVALID)
2131 {
2132 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entry.mobid);
2133 if (pMob)
2134 {
2135 /* Get the content. */
2136 SVGADXContextMobFormat *pSvgaDXContext = (SVGADXContextMobFormat *)RTMemAlloc(sizeof(SVGADXContextMobFormat));
2137 if (pSvgaDXContext)
2138 {
2139 rc = vmsvga3dDXReadbackContext(pThisCC, pCmd->cid, pSvgaDXContext);
2140 if (RT_SUCCESS(rc))
2141 rc = vmsvgaR3GboWrite(pSvgaR3State, &pMob->Gbo, 0, pSvgaDXContext, sizeof(SVGADXContextMobFormat));
2142
2143 RTMemFree(pSvgaDXContext);
2144 }
2145 else
2146 rc = VERR_NO_MEMORY;
2147 }
2148 }
2149 }
2150
2151 return rc;
2152#else
2153 RT_NOREF(pThisCC, pCmd, cbCmd);
2154 return VERR_NOT_SUPPORTED;
2155#endif
2156}
2157
2158
2159/* SVGA_3D_CMD_DX_INVALIDATE_CONTEXT 1147 */
2160static int vmsvga3dCmdDXInvalidateContext(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXInvalidateContext const *pCmd, uint32_t cbCmd)
2161{
2162#ifdef VMSVGA3D_DX
2163 DEBUG_BREAKPOINT_TEST();
2164 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2165 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2166 return vmsvga3dDXInvalidateContext(pThisCC, idDXContext);
2167#else
2168 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2169 return VERR_NOT_SUPPORTED;
2170#endif
2171}
2172
2173
2174/* SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER 1148 */
2175static int vmsvga3dCmdDXSetSingleConstantBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetSingleConstantBuffer const *pCmd, uint32_t cbCmd)
2176{
2177#ifdef VMSVGA3D_DX
2178 //DEBUG_BREAKPOINT_TEST();
2179 RT_NOREF(cbCmd);
2180 return vmsvga3dDXSetSingleConstantBuffer(pThisCC, idDXContext, pCmd);
2181#else
2182 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2183 return VERR_NOT_SUPPORTED;
2184#endif
2185}
2186
2187
2188/* SVGA_3D_CMD_DX_SET_SHADER_RESOURCES 1149 */
2189static int vmsvga3dCmdDXSetShaderResources(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetShaderResources const *pCmd, uint32_t cbCmd)
2190{
2191#ifdef VMSVGA3D_DX
2192 //DEBUG_BREAKPOINT_TEST();
2193 SVGA3dShaderResourceViewId const *paShaderResourceViewId = (SVGA3dShaderResourceViewId *)&pCmd[1];
2194 uint32_t const cShaderResourceViewId = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dShaderResourceViewId);
2195 return vmsvga3dDXSetShaderResources(pThisCC, idDXContext, pCmd, cShaderResourceViewId, paShaderResourceViewId);
2196#else
2197 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2198 return VERR_NOT_SUPPORTED;
2199#endif
2200}
2201
2202
2203/* SVGA_3D_CMD_DX_SET_SHADER 1150 */
2204static int vmsvga3dCmdDXSetShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetShader const *pCmd, uint32_t cbCmd)
2205{
2206#ifdef VMSVGA3D_DX
2207 //DEBUG_BREAKPOINT_TEST();
2208 RT_NOREF(cbCmd);
2209 return vmsvga3dDXSetShader(pThisCC, idDXContext, pCmd);
2210#else
2211 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2212 return VERR_NOT_SUPPORTED;
2213#endif
2214}
2215
2216
2217/* SVGA_3D_CMD_DX_SET_SAMPLERS 1151 */
2218static int vmsvga3dCmdDXSetSamplers(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetSamplers const *pCmd, uint32_t cbCmd)
2219{
2220#ifdef VMSVGA3D_DX
2221 //DEBUG_BREAKPOINT_TEST();
2222 SVGA3dSamplerId const *paSamplerId = (SVGA3dSamplerId *)&pCmd[1];
2223 uint32_t const cSamplerId = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSamplerId);
2224 return vmsvga3dDXSetSamplers(pThisCC, idDXContext, pCmd, cSamplerId, paSamplerId);
2225#else
2226 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2227 return VERR_NOT_SUPPORTED;
2228#endif
2229}
2230
2231
2232/* SVGA_3D_CMD_DX_DRAW 1152 */
2233static int vmsvga3dCmdDXDraw(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDraw const *pCmd, uint32_t cbCmd)
2234{
2235#ifdef VMSVGA3D_DX
2236 //DEBUG_BREAKPOINT_TEST();
2237 RT_NOREF(cbCmd);
2238 return vmsvga3dDXDraw(pThisCC, idDXContext, pCmd);
2239#else
2240 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2241 return VERR_NOT_SUPPORTED;
2242#endif
2243}
2244
2245
2246/* SVGA_3D_CMD_DX_DRAW_INDEXED 1153 */
2247static int vmsvga3dCmdDXDrawIndexed(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawIndexed const *pCmd, uint32_t cbCmd)
2248{
2249#ifdef VMSVGA3D_DX
2250 //DEBUG_BREAKPOINT_TEST();
2251 RT_NOREF(cbCmd);
2252 return vmsvga3dDXDrawIndexed(pThisCC, idDXContext, pCmd);
2253#else
2254 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2255 return VERR_NOT_SUPPORTED;
2256#endif
2257}
2258
2259
2260/* SVGA_3D_CMD_DX_DRAW_INSTANCED 1154 */
2261static int vmsvga3dCmdDXDrawInstanced(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawInstanced const *pCmd, uint32_t cbCmd)
2262{
2263#ifdef VMSVGA3D_DX
2264 //DEBUG_BREAKPOINT_TEST();
2265 RT_NOREF(cbCmd);
2266 return vmsvga3dDXDrawInstanced(pThisCC, idDXContext, pCmd);
2267#else
2268 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2269 return VERR_NOT_SUPPORTED;
2270#endif
2271}
2272
2273
2274/* SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED 1155 */
2275static int vmsvga3dCmdDXDrawIndexedInstanced(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawIndexedInstanced const *pCmd, uint32_t cbCmd)
2276{
2277#ifdef VMSVGA3D_DX
2278 //DEBUG_BREAKPOINT_TEST();
2279 RT_NOREF(cbCmd);
2280 return vmsvga3dDXDrawIndexedInstanced(pThisCC, idDXContext, pCmd);
2281#else
2282 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2283 return VERR_NOT_SUPPORTED;
2284#endif
2285}
2286
2287
2288/* SVGA_3D_CMD_DX_DRAW_AUTO 1156 */
2289static int vmsvga3dCmdDXDrawAuto(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawAuto const *pCmd, uint32_t cbCmd)
2290{
2291#ifdef VMSVGA3D_DX
2292 DEBUG_BREAKPOINT_TEST();
2293 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2294 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2295 return vmsvga3dDXDrawAuto(pThisCC, idDXContext);
2296#else
2297 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2298 return VERR_NOT_SUPPORTED;
2299#endif
2300}
2301
2302
2303/* SVGA_3D_CMD_DX_SET_INPUT_LAYOUT 1157 */
2304static int vmsvga3dCmdDXSetInputLayout(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetInputLayout const *pCmd, uint32_t cbCmd)
2305{
2306#ifdef VMSVGA3D_DX
2307 //DEBUG_BREAKPOINT_TEST();
2308 RT_NOREF(cbCmd);
2309 return vmsvga3dDXSetInputLayout(pThisCC, idDXContext, pCmd->elementLayoutId);
2310#else
2311 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2312 return VERR_NOT_SUPPORTED;
2313#endif
2314}
2315
2316
2317/* SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS 1158 */
2318static int vmsvga3dCmdDXSetVertexBuffers(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetVertexBuffers const *pCmd, uint32_t cbCmd)
2319{
2320#ifdef VMSVGA3D_DX
2321 //DEBUG_BREAKPOINT_TEST();
2322 SVGA3dVertexBuffer const *paVertexBuffer = (SVGA3dVertexBuffer *)&pCmd[1];
2323 uint32_t const cVertexBuffer = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dVertexBuffer);
2324 return vmsvga3dDXSetVertexBuffers(pThisCC, idDXContext, pCmd->startBuffer, cVertexBuffer, paVertexBuffer);
2325#else
2326 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2327 return VERR_NOT_SUPPORTED;
2328#endif
2329}
2330
2331
2332/* SVGA_3D_CMD_DX_SET_INDEX_BUFFER 1159 */
2333static int vmsvga3dCmdDXSetIndexBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetIndexBuffer const *pCmd, uint32_t cbCmd)
2334{
2335#ifdef VMSVGA3D_DX
2336 //DEBUG_BREAKPOINT_TEST();
2337 RT_NOREF(cbCmd);
2338 return vmsvga3dDXSetIndexBuffer(pThisCC, idDXContext, pCmd);
2339#else
2340 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2341 return VERR_NOT_SUPPORTED;
2342#endif
2343}
2344
2345
2346/* SVGA_3D_CMD_DX_SET_TOPOLOGY 1160 */
2347static int vmsvga3dCmdDXSetTopology(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetTopology const *pCmd, uint32_t cbCmd)
2348{
2349#ifdef VMSVGA3D_DX
2350 //DEBUG_BREAKPOINT_TEST();
2351 RT_NOREF(cbCmd);
2352 return vmsvga3dDXSetTopology(pThisCC, idDXContext, pCmd->topology);
2353#else
2354 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2355 return VERR_NOT_SUPPORTED;
2356#endif
2357}
2358
2359
2360/* SVGA_3D_CMD_DX_SET_RENDERTARGETS 1161 */
2361static int vmsvga3dCmdDXSetRenderTargets(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetRenderTargets const *pCmd, uint32_t cbCmd)
2362{
2363#ifdef VMSVGA3D_DX
2364 //DEBUG_BREAKPOINT_TEST();
2365 SVGA3dRenderTargetViewId const *paRenderTargetViewId = (SVGA3dRenderTargetViewId *)&pCmd[1];
2366 uint32_t const cRenderTargetViewId = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRenderTargetViewId);
2367 return vmsvga3dDXSetRenderTargets(pThisCC, idDXContext, pCmd->depthStencilViewId, cRenderTargetViewId, paRenderTargetViewId);
2368#else
2369 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2370 return VERR_NOT_SUPPORTED;
2371#endif
2372}
2373
2374
2375/* SVGA_3D_CMD_DX_SET_BLEND_STATE 1162 */
2376static int vmsvga3dCmdDXSetBlendState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetBlendState const *pCmd, uint32_t cbCmd)
2377{
2378#ifdef VMSVGA3D_DX
2379 //DEBUG_BREAKPOINT_TEST();
2380 RT_NOREF(cbCmd);
2381 return vmsvga3dDXSetBlendState(pThisCC, idDXContext, pCmd);
2382#else
2383 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2384 return VERR_NOT_SUPPORTED;
2385#endif
2386}
2387
2388
2389/* SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE 1163 */
2390static int vmsvga3dCmdDXSetDepthStencilState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetDepthStencilState const *pCmd, uint32_t cbCmd)
2391{
2392#ifdef VMSVGA3D_DX
2393 //DEBUG_BREAKPOINT_TEST();
2394 RT_NOREF(cbCmd);
2395 return vmsvga3dDXSetDepthStencilState(pThisCC, idDXContext, pCmd);
2396#else
2397 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2398 return VERR_NOT_SUPPORTED;
2399#endif
2400}
2401
2402
2403/* SVGA_3D_CMD_DX_SET_RASTERIZER_STATE 1164 */
2404static int vmsvga3dCmdDXSetRasterizerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetRasterizerState const *pCmd, uint32_t cbCmd)
2405{
2406#ifdef VMSVGA3D_DX
2407 //DEBUG_BREAKPOINT_TEST();
2408 RT_NOREF(cbCmd);
2409 return vmsvga3dDXSetRasterizerState(pThisCC, idDXContext, pCmd->rasterizerId);
2410#else
2411 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2412 return VERR_NOT_SUPPORTED;
2413#endif
2414}
2415
2416
2417/* SVGA_3D_CMD_DX_DEFINE_QUERY 1165 */
2418static int vmsvga3dCmdDXDefineQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineQuery const *pCmd, uint32_t cbCmd)
2419{
2420#ifdef VMSVGA3D_DX
2421 DEBUG_BREAKPOINT_TEST();
2422 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2423 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2424 return vmsvga3dDXDefineQuery(pThisCC, idDXContext);
2425#else
2426 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2427 return VERR_NOT_SUPPORTED;
2428#endif
2429}
2430
2431
2432/* SVGA_3D_CMD_DX_DESTROY_QUERY 1166 */
2433static int vmsvga3dCmdDXDestroyQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyQuery const *pCmd, uint32_t cbCmd)
2434{
2435#ifdef VMSVGA3D_DX
2436 DEBUG_BREAKPOINT_TEST();
2437 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2438 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2439 return vmsvga3dDXDestroyQuery(pThisCC, idDXContext);
2440#else
2441 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2442 return VERR_NOT_SUPPORTED;
2443#endif
2444}
2445
2446
2447/* SVGA_3D_CMD_DX_BIND_QUERY 1167 */
2448static int vmsvga3dCmdDXBindQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindQuery const *pCmd, uint32_t cbCmd)
2449{
2450#ifdef VMSVGA3D_DX
2451 DEBUG_BREAKPOINT_TEST();
2452 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2453 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2454 return vmsvga3dDXBindQuery(pThisCC, idDXContext);
2455#else
2456 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2457 return VERR_NOT_SUPPORTED;
2458#endif
2459}
2460
2461
2462/* SVGA_3D_CMD_DX_SET_QUERY_OFFSET 1168 */
2463static int vmsvga3dCmdDXSetQueryOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetQueryOffset const *pCmd, uint32_t cbCmd)
2464{
2465#ifdef VMSVGA3D_DX
2466 DEBUG_BREAKPOINT_TEST();
2467 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2468 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2469 return vmsvga3dDXSetQueryOffset(pThisCC, idDXContext);
2470#else
2471 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2472 return VERR_NOT_SUPPORTED;
2473#endif
2474}
2475
2476
2477/* SVGA_3D_CMD_DX_BEGIN_QUERY 1169 */
2478static int vmsvga3dCmdDXBeginQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBeginQuery const *pCmd, uint32_t cbCmd)
2479{
2480#ifdef VMSVGA3D_DX
2481 DEBUG_BREAKPOINT_TEST();
2482 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2483 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2484 return vmsvga3dDXBeginQuery(pThisCC, idDXContext);
2485#else
2486 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2487 return VERR_NOT_SUPPORTED;
2488#endif
2489}
2490
2491
2492/* SVGA_3D_CMD_DX_END_QUERY 1170 */
2493static int vmsvga3dCmdDXEndQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXEndQuery const *pCmd, uint32_t cbCmd)
2494{
2495#ifdef VMSVGA3D_DX
2496 DEBUG_BREAKPOINT_TEST();
2497 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2498 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2499 return vmsvga3dDXEndQuery(pThisCC, idDXContext);
2500#else
2501 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2502 return VERR_NOT_SUPPORTED;
2503#endif
2504}
2505
2506
2507/* SVGA_3D_CMD_DX_READBACK_QUERY 1171 */
2508static int vmsvga3dCmdDXReadbackQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXReadbackQuery const *pCmd, uint32_t cbCmd)
2509{
2510#ifdef VMSVGA3D_DX
2511 DEBUG_BREAKPOINT_TEST();
2512 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2513 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2514 return vmsvga3dDXReadbackQuery(pThisCC, idDXContext);
2515#else
2516 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2517 return VERR_NOT_SUPPORTED;
2518#endif
2519}
2520
2521
2522/* SVGA_3D_CMD_DX_SET_PREDICATION 1172 */
2523static int vmsvga3dCmdDXSetPredication(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetPredication const *pCmd, uint32_t cbCmd)
2524{
2525#ifdef VMSVGA3D_DX
2526 DEBUG_BREAKPOINT_TEST();
2527 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2528 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2529 return vmsvga3dDXSetPredication(pThisCC, idDXContext);
2530#else
2531 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2532 return VERR_NOT_SUPPORTED;
2533#endif
2534}
2535
2536
2537/* SVGA_3D_CMD_DX_SET_SOTARGETS 1173 */
2538static int vmsvga3dCmdDXSetSOTargets(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetSOTargets const *pCmd, uint32_t cbCmd)
2539{
2540#ifdef VMSVGA3D_DX
2541 //DEBUG_BREAKPOINT_TEST();
2542 SVGA3dSoTarget const *paSoTarget = (SVGA3dSoTarget *)&pCmd[1];
2543 uint32_t const cSoTarget = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSoTarget);
2544 return vmsvga3dDXSetSOTargets(pThisCC, idDXContext, cSoTarget, paSoTarget);
2545#else
2546 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2547 return VERR_NOT_SUPPORTED;
2548#endif
2549}
2550
2551
2552/* SVGA_3D_CMD_DX_SET_VIEWPORTS 1174 */
2553static int vmsvga3dCmdDXSetViewports(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetViewports const *pCmd, uint32_t cbCmd)
2554{
2555#ifdef VMSVGA3D_DX
2556 //DEBUG_BREAKPOINT_TEST();
2557 SVGA3dViewport const *paViewport = (SVGA3dViewport *)&pCmd[1];
2558 uint32_t const cViewport = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dViewport);
2559 return vmsvga3dDXSetViewports(pThisCC, idDXContext, cViewport, paViewport);
2560#else
2561 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2562 return VERR_NOT_SUPPORTED;
2563#endif
2564}
2565
2566
2567/* SVGA_3D_CMD_DX_SET_SCISSORRECTS 1175 */
2568static int vmsvga3dCmdDXSetScissorRects(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetScissorRects const *pCmd, uint32_t cbCmd)
2569{
2570#ifdef VMSVGA3D_DX
2571 //DEBUG_BREAKPOINT_TEST();
2572 SVGASignedRect const *paRect = (SVGASignedRect *)&pCmd[1];
2573 uint32_t const cRect = (cbCmd - sizeof(*pCmd)) / sizeof(SVGASignedRect);
2574 return vmsvga3dDXSetScissorRects(pThisCC, idDXContext, cRect, paRect);
2575#else
2576 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2577 return VERR_NOT_SUPPORTED;
2578#endif
2579}
2580
2581
2582/* SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW 1176 */
2583static int vmsvga3dCmdDXClearRenderTargetView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearRenderTargetView const *pCmd, uint32_t cbCmd)
2584{
2585#ifdef VMSVGA3D_DX
2586 //DEBUG_BREAKPOINT_TEST();
2587 RT_NOREF(cbCmd);
2588 return vmsvga3dDXClearRenderTargetView(pThisCC, idDXContext, pCmd);
2589#else
2590 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2591 return VERR_NOT_SUPPORTED;
2592#endif
2593}
2594
2595
2596/* SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW 1177 */
2597static int vmsvga3dCmdDXClearDepthStencilView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearDepthStencilView const *pCmd, uint32_t cbCmd)
2598{
2599#ifdef VMSVGA3D_DX
2600 //DEBUG_BREAKPOINT_TEST();
2601 RT_NOREF(cbCmd);
2602 return vmsvga3dDXClearDepthStencilView(pThisCC, idDXContext, pCmd);
2603#else
2604 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2605 return VERR_NOT_SUPPORTED;
2606#endif
2607}
2608
2609
2610/* SVGA_3D_CMD_DX_PRED_COPY_REGION 1178 */
2611static int vmsvga3dCmdDXPredCopyRegion(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredCopyRegion const *pCmd, uint32_t cbCmd)
2612{
2613#ifdef VMSVGA3D_DX
2614 //DEBUG_BREAKPOINT_TEST();
2615 RT_NOREF(cbCmd);
2616 return vmsvga3dDXPredCopyRegion(pThisCC, idDXContext, pCmd);
2617#else
2618 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2619 return VERR_NOT_SUPPORTED;
2620#endif
2621}
2622
2623
2624/* SVGA_3D_CMD_DX_PRED_COPY 1179 */
2625static int vmsvga3dCmdDXPredCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredCopy const *pCmd, uint32_t cbCmd)
2626{
2627#ifdef VMSVGA3D_DX
2628 DEBUG_BREAKPOINT_TEST();
2629 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2630 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2631 return vmsvga3dDXPredCopy(pThisCC, idDXContext);
2632#else
2633 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2634 return VERR_NOT_SUPPORTED;
2635#endif
2636}
2637
2638
2639/* SVGA_3D_CMD_DX_PRESENTBLT 1180 */
2640static int vmsvga3dCmdDXPresentBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPresentBlt const *pCmd, uint32_t cbCmd)
2641{
2642#ifdef VMSVGA3D_DX
2643 DEBUG_BREAKPOINT_TEST();
2644 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2645 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2646 return vmsvga3dDXPresentBlt(pThisCC, idDXContext);
2647#else
2648 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2649 return VERR_NOT_SUPPORTED;
2650#endif
2651}
2652
2653
2654/* SVGA_3D_CMD_DX_GENMIPS 1181 */
2655static int vmsvga3dCmdDXGenMips(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXGenMips const *pCmd, uint32_t cbCmd)
2656{
2657#ifdef VMSVGA3D_DX
2658 //DEBUG_BREAKPOINT_TEST();
2659 RT_NOREF(cbCmd);
2660 return vmsvga3dDXGenMips(pThisCC, idDXContext, pCmd);
2661#else
2662 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2663 return VERR_NOT_SUPPORTED;
2664#endif
2665}
2666
2667
2668/* SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE 1182 */
2669static int vmsvga3dCmdDXUpdateSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXUpdateSubResource const *pCmd, uint32_t cbCmd)
2670{
2671#ifdef VMSVGA3D_DX
2672 //DEBUG_BREAKPOINT_TEST();
2673 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2674 RT_NOREF(cbCmd);
2675
2676 LogFlowFunc(("sid=%u, subResource=%u, box=%d,%d,%d %ux%ux%u\n",
2677 pCmd->sid, pCmd->subResource, pCmd->box.x, pCmd->box.y, pCmd->box.z, pCmd->box.w, pCmd->box.h, pCmd->box.z));
2678
2679 /* "Inform the device that the guest-contents have been updated." */
2680 SVGAOTableSurfaceEntry entrySurface;
2681 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2682 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2683 if (RT_SUCCESS(rc))
2684 {
2685 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
2686 if (pMob)
2687 {
2688 uint32 const arraySize = (entrySurface.surface1Flags & SVGA3D_SURFACE_CUBEMAP)
2689 ? SVGA3D_MAX_SURFACE_FACES
2690 : RT_MAX(entrySurface.arraySize, 1);
2691 ASSERT_GUEST_RETURN(pCmd->subResource < arraySize * entrySurface.numMipLevels, VERR_INVALID_PARAMETER);
2692 /* pCmd->box will be verified by the mapping function. */
2693 RT_UNTRUSTED_VALIDATED_FENCE();
2694
2695 /** @todo Mapping functions should use subresource index rather than SVGA3dSurfaceImageId? */
2696 SVGA3dSurfaceImageId image;
2697 image.sid = pCmd->sid;
2698 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &image.mipmap, &image.face);
2699
2700 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, &pCmd->box, SVGA3D_WRITE_HOST_VRAM);
2701 AssertRC(rc);
2702 }
2703 }
2704
2705 return rc;
2706#else
2707 RT_NOREF(pThisCC, pCmd, cbCmd);
2708 return VERR_NOT_SUPPORTED;
2709#endif
2710}
2711
2712
2713/* SVGA_3D_CMD_DX_READBACK_SUBRESOURCE 1183 */
2714static int vmsvga3dCmdDXReadbackSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXReadbackSubResource const *pCmd, uint32_t cbCmd)
2715{
2716#ifdef VMSVGA3D_DX
2717 //DEBUG_BREAKPOINT_TEST();
2718 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2719 RT_NOREF(cbCmd);
2720
2721 LogFlowFunc(("sid=%u, subResource=%u\n",
2722 pCmd->sid, pCmd->subResource));
2723
2724 /* "Request the device to flush the dirty contents into the guest." */
2725 SVGAOTableSurfaceEntry entrySurface;
2726 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2727 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2728 if (RT_SUCCESS(rc))
2729 {
2730 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
2731 if (pMob)
2732 {
2733 uint32 const arraySize = (entrySurface.surface1Flags & SVGA3D_SURFACE_CUBEMAP)
2734 ? SVGA3D_MAX_SURFACE_FACES
2735 : RT_MAX(entrySurface.arraySize, 1);
2736 ASSERT_GUEST_RETURN(pCmd->subResource < arraySize * entrySurface.numMipLevels, VERR_INVALID_PARAMETER);
2737 RT_UNTRUSTED_VALIDATED_FENCE();
2738
2739 /** @todo Mapping functions should use subresource index rather than SVGA3dSurfaceImageId? */
2740 SVGA3dSurfaceImageId image;
2741 image.sid = pCmd->sid;
2742 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &image.mipmap, &image.face);
2743
2744 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, /* all pBox = */ NULL, SVGA3D_READ_HOST_VRAM);
2745 AssertRC(rc);
2746 }
2747 }
2748
2749 return rc;
2750#else
2751 RT_NOREF(pThisCC, pCmd, cbCmd);
2752 return VERR_NOT_SUPPORTED;
2753#endif
2754}
2755
2756
2757/* SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE 1184 */
2758static int vmsvga3dCmdDXInvalidateSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXInvalidateSubResource const *pCmd, uint32_t cbCmd)
2759{
2760#ifdef VMSVGA3D_DX
2761 DEBUG_BREAKPOINT_TEST();
2762 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2763 RT_NOREF(cbCmd);
2764
2765 LogFlowFunc(("sid=%u, subResource=%u\n",
2766 pCmd->sid, pCmd->subResource));
2767
2768 /* "Notify the device that the contents can be lost." */
2769 SVGAOTableSurfaceEntry entrySurface;
2770 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2771 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2772 if (RT_SUCCESS(rc))
2773 {
2774 uint32_t iFace;
2775 uint32_t iMipmap;
2776 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &iMipmap, &iFace);
2777 vmsvga3dSurfaceInvalidate(pThisCC, pCmd->sid, iFace, iMipmap);
2778 }
2779
2780 return rc;
2781#else
2782 RT_NOREF(pThisCC, pCmd, cbCmd);
2783 return VERR_NOT_SUPPORTED;
2784#endif
2785}
2786
2787
2788/* SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW 1185 */
2789static int vmsvga3dCmdDXDefineShaderResourceView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineShaderResourceView const *pCmd, uint32_t cbCmd)
2790{
2791#ifdef VMSVGA3D_DX
2792 //DEBUG_BREAKPOINT_TEST();
2793 RT_NOREF(cbCmd);
2794 return vmsvga3dDXDefineShaderResourceView(pThisCC, idDXContext, pCmd);
2795#else
2796 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2797 return VERR_NOT_SUPPORTED;
2798#endif
2799}
2800
2801
2802/* SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW 1186 */
2803static int vmsvga3dCmdDXDestroyShaderResourceView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyShaderResourceView const *pCmd, uint32_t cbCmd)
2804{
2805#ifdef VMSVGA3D_DX
2806 //DEBUG_BREAKPOINT_TEST();
2807 RT_NOREF(cbCmd);
2808 return vmsvga3dDXDestroyShaderResourceView(pThisCC, idDXContext, pCmd);
2809#else
2810 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2811 return VERR_NOT_SUPPORTED;
2812#endif
2813}
2814
2815
2816/* SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW 1187 */
2817static int vmsvga3dCmdDXDefineRenderTargetView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineRenderTargetView const *pCmd, uint32_t cbCmd)
2818{
2819#ifdef VMSVGA3D_DX
2820 //DEBUG_BREAKPOINT_TEST();
2821 RT_NOREF(cbCmd);
2822 return vmsvga3dDXDefineRenderTargetView(pThisCC, idDXContext, pCmd);
2823#else
2824 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2825 return VERR_NOT_SUPPORTED;
2826#endif
2827}
2828
2829
2830/* SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW 1188 */
2831static int vmsvga3dCmdDXDestroyRenderTargetView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyRenderTargetView const *pCmd, uint32_t cbCmd)
2832{
2833#ifdef VMSVGA3D_DX
2834 //DEBUG_BREAKPOINT_TEST();
2835 RT_NOREF(cbCmd);
2836 return vmsvga3dDXDestroyRenderTargetView(pThisCC, idDXContext, pCmd);
2837#else
2838 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2839 return VERR_NOT_SUPPORTED;
2840#endif
2841}
2842
2843
2844/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW 1189 */
2845static int vmsvga3dCmdDXDefineDepthStencilView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilView const *pCmd, uint32_t cbCmd)
2846{
2847#ifdef VMSVGA3D_DX
2848 //DEBUG_BREAKPOINT_TEST();
2849 RT_NOREF(cbCmd);
2850 SVGA3dCmdDXDefineDepthStencilView_v2 cmd;
2851 cmd.depthStencilViewId = pCmd->depthStencilViewId;
2852 cmd.sid = pCmd->sid;
2853 cmd.format = pCmd->format;
2854 cmd.resourceDimension = pCmd->resourceDimension;
2855 cmd.mipSlice = pCmd->mipSlice;
2856 cmd.firstArraySlice = pCmd->firstArraySlice;
2857 cmd.arraySize = pCmd->arraySize;
2858 cmd.flags = 0;
2859 return vmsvga3dDXDefineDepthStencilView(pThisCC, idDXContext, &cmd);
2860#else
2861 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2862 return VERR_NOT_SUPPORTED;
2863#endif
2864}
2865
2866
2867/* SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW 1190 */
2868static int vmsvga3dCmdDXDestroyDepthStencilView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyDepthStencilView const *pCmd, uint32_t cbCmd)
2869{
2870#ifdef VMSVGA3D_DX
2871 //DEBUG_BREAKPOINT_TEST();
2872 RT_NOREF(cbCmd);
2873 return vmsvga3dDXDestroyDepthStencilView(pThisCC, idDXContext, pCmd);
2874#else
2875 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2876 return VERR_NOT_SUPPORTED;
2877#endif
2878}
2879
2880
2881/* SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT 1191 */
2882static int vmsvga3dCmdDXDefineElementLayout(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineElementLayout const *pCmd, uint32_t cbCmd)
2883{
2884#ifdef VMSVGA3D_DX
2885 //DEBUG_BREAKPOINT_TEST();
2886 SVGA3dInputElementDesc const *paDesc = (SVGA3dInputElementDesc *)&pCmd[1];
2887 uint32_t const cDesc = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dInputElementDesc);
2888 return vmsvga3dDXDefineElementLayout(pThisCC, idDXContext, pCmd->elementLayoutId, cDesc, paDesc);
2889#else
2890 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2891 return VERR_NOT_SUPPORTED;
2892#endif
2893}
2894
2895
2896/* SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT 1192 */
2897static int vmsvga3dCmdDXDestroyElementLayout(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyElementLayout const *pCmd, uint32_t cbCmd)
2898{
2899#ifdef VMSVGA3D_DX
2900 DEBUG_BREAKPOINT_TEST();
2901 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2902 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2903 return vmsvga3dDXDestroyElementLayout(pThisCC, idDXContext);
2904#else
2905 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2906 return VERR_NOT_SUPPORTED;
2907#endif
2908}
2909
2910
2911/* SVGA_3D_CMD_DX_DEFINE_BLEND_STATE 1193 */
2912static int vmsvga3dCmdDXDefineBlendState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineBlendState const *pCmd, uint32_t cbCmd)
2913{
2914#ifdef VMSVGA3D_DX
2915 //DEBUG_BREAKPOINT_TEST();
2916 RT_NOREF(cbCmd);
2917 return vmsvga3dDXDefineBlendState(pThisCC, idDXContext, pCmd);
2918#else
2919 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2920 return VERR_NOT_SUPPORTED;
2921#endif
2922}
2923
2924
2925/* SVGA_3D_CMD_DX_DESTROY_BLEND_STATE 1194 */
2926static int vmsvga3dCmdDXDestroyBlendState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyBlendState const *pCmd, uint32_t cbCmd)
2927{
2928#ifdef VMSVGA3D_DX
2929 DEBUG_BREAKPOINT_TEST();
2930 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2931 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2932 return vmsvga3dDXDestroyBlendState(pThisCC, idDXContext);
2933#else
2934 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2935 return VERR_NOT_SUPPORTED;
2936#endif
2937}
2938
2939
2940/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE 1195 */
2941static int vmsvga3dCmdDXDefineDepthStencilState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilState const *pCmd, uint32_t cbCmd)
2942{
2943#ifdef VMSVGA3D_DX
2944 //DEBUG_BREAKPOINT_TEST();
2945 RT_NOREF(cbCmd);
2946 return vmsvga3dDXDefineDepthStencilState(pThisCC, idDXContext, pCmd);
2947#else
2948 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2949 return VERR_NOT_SUPPORTED;
2950#endif
2951}
2952
2953
2954/* SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE 1196 */
2955static int vmsvga3dCmdDXDestroyDepthStencilState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyDepthStencilState const *pCmd, uint32_t cbCmd)
2956{
2957#ifdef VMSVGA3D_DX
2958 DEBUG_BREAKPOINT_TEST();
2959 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2960 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2961 return vmsvga3dDXDestroyDepthStencilState(pThisCC, idDXContext);
2962#else
2963 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2964 return VERR_NOT_SUPPORTED;
2965#endif
2966}
2967
2968
2969/* SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE 1197 */
2970static int vmsvga3dCmdDXDefineRasterizerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineRasterizerState const *pCmd, uint32_t cbCmd)
2971{
2972#ifdef VMSVGA3D_DX
2973 //DEBUG_BREAKPOINT_TEST();
2974 RT_NOREF(cbCmd);
2975 return vmsvga3dDXDefineRasterizerState(pThisCC, idDXContext, pCmd);
2976#else
2977 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2978 return VERR_NOT_SUPPORTED;
2979#endif
2980}
2981
2982
2983/* SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE 1198 */
2984static int vmsvga3dCmdDXDestroyRasterizerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyRasterizerState const *pCmd, uint32_t cbCmd)
2985{
2986#ifdef VMSVGA3D_DX
2987 DEBUG_BREAKPOINT_TEST();
2988 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2989 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2990 return vmsvga3dDXDestroyRasterizerState(pThisCC, idDXContext);
2991#else
2992 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2993 return VERR_NOT_SUPPORTED;
2994#endif
2995}
2996
2997
2998/* SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE 1199 */
2999static int vmsvga3dCmdDXDefineSamplerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineSamplerState const *pCmd, uint32_t cbCmd)
3000{
3001#ifdef VMSVGA3D_DX
3002 //DEBUG_BREAKPOINT_TEST();
3003 RT_NOREF(cbCmd);
3004 return vmsvga3dDXDefineSamplerState(pThisCC, idDXContext, pCmd);
3005#else
3006 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3007 return VERR_NOT_SUPPORTED;
3008#endif
3009}
3010
3011
3012/* SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE 1200 */
3013static int vmsvga3dCmdDXDestroySamplerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroySamplerState const *pCmd, uint32_t cbCmd)
3014{
3015#ifdef VMSVGA3D_DX
3016 DEBUG_BREAKPOINT_TEST();
3017 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3018 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3019 return vmsvga3dDXDestroySamplerState(pThisCC, idDXContext);
3020#else
3021 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3022 return VERR_NOT_SUPPORTED;
3023#endif
3024}
3025
3026
3027/* SVGA_3D_CMD_DX_DEFINE_SHADER 1201 */
3028static int vmsvga3dCmdDXDefineShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineShader const *pCmd, uint32_t cbCmd)
3029{
3030#ifdef VMSVGA3D_DX
3031 //DEBUG_BREAKPOINT_TEST();
3032 RT_NOREF(cbCmd);
3033 return vmsvga3dDXDefineShader(pThisCC, idDXContext, pCmd);
3034#else
3035 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3036 return VERR_NOT_SUPPORTED;
3037#endif
3038}
3039
3040
3041/* SVGA_3D_CMD_DX_DESTROY_SHADER 1202 */
3042static int vmsvga3dCmdDXDestroyShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyShader const *pCmd, uint32_t cbCmd)
3043{
3044#ifdef VMSVGA3D_DX
3045 //DEBUG_BREAKPOINT_TEST();
3046 RT_NOREF(cbCmd);
3047 return vmsvga3dDXDestroyShader(pThisCC, idDXContext, pCmd);
3048#else
3049 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3050 return VERR_NOT_SUPPORTED;
3051#endif
3052}
3053
3054
3055/* SVGA_3D_CMD_DX_BIND_SHADER 1203 */
3056static int vmsvga3dCmdDXBindShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindShader const *pCmd, uint32_t cbCmd)
3057{
3058#ifdef VMSVGA3D_DX
3059 //DEBUG_BREAKPOINT_TEST();
3060 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3061 RT_NOREF(idDXContext, cbCmd);
3062 /* This returns NULL if mob does not exist. If the guest sends a wrong mob id, the current mob will be unbound. */
3063 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobid);
3064 return vmsvga3dDXBindShader(pThisCC, pCmd, pMob);
3065#else
3066 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3067 return VERR_NOT_SUPPORTED;
3068#endif
3069}
3070
3071
3072/* SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT 1204 */
3073static int vmsvga3dCmdDXDefineStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineStreamOutput const *pCmd, uint32_t cbCmd)
3074{
3075#ifdef VMSVGA3D_DX
3076 //DEBUG_BREAKPOINT_TEST();
3077 RT_NOREF(cbCmd);
3078 return vmsvga3dDXDefineStreamOutput(pThisCC, idDXContext, pCmd);
3079#else
3080 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3081 return VERR_NOT_SUPPORTED;
3082#endif
3083}
3084
3085
3086/* SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT 1205 */
3087static int vmsvga3dCmdDXDestroyStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyStreamOutput const *pCmd, uint32_t cbCmd)
3088{
3089#ifdef VMSVGA3D_DX
3090 DEBUG_BREAKPOINT_TEST();
3091 RT_NOREF(cbCmd);
3092 return vmsvga3dDXDestroyStreamOutput(pThisCC, idDXContext, pCmd);
3093#else
3094 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3095 return VERR_NOT_SUPPORTED;
3096#endif
3097}
3098
3099
3100/* SVGA_3D_CMD_DX_SET_STREAMOUTPUT 1206 */
3101static int vmsvga3dCmdDXSetStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetStreamOutput const *pCmd, uint32_t cbCmd)
3102{
3103#ifdef VMSVGA3D_DX
3104 //DEBUG_BREAKPOINT_TEST();
3105 RT_NOREF(cbCmd);
3106 return vmsvga3dDXSetStreamOutput(pThisCC, idDXContext, pCmd);
3107#else
3108 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3109 return VERR_NOT_SUPPORTED;
3110#endif
3111}
3112
3113
3114/* SVGA_3D_CMD_DX_SET_COTABLE 1207 */
3115static int vmsvga3dCmdDXSetCOTable(PVGASTATECC pThisCC, SVGA3dCmdDXSetCOTable const *pCmd, uint32_t cbCmd)
3116{
3117#ifdef VMSVGA3D_DX
3118 //DEBUG_BREAKPOINT_TEST();
3119 RT_NOREF(cbCmd);
3120 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3121 /* This returns NULL if mob does not exist. If the guest sends a wrong mob id, the current mob will be unbound. */
3122 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobid);
3123 return vmsvga3dDXSetCOTable(pThisCC, pCmd, pMob);
3124#else
3125 RT_NOREF(pThisCC, pCmd, cbCmd);
3126 return VERR_NOT_SUPPORTED;
3127#endif
3128}
3129
3130
3131/* SVGA_3D_CMD_DX_READBACK_COTABLE 1208 */
3132static int vmsvga3dCmdDXReadbackCOTable(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXReadbackCOTable const *pCmd, uint32_t cbCmd)
3133{
3134#ifdef VMSVGA3D_DX
3135 //DEBUG_BREAKPOINT_TEST();
3136 RT_NOREF(idDXContext, cbCmd);
3137 return vmsvga3dDXReadbackCOTable(pThisCC, pCmd);
3138#else
3139 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3140 return VERR_NOT_SUPPORTED;
3141#endif
3142}
3143
3144
3145/* SVGA_3D_CMD_DX_BUFFER_COPY 1209 */
3146static int vmsvga3dCmdDXBufferCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBufferCopy const *pCmd, uint32_t cbCmd)
3147{
3148#ifdef VMSVGA3D_DX
3149 DEBUG_BREAKPOINT_TEST();
3150 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3151 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3152 return vmsvga3dDXBufferCopy(pThisCC, idDXContext);
3153#else
3154 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3155 return VERR_NOT_SUPPORTED;
3156#endif
3157}
3158
3159
3160/* SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER 1210 */
3161static int vmsvga3dCmdDXTransferFromBuffer(PVGASTATECC pThisCC, SVGA3dCmdDXTransferFromBuffer const *pCmd, uint32_t cbCmd)
3162{
3163#ifdef VMSVGA3D_DX
3164 //DEBUG_BREAKPOINT_TEST();
3165 RT_NOREF(cbCmd);
3166
3167 /* Plan:
3168 * - map the buffer;
3169 * - map the surface;
3170 * - copy from buffer map to the surface map.
3171 */
3172
3173 int rc;
3174
3175 SVGA3dSurfaceImageId imageBuffer;
3176 imageBuffer.sid = pCmd->srcSid;
3177 imageBuffer.face = 0;
3178 imageBuffer.mipmap = 0;
3179
3180 SVGA3dSurfaceImageId imageSurface;
3181 imageSurface.sid = pCmd->destSid;
3182 rc = vmsvga3dCalcSurfaceMipmapAndFace(pThisCC, pCmd->destSid, pCmd->destSubResource, &imageSurface.mipmap, &imageSurface.face);
3183 AssertRCReturn(rc, rc);
3184
3185 /*
3186 * Map the buffer.
3187 */
3188 VMSVGA3D_MAPPED_SURFACE mapBuffer;
3189 rc = vmsvga3dSurfaceMap(pThisCC, &imageBuffer, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapBuffer);
3190 if (RT_SUCCESS(rc))
3191 {
3192 /*
3193 * Map the surface.
3194 */
3195 VMSVGA3D_MAPPED_SURFACE mapSurface;
3196 rc = vmsvga3dSurfaceMap(pThisCC, &imageSurface, &pCmd->destBox, VMSVGA3D_SURFACE_MAP_WRITE, &mapSurface);
3197 if (RT_SUCCESS(rc))
3198 {
3199 /*
3200 * Copy the mapped buffer to the surface.
3201 */
3202 uint8_t const *pu8Buffer = (uint8_t *)mapBuffer.pvData;
3203 uint32_t const cbBuffer = mapBuffer.box.w * mapBuffer.cbPixel;
3204
3205 if (pCmd->srcOffset <= cbBuffer)
3206 {
3207 RT_UNTRUSTED_VALIDATED_FENCE();
3208 uint8_t const *pu8BufferBegin = pu8Buffer;
3209 uint8_t const *pu8BufferEnd = pu8Buffer + cbBuffer;
3210
3211 pu8Buffer += pCmd->srcOffset;
3212
3213 uint8_t *pu8Surface = (uint8_t *)mapSurface.pvData;
3214
3215 uint32_t const cbWidth = mapSurface.box.w * mapSurface.cbPixel;
3216 for (uint32_t z = 0; z < mapSurface.box.d && RT_SUCCESS(rc); ++z)
3217 {
3218 uint8_t const *pu8BufferRow = pu8Buffer;
3219 uint8_t *pu8SurfaceRow = pu8Surface;
3220 for (uint32_t y = 0; y < mapSurface.box.h; ++y)
3221 {
3222 ASSERT_GUEST_STMT_BREAK( (uintptr_t)pu8BufferRow >= (uintptr_t)pu8BufferBegin
3223 && (uintptr_t)pu8BufferRow < (uintptr_t)pu8BufferEnd
3224 && (uintptr_t)(pu8BufferRow + cbWidth) > (uintptr_t)pu8BufferBegin
3225 && (uintptr_t)(pu8BufferRow + cbWidth) <= (uintptr_t)pu8BufferEnd,
3226 rc = VERR_INVALID_PARAMETER);
3227
3228 memcpy(pu8SurfaceRow, pu8BufferRow, cbWidth);
3229
3230 pu8SurfaceRow += mapSurface.cbRowPitch;
3231 pu8BufferRow += pCmd->srcPitch;
3232 }
3233
3234 pu8Buffer += pCmd->srcSlicePitch;
3235 pu8Surface += mapSurface.cbDepthPitch;
3236 }
3237 }
3238 else
3239 ASSERT_GUEST_FAILED_STMT(rc = VERR_INVALID_PARAMETER);
3240
3241 vmsvga3dSurfaceUnmap(pThisCC, &imageSurface, &mapSurface, true);
3242 }
3243
3244 vmsvga3dSurfaceUnmap(pThisCC, &imageBuffer, &mapBuffer, false);
3245 }
3246
3247 return rc;
3248#else
3249 RT_NOREF(pThisCC, pCmd, cbCmd);
3250 return VERR_NOT_SUPPORTED;
3251#endif
3252}
3253
3254
3255/* SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK 1211 */
3256static int vmsvga3dCmdDXSurfaceCopyAndReadback(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSurfaceCopyAndReadback const *pCmd, uint32_t cbCmd)
3257{
3258#ifdef VMSVGA3D_DX
3259 DEBUG_BREAKPOINT_TEST();
3260 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3261 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3262 return vmsvga3dDXSurfaceCopyAndReadback(pThisCC, idDXContext);
3263#else
3264 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3265 return VERR_NOT_SUPPORTED;
3266#endif
3267}
3268
3269
3270/* SVGA_3D_CMD_DX_MOVE_QUERY 1212 */
3271static int vmsvga3dCmdDXMoveQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXMoveQuery const *pCmd, uint32_t cbCmd)
3272{
3273#ifdef VMSVGA3D_DX
3274 DEBUG_BREAKPOINT_TEST();
3275 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3276 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3277 return vmsvga3dDXMoveQuery(pThisCC, idDXContext);
3278#else
3279 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3280 return VERR_NOT_SUPPORTED;
3281#endif
3282}
3283
3284
3285/* SVGA_3D_CMD_DX_BIND_ALL_QUERY 1213 */
3286static int vmsvga3dCmdDXBindAllQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindAllQuery const *pCmd, uint32_t cbCmd)
3287{
3288#ifdef VMSVGA3D_DX
3289 DEBUG_BREAKPOINT_TEST();
3290 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3291 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3292 return vmsvga3dDXBindAllQuery(pThisCC, idDXContext);
3293#else
3294 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3295 return VERR_NOT_SUPPORTED;
3296#endif
3297}
3298
3299
3300/* SVGA_3D_CMD_DX_READBACK_ALL_QUERY 1214 */
3301static int vmsvga3dCmdDXReadbackAllQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXReadbackAllQuery const *pCmd, uint32_t cbCmd)
3302{
3303#ifdef VMSVGA3D_DX
3304 DEBUG_BREAKPOINT_TEST();
3305 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3306 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3307 return vmsvga3dDXReadbackAllQuery(pThisCC, idDXContext);
3308#else
3309 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3310 return VERR_NOT_SUPPORTED;
3311#endif
3312}
3313
3314
3315/* SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER 1215 */
3316static int vmsvga3dCmdDXPredTransferFromBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredTransferFromBuffer const *pCmd, uint32_t cbCmd)
3317{
3318#ifdef VMSVGA3D_DX
3319 //DEBUG_BREAKPOINT_TEST();
3320 RT_NOREF(idDXContext, cbCmd);
3321
3322 /* This command is executed in a context: "The context is implied from the command buffer header."
3323 * However the device design allows to do the transfer without a context, so re-use context-less command handler.
3324 */
3325 SVGA3dCmdDXTransferFromBuffer cmd;
3326 cmd.srcSid = pCmd->srcSid;
3327 cmd.srcOffset = pCmd->srcOffset;
3328 cmd.srcPitch = pCmd->srcPitch;
3329 cmd.srcSlicePitch = pCmd->srcSlicePitch;
3330 cmd.destSid = pCmd->destSid;
3331 cmd.destSubResource = pCmd->destSubResource;
3332 cmd.destBox = pCmd->destBox;
3333 return vmsvga3dCmdDXTransferFromBuffer(pThisCC, &cmd, sizeof(cmd));
3334#else
3335 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3336 return VERR_NOT_SUPPORTED;
3337#endif
3338}
3339
3340
3341/* SVGA_3D_CMD_DX_MOB_FENCE_64 1216 */
3342static int vmsvga3dCmdDXMobFence64(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXMobFence64 const *pCmd, uint32_t cbCmd)
3343{
3344#ifdef VMSVGA3D_DX
3345 DEBUG_BREAKPOINT_TEST();
3346 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3347 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3348 return vmsvga3dDXMobFence64(pThisCC, idDXContext);
3349#else
3350 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3351 return VERR_NOT_SUPPORTED;
3352#endif
3353}
3354
3355
3356/* SVGA_3D_CMD_DX_BIND_ALL_SHADER 1217 */
3357static int vmsvga3dCmdDXBindAllShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindAllShader const *pCmd, uint32_t cbCmd)
3358{
3359#ifdef VMSVGA3D_DX
3360 DEBUG_BREAKPOINT_TEST();
3361 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3362 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3363 return vmsvga3dDXBindAllShader(pThisCC, idDXContext);
3364#else
3365 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3366 return VERR_NOT_SUPPORTED;
3367#endif
3368}
3369
3370
3371/* SVGA_3D_CMD_DX_HINT 1218 */
3372static int vmsvga3dCmdDXHint(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXHint const *pCmd, uint32_t cbCmd)
3373{
3374#ifdef VMSVGA3D_DX
3375 DEBUG_BREAKPOINT_TEST();
3376 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3377 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3378 return vmsvga3dDXHint(pThisCC, idDXContext);
3379#else
3380 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3381 return VERR_NOT_SUPPORTED;
3382#endif
3383}
3384
3385
3386/* SVGA_3D_CMD_DX_BUFFER_UPDATE 1219 */
3387static int vmsvga3dCmdDXBufferUpdate(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBufferUpdate const *pCmd, uint32_t cbCmd)
3388{
3389#ifdef VMSVGA3D_DX
3390 DEBUG_BREAKPOINT_TEST();
3391 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3392 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3393 return vmsvga3dDXBufferUpdate(pThisCC, idDXContext);
3394#else
3395 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3396 return VERR_NOT_SUPPORTED;
3397#endif
3398}
3399
3400
3401/* SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET 1220 */
3402static int vmsvga3dCmdDXSetVSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetVSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3403{
3404#ifdef VMSVGA3D_DX
3405 DEBUG_BREAKPOINT_TEST();
3406 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3407 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3408 return vmsvga3dDXSetVSConstantBufferOffset(pThisCC, idDXContext);
3409#else
3410 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3411 return VERR_NOT_SUPPORTED;
3412#endif
3413}
3414
3415
3416/* SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET 1221 */
3417static int vmsvga3dCmdDXSetPSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetPSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3418{
3419#ifdef VMSVGA3D_DX
3420 DEBUG_BREAKPOINT_TEST();
3421 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3422 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3423 return vmsvga3dDXSetPSConstantBufferOffset(pThisCC, idDXContext);
3424#else
3425 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3426 return VERR_NOT_SUPPORTED;
3427#endif
3428}
3429
3430
3431/* SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET 1222 */
3432static int vmsvga3dCmdDXSetGSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetGSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3433{
3434#ifdef VMSVGA3D_DX
3435 DEBUG_BREAKPOINT_TEST();
3436 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3437 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3438 return vmsvga3dDXSetGSConstantBufferOffset(pThisCC, idDXContext);
3439#else
3440 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3441 return VERR_NOT_SUPPORTED;
3442#endif
3443}
3444
3445
3446/* SVGA_3D_CMD_DX_SET_HS_CONSTANT_BUFFER_OFFSET 1223 */
3447static int vmsvga3dCmdDXSetHSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetHSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3448{
3449#ifdef VMSVGA3D_DX
3450 DEBUG_BREAKPOINT_TEST();
3451 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3452 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3453 return vmsvga3dDXSetHSConstantBufferOffset(pThisCC, idDXContext);
3454#else
3455 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3456 return VERR_NOT_SUPPORTED;
3457#endif
3458}
3459
3460
3461/* SVGA_3D_CMD_DX_SET_DS_CONSTANT_BUFFER_OFFSET 1224 */
3462static int vmsvga3dCmdDXSetDSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetDSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3463{
3464#ifdef VMSVGA3D_DX
3465 DEBUG_BREAKPOINT_TEST();
3466 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3467 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3468 return vmsvga3dDXSetDSConstantBufferOffset(pThisCC, idDXContext);
3469#else
3470 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3471 return VERR_NOT_SUPPORTED;
3472#endif
3473}
3474
3475
3476/* SVGA_3D_CMD_DX_SET_CS_CONSTANT_BUFFER_OFFSET 1225 */
3477static int vmsvga3dCmdDXSetCSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetCSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3478{
3479#ifdef VMSVGA3D_DX
3480 DEBUG_BREAKPOINT_TEST();
3481 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3482 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3483 return vmsvga3dDXSetCSConstantBufferOffset(pThisCC, idDXContext);
3484#else
3485 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3486 return VERR_NOT_SUPPORTED;
3487#endif
3488}
3489
3490
3491/* SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER 1226 */
3492static int vmsvga3dCmdDXCondBindAllShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXCondBindAllShader const *pCmd, uint32_t cbCmd)
3493{
3494#ifdef VMSVGA3D_DX
3495 DEBUG_BREAKPOINT_TEST();
3496 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3497 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3498 return vmsvga3dDXCondBindAllShader(pThisCC, idDXContext);
3499#else
3500 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3501 return VERR_NOT_SUPPORTED;
3502#endif
3503}
3504
3505
3506/* SVGA_3D_CMD_SCREEN_COPY 1227 */
3507static int vmsvga3dCmdScreenCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdScreenCopy const *pCmd, uint32_t cbCmd)
3508{
3509#ifdef VMSVGA3D_DX
3510 DEBUG_BREAKPOINT_TEST();
3511 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3512 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3513 return vmsvga3dScreenCopy(pThisCC, idDXContext);
3514#else
3515 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3516 return VERR_NOT_SUPPORTED;
3517#endif
3518}
3519
3520
3521/* SVGA_3D_CMD_GROW_OTABLE 1236 */
3522static int vmsvga3dCmdGrowOTable(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdGrowOTable const *pCmd, uint32_t cbCmd)
3523{
3524#ifdef VMSVGA3D_DX
3525 DEBUG_BREAKPOINT_TEST();
3526 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3527 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3528 return vmsvga3dGrowOTable(pThisCC, idDXContext);
3529#else
3530 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3531 return VERR_NOT_SUPPORTED;
3532#endif
3533}
3534
3535
3536/* SVGA_3D_CMD_DX_GROW_COTABLE 1237 */
3537static int vmsvga3dCmdDXGrowCOTable(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXGrowCOTable const *pCmd, uint32_t cbCmd)
3538{
3539#ifdef VMSVGA3D_DX
3540 DEBUG_BREAKPOINT_TEST();
3541 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3542 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3543 return vmsvga3dDXGrowCOTable(pThisCC, idDXContext);
3544#else
3545 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3546 return VERR_NOT_SUPPORTED;
3547#endif
3548}
3549
3550
3551/* SVGA_3D_CMD_INTRA_SURFACE_COPY 1238 */
3552static int vmsvga3dCmdIntraSurfaceCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdIntraSurfaceCopy const *pCmd, uint32_t cbCmd)
3553{
3554#ifdef VMSVGA3D_DX
3555 DEBUG_BREAKPOINT_TEST();
3556 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3557 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3558 return vmsvga3dIntraSurfaceCopy(pThisCC, idDXContext);
3559#else
3560 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3561 return VERR_NOT_SUPPORTED;
3562#endif
3563}
3564
3565
3566/* SVGA_3D_CMD_DEFINE_GB_SURFACE_V3 1239 */
3567static int vmsvga3dCmdDefineGBSurface_v3(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDefineGBSurface_v3 const *pCmd, uint32_t cbCmd)
3568{
3569#ifdef VMSVGA3D_DX
3570 DEBUG_BREAKPOINT_TEST();
3571 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3572 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3573 return vmsvga3dDefineGBSurface_v3(pThisCC, idDXContext);
3574#else
3575 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3576 return VERR_NOT_SUPPORTED;
3577#endif
3578}
3579
3580
3581/* SVGA_3D_CMD_DX_RESOLVE_COPY 1240 */
3582static int vmsvga3dCmdDXResolveCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXResolveCopy const *pCmd, uint32_t cbCmd)
3583{
3584#ifdef VMSVGA3D_DX
3585 DEBUG_BREAKPOINT_TEST();
3586 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3587 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3588 return vmsvga3dDXResolveCopy(pThisCC, idDXContext);
3589#else
3590 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3591 return VERR_NOT_SUPPORTED;
3592#endif
3593}
3594
3595
3596/* SVGA_3D_CMD_DX_PRED_RESOLVE_COPY 1241 */
3597static int vmsvga3dCmdDXPredResolveCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredResolveCopy const *pCmd, uint32_t cbCmd)
3598{
3599#ifdef VMSVGA3D_DX
3600 DEBUG_BREAKPOINT_TEST();
3601 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3602 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3603 return vmsvga3dDXPredResolveCopy(pThisCC, idDXContext);
3604#else
3605 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3606 return VERR_NOT_SUPPORTED;
3607#endif
3608}
3609
3610
3611/* SVGA_3D_CMD_DX_PRED_CONVERT_REGION 1242 */
3612static int vmsvga3dCmdDXPredConvertRegion(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredConvertRegion const *pCmd, uint32_t cbCmd)
3613{
3614#ifdef VMSVGA3D_DX
3615 DEBUG_BREAKPOINT_TEST();
3616 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3617 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3618 return vmsvga3dDXPredConvertRegion(pThisCC, idDXContext);
3619#else
3620 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3621 return VERR_NOT_SUPPORTED;
3622#endif
3623}
3624
3625
3626/* SVGA_3D_CMD_DX_PRED_CONVERT 1243 */
3627static int vmsvga3dCmdDXPredConvert(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredConvert const *pCmd, uint32_t cbCmd)
3628{
3629#ifdef VMSVGA3D_DX
3630 DEBUG_BREAKPOINT_TEST();
3631 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3632 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3633 return vmsvga3dDXPredConvert(pThisCC, idDXContext);
3634#else
3635 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3636 return VERR_NOT_SUPPORTED;
3637#endif
3638}
3639
3640
3641/* SVGA_3D_CMD_WHOLE_SURFACE_COPY 1244 */
3642static int vmsvga3dCmdWholeSurfaceCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdWholeSurfaceCopy const *pCmd, uint32_t cbCmd)
3643{
3644#ifdef VMSVGA3D_DX
3645 DEBUG_BREAKPOINT_TEST();
3646 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3647 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3648 return vmsvga3dWholeSurfaceCopy(pThisCC, idDXContext);
3649#else
3650 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3651 return VERR_NOT_SUPPORTED;
3652#endif
3653}
3654
3655
3656/* SVGA_3D_CMD_DX_DEFINE_UA_VIEW 1245 */
3657static int vmsvga3dCmdDXDefineUAView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineUAView const *pCmd, uint32_t cbCmd)
3658{
3659#ifdef VMSVGA3D_DX
3660 DEBUG_BREAKPOINT_TEST();
3661 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3662 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3663 return vmsvga3dDXDefineUAView(pThisCC, idDXContext);
3664#else
3665 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3666 return VERR_NOT_SUPPORTED;
3667#endif
3668}
3669
3670
3671/* SVGA_3D_CMD_DX_DESTROY_UA_VIEW 1246 */
3672static int vmsvga3dCmdDXDestroyUAView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyUAView const *pCmd, uint32_t cbCmd)
3673{
3674#ifdef VMSVGA3D_DX
3675 DEBUG_BREAKPOINT_TEST();
3676 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3677 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3678 return vmsvga3dDXDestroyUAView(pThisCC, idDXContext);
3679#else
3680 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3681 return VERR_NOT_SUPPORTED;
3682#endif
3683}
3684
3685
3686/* SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT 1247 */
3687static int vmsvga3dCmdDXClearUAViewUint(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearUAViewUint const *pCmd, uint32_t cbCmd)
3688{
3689#ifdef VMSVGA3D_DX
3690 DEBUG_BREAKPOINT_TEST();
3691 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3692 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3693 return vmsvga3dDXClearUAViewUint(pThisCC, idDXContext);
3694#else
3695 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3696 return VERR_NOT_SUPPORTED;
3697#endif
3698}
3699
3700
3701/* SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT 1248 */
3702static int vmsvga3dCmdDXClearUAViewFloat(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearUAViewFloat const *pCmd, uint32_t cbCmd)
3703{
3704#ifdef VMSVGA3D_DX
3705 DEBUG_BREAKPOINT_TEST();
3706 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3707 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3708 return vmsvga3dDXClearUAViewFloat(pThisCC, idDXContext);
3709#else
3710 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3711 return VERR_NOT_SUPPORTED;
3712#endif
3713}
3714
3715
3716/* SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT 1249 */
3717static int vmsvga3dCmdDXCopyStructureCount(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXCopyStructureCount const *pCmd, uint32_t cbCmd)
3718{
3719#ifdef VMSVGA3D_DX
3720 DEBUG_BREAKPOINT_TEST();
3721 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3722 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3723 return vmsvga3dDXCopyStructureCount(pThisCC, idDXContext);
3724#else
3725 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3726 return VERR_NOT_SUPPORTED;
3727#endif
3728}
3729
3730
3731/* SVGA_3D_CMD_DX_SET_UA_VIEWS 1250 */
3732static int vmsvga3dCmdDXSetUAViews(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetUAViews const *pCmd, uint32_t cbCmd)
3733{
3734#ifdef VMSVGA3D_DX
3735 DEBUG_BREAKPOINT_TEST();
3736 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3737 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3738 return vmsvga3dDXSetUAViews(pThisCC, idDXContext);
3739#else
3740 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3741 return VERR_NOT_SUPPORTED;
3742#endif
3743}
3744
3745
3746/* SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT 1251 */
3747static int vmsvga3dCmdDXDrawIndexedInstancedIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawIndexedInstancedIndirect const *pCmd, uint32_t cbCmd)
3748{
3749#ifdef VMSVGA3D_DX
3750 DEBUG_BREAKPOINT_TEST();
3751 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3752 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3753 return vmsvga3dDXDrawIndexedInstancedIndirect(pThisCC, idDXContext);
3754#else
3755 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3756 return VERR_NOT_SUPPORTED;
3757#endif
3758}
3759
3760
3761/* SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT 1252 */
3762static int vmsvga3dCmdDXDrawInstancedIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawInstancedIndirect const *pCmd, uint32_t cbCmd)
3763{
3764#ifdef VMSVGA3D_DX
3765 DEBUG_BREAKPOINT_TEST();
3766 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3767 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3768 return vmsvga3dDXDrawInstancedIndirect(pThisCC, idDXContext);
3769#else
3770 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3771 return VERR_NOT_SUPPORTED;
3772#endif
3773}
3774
3775
3776/* SVGA_3D_CMD_DX_DISPATCH 1253 */
3777static int vmsvga3dCmdDXDispatch(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDispatch const *pCmd, uint32_t cbCmd)
3778{
3779#ifdef VMSVGA3D_DX
3780 DEBUG_BREAKPOINT_TEST();
3781 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3782 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3783 return vmsvga3dDXDispatch(pThisCC, idDXContext);
3784#else
3785 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3786 return VERR_NOT_SUPPORTED;
3787#endif
3788}
3789
3790
3791/* SVGA_3D_CMD_DX_DISPATCH_INDIRECT 1254 */
3792static int vmsvga3dCmdDXDispatchIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDispatchIndirect const *pCmd, uint32_t cbCmd)
3793{
3794#ifdef VMSVGA3D_DX
3795 DEBUG_BREAKPOINT_TEST();
3796 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3797 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3798 return vmsvga3dDXDispatchIndirect(pThisCC, idDXContext);
3799#else
3800 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3801 return VERR_NOT_SUPPORTED;
3802#endif
3803}
3804
3805
3806/* SVGA_3D_CMD_WRITE_ZERO_SURFACE 1255 */
3807static int vmsvga3dCmdWriteZeroSurface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdWriteZeroSurface const *pCmd, uint32_t cbCmd)
3808{
3809#ifdef VMSVGA3D_DX
3810 DEBUG_BREAKPOINT_TEST();
3811 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3812 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3813 return vmsvga3dWriteZeroSurface(pThisCC, idDXContext);
3814#else
3815 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3816 return VERR_NOT_SUPPORTED;
3817#endif
3818}
3819
3820
3821/* SVGA_3D_CMD_HINT_ZERO_SURFACE 1256 */
3822static int vmsvga3dCmdHintZeroSurface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdHintZeroSurface const *pCmd, uint32_t cbCmd)
3823{
3824#ifdef VMSVGA3D_DX
3825 DEBUG_BREAKPOINT_TEST();
3826 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3827 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3828 return vmsvga3dHintZeroSurface(pThisCC, idDXContext);
3829#else
3830 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3831 return VERR_NOT_SUPPORTED;
3832#endif
3833}
3834
3835
3836/* SVGA_3D_CMD_DX_TRANSFER_TO_BUFFER 1257 */
3837static int vmsvga3dCmdDXTransferToBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXTransferToBuffer const *pCmd, uint32_t cbCmd)
3838{
3839#ifdef VMSVGA3D_DX
3840 DEBUG_BREAKPOINT_TEST();
3841 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3842 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3843 return vmsvga3dDXTransferToBuffer(pThisCC, idDXContext);
3844#else
3845 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3846 return VERR_NOT_SUPPORTED;
3847#endif
3848}
3849
3850
3851/* SVGA_3D_CMD_DX_SET_STRUCTURE_COUNT 1258 */
3852static int vmsvga3dCmdDXSetStructureCount(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetStructureCount const *pCmd, uint32_t cbCmd)
3853{
3854#ifdef VMSVGA3D_DX
3855 DEBUG_BREAKPOINT_TEST();
3856 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3857 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3858 return vmsvga3dDXSetStructureCount(pThisCC, idDXContext);
3859#else
3860 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3861 return VERR_NOT_SUPPORTED;
3862#endif
3863}
3864
3865
3866/* SVGA_3D_CMD_LOGICOPS_BITBLT 1259 */
3867static int vmsvga3dCmdLogicOpsBitBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsBitBlt const *pCmd, uint32_t cbCmd)
3868{
3869#ifdef VMSVGA3D_DX
3870 DEBUG_BREAKPOINT_TEST();
3871 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3872 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3873 return vmsvga3dLogicOpsBitBlt(pThisCC, idDXContext);
3874#else
3875 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3876 return VERR_NOT_SUPPORTED;
3877#endif
3878}
3879
3880
3881/* SVGA_3D_CMD_LOGICOPS_TRANSBLT 1260 */
3882static int vmsvga3dCmdLogicOpsTransBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsTransBlt const *pCmd, uint32_t cbCmd)
3883{
3884#ifdef VMSVGA3D_DX
3885 DEBUG_BREAKPOINT_TEST();
3886 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3887 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3888 return vmsvga3dLogicOpsTransBlt(pThisCC, idDXContext);
3889#else
3890 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3891 return VERR_NOT_SUPPORTED;
3892#endif
3893}
3894
3895
3896/* SVGA_3D_CMD_LOGICOPS_STRETCHBLT 1261 */
3897static int vmsvga3dCmdLogicOpsStretchBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsStretchBlt const *pCmd, uint32_t cbCmd)
3898{
3899#ifdef VMSVGA3D_DX
3900 DEBUG_BREAKPOINT_TEST();
3901 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3902 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3903 return vmsvga3dLogicOpsStretchBlt(pThisCC, idDXContext);
3904#else
3905 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3906 return VERR_NOT_SUPPORTED;
3907#endif
3908}
3909
3910
3911/* SVGA_3D_CMD_LOGICOPS_COLORFILL 1262 */
3912static int vmsvga3dCmdLogicOpsColorFill(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsColorFill const *pCmd, uint32_t cbCmd)
3913{
3914#ifdef VMSVGA3D_DX
3915 DEBUG_BREAKPOINT_TEST();
3916 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3917 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3918 return vmsvga3dLogicOpsColorFill(pThisCC, idDXContext);
3919#else
3920 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3921 return VERR_NOT_SUPPORTED;
3922#endif
3923}
3924
3925
3926/* SVGA_3D_CMD_LOGICOPS_ALPHABLEND 1263 */
3927static int vmsvga3dCmdLogicOpsAlphaBlend(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsAlphaBlend const *pCmd, uint32_t cbCmd)
3928{
3929#ifdef VMSVGA3D_DX
3930 DEBUG_BREAKPOINT_TEST();
3931 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3932 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3933 return vmsvga3dLogicOpsAlphaBlend(pThisCC, idDXContext);
3934#else
3935 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3936 return VERR_NOT_SUPPORTED;
3937#endif
3938}
3939
3940
3941/* SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND 1264 */
3942static int vmsvga3dCmdLogicOpsClearTypeBlend(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsClearTypeBlend const *pCmd, uint32_t cbCmd)
3943{
3944#ifdef VMSVGA3D_DX
3945 DEBUG_BREAKPOINT_TEST();
3946 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3947 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3948 return vmsvga3dLogicOpsClearTypeBlend(pThisCC, idDXContext);
3949#else
3950 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3951 return VERR_NOT_SUPPORTED;
3952#endif
3953}
3954
3955
3956/* SVGA_3D_CMD_DEFINE_GB_SURFACE_V4 1267 */
3957static int vmsvga3dCmdDefineGBSurface_v4(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDefineGBSurface_v4 const *pCmd, uint32_t cbCmd)
3958{
3959#ifdef VMSVGA3D_DX
3960 DEBUG_BREAKPOINT_TEST();
3961 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3962 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3963 return vmsvga3dDefineGBSurface_v4(pThisCC, idDXContext);
3964#else
3965 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3966 return VERR_NOT_SUPPORTED;
3967#endif
3968}
3969
3970
3971/* SVGA_3D_CMD_DX_SET_CS_UA_VIEWS 1268 */
3972static int vmsvga3dCmdDXSetCSUAViews(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetCSUAViews const *pCmd, uint32_t cbCmd)
3973{
3974#ifdef VMSVGA3D_DX
3975 DEBUG_BREAKPOINT_TEST();
3976 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3977 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3978 return vmsvga3dDXSetCSUAViews(pThisCC, idDXContext);
3979#else
3980 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3981 return VERR_NOT_SUPPORTED;
3982#endif
3983}
3984
3985
3986/* SVGA_3D_CMD_DX_SET_MIN_LOD 1269 */
3987static int vmsvga3dCmdDXSetMinLOD(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetMinLOD const *pCmd, uint32_t cbCmd)
3988{
3989#ifdef VMSVGA3D_DX
3990 DEBUG_BREAKPOINT_TEST();
3991 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3992 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3993 return vmsvga3dDXSetMinLOD(pThisCC, idDXContext);
3994#else
3995 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3996 return VERR_NOT_SUPPORTED;
3997#endif
3998}
3999
4000
4001/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2 1272 */
4002static int vmsvga3dCmdDXDefineDepthStencilView_v2(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilView_v2 const *pCmd, uint32_t cbCmd)
4003{
4004#ifdef VMSVGA3D_DX
4005 //DEBUG_BREAKPOINT_TEST();
4006 RT_NOREF(cbCmd);
4007 return vmsvga3dDXDefineDepthStencilView(pThisCC, idDXContext, pCmd);
4008#else
4009 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4010 return VERR_NOT_SUPPORTED;
4011#endif
4012}
4013
4014
4015/* SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB 1273 */
4016static int vmsvga3dCmdDXDefineStreamOutputWithMob(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineStreamOutputWithMob const *pCmd, uint32_t cbCmd)
4017{
4018#ifdef VMSVGA3D_DX
4019 DEBUG_BREAKPOINT_TEST();
4020 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4021 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4022 return vmsvga3dDXDefineStreamOutputWithMob(pThisCC, idDXContext);
4023#else
4024 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4025 return VERR_NOT_SUPPORTED;
4026#endif
4027}
4028
4029
4030/* SVGA_3D_CMD_DX_SET_SHADER_IFACE 1274 */
4031static int vmsvga3dCmdDXSetShaderIface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetShaderIface const *pCmd, uint32_t cbCmd)
4032{
4033#ifdef VMSVGA3D_DX
4034 DEBUG_BREAKPOINT_TEST();
4035 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4036 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4037 return vmsvga3dDXSetShaderIface(pThisCC, idDXContext);
4038#else
4039 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4040 return VERR_NOT_SUPPORTED;
4041#endif
4042}
4043
4044
4045/* SVGA_3D_CMD_DX_BIND_STREAMOUTPUT 1275 */
4046static int vmsvga3dCmdDXBindStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindStreamOutput const *pCmd, uint32_t cbCmd)
4047{
4048#ifdef VMSVGA3D_DX
4049 DEBUG_BREAKPOINT_TEST();
4050 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4051 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4052 return vmsvga3dDXBindStreamOutput(pThisCC, idDXContext);
4053#else
4054 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4055 return VERR_NOT_SUPPORTED;
4056#endif
4057}
4058
4059
4060/* SVGA_3D_CMD_SURFACE_STRETCHBLT_NON_MS_TO_MS 1276 */
4061static int vmsvga3dCmdSurfaceStretchBltNonMSToMS(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdSurfaceStretchBltNonMSToMS const *pCmd, uint32_t cbCmd)
4062{
4063#ifdef VMSVGA3D_DX
4064 DEBUG_BREAKPOINT_TEST();
4065 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4066 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4067 return vmsvga3dSurfaceStretchBltNonMSToMS(pThisCC, idDXContext);
4068#else
4069 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4070 return VERR_NOT_SUPPORTED;
4071#endif
4072}
4073
4074
4075/* SVGA_3D_CMD_DX_BIND_SHADER_IFACE 1277 */
4076static int vmsvga3dCmdDXBindShaderIface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindShaderIface const *pCmd, uint32_t cbCmd)
4077{
4078#ifdef VMSVGA3D_DX
4079 DEBUG_BREAKPOINT_TEST();
4080 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4081 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4082 return vmsvga3dDXBindShaderIface(pThisCC, idDXContext);
4083#else
4084 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4085 return VERR_NOT_SUPPORTED;
4086#endif
4087}
4088
4089
4090/** @def VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
4091 * Check that the 3D command has at least a_cbMin of payload bytes after the
4092 * header. Will break out of the switch if it doesn't.
4093 */
4094# define VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(a_cbMin) \
4095 if (1) { \
4096 AssertMsgBreak(cbCmd >= (a_cbMin), ("size=%#x a_cbMin=%#zx\n", cbCmd, (size_t)(a_cbMin))); \
4097 RT_UNTRUSTED_VALIDATED_FENCE(); \
4098 } else do {} while (0)
4099
4100# define VMSVGA_3D_CMD_NOTIMPL() \
4101 if (1) { \
4102 AssertMsgFailed(("Not implemented %d %s\n", enmCmdId, vmsvgaR3FifoCmdToString(enmCmdId))); \
4103 } else do {} while (0)
4104
4105/** SVGA_3D_CMD_* handler.
4106 * This function parses the command and calls the corresponding command handler.
4107 *
4108 * @param pThis The shared VGA/VMSVGA state.
4109 * @param pThisCC The VGA/VMSVGA state for the current context.
4110 * @param idDXContext VGPU10 DX context of the commands or SVGA3D_INVALID_ID if they are not for a specific context.
4111 * @param enmCmdId SVGA_3D_CMD_* command identifier.
4112 * @param cbCmd Size of the command in bytes.
4113 * @param pvCmd Pointer to the command.
4114 * @returns VBox status code if an error was detected parsing a command.
4115 */
4116int vmsvgaR3Process3dCmd(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t idDXContext, SVGAFifo3dCmdId enmCmdId, uint32_t cbCmd, void const *pvCmd)
4117{
4118 if (enmCmdId > SVGA_3D_CMD_MAX)
4119 {
4120 LogRelMax(16, ("VMSVGA: unsupported 3D command %d\n", enmCmdId));
4121 ASSERT_GUEST_FAILED_RETURN(VERR_NOT_IMPLEMENTED);
4122 }
4123
4124 int rcParse = VINF_SUCCESS;
4125 PVMSVGAR3STATE pSvgaR3State = pThisCC->svga.pSvgaR3State;
4126
4127 switch (enmCmdId)
4128 {
4129 case SVGA_3D_CMD_SURFACE_DEFINE:
4130 {
4131 SVGA3dCmdDefineSurface *pCmd = (SVGA3dCmdDefineSurface *)pvCmd;
4132 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4133 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefine);
4134
4135 SVGA3dCmdDefineSurface_v2 cmd;
4136 cmd.sid = pCmd->sid;
4137 cmd.surfaceFlags = pCmd->surfaceFlags;
4138 cmd.format = pCmd->format;
4139 memcpy(cmd.face, pCmd->face, sizeof(cmd.face));
4140 cmd.multisampleCount = 0;
4141 cmd.autogenFilter = SVGA3D_TEX_FILTER_NONE;
4142
4143 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4144 vmsvga3dCmdDefineSurface(pThisCC, &cmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
4145# ifdef DEBUG_GMR_ACCESS
4146 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
4147# endif
4148 break;
4149 }
4150
4151 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
4152 {
4153 SVGA3dCmdDefineSurface_v2 *pCmd = (SVGA3dCmdDefineSurface_v2 *)pvCmd;
4154 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4155 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefineV2);
4156
4157 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4158 vmsvga3dCmdDefineSurface(pThisCC, pCmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
4159# ifdef DEBUG_GMR_ACCESS
4160 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
4161# endif
4162 break;
4163 }
4164
4165 case SVGA_3D_CMD_SURFACE_DESTROY:
4166 {
4167 SVGA3dCmdDestroySurface *pCmd = (SVGA3dCmdDestroySurface *)pvCmd;
4168 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4169 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDestroy);
4170
4171 vmsvga3dSurfaceDestroy(pThisCC, pCmd->sid);
4172 break;
4173 }
4174
4175 case SVGA_3D_CMD_SURFACE_COPY:
4176 {
4177 SVGA3dCmdSurfaceCopy *pCmd = (SVGA3dCmdSurfaceCopy *)pvCmd;
4178 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4179 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceCopy);
4180
4181 uint32_t const cCopyBoxes = (cbCmd - sizeof(pCmd)) / sizeof(SVGA3dCopyBox);
4182 vmsvga3dSurfaceCopy(pThisCC, pCmd->dest, pCmd->src, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4183 break;
4184 }
4185
4186 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
4187 {
4188 SVGA3dCmdSurfaceStretchBlt *pCmd = (SVGA3dCmdSurfaceStretchBlt *)pvCmd;
4189 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4190 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceStretchBlt);
4191
4192 vmsvga3dSurfaceStretchBlt(pThis, pThisCC, &pCmd->dest, &pCmd->boxDest,
4193 &pCmd->src, &pCmd->boxSrc, pCmd->mode);
4194 break;
4195 }
4196
4197 case SVGA_3D_CMD_SURFACE_DMA:
4198 {
4199 SVGA3dCmdSurfaceDMA *pCmd = (SVGA3dCmdSurfaceDMA *)pvCmd;
4200 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4201 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDma);
4202
4203 uint64_t u64NanoTS = 0;
4204 if (LogRelIs3Enabled())
4205 u64NanoTS = RTTimeNanoTS();
4206 uint32_t const cCopyBoxes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyBox);
4207 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
4208 vmsvga3dSurfaceDMA(pThis, pThisCC, pCmd->guest, pCmd->host, pCmd->transfer,
4209 cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4210 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
4211 if (LogRelIs3Enabled())
4212 {
4213 if (cCopyBoxes)
4214 {
4215 SVGA3dCopyBox *pFirstBox = (SVGA3dCopyBox *)(pCmd + 1);
4216 LogRel3(("VMSVGA: SURFACE_DMA: %d us %d boxes %d,%d %dx%d%s\n",
4217 (RTTimeNanoTS() - u64NanoTS) / 1000ULL, cCopyBoxes,
4218 pFirstBox->x, pFirstBox->y, pFirstBox->w, pFirstBox->h,
4219 pCmd->transfer == SVGA3D_READ_HOST_VRAM ? " readback!!!" : ""));
4220 }
4221 }
4222 break;
4223 }
4224
4225 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
4226 {
4227 SVGA3dCmdBlitSurfaceToScreen *pCmd = (SVGA3dCmdBlitSurfaceToScreen *)pvCmd;
4228 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4229 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceScreen);
4230
4231 static uint64_t u64FrameStartNanoTS = 0;
4232 static uint64_t u64ElapsedPerSecNano = 0;
4233 static int cFrames = 0;
4234 uint64_t u64NanoTS = 0;
4235 if (LogRelIs3Enabled())
4236 u64NanoTS = RTTimeNanoTS();
4237 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGASignedRect);
4238 STAM_REL_PROFILE_START(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
4239 vmsvga3dSurfaceBlitToScreen(pThis, pThisCC, pCmd->destScreenId, pCmd->destRect, pCmd->srcImage,
4240 pCmd->srcRect, cRects, (SVGASignedRect *)(pCmd + 1));
4241 STAM_REL_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
4242 if (LogRelIs3Enabled())
4243 {
4244 uint64_t u64ElapsedNano = RTTimeNanoTS() - u64NanoTS;
4245 u64ElapsedPerSecNano += u64ElapsedNano;
4246
4247 SVGASignedRect *pFirstRect = cRects ? (SVGASignedRect *)(pCmd + 1) : &pCmd->destRect;
4248 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: %d us %d rects %d,%d %dx%d\n",
4249 (u64ElapsedNano) / 1000ULL, cRects,
4250 pFirstRect->left, pFirstRect->top,
4251 pFirstRect->right - pFirstRect->left, pFirstRect->bottom - pFirstRect->top));
4252
4253 ++cFrames;
4254 if (u64NanoTS - u64FrameStartNanoTS >= UINT64_C(1000000000))
4255 {
4256 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: FPS %d, elapsed %llu us\n",
4257 cFrames, u64ElapsedPerSecNano / 1000ULL));
4258 u64FrameStartNanoTS = u64NanoTS;
4259 cFrames = 0;
4260 u64ElapsedPerSecNano = 0;
4261 }
4262 }
4263 break;
4264 }
4265
4266 case SVGA_3D_CMD_CONTEXT_DEFINE:
4267 {
4268 SVGA3dCmdDefineContext *pCmd = (SVGA3dCmdDefineContext *)pvCmd;
4269 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4270 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDefine);
4271
4272 vmsvga3dContextDefine(pThisCC, pCmd->cid);
4273 break;
4274 }
4275
4276 case SVGA_3D_CMD_CONTEXT_DESTROY:
4277 {
4278 SVGA3dCmdDestroyContext *pCmd = (SVGA3dCmdDestroyContext *)pvCmd;
4279 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4280 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDestroy);
4281
4282 vmsvga3dContextDestroy(pThisCC, pCmd->cid);
4283 break;
4284 }
4285
4286 case SVGA_3D_CMD_SETTRANSFORM:
4287 {
4288 SVGA3dCmdSetTransform *pCmd = (SVGA3dCmdSetTransform *)pvCmd;
4289 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4290 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTransform);
4291
4292 vmsvga3dSetTransform(pThisCC, pCmd->cid, pCmd->type, pCmd->matrix);
4293 break;
4294 }
4295
4296 case SVGA_3D_CMD_SETZRANGE:
4297 {
4298 SVGA3dCmdSetZRange *pCmd = (SVGA3dCmdSetZRange *)pvCmd;
4299 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4300 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetZRange);
4301
4302 vmsvga3dSetZRange(pThisCC, pCmd->cid, pCmd->zRange);
4303 break;
4304 }
4305
4306 case SVGA_3D_CMD_SETRENDERSTATE:
4307 {
4308 SVGA3dCmdSetRenderState *pCmd = (SVGA3dCmdSetRenderState *)pvCmd;
4309 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4310 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderState);
4311
4312 uint32_t const cRenderStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRenderState);
4313 vmsvga3dSetRenderState(pThisCC, pCmd->cid, cRenderStates, (SVGA3dRenderState *)(pCmd + 1));
4314 break;
4315 }
4316
4317 case SVGA_3D_CMD_SETRENDERTARGET:
4318 {
4319 SVGA3dCmdSetRenderTarget *pCmd = (SVGA3dCmdSetRenderTarget *)pvCmd;
4320 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4321 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderTarget);
4322
4323 vmsvga3dSetRenderTarget(pThisCC, pCmd->cid, pCmd->type, pCmd->target);
4324 break;
4325 }
4326
4327 case SVGA_3D_CMD_SETTEXTURESTATE:
4328 {
4329 SVGA3dCmdSetTextureState *pCmd = (SVGA3dCmdSetTextureState *)pvCmd;
4330 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4331 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTextureState);
4332
4333 uint32_t const cTextureStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dTextureState);
4334 vmsvga3dSetTextureState(pThisCC, pCmd->cid, cTextureStates, (SVGA3dTextureState *)(pCmd + 1));
4335 break;
4336 }
4337
4338 case SVGA_3D_CMD_SETMATERIAL:
4339 {
4340 SVGA3dCmdSetMaterial *pCmd = (SVGA3dCmdSetMaterial *)pvCmd;
4341 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4342 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetMaterial);
4343
4344 vmsvga3dSetMaterial(pThisCC, pCmd->cid, pCmd->face, &pCmd->material);
4345 break;
4346 }
4347
4348 case SVGA_3D_CMD_SETLIGHTDATA:
4349 {
4350 SVGA3dCmdSetLightData *pCmd = (SVGA3dCmdSetLightData *)pvCmd;
4351 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4352 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightData);
4353
4354 vmsvga3dSetLightData(pThisCC, pCmd->cid, pCmd->index, &pCmd->data);
4355 break;
4356 }
4357
4358 case SVGA_3D_CMD_SETLIGHTENABLED:
4359 {
4360 SVGA3dCmdSetLightEnabled *pCmd = (SVGA3dCmdSetLightEnabled *)pvCmd;
4361 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4362 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightEnable);
4363
4364 vmsvga3dSetLightEnabled(pThisCC, pCmd->cid, pCmd->index, pCmd->enabled);
4365 break;
4366 }
4367
4368 case SVGA_3D_CMD_SETVIEWPORT:
4369 {
4370 SVGA3dCmdSetViewport *pCmd = (SVGA3dCmdSetViewport *)pvCmd;
4371 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4372 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetViewPort);
4373
4374 vmsvga3dSetViewPort(pThisCC, pCmd->cid, &pCmd->rect);
4375 break;
4376 }
4377
4378 case SVGA_3D_CMD_SETCLIPPLANE:
4379 {
4380 SVGA3dCmdSetClipPlane *pCmd = (SVGA3dCmdSetClipPlane *)pvCmd;
4381 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4382 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetClipPlane);
4383
4384 vmsvga3dSetClipPlane(pThisCC, pCmd->cid, pCmd->index, pCmd->plane);
4385 break;
4386 }
4387
4388 case SVGA_3D_CMD_CLEAR:
4389 {
4390 SVGA3dCmdClear *pCmd = (SVGA3dCmdClear *)pvCmd;
4391 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4392 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dClear);
4393
4394 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRect);
4395 vmsvga3dCommandClear(pThisCC, pCmd->cid, pCmd->clearFlag, pCmd->color, pCmd->depth, pCmd->stencil, cRects, (SVGA3dRect *)(pCmd + 1));
4396 break;
4397 }
4398
4399 case SVGA_3D_CMD_PRESENT:
4400 case SVGA_3D_CMD_PRESENT_READBACK: /** @todo SVGA_3D_CMD_PRESENT_READBACK isn't quite the same as present... */
4401 {
4402 SVGA3dCmdPresent *pCmd = (SVGA3dCmdPresent *)pvCmd;
4403 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4404 if (enmCmdId == SVGA_3D_CMD_PRESENT)
4405 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresent);
4406 else
4407 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresentReadBack);
4408
4409 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyRect);
4410 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
4411 vmsvga3dCommandPresent(pThis, pThisCC, pCmd->sid, cRects, (SVGA3dCopyRect *)(pCmd + 1));
4412 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
4413 break;
4414 }
4415
4416 case SVGA_3D_CMD_SHADER_DEFINE:
4417 {
4418 SVGA3dCmdDefineShader *pCmd = (SVGA3dCmdDefineShader *)pvCmd;
4419 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4420 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDefine);
4421
4422 uint32_t const cbData = (cbCmd - sizeof(*pCmd));
4423 vmsvga3dShaderDefine(pThisCC, pCmd->cid, pCmd->shid, pCmd->type, cbData, (uint32_t *)(pCmd + 1));
4424 break;
4425 }
4426
4427 case SVGA_3D_CMD_SHADER_DESTROY:
4428 {
4429 SVGA3dCmdDestroyShader *pCmd = (SVGA3dCmdDestroyShader *)pvCmd;
4430 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4431 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDestroy);
4432
4433 vmsvga3dShaderDestroy(pThisCC, pCmd->cid, pCmd->shid, pCmd->type);
4434 break;
4435 }
4436
4437 case SVGA_3D_CMD_SET_SHADER:
4438 {
4439 SVGA3dCmdSetShader *pCmd = (SVGA3dCmdSetShader *)pvCmd;
4440 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4441 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShader);
4442
4443 vmsvga3dShaderSet(pThisCC, NULL, pCmd->cid, pCmd->type, pCmd->shid);
4444 break;
4445 }
4446
4447 case SVGA_3D_CMD_SET_SHADER_CONST:
4448 {
4449 SVGA3dCmdSetShaderConst *pCmd = (SVGA3dCmdSetShaderConst *)pvCmd;
4450 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4451 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShaderConst);
4452
4453 uint32_t const cRegisters = (cbCmd - sizeof(*pCmd)) / sizeof(pCmd->values) + 1;
4454 vmsvga3dShaderSetConst(pThisCC, pCmd->cid, pCmd->reg, pCmd->type, pCmd->ctype, cRegisters, pCmd->values);
4455 break;
4456 }
4457
4458 case SVGA_3D_CMD_DRAW_PRIMITIVES:
4459 {
4460 SVGA3dCmdDrawPrimitives *pCmd = (SVGA3dCmdDrawPrimitives *)pvCmd;
4461 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4462 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDrawPrimitives);
4463
4464 ASSERT_GUEST_STMT_BREAK(pCmd->numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES, rcParse = VERR_INVALID_PARAMETER);
4465 ASSERT_GUEST_STMT_BREAK(pCmd->numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, rcParse = VERR_INVALID_PARAMETER);
4466 uint32_t const cbRangesAndVertexDecls = pCmd->numVertexDecls * sizeof(SVGA3dVertexDecl)
4467 + pCmd->numRanges * sizeof(SVGA3dPrimitiveRange);
4468 ASSERT_GUEST_STMT_BREAK(cbRangesAndVertexDecls <= cbCmd - sizeof(*pCmd), rcParse = VERR_INVALID_PARAMETER);
4469
4470 uint32_t const cVertexDivisor = (cbCmd - sizeof(*pCmd) - cbRangesAndVertexDecls) / sizeof(uint32_t);
4471 ASSERT_GUEST_STMT_BREAK(!cVertexDivisor || cVertexDivisor == pCmd->numVertexDecls, rcParse = VERR_INVALID_PARAMETER);
4472 RT_UNTRUSTED_VALIDATED_FENCE();
4473
4474 SVGA3dVertexDecl *pVertexDecl = (SVGA3dVertexDecl *)(pCmd + 1);
4475 SVGA3dPrimitiveRange *pNumRange = (SVGA3dPrimitiveRange *)&pVertexDecl[pCmd->numVertexDecls];
4476 SVGA3dVertexDivisor *pVertexDivisor = cVertexDivisor ? (SVGA3dVertexDivisor *)&pNumRange[pCmd->numRanges] : NULL;
4477
4478 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
4479 vmsvga3dDrawPrimitives(pThisCC, pCmd->cid, pCmd->numVertexDecls, pVertexDecl, pCmd->numRanges,
4480 pNumRange, cVertexDivisor, pVertexDivisor);
4481 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
4482 break;
4483 }
4484
4485 case SVGA_3D_CMD_SETSCISSORRECT:
4486 {
4487 SVGA3dCmdSetScissorRect *pCmd = (SVGA3dCmdSetScissorRect *)pvCmd;
4488 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4489 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetScissorRect);
4490
4491 vmsvga3dSetScissorRect(pThisCC, pCmd->cid, &pCmd->rect);
4492 break;
4493 }
4494
4495 case SVGA_3D_CMD_BEGIN_QUERY:
4496 {
4497 SVGA3dCmdBeginQuery *pCmd = (SVGA3dCmdBeginQuery *)pvCmd;
4498 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4499 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dBeginQuery);
4500
4501 vmsvga3dQueryBegin(pThisCC, pCmd->cid, pCmd->type);
4502 break;
4503 }
4504
4505 case SVGA_3D_CMD_END_QUERY:
4506 {
4507 SVGA3dCmdEndQuery *pCmd = (SVGA3dCmdEndQuery *)pvCmd;
4508 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4509 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dEndQuery);
4510
4511 vmsvga3dQueryEnd(pThisCC, pCmd->cid, pCmd->type);
4512 break;
4513 }
4514
4515 case SVGA_3D_CMD_WAIT_FOR_QUERY:
4516 {
4517 SVGA3dCmdWaitForQuery *pCmd = (SVGA3dCmdWaitForQuery *)pvCmd;
4518 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4519 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dWaitForQuery);
4520
4521 vmsvga3dQueryWait(pThisCC, pCmd->cid, pCmd->type, pThis, &pCmd->guestResult);
4522 break;
4523 }
4524
4525 case SVGA_3D_CMD_GENERATE_MIPMAPS:
4526 {
4527 SVGA3dCmdGenerateMipmaps *pCmd = (SVGA3dCmdGenerateMipmaps *)pvCmd;
4528 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4529 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dGenerateMipmaps);
4530
4531 vmsvga3dGenerateMipmaps(pThisCC, pCmd->sid, pCmd->filter);
4532 break;
4533 }
4534
4535 case SVGA_3D_CMD_ACTIVATE_SURFACE:
4536 /* context id + surface id? */
4537 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dActivateSurface);
4538 break;
4539
4540 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
4541 /* context id + surface id? */
4542 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDeactivateSurface);
4543 break;
4544
4545 /*
4546 *
4547 * VPGU10: SVGA_CAP_GBOBJECTS+ commands.
4548 *
4549 */
4550 case SVGA_3D_CMD_SCREEN_DMA:
4551 {
4552 SVGA3dCmdScreenDMA *pCmd = (SVGA3dCmdScreenDMA *)pvCmd;
4553 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4554 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4555 break;
4556 }
4557
4558 case SVGA_3D_CMD_DEAD1:
4559 case SVGA_3D_CMD_DEAD2:
4560 case SVGA_3D_CMD_DEAD12: /* Old SVGA_3D_CMD_LOGICOPS_BITBLT */
4561 case SVGA_3D_CMD_DEAD13: /* Old SVGA_3D_CMD_LOGICOPS_TRANSBLT */
4562 case SVGA_3D_CMD_DEAD14: /* Old SVGA_3D_CMD_LOGICOPS_STRETCHBLT */
4563 case SVGA_3D_CMD_DEAD15: /* Old SVGA_3D_CMD_LOGICOPS_COLORFILL */
4564 case SVGA_3D_CMD_DEAD16: /* Old SVGA_3D_CMD_LOGICOPS_ALPHABLEND */
4565 case SVGA_3D_CMD_DEAD17: /* Old SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND */
4566 {
4567 VMSVGA_3D_CMD_NOTIMPL();
4568 break;
4569 }
4570
4571 case SVGA_3D_CMD_SET_OTABLE_BASE:
4572 {
4573 SVGA3dCmdSetOTableBase *pCmd = (SVGA3dCmdSetOTableBase *)pvCmd;
4574 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4575 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4576 break;
4577 }
4578
4579 case SVGA_3D_CMD_READBACK_OTABLE:
4580 {
4581 SVGA3dCmdReadbackOTable *pCmd = (SVGA3dCmdReadbackOTable *)pvCmd;
4582 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4583 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4584 break;
4585 }
4586
4587 case SVGA_3D_CMD_DEFINE_GB_MOB:
4588 {
4589 SVGA3dCmdDefineGBMob *pCmd = (SVGA3dCmdDefineGBMob *)pvCmd;
4590 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4591 vmsvga3dCmdDefineGBMob(pThisCC, pCmd);
4592 break;
4593 }
4594
4595 case SVGA_3D_CMD_DESTROY_GB_MOB:
4596 {
4597 SVGA3dCmdDestroyGBMob *pCmd = (SVGA3dCmdDestroyGBMob *)pvCmd;
4598 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4599 vmsvga3dCmdDestroyGBMob(pThisCC, pCmd);
4600 break;
4601 }
4602
4603 case SVGA_3D_CMD_DEAD3:
4604 {
4605 VMSVGA_3D_CMD_NOTIMPL();
4606 break;
4607 }
4608
4609 case SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING:
4610 {
4611 SVGA3dCmdUpdateGBMobMapping *pCmd = (SVGA3dCmdUpdateGBMobMapping *)pvCmd;
4612 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4613 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4614 break;
4615 }
4616
4617 case SVGA_3D_CMD_DEFINE_GB_SURFACE:
4618 {
4619 SVGA3dCmdDefineGBSurface *pCmd = (SVGA3dCmdDefineGBSurface *)pvCmd;
4620 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4621 vmsvga3dCmdDefineGBSurface(pThisCC, pCmd);
4622 break;
4623 }
4624
4625 case SVGA_3D_CMD_DESTROY_GB_SURFACE:
4626 {
4627 SVGA3dCmdDestroyGBSurface *pCmd = (SVGA3dCmdDestroyGBSurface *)pvCmd;
4628 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4629 vmsvga3dCmdDestroyGBSurface(pThisCC, pCmd);
4630 break;
4631 }
4632
4633 case SVGA_3D_CMD_BIND_GB_SURFACE:
4634 {
4635 SVGA3dCmdBindGBSurface *pCmd = (SVGA3dCmdBindGBSurface *)pvCmd;
4636 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4637 vmsvga3dCmdBindGBSurface(pThisCC, pCmd);
4638 break;
4639 }
4640
4641 case SVGA_3D_CMD_COND_BIND_GB_SURFACE:
4642 {
4643 SVGA3dCmdCondBindGBSurface *pCmd = (SVGA3dCmdCondBindGBSurface *)pvCmd;
4644 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4645 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4646 break;
4647 }
4648
4649 case SVGA_3D_CMD_UPDATE_GB_IMAGE:
4650 {
4651 SVGA3dCmdUpdateGBImage *pCmd = (SVGA3dCmdUpdateGBImage *)pvCmd;
4652 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4653 vmsvga3dCmdUpdateGBImage(pThisCC, pCmd);
4654 break;
4655 }
4656
4657 case SVGA_3D_CMD_UPDATE_GB_SURFACE:
4658 {
4659 SVGA3dCmdUpdateGBSurface *pCmd = (SVGA3dCmdUpdateGBSurface *)pvCmd;
4660 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4661 vmsvga3dCmdUpdateGBSurface(pThisCC, pCmd);
4662 break;
4663 }
4664
4665 case SVGA_3D_CMD_READBACK_GB_IMAGE:
4666 {
4667 SVGA3dCmdReadbackGBImage *pCmd = (SVGA3dCmdReadbackGBImage *)pvCmd;
4668 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4669 vmsvga3dCmdReadbackGBImage(pThisCC, pCmd);
4670 break;
4671 }
4672
4673 case SVGA_3D_CMD_READBACK_GB_SURFACE:
4674 {
4675 SVGA3dCmdReadbackGBSurface *pCmd = (SVGA3dCmdReadbackGBSurface *)pvCmd;
4676 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4677 vmsvga3dCmdReadbackGBSurface(pThisCC, pCmd);
4678 break;
4679 }
4680
4681 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE:
4682 {
4683 SVGA3dCmdInvalidateGBImage *pCmd = (SVGA3dCmdInvalidateGBImage *)pvCmd;
4684 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4685 vmsvga3dCmdInvalidateGBImage(pThisCC, pCmd);
4686 break;
4687 }
4688
4689 case SVGA_3D_CMD_INVALIDATE_GB_SURFACE:
4690 {
4691 SVGA3dCmdInvalidateGBSurface *pCmd = (SVGA3dCmdInvalidateGBSurface *)pvCmd;
4692 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4693 vmsvga3dCmdInvalidateGBSurface(pThisCC, pCmd);
4694 break;
4695 }
4696
4697 case SVGA_3D_CMD_DEFINE_GB_CONTEXT:
4698 {
4699 SVGA3dCmdDefineGBContext *pCmd = (SVGA3dCmdDefineGBContext *)pvCmd;
4700 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4701 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4702 break;
4703 }
4704
4705 case SVGA_3D_CMD_DESTROY_GB_CONTEXT:
4706 {
4707 SVGA3dCmdDestroyGBContext *pCmd = (SVGA3dCmdDestroyGBContext *)pvCmd;
4708 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4709 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4710 break;
4711 }
4712
4713 case SVGA_3D_CMD_BIND_GB_CONTEXT:
4714 {
4715 SVGA3dCmdBindGBContext *pCmd = (SVGA3dCmdBindGBContext *)pvCmd;
4716 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4717 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4718 break;
4719 }
4720
4721 case SVGA_3D_CMD_READBACK_GB_CONTEXT:
4722 {
4723 SVGA3dCmdReadbackGBContext *pCmd = (SVGA3dCmdReadbackGBContext *)pvCmd;
4724 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4725 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4726 break;
4727 }
4728
4729 case SVGA_3D_CMD_INVALIDATE_GB_CONTEXT:
4730 {
4731 SVGA3dCmdInvalidateGBContext *pCmd = (SVGA3dCmdInvalidateGBContext *)pvCmd;
4732 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4733 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4734 break;
4735 }
4736
4737 case SVGA_3D_CMD_DEFINE_GB_SHADER:
4738 {
4739 SVGA3dCmdDefineGBShader *pCmd = (SVGA3dCmdDefineGBShader *)pvCmd;
4740 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4741 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4742 break;
4743 }
4744
4745 case SVGA_3D_CMD_DESTROY_GB_SHADER:
4746 {
4747 SVGA3dCmdDestroyGBShader *pCmd = (SVGA3dCmdDestroyGBShader *)pvCmd;
4748 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4749 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4750 break;
4751 }
4752
4753 case SVGA_3D_CMD_BIND_GB_SHADER:
4754 {
4755 SVGA3dCmdBindGBShader *pCmd = (SVGA3dCmdBindGBShader *)pvCmd;
4756 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4757 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4758 break;
4759 }
4760
4761 case SVGA_3D_CMD_SET_OTABLE_BASE64:
4762 {
4763 SVGA3dCmdSetOTableBase64 *pCmd = (SVGA3dCmdSetOTableBase64 *)pvCmd;
4764 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4765 vmsvga3dCmdSetOTableBase64(pThisCC, pCmd);
4766 break;
4767 }
4768
4769 case SVGA_3D_CMD_BEGIN_GB_QUERY:
4770 {
4771 SVGA3dCmdBeginGBQuery *pCmd = (SVGA3dCmdBeginGBQuery *)pvCmd;
4772 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4773 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4774 break;
4775 }
4776
4777 case SVGA_3D_CMD_END_GB_QUERY:
4778 {
4779 SVGA3dCmdEndGBQuery *pCmd = (SVGA3dCmdEndGBQuery *)pvCmd;
4780 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4781 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4782 break;
4783 }
4784
4785 case SVGA_3D_CMD_WAIT_FOR_GB_QUERY:
4786 {
4787 SVGA3dCmdWaitForGBQuery *pCmd = (SVGA3dCmdWaitForGBQuery *)pvCmd;
4788 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4789 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4790 break;
4791 }
4792
4793 case SVGA_3D_CMD_NOP:
4794 {
4795 /* Apparently there is nothing to do. */
4796 break;
4797 }
4798
4799 case SVGA_3D_CMD_ENABLE_GART:
4800 {
4801 SVGA3dCmdEnableGart *pCmd = (SVGA3dCmdEnableGart *)pvCmd;
4802 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4803 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4804 break;
4805 }
4806
4807 case SVGA_3D_CMD_DISABLE_GART:
4808 {
4809 /* No corresponding SVGA3dCmd structure. */
4810 VMSVGA_3D_CMD_NOTIMPL();
4811 break;
4812 }
4813
4814 case SVGA_3D_CMD_MAP_MOB_INTO_GART:
4815 {
4816 SVGA3dCmdMapMobIntoGart *pCmd = (SVGA3dCmdMapMobIntoGart *)pvCmd;
4817 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4818 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4819 break;
4820 }
4821
4822 case SVGA_3D_CMD_UNMAP_GART_RANGE:
4823 {
4824 SVGA3dCmdUnmapGartRange *pCmd = (SVGA3dCmdUnmapGartRange *)pvCmd;
4825 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4826 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4827 break;
4828 }
4829
4830 case SVGA_3D_CMD_DEFINE_GB_SCREENTARGET:
4831 {
4832 SVGA3dCmdDefineGBScreenTarget *pCmd = (SVGA3dCmdDefineGBScreenTarget *)pvCmd;
4833 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4834 vmsvga3dCmdDefineGBScreenTarget(pThis, pThisCC, pCmd);
4835 break;
4836 }
4837
4838 case SVGA_3D_CMD_DESTROY_GB_SCREENTARGET:
4839 {
4840 SVGA3dCmdDestroyGBScreenTarget *pCmd = (SVGA3dCmdDestroyGBScreenTarget *)pvCmd;
4841 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4842 vmsvga3dCmdDestroyGBScreenTarget(pThis, pThisCC, pCmd);
4843 break;
4844 }
4845
4846 case SVGA_3D_CMD_BIND_GB_SCREENTARGET:
4847 {
4848 SVGA3dCmdBindGBScreenTarget *pCmd = (SVGA3dCmdBindGBScreenTarget *)pvCmd;
4849 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4850 vmsvga3dCmdBindGBScreenTarget(pThisCC, pCmd);
4851 break;
4852 }
4853
4854 case SVGA_3D_CMD_UPDATE_GB_SCREENTARGET:
4855 {
4856 SVGA3dCmdUpdateGBScreenTarget *pCmd = (SVGA3dCmdUpdateGBScreenTarget *)pvCmd;
4857 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4858 vmsvga3dCmdUpdateGBScreenTarget(pThisCC, pCmd);
4859 break;
4860 }
4861
4862 case SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL:
4863 {
4864 SVGA3dCmdReadbackGBImagePartial *pCmd = (SVGA3dCmdReadbackGBImagePartial *)pvCmd;
4865 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4866 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4867 break;
4868 }
4869
4870 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL:
4871 {
4872 SVGA3dCmdInvalidateGBImagePartial *pCmd = (SVGA3dCmdInvalidateGBImagePartial *)pvCmd;
4873 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4874 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4875 break;
4876 }
4877
4878 case SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE:
4879 {
4880 SVGA3dCmdSetGBShaderConstInline *pCmd = (SVGA3dCmdSetGBShaderConstInline *)pvCmd;
4881 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4882 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4883 break;
4884 }
4885
4886 case SVGA_3D_CMD_GB_SCREEN_DMA:
4887 {
4888 SVGA3dCmdGBScreenDMA *pCmd = (SVGA3dCmdGBScreenDMA *)pvCmd;
4889 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4890 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4891 break;
4892 }
4893
4894 case SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH:
4895 {
4896 SVGA3dCmdBindGBSurfaceWithPitch *pCmd = (SVGA3dCmdBindGBSurfaceWithPitch *)pvCmd;
4897 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4898 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4899 break;
4900 }
4901
4902 case SVGA_3D_CMD_GB_MOB_FENCE:
4903 {
4904 SVGA3dCmdGBMobFence *pCmd = (SVGA3dCmdGBMobFence *)pvCmd;
4905 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4906 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4907 break;
4908 }
4909
4910 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V2:
4911 {
4912 SVGA3dCmdDefineGBSurface_v2 *pCmd = (SVGA3dCmdDefineGBSurface_v2 *)pvCmd;
4913 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4914 vmsvga3dCmdDefineGBSurface_v2(pThisCC, pCmd);
4915 break;
4916 }
4917
4918 case SVGA_3D_CMD_DEFINE_GB_MOB64:
4919 {
4920 SVGA3dCmdDefineGBMob64 *pCmd = (SVGA3dCmdDefineGBMob64 *)pvCmd;
4921 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4922 vmsvga3dCmdDefineGBMob64(pThisCC, pCmd);
4923 break;
4924 }
4925
4926 case SVGA_3D_CMD_REDEFINE_GB_MOB64:
4927 {
4928 SVGA3dCmdRedefineGBMob64 *pCmd = (SVGA3dCmdRedefineGBMob64 *)pvCmd;
4929 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4930 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4931 break;
4932 }
4933
4934 case SVGA_3D_CMD_NOP_ERROR:
4935 {
4936 /* Apparently there is nothing to do. */
4937 break;
4938 }
4939
4940 case SVGA_3D_CMD_SET_VERTEX_STREAMS:
4941 {
4942 SVGA3dCmdSetVertexStreams *pCmd = (SVGA3dCmdSetVertexStreams *)pvCmd;
4943 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4944 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4945 break;
4946 }
4947
4948 case SVGA_3D_CMD_SET_VERTEX_DECLS:
4949 {
4950 SVGA3dCmdSetVertexDecls *pCmd = (SVGA3dCmdSetVertexDecls *)pvCmd;
4951 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4952 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4953 break;
4954 }
4955
4956 case SVGA_3D_CMD_SET_VERTEX_DIVISORS:
4957 {
4958 SVGA3dCmdSetVertexDivisors *pCmd = (SVGA3dCmdSetVertexDivisors *)pvCmd;
4959 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4960 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4961 break;
4962 }
4963
4964 case SVGA_3D_CMD_DRAW:
4965 {
4966 /* No corresponding SVGA3dCmd structure. */
4967 VMSVGA_3D_CMD_NOTIMPL();
4968 break;
4969 }
4970
4971 case SVGA_3D_CMD_DRAW_INDEXED:
4972 {
4973 /* No corresponding SVGA3dCmd structure. */
4974 VMSVGA_3D_CMD_NOTIMPL();
4975 break;
4976 }
4977
4978 case SVGA_3D_CMD_DX_DEFINE_CONTEXT:
4979 {
4980 SVGA3dCmdDXDefineContext *pCmd = (SVGA3dCmdDXDefineContext *)pvCmd;
4981 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4982 rcParse = vmsvga3dCmdDXDefineContext(pThisCC, pCmd, cbCmd);
4983 break;
4984 }
4985
4986 case SVGA_3D_CMD_DX_DESTROY_CONTEXT:
4987 {
4988 SVGA3dCmdDXDestroyContext *pCmd = (SVGA3dCmdDXDestroyContext *)pvCmd;
4989 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4990 rcParse = vmsvga3dCmdDXDestroyContext(pThisCC, pCmd, cbCmd);
4991 break;
4992 }
4993
4994 case SVGA_3D_CMD_DX_BIND_CONTEXT:
4995 {
4996 SVGA3dCmdDXBindContext *pCmd = (SVGA3dCmdDXBindContext *)pvCmd;
4997 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4998 rcParse = vmsvga3dCmdDXBindContext(pThisCC, pCmd, cbCmd);
4999 break;
5000 }
5001
5002 case SVGA_3D_CMD_DX_READBACK_CONTEXT:
5003 {
5004 SVGA3dCmdDXReadbackContext *pCmd = (SVGA3dCmdDXReadbackContext *)pvCmd;
5005 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5006 rcParse = vmsvga3dCmdDXReadbackContext(pThisCC, pCmd, cbCmd);
5007 break;
5008 }
5009
5010 case SVGA_3D_CMD_DX_INVALIDATE_CONTEXT:
5011 {
5012 SVGA3dCmdDXInvalidateContext *pCmd = (SVGA3dCmdDXInvalidateContext *)pvCmd;
5013 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5014 rcParse = vmsvga3dCmdDXInvalidateContext(pThisCC, idDXContext, pCmd, cbCmd);
5015 break;
5016 }
5017
5018 case SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER:
5019 {
5020 SVGA3dCmdDXSetSingleConstantBuffer *pCmd = (SVGA3dCmdDXSetSingleConstantBuffer *)pvCmd;
5021 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5022 rcParse = vmsvga3dCmdDXSetSingleConstantBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5023 break;
5024 }
5025
5026 case SVGA_3D_CMD_DX_SET_SHADER_RESOURCES:
5027 {
5028 SVGA3dCmdDXSetShaderResources *pCmd = (SVGA3dCmdDXSetShaderResources *)pvCmd;
5029 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5030 rcParse = vmsvga3dCmdDXSetShaderResources(pThisCC, idDXContext, pCmd, cbCmd);
5031 break;
5032 }
5033
5034 case SVGA_3D_CMD_DX_SET_SHADER:
5035 {
5036 SVGA3dCmdDXSetShader *pCmd = (SVGA3dCmdDXSetShader *)pvCmd;
5037 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5038 rcParse = vmsvga3dCmdDXSetShader(pThisCC, idDXContext, pCmd, cbCmd);
5039 break;
5040 }
5041
5042 case SVGA_3D_CMD_DX_SET_SAMPLERS:
5043 {
5044 SVGA3dCmdDXSetSamplers *pCmd = (SVGA3dCmdDXSetSamplers *)pvCmd;
5045 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5046 rcParse = vmsvga3dCmdDXSetSamplers(pThisCC, idDXContext, pCmd, cbCmd);
5047 break;
5048 }
5049
5050 case SVGA_3D_CMD_DX_DRAW:
5051 {
5052 SVGA3dCmdDXDraw *pCmd = (SVGA3dCmdDXDraw *)pvCmd;
5053 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5054 rcParse = vmsvga3dCmdDXDraw(pThisCC, idDXContext, pCmd, cbCmd);
5055 break;
5056 }
5057
5058 case SVGA_3D_CMD_DX_DRAW_INDEXED:
5059 {
5060 SVGA3dCmdDXDrawIndexed *pCmd = (SVGA3dCmdDXDrawIndexed *)pvCmd;
5061 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5062 rcParse = vmsvga3dCmdDXDrawIndexed(pThisCC, idDXContext, pCmd, cbCmd);
5063 break;
5064 }
5065
5066 case SVGA_3D_CMD_DX_DRAW_INSTANCED:
5067 {
5068 SVGA3dCmdDXDrawInstanced *pCmd = (SVGA3dCmdDXDrawInstanced *)pvCmd;
5069 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5070 rcParse = vmsvga3dCmdDXDrawInstanced(pThisCC, idDXContext, pCmd, cbCmd);
5071 break;
5072 }
5073
5074 case SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED:
5075 {
5076 SVGA3dCmdDXDrawIndexedInstanced *pCmd = (SVGA3dCmdDXDrawIndexedInstanced *)pvCmd;
5077 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5078 rcParse = vmsvga3dCmdDXDrawIndexedInstanced(pThisCC, idDXContext, pCmd, cbCmd);
5079 break;
5080 }
5081
5082 case SVGA_3D_CMD_DX_DRAW_AUTO:
5083 {
5084 SVGA3dCmdDXDrawAuto *pCmd = (SVGA3dCmdDXDrawAuto *)pvCmd;
5085 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5086 rcParse = vmsvga3dCmdDXDrawAuto(pThisCC, idDXContext, pCmd, cbCmd);
5087 break;
5088 }
5089
5090 case SVGA_3D_CMD_DX_SET_INPUT_LAYOUT:
5091 {
5092 SVGA3dCmdDXSetInputLayout *pCmd = (SVGA3dCmdDXSetInputLayout *)pvCmd;
5093 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5094 rcParse = vmsvga3dCmdDXSetInputLayout(pThisCC, idDXContext, pCmd, cbCmd);
5095 break;
5096 }
5097
5098 case SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS:
5099 {
5100 SVGA3dCmdDXSetVertexBuffers *pCmd = (SVGA3dCmdDXSetVertexBuffers *)pvCmd;
5101 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5102 rcParse = vmsvga3dCmdDXSetVertexBuffers(pThisCC, idDXContext, pCmd, cbCmd);
5103 break;
5104 }
5105
5106 case SVGA_3D_CMD_DX_SET_INDEX_BUFFER:
5107 {
5108 SVGA3dCmdDXSetIndexBuffer *pCmd = (SVGA3dCmdDXSetIndexBuffer *)pvCmd;
5109 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5110 rcParse = vmsvga3dCmdDXSetIndexBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5111 break;
5112 }
5113
5114 case SVGA_3D_CMD_DX_SET_TOPOLOGY:
5115 {
5116 SVGA3dCmdDXSetTopology *pCmd = (SVGA3dCmdDXSetTopology *)pvCmd;
5117 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5118 rcParse = vmsvga3dCmdDXSetTopology(pThisCC, idDXContext, pCmd, cbCmd);
5119 break;
5120 }
5121
5122 case SVGA_3D_CMD_DX_SET_RENDERTARGETS:
5123 {
5124 SVGA3dCmdDXSetRenderTargets *pCmd = (SVGA3dCmdDXSetRenderTargets *)pvCmd;
5125 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5126 rcParse = vmsvga3dCmdDXSetRenderTargets(pThisCC, idDXContext, pCmd, cbCmd);
5127 break;
5128 }
5129
5130 case SVGA_3D_CMD_DX_SET_BLEND_STATE:
5131 {
5132 SVGA3dCmdDXSetBlendState *pCmd = (SVGA3dCmdDXSetBlendState *)pvCmd;
5133 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5134 rcParse = vmsvga3dCmdDXSetBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5135 break;
5136 }
5137
5138 case SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE:
5139 {
5140 SVGA3dCmdDXSetDepthStencilState *pCmd = (SVGA3dCmdDXSetDepthStencilState *)pvCmd;
5141 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5142 rcParse = vmsvga3dCmdDXSetDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5143 break;
5144 }
5145
5146 case SVGA_3D_CMD_DX_SET_RASTERIZER_STATE:
5147 {
5148 SVGA3dCmdDXSetRasterizerState *pCmd = (SVGA3dCmdDXSetRasterizerState *)pvCmd;
5149 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5150 rcParse = vmsvga3dCmdDXSetRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5151 break;
5152 }
5153
5154 case SVGA_3D_CMD_DX_DEFINE_QUERY:
5155 {
5156 SVGA3dCmdDXDefineQuery *pCmd = (SVGA3dCmdDXDefineQuery *)pvCmd;
5157 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5158 rcParse = vmsvga3dCmdDXDefineQuery(pThisCC, idDXContext, pCmd, cbCmd);
5159 break;
5160 }
5161
5162 case SVGA_3D_CMD_DX_DESTROY_QUERY:
5163 {
5164 SVGA3dCmdDXDestroyQuery *pCmd = (SVGA3dCmdDXDestroyQuery *)pvCmd;
5165 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5166 rcParse = vmsvga3dCmdDXDestroyQuery(pThisCC, idDXContext, pCmd, cbCmd);
5167 break;
5168 }
5169
5170 case SVGA_3D_CMD_DX_BIND_QUERY:
5171 {
5172 SVGA3dCmdDXBindQuery *pCmd = (SVGA3dCmdDXBindQuery *)pvCmd;
5173 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5174 rcParse = vmsvga3dCmdDXBindQuery(pThisCC, idDXContext, pCmd, cbCmd);
5175 break;
5176 }
5177
5178 case SVGA_3D_CMD_DX_SET_QUERY_OFFSET:
5179 {
5180 SVGA3dCmdDXSetQueryOffset *pCmd = (SVGA3dCmdDXSetQueryOffset *)pvCmd;
5181 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5182 rcParse = vmsvga3dCmdDXSetQueryOffset(pThisCC, idDXContext, pCmd, cbCmd);
5183 break;
5184 }
5185
5186 case SVGA_3D_CMD_DX_BEGIN_QUERY:
5187 {
5188 SVGA3dCmdDXBeginQuery *pCmd = (SVGA3dCmdDXBeginQuery *)pvCmd;
5189 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5190 rcParse = vmsvga3dCmdDXBeginQuery(pThisCC, idDXContext, pCmd, cbCmd);
5191 break;
5192 }
5193
5194 case SVGA_3D_CMD_DX_END_QUERY:
5195 {
5196 SVGA3dCmdDXEndQuery *pCmd = (SVGA3dCmdDXEndQuery *)pvCmd;
5197 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5198 rcParse = vmsvga3dCmdDXEndQuery(pThisCC, idDXContext, pCmd, cbCmd);
5199 break;
5200 }
5201
5202 case SVGA_3D_CMD_DX_READBACK_QUERY:
5203 {
5204 SVGA3dCmdDXReadbackQuery *pCmd = (SVGA3dCmdDXReadbackQuery *)pvCmd;
5205 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5206 rcParse = vmsvga3dCmdDXReadbackQuery(pThisCC, idDXContext, pCmd, cbCmd);
5207 break;
5208 }
5209
5210 case SVGA_3D_CMD_DX_SET_PREDICATION:
5211 {
5212 SVGA3dCmdDXSetPredication *pCmd = (SVGA3dCmdDXSetPredication *)pvCmd;
5213 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5214 rcParse = vmsvga3dCmdDXSetPredication(pThisCC, idDXContext, pCmd, cbCmd);
5215 break;
5216 }
5217
5218 case SVGA_3D_CMD_DX_SET_SOTARGETS:
5219 {
5220 SVGA3dCmdDXSetSOTargets *pCmd = (SVGA3dCmdDXSetSOTargets *)pvCmd;
5221 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5222 rcParse = vmsvga3dCmdDXSetSOTargets(pThisCC, idDXContext, pCmd, cbCmd);
5223 break;
5224 }
5225
5226 case SVGA_3D_CMD_DX_SET_VIEWPORTS:
5227 {
5228 SVGA3dCmdDXSetViewports *pCmd = (SVGA3dCmdDXSetViewports *)pvCmd;
5229 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5230 rcParse = vmsvga3dCmdDXSetViewports(pThisCC, idDXContext, pCmd, cbCmd);
5231 break;
5232 }
5233
5234 case SVGA_3D_CMD_DX_SET_SCISSORRECTS:
5235 {
5236 SVGA3dCmdDXSetScissorRects *pCmd = (SVGA3dCmdDXSetScissorRects *)pvCmd;
5237 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5238 rcParse = vmsvga3dCmdDXSetScissorRects(pThisCC, idDXContext, pCmd, cbCmd);
5239 break;
5240 }
5241
5242 case SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW:
5243 {
5244 SVGA3dCmdDXClearRenderTargetView *pCmd = (SVGA3dCmdDXClearRenderTargetView *)pvCmd;
5245 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5246 rcParse = vmsvga3dCmdDXClearRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5247 break;
5248 }
5249
5250 case SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW:
5251 {
5252 SVGA3dCmdDXClearDepthStencilView *pCmd = (SVGA3dCmdDXClearDepthStencilView *)pvCmd;
5253 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5254 rcParse = vmsvga3dCmdDXClearDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5255 break;
5256 }
5257
5258 case SVGA_3D_CMD_DX_PRED_COPY_REGION:
5259 {
5260 SVGA3dCmdDXPredCopyRegion *pCmd = (SVGA3dCmdDXPredCopyRegion *)pvCmd;
5261 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5262 rcParse = vmsvga3dCmdDXPredCopyRegion(pThisCC, idDXContext, pCmd, cbCmd);
5263 break;
5264 }
5265
5266 case SVGA_3D_CMD_DX_PRED_COPY:
5267 {
5268 SVGA3dCmdDXPredCopy *pCmd = (SVGA3dCmdDXPredCopy *)pvCmd;
5269 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5270 rcParse = vmsvga3dCmdDXPredCopy(pThisCC, idDXContext, pCmd, cbCmd);
5271 break;
5272 }
5273
5274 case SVGA_3D_CMD_DX_PRESENTBLT:
5275 {
5276 SVGA3dCmdDXPresentBlt *pCmd = (SVGA3dCmdDXPresentBlt *)pvCmd;
5277 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5278 rcParse = vmsvga3dCmdDXPresentBlt(pThisCC, idDXContext, pCmd, cbCmd);
5279 break;
5280 }
5281
5282 case SVGA_3D_CMD_DX_GENMIPS:
5283 {
5284 SVGA3dCmdDXGenMips *pCmd = (SVGA3dCmdDXGenMips *)pvCmd;
5285 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5286 rcParse = vmsvga3dCmdDXGenMips(pThisCC, idDXContext, pCmd, cbCmd);
5287 break;
5288 }
5289
5290 case SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE:
5291 {
5292 SVGA3dCmdDXUpdateSubResource *pCmd = (SVGA3dCmdDXUpdateSubResource *)pvCmd;
5293 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5294 rcParse = vmsvga3dCmdDXUpdateSubResource(pThisCC, pCmd, cbCmd);
5295 break;
5296 }
5297
5298 case SVGA_3D_CMD_DX_READBACK_SUBRESOURCE:
5299 {
5300 SVGA3dCmdDXReadbackSubResource *pCmd = (SVGA3dCmdDXReadbackSubResource *)pvCmd;
5301 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5302 rcParse = vmsvga3dCmdDXReadbackSubResource(pThisCC, pCmd, cbCmd);
5303 break;
5304 }
5305
5306 case SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE:
5307 {
5308 SVGA3dCmdDXInvalidateSubResource *pCmd = (SVGA3dCmdDXInvalidateSubResource *)pvCmd;
5309 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5310 rcParse = vmsvga3dCmdDXInvalidateSubResource(pThisCC, pCmd, cbCmd);
5311 break;
5312 }
5313
5314 case SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW:
5315 {
5316 SVGA3dCmdDXDefineShaderResourceView *pCmd = (SVGA3dCmdDXDefineShaderResourceView *)pvCmd;
5317 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5318 rcParse = vmsvga3dCmdDXDefineShaderResourceView(pThisCC, idDXContext, pCmd, cbCmd);
5319 break;
5320 }
5321
5322 case SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW:
5323 {
5324 SVGA3dCmdDXDestroyShaderResourceView *pCmd = (SVGA3dCmdDXDestroyShaderResourceView *)pvCmd;
5325 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5326 rcParse = vmsvga3dCmdDXDestroyShaderResourceView(pThisCC, idDXContext, pCmd, cbCmd);
5327 break;
5328 }
5329
5330 case SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW:
5331 {
5332 SVGA3dCmdDXDefineRenderTargetView *pCmd = (SVGA3dCmdDXDefineRenderTargetView *)pvCmd;
5333 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5334 rcParse = vmsvga3dCmdDXDefineRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5335 break;
5336 }
5337
5338 case SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW:
5339 {
5340 SVGA3dCmdDXDestroyRenderTargetView *pCmd = (SVGA3dCmdDXDestroyRenderTargetView *)pvCmd;
5341 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5342 rcParse = vmsvga3dCmdDXDestroyRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5343 break;
5344 }
5345
5346 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW:
5347 {
5348 SVGA3dCmdDXDefineDepthStencilView *pCmd = (SVGA3dCmdDXDefineDepthStencilView *)pvCmd;
5349 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5350 rcParse = vmsvga3dCmdDXDefineDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5351 break;
5352 }
5353
5354 case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW:
5355 {
5356 SVGA3dCmdDXDestroyDepthStencilView *pCmd = (SVGA3dCmdDXDestroyDepthStencilView *)pvCmd;
5357 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5358 rcParse = vmsvga3dCmdDXDestroyDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5359 break;
5360 }
5361
5362 case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
5363 {
5364 SVGA3dCmdDXDefineElementLayout *pCmd = (SVGA3dCmdDXDefineElementLayout *)pvCmd;
5365 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5366 rcParse = vmsvga3dCmdDXDefineElementLayout(pThisCC, idDXContext, pCmd, cbCmd);
5367 break;
5368 }
5369
5370 case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
5371 {
5372 SVGA3dCmdDXDestroyElementLayout *pCmd = (SVGA3dCmdDXDestroyElementLayout *)pvCmd;
5373 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5374 rcParse = vmsvga3dCmdDXDestroyElementLayout(pThisCC, idDXContext, pCmd, cbCmd);
5375 break;
5376 }
5377
5378 case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
5379 {
5380 SVGA3dCmdDXDefineBlendState *pCmd = (SVGA3dCmdDXDefineBlendState *)pvCmd;
5381 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5382 rcParse = vmsvga3dCmdDXDefineBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5383 break;
5384 }
5385
5386 case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
5387 {
5388 SVGA3dCmdDXDestroyBlendState *pCmd = (SVGA3dCmdDXDestroyBlendState *)pvCmd;
5389 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5390 rcParse = vmsvga3dCmdDXDestroyBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5391 break;
5392 }
5393
5394 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
5395 {
5396 SVGA3dCmdDXDefineDepthStencilState *pCmd = (SVGA3dCmdDXDefineDepthStencilState *)pvCmd;
5397 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5398 rcParse = vmsvga3dCmdDXDefineDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5399 break;
5400 }
5401
5402 case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
5403 {
5404 SVGA3dCmdDXDestroyDepthStencilState *pCmd = (SVGA3dCmdDXDestroyDepthStencilState *)pvCmd;
5405 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5406 rcParse = vmsvga3dCmdDXDestroyDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5407 break;
5408 }
5409
5410 case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
5411 {
5412 SVGA3dCmdDXDefineRasterizerState *pCmd = (SVGA3dCmdDXDefineRasterizerState *)pvCmd;
5413 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5414 rcParse = vmsvga3dCmdDXDefineRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5415 break;
5416 }
5417
5418 case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
5419 {
5420 SVGA3dCmdDXDestroyRasterizerState *pCmd = (SVGA3dCmdDXDestroyRasterizerState *)pvCmd;
5421 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5422 rcParse = vmsvga3dCmdDXDestroyRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5423 break;
5424 }
5425
5426 case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
5427 {
5428 SVGA3dCmdDXDefineSamplerState *pCmd = (SVGA3dCmdDXDefineSamplerState *)pvCmd;
5429 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5430 rcParse = vmsvga3dCmdDXDefineSamplerState(pThisCC, idDXContext, pCmd, cbCmd);
5431 break;
5432 }
5433
5434 case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
5435 {
5436 SVGA3dCmdDXDestroySamplerState *pCmd = (SVGA3dCmdDXDestroySamplerState *)pvCmd;
5437 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5438 rcParse = vmsvga3dCmdDXDestroySamplerState(pThisCC, idDXContext, pCmd, cbCmd);
5439 break;
5440 }
5441
5442 case SVGA_3D_CMD_DX_DEFINE_SHADER:
5443 {
5444 SVGA3dCmdDXDefineShader *pCmd = (SVGA3dCmdDXDefineShader *)pvCmd;
5445 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5446 rcParse = vmsvga3dCmdDXDefineShader(pThisCC, idDXContext, pCmd, cbCmd);
5447 break;
5448 }
5449
5450 case SVGA_3D_CMD_DX_DESTROY_SHADER:
5451 {
5452 SVGA3dCmdDXDestroyShader *pCmd = (SVGA3dCmdDXDestroyShader *)pvCmd;
5453 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5454 rcParse = vmsvga3dCmdDXDestroyShader(pThisCC, idDXContext, pCmd, cbCmd);
5455 break;
5456 }
5457
5458 case SVGA_3D_CMD_DX_BIND_SHADER:
5459 {
5460 SVGA3dCmdDXBindShader *pCmd = (SVGA3dCmdDXBindShader *)pvCmd;
5461 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5462 rcParse = vmsvga3dCmdDXBindShader(pThisCC, idDXContext, pCmd, cbCmd);
5463 break;
5464 }
5465
5466 case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
5467 {
5468 SVGA3dCmdDXDefineStreamOutput *pCmd = (SVGA3dCmdDXDefineStreamOutput *)pvCmd;
5469 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5470 rcParse = vmsvga3dCmdDXDefineStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5471 break;
5472 }
5473
5474 case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
5475 {
5476 SVGA3dCmdDXDestroyStreamOutput *pCmd = (SVGA3dCmdDXDestroyStreamOutput *)pvCmd;
5477 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5478 rcParse = vmsvga3dCmdDXDestroyStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5479 break;
5480 }
5481
5482 case SVGA_3D_CMD_DX_SET_STREAMOUTPUT:
5483 {
5484 SVGA3dCmdDXSetStreamOutput *pCmd = (SVGA3dCmdDXSetStreamOutput *)pvCmd;
5485 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5486 rcParse = vmsvga3dCmdDXSetStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5487 break;
5488 }
5489
5490 case SVGA_3D_CMD_DX_SET_COTABLE:
5491 {
5492 SVGA3dCmdDXSetCOTable *pCmd = (SVGA3dCmdDXSetCOTable *)pvCmd;
5493 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5494 rcParse = vmsvga3dCmdDXSetCOTable(pThisCC, pCmd, cbCmd);
5495 break;
5496 }
5497
5498 case SVGA_3D_CMD_DX_READBACK_COTABLE:
5499 {
5500 SVGA3dCmdDXReadbackCOTable *pCmd = (SVGA3dCmdDXReadbackCOTable *)pvCmd;
5501 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5502 rcParse = vmsvga3dCmdDXReadbackCOTable(pThisCC, idDXContext, pCmd, cbCmd);
5503 break;
5504 }
5505
5506 case SVGA_3D_CMD_DX_BUFFER_COPY:
5507 {
5508 SVGA3dCmdDXBufferCopy *pCmd = (SVGA3dCmdDXBufferCopy *)pvCmd;
5509 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5510 rcParse = vmsvga3dCmdDXBufferCopy(pThisCC, idDXContext, pCmd, cbCmd);
5511 break;
5512 }
5513
5514 case SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER:
5515 {
5516 SVGA3dCmdDXTransferFromBuffer *pCmd = (SVGA3dCmdDXTransferFromBuffer *)pvCmd;
5517 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5518 rcParse = vmsvga3dCmdDXTransferFromBuffer(pThisCC, pCmd, cbCmd);
5519 break;
5520 }
5521
5522 case SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK:
5523 {
5524 SVGA3dCmdDXSurfaceCopyAndReadback *pCmd = (SVGA3dCmdDXSurfaceCopyAndReadback *)pvCmd;
5525 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5526 rcParse = vmsvga3dCmdDXSurfaceCopyAndReadback(pThisCC, idDXContext, pCmd, cbCmd);
5527 break;
5528 }
5529
5530 case SVGA_3D_CMD_DX_MOVE_QUERY:
5531 {
5532 SVGA3dCmdDXMoveQuery *pCmd = (SVGA3dCmdDXMoveQuery *)pvCmd;
5533 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5534 rcParse = vmsvga3dCmdDXMoveQuery(pThisCC, idDXContext, pCmd, cbCmd);
5535 break;
5536 }
5537
5538 case SVGA_3D_CMD_DX_BIND_ALL_QUERY:
5539 {
5540 SVGA3dCmdDXBindAllQuery *pCmd = (SVGA3dCmdDXBindAllQuery *)pvCmd;
5541 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5542 rcParse = vmsvga3dCmdDXBindAllQuery(pThisCC, idDXContext, pCmd, cbCmd);
5543 break;
5544 }
5545
5546 case SVGA_3D_CMD_DX_READBACK_ALL_QUERY:
5547 {
5548 SVGA3dCmdDXReadbackAllQuery *pCmd = (SVGA3dCmdDXReadbackAllQuery *)pvCmd;
5549 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5550 rcParse = vmsvga3dCmdDXReadbackAllQuery(pThisCC, idDXContext, pCmd, cbCmd);
5551 break;
5552 }
5553
5554 case SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER:
5555 {
5556 SVGA3dCmdDXPredTransferFromBuffer *pCmd = (SVGA3dCmdDXPredTransferFromBuffer *)pvCmd;
5557 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5558 rcParse = vmsvga3dCmdDXPredTransferFromBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5559 break;
5560 }
5561
5562 case SVGA_3D_CMD_DX_MOB_FENCE_64:
5563 {
5564 SVGA3dCmdDXMobFence64 *pCmd = (SVGA3dCmdDXMobFence64 *)pvCmd;
5565 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5566 rcParse = vmsvga3dCmdDXMobFence64(pThisCC, idDXContext, pCmd, cbCmd);
5567 break;
5568 }
5569
5570 case SVGA_3D_CMD_DX_BIND_ALL_SHADER:
5571 {
5572 SVGA3dCmdDXBindAllShader *pCmd = (SVGA3dCmdDXBindAllShader *)pvCmd;
5573 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5574 rcParse = vmsvga3dCmdDXBindAllShader(pThisCC, idDXContext, pCmd, cbCmd);
5575 break;
5576 }
5577
5578 case SVGA_3D_CMD_DX_HINT:
5579 {
5580 SVGA3dCmdDXHint *pCmd = (SVGA3dCmdDXHint *)pvCmd;
5581 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5582 rcParse = vmsvga3dCmdDXHint(pThisCC, idDXContext, pCmd, cbCmd);
5583 break;
5584 }
5585
5586 case SVGA_3D_CMD_DX_BUFFER_UPDATE:
5587 {
5588 SVGA3dCmdDXBufferUpdate *pCmd = (SVGA3dCmdDXBufferUpdate *)pvCmd;
5589 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5590 rcParse = vmsvga3dCmdDXBufferUpdate(pThisCC, idDXContext, pCmd, cbCmd);
5591 break;
5592 }
5593
5594 case SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET:
5595 {
5596 SVGA3dCmdDXSetVSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetVSConstantBufferOffset *)pvCmd;
5597 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5598 rcParse = vmsvga3dCmdDXSetVSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5599 break;
5600 }
5601
5602 case SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET:
5603 {
5604 SVGA3dCmdDXSetPSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetPSConstantBufferOffset *)pvCmd;
5605 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5606 rcParse = vmsvga3dCmdDXSetPSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5607 break;
5608 }
5609
5610 case SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET:
5611 {
5612 SVGA3dCmdDXSetGSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetGSConstantBufferOffset *)pvCmd;
5613 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5614 rcParse = vmsvga3dCmdDXSetGSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5615 break;
5616 }
5617
5618 case SVGA_3D_CMD_DX_SET_HS_CONSTANT_BUFFER_OFFSET:
5619 {
5620 SVGA3dCmdDXSetHSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetHSConstantBufferOffset *)pvCmd;
5621 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5622 rcParse = vmsvga3dCmdDXSetHSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5623 break;
5624 }
5625
5626 case SVGA_3D_CMD_DX_SET_DS_CONSTANT_BUFFER_OFFSET:
5627 {
5628 SVGA3dCmdDXSetDSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetDSConstantBufferOffset *)pvCmd;
5629 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5630 rcParse = vmsvga3dCmdDXSetDSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5631 break;
5632 }
5633
5634 case SVGA_3D_CMD_DX_SET_CS_CONSTANT_BUFFER_OFFSET:
5635 {
5636 SVGA3dCmdDXSetCSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetCSConstantBufferOffset *)pvCmd;
5637 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5638 rcParse = vmsvga3dCmdDXSetCSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5639 break;
5640 }
5641
5642 case SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER:
5643 {
5644 SVGA3dCmdDXCondBindAllShader *pCmd = (SVGA3dCmdDXCondBindAllShader *)pvCmd;
5645 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5646 rcParse = vmsvga3dCmdDXCondBindAllShader(pThisCC, idDXContext, pCmd, cbCmd);
5647 break;
5648 }
5649
5650 case SVGA_3D_CMD_SCREEN_COPY:
5651 {
5652 SVGA3dCmdScreenCopy *pCmd = (SVGA3dCmdScreenCopy *)pvCmd;
5653 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5654 rcParse = vmsvga3dCmdScreenCopy(pThisCC, idDXContext, pCmd, cbCmd);
5655 break;
5656 }
5657
5658 case SVGA_3D_CMD_RESERVED1:
5659 {
5660 VMSVGA_3D_CMD_NOTIMPL();
5661 break;
5662 }
5663
5664 case SVGA_3D_CMD_RESERVED2:
5665 {
5666 VMSVGA_3D_CMD_NOTIMPL();
5667 break;
5668 }
5669
5670 case SVGA_3D_CMD_RESERVED3:
5671 {
5672 VMSVGA_3D_CMD_NOTIMPL();
5673 break;
5674 }
5675
5676 case SVGA_3D_CMD_RESERVED4:
5677 {
5678 VMSVGA_3D_CMD_NOTIMPL();
5679 break;
5680 }
5681
5682 case SVGA_3D_CMD_RESERVED5:
5683 {
5684 VMSVGA_3D_CMD_NOTIMPL();
5685 break;
5686 }
5687
5688 case SVGA_3D_CMD_RESERVED6:
5689 {
5690 VMSVGA_3D_CMD_NOTIMPL();
5691 break;
5692 }
5693
5694 case SVGA_3D_CMD_RESERVED7:
5695 {
5696 VMSVGA_3D_CMD_NOTIMPL();
5697 break;
5698 }
5699
5700 case SVGA_3D_CMD_RESERVED8:
5701 {
5702 VMSVGA_3D_CMD_NOTIMPL();
5703 break;
5704 }
5705
5706 case SVGA_3D_CMD_GROW_OTABLE:
5707 {
5708 SVGA3dCmdGrowOTable *pCmd = (SVGA3dCmdGrowOTable *)pvCmd;
5709 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5710 rcParse = vmsvga3dCmdGrowOTable(pThisCC, idDXContext, pCmd, cbCmd);
5711 break;
5712 }
5713
5714 case SVGA_3D_CMD_DX_GROW_COTABLE:
5715 {
5716 SVGA3dCmdDXGrowCOTable *pCmd = (SVGA3dCmdDXGrowCOTable *)pvCmd;
5717 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5718 rcParse = vmsvga3dCmdDXGrowCOTable(pThisCC, idDXContext, pCmd, cbCmd);
5719 break;
5720 }
5721
5722 case SVGA_3D_CMD_INTRA_SURFACE_COPY:
5723 {
5724 SVGA3dCmdIntraSurfaceCopy *pCmd = (SVGA3dCmdIntraSurfaceCopy *)pvCmd;
5725 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5726 rcParse = vmsvga3dCmdIntraSurfaceCopy(pThisCC, idDXContext, pCmd, cbCmd);
5727 break;
5728 }
5729
5730 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V3:
5731 {
5732 SVGA3dCmdDefineGBSurface_v3 *pCmd = (SVGA3dCmdDefineGBSurface_v3 *)pvCmd;
5733 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5734 rcParse = vmsvga3dCmdDefineGBSurface_v3(pThisCC, idDXContext, pCmd, cbCmd);
5735 break;
5736 }
5737
5738 case SVGA_3D_CMD_DX_RESOLVE_COPY:
5739 {
5740 SVGA3dCmdDXResolveCopy *pCmd = (SVGA3dCmdDXResolveCopy *)pvCmd;
5741 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5742 rcParse = vmsvga3dCmdDXResolveCopy(pThisCC, idDXContext, pCmd, cbCmd);
5743 break;
5744 }
5745
5746 case SVGA_3D_CMD_DX_PRED_RESOLVE_COPY:
5747 {
5748 SVGA3dCmdDXPredResolveCopy *pCmd = (SVGA3dCmdDXPredResolveCopy *)pvCmd;
5749 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5750 rcParse = vmsvga3dCmdDXPredResolveCopy(pThisCC, idDXContext, pCmd, cbCmd);
5751 break;
5752 }
5753
5754 case SVGA_3D_CMD_DX_PRED_CONVERT_REGION:
5755 {
5756 SVGA3dCmdDXPredConvertRegion *pCmd = (SVGA3dCmdDXPredConvertRegion *)pvCmd;
5757 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5758 rcParse = vmsvga3dCmdDXPredConvertRegion(pThisCC, idDXContext, pCmd, cbCmd);
5759 break;
5760 }
5761
5762 case SVGA_3D_CMD_DX_PRED_CONVERT:
5763 {
5764 SVGA3dCmdDXPredConvert *pCmd = (SVGA3dCmdDXPredConvert *)pvCmd;
5765 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5766 rcParse = vmsvga3dCmdDXPredConvert(pThisCC, idDXContext, pCmd, cbCmd);
5767 break;
5768 }
5769
5770 case SVGA_3D_CMD_WHOLE_SURFACE_COPY:
5771 {
5772 SVGA3dCmdWholeSurfaceCopy *pCmd = (SVGA3dCmdWholeSurfaceCopy *)pvCmd;
5773 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5774 rcParse = vmsvga3dCmdWholeSurfaceCopy(pThisCC, idDXContext, pCmd, cbCmd);
5775 break;
5776 }
5777
5778 case SVGA_3D_CMD_DX_DEFINE_UA_VIEW:
5779 {
5780 SVGA3dCmdDXDefineUAView *pCmd = (SVGA3dCmdDXDefineUAView *)pvCmd;
5781 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5782 rcParse = vmsvga3dCmdDXDefineUAView(pThisCC, idDXContext, pCmd, cbCmd);
5783 break;
5784 }
5785
5786 case SVGA_3D_CMD_DX_DESTROY_UA_VIEW:
5787 {
5788 SVGA3dCmdDXDestroyUAView *pCmd = (SVGA3dCmdDXDestroyUAView *)pvCmd;
5789 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5790 rcParse = vmsvga3dCmdDXDestroyUAView(pThisCC, idDXContext, pCmd, cbCmd);
5791 break;
5792 }
5793
5794 case SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT:
5795 {
5796 SVGA3dCmdDXClearUAViewUint *pCmd = (SVGA3dCmdDXClearUAViewUint *)pvCmd;
5797 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5798 rcParse = vmsvga3dCmdDXClearUAViewUint(pThisCC, idDXContext, pCmd, cbCmd);
5799 break;
5800 }
5801
5802 case SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT:
5803 {
5804 SVGA3dCmdDXClearUAViewFloat *pCmd = (SVGA3dCmdDXClearUAViewFloat *)pvCmd;
5805 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5806 rcParse = vmsvga3dCmdDXClearUAViewFloat(pThisCC, idDXContext, pCmd, cbCmd);
5807 break;
5808 }
5809
5810 case SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT:
5811 {
5812 SVGA3dCmdDXCopyStructureCount *pCmd = (SVGA3dCmdDXCopyStructureCount *)pvCmd;
5813 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5814 rcParse = vmsvga3dCmdDXCopyStructureCount(pThisCC, idDXContext, pCmd, cbCmd);
5815 break;
5816 }
5817
5818 case SVGA_3D_CMD_DX_SET_UA_VIEWS:
5819 {
5820 SVGA3dCmdDXSetUAViews *pCmd = (SVGA3dCmdDXSetUAViews *)pvCmd;
5821 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5822 rcParse = vmsvga3dCmdDXSetUAViews(pThisCC, idDXContext, pCmd, cbCmd);
5823 break;
5824 }
5825
5826 case SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT:
5827 {
5828 SVGA3dCmdDXDrawIndexedInstancedIndirect *pCmd = (SVGA3dCmdDXDrawIndexedInstancedIndirect *)pvCmd;
5829 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5830 rcParse = vmsvga3dCmdDXDrawIndexedInstancedIndirect(pThisCC, idDXContext, pCmd, cbCmd);
5831 break;
5832 }
5833
5834 case SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT:
5835 {
5836 SVGA3dCmdDXDrawInstancedIndirect *pCmd = (SVGA3dCmdDXDrawInstancedIndirect *)pvCmd;
5837 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5838 rcParse = vmsvga3dCmdDXDrawInstancedIndirect(pThisCC, idDXContext, pCmd, cbCmd);
5839 break;
5840 }
5841
5842 case SVGA_3D_CMD_DX_DISPATCH:
5843 {
5844 SVGA3dCmdDXDispatch *pCmd = (SVGA3dCmdDXDispatch *)pvCmd;
5845 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5846 rcParse = vmsvga3dCmdDXDispatch(pThisCC, idDXContext, pCmd, cbCmd);
5847 break;
5848 }
5849
5850 case SVGA_3D_CMD_DX_DISPATCH_INDIRECT:
5851 {
5852 SVGA3dCmdDXDispatchIndirect *pCmd = (SVGA3dCmdDXDispatchIndirect *)pvCmd;
5853 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5854 rcParse = vmsvga3dCmdDXDispatchIndirect(pThisCC, idDXContext, pCmd, cbCmd);
5855 break;
5856 }
5857
5858 case SVGA_3D_CMD_WRITE_ZERO_SURFACE:
5859 {
5860 SVGA3dCmdWriteZeroSurface *pCmd = (SVGA3dCmdWriteZeroSurface *)pvCmd;
5861 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5862 rcParse = vmsvga3dCmdWriteZeroSurface(pThisCC, idDXContext, pCmd, cbCmd);
5863 break;
5864 }
5865
5866 case SVGA_3D_CMD_HINT_ZERO_SURFACE:
5867 {
5868 SVGA3dCmdHintZeroSurface *pCmd = (SVGA3dCmdHintZeroSurface *)pvCmd;
5869 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5870 rcParse = vmsvga3dCmdHintZeroSurface(pThisCC, idDXContext, pCmd, cbCmd);
5871 break;
5872 }
5873
5874 case SVGA_3D_CMD_DX_TRANSFER_TO_BUFFER:
5875 {
5876 SVGA3dCmdDXTransferToBuffer *pCmd = (SVGA3dCmdDXTransferToBuffer *)pvCmd;
5877 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5878 rcParse = vmsvga3dCmdDXTransferToBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5879 break;
5880 }
5881
5882 case SVGA_3D_CMD_DX_SET_STRUCTURE_COUNT:
5883 {
5884 SVGA3dCmdDXSetStructureCount *pCmd = (SVGA3dCmdDXSetStructureCount *)pvCmd;
5885 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5886 rcParse = vmsvga3dCmdDXSetStructureCount(pThisCC, idDXContext, pCmd, cbCmd);
5887 break;
5888 }
5889
5890 case SVGA_3D_CMD_LOGICOPS_BITBLT:
5891 {
5892 SVGA3dCmdLogicOpsBitBlt *pCmd = (SVGA3dCmdLogicOpsBitBlt *)pvCmd;
5893 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5894 rcParse = vmsvga3dCmdLogicOpsBitBlt(pThisCC, idDXContext, pCmd, cbCmd);
5895 break;
5896 }
5897
5898 case SVGA_3D_CMD_LOGICOPS_TRANSBLT:
5899 {
5900 SVGA3dCmdLogicOpsTransBlt *pCmd = (SVGA3dCmdLogicOpsTransBlt *)pvCmd;
5901 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5902 rcParse = vmsvga3dCmdLogicOpsTransBlt(pThisCC, idDXContext, pCmd, cbCmd);
5903 break;
5904 }
5905
5906 case SVGA_3D_CMD_LOGICOPS_STRETCHBLT:
5907 {
5908 SVGA3dCmdLogicOpsStretchBlt *pCmd = (SVGA3dCmdLogicOpsStretchBlt *)pvCmd;
5909 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5910 rcParse = vmsvga3dCmdLogicOpsStretchBlt(pThisCC, idDXContext, pCmd, cbCmd);
5911 break;
5912 }
5913
5914 case SVGA_3D_CMD_LOGICOPS_COLORFILL:
5915 {
5916 SVGA3dCmdLogicOpsColorFill *pCmd = (SVGA3dCmdLogicOpsColorFill *)pvCmd;
5917 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5918 rcParse = vmsvga3dCmdLogicOpsColorFill(pThisCC, idDXContext, pCmd, cbCmd);
5919 break;
5920 }
5921
5922 case SVGA_3D_CMD_LOGICOPS_ALPHABLEND:
5923 {
5924 SVGA3dCmdLogicOpsAlphaBlend *pCmd = (SVGA3dCmdLogicOpsAlphaBlend *)pvCmd;
5925 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5926 rcParse = vmsvga3dCmdLogicOpsAlphaBlend(pThisCC, idDXContext, pCmd, cbCmd);
5927 break;
5928 }
5929
5930 case SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND:
5931 {
5932 SVGA3dCmdLogicOpsClearTypeBlend *pCmd = (SVGA3dCmdLogicOpsClearTypeBlend *)pvCmd;
5933 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5934 rcParse = vmsvga3dCmdLogicOpsClearTypeBlend(pThisCC, idDXContext, pCmd, cbCmd);
5935 break;
5936 }
5937
5938 case SVGA_3D_CMD_RESERVED2_1:
5939 {
5940 VMSVGA_3D_CMD_NOTIMPL();
5941 break;
5942 }
5943
5944 case SVGA_3D_CMD_RESERVED2_2:
5945 {
5946 VMSVGA_3D_CMD_NOTIMPL();
5947 break;
5948 }
5949
5950 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V4:
5951 {
5952 SVGA3dCmdDefineGBSurface_v4 *pCmd = (SVGA3dCmdDefineGBSurface_v4 *)pvCmd;
5953 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5954 rcParse = vmsvga3dCmdDefineGBSurface_v4(pThisCC, idDXContext, pCmd, cbCmd);
5955 break;
5956 }
5957
5958 case SVGA_3D_CMD_DX_SET_CS_UA_VIEWS:
5959 {
5960 SVGA3dCmdDXSetCSUAViews *pCmd = (SVGA3dCmdDXSetCSUAViews *)pvCmd;
5961 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5962 rcParse = vmsvga3dCmdDXSetCSUAViews(pThisCC, idDXContext, pCmd, cbCmd);
5963 break;
5964 }
5965
5966 case SVGA_3D_CMD_DX_SET_MIN_LOD:
5967 {
5968 SVGA3dCmdDXSetMinLOD *pCmd = (SVGA3dCmdDXSetMinLOD *)pvCmd;
5969 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5970 rcParse = vmsvga3dCmdDXSetMinLOD(pThisCC, idDXContext, pCmd, cbCmd);
5971 break;
5972 }
5973
5974 case SVGA_3D_CMD_RESERVED2_3:
5975 {
5976 VMSVGA_3D_CMD_NOTIMPL();
5977 break;
5978 }
5979
5980 case SVGA_3D_CMD_RESERVED2_4:
5981 {
5982 VMSVGA_3D_CMD_NOTIMPL();
5983 break;
5984 }
5985
5986 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2:
5987 {
5988 SVGA3dCmdDXDefineDepthStencilView_v2 *pCmd = (SVGA3dCmdDXDefineDepthStencilView_v2 *)pvCmd;
5989 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5990 rcParse = vmsvga3dCmdDXDefineDepthStencilView_v2(pThisCC, idDXContext, pCmd, cbCmd);
5991 break;
5992 }
5993
5994 case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB:
5995 {
5996 SVGA3dCmdDXDefineStreamOutputWithMob *pCmd = (SVGA3dCmdDXDefineStreamOutputWithMob *)pvCmd;
5997 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5998 rcParse = vmsvga3dCmdDXDefineStreamOutputWithMob(pThisCC, idDXContext, pCmd, cbCmd);
5999 break;
6000 }
6001
6002 case SVGA_3D_CMD_DX_SET_SHADER_IFACE:
6003 {
6004 SVGA3dCmdDXSetShaderIface *pCmd = (SVGA3dCmdDXSetShaderIface *)pvCmd;
6005 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6006 rcParse = vmsvga3dCmdDXSetShaderIface(pThisCC, idDXContext, pCmd, cbCmd);
6007 break;
6008 }
6009
6010 case SVGA_3D_CMD_DX_BIND_STREAMOUTPUT:
6011 {
6012 SVGA3dCmdDXBindStreamOutput *pCmd = (SVGA3dCmdDXBindStreamOutput *)pvCmd;
6013 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6014 rcParse = vmsvga3dCmdDXBindStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
6015 break;
6016 }
6017
6018 case SVGA_3D_CMD_SURFACE_STRETCHBLT_NON_MS_TO_MS:
6019 {
6020 SVGA3dCmdSurfaceStretchBltNonMSToMS *pCmd = (SVGA3dCmdSurfaceStretchBltNonMSToMS *)pvCmd;
6021 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6022 rcParse = vmsvga3dCmdSurfaceStretchBltNonMSToMS(pThisCC, idDXContext, pCmd, cbCmd);
6023 break;
6024 }
6025
6026 case SVGA_3D_CMD_DX_BIND_SHADER_IFACE:
6027 {
6028 SVGA3dCmdDXBindShaderIface *pCmd = (SVGA3dCmdDXBindShaderIface *)pvCmd;
6029 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6030 rcParse = vmsvga3dCmdDXBindShaderIface(pThisCC, idDXContext, pCmd, cbCmd);
6031 break;
6032 }
6033
6034 /* Unsupported commands. */
6035 case SVGA_3D_CMD_DEAD4: /* SVGA_3D_CMD_VIDEO_CREATE_DECODER */
6036 case SVGA_3D_CMD_DEAD5: /* SVGA_3D_CMD_VIDEO_DESTROY_DECODER */
6037 case SVGA_3D_CMD_DEAD6: /* SVGA_3D_CMD_VIDEO_CREATE_PROCESSOR */
6038 case SVGA_3D_CMD_DEAD7: /* SVGA_3D_CMD_VIDEO_DESTROY_PROCESSOR */
6039 case SVGA_3D_CMD_DEAD8: /* SVGA_3D_CMD_VIDEO_DECODE_START_FRAME */
6040 case SVGA_3D_CMD_DEAD9: /* SVGA_3D_CMD_VIDEO_DECODE_RENDER */
6041 case SVGA_3D_CMD_DEAD10: /* SVGA_3D_CMD_VIDEO_DECODE_END_FRAME */
6042 case SVGA_3D_CMD_DEAD11: /* SVGA_3D_CMD_VIDEO_PROCESS_FRAME */
6043 /* Prevent the compiler warning. */
6044 case SVGA_3D_CMD_LEGACY_BASE:
6045 case SVGA_3D_CMD_MAX:
6046 case SVGA_3D_CMD_FUTURE_MAX:
6047 /* No 'default' case */
6048 STAM_REL_COUNTER_INC(&pSvgaR3State->StatFifoUnkCmds);
6049 ASSERT_GUEST_MSG_FAILED(("enmCmdId=%d\n", enmCmdId));
6050 LogRelMax(16, ("VMSVGA: unsupported 3D command %d\n", enmCmdId));
6051 rcParse = VERR_NOT_IMPLEMENTED;
6052 break;
6053 }
6054
6055 return VINF_SUCCESS;
6056// return rcParse;
6057}
6058# undef VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
6059#endif /* VBOX_WITH_VMSVGA3D */
6060
6061
6062/*
6063 *
6064 * Handlers for FIFO commands.
6065 *
6066 * Every handler takes the following parameters:
6067 *
6068 * pThis The shared VGA/VMSVGA state.
6069 * pThisCC The VGA/VMSVGA state for ring-3.
6070 * pCmd The command data.
6071 */
6072
6073
6074/* SVGA_CMD_UPDATE */
6075void vmsvgaR3CmdUpdate(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdate const *pCmd)
6076{
6077 RT_NOREF(pThis);
6078 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6079
6080 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdate);
6081 Log(("SVGA_CMD_UPDATE %d,%d %dx%d\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height));
6082
6083 /** @todo Multiple screens? */
6084 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6085 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
6086 return;
6087
6088 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
6089}
6090
6091
6092/* SVGA_CMD_UPDATE_VERBOSE */
6093void vmsvgaR3CmdUpdateVerbose(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdateVerbose const *pCmd)
6094{
6095 RT_NOREF(pThis);
6096 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6097
6098 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdateVerbose);
6099 Log(("SVGA_CMD_UPDATE_VERBOSE %d,%d %dx%d reason %#x\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height, pCmd->reason));
6100
6101 /** @todo Multiple screens? */
6102 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6103 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
6104 return;
6105
6106 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
6107}
6108
6109
6110/* SVGA_CMD_RECT_FILL */
6111void vmsvgaR3CmdRectFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectFill const *pCmd)
6112{
6113 RT_NOREF(pThis, pCmd);
6114 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6115
6116 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectFill);
6117 Log(("SVGA_CMD_RECT_FILL %08X @ %d,%d (%dx%d)\n", pCmd->pixel, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
6118 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_RECT_FILL command ignored.\n"));
6119}
6120
6121
6122/* SVGA_CMD_RECT_COPY */
6123void vmsvgaR3CmdRectCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectCopy const *pCmd)
6124{
6125 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6126
6127 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectCopy);
6128 Log(("SVGA_CMD_RECT_COPY %d,%d -> %d,%d %dx%d\n", pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
6129
6130 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6131 AssertPtrReturnVoid(pScreen);
6132
6133 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
6134 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
6135 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
6136 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
6137 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
6138 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
6139 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
6140
6141 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
6142 pCmd->width, pCmd->height, pThis->vram_size);
6143 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
6144}
6145
6146
6147/* SVGA_CMD_RECT_ROP_COPY */
6148void vmsvgaR3CmdRectRopCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectRopCopy const *pCmd)
6149{
6150 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6151
6152 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectRopCopy);
6153 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));
6154
6155 if (pCmd->rop != SVGA_ROP_COPY)
6156 {
6157 /* We only support the plain copy ROP which makes SVGA_CMD_RECT_ROP_COPY exactly the same
6158 * as SVGA_CMD_RECT_COPY. XFree86 4.1.0 and 4.2.0 drivers (driver version 10.4.0 and 10.7.0,
6159 * respectively) issue SVGA_CMD_RECT_ROP_COPY when SVGA_CAP_RECT_COPY is present even when
6160 * SVGA_CAP_RASTER_OP is not. However, the ROP will always be SVGA_ROP_COPY.
6161 */
6162 LogRelMax(4, ("VMSVGA: SVGA_CMD_RECT_ROP_COPY %d,%d -> %d,%d (%dx%d) ROP %X unsupported\n",
6163 pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height, pCmd->rop));
6164 return;
6165 }
6166
6167 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6168 AssertPtrReturnVoid(pScreen);
6169
6170 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
6171 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
6172 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
6173 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
6174 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
6175 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
6176 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
6177
6178 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
6179 pCmd->width, pCmd->height, pThis->vram_size);
6180 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
6181}
6182
6183
6184/* SVGA_CMD_DISPLAY_CURSOR */
6185void vmsvgaR3CmdDisplayCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDisplayCursor const *pCmd)
6186{
6187 RT_NOREF(pThis, pCmd);
6188 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6189
6190 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDisplayCursor);
6191 Log(("SVGA_CMD_DISPLAY_CURSOR id=%d state=%d\n", pCmd->id, pCmd->state));
6192 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_DISPLAY_CURSOR command ignored.\n"));
6193}
6194
6195
6196/* SVGA_CMD_MOVE_CURSOR */
6197void vmsvgaR3CmdMoveCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdMoveCursor const *pCmd)
6198{
6199 RT_NOREF(pThis, pCmd);
6200 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6201
6202 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdMoveCursor);
6203 Log(("SVGA_CMD_MOVE_CURSOR to %d,%d\n", pCmd->pos.x, pCmd->pos.y));
6204 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_MOVE_CURSOR command ignored.\n"));
6205}
6206
6207
6208/* SVGA_CMD_DEFINE_CURSOR */
6209void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineCursor const *pCmd)
6210{
6211 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6212
6213 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineCursor);
6214 Log(("SVGA_CMD_DEFINE_CURSOR id=%d size (%dx%d) hotspot (%d,%d) andMaskDepth=%d xorMaskDepth=%d\n",
6215 pCmd->id, pCmd->width, pCmd->height, pCmd->hotspotX, pCmd->hotspotY, pCmd->andMaskDepth, pCmd->xorMaskDepth));
6216
6217 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
6218 ASSERT_GUEST_RETURN_VOID(pCmd->andMaskDepth <= 32);
6219 ASSERT_GUEST_RETURN_VOID(pCmd->xorMaskDepth <= 32);
6220 RT_UNTRUSTED_VALIDATED_FENCE();
6221
6222 uint32_t const cbSrcAndLine = RT_ALIGN_32(pCmd->width * (pCmd->andMaskDepth + (pCmd->andMaskDepth == 15)), 32) / 8;
6223 uint32_t const cbSrcAndMask = cbSrcAndLine * pCmd->height;
6224 uint32_t const cbSrcXorLine = RT_ALIGN_32(pCmd->width * (pCmd->xorMaskDepth + (pCmd->xorMaskDepth == 15)), 32) / 8;
6225
6226 uint8_t const *pbSrcAndMask = (uint8_t const *)(pCmd + 1);
6227 uint8_t const *pbSrcXorMask = (uint8_t const *)(pCmd + 1) + cbSrcAndMask;
6228
6229 uint32_t const cx = pCmd->width;
6230 uint32_t const cy = pCmd->height;
6231
6232 /*
6233 * Convert the input to 1-bit AND mask and a 32-bit BRGA XOR mask.
6234 * The AND data uses 8-bit aligned scanlines.
6235 * The XOR data must be starting on a 32-bit boundrary.
6236 */
6237 uint32_t cbDstAndLine = RT_ALIGN_32(cx, 8) / 8;
6238 uint32_t cbDstAndMask = cbDstAndLine * cy;
6239 uint32_t cbDstXorMask = cx * sizeof(uint32_t) * cy;
6240 uint32_t cbCopy = RT_ALIGN_32(cbDstAndMask, 4) + cbDstXorMask;
6241
6242 uint8_t *pbCopy = (uint8_t *)RTMemAlloc(cbCopy);
6243 AssertReturnVoid(pbCopy);
6244
6245 /* Convert the AND mask. */
6246 uint8_t *pbDst = pbCopy;
6247 uint8_t const *pbSrc = pbSrcAndMask;
6248 switch (pCmd->andMaskDepth)
6249 {
6250 case 1:
6251 if (cbSrcAndLine == cbDstAndLine)
6252 memcpy(pbDst, pbSrc, cbSrcAndLine * cy);
6253 else
6254 {
6255 Assert(cbSrcAndLine > cbDstAndLine); /* lines are dword alined in source, but only byte in destination. */
6256 for (uint32_t y = 0; y < cy; y++)
6257 {
6258 memcpy(pbDst, pbSrc, cbDstAndLine);
6259 pbDst += cbDstAndLine;
6260 pbSrc += cbSrcAndLine;
6261 }
6262 }
6263 break;
6264 /* Should take the XOR mask into account for the multi-bit AND mask. */
6265 case 8:
6266 for (uint32_t y = 0; y < cy; y++)
6267 {
6268 for (uint32_t x = 0; x < cx; )
6269 {
6270 uint8_t bDst = 0;
6271 uint8_t fBit = 0x80;
6272 do
6273 {
6274 uintptr_t const idxPal = pbSrc[x] * 3;
6275 if ((( pThis->last_palette[idxPal]
6276 | (pThis->last_palette[idxPal] >> 8)
6277 | (pThis->last_palette[idxPal] >> 16)) & 0xff) > 0xfc)
6278 bDst |= fBit;
6279 fBit >>= 1;
6280 x++;
6281 } while (x < cx && (x & 7));
6282 pbDst[(x - 1) / 8] = bDst;
6283 }
6284 pbDst += cbDstAndLine;
6285 pbSrc += cbSrcAndLine;
6286 }
6287 break;
6288 case 15:
6289 for (uint32_t y = 0; y < cy; y++)
6290 {
6291 for (uint32_t x = 0; x < cx; )
6292 {
6293 uint8_t bDst = 0;
6294 uint8_t fBit = 0x80;
6295 do
6296 {
6297 if ((pbSrc[x * 2] | (pbSrc[x * 2 + 1] & 0x7f)) >= 0xfc)
6298 bDst |= fBit;
6299 fBit >>= 1;
6300 x++;
6301 } while (x < cx && (x & 7));
6302 pbDst[(x - 1) / 8] = bDst;
6303 }
6304 pbDst += cbDstAndLine;
6305 pbSrc += cbSrcAndLine;
6306 }
6307 break;
6308 case 16:
6309 for (uint32_t y = 0; y < cy; y++)
6310 {
6311 for (uint32_t x = 0; x < cx; )
6312 {
6313 uint8_t bDst = 0;
6314 uint8_t fBit = 0x80;
6315 do
6316 {
6317 if ((pbSrc[x * 2] | pbSrc[x * 2 + 1]) >= 0xfc)
6318 bDst |= fBit;
6319 fBit >>= 1;
6320 x++;
6321 } while (x < cx && (x & 7));
6322 pbDst[(x - 1) / 8] = bDst;
6323 }
6324 pbDst += cbDstAndLine;
6325 pbSrc += cbSrcAndLine;
6326 }
6327 break;
6328 case 24:
6329 for (uint32_t y = 0; y < cy; y++)
6330 {
6331 for (uint32_t x = 0; x < cx; )
6332 {
6333 uint8_t bDst = 0;
6334 uint8_t fBit = 0x80;
6335 do
6336 {
6337 if ((pbSrc[x * 3] | pbSrc[x * 3 + 1] | pbSrc[x * 3 + 2]) >= 0xfc)
6338 bDst |= fBit;
6339 fBit >>= 1;
6340 x++;
6341 } while (x < cx && (x & 7));
6342 pbDst[(x - 1) / 8] = bDst;
6343 }
6344 pbDst += cbDstAndLine;
6345 pbSrc += cbSrcAndLine;
6346 }
6347 break;
6348 case 32:
6349 for (uint32_t y = 0; y < cy; y++)
6350 {
6351 for (uint32_t x = 0; x < cx; )
6352 {
6353 uint8_t bDst = 0;
6354 uint8_t fBit = 0x80;
6355 do
6356 {
6357 if ((pbSrc[x * 4] | pbSrc[x * 4 + 1] | pbSrc[x * 4 + 2] | pbSrc[x * 4 + 3]) >= 0xfc)
6358 bDst |= fBit;
6359 fBit >>= 1;
6360 x++;
6361 } while (x < cx && (x & 7));
6362 pbDst[(x - 1) / 8] = bDst;
6363 }
6364 pbDst += cbDstAndLine;
6365 pbSrc += cbSrcAndLine;
6366 }
6367 break;
6368 default:
6369 RTMemFreeZ(pbCopy, cbCopy);
6370 AssertFailedReturnVoid();
6371 }
6372
6373 /* Convert the XOR mask. */
6374 uint32_t *pu32Dst = (uint32_t *)(pbCopy + RT_ALIGN_32(cbDstAndMask, 4));
6375 pbSrc = pbSrcXorMask;
6376 switch (pCmd->xorMaskDepth)
6377 {
6378 case 1:
6379 for (uint32_t y = 0; y < cy; y++)
6380 {
6381 for (uint32_t x = 0; x < cx; )
6382 {
6383 /* most significant bit is the left most one. */
6384 uint8_t bSrc = pbSrc[x / 8];
6385 do
6386 {
6387 *pu32Dst++ = bSrc & 0x80 ? UINT32_C(0x00ffffff) : 0;
6388 bSrc <<= 1;
6389 x++;
6390 } while ((x & 7) && x < cx);
6391 }
6392 pbSrc += cbSrcXorLine;
6393 }
6394 break;
6395 case 8:
6396 for (uint32_t y = 0; y < cy; y++)
6397 {
6398 for (uint32_t x = 0; x < cx; x++)
6399 {
6400 uint32_t u = pThis->last_palette[pbSrc[x]];
6401 *pu32Dst++ = u;//RT_MAKE_U32_FROM_U8(RT_BYTE1(u), RT_BYTE2(u), RT_BYTE3(u), 0);
6402 }
6403 pbSrc += cbSrcXorLine;
6404 }
6405 break;
6406 case 15: /* Src: RGB-5-5-5 */
6407 for (uint32_t y = 0; y < cy; y++)
6408 {
6409 for (uint32_t x = 0; x < cx; x++)
6410 {
6411 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
6412 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
6413 ((uValue >> 5) & 0x1f) << 3,
6414 ((uValue >> 10) & 0x1f) << 3, 0);
6415 }
6416 pbSrc += cbSrcXorLine;
6417 }
6418 break;
6419 case 16: /* Src: RGB-5-6-5 */
6420 for (uint32_t y = 0; y < cy; y++)
6421 {
6422 for (uint32_t x = 0; x < cx; x++)
6423 {
6424 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
6425 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
6426 ((uValue >> 5) & 0x3f) << 2,
6427 ((uValue >> 11) & 0x1f) << 3, 0);
6428 }
6429 pbSrc += cbSrcXorLine;
6430 }
6431 break;
6432 case 24:
6433 for (uint32_t y = 0; y < cy; y++)
6434 {
6435 for (uint32_t x = 0; x < cx; x++)
6436 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*3], pbSrc[x*3 + 1], pbSrc[x*3 + 2], 0);
6437 pbSrc += cbSrcXorLine;
6438 }
6439 break;
6440 case 32:
6441 for (uint32_t y = 0; y < cy; y++)
6442 {
6443 for (uint32_t x = 0; x < cx; x++)
6444 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*4], pbSrc[x*4 + 1], pbSrc[x*4 + 2], 0);
6445 pbSrc += cbSrcXorLine;
6446 }
6447 break;
6448 default:
6449 RTMemFreeZ(pbCopy, cbCopy);
6450 AssertFailedReturnVoid();
6451 }
6452
6453 /*
6454 * Pass it to the frontend/whatever.
6455 */
6456 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, false /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
6457 cx, cy, pbCopy, cbCopy);
6458}
6459
6460
6461/* SVGA_CMD_DEFINE_ALPHA_CURSOR */
6462void vmsvgaR3CmdDefineAlphaCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineAlphaCursor const *pCmd)
6463{
6464 RT_NOREF(pThis);
6465 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6466
6467 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineAlphaCursor);
6468 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));
6469
6470 /* Check against a reasonable upper limit to prevent integer overflows in the sanity checks below. */
6471 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
6472 RT_UNTRUSTED_VALIDATED_FENCE();
6473
6474 /* The mouse pointer interface always expects an AND mask followed by the color data (XOR mask). */
6475 uint32_t cbAndMask = (pCmd->width + 7) / 8 * pCmd->height; /* size of the AND mask */
6476 cbAndMask = ((cbAndMask + 3) & ~3); /* + gap for alignment */
6477 uint32_t cbXorMask = pCmd->width * sizeof(uint32_t) * pCmd->height; /* + size of the XOR mask (32-bit BRGA format) */
6478 uint32_t cbCursorShape = cbAndMask + cbXorMask;
6479
6480 uint8_t *pCursorCopy = (uint8_t *)RTMemAlloc(cbCursorShape);
6481 AssertPtrReturnVoid(pCursorCopy);
6482
6483 /* Transparency is defined by the alpha bytes, so make the whole bitmap visible. */
6484 memset(pCursorCopy, 0xff, cbAndMask);
6485 /* Colour data */
6486 memcpy(pCursorCopy + cbAndMask, pCmd + 1, cbXorMask);
6487
6488 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, true /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
6489 pCmd->width, pCmd->height, pCursorCopy, cbCursorShape);
6490}
6491
6492
6493/* SVGA_CMD_ESCAPE */
6494void vmsvgaR3CmdEscape(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdEscape const *pCmd)
6495{
6496 RT_NOREF(pThis);
6497 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6498
6499 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdEscape);
6500
6501 if (pCmd->nsid == SVGA_ESCAPE_NSID_VMWARE)
6502 {
6503 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(uint32_t));
6504 RT_UNTRUSTED_VALIDATED_FENCE();
6505
6506 uint32_t const cmd = *(uint32_t *)(pCmd + 1);
6507 Log(("SVGA_CMD_ESCAPE (%#x %#x) VMWARE cmd=%#x\n", pCmd->nsid, pCmd->size, cmd));
6508
6509 switch (cmd)
6510 {
6511 case SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS:
6512 {
6513 SVGAEscapeVideoSetRegs *pVideoCmd = (SVGAEscapeVideoSetRegs *)(pCmd + 1);
6514 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(pVideoCmd->header));
6515 RT_UNTRUSTED_VALIDATED_FENCE();
6516
6517 uint32_t const cRegs = (pCmd->size - sizeof(pVideoCmd->header)) / sizeof(pVideoCmd->items[0]);
6518
6519 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: stream %#x\n", pVideoCmd->header.streamId));
6520 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
6521 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: reg %#x val %#x\n", pVideoCmd->items[iReg].registerId, pVideoCmd->items[iReg].value));
6522 RT_NOREF_PV(pVideoCmd);
6523 break;
6524 }
6525
6526 case SVGA_ESCAPE_VMWARE_VIDEO_FLUSH:
6527 {
6528 SVGAEscapeVideoFlush *pVideoCmd = (SVGAEscapeVideoFlush *)(pCmd + 1);
6529 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(*pVideoCmd));
6530 Log(("SVGA_ESCAPE_VMWARE_VIDEO_FLUSH: stream %#x\n", pVideoCmd->streamId));
6531 RT_NOREF_PV(pVideoCmd);
6532 break;
6533 }
6534
6535 default:
6536 Log(("SVGA_CMD_ESCAPE: Unknown vmware escape: %#x\n", cmd));
6537 break;
6538 }
6539 }
6540 else
6541 Log(("SVGA_CMD_ESCAPE %#x %#x\n", pCmd->nsid, pCmd->size));
6542}
6543
6544
6545/* SVGA_CMD_DEFINE_SCREEN */
6546void vmsvgaR3CmdDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineScreen const *pCmd)
6547{
6548 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6549
6550 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineScreen);
6551 Log(("SVGA_CMD_DEFINE_SCREEN id=%x flags=%x size=(%d,%d) root=(%d,%d) %d:0x%x 0x%x\n",
6552 pCmd->screen.id, pCmd->screen.flags, pCmd->screen.size.width, pCmd->screen.size.height, pCmd->screen.root.x, pCmd->screen.root.y,
6553 pCmd->screen.backingStore.ptr.gmrId, pCmd->screen.backingStore.ptr.offset, pCmd->screen.backingStore.pitch));
6554
6555 uint32_t const idScreen = pCmd->screen.id;
6556 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
6557
6558 uint32_t const uWidth = pCmd->screen.size.width;
6559 ASSERT_GUEST_RETURN_VOID(uWidth <= pThis->svga.u32MaxWidth);
6560
6561 uint32_t const uHeight = pCmd->screen.size.height;
6562 ASSERT_GUEST_RETURN_VOID(uHeight <= pThis->svga.u32MaxHeight);
6563
6564 uint32_t const cbWidth = uWidth * ((32 + 7) / 8); /** @todo 32? */
6565 uint32_t const cbPitch = pCmd->screen.backingStore.pitch ? pCmd->screen.backingStore.pitch : cbWidth;
6566 ASSERT_GUEST_RETURN_VOID(cbWidth <= cbPitch);
6567
6568 uint32_t const uScreenOffset = pCmd->screen.backingStore.ptr.offset;
6569 ASSERT_GUEST_RETURN_VOID(uScreenOffset < pThis->vram_size);
6570
6571 uint32_t const cbVram = pThis->vram_size - uScreenOffset;
6572 /* If we have a not zero pitch, then height can't exceed the available VRAM. */
6573 ASSERT_GUEST_RETURN_VOID( (uHeight == 0 && cbPitch == 0)
6574 || (cbPitch > 0 && uHeight <= cbVram / cbPitch));
6575 RT_UNTRUSTED_VALIDATED_FENCE();
6576
6577 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
6578 pScreen->fDefined = true;
6579 pScreen->fModified = true;
6580 pScreen->fuScreen = pCmd->screen.flags;
6581 pScreen->idScreen = idScreen;
6582 if (!RT_BOOL(pCmd->screen.flags & (SVGA_SCREEN_DEACTIVATE | SVGA_SCREEN_BLANKING)))
6583 {
6584 /* Not blanked. */
6585 ASSERT_GUEST_RETURN_VOID(uWidth > 0 && uHeight > 0);
6586 RT_UNTRUSTED_VALIDATED_FENCE();
6587
6588 pScreen->xOrigin = pCmd->screen.root.x;
6589 pScreen->yOrigin = pCmd->screen.root.y;
6590 pScreen->cWidth = uWidth;
6591 pScreen->cHeight = uHeight;
6592 pScreen->offVRAM = uScreenOffset;
6593 pScreen->cbPitch = cbPitch;
6594 pScreen->cBpp = 32;
6595 }
6596 else
6597 {
6598 /* Screen blanked. Keep old values. */
6599 }
6600
6601 pThis->svga.fGFBRegisters = false;
6602 vmsvgaR3ChangeMode(pThis, pThisCC);
6603
6604#ifdef VBOX_WITH_VMSVGA3D
6605 if (RT_LIKELY(pThis->svga.f3DEnabled))
6606 vmsvga3dDefineScreen(pThis, pThisCC, pScreen);
6607#endif
6608}
6609
6610
6611/* SVGA_CMD_DESTROY_SCREEN */
6612void vmsvgaR3CmdDestroyScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDestroyScreen const *pCmd)
6613{
6614 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6615
6616 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDestroyScreen);
6617 Log(("SVGA_CMD_DESTROY_SCREEN id=%x\n", pCmd->screenId));
6618
6619 uint32_t const idScreen = pCmd->screenId;
6620 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
6621 RT_UNTRUSTED_VALIDATED_FENCE();
6622
6623 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
6624 pScreen->fModified = true;
6625 pScreen->fDefined = false;
6626 pScreen->idScreen = idScreen;
6627
6628#ifdef VBOX_WITH_VMSVGA3D
6629 if (RT_LIKELY(pThis->svga.f3DEnabled))
6630 vmsvga3dDestroyScreen(pThisCC, pScreen);
6631#endif
6632 vmsvgaR3ChangeMode(pThis, pThisCC);
6633}
6634
6635
6636/* SVGA_CMD_DEFINE_GMRFB */
6637void vmsvgaR3CmdDefineGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMRFB const *pCmd)
6638{
6639 RT_NOREF(pThis);
6640 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6641
6642 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmrFb);
6643 Log(("SVGA_CMD_DEFINE_GMRFB gmr=%x offset=%x bytesPerLine=%x bpp=%d color depth=%d\n",
6644 pCmd->ptr.gmrId, pCmd->ptr.offset, pCmd->bytesPerLine, pCmd->format.bitsPerPixel, pCmd->format.colorDepth));
6645
6646 pSvgaR3State->GMRFB.ptr = pCmd->ptr;
6647 pSvgaR3State->GMRFB.bytesPerLine = pCmd->bytesPerLine;
6648 pSvgaR3State->GMRFB.format = pCmd->format;
6649}
6650
6651
6652/* SVGA_CMD_BLIT_GMRFB_TO_SCREEN */
6653void vmsvgaR3CmdBlitGMRFBToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitGMRFBToScreen const *pCmd)
6654{
6655 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6656
6657 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitGmrFbToScreen);
6658 Log(("SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n",
6659 pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
6660
6661 ASSERT_GUEST_RETURN_VOID(pCmd->destScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
6662 RT_UNTRUSTED_VALIDATED_FENCE();
6663
6664 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->destScreenId);
6665 AssertPtrReturnVoid(pScreen);
6666
6667 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp ? */
6668 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
6669
6670 /* Clip destRect to the screen dimensions. */
6671 SVGASignedRect screenRect;
6672 screenRect.left = 0;
6673 screenRect.top = 0;
6674 screenRect.right = pScreen->cWidth;
6675 screenRect.bottom = pScreen->cHeight;
6676 SVGASignedRect clipRect = pCmd->destRect;
6677 vmsvgaR3ClipRect(&screenRect, &clipRect);
6678 RT_UNTRUSTED_VALIDATED_FENCE();
6679
6680 uint32_t const width = clipRect.right - clipRect.left;
6681 uint32_t const height = clipRect.bottom - clipRect.top;
6682
6683 if ( width == 0
6684 || height == 0)
6685 return; /* Nothing to do. */
6686
6687 int32_t const srcx = pCmd->srcOrigin.x + (clipRect.left - pCmd->destRect.left);
6688 int32_t const srcy = pCmd->srcOrigin.y + (clipRect.top - pCmd->destRect.top);
6689
6690 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
6691 * Prepare parameters for vmsvgaR3GmrTransfer.
6692 */
6693 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
6694
6695 /* Destination: host buffer which describes the screen 0 VRAM.
6696 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
6697 */
6698 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
6699 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
6700 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
6701 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
6702 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
6703 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
6704 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
6705 + cbScanline * clipRect.top;
6706 int32_t const cbHstPitch = cbScanline;
6707
6708 /* Source: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
6709 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
6710 uint32_t const offGst = (srcx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
6711 + pSvgaR3State->GMRFB.bytesPerLine * srcy;
6712 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
6713
6714 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_WRITE_HOST_VRAM,
6715 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
6716 gstPtr, offGst, cbGstPitch,
6717 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
6718 AssertRC(rc);
6719 vmsvgaR3UpdateScreen(pThisCC, pScreen, clipRect.left, clipRect.top, width, height);
6720}
6721
6722
6723/* SVGA_CMD_BLIT_SCREEN_TO_GMRFB */
6724void vmsvgaR3CmdBlitScreenToGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitScreenToGMRFB const *pCmd)
6725{
6726 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6727
6728 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitScreentoGmrFb);
6729 /* Note! This can fetch 3d render results as well!! */
6730 Log(("SVGA_CMD_BLIT_SCREEN_TO_GMRFB dest=(%d,%d) src id=%d (%d,%d)(%d,%d)\n",
6731 pCmd->destOrigin.x, pCmd->destOrigin.y, pCmd->srcScreenId, pCmd->srcRect.left, pCmd->srcRect.top, pCmd->srcRect.right, pCmd->srcRect.bottom));
6732
6733 ASSERT_GUEST_RETURN_VOID(pCmd->srcScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
6734 RT_UNTRUSTED_VALIDATED_FENCE();
6735
6736 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->srcScreenId);
6737 AssertPtrReturnVoid(pScreen);
6738
6739 /** @todo Support GMRFB.format.bitsPerPixel != pThis->svga.uBpp ? */
6740 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
6741
6742 /* Clip destRect to the screen dimensions. */
6743 SVGASignedRect screenRect;
6744 screenRect.left = 0;
6745 screenRect.top = 0;
6746 screenRect.right = pScreen->cWidth;
6747 screenRect.bottom = pScreen->cHeight;
6748 SVGASignedRect clipRect = pCmd->srcRect;
6749 vmsvgaR3ClipRect(&screenRect, &clipRect);
6750 RT_UNTRUSTED_VALIDATED_FENCE();
6751
6752 uint32_t const width = clipRect.right - clipRect.left;
6753 uint32_t const height = clipRect.bottom - clipRect.top;
6754
6755 if ( width == 0
6756 || height == 0)
6757 return; /* Nothing to do. */
6758
6759 int32_t const dstx = pCmd->destOrigin.x + (clipRect.left - pCmd->srcRect.left);
6760 int32_t const dsty = pCmd->destOrigin.y + (clipRect.top - pCmd->srcRect.top);
6761
6762 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
6763 * Prepare parameters for vmsvgaR3GmrTransfer.
6764 */
6765 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
6766
6767 /* Source: host buffer which describes the screen 0 VRAM.
6768 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
6769 */
6770 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
6771 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
6772 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
6773 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
6774 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
6775 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
6776 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
6777 + cbScanline * clipRect.top;
6778 int32_t const cbHstPitch = cbScanline;
6779
6780 /* Destination: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
6781 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
6782 uint32_t const offGst = (dstx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
6783 + pSvgaR3State->GMRFB.bytesPerLine * dsty;
6784 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
6785
6786 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_READ_HOST_VRAM,
6787 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
6788 gstPtr, offGst, cbGstPitch,
6789 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
6790 AssertRC(rc);
6791}
6792
6793
6794/* SVGA_CMD_ANNOTATION_FILL */
6795void vmsvgaR3CmdAnnotationFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationFill const *pCmd)
6796{
6797 RT_NOREF(pThis);
6798 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6799
6800 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationFill);
6801 Log(("SVGA_CMD_ANNOTATION_FILL red=%x green=%x blue=%x\n", pCmd->color.r, pCmd->color.g, pCmd->color.b));
6802
6803 pSvgaR3State->colorAnnotation = pCmd->color;
6804}
6805
6806
6807/* SVGA_CMD_ANNOTATION_COPY */
6808void vmsvgaR3CmdAnnotationCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationCopy const *pCmd)
6809{
6810 RT_NOREF(pThis, pCmd);
6811 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6812
6813 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationCopy);
6814 Log(("SVGA_CMD_ANNOTATION_COPY srcOrigin %d,%d, srcScreenId %u\n", pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->srcScreenId));
6815
6816 AssertFailed();
6817}
6818
6819
6820#ifdef VBOX_WITH_VMSVGA3D
6821/* SVGA_CMD_DEFINE_GMR2 */
6822void vmsvgaR3CmdDefineGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMR2 const *pCmd)
6823{
6824 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6825
6826 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2);
6827 Log(("SVGA_CMD_DEFINE_GMR2 id=%#x %#x pages\n", pCmd->gmrId, pCmd->numPages));
6828
6829 /* Validate current GMR id. */
6830 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
6831 ASSERT_GUEST_RETURN_VOID(pCmd->numPages <= VMSVGA_MAX_GMR_PAGES);
6832 RT_UNTRUSTED_VALIDATED_FENCE();
6833
6834 if (!pCmd->numPages)
6835 {
6836 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Free);
6837 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
6838 }
6839 else
6840 {
6841 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
6842 if (pGMR->cMaxPages)
6843 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Modify);
6844
6845 /* Not sure if we should always free the descriptor, but for simplicity
6846 we do so if the new size is smaller than the current. */
6847 /** @todo always free the descriptor in SVGA_CMD_DEFINE_GMR2? */
6848 if (pGMR->cbTotal / X86_PAGE_SIZE > pCmd->numPages)
6849 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
6850
6851 pGMR->cMaxPages = pCmd->numPages;
6852 /* The rest is done by the REMAP_GMR2 command. */
6853 }
6854}
6855
6856
6857/* SVGA_CMD_REMAP_GMR2 */
6858void vmsvgaR3CmdRemapGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRemapGMR2 const *pCmd)
6859{
6860 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6861
6862 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2);
6863 Log(("SVGA_CMD_REMAP_GMR2 id=%#x flags=%#x offset=%#x npages=%#x\n", pCmd->gmrId, pCmd->flags, pCmd->offsetPages, pCmd->numPages));
6864
6865 /* Validate current GMR id and size. */
6866 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
6867 RT_UNTRUSTED_VALIDATED_FENCE();
6868 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
6869 ASSERT_GUEST_RETURN_VOID( (uint64_t)pCmd->offsetPages + pCmd->numPages
6870 <= RT_MIN(pGMR->cMaxPages, RT_MIN(VMSVGA_MAX_GMR_PAGES, UINT32_MAX / X86_PAGE_SIZE)));
6871 ASSERT_GUEST_RETURN_VOID(!pCmd->offsetPages || pGMR->paDesc); /** @todo */
6872
6873 if (pCmd->numPages == 0)
6874 return;
6875 RT_UNTRUSTED_VALIDATED_FENCE();
6876
6877 /* Calc new total page count so we can use it instead of cMaxPages for allocations below. */
6878 uint32_t const cNewTotalPages = RT_MAX(pGMR->cbTotal >> X86_PAGE_SHIFT, pCmd->offsetPages + pCmd->numPages);
6879
6880 /*
6881 * We flatten the existing descriptors into a page array, overwrite the
6882 * pages specified in this command and then recompress the descriptor.
6883 */
6884 /** @todo Optimize the GMR remap algorithm! */
6885
6886 /* Save the old page descriptors as an array of page frame numbers (address >> X86_PAGE_SHIFT) */
6887 uint64_t *paNewPage64 = NULL;
6888 if (pGMR->paDesc)
6889 {
6890 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2Modify);
6891
6892 paNewPage64 = (uint64_t *)RTMemAllocZ(cNewTotalPages * sizeof(uint64_t));
6893 AssertPtrReturnVoid(paNewPage64);
6894
6895 uint32_t idxPage = 0;
6896 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
6897 for (uint32_t j = 0; j < pGMR->paDesc[i].numPages; j++)
6898 paNewPage64[idxPage++] = (pGMR->paDesc[i].GCPhys + j * X86_PAGE_SIZE) >> X86_PAGE_SHIFT;
6899 AssertReturnVoidStmt(idxPage == pGMR->cbTotal >> X86_PAGE_SHIFT, RTMemFree(paNewPage64));
6900 RT_UNTRUSTED_VALIDATED_FENCE();
6901 }
6902
6903 /* Free the old GMR if present. */
6904 if (pGMR->paDesc)
6905 RTMemFree(pGMR->paDesc);
6906
6907 /* Allocate the maximum amount possible (everything non-continuous) */
6908 PVMSVGAGMRDESCRIPTOR paDescs;
6909 pGMR->paDesc = paDescs = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(cNewTotalPages * sizeof(VMSVGAGMRDESCRIPTOR));
6910 AssertReturnVoidStmt(paDescs, RTMemFree(paNewPage64));
6911
6912 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
6913 {
6914 /** @todo */
6915 AssertFailed();
6916 pGMR->numDescriptors = 0;
6917 }
6918 else
6919 {
6920 uint32_t *paPages32 = (uint32_t *)(pCmd + 1);
6921 uint64_t *paPages64 = (uint64_t *)(pCmd + 1);
6922 bool fGCPhys64 = RT_BOOL(pCmd->flags & SVGA_REMAP_GMR2_PPN64);
6923
6924 uint32_t cPages;
6925 if (paNewPage64)
6926 {
6927 /* Overwrite the old page array with the new page values. */
6928 if (fGCPhys64)
6929 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
6930 paNewPage64[i] = paPages64[i - pCmd->offsetPages];
6931 else
6932 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
6933 paNewPage64[i] = paPages32[i - pCmd->offsetPages];
6934
6935 /* Use the updated page array instead of the command data. */
6936 fGCPhys64 = true;
6937 paPages64 = paNewPage64;
6938 cPages = cNewTotalPages;
6939 }
6940 else
6941 cPages = pCmd->numPages;
6942
6943 /* The first page. */
6944 /** @todo The 0x00000FFFFFFFFFFF mask limits to 44 bits and should not be
6945 * applied to paNewPage64. */
6946 RTGCPHYS GCPhys;
6947 if (fGCPhys64)
6948 GCPhys = (paPages64[0] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
6949 else
6950 GCPhys = (RTGCPHYS)paPages32[0] << PAGE_SHIFT;
6951 paDescs[0].GCPhys = GCPhys;
6952 paDescs[0].numPages = 1;
6953
6954 /* Subsequent pages. */
6955 uint32_t iDescriptor = 0;
6956 for (uint32_t i = 1; i < cPages; i++)
6957 {
6958 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
6959 GCPhys = (paPages64[i] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
6960 else
6961 GCPhys = (RTGCPHYS)paPages32[i] << X86_PAGE_SHIFT;
6962
6963 /* Continuous physical memory? */
6964 if (GCPhys == paDescs[iDescriptor].GCPhys + paDescs[iDescriptor].numPages * X86_PAGE_SIZE)
6965 {
6966 Assert(paDescs[iDescriptor].numPages);
6967 paDescs[iDescriptor].numPages++;
6968 Log5Func(("Page %x GCPhys=%RGp successor\n", i, GCPhys));
6969 }
6970 else
6971 {
6972 iDescriptor++;
6973 paDescs[iDescriptor].GCPhys = GCPhys;
6974 paDescs[iDescriptor].numPages = 1;
6975 Log5Func(("Page %x GCPhys=%RGp\n", i, paDescs[iDescriptor].GCPhys));
6976 }
6977 }
6978
6979 pGMR->cbTotal = cNewTotalPages << X86_PAGE_SHIFT;
6980 Log5Func(("Nr of descriptors %x; cbTotal=%#x\n", iDescriptor + 1, cNewTotalPages));
6981 pGMR->numDescriptors = iDescriptor + 1;
6982 }
6983
6984 if (paNewPage64)
6985 RTMemFree(paNewPage64);
6986}
6987
6988
6989/**
6990 * Free the specified GMR
6991 *
6992 * @param pThisCC The VGA/VMSVGA state for ring-3.
6993 * @param idGMR GMR id
6994 */
6995void vmsvgaR3GmrFree(PVGASTATECC pThisCC, uint32_t idGMR)
6996{
6997 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
6998
6999 /* Free the old descriptor if present. */
7000 PGMR pGMR = &pSVGAState->paGMR[idGMR];
7001 if ( pGMR->numDescriptors
7002 || pGMR->paDesc /* needed till we implement SVGA_REMAP_GMR2_VIA_GMR */)
7003 {
7004# ifdef DEBUG_GMR_ACCESS
7005 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThisCC->pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3DeregisterGmr, 2, pDevIns, idGMR);
7006# endif
7007
7008 Assert(pGMR->paDesc);
7009 RTMemFree(pGMR->paDesc);
7010 pGMR->paDesc = NULL;
7011 pGMR->numDescriptors = 0;
7012 pGMR->cbTotal = 0;
7013 pGMR->cMaxPages = 0;
7014 }
7015 Assert(!pGMR->cMaxPages);
7016 Assert(!pGMR->cbTotal);
7017}
7018#endif /* VBOX_WITH_VMSVGA3D */
7019
7020
7021/**
7022 * Copy between a GMR and a host memory buffer.
7023 *
7024 * @returns VBox status code.
7025 * @param pThis The shared VGA/VMSVGA instance data.
7026 * @param pThisCC The VGA/VMSVGA state for ring-3.
7027 * @param enmTransferType Transfer type (read/write)
7028 * @param pbHstBuf Host buffer pointer (valid)
7029 * @param cbHstBuf Size of host buffer (valid)
7030 * @param offHst Host buffer offset of the first scanline
7031 * @param cbHstPitch Destination buffer pitch
7032 * @param gstPtr GMR description
7033 * @param offGst Guest buffer offset of the first scanline
7034 * @param cbGstPitch Guest buffer pitch
7035 * @param cbWidth Width in bytes to copy
7036 * @param cHeight Number of scanllines to copy
7037 */
7038int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
7039 uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
7040 SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
7041 uint32_t cbWidth, uint32_t cHeight)
7042{
7043 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
7044 PPDMDEVINS pDevIns = pThisCC->pDevIns; /* simpler */
7045 int rc;
7046
7047 LogFunc(("%s host %p size=%d offset %d pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
7048 enmTransferType == SVGA3D_READ_HOST_VRAM ? "WRITE" : "READ", /* GMR op: READ host VRAM means WRITE GMR */
7049 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
7050 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cbWidth, cHeight));
7051 AssertReturn(cbWidth && cHeight, VERR_INVALID_PARAMETER);
7052
7053 PGMR pGMR;
7054 uint32_t cbGmr; /* The GMR size in bytes. */
7055 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
7056 {
7057 pGMR = NULL;
7058 cbGmr = pThis->vram_size;
7059 }
7060 else
7061 {
7062 AssertReturn(gstPtr.gmrId < pThis->svga.cGMR, VERR_INVALID_PARAMETER);
7063 RT_UNTRUSTED_VALIDATED_FENCE();
7064 pGMR = &pSVGAState->paGMR[gstPtr.gmrId];
7065 cbGmr = pGMR->cbTotal;
7066 }
7067
7068 /*
7069 * GMR
7070 */
7071 /* Calculate GMR offset of the data to be copied. */
7072 AssertMsgReturn(gstPtr.offset < cbGmr,
7073 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7074 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7075 VERR_INVALID_PARAMETER);
7076 RT_UNTRUSTED_VALIDATED_FENCE();
7077 AssertMsgReturn(offGst < cbGmr - gstPtr.offset,
7078 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7079 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7080 VERR_INVALID_PARAMETER);
7081 RT_UNTRUSTED_VALIDATED_FENCE();
7082 uint32_t const offGmr = offGst + gstPtr.offset; /* Offset in the GMR, where the first scanline is located. */
7083
7084 /* Verify that cbWidth is less than scanline and fits into the GMR. */
7085 uint32_t const cbGmrScanline = cbGstPitch > 0 ? cbGstPitch : -cbGstPitch;
7086 AssertMsgReturn(cbGmrScanline != 0,
7087 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7088 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7089 VERR_INVALID_PARAMETER);
7090 RT_UNTRUSTED_VALIDATED_FENCE();
7091 AssertMsgReturn(cbWidth <= cbGmrScanline,
7092 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7093 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7094 VERR_INVALID_PARAMETER);
7095 AssertMsgReturn(cbWidth <= cbGmr - offGmr,
7096 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7097 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7098 VERR_INVALID_PARAMETER);
7099 RT_UNTRUSTED_VALIDATED_FENCE();
7100
7101 /* How many bytes are available for the data in the GMR. */
7102 uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmr - offGmr : offGmr + cbWidth;
7103
7104 /* How many scanlines would fit into the available data. */
7105 uint32_t cGmrScanlines = cbGmrLeft / cbGmrScanline;
7106 uint32_t const cbGmrLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
7107 if (cbWidth <= cbGmrLastScanline)
7108 ++cGmrScanlines;
7109
7110 if (cHeight > cGmrScanlines)
7111 cHeight = cGmrScanlines;
7112
7113 AssertMsgReturn(cHeight > 0,
7114 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7115 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7116 VERR_INVALID_PARAMETER);
7117 RT_UNTRUSTED_VALIDATED_FENCE();
7118
7119 /*
7120 * Host buffer.
7121 */
7122 AssertMsgReturn(offHst < cbHstBuf,
7123 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7124 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7125 VERR_INVALID_PARAMETER);
7126
7127 /* Verify that cbWidth is less than scanline and fits into the buffer. */
7128 uint32_t const cbHstScanline = cbHstPitch > 0 ? cbHstPitch : -cbHstPitch;
7129 AssertMsgReturn(cbHstScanline != 0,
7130 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7131 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7132 VERR_INVALID_PARAMETER);
7133 AssertMsgReturn(cbWidth <= cbHstScanline,
7134 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7135 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7136 VERR_INVALID_PARAMETER);
7137 AssertMsgReturn(cbWidth <= cbHstBuf - offHst,
7138 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7139 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7140 VERR_INVALID_PARAMETER);
7141
7142 /* How many bytes are available for the data in the buffer. */
7143 uint32_t const cbHstLeft = cbHstPitch > 0 ? cbHstBuf - offHst : offHst + cbWidth;
7144
7145 /* How many scanlines would fit into the available data. */
7146 uint32_t cHstScanlines = cbHstLeft / cbHstScanline;
7147 uint32_t const cbHstLastScanline = cbHstLeft - cHstScanlines * cbHstScanline; /* Slack space. */
7148 if (cbWidth <= cbHstLastScanline)
7149 ++cHstScanlines;
7150
7151 if (cHeight > cHstScanlines)
7152 cHeight = cHstScanlines;
7153
7154 AssertMsgReturn(cHeight > 0,
7155 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7156 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7157 VERR_INVALID_PARAMETER);
7158
7159 uint8_t *pbHst = pbHstBuf + offHst;
7160
7161 /* Shortcut for the framebuffer. */
7162 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
7163 {
7164 uint8_t *pbGst = pThisCC->pbVRam + offGmr;
7165
7166 uint8_t const *pbSrc;
7167 int32_t cbSrcPitch;
7168 uint8_t *pbDst;
7169 int32_t cbDstPitch;
7170
7171 if (enmTransferType == SVGA3D_READ_HOST_VRAM)
7172 {
7173 pbSrc = pbHst;
7174 cbSrcPitch = cbHstPitch;
7175 pbDst = pbGst;
7176 cbDstPitch = cbGstPitch;
7177 }
7178 else
7179 {
7180 pbSrc = pbGst;
7181 cbSrcPitch = cbGstPitch;
7182 pbDst = pbHst;
7183 cbDstPitch = cbHstPitch;
7184 }
7185
7186 if ( cbWidth == (uint32_t)cbGstPitch
7187 && cbGstPitch == cbHstPitch)
7188 {
7189 /* Entire scanlines, positive pitch. */
7190 memcpy(pbDst, pbSrc, cbWidth * cHeight);
7191 }
7192 else
7193 {
7194 for (uint32_t i = 0; i < cHeight; ++i)
7195 {
7196 memcpy(pbDst, pbSrc, cbWidth);
7197
7198 pbDst += cbDstPitch;
7199 pbSrc += cbSrcPitch;
7200 }
7201 }
7202 return VINF_SUCCESS;
7203 }
7204
7205 AssertPtrReturn(pGMR, VERR_INVALID_PARAMETER);
7206 AssertReturn(pGMR->numDescriptors > 0, VERR_INVALID_PARAMETER);
7207
7208 PVMSVGAGMRDESCRIPTOR const paDesc = pGMR->paDesc; /* Local copy of the pointer. */
7209 uint32_t iDesc = 0; /* Index in the descriptor array. */
7210 uint32_t offDesc = 0; /* GMR offset of the current descriptor. */
7211 uint32_t offGmrScanline = offGmr; /* GMR offset of the scanline which is being copied. */
7212 uint8_t *pbHstScanline = pbHst; /* Host address of the scanline which is being copied. */
7213 for (uint32_t i = 0; i < cHeight; ++i)
7214 {
7215 uint32_t cbCurrentWidth = cbWidth;
7216 uint32_t offGmrCurrent = offGmrScanline;
7217 uint8_t *pbCurrentHost = pbHstScanline;
7218
7219 /* Find the right descriptor */
7220 while (offDesc + paDesc[iDesc].numPages * PAGE_SIZE <= offGmrCurrent)
7221 {
7222 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
7223 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
7224 ++iDesc;
7225 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
7226 }
7227
7228 while (cbCurrentWidth)
7229 {
7230 uint32_t cbToCopy;
7231
7232 if (offGmrCurrent + cbCurrentWidth <= offDesc + paDesc[iDesc].numPages * PAGE_SIZE)
7233 {
7234 cbToCopy = cbCurrentWidth;
7235 }
7236 else
7237 {
7238 cbToCopy = (offDesc + paDesc[iDesc].numPages * PAGE_SIZE - offGmrCurrent);
7239 AssertReturn(cbToCopy <= cbCurrentWidth, VERR_INVALID_PARAMETER);
7240 }
7241
7242 RTGCPHYS const GCPhys = paDesc[iDesc].GCPhys + offGmrCurrent - offDesc;
7243
7244 Log5Func(("%s phys=%RGp\n", (enmTransferType == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", GCPhys));
7245
7246 /*
7247 * We are deliberately using the non-PCI version of PDMDevHlpPCIPhys[Read|Write] as the
7248 * guest-side VMSVGA driver seems to allocate non-DMA (physical memory) addresses,
7249 * see @bugref{9654#c75}.
7250 */
7251 if (enmTransferType == SVGA3D_WRITE_HOST_VRAM)
7252 rc = PDMDevHlpPhysRead(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
7253 else
7254 rc = PDMDevHlpPhysWrite(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
7255 AssertRCBreak(rc);
7256
7257 cbCurrentWidth -= cbToCopy;
7258 offGmrCurrent += cbToCopy;
7259 pbCurrentHost += cbToCopy;
7260
7261 /* Go to the next descriptor if there's anything left. */
7262 if (cbCurrentWidth)
7263 {
7264 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
7265 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR);
7266 ++iDesc;
7267 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
7268 }
7269 }
7270
7271 offGmrScanline += cbGstPitch;
7272 pbHstScanline += cbHstPitch;
7273 }
7274
7275 return VINF_SUCCESS;
7276}
7277
7278
7279/**
7280 * Unsigned coordinates in pBox. Clip to [0; pSizeSrc), [0; pSizeDest).
7281 *
7282 * @param pSizeSrc Source surface dimensions.
7283 * @param pSizeDest Destination surface dimensions.
7284 * @param pBox Coordinates to be clipped.
7285 */
7286void vmsvgaR3ClipCopyBox(const SVGA3dSize *pSizeSrc, const SVGA3dSize *pSizeDest, SVGA3dCopyBox *pBox)
7287{
7288 /* Src x, w */
7289 if (pBox->srcx > pSizeSrc->width)
7290 pBox->srcx = pSizeSrc->width;
7291 if (pBox->w > pSizeSrc->width - pBox->srcx)
7292 pBox->w = pSizeSrc->width - pBox->srcx;
7293
7294 /* Src y, h */
7295 if (pBox->srcy > pSizeSrc->height)
7296 pBox->srcy = pSizeSrc->height;
7297 if (pBox->h > pSizeSrc->height - pBox->srcy)
7298 pBox->h = pSizeSrc->height - pBox->srcy;
7299
7300 /* Src z, d */
7301 if (pBox->srcz > pSizeSrc->depth)
7302 pBox->srcz = pSizeSrc->depth;
7303 if (pBox->d > pSizeSrc->depth - pBox->srcz)
7304 pBox->d = pSizeSrc->depth - pBox->srcz;
7305
7306 /* Dest x, w */
7307 if (pBox->x > pSizeDest->width)
7308 pBox->x = pSizeDest->width;
7309 if (pBox->w > pSizeDest->width - pBox->x)
7310 pBox->w = pSizeDest->width - pBox->x;
7311
7312 /* Dest y, h */
7313 if (pBox->y > pSizeDest->height)
7314 pBox->y = pSizeDest->height;
7315 if (pBox->h > pSizeDest->height - pBox->y)
7316 pBox->h = pSizeDest->height - pBox->y;
7317
7318 /* Dest z, d */
7319 if (pBox->z > pSizeDest->depth)
7320 pBox->z = pSizeDest->depth;
7321 if (pBox->d > pSizeDest->depth - pBox->z)
7322 pBox->d = pSizeDest->depth - pBox->z;
7323}
7324
7325
7326/**
7327 * Unsigned coordinates in pBox. Clip to [0; pSize).
7328 *
7329 * @param pSize Source surface dimensions.
7330 * @param pBox Coordinates to be clipped.
7331 */
7332void vmsvgaR3ClipBox(const SVGA3dSize *pSize, SVGA3dBox *pBox)
7333{
7334 /* x, w */
7335 if (pBox->x > pSize->width)
7336 pBox->x = pSize->width;
7337 if (pBox->w > pSize->width - pBox->x)
7338 pBox->w = pSize->width - pBox->x;
7339
7340 /* y, h */
7341 if (pBox->y > pSize->height)
7342 pBox->y = pSize->height;
7343 if (pBox->h > pSize->height - pBox->y)
7344 pBox->h = pSize->height - pBox->y;
7345
7346 /* z, d */
7347 if (pBox->z > pSize->depth)
7348 pBox->z = pSize->depth;
7349 if (pBox->d > pSize->depth - pBox->z)
7350 pBox->d = pSize->depth - pBox->z;
7351}
7352
7353
7354/**
7355 * Clip.
7356 *
7357 * @param pBound Bounding rectangle.
7358 * @param pRect Rectangle to be clipped.
7359 */
7360void vmsvgaR3ClipRect(SVGASignedRect const *pBound, SVGASignedRect *pRect)
7361{
7362 int32_t left;
7363 int32_t top;
7364 int32_t right;
7365 int32_t bottom;
7366
7367 /* Right order. */
7368 Assert(pBound->left <= pBound->right && pBound->top <= pBound->bottom);
7369 if (pRect->left < pRect->right)
7370 {
7371 left = pRect->left;
7372 right = pRect->right;
7373 }
7374 else
7375 {
7376 left = pRect->right;
7377 right = pRect->left;
7378 }
7379 if (pRect->top < pRect->bottom)
7380 {
7381 top = pRect->top;
7382 bottom = pRect->bottom;
7383 }
7384 else
7385 {
7386 top = pRect->bottom;
7387 bottom = pRect->top;
7388 }
7389
7390 if (left < pBound->left)
7391 left = pBound->left;
7392 if (right < pBound->left)
7393 right = pBound->left;
7394
7395 if (left > pBound->right)
7396 left = pBound->right;
7397 if (right > pBound->right)
7398 right = pBound->right;
7399
7400 if (top < pBound->top)
7401 top = pBound->top;
7402 if (bottom < pBound->top)
7403 bottom = pBound->top;
7404
7405 if (top > pBound->bottom)
7406 top = pBound->bottom;
7407 if (bottom > pBound->bottom)
7408 bottom = pBound->bottom;
7409
7410 pRect->left = left;
7411 pRect->right = right;
7412 pRect->top = top;
7413 pRect->bottom = bottom;
7414}
7415
7416
7417/**
7418 * Clip.
7419 *
7420 * @param pBound Bounding rectangle.
7421 * @param pRect Rectangle to be clipped.
7422 */
7423void vmsvgaR3Clip3dRect(SVGA3dRect const *pBound, SVGA3dRect RT_UNTRUSTED_GUEST *pRect)
7424{
7425 uint32_t const leftBound = pBound->x;
7426 uint32_t const rightBound = pBound->x + pBound->w;
7427 uint32_t const topBound = pBound->y;
7428 uint32_t const bottomBound = pBound->y + pBound->h;
7429
7430 uint32_t x = pRect->x;
7431 uint32_t y = pRect->y;
7432 uint32_t w = pRect->w;
7433 uint32_t h = pRect->h;
7434
7435 /* Make sure that right and bottom coordinates can be safely computed. */
7436 if (x > rightBound)
7437 x = rightBound;
7438 if (w > rightBound - x)
7439 w = rightBound - x;
7440 if (y > bottomBound)
7441 y = bottomBound;
7442 if (h > bottomBound - y)
7443 h = bottomBound - y;
7444
7445 /* Switch from x, y, w, h to left, top, right, bottom. */
7446 uint32_t left = x;
7447 uint32_t right = x + w;
7448 uint32_t top = y;
7449 uint32_t bottom = y + h;
7450
7451 /* A standard left, right, bottom, top clipping. */
7452 if (left < leftBound)
7453 left = leftBound;
7454 if (right < leftBound)
7455 right = leftBound;
7456
7457 if (left > rightBound)
7458 left = rightBound;
7459 if (right > rightBound)
7460 right = rightBound;
7461
7462 if (top < topBound)
7463 top = topBound;
7464 if (bottom < topBound)
7465 bottom = topBound;
7466
7467 if (top > bottomBound)
7468 top = bottomBound;
7469 if (bottom > bottomBound)
7470 bottom = bottomBound;
7471
7472 /* Back to x, y, w, h representation. */
7473 pRect->x = left;
7474 pRect->y = top;
7475 pRect->w = right - left;
7476 pRect->h = bottom - top;
7477}
7478
Note: See TracBrowser for help on using the repository browser.

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