VirtualBox

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

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

Devices/Graphics: implemented queries; fixed generation of GS attributes: bugref:9830

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

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