VirtualBox

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

最後變更 在這個檔案從99535是 99535,由 vboxsync 提交於 23 月 前

Devices/Graphics: SVGA_REG_CAP2; SET_*_CONSTANT_BUFFER_OFFSET; fixes for shader parser. bugref:9830

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

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