VirtualBox

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

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

Devices/Graphics: implemented some DXQuery commands; fixed various issues found by piglit: bugref:9830

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