VirtualBox

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

最後變更 在這個檔案從95232是 95149,由 vboxsync 提交於 3 年 前

Devices/Graphics: PresentBlt. bugref:9830

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

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