VirtualBox

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

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

Devices/Graphics: dump float format: bugref:9830

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 277.8 KB
 
1/* $Id: DevVGA-SVGA-cmd.cpp 95101 2022-05-25 14:16:27Z 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 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2738 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
2739 return vmsvga3dDXPresentBlt(pThisCC, idDXContext);
2740#else
2741 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2742 return VERR_NOT_SUPPORTED;
2743#endif
2744}
2745
2746
2747/* SVGA_3D_CMD_DX_GENMIPS 1181 */
2748static int vmsvga3dCmdDXGenMips(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXGenMips const *pCmd, uint32_t cbCmd)
2749{
2750#ifdef VMSVGA3D_DX
2751 //DEBUG_BREAKPOINT_TEST();
2752 RT_NOREF(cbCmd);
2753 return vmsvga3dDXGenMips(pThisCC, idDXContext, pCmd);
2754#else
2755 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2756 return VERR_NOT_SUPPORTED;
2757#endif
2758}
2759
2760
2761/* SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE 1182 */
2762static int vmsvga3dCmdDXUpdateSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXUpdateSubResource const *pCmd, uint32_t cbCmd)
2763{
2764#ifdef VMSVGA3D_DX
2765 //DEBUG_BREAKPOINT_TEST();
2766 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2767 RT_NOREF(cbCmd);
2768
2769 LogFlowFunc(("sid=%u, subResource=%u, box=%d,%d,%d %ux%ux%u\n",
2770 pCmd->sid, pCmd->subResource, pCmd->box.x, pCmd->box.y, pCmd->box.z, pCmd->box.w, pCmd->box.h, pCmd->box.z));
2771
2772 /* "Inform the device that the guest-contents have been updated." */
2773 SVGAOTableSurfaceEntry entrySurface;
2774 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2775 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2776 if (RT_SUCCESS(rc))
2777 {
2778 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
2779 if (pMob)
2780 {
2781 uint32 const cSubresource = vmsvga3dGetSubresourceCount(pThisCC, pCmd->sid);
2782 ASSERT_GUEST_RETURN(pCmd->subResource < cSubresource, VERR_INVALID_PARAMETER);
2783 /* pCmd->box will be verified by the mapping function. */
2784 RT_UNTRUSTED_VALIDATED_FENCE();
2785
2786 /** @todo Mapping functions should use subresource index rather than SVGA3dSurfaceImageId? */
2787 SVGA3dSurfaceImageId image;
2788 image.sid = pCmd->sid;
2789 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &image.mipmap, &image.face);
2790
2791 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, &pCmd->box, SVGA3D_WRITE_HOST_VRAM);
2792 AssertRC(rc);
2793 }
2794 }
2795
2796 return rc;
2797#else
2798 RT_NOREF(pThisCC, pCmd, cbCmd);
2799 return VERR_NOT_SUPPORTED;
2800#endif
2801}
2802
2803
2804/* SVGA_3D_CMD_DX_READBACK_SUBRESOURCE 1183 */
2805static int vmsvga3dCmdDXReadbackSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXReadbackSubResource const *pCmd, uint32_t cbCmd)
2806{
2807#ifdef VMSVGA3D_DX
2808 //DEBUG_BREAKPOINT_TEST();
2809 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2810 RT_NOREF(cbCmd);
2811
2812 LogFlowFunc(("sid=%u, subResource=%u\n",
2813 pCmd->sid, pCmd->subResource));
2814
2815 /* "Request the device to flush the dirty contents into the guest." */
2816 SVGAOTableSurfaceEntry entrySurface;
2817 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2818 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2819 if (RT_SUCCESS(rc))
2820 {
2821 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, entrySurface.mobid);
2822 if (pMob)
2823 {
2824 uint32 const cSubresource = vmsvga3dGetSubresourceCount(pThisCC, pCmd->sid);
2825 ASSERT_GUEST_RETURN(pCmd->subResource < cSubresource, VERR_INVALID_PARAMETER);
2826 RT_UNTRUSTED_VALIDATED_FENCE();
2827
2828 /** @todo Mapping functions should use subresource index rather than SVGA3dSurfaceImageId? */
2829 SVGA3dSurfaceImageId image;
2830 image.sid = pCmd->sid;
2831 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &image.mipmap, &image.face);
2832
2833 rc = vmsvgaR3TransferSurfaceLevel(pThisCC, pMob, &image, /* all pBox = */ NULL, SVGA3D_READ_HOST_VRAM);
2834 AssertRC(rc);
2835 }
2836 }
2837
2838 return rc;
2839#else
2840 RT_NOREF(pThisCC, pCmd, cbCmd);
2841 return VERR_NOT_SUPPORTED;
2842#endif
2843}
2844
2845
2846/* SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE 1184 */
2847static int vmsvga3dCmdDXInvalidateSubResource(PVGASTATECC pThisCC, SVGA3dCmdDXInvalidateSubResource const *pCmd, uint32_t cbCmd)
2848{
2849#ifdef VMSVGA3D_DX
2850 DEBUG_BREAKPOINT_TEST();
2851 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
2852 RT_NOREF(cbCmd);
2853
2854 LogFlowFunc(("sid=%u, subResource=%u\n",
2855 pCmd->sid, pCmd->subResource));
2856
2857 /* "Notify the device that the contents can be lost." */
2858 SVGAOTableSurfaceEntry entrySurface;
2859 int rc = vmsvgaR3OTableRead(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
2860 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entrySurface, sizeof(entrySurface));
2861 if (RT_SUCCESS(rc))
2862 {
2863 uint32_t iFace;
2864 uint32_t iMipmap;
2865 vmsvga3dCalcMipmapAndFace(entrySurface.numMipLevels, pCmd->subResource, &iMipmap, &iFace);
2866 vmsvga3dSurfaceInvalidate(pThisCC, pCmd->sid, iFace, iMipmap);
2867 }
2868
2869 return rc;
2870#else
2871 RT_NOREF(pThisCC, pCmd, cbCmd);
2872 return VERR_NOT_SUPPORTED;
2873#endif
2874}
2875
2876
2877/* SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW 1185 */
2878static int vmsvga3dCmdDXDefineShaderResourceView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineShaderResourceView const *pCmd, uint32_t cbCmd)
2879{
2880#ifdef VMSVGA3D_DX
2881 //DEBUG_BREAKPOINT_TEST();
2882 RT_NOREF(cbCmd);
2883 return vmsvga3dDXDefineShaderResourceView(pThisCC, idDXContext, pCmd);
2884#else
2885 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2886 return VERR_NOT_SUPPORTED;
2887#endif
2888}
2889
2890
2891/* SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW 1186 */
2892static int vmsvga3dCmdDXDestroyShaderResourceView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyShaderResourceView const *pCmd, uint32_t cbCmd)
2893{
2894#ifdef VMSVGA3D_DX
2895 //DEBUG_BREAKPOINT_TEST();
2896 RT_NOREF(cbCmd);
2897 return vmsvga3dDXDestroyShaderResourceView(pThisCC, idDXContext, pCmd);
2898#else
2899 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2900 return VERR_NOT_SUPPORTED;
2901#endif
2902}
2903
2904
2905/* SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW 1187 */
2906static int vmsvga3dCmdDXDefineRenderTargetView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineRenderTargetView const *pCmd, uint32_t cbCmd)
2907{
2908#ifdef VMSVGA3D_DX
2909 //DEBUG_BREAKPOINT_TEST();
2910 RT_NOREF(cbCmd);
2911 return vmsvga3dDXDefineRenderTargetView(pThisCC, idDXContext, pCmd);
2912#else
2913 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2914 return VERR_NOT_SUPPORTED;
2915#endif
2916}
2917
2918
2919/* SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW 1188 */
2920static int vmsvga3dCmdDXDestroyRenderTargetView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyRenderTargetView const *pCmd, uint32_t cbCmd)
2921{
2922#ifdef VMSVGA3D_DX
2923 //DEBUG_BREAKPOINT_TEST();
2924 RT_NOREF(cbCmd);
2925 return vmsvga3dDXDestroyRenderTargetView(pThisCC, idDXContext, pCmd);
2926#else
2927 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2928 return VERR_NOT_SUPPORTED;
2929#endif
2930}
2931
2932
2933/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW 1189 */
2934static int vmsvga3dCmdDXDefineDepthStencilView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilView const *pCmd, uint32_t cbCmd)
2935{
2936#ifdef VMSVGA3D_DX
2937 //DEBUG_BREAKPOINT_TEST();
2938 RT_NOREF(cbCmd);
2939 SVGA3dCmdDXDefineDepthStencilView_v2 cmd;
2940 cmd.depthStencilViewId = pCmd->depthStencilViewId;
2941 cmd.sid = pCmd->sid;
2942 cmd.format = pCmd->format;
2943 cmd.resourceDimension = pCmd->resourceDimension;
2944 cmd.mipSlice = pCmd->mipSlice;
2945 cmd.firstArraySlice = pCmd->firstArraySlice;
2946 cmd.arraySize = pCmd->arraySize;
2947 cmd.flags = 0;
2948 return vmsvga3dDXDefineDepthStencilView(pThisCC, idDXContext, &cmd);
2949#else
2950 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2951 return VERR_NOT_SUPPORTED;
2952#endif
2953}
2954
2955
2956/* SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW 1190 */
2957static int vmsvga3dCmdDXDestroyDepthStencilView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyDepthStencilView const *pCmd, uint32_t cbCmd)
2958{
2959#ifdef VMSVGA3D_DX
2960 //DEBUG_BREAKPOINT_TEST();
2961 RT_NOREF(cbCmd);
2962 return vmsvga3dDXDestroyDepthStencilView(pThisCC, idDXContext, pCmd);
2963#else
2964 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2965 return VERR_NOT_SUPPORTED;
2966#endif
2967}
2968
2969
2970/* SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT 1191 */
2971static int vmsvga3dCmdDXDefineElementLayout(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineElementLayout const *pCmd, uint32_t cbCmd)
2972{
2973#ifdef VMSVGA3D_DX
2974 //DEBUG_BREAKPOINT_TEST();
2975 SVGA3dInputElementDesc const *paDesc = (SVGA3dInputElementDesc *)&pCmd[1];
2976 uint32_t const cDesc = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dInputElementDesc);
2977 return vmsvga3dDXDefineElementLayout(pThisCC, idDXContext, pCmd->elementLayoutId, cDesc, paDesc);
2978#else
2979 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2980 return VERR_NOT_SUPPORTED;
2981#endif
2982}
2983
2984
2985/* SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT 1192 */
2986static int vmsvga3dCmdDXDestroyElementLayout(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyElementLayout const *pCmd, uint32_t cbCmd)
2987{
2988#ifdef VMSVGA3D_DX
2989 //DEBUG_BREAKPOINT_TEST();
2990 RT_NOREF(cbCmd);
2991 return vmsvga3dDXDestroyElementLayout(pThisCC, idDXContext, pCmd);
2992#else
2993 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
2994 return VERR_NOT_SUPPORTED;
2995#endif
2996}
2997
2998
2999/* SVGA_3D_CMD_DX_DEFINE_BLEND_STATE 1193 */
3000static int vmsvga3dCmdDXDefineBlendState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineBlendState const *pCmd, uint32_t cbCmd)
3001{
3002#ifdef VMSVGA3D_DX
3003 //DEBUG_BREAKPOINT_TEST();
3004 RT_NOREF(cbCmd);
3005 return vmsvga3dDXDefineBlendState(pThisCC, idDXContext, pCmd);
3006#else
3007 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3008 return VERR_NOT_SUPPORTED;
3009#endif
3010}
3011
3012
3013/* SVGA_3D_CMD_DX_DESTROY_BLEND_STATE 1194 */
3014static int vmsvga3dCmdDXDestroyBlendState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyBlendState const *pCmd, uint32_t cbCmd)
3015{
3016#ifdef VMSVGA3D_DX
3017 //DEBUG_BREAKPOINT_TEST();
3018 RT_NOREF(cbCmd);
3019 return vmsvga3dDXDestroyBlendState(pThisCC, idDXContext, pCmd);
3020#else
3021 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3022 return VERR_NOT_SUPPORTED;
3023#endif
3024}
3025
3026
3027/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE 1195 */
3028static int vmsvga3dCmdDXDefineDepthStencilState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilState const *pCmd, uint32_t cbCmd)
3029{
3030#ifdef VMSVGA3D_DX
3031 //DEBUG_BREAKPOINT_TEST();
3032 RT_NOREF(cbCmd);
3033 return vmsvga3dDXDefineDepthStencilState(pThisCC, idDXContext, pCmd);
3034#else
3035 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3036 return VERR_NOT_SUPPORTED;
3037#endif
3038}
3039
3040
3041/* SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE 1196 */
3042static int vmsvga3dCmdDXDestroyDepthStencilState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyDepthStencilState const *pCmd, uint32_t cbCmd)
3043{
3044#ifdef VMSVGA3D_DX
3045 //DEBUG_BREAKPOINT_TEST();
3046 RT_NOREF(cbCmd);
3047 return vmsvga3dDXDestroyDepthStencilState(pThisCC, idDXContext, pCmd);
3048#else
3049 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3050 return VERR_NOT_SUPPORTED;
3051#endif
3052}
3053
3054
3055/* SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE 1197 */
3056static int vmsvga3dCmdDXDefineRasterizerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineRasterizerState const *pCmd, uint32_t cbCmd)
3057{
3058#ifdef VMSVGA3D_DX
3059 //DEBUG_BREAKPOINT_TEST();
3060 RT_NOREF(cbCmd);
3061 return vmsvga3dDXDefineRasterizerState(pThisCC, idDXContext, pCmd);
3062#else
3063 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3064 return VERR_NOT_SUPPORTED;
3065#endif
3066}
3067
3068
3069/* SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE 1198 */
3070static int vmsvga3dCmdDXDestroyRasterizerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyRasterizerState const *pCmd, uint32_t cbCmd)
3071{
3072#ifdef VMSVGA3D_DX
3073 //DEBUG_BREAKPOINT_TEST();
3074 RT_NOREF(cbCmd);
3075 return vmsvga3dDXDestroyRasterizerState(pThisCC, idDXContext, pCmd);
3076#else
3077 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3078 return VERR_NOT_SUPPORTED;
3079#endif
3080}
3081
3082
3083/* SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE 1199 */
3084static int vmsvga3dCmdDXDefineSamplerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineSamplerState const *pCmd, uint32_t cbCmd)
3085{
3086#ifdef VMSVGA3D_DX
3087 //DEBUG_BREAKPOINT_TEST();
3088 RT_NOREF(cbCmd);
3089 return vmsvga3dDXDefineSamplerState(pThisCC, idDXContext, pCmd);
3090#else
3091 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3092 return VERR_NOT_SUPPORTED;
3093#endif
3094}
3095
3096
3097/* SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE 1200 */
3098static int vmsvga3dCmdDXDestroySamplerState(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroySamplerState const *pCmd, uint32_t cbCmd)
3099{
3100#ifdef VMSVGA3D_DX
3101 //DEBUG_BREAKPOINT_TEST();
3102 RT_NOREF(cbCmd);
3103 return vmsvga3dDXDestroySamplerState(pThisCC, idDXContext, pCmd);
3104#else
3105 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3106 return VERR_NOT_SUPPORTED;
3107#endif
3108}
3109
3110
3111/* SVGA_3D_CMD_DX_DEFINE_SHADER 1201 */
3112static int vmsvga3dCmdDXDefineShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineShader const *pCmd, uint32_t cbCmd)
3113{
3114#ifdef VMSVGA3D_DX
3115 //DEBUG_BREAKPOINT_TEST();
3116 RT_NOREF(cbCmd);
3117 return vmsvga3dDXDefineShader(pThisCC, idDXContext, pCmd);
3118#else
3119 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3120 return VERR_NOT_SUPPORTED;
3121#endif
3122}
3123
3124
3125/* SVGA_3D_CMD_DX_DESTROY_SHADER 1202 */
3126static int vmsvga3dCmdDXDestroyShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyShader const *pCmd, uint32_t cbCmd)
3127{
3128#ifdef VMSVGA3D_DX
3129 //DEBUG_BREAKPOINT_TEST();
3130 RT_NOREF(cbCmd);
3131 return vmsvga3dDXDestroyShader(pThisCC, idDXContext, pCmd);
3132#else
3133 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3134 return VERR_NOT_SUPPORTED;
3135#endif
3136}
3137
3138
3139/* SVGA_3D_CMD_DX_BIND_SHADER 1203 */
3140static int vmsvga3dCmdDXBindShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindShader const *pCmd, uint32_t cbCmd)
3141{
3142#ifdef VMSVGA3D_DX
3143 //DEBUG_BREAKPOINT_TEST();
3144 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3145 RT_NOREF(idDXContext, cbCmd);
3146 /* This returns NULL if mob does not exist. If the guest sends a wrong mob id, the current mob will be unbound. */
3147 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobid);
3148 return vmsvga3dDXBindShader(pThisCC, pCmd, pMob);
3149#else
3150 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3151 return VERR_NOT_SUPPORTED;
3152#endif
3153}
3154
3155
3156/* SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT 1204 */
3157static int vmsvga3dCmdDXDefineStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineStreamOutput const *pCmd, uint32_t cbCmd)
3158{
3159#ifdef VMSVGA3D_DX
3160 //DEBUG_BREAKPOINT_TEST();
3161 RT_NOREF(cbCmd);
3162 return vmsvga3dDXDefineStreamOutput(pThisCC, idDXContext, pCmd);
3163#else
3164 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3165 return VERR_NOT_SUPPORTED;
3166#endif
3167}
3168
3169
3170/* SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT 1205 */
3171static int vmsvga3dCmdDXDestroyStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyStreamOutput const *pCmd, uint32_t cbCmd)
3172{
3173#ifdef VMSVGA3D_DX
3174 //DEBUG_BREAKPOINT_TEST();
3175 RT_NOREF(cbCmd);
3176 return vmsvga3dDXDestroyStreamOutput(pThisCC, idDXContext, pCmd);
3177#else
3178 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3179 return VERR_NOT_SUPPORTED;
3180#endif
3181}
3182
3183
3184/* SVGA_3D_CMD_DX_SET_STREAMOUTPUT 1206 */
3185static int vmsvga3dCmdDXSetStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetStreamOutput const *pCmd, uint32_t cbCmd)
3186{
3187#ifdef VMSVGA3D_DX
3188 //DEBUG_BREAKPOINT_TEST();
3189 RT_NOREF(cbCmd);
3190 return vmsvga3dDXSetStreamOutput(pThisCC, idDXContext, pCmd);
3191#else
3192 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3193 return VERR_NOT_SUPPORTED;
3194#endif
3195}
3196
3197
3198/* SVGA_3D_CMD_DX_SET_COTABLE 1207 */
3199static int vmsvga3dCmdDXSetCOTable(PVGASTATECC pThisCC, SVGA3dCmdDXSetCOTable const *pCmd, uint32_t cbCmd)
3200{
3201#ifdef VMSVGA3D_DX
3202 //DEBUG_BREAKPOINT_TEST();
3203 RT_NOREF(cbCmd);
3204 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3205 /* This returns NULL if mob does not exist. If the guest sends a wrong mob id, the current mob will be unbound. */
3206 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobid);
3207 return vmsvga3dDXSetCOTable(pThisCC, pCmd, pMob);
3208#else
3209 RT_NOREF(pThisCC, pCmd, cbCmd);
3210 return VERR_NOT_SUPPORTED;
3211#endif
3212}
3213
3214
3215/* SVGA_3D_CMD_DX_READBACK_COTABLE 1208 */
3216static int vmsvga3dCmdDXReadbackCOTable(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXReadbackCOTable const *pCmd, uint32_t cbCmd)
3217{
3218#ifdef VMSVGA3D_DX
3219 //DEBUG_BREAKPOINT_TEST();
3220 RT_NOREF(idDXContext, cbCmd);
3221 return vmsvga3dDXReadbackCOTable(pThisCC, pCmd);
3222#else
3223 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3224 return VERR_NOT_SUPPORTED;
3225#endif
3226}
3227
3228
3229/* SVGA_3D_CMD_DX_BUFFER_COPY 1209 */
3230static int vmsvga3dCmdDXBufferCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBufferCopy const *pCmd, uint32_t cbCmd)
3231{
3232#ifdef VMSVGA3D_DX
3233 //DEBUG_BREAKPOINT_TEST();
3234 RT_NOREF(idDXContext, cbCmd);
3235
3236 int rc;
3237
3238 /** @todo Backend should o the copy is both buffers have a hardware resource. */
3239 SVGA3dSurfaceImageId imageBufferSrc;
3240 imageBufferSrc.sid = pCmd->src;
3241 imageBufferSrc.face = 0;
3242 imageBufferSrc.mipmap = 0;
3243
3244 SVGA3dSurfaceImageId imageBufferDest;
3245 imageBufferDest.sid = pCmd->dest;
3246 imageBufferDest.face = 0;
3247 imageBufferDest.mipmap = 0;
3248
3249 /*
3250 * Map the source buffer.
3251 */
3252 VMSVGA3D_MAPPED_SURFACE mapBufferSrc;
3253 rc = vmsvga3dSurfaceMap(pThisCC, &imageBufferSrc, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapBufferSrc);
3254 if (RT_SUCCESS(rc))
3255 {
3256 /*
3257 * Map the destination buffer.
3258 */
3259 VMSVGA3D_MAPPED_SURFACE mapBufferDest;
3260 rc = vmsvga3dSurfaceMap(pThisCC, &imageBufferDest, NULL, VMSVGA3D_SURFACE_MAP_WRITE, &mapBufferDest);
3261 if (RT_SUCCESS(rc))
3262 {
3263 /*
3264 * Copy the source buffer to the destination.
3265 */
3266 uint8_t const *pu8BufferSrc = (uint8_t *)mapBufferSrc.pvData;
3267 uint32_t const cbBufferSrc = mapBufferSrc.cbRow;
3268
3269 uint8_t *pu8BufferDest = (uint8_t *)mapBufferDest.pvData;
3270 uint32_t const cbBufferDest = mapBufferDest.cbRow;
3271
3272 if ( pCmd->srcX < cbBufferSrc
3273 && pCmd->width <= cbBufferSrc- pCmd->srcX
3274 && pCmd->destX < cbBufferDest
3275 && pCmd->width <= cbBufferDest - pCmd->destX)
3276 {
3277 RT_UNTRUSTED_VALIDATED_FENCE();
3278
3279 memcpy(&pu8BufferDest[pCmd->destX], &pu8BufferSrc[pCmd->srcX], pCmd->width);
3280 }
3281 else
3282 ASSERT_GUEST_FAILED_STMT(rc = VERR_INVALID_PARAMETER);
3283
3284 vmsvga3dSurfaceUnmap(pThisCC, &imageBufferDest, &mapBufferDest, true);
3285 }
3286
3287 vmsvga3dSurfaceUnmap(pThisCC, &imageBufferSrc, &mapBufferSrc, false);
3288 }
3289
3290 return rc;
3291#else
3292 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3293 return VERR_NOT_SUPPORTED;
3294#endif
3295}
3296
3297
3298/* SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER 1210 */
3299static int vmsvga3dCmdDXTransferFromBuffer(PVGASTATECC pThisCC, SVGA3dCmdDXTransferFromBuffer const *pCmd, uint32_t cbCmd)
3300{
3301#ifdef VMSVGA3D_DX
3302 //DEBUG_BREAKPOINT_TEST();
3303 RT_NOREF(cbCmd);
3304
3305 /* Plan:
3306 * - map the buffer;
3307 * - map the surface;
3308 * - copy from buffer map to the surface map.
3309 */
3310
3311 int rc;
3312
3313 SVGA3dSurfaceImageId imageBuffer;
3314 imageBuffer.sid = pCmd->srcSid;
3315 imageBuffer.face = 0;
3316 imageBuffer.mipmap = 0;
3317
3318 SVGA3dSurfaceImageId imageSurface;
3319 imageSurface.sid = pCmd->destSid;
3320 rc = vmsvga3dCalcSurfaceMipmapAndFace(pThisCC, pCmd->destSid, pCmd->destSubResource, &imageSurface.mipmap, &imageSurface.face);
3321 AssertRCReturn(rc, rc);
3322
3323 /*
3324 * Map the buffer.
3325 */
3326 VMSVGA3D_MAPPED_SURFACE mapBuffer;
3327 rc = vmsvga3dSurfaceMap(pThisCC, &imageBuffer, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapBuffer);
3328 if (RT_SUCCESS(rc))
3329 {
3330 /*
3331 * Map the surface.
3332 */
3333 VMSVGA3D_MAPPED_SURFACE mapSurface;
3334 rc = vmsvga3dSurfaceMap(pThisCC, &imageSurface, &pCmd->destBox, VMSVGA3D_SURFACE_MAP_WRITE, &mapSurface);
3335 if (RT_SUCCESS(rc))
3336 {
3337 /*
3338 * Copy the mapped buffer to the surface. "Raw byte wise transfer"
3339 */
3340 uint8_t const *pu8Buffer = (uint8_t *)mapBuffer.pvData;
3341 uint32_t const cbBuffer = mapBuffer.cbRow;
3342
3343 if (pCmd->srcOffset <= cbBuffer)
3344 {
3345 RT_UNTRUSTED_VALIDATED_FENCE();
3346 uint8_t const *pu8BufferBegin = pu8Buffer;
3347 uint8_t const *pu8BufferEnd = pu8Buffer + cbBuffer;
3348
3349 pu8Buffer += pCmd->srcOffset;
3350
3351 uint8_t *pu8Surface = (uint8_t *)mapSurface.pvData;
3352
3353 uint32_t const cbRowCopy = RT_MIN(pCmd->srcPitch, mapSurface.cbRow);
3354 for (uint32_t z = 0; z < mapSurface.box.d && RT_SUCCESS(rc); ++z)
3355 {
3356 uint8_t const *pu8BufferRow = pu8Buffer;
3357 uint8_t *pu8SurfaceRow = pu8Surface;
3358 for (uint32_t iRow = 0; iRow < mapSurface.cRows; ++iRow)
3359 {
3360 ASSERT_GUEST_STMT_BREAK( (uintptr_t)pu8BufferRow >= (uintptr_t)pu8BufferBegin
3361 && (uintptr_t)pu8BufferRow < (uintptr_t)pu8BufferEnd
3362 && (uintptr_t)pu8BufferRow < (uintptr_t)(pu8BufferRow + cbRowCopy)
3363 && (uintptr_t)(pu8BufferRow + cbRowCopy) > (uintptr_t)pu8BufferBegin
3364 && (uintptr_t)(pu8BufferRow + cbRowCopy) <= (uintptr_t)pu8BufferEnd,
3365 rc = VERR_INVALID_PARAMETER);
3366
3367 memcpy(pu8SurfaceRow, pu8BufferRow, cbRowCopy);
3368
3369 pu8SurfaceRow += mapSurface.cbRowPitch;
3370 pu8BufferRow += pCmd->srcPitch;
3371 }
3372
3373 pu8Buffer += pCmd->srcSlicePitch;
3374 pu8Surface += mapSurface.cbDepthPitch;
3375 }
3376 }
3377 else
3378 ASSERT_GUEST_FAILED_STMT(rc = VERR_INVALID_PARAMETER);
3379
3380 vmsvga3dSurfaceUnmap(pThisCC, &imageSurface, &mapSurface, true);
3381 }
3382
3383 vmsvga3dSurfaceUnmap(pThisCC, &imageBuffer, &mapBuffer, false);
3384 }
3385
3386 return rc;
3387#else
3388 RT_NOREF(pThisCC, pCmd, cbCmd);
3389 return VERR_NOT_SUPPORTED;
3390#endif
3391}
3392
3393
3394/* SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK 1211 */
3395static int vmsvga3dCmdDXSurfaceCopyAndReadback(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSurfaceCopyAndReadback const *pCmd, uint32_t cbCmd)
3396{
3397#ifdef VMSVGA3D_DX
3398 DEBUG_BREAKPOINT_TEST();
3399 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3400 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3401 return vmsvga3dDXSurfaceCopyAndReadback(pThisCC, idDXContext);
3402#else
3403 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3404 return VERR_NOT_SUPPORTED;
3405#endif
3406}
3407
3408
3409/* SVGA_3D_CMD_DX_MOVE_QUERY 1212 */
3410static int vmsvga3dCmdDXMoveQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXMoveQuery const *pCmd, uint32_t cbCmd)
3411{
3412#ifdef VMSVGA3D_DX
3413 DEBUG_BREAKPOINT_TEST();
3414 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3415 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3416 return vmsvga3dDXMoveQuery(pThisCC, idDXContext);
3417#else
3418 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3419 return VERR_NOT_SUPPORTED;
3420#endif
3421}
3422
3423
3424/* SVGA_3D_CMD_DX_BIND_ALL_QUERY 1213 */
3425static int vmsvga3dCmdDXBindAllQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindAllQuery const *pCmd, uint32_t cbCmd)
3426{
3427#ifdef VMSVGA3D_DX
3428 //DEBUG_BREAKPOINT_TEST();
3429 RT_NOREF(cbCmd);
3430 return vmsvga3dDXBindAllQuery(pThisCC, idDXContext, pCmd);
3431#else
3432 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3433 return VERR_NOT_SUPPORTED;
3434#endif
3435}
3436
3437
3438/* SVGA_3D_CMD_DX_READBACK_ALL_QUERY 1214 */
3439static int vmsvga3dCmdDXReadbackAllQuery(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXReadbackAllQuery const *pCmd, uint32_t cbCmd)
3440{
3441#ifdef VMSVGA3D_DX
3442 //DEBUG_BREAKPOINT_TEST();
3443 RT_NOREF(cbCmd);
3444 return vmsvga3dDXReadbackAllQuery(pThisCC, idDXContext, pCmd);
3445#else
3446 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3447 return VERR_NOT_SUPPORTED;
3448#endif
3449}
3450
3451
3452/* SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER 1215 */
3453static int vmsvga3dCmdDXPredTransferFromBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredTransferFromBuffer const *pCmd, uint32_t cbCmd)
3454{
3455#ifdef VMSVGA3D_DX
3456 //DEBUG_BREAKPOINT_TEST();
3457 RT_NOREF(idDXContext, cbCmd);
3458
3459 /* This command is executed in a context: "The context is implied from the command buffer header."
3460 * However the device design allows to do the transfer without a context, so re-use context-less command handler.
3461 */
3462 SVGA3dCmdDXTransferFromBuffer cmd;
3463 cmd.srcSid = pCmd->srcSid;
3464 cmd.srcOffset = pCmd->srcOffset;
3465 cmd.srcPitch = pCmd->srcPitch;
3466 cmd.srcSlicePitch = pCmd->srcSlicePitch;
3467 cmd.destSid = pCmd->destSid;
3468 cmd.destSubResource = pCmd->destSubResource;
3469 cmd.destBox = pCmd->destBox;
3470 return vmsvga3dCmdDXTransferFromBuffer(pThisCC, &cmd, sizeof(cmd));
3471#else
3472 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3473 return VERR_NOT_SUPPORTED;
3474#endif
3475}
3476
3477
3478/* SVGA_3D_CMD_DX_MOB_FENCE_64 1216 */
3479static int vmsvga3dCmdDXMobFence64(PVGASTATECC pThisCC, SVGA3dCmdDXMobFence64 const *pCmd, uint32_t cbCmd)
3480{
3481#ifdef VMSVGA3D_DX
3482 //DEBUG_BREAKPOINT_TEST();
3483 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3484 RT_NOREF(cbCmd);
3485
3486 PVMSVGAMOB pMob = vmsvgaR3MobGet(pSvgaR3State, pCmd->mobId);
3487 ASSERT_GUEST_RETURN(pMob, VERR_INVALID_PARAMETER);
3488
3489 int rc = vmsvgaR3MobWrite(pSvgaR3State, pMob, pCmd->mobOffset, &pCmd->value, sizeof(pCmd->value));
3490 ASSERT_GUEST_RETURN(RT_SUCCESS(rc), rc);
3491
3492 return VINF_SUCCESS;
3493#else
3494 RT_NOREF(pThisCC, pCmd, cbCmd);
3495 return VERR_NOT_SUPPORTED;
3496#endif
3497}
3498
3499
3500/* SVGA_3D_CMD_DX_BIND_ALL_SHADER 1217 */
3501static int vmsvga3dCmdDXBindAllShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindAllShader const *pCmd, uint32_t cbCmd)
3502{
3503#ifdef VMSVGA3D_DX
3504 DEBUG_BREAKPOINT_TEST();
3505 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3506 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3507 return vmsvga3dDXBindAllShader(pThisCC, idDXContext);
3508#else
3509 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3510 return VERR_NOT_SUPPORTED;
3511#endif
3512}
3513
3514
3515/* SVGA_3D_CMD_DX_HINT 1218 */
3516static int vmsvga3dCmdDXHint(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXHint const *pCmd, uint32_t cbCmd)
3517{
3518#ifdef VMSVGA3D_DX
3519 DEBUG_BREAKPOINT_TEST();
3520 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3521 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3522 return vmsvga3dDXHint(pThisCC, idDXContext);
3523#else
3524 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3525 return VERR_NOT_SUPPORTED;
3526#endif
3527}
3528
3529
3530/* SVGA_3D_CMD_DX_BUFFER_UPDATE 1219 */
3531static int vmsvga3dCmdDXBufferUpdate(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBufferUpdate const *pCmd, uint32_t cbCmd)
3532{
3533#ifdef VMSVGA3D_DX
3534 DEBUG_BREAKPOINT_TEST();
3535 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3536 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3537 return vmsvga3dDXBufferUpdate(pThisCC, idDXContext);
3538#else
3539 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3540 return VERR_NOT_SUPPORTED;
3541#endif
3542}
3543
3544
3545/* SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET 1220 */
3546static int vmsvga3dCmdDXSetVSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetVSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3547{
3548#ifdef VMSVGA3D_DX
3549 DEBUG_BREAKPOINT_TEST();
3550 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3551 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3552 return vmsvga3dDXSetVSConstantBufferOffset(pThisCC, idDXContext);
3553#else
3554 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3555 return VERR_NOT_SUPPORTED;
3556#endif
3557}
3558
3559
3560/* SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET 1221 */
3561static int vmsvga3dCmdDXSetPSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetPSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3562{
3563#ifdef VMSVGA3D_DX
3564 DEBUG_BREAKPOINT_TEST();
3565 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3566 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3567 return vmsvga3dDXSetPSConstantBufferOffset(pThisCC, idDXContext);
3568#else
3569 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3570 return VERR_NOT_SUPPORTED;
3571#endif
3572}
3573
3574
3575/* SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET 1222 */
3576static int vmsvga3dCmdDXSetGSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetGSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3577{
3578#ifdef VMSVGA3D_DX
3579 DEBUG_BREAKPOINT_TEST();
3580 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3581 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3582 return vmsvga3dDXSetGSConstantBufferOffset(pThisCC, idDXContext);
3583#else
3584 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3585 return VERR_NOT_SUPPORTED;
3586#endif
3587}
3588
3589
3590/* SVGA_3D_CMD_DX_SET_HS_CONSTANT_BUFFER_OFFSET 1223 */
3591static int vmsvga3dCmdDXSetHSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetHSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3592{
3593#ifdef VMSVGA3D_DX
3594 DEBUG_BREAKPOINT_TEST();
3595 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3596 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3597 return vmsvga3dDXSetHSConstantBufferOffset(pThisCC, idDXContext);
3598#else
3599 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3600 return VERR_NOT_SUPPORTED;
3601#endif
3602}
3603
3604
3605/* SVGA_3D_CMD_DX_SET_DS_CONSTANT_BUFFER_OFFSET 1224 */
3606static int vmsvga3dCmdDXSetDSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetDSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3607{
3608#ifdef VMSVGA3D_DX
3609 DEBUG_BREAKPOINT_TEST();
3610 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3611 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3612 return vmsvga3dDXSetDSConstantBufferOffset(pThisCC, idDXContext);
3613#else
3614 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3615 return VERR_NOT_SUPPORTED;
3616#endif
3617}
3618
3619
3620/* SVGA_3D_CMD_DX_SET_CS_CONSTANT_BUFFER_OFFSET 1225 */
3621static int vmsvga3dCmdDXSetCSConstantBufferOffset(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetCSConstantBufferOffset const *pCmd, uint32_t cbCmd)
3622{
3623#ifdef VMSVGA3D_DX
3624 DEBUG_BREAKPOINT_TEST();
3625 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3626 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3627 return vmsvga3dDXSetCSConstantBufferOffset(pThisCC, idDXContext);
3628#else
3629 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3630 return VERR_NOT_SUPPORTED;
3631#endif
3632}
3633
3634
3635/* SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER 1226 */
3636static int vmsvga3dCmdDXCondBindAllShader(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXCondBindAllShader const *pCmd, uint32_t cbCmd)
3637{
3638#ifdef VMSVGA3D_DX
3639 DEBUG_BREAKPOINT_TEST();
3640 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3641 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3642 return vmsvga3dDXCondBindAllShader(pThisCC, idDXContext);
3643#else
3644 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3645 return VERR_NOT_SUPPORTED;
3646#endif
3647}
3648
3649
3650/* SVGA_3D_CMD_SCREEN_COPY 1227 */
3651static int vmsvga3dCmdScreenCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdScreenCopy const *pCmd, uint32_t cbCmd)
3652{
3653#ifdef VMSVGA3D_DX
3654 DEBUG_BREAKPOINT_TEST();
3655 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3656 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3657 return vmsvga3dScreenCopy(pThisCC, idDXContext);
3658#else
3659 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3660 return VERR_NOT_SUPPORTED;
3661#endif
3662}
3663
3664
3665/* SVGA_3D_CMD_GROW_OTABLE 1236 */
3666static int vmsvga3dCmdGrowOTable(PVGASTATECC pThisCC, SVGA3dCmdGrowOTable const *pCmd, uint32_t cbCmd)
3667{
3668#ifdef VMSVGA3D_DX
3669 //DEBUG_BREAKPOINT_TEST();
3670 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3671 RT_NOREF(cbCmd);
3672 return vmsvgaR3OTableSetOrGrow(pSvgaR3State, pCmd->type, pCmd->baseAddress,
3673 pCmd->sizeInBytes, pCmd->validSizeInBytes, pCmd->ptDepth, /*fGrow*/ true);
3674#else
3675 RT_NOREF(pThisCC, pCmd, cbCmd);
3676 return VERR_NOT_SUPPORTED;
3677#endif
3678}
3679
3680
3681/* SVGA_3D_CMD_DX_GROW_COTABLE 1237 */
3682static int vmsvga3dCmdDXGrowCOTable(PVGASTATECC pThisCC, SVGA3dCmdDXGrowCOTable const *pCmd, uint32_t cbCmd)
3683{
3684#ifdef VMSVGA3D_DX
3685 //DEBUG_BREAKPOINT_TEST();
3686 RT_NOREF(cbCmd);
3687 return vmsvga3dDXGrowCOTable(pThisCC, pCmd);
3688#else
3689 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3690 return VERR_NOT_SUPPORTED;
3691#endif
3692}
3693
3694
3695/* SVGA_3D_CMD_INTRA_SURFACE_COPY 1238 */
3696static int vmsvga3dCmdIntraSurfaceCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdIntraSurfaceCopy const *pCmd, uint32_t cbCmd)
3697{
3698#ifdef VMSVGA3D_DX
3699 DEBUG_BREAKPOINT_TEST();
3700 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3701 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3702 return vmsvga3dIntraSurfaceCopy(pThisCC, idDXContext);
3703#else
3704 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3705 return VERR_NOT_SUPPORTED;
3706#endif
3707}
3708
3709
3710/* SVGA_3D_CMD_DEFINE_GB_SURFACE_V3 1239 */
3711static int vmsvga3dCmdDefineGBSurface_v3(PVGASTATECC pThisCC, SVGA3dCmdDefineGBSurface_v3 const *pCmd)
3712{
3713#ifdef VMSVGA3D_DX
3714 DEBUG_BREAKPOINT_TEST();
3715 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3716
3717 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
3718 SVGAOTableSurfaceEntry entry;
3719 RT_ZERO(entry);
3720 entry.format = pCmd->format;
3721 entry.surface1Flags = (uint32_t)(pCmd->surfaceFlags);
3722 entry.numMipLevels = pCmd->numMipLevels;
3723 entry.multisampleCount = pCmd->multisampleCount;
3724 entry.autogenFilter = pCmd->autogenFilter;
3725 entry.size = pCmd->size;
3726 entry.mobid = SVGA_ID_INVALID;
3727 entry.arraySize = pCmd->arraySize;
3728 // entry.mobPitch = 0;
3729 // entry.mobPitch = 0;
3730 entry.surface2Flags = (uint32_t)(pCmd->surfaceFlags >> UINT64_C(32));
3731 // entry.multisamplePattern = 0;
3732 // entry.qualityLevel = 0;
3733 // entry.bufferByteStride = 0;
3734 // entry.minLOD = 0;
3735
3736 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
3737 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
3738 if (RT_SUCCESS(rc))
3739 {
3740 /* Create the host surface. */
3741 /** @todo SVGAOTableSurfaceEntry as input parameter? */
3742 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
3743 pCmd->multisampleCount, pCmd->autogenFilter,
3744 pCmd->numMipLevels, &pCmd->size, pCmd->arraySize, /* fAllocMipLevels = */ false);
3745 }
3746 return rc;
3747#else
3748 RT_NOREF(pThisCC, pCmd);
3749 return VERR_NOT_SUPPORTED;
3750#endif
3751}
3752
3753
3754/* SVGA_3D_CMD_DX_RESOLVE_COPY 1240 */
3755static int vmsvga3dCmdDXResolveCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXResolveCopy const *pCmd, uint32_t cbCmd)
3756{
3757#ifdef VMSVGA3D_DX
3758 DEBUG_BREAKPOINT_TEST();
3759 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3760 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3761 return vmsvga3dDXResolveCopy(pThisCC, idDXContext);
3762#else
3763 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3764 return VERR_NOT_SUPPORTED;
3765#endif
3766}
3767
3768
3769/* SVGA_3D_CMD_DX_PRED_RESOLVE_COPY 1241 */
3770static int vmsvga3dCmdDXPredResolveCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredResolveCopy const *pCmd, uint32_t cbCmd)
3771{
3772#ifdef VMSVGA3D_DX
3773 DEBUG_BREAKPOINT_TEST();
3774 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3775 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3776 return vmsvga3dDXPredResolveCopy(pThisCC, idDXContext);
3777#else
3778 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3779 return VERR_NOT_SUPPORTED;
3780#endif
3781}
3782
3783
3784/* SVGA_3D_CMD_DX_PRED_CONVERT_REGION 1242 */
3785static int vmsvga3dCmdDXPredConvertRegion(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredConvertRegion const *pCmd, uint32_t cbCmd)
3786{
3787#ifdef VMSVGA3D_DX
3788 DEBUG_BREAKPOINT_TEST();
3789 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3790 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3791 return vmsvga3dDXPredConvertRegion(pThisCC, idDXContext);
3792#else
3793 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3794 return VERR_NOT_SUPPORTED;
3795#endif
3796}
3797
3798
3799/* SVGA_3D_CMD_DX_PRED_CONVERT 1243 */
3800static int vmsvga3dCmdDXPredConvert(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXPredConvert const *pCmd, uint32_t cbCmd)
3801{
3802#ifdef VMSVGA3D_DX
3803 DEBUG_BREAKPOINT_TEST();
3804 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3805 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3806 return vmsvga3dDXPredConvert(pThisCC, idDXContext);
3807#else
3808 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3809 return VERR_NOT_SUPPORTED;
3810#endif
3811}
3812
3813
3814/* SVGA_3D_CMD_WHOLE_SURFACE_COPY 1244 */
3815static int vmsvga3dCmdWholeSurfaceCopy(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdWholeSurfaceCopy const *pCmd, uint32_t cbCmd)
3816{
3817#ifdef VMSVGA3D_DX
3818 DEBUG_BREAKPOINT_TEST();
3819 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3820 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3821 return vmsvga3dWholeSurfaceCopy(pThisCC, idDXContext);
3822#else
3823 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3824 return VERR_NOT_SUPPORTED;
3825#endif
3826}
3827
3828
3829/* SVGA_3D_CMD_DX_DEFINE_UA_VIEW 1245 */
3830static int vmsvga3dCmdDXDefineUAView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineUAView const *pCmd, uint32_t cbCmd)
3831{
3832#ifdef VMSVGA3D_DX
3833 //DEBUG_BREAKPOINT_TEST();
3834 RT_NOREF(cbCmd);
3835 return vmsvga3dDXDefineUAView(pThisCC, idDXContext, pCmd);
3836#else
3837 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3838 return VERR_NOT_SUPPORTED;
3839#endif
3840}
3841
3842
3843/* SVGA_3D_CMD_DX_DESTROY_UA_VIEW 1246 */
3844static int vmsvga3dCmdDXDestroyUAView(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDestroyUAView const *pCmd, uint32_t cbCmd)
3845{
3846#ifdef VMSVGA3D_DX
3847 //DEBUG_BREAKPOINT_TEST();
3848 RT_NOREF(cbCmd);
3849 return vmsvga3dDXDestroyUAView(pThisCC, idDXContext, pCmd);
3850#else
3851 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3852 return VERR_NOT_SUPPORTED;
3853#endif
3854}
3855
3856
3857/* SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT 1247 */
3858static int vmsvga3dCmdDXClearUAViewUint(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearUAViewUint const *pCmd, uint32_t cbCmd)
3859{
3860#ifdef VMSVGA3D_DX
3861 DEBUG_BREAKPOINT_TEST();
3862 RT_NOREF(cbCmd);
3863 return vmsvga3dDXClearUAViewUint(pThisCC, idDXContext, pCmd);
3864#else
3865 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3866 return VERR_NOT_SUPPORTED;
3867#endif
3868}
3869
3870
3871/* SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT 1248 */
3872static int vmsvga3dCmdDXClearUAViewFloat(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXClearUAViewFloat const *pCmd, uint32_t cbCmd)
3873{
3874#ifdef VMSVGA3D_DX
3875 DEBUG_BREAKPOINT_TEST();
3876 RT_NOREF(cbCmd);
3877 return vmsvga3dDXClearUAViewFloat(pThisCC, idDXContext, pCmd);
3878#else
3879 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3880 return VERR_NOT_SUPPORTED;
3881#endif
3882}
3883
3884
3885/* SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT 1249 */
3886static int vmsvga3dCmdDXCopyStructureCount(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXCopyStructureCount const *pCmd, uint32_t cbCmd)
3887{
3888#ifdef VMSVGA3D_DX
3889 //DEBUG_BREAKPOINT_TEST();
3890 RT_NOREF(cbCmd);
3891 return vmsvga3dDXCopyStructureCount(pThisCC, idDXContext, pCmd);
3892#else
3893 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3894 return VERR_NOT_SUPPORTED;
3895#endif
3896}
3897
3898
3899/* SVGA_3D_CMD_DX_SET_UA_VIEWS 1250 */
3900static int vmsvga3dCmdDXSetUAViews(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetUAViews const *pCmd, uint32_t cbCmd)
3901{
3902#ifdef VMSVGA3D_DX
3903 //DEBUG_BREAKPOINT_TEST();
3904 SVGA3dUAViewId const *paUAViewId = (SVGA3dUAViewId *)&pCmd[1];
3905 uint32_t const cUAViewId = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dUAViewId);
3906 return vmsvga3dDXSetUAViews(pThisCC, idDXContext, pCmd, cUAViewId, paUAViewId);
3907#else
3908 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3909 return VERR_NOT_SUPPORTED;
3910#endif
3911}
3912
3913
3914/* SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT 1251 */
3915static int vmsvga3dCmdDXDrawIndexedInstancedIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawIndexedInstancedIndirect const *pCmd, uint32_t cbCmd)
3916{
3917#ifdef VMSVGA3D_DX
3918 //DEBUG_BREAKPOINT_TEST();
3919 RT_NOREF(cbCmd);
3920 return vmsvga3dDXDrawIndexedInstancedIndirect(pThisCC, idDXContext, pCmd);
3921#else
3922 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3923 return VERR_NOT_SUPPORTED;
3924#endif
3925}
3926
3927
3928/* SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT 1252 */
3929static int vmsvga3dCmdDXDrawInstancedIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDrawInstancedIndirect const *pCmd, uint32_t cbCmd)
3930{
3931#ifdef VMSVGA3D_DX
3932 //DEBUG_BREAKPOINT_TEST();
3933 RT_NOREF(cbCmd);
3934 return vmsvga3dDXDrawInstancedIndirect(pThisCC, idDXContext, pCmd);
3935#else
3936 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3937 return VERR_NOT_SUPPORTED;
3938#endif
3939}
3940
3941
3942/* SVGA_3D_CMD_DX_DISPATCH 1253 */
3943static int vmsvga3dCmdDXDispatch(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDispatch const *pCmd, uint32_t cbCmd)
3944{
3945#ifdef VMSVGA3D_DX
3946 //DEBUG_BREAKPOINT_TEST();
3947 RT_NOREF(cbCmd);
3948 return vmsvga3dDXDispatch(pThisCC, idDXContext, pCmd);
3949#else
3950 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3951 return VERR_NOT_SUPPORTED;
3952#endif
3953}
3954
3955
3956/* SVGA_3D_CMD_DX_DISPATCH_INDIRECT 1254 */
3957static int vmsvga3dCmdDXDispatchIndirect(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDispatchIndirect const *pCmd, uint32_t cbCmd)
3958{
3959#ifdef VMSVGA3D_DX
3960 DEBUG_BREAKPOINT_TEST();
3961 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3962 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3963 return vmsvga3dDXDispatchIndirect(pThisCC, idDXContext);
3964#else
3965 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3966 return VERR_NOT_SUPPORTED;
3967#endif
3968}
3969
3970
3971/* SVGA_3D_CMD_WRITE_ZERO_SURFACE 1255 */
3972static int vmsvga3dCmdWriteZeroSurface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdWriteZeroSurface const *pCmd, uint32_t cbCmd)
3973{
3974#ifdef VMSVGA3D_DX
3975 DEBUG_BREAKPOINT_TEST();
3976 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3977 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3978 return vmsvga3dWriteZeroSurface(pThisCC, idDXContext);
3979#else
3980 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3981 return VERR_NOT_SUPPORTED;
3982#endif
3983}
3984
3985
3986/* SVGA_3D_CMD_HINT_ZERO_SURFACE 1256 */
3987static int vmsvga3dCmdHintZeroSurface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdHintZeroSurface const *pCmd, uint32_t cbCmd)
3988{
3989#ifdef VMSVGA3D_DX
3990 DEBUG_BREAKPOINT_TEST();
3991 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
3992 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
3993 return vmsvga3dHintZeroSurface(pThisCC, idDXContext);
3994#else
3995 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
3996 return VERR_NOT_SUPPORTED;
3997#endif
3998}
3999
4000
4001/* SVGA_3D_CMD_DX_TRANSFER_TO_BUFFER 1257 */
4002static int vmsvga3dCmdDXTransferToBuffer(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXTransferToBuffer const *pCmd, uint32_t cbCmd)
4003{
4004#ifdef VMSVGA3D_DX
4005 DEBUG_BREAKPOINT_TEST();
4006 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4007 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4008 return vmsvga3dDXTransferToBuffer(pThisCC, idDXContext);
4009#else
4010 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4011 return VERR_NOT_SUPPORTED;
4012#endif
4013}
4014
4015
4016/* SVGA_3D_CMD_DX_SET_STRUCTURE_COUNT 1258 */
4017static int vmsvga3dCmdDXSetStructureCount(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetStructureCount const *pCmd, uint32_t cbCmd)
4018{
4019#ifdef VMSVGA3D_DX
4020 //DEBUG_BREAKPOINT_TEST();
4021 RT_NOREF(cbCmd);
4022 return vmsvga3dDXSetStructureCount(pThisCC, idDXContext, pCmd);
4023#else
4024 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4025 return VERR_NOT_SUPPORTED;
4026#endif
4027}
4028
4029
4030/* SVGA_3D_CMD_LOGICOPS_BITBLT 1259 */
4031static int vmsvga3dCmdLogicOpsBitBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsBitBlt const *pCmd, uint32_t cbCmd)
4032{
4033#ifdef VMSVGA3D_DX
4034 DEBUG_BREAKPOINT_TEST();
4035 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4036 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4037 return vmsvga3dLogicOpsBitBlt(pThisCC, idDXContext);
4038#else
4039 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4040 return VERR_NOT_SUPPORTED;
4041#endif
4042}
4043
4044
4045/* SVGA_3D_CMD_LOGICOPS_TRANSBLT 1260 */
4046static int vmsvga3dCmdLogicOpsTransBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsTransBlt const *pCmd, uint32_t cbCmd)
4047{
4048#ifdef VMSVGA3D_DX
4049 DEBUG_BREAKPOINT_TEST();
4050 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4051 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4052 return vmsvga3dLogicOpsTransBlt(pThisCC, idDXContext);
4053#else
4054 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4055 return VERR_NOT_SUPPORTED;
4056#endif
4057}
4058
4059
4060/* SVGA_3D_CMD_LOGICOPS_STRETCHBLT 1261 */
4061static int vmsvga3dCmdLogicOpsStretchBlt(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsStretchBlt const *pCmd, uint32_t cbCmd)
4062{
4063#ifdef VMSVGA3D_DX
4064 DEBUG_BREAKPOINT_TEST();
4065 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4066 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4067 return vmsvga3dLogicOpsStretchBlt(pThisCC, idDXContext);
4068#else
4069 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4070 return VERR_NOT_SUPPORTED;
4071#endif
4072}
4073
4074
4075/* SVGA_3D_CMD_LOGICOPS_COLORFILL 1262 */
4076static int vmsvga3dCmdLogicOpsColorFill(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsColorFill const *pCmd, uint32_t cbCmd)
4077{
4078#ifdef VMSVGA3D_DX
4079 DEBUG_BREAKPOINT_TEST();
4080 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4081 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4082 return vmsvga3dLogicOpsColorFill(pThisCC, idDXContext);
4083#else
4084 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4085 return VERR_NOT_SUPPORTED;
4086#endif
4087}
4088
4089
4090/* SVGA_3D_CMD_LOGICOPS_ALPHABLEND 1263 */
4091static int vmsvga3dCmdLogicOpsAlphaBlend(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsAlphaBlend const *pCmd, uint32_t cbCmd)
4092{
4093#ifdef VMSVGA3D_DX
4094 DEBUG_BREAKPOINT_TEST();
4095 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4096 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4097 return vmsvga3dLogicOpsAlphaBlend(pThisCC, idDXContext);
4098#else
4099 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4100 return VERR_NOT_SUPPORTED;
4101#endif
4102}
4103
4104
4105/* SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND 1264 */
4106static int vmsvga3dCmdLogicOpsClearTypeBlend(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdLogicOpsClearTypeBlend const *pCmd, uint32_t cbCmd)
4107{
4108#ifdef VMSVGA3D_DX
4109 DEBUG_BREAKPOINT_TEST();
4110 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4111 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4112 return vmsvga3dLogicOpsClearTypeBlend(pThisCC, idDXContext);
4113#else
4114 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4115 return VERR_NOT_SUPPORTED;
4116#endif
4117}
4118
4119
4120/* SVGA_3D_CMD_DEFINE_GB_SURFACE_V4 1267 */
4121static int vmsvga3dCmdDefineGBSurface_v4(PVGASTATECC pThisCC, SVGA3dCmdDefineGBSurface_v4 const *pCmd)
4122{
4123#ifdef VMSVGA3D_DX
4124 //DEBUG_BREAKPOINT_TEST();
4125 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4126
4127 /* Update the entry in the pSvgaR3State->pGboOTableSurface. */
4128 SVGAOTableSurfaceEntry entry;
4129 RT_ZERO(entry);
4130 entry.format = pCmd->format;
4131 entry.surface1Flags = (uint32_t)(pCmd->surfaceFlags);
4132 entry.numMipLevels = pCmd->numMipLevels;
4133 entry.multisampleCount = pCmd->multisampleCount;
4134 entry.autogenFilter = pCmd->autogenFilter;
4135 entry.size = pCmd->size;
4136 entry.mobid = SVGA_ID_INVALID;
4137 entry.arraySize = pCmd->arraySize;
4138 // entry.mobPitch = 0;
4139 // entry.mobPitch = 0;
4140 entry.surface2Flags = (uint32_t)(pCmd->surfaceFlags >> UINT64_C(32));
4141 // entry.multisamplePattern = 0;
4142 // entry.qualityLevel = 0;
4143 entry.bufferByteStride = pCmd->bufferByteStride;
4144 // entry.minLOD = 0;
4145
4146 int rc = vmsvgaR3OTableWrite(pSvgaR3State, &pSvgaR3State->aGboOTables[SVGA_OTABLE_SURFACE],
4147 pCmd->sid, SVGA3D_OTABLE_SURFACE_ENTRY_SIZE, &entry, sizeof(entry));
4148 if (RT_SUCCESS(rc))
4149 {
4150 /* Create the host surface. */
4151 /** @todo SVGAOTableSurfaceEntry as input parameter? */
4152 vmsvga3dSurfaceDefine(pThisCC, pCmd->sid, pCmd->surfaceFlags, pCmd->format,
4153 pCmd->multisampleCount, pCmd->autogenFilter,
4154 pCmd->numMipLevels, &pCmd->size, pCmd->arraySize, /* fAllocMipLevels = */ false);
4155 }
4156 return rc;
4157#else
4158 RT_NOREF(pThisCC, pCmd);
4159 return VERR_NOT_SUPPORTED;
4160#endif
4161}
4162
4163
4164/* SVGA_3D_CMD_DX_SET_CS_UA_VIEWS 1268 */
4165static int vmsvga3dCmdDXSetCSUAViews(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetCSUAViews const *pCmd, uint32_t cbCmd)
4166{
4167#ifdef VMSVGA3D_DX
4168 //DEBUG_BREAKPOINT_TEST();
4169 SVGA3dUAViewId const *paUAViewId = (SVGA3dUAViewId *)&pCmd[1];
4170 uint32_t const cUAViewId = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dUAViewId);
4171 return vmsvga3dDXSetCSUAViews(pThisCC, idDXContext, pCmd, cUAViewId, paUAViewId);
4172#else
4173 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4174 return VERR_NOT_SUPPORTED;
4175#endif
4176}
4177
4178
4179/* SVGA_3D_CMD_DX_SET_MIN_LOD 1269 */
4180static int vmsvga3dCmdDXSetMinLOD(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetMinLOD const *pCmd, uint32_t cbCmd)
4181{
4182#ifdef VMSVGA3D_DX
4183 DEBUG_BREAKPOINT_TEST();
4184 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4185 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4186 return vmsvga3dDXSetMinLOD(pThisCC, idDXContext);
4187#else
4188 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4189 return VERR_NOT_SUPPORTED;
4190#endif
4191}
4192
4193
4194/* SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2 1272 */
4195static int vmsvga3dCmdDXDefineDepthStencilView_v2(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineDepthStencilView_v2 const *pCmd, uint32_t cbCmd)
4196{
4197#ifdef VMSVGA3D_DX
4198 //DEBUG_BREAKPOINT_TEST();
4199 RT_NOREF(cbCmd);
4200 return vmsvga3dDXDefineDepthStencilView(pThisCC, idDXContext, pCmd);
4201#else
4202 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4203 return VERR_NOT_SUPPORTED;
4204#endif
4205}
4206
4207
4208/* SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB 1273 */
4209static int vmsvga3dCmdDXDefineStreamOutputWithMob(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXDefineStreamOutputWithMob const *pCmd, uint32_t cbCmd)
4210{
4211#ifdef VMSVGA3D_DX
4212 //DEBUG_BREAKPOINT_TEST();
4213 RT_NOREF(cbCmd);
4214 return vmsvga3dDXDefineStreamOutputWithMob(pThisCC, idDXContext, pCmd);
4215#else
4216 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4217 return VERR_NOT_SUPPORTED;
4218#endif
4219}
4220
4221
4222/* SVGA_3D_CMD_DX_SET_SHADER_IFACE 1274 */
4223static int vmsvga3dCmdDXSetShaderIface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXSetShaderIface const *pCmd, uint32_t cbCmd)
4224{
4225#ifdef VMSVGA3D_DX
4226 DEBUG_BREAKPOINT_TEST();
4227 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4228 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4229 return vmsvga3dDXSetShaderIface(pThisCC, idDXContext);
4230#else
4231 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4232 return VERR_NOT_SUPPORTED;
4233#endif
4234}
4235
4236
4237/* SVGA_3D_CMD_DX_BIND_STREAMOUTPUT 1275 */
4238static int vmsvga3dCmdDXBindStreamOutput(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindStreamOutput const *pCmd, uint32_t cbCmd)
4239{
4240#ifdef VMSVGA3D_DX
4241 //DEBUG_BREAKPOINT_TEST();
4242 RT_NOREF(cbCmd);
4243 return vmsvga3dDXBindStreamOutput(pThisCC, idDXContext, pCmd);
4244#else
4245 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4246 return VERR_NOT_SUPPORTED;
4247#endif
4248}
4249
4250
4251/* SVGA_3D_CMD_SURFACE_STRETCHBLT_NON_MS_TO_MS 1276 */
4252static int vmsvga3dCmdSurfaceStretchBltNonMSToMS(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdSurfaceStretchBltNonMSToMS const *pCmd, uint32_t cbCmd)
4253{
4254#ifdef VMSVGA3D_DX
4255 DEBUG_BREAKPOINT_TEST();
4256 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4257 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4258 return vmsvga3dSurfaceStretchBltNonMSToMS(pThisCC, idDXContext);
4259#else
4260 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4261 return VERR_NOT_SUPPORTED;
4262#endif
4263}
4264
4265
4266/* SVGA_3D_CMD_DX_BIND_SHADER_IFACE 1277 */
4267static int vmsvga3dCmdDXBindShaderIface(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdDXBindShaderIface const *pCmd, uint32_t cbCmd)
4268{
4269#ifdef VMSVGA3D_DX
4270 DEBUG_BREAKPOINT_TEST();
4271 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
4272 RT_NOREF(pSvgaR3State, pCmd, cbCmd);
4273 return vmsvga3dDXBindShaderIface(pThisCC, idDXContext);
4274#else
4275 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4276 return VERR_NOT_SUPPORTED;
4277#endif
4278}
4279
4280
4281/* SVGA_3D_CMD_VB_DX_CLEAR_RENDERTARGET_VIEW_REGION 1083 */
4282static int vmsvga3dCmdVBDXClearRenderTargetViewRegion(PVGASTATECC pThisCC, uint32_t idDXContext, SVGA3dCmdVBDXClearRenderTargetViewRegion *pCmd, uint32_t cbCmd)
4283{
4284#ifdef VMSVGA3D_DX
4285 //DEBUG_BREAKPOINT_TEST();
4286 SVGASignedRect const *paRect = (SVGASignedRect *)&pCmd[1];
4287 uint32_t const cRect = (cbCmd - sizeof(*pCmd)) / sizeof(SVGASignedRect);
4288 return vmsvga3dVBDXClearRenderTargetViewRegion(pThisCC, idDXContext, pCmd, cRect, paRect);
4289#else
4290 RT_NOREF(pThisCC, idDXContext, pCmd, cbCmd);
4291 return VERR_NOT_SUPPORTED;
4292#endif
4293}
4294
4295
4296/** @def VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
4297 * Check that the 3D command has at least a_cbMin of payload bytes after the
4298 * header. Will break out of the switch if it doesn't.
4299 */
4300# define VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(a_cbMin) \
4301 if (1) { \
4302 AssertMsgBreak(cbCmd >= (a_cbMin), ("size=%#x a_cbMin=%#zx\n", cbCmd, (size_t)(a_cbMin))); \
4303 RT_UNTRUSTED_VALIDATED_FENCE(); \
4304 } else do {} while (0)
4305
4306# define VMSVGA_3D_CMD_NOTIMPL() \
4307 if (1) { \
4308 AssertMsgFailed(("Not implemented %d %s\n", enmCmdId, vmsvgaR3FifoCmdToString(enmCmdId))); \
4309 } else do {} while (0)
4310
4311/** SVGA_3D_CMD_* handler.
4312 * This function parses the command and calls the corresponding command handler.
4313 *
4314 * @param pThis The shared VGA/VMSVGA state.
4315 * @param pThisCC The VGA/VMSVGA state for the current context.
4316 * @param idDXContext VGPU10 DX context of the commands or SVGA3D_INVALID_ID if they are not for a specific context.
4317 * @param enmCmdId SVGA_3D_CMD_* command identifier.
4318 * @param cbCmd Size of the command in bytes.
4319 * @param pvCmd Pointer to the command.
4320 * @returns VBox status code if an error was detected parsing a command.
4321 */
4322int vmsvgaR3Process3dCmd(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t idDXContext, SVGAFifo3dCmdId enmCmdId, uint32_t cbCmd, void const *pvCmd)
4323{
4324 if (enmCmdId > SVGA_3D_CMD_MAX)
4325 {
4326 LogRelMax(16, ("VMSVGA: unsupported 3D command %d\n", enmCmdId));
4327 ASSERT_GUEST_FAILED_RETURN(VERR_NOT_IMPLEMENTED);
4328 }
4329
4330 int rcParse = VINF_SUCCESS;
4331 PVMSVGAR3STATE pSvgaR3State = pThisCC->svga.pSvgaR3State;
4332
4333 switch (enmCmdId)
4334 {
4335 case SVGA_3D_CMD_SURFACE_DEFINE:
4336 {
4337 SVGA3dCmdDefineSurface *pCmd = (SVGA3dCmdDefineSurface *)pvCmd;
4338 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4339 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefine);
4340
4341 SVGA3dCmdDefineSurface_v2 cmd;
4342 cmd.sid = pCmd->sid;
4343 cmd.surfaceFlags = pCmd->surfaceFlags;
4344 cmd.format = pCmd->format;
4345 memcpy(cmd.face, pCmd->face, sizeof(cmd.face));
4346 cmd.multisampleCount = 0;
4347 cmd.autogenFilter = SVGA3D_TEX_FILTER_NONE;
4348
4349 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4350 vmsvga3dCmdDefineSurface(pThisCC, &cmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
4351# ifdef DEBUG_GMR_ACCESS
4352 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
4353# endif
4354 break;
4355 }
4356
4357 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
4358 {
4359 SVGA3dCmdDefineSurface_v2 *pCmd = (SVGA3dCmdDefineSurface_v2 *)pvCmd;
4360 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4361 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDefineV2);
4362
4363 uint32_t const cMipLevelSizes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4364 vmsvga3dCmdDefineSurface(pThisCC, pCmd, cMipLevelSizes, (SVGA3dSize *)(pCmd + 1));
4365# ifdef DEBUG_GMR_ACCESS
4366 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3ResetGmrHandlers, 1, pThis);
4367# endif
4368 break;
4369 }
4370
4371 case SVGA_3D_CMD_SURFACE_DESTROY:
4372 {
4373 SVGA3dCmdDestroySurface *pCmd = (SVGA3dCmdDestroySurface *)pvCmd;
4374 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4375 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDestroy);
4376
4377 vmsvga3dSurfaceDestroy(pThisCC, pCmd->sid);
4378 break;
4379 }
4380
4381 case SVGA_3D_CMD_SURFACE_COPY:
4382 {
4383 SVGA3dCmdSurfaceCopy *pCmd = (SVGA3dCmdSurfaceCopy *)pvCmd;
4384 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4385 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceCopy);
4386
4387 uint32_t const cCopyBoxes = (cbCmd - sizeof(pCmd)) / sizeof(SVGA3dCopyBox);
4388 vmsvga3dSurfaceCopy(pThisCC, pCmd->dest, pCmd->src, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4389 break;
4390 }
4391
4392 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
4393 {
4394 SVGA3dCmdSurfaceStretchBlt *pCmd = (SVGA3dCmdSurfaceStretchBlt *)pvCmd;
4395 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4396 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceStretchBlt);
4397
4398 vmsvga3dSurfaceStretchBlt(pThis, pThisCC, &pCmd->dest, &pCmd->boxDest,
4399 &pCmd->src, &pCmd->boxSrc, pCmd->mode);
4400 break;
4401 }
4402
4403 case SVGA_3D_CMD_SURFACE_DMA:
4404 {
4405 SVGA3dCmdSurfaceDMA *pCmd = (SVGA3dCmdSurfaceDMA *)pvCmd;
4406 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4407 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceDma);
4408
4409 uint64_t u64NanoTS = 0;
4410 if (LogRelIs3Enabled())
4411 u64NanoTS = RTTimeNanoTS();
4412 uint32_t const cCopyBoxes = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyBox);
4413 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
4414 vmsvga3dSurfaceDMA(pThis, pThisCC, pCmd->guest, pCmd->host, pCmd->transfer,
4415 cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4416 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dSurfaceDmaProf, a);
4417 if (LogRelIs3Enabled())
4418 {
4419 if (cCopyBoxes)
4420 {
4421 SVGA3dCopyBox *pFirstBox = (SVGA3dCopyBox *)(pCmd + 1);
4422 LogRel3(("VMSVGA: SURFACE_DMA: %d us %d boxes %d,%d %dx%d%s\n",
4423 (RTTimeNanoTS() - u64NanoTS) / 1000ULL, cCopyBoxes,
4424 pFirstBox->x, pFirstBox->y, pFirstBox->w, pFirstBox->h,
4425 pCmd->transfer == SVGA3D_READ_HOST_VRAM ? " readback!!!" : ""));
4426 }
4427 }
4428 break;
4429 }
4430
4431 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
4432 {
4433 SVGA3dCmdBlitSurfaceToScreen *pCmd = (SVGA3dCmdBlitSurfaceToScreen *)pvCmd;
4434 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4435 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSurfaceScreen);
4436
4437 static uint64_t u64FrameStartNanoTS = 0;
4438 static uint64_t u64ElapsedPerSecNano = 0;
4439 static int cFrames = 0;
4440 uint64_t u64NanoTS = 0;
4441 if (LogRelIs3Enabled())
4442 u64NanoTS = RTTimeNanoTS();
4443 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGASignedRect);
4444 STAM_REL_PROFILE_START(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
4445 vmsvga3dSurfaceBlitToScreen(pThis, pThisCC, pCmd->destScreenId, pCmd->destRect, pCmd->srcImage,
4446 pCmd->srcRect, cRects, (SVGASignedRect *)(pCmd + 1));
4447 STAM_REL_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dBlitSurfaceToScreenProf, a);
4448 if (LogRelIs3Enabled())
4449 {
4450 uint64_t u64ElapsedNano = RTTimeNanoTS() - u64NanoTS;
4451 u64ElapsedPerSecNano += u64ElapsedNano;
4452
4453 SVGASignedRect *pFirstRect = cRects ? (SVGASignedRect *)(pCmd + 1) : &pCmd->destRect;
4454 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: %d us %d rects %d,%d %dx%d\n",
4455 (u64ElapsedNano) / 1000ULL, cRects,
4456 pFirstRect->left, pFirstRect->top,
4457 pFirstRect->right - pFirstRect->left, pFirstRect->bottom - pFirstRect->top));
4458
4459 ++cFrames;
4460 if (u64NanoTS - u64FrameStartNanoTS >= UINT64_C(1000000000))
4461 {
4462 LogRel3(("VMSVGA: SURFACE_TO_SCREEN: FPS %d, elapsed %llu us\n",
4463 cFrames, u64ElapsedPerSecNano / 1000ULL));
4464 u64FrameStartNanoTS = u64NanoTS;
4465 cFrames = 0;
4466 u64ElapsedPerSecNano = 0;
4467 }
4468 }
4469 break;
4470 }
4471
4472 case SVGA_3D_CMD_CONTEXT_DEFINE:
4473 {
4474 SVGA3dCmdDefineContext *pCmd = (SVGA3dCmdDefineContext *)pvCmd;
4475 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4476 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDefine);
4477
4478 vmsvga3dContextDefine(pThisCC, pCmd->cid);
4479 break;
4480 }
4481
4482 case SVGA_3D_CMD_CONTEXT_DESTROY:
4483 {
4484 SVGA3dCmdDestroyContext *pCmd = (SVGA3dCmdDestroyContext *)pvCmd;
4485 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4486 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dContextDestroy);
4487
4488 vmsvga3dContextDestroy(pThisCC, pCmd->cid);
4489 break;
4490 }
4491
4492 case SVGA_3D_CMD_SETTRANSFORM:
4493 {
4494 SVGA3dCmdSetTransform *pCmd = (SVGA3dCmdSetTransform *)pvCmd;
4495 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4496 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTransform);
4497
4498 vmsvga3dSetTransform(pThisCC, pCmd->cid, pCmd->type, pCmd->matrix);
4499 break;
4500 }
4501
4502 case SVGA_3D_CMD_SETZRANGE:
4503 {
4504 SVGA3dCmdSetZRange *pCmd = (SVGA3dCmdSetZRange *)pvCmd;
4505 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4506 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetZRange);
4507
4508 vmsvga3dSetZRange(pThisCC, pCmd->cid, pCmd->zRange);
4509 break;
4510 }
4511
4512 case SVGA_3D_CMD_SETRENDERSTATE:
4513 {
4514 SVGA3dCmdSetRenderState *pCmd = (SVGA3dCmdSetRenderState *)pvCmd;
4515 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4516 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderState);
4517
4518 uint32_t const cRenderStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRenderState);
4519 vmsvga3dSetRenderState(pThisCC, pCmd->cid, cRenderStates, (SVGA3dRenderState *)(pCmd + 1));
4520 break;
4521 }
4522
4523 case SVGA_3D_CMD_SETRENDERTARGET:
4524 {
4525 SVGA3dCmdSetRenderTarget *pCmd = (SVGA3dCmdSetRenderTarget *)pvCmd;
4526 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4527 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetRenderTarget);
4528
4529 vmsvga3dSetRenderTarget(pThisCC, pCmd->cid, pCmd->type, pCmd->target);
4530 break;
4531 }
4532
4533 case SVGA_3D_CMD_SETTEXTURESTATE:
4534 {
4535 SVGA3dCmdSetTextureState *pCmd = (SVGA3dCmdSetTextureState *)pvCmd;
4536 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4537 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetTextureState);
4538
4539 uint32_t const cTextureStates = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dTextureState);
4540 vmsvga3dSetTextureState(pThisCC, pCmd->cid, cTextureStates, (SVGA3dTextureState *)(pCmd + 1));
4541 break;
4542 }
4543
4544 case SVGA_3D_CMD_SETMATERIAL:
4545 {
4546 SVGA3dCmdSetMaterial *pCmd = (SVGA3dCmdSetMaterial *)pvCmd;
4547 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4548 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetMaterial);
4549
4550 vmsvga3dSetMaterial(pThisCC, pCmd->cid, pCmd->face, &pCmd->material);
4551 break;
4552 }
4553
4554 case SVGA_3D_CMD_SETLIGHTDATA:
4555 {
4556 SVGA3dCmdSetLightData *pCmd = (SVGA3dCmdSetLightData *)pvCmd;
4557 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4558 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightData);
4559
4560 vmsvga3dSetLightData(pThisCC, pCmd->cid, pCmd->index, &pCmd->data);
4561 break;
4562 }
4563
4564 case SVGA_3D_CMD_SETLIGHTENABLED:
4565 {
4566 SVGA3dCmdSetLightEnabled *pCmd = (SVGA3dCmdSetLightEnabled *)pvCmd;
4567 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4568 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetLightEnable);
4569
4570 vmsvga3dSetLightEnabled(pThisCC, pCmd->cid, pCmd->index, pCmd->enabled);
4571 break;
4572 }
4573
4574 case SVGA_3D_CMD_SETVIEWPORT:
4575 {
4576 SVGA3dCmdSetViewport *pCmd = (SVGA3dCmdSetViewport *)pvCmd;
4577 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4578 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetViewPort);
4579
4580 vmsvga3dSetViewPort(pThisCC, pCmd->cid, &pCmd->rect);
4581 break;
4582 }
4583
4584 case SVGA_3D_CMD_SETCLIPPLANE:
4585 {
4586 SVGA3dCmdSetClipPlane *pCmd = (SVGA3dCmdSetClipPlane *)pvCmd;
4587 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4588 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetClipPlane);
4589
4590 vmsvga3dSetClipPlane(pThisCC, pCmd->cid, pCmd->index, pCmd->plane);
4591 break;
4592 }
4593
4594 case SVGA_3D_CMD_CLEAR:
4595 {
4596 SVGA3dCmdClear *pCmd = (SVGA3dCmdClear *)pvCmd;
4597 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4598 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dClear);
4599
4600 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dRect);
4601 vmsvga3dCommandClear(pThisCC, pCmd->cid, pCmd->clearFlag, pCmd->color, pCmd->depth, pCmd->stencil, cRects, (SVGA3dRect *)(pCmd + 1));
4602 break;
4603 }
4604
4605 case SVGA_3D_CMD_PRESENT:
4606 case SVGA_3D_CMD_PRESENT_READBACK: /** @todo SVGA_3D_CMD_PRESENT_READBACK isn't quite the same as present... */
4607 {
4608 SVGA3dCmdPresent *pCmd = (SVGA3dCmdPresent *)pvCmd;
4609 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4610 if (enmCmdId == SVGA_3D_CMD_PRESENT)
4611 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresent);
4612 else
4613 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dPresentReadBack);
4614
4615 uint32_t const cRects = (cbCmd - sizeof(*pCmd)) / sizeof(SVGA3dCopyRect);
4616 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
4617 vmsvga3dCommandPresent(pThis, pThisCC, pCmd->sid, cRects, (SVGA3dCopyRect *)(pCmd + 1));
4618 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dPresentProf, a);
4619 break;
4620 }
4621
4622 case SVGA_3D_CMD_SHADER_DEFINE:
4623 {
4624 SVGA3dCmdDefineShader *pCmd = (SVGA3dCmdDefineShader *)pvCmd;
4625 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4626 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDefine);
4627
4628 uint32_t const cbData = (cbCmd - sizeof(*pCmd));
4629 vmsvga3dShaderDefine(pThisCC, pCmd->cid, pCmd->shid, pCmd->type, cbData, (uint32_t *)(pCmd + 1));
4630 break;
4631 }
4632
4633 case SVGA_3D_CMD_SHADER_DESTROY:
4634 {
4635 SVGA3dCmdDestroyShader *pCmd = (SVGA3dCmdDestroyShader *)pvCmd;
4636 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4637 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dShaderDestroy);
4638
4639 vmsvga3dShaderDestroy(pThisCC, pCmd->cid, pCmd->shid, pCmd->type);
4640 break;
4641 }
4642
4643 case SVGA_3D_CMD_SET_SHADER:
4644 {
4645 SVGA3dCmdSetShader *pCmd = (SVGA3dCmdSetShader *)pvCmd;
4646 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4647 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShader);
4648
4649 vmsvga3dShaderSet(pThisCC, NULL, pCmd->cid, pCmd->type, pCmd->shid);
4650 break;
4651 }
4652
4653 case SVGA_3D_CMD_SET_SHADER_CONST:
4654 {
4655 SVGA3dCmdSetShaderConst *pCmd = (SVGA3dCmdSetShaderConst *)pvCmd;
4656 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4657 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetShaderConst);
4658
4659 uint32_t const cRegisters = (cbCmd - sizeof(*pCmd)) / sizeof(pCmd->values) + 1;
4660 vmsvga3dShaderSetConst(pThisCC, pCmd->cid, pCmd->reg, pCmd->type, pCmd->ctype, cRegisters, pCmd->values);
4661 break;
4662 }
4663
4664 case SVGA_3D_CMD_DRAW_PRIMITIVES:
4665 {
4666 SVGA3dCmdDrawPrimitives *pCmd = (SVGA3dCmdDrawPrimitives *)pvCmd;
4667 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4668 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDrawPrimitives);
4669
4670 ASSERT_GUEST_STMT_BREAK(pCmd->numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES, rcParse = VERR_INVALID_PARAMETER);
4671 ASSERT_GUEST_STMT_BREAK(pCmd->numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, rcParse = VERR_INVALID_PARAMETER);
4672 uint32_t const cbRangesAndVertexDecls = pCmd->numVertexDecls * sizeof(SVGA3dVertexDecl)
4673 + pCmd->numRanges * sizeof(SVGA3dPrimitiveRange);
4674 ASSERT_GUEST_STMT_BREAK(cbRangesAndVertexDecls <= cbCmd - sizeof(*pCmd), rcParse = VERR_INVALID_PARAMETER);
4675
4676 uint32_t const cVertexDivisor = (cbCmd - sizeof(*pCmd) - cbRangesAndVertexDecls) / sizeof(uint32_t);
4677 ASSERT_GUEST_STMT_BREAK(!cVertexDivisor || cVertexDivisor == pCmd->numVertexDecls, rcParse = VERR_INVALID_PARAMETER);
4678 RT_UNTRUSTED_VALIDATED_FENCE();
4679
4680 SVGA3dVertexDecl *pVertexDecl = (SVGA3dVertexDecl *)(pCmd + 1);
4681 SVGA3dPrimitiveRange *pNumRange = (SVGA3dPrimitiveRange *)&pVertexDecl[pCmd->numVertexDecls];
4682 SVGA3dVertexDivisor *pVertexDivisor = cVertexDivisor ? (SVGA3dVertexDivisor *)&pNumRange[pCmd->numRanges] : NULL;
4683
4684 STAM_PROFILE_START(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
4685 vmsvga3dDrawPrimitives(pThisCC, pCmd->cid, pCmd->numVertexDecls, pVertexDecl, pCmd->numRanges,
4686 pNumRange, cVertexDivisor, pVertexDivisor);
4687 STAM_PROFILE_STOP(&pSvgaR3State->StatR3Cmd3dDrawPrimitivesProf, a);
4688 break;
4689 }
4690
4691 case SVGA_3D_CMD_SETSCISSORRECT:
4692 {
4693 SVGA3dCmdSetScissorRect *pCmd = (SVGA3dCmdSetScissorRect *)pvCmd;
4694 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4695 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dSetScissorRect);
4696
4697 vmsvga3dSetScissorRect(pThisCC, pCmd->cid, &pCmd->rect);
4698 break;
4699 }
4700
4701 case SVGA_3D_CMD_BEGIN_QUERY:
4702 {
4703 SVGA3dCmdBeginQuery *pCmd = (SVGA3dCmdBeginQuery *)pvCmd;
4704 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4705 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dBeginQuery);
4706
4707 vmsvga3dQueryBegin(pThisCC, pCmd->cid, pCmd->type);
4708 break;
4709 }
4710
4711 case SVGA_3D_CMD_END_QUERY:
4712 {
4713 SVGA3dCmdEndQuery *pCmd = (SVGA3dCmdEndQuery *)pvCmd;
4714 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4715 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dEndQuery);
4716
4717 vmsvga3dQueryEnd(pThisCC, pCmd->cid, pCmd->type);
4718 break;
4719 }
4720
4721 case SVGA_3D_CMD_WAIT_FOR_QUERY:
4722 {
4723 SVGA3dCmdWaitForQuery *pCmd = (SVGA3dCmdWaitForQuery *)pvCmd;
4724 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4725 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dWaitForQuery);
4726
4727 vmsvga3dQueryWait(pThisCC, pCmd->cid, pCmd->type, pThis, &pCmd->guestResult);
4728 break;
4729 }
4730
4731 case SVGA_3D_CMD_GENERATE_MIPMAPS:
4732 {
4733 SVGA3dCmdGenerateMipmaps *pCmd = (SVGA3dCmdGenerateMipmaps *)pvCmd;
4734 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4735 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dGenerateMipmaps);
4736
4737 vmsvga3dGenerateMipmaps(pThisCC, pCmd->sid, pCmd->filter);
4738 break;
4739 }
4740
4741 case SVGA_3D_CMD_ACTIVATE_SURFACE:
4742 /* context id + surface id? */
4743 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dActivateSurface);
4744 break;
4745
4746 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
4747 /* context id + surface id? */
4748 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3Cmd3dDeactivateSurface);
4749 break;
4750
4751 /*
4752 *
4753 * VPGU10: SVGA_CAP_GBOBJECTS+ commands.
4754 *
4755 */
4756 case SVGA_3D_CMD_SCREEN_DMA:
4757 {
4758 SVGA3dCmdScreenDMA *pCmd = (SVGA3dCmdScreenDMA *)pvCmd;
4759 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4760 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4761 break;
4762 }
4763
4764 /* case SVGA_3D_CMD_DEAD1: New SVGA_3D_CMD_VB_DX_CLEAR_RENDERTARGET_VIEW_REGION */
4765 case SVGA_3D_CMD_DEAD2:
4766 case SVGA_3D_CMD_DEAD12: /* Old SVGA_3D_CMD_LOGICOPS_BITBLT */
4767 case SVGA_3D_CMD_DEAD13: /* Old SVGA_3D_CMD_LOGICOPS_TRANSBLT */
4768 case SVGA_3D_CMD_DEAD14: /* Old SVGA_3D_CMD_LOGICOPS_STRETCHBLT */
4769 case SVGA_3D_CMD_DEAD15: /* Old SVGA_3D_CMD_LOGICOPS_COLORFILL */
4770 case SVGA_3D_CMD_DEAD16: /* Old SVGA_3D_CMD_LOGICOPS_ALPHABLEND */
4771 case SVGA_3D_CMD_DEAD17: /* Old SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND */
4772 {
4773 VMSVGA_3D_CMD_NOTIMPL();
4774 break;
4775 }
4776
4777 case SVGA_3D_CMD_SET_OTABLE_BASE:
4778 {
4779 SVGA3dCmdSetOTableBase *pCmd = (SVGA3dCmdSetOTableBase *)pvCmd;
4780 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4781 vmsvga3dCmdSetOTableBase(pThisCC, pCmd);
4782 break;
4783 }
4784
4785 case SVGA_3D_CMD_READBACK_OTABLE:
4786 {
4787 SVGA3dCmdReadbackOTable *pCmd = (SVGA3dCmdReadbackOTable *)pvCmd;
4788 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4789 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4790 break;
4791 }
4792
4793 case SVGA_3D_CMD_DEFINE_GB_MOB:
4794 {
4795 SVGA3dCmdDefineGBMob *pCmd = (SVGA3dCmdDefineGBMob *)pvCmd;
4796 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4797 vmsvga3dCmdDefineGBMob(pThisCC, pCmd);
4798 break;
4799 }
4800
4801 case SVGA_3D_CMD_DESTROY_GB_MOB:
4802 {
4803 SVGA3dCmdDestroyGBMob *pCmd = (SVGA3dCmdDestroyGBMob *)pvCmd;
4804 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4805 vmsvga3dCmdDestroyGBMob(pThisCC, pCmd);
4806 break;
4807 }
4808
4809 case SVGA_3D_CMD_DEAD3:
4810 {
4811 VMSVGA_3D_CMD_NOTIMPL();
4812 break;
4813 }
4814
4815 case SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING:
4816 {
4817 SVGA3dCmdUpdateGBMobMapping *pCmd = (SVGA3dCmdUpdateGBMobMapping *)pvCmd;
4818 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4819 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4820 break;
4821 }
4822
4823 case SVGA_3D_CMD_DEFINE_GB_SURFACE:
4824 {
4825 SVGA3dCmdDefineGBSurface *pCmd = (SVGA3dCmdDefineGBSurface *)pvCmd;
4826 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4827 vmsvga3dCmdDefineGBSurface(pThisCC, pCmd);
4828 break;
4829 }
4830
4831 case SVGA_3D_CMD_DESTROY_GB_SURFACE:
4832 {
4833 SVGA3dCmdDestroyGBSurface *pCmd = (SVGA3dCmdDestroyGBSurface *)pvCmd;
4834 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4835 vmsvga3dCmdDestroyGBSurface(pThisCC, pCmd);
4836 break;
4837 }
4838
4839 case SVGA_3D_CMD_BIND_GB_SURFACE:
4840 {
4841 SVGA3dCmdBindGBSurface *pCmd = (SVGA3dCmdBindGBSurface *)pvCmd;
4842 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4843 vmsvga3dCmdBindGBSurface(pThisCC, pCmd);
4844 break;
4845 }
4846
4847 case SVGA_3D_CMD_COND_BIND_GB_SURFACE:
4848 {
4849 SVGA3dCmdCondBindGBSurface *pCmd = (SVGA3dCmdCondBindGBSurface *)pvCmd;
4850 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4851 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4852 break;
4853 }
4854
4855 case SVGA_3D_CMD_UPDATE_GB_IMAGE:
4856 {
4857 SVGA3dCmdUpdateGBImage *pCmd = (SVGA3dCmdUpdateGBImage *)pvCmd;
4858 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4859 vmsvga3dCmdUpdateGBImage(pThisCC, pCmd);
4860 break;
4861 }
4862
4863 case SVGA_3D_CMD_UPDATE_GB_SURFACE:
4864 {
4865 SVGA3dCmdUpdateGBSurface *pCmd = (SVGA3dCmdUpdateGBSurface *)pvCmd;
4866 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4867 vmsvga3dCmdUpdateGBSurface(pThisCC, pCmd);
4868 break;
4869 }
4870
4871 case SVGA_3D_CMD_READBACK_GB_IMAGE:
4872 {
4873 SVGA3dCmdReadbackGBImage *pCmd = (SVGA3dCmdReadbackGBImage *)pvCmd;
4874 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4875 vmsvga3dCmdReadbackGBImage(pThisCC, pCmd);
4876 break;
4877 }
4878
4879 case SVGA_3D_CMD_READBACK_GB_SURFACE:
4880 {
4881 SVGA3dCmdReadbackGBSurface *pCmd = (SVGA3dCmdReadbackGBSurface *)pvCmd;
4882 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4883 vmsvga3dCmdReadbackGBSurface(pThisCC, pCmd);
4884 break;
4885 }
4886
4887 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE:
4888 {
4889 SVGA3dCmdInvalidateGBImage *pCmd = (SVGA3dCmdInvalidateGBImage *)pvCmd;
4890 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4891 vmsvga3dCmdInvalidateGBImage(pThisCC, pCmd);
4892 break;
4893 }
4894
4895 case SVGA_3D_CMD_INVALIDATE_GB_SURFACE:
4896 {
4897 SVGA3dCmdInvalidateGBSurface *pCmd = (SVGA3dCmdInvalidateGBSurface *)pvCmd;
4898 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4899 vmsvga3dCmdInvalidateGBSurface(pThisCC, pCmd);
4900 break;
4901 }
4902
4903 case SVGA_3D_CMD_DEFINE_GB_CONTEXT:
4904 {
4905 SVGA3dCmdDefineGBContext *pCmd = (SVGA3dCmdDefineGBContext *)pvCmd;
4906 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4907 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4908 break;
4909 }
4910
4911 case SVGA_3D_CMD_DESTROY_GB_CONTEXT:
4912 {
4913 SVGA3dCmdDestroyGBContext *pCmd = (SVGA3dCmdDestroyGBContext *)pvCmd;
4914 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4915 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4916 break;
4917 }
4918
4919 case SVGA_3D_CMD_BIND_GB_CONTEXT:
4920 {
4921 SVGA3dCmdBindGBContext *pCmd = (SVGA3dCmdBindGBContext *)pvCmd;
4922 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4923 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4924 break;
4925 }
4926
4927 case SVGA_3D_CMD_READBACK_GB_CONTEXT:
4928 {
4929 SVGA3dCmdReadbackGBContext *pCmd = (SVGA3dCmdReadbackGBContext *)pvCmd;
4930 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4931 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4932 break;
4933 }
4934
4935 case SVGA_3D_CMD_INVALIDATE_GB_CONTEXT:
4936 {
4937 SVGA3dCmdInvalidateGBContext *pCmd = (SVGA3dCmdInvalidateGBContext *)pvCmd;
4938 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4939 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4940 break;
4941 }
4942
4943 case SVGA_3D_CMD_DEFINE_GB_SHADER:
4944 {
4945 SVGA3dCmdDefineGBShader *pCmd = (SVGA3dCmdDefineGBShader *)pvCmd;
4946 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4947 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4948 break;
4949 }
4950
4951 case SVGA_3D_CMD_DESTROY_GB_SHADER:
4952 {
4953 SVGA3dCmdDestroyGBShader *pCmd = (SVGA3dCmdDestroyGBShader *)pvCmd;
4954 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4955 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4956 break;
4957 }
4958
4959 case SVGA_3D_CMD_BIND_GB_SHADER:
4960 {
4961 SVGA3dCmdBindGBShader *pCmd = (SVGA3dCmdBindGBShader *)pvCmd;
4962 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4963 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4964 break;
4965 }
4966
4967 case SVGA_3D_CMD_SET_OTABLE_BASE64:
4968 {
4969 SVGA3dCmdSetOTableBase64 *pCmd = (SVGA3dCmdSetOTableBase64 *)pvCmd;
4970 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4971 vmsvga3dCmdSetOTableBase64(pThisCC, pCmd);
4972 break;
4973 }
4974
4975 case SVGA_3D_CMD_BEGIN_GB_QUERY:
4976 {
4977 SVGA3dCmdBeginGBQuery *pCmd = (SVGA3dCmdBeginGBQuery *)pvCmd;
4978 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4979 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4980 break;
4981 }
4982
4983 case SVGA_3D_CMD_END_GB_QUERY:
4984 {
4985 SVGA3dCmdEndGBQuery *pCmd = (SVGA3dCmdEndGBQuery *)pvCmd;
4986 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4987 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4988 break;
4989 }
4990
4991 case SVGA_3D_CMD_WAIT_FOR_GB_QUERY:
4992 {
4993 SVGA3dCmdWaitForGBQuery *pCmd = (SVGA3dCmdWaitForGBQuery *)pvCmd;
4994 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4995 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
4996 break;
4997 }
4998
4999 case SVGA_3D_CMD_NOP:
5000 {
5001 /* Apparently there is nothing to do. */
5002 break;
5003 }
5004
5005 case SVGA_3D_CMD_ENABLE_GART:
5006 {
5007 SVGA3dCmdEnableGart *pCmd = (SVGA3dCmdEnableGart *)pvCmd;
5008 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5009 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5010 break;
5011 }
5012
5013 case SVGA_3D_CMD_DISABLE_GART:
5014 {
5015 /* No corresponding SVGA3dCmd structure. */
5016 VMSVGA_3D_CMD_NOTIMPL();
5017 break;
5018 }
5019
5020 case SVGA_3D_CMD_MAP_MOB_INTO_GART:
5021 {
5022 SVGA3dCmdMapMobIntoGart *pCmd = (SVGA3dCmdMapMobIntoGart *)pvCmd;
5023 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5024 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5025 break;
5026 }
5027
5028 case SVGA_3D_CMD_UNMAP_GART_RANGE:
5029 {
5030 SVGA3dCmdUnmapGartRange *pCmd = (SVGA3dCmdUnmapGartRange *)pvCmd;
5031 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5032 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5033 break;
5034 }
5035
5036 case SVGA_3D_CMD_DEFINE_GB_SCREENTARGET:
5037 {
5038 SVGA3dCmdDefineGBScreenTarget *pCmd = (SVGA3dCmdDefineGBScreenTarget *)pvCmd;
5039 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5040 vmsvga3dCmdDefineGBScreenTarget(pThis, pThisCC, pCmd);
5041 break;
5042 }
5043
5044 case SVGA_3D_CMD_DESTROY_GB_SCREENTARGET:
5045 {
5046 SVGA3dCmdDestroyGBScreenTarget *pCmd = (SVGA3dCmdDestroyGBScreenTarget *)pvCmd;
5047 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5048 vmsvga3dCmdDestroyGBScreenTarget(pThis, pThisCC, pCmd);
5049 break;
5050 }
5051
5052 case SVGA_3D_CMD_BIND_GB_SCREENTARGET:
5053 {
5054 SVGA3dCmdBindGBScreenTarget *pCmd = (SVGA3dCmdBindGBScreenTarget *)pvCmd;
5055 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5056 vmsvga3dCmdBindGBScreenTarget(pThisCC, pCmd);
5057 break;
5058 }
5059
5060 case SVGA_3D_CMD_UPDATE_GB_SCREENTARGET:
5061 {
5062 SVGA3dCmdUpdateGBScreenTarget *pCmd = (SVGA3dCmdUpdateGBScreenTarget *)pvCmd;
5063 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5064 vmsvga3dCmdUpdateGBScreenTarget(pThisCC, pCmd);
5065 break;
5066 }
5067
5068 case SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL:
5069 {
5070 SVGA3dCmdReadbackGBImagePartial *pCmd = (SVGA3dCmdReadbackGBImagePartial *)pvCmd;
5071 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5072 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5073 break;
5074 }
5075
5076 case SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL:
5077 {
5078 SVGA3dCmdInvalidateGBImagePartial *pCmd = (SVGA3dCmdInvalidateGBImagePartial *)pvCmd;
5079 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5080 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5081 break;
5082 }
5083
5084 case SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE:
5085 {
5086 SVGA3dCmdSetGBShaderConstInline *pCmd = (SVGA3dCmdSetGBShaderConstInline *)pvCmd;
5087 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5088 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5089 break;
5090 }
5091
5092 case SVGA_3D_CMD_GB_SCREEN_DMA:
5093 {
5094 SVGA3dCmdGBScreenDMA *pCmd = (SVGA3dCmdGBScreenDMA *)pvCmd;
5095 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5096 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5097 break;
5098 }
5099
5100 case SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH:
5101 {
5102 SVGA3dCmdBindGBSurfaceWithPitch *pCmd = (SVGA3dCmdBindGBSurfaceWithPitch *)pvCmd;
5103 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5104 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5105 break;
5106 }
5107
5108 case SVGA_3D_CMD_GB_MOB_FENCE:
5109 {
5110 SVGA3dCmdGBMobFence *pCmd = (SVGA3dCmdGBMobFence *)pvCmd;
5111 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5112 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5113 break;
5114 }
5115
5116 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V2:
5117 {
5118 SVGA3dCmdDefineGBSurface_v2 *pCmd = (SVGA3dCmdDefineGBSurface_v2 *)pvCmd;
5119 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5120 vmsvga3dCmdDefineGBSurface_v2(pThisCC, pCmd);
5121 break;
5122 }
5123
5124 case SVGA_3D_CMD_DEFINE_GB_MOB64:
5125 {
5126 SVGA3dCmdDefineGBMob64 *pCmd = (SVGA3dCmdDefineGBMob64 *)pvCmd;
5127 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5128 vmsvga3dCmdDefineGBMob64(pThisCC, pCmd);
5129 break;
5130 }
5131
5132 case SVGA_3D_CMD_REDEFINE_GB_MOB64:
5133 {
5134 SVGA3dCmdRedefineGBMob64 *pCmd = (SVGA3dCmdRedefineGBMob64 *)pvCmd;
5135 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5136 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5137 break;
5138 }
5139
5140 case SVGA_3D_CMD_NOP_ERROR:
5141 {
5142 /* Apparently there is nothing to do. */
5143 break;
5144 }
5145
5146 case SVGA_3D_CMD_SET_VERTEX_STREAMS:
5147 {
5148 SVGA3dCmdSetVertexStreams *pCmd = (SVGA3dCmdSetVertexStreams *)pvCmd;
5149 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5150 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5151 break;
5152 }
5153
5154 case SVGA_3D_CMD_SET_VERTEX_DECLS:
5155 {
5156 SVGA3dCmdSetVertexDecls *pCmd = (SVGA3dCmdSetVertexDecls *)pvCmd;
5157 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5158 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5159 break;
5160 }
5161
5162 case SVGA_3D_CMD_SET_VERTEX_DIVISORS:
5163 {
5164 SVGA3dCmdSetVertexDivisors *pCmd = (SVGA3dCmdSetVertexDivisors *)pvCmd;
5165 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5166 VMSVGA_3D_CMD_NOTIMPL(); RT_NOREF(pCmd);
5167 break;
5168 }
5169
5170 case SVGA_3D_CMD_DRAW:
5171 {
5172 /* No corresponding SVGA3dCmd structure. */
5173 VMSVGA_3D_CMD_NOTIMPL();
5174 break;
5175 }
5176
5177 case SVGA_3D_CMD_DRAW_INDEXED:
5178 {
5179 /* No corresponding SVGA3dCmd structure. */
5180 VMSVGA_3D_CMD_NOTIMPL();
5181 break;
5182 }
5183
5184 case SVGA_3D_CMD_DX_DEFINE_CONTEXT:
5185 {
5186 SVGA3dCmdDXDefineContext *pCmd = (SVGA3dCmdDXDefineContext *)pvCmd;
5187 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5188 rcParse = vmsvga3dCmdDXDefineContext(pThisCC, pCmd, cbCmd);
5189 break;
5190 }
5191
5192 case SVGA_3D_CMD_DX_DESTROY_CONTEXT:
5193 {
5194 SVGA3dCmdDXDestroyContext *pCmd = (SVGA3dCmdDXDestroyContext *)pvCmd;
5195 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5196 rcParse = vmsvga3dCmdDXDestroyContext(pThisCC, pCmd, cbCmd);
5197 break;
5198 }
5199
5200 case SVGA_3D_CMD_DX_BIND_CONTEXT:
5201 {
5202 SVGA3dCmdDXBindContext *pCmd = (SVGA3dCmdDXBindContext *)pvCmd;
5203 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5204 rcParse = vmsvga3dCmdDXBindContext(pThisCC, pCmd, cbCmd);
5205 break;
5206 }
5207
5208 case SVGA_3D_CMD_DX_READBACK_CONTEXT:
5209 {
5210 SVGA3dCmdDXReadbackContext *pCmd = (SVGA3dCmdDXReadbackContext *)pvCmd;
5211 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5212 rcParse = vmsvga3dCmdDXReadbackContext(pThisCC, pCmd, cbCmd);
5213 break;
5214 }
5215
5216 case SVGA_3D_CMD_DX_INVALIDATE_CONTEXT:
5217 {
5218 SVGA3dCmdDXInvalidateContext *pCmd = (SVGA3dCmdDXInvalidateContext *)pvCmd;
5219 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5220 rcParse = vmsvga3dCmdDXInvalidateContext(pThisCC, idDXContext, pCmd, cbCmd);
5221 break;
5222 }
5223
5224 case SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER:
5225 {
5226 SVGA3dCmdDXSetSingleConstantBuffer *pCmd = (SVGA3dCmdDXSetSingleConstantBuffer *)pvCmd;
5227 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5228 rcParse = vmsvga3dCmdDXSetSingleConstantBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5229 break;
5230 }
5231
5232 case SVGA_3D_CMD_DX_SET_SHADER_RESOURCES:
5233 {
5234 SVGA3dCmdDXSetShaderResources *pCmd = (SVGA3dCmdDXSetShaderResources *)pvCmd;
5235 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5236 rcParse = vmsvga3dCmdDXSetShaderResources(pThisCC, idDXContext, pCmd, cbCmd);
5237 break;
5238 }
5239
5240 case SVGA_3D_CMD_DX_SET_SHADER:
5241 {
5242 SVGA3dCmdDXSetShader *pCmd = (SVGA3dCmdDXSetShader *)pvCmd;
5243 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5244 rcParse = vmsvga3dCmdDXSetShader(pThisCC, idDXContext, pCmd, cbCmd);
5245 break;
5246 }
5247
5248 case SVGA_3D_CMD_DX_SET_SAMPLERS:
5249 {
5250 SVGA3dCmdDXSetSamplers *pCmd = (SVGA3dCmdDXSetSamplers *)pvCmd;
5251 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5252 rcParse = vmsvga3dCmdDXSetSamplers(pThisCC, idDXContext, pCmd, cbCmd);
5253 break;
5254 }
5255
5256 case SVGA_3D_CMD_DX_DRAW:
5257 {
5258 SVGA3dCmdDXDraw *pCmd = (SVGA3dCmdDXDraw *)pvCmd;
5259 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5260 rcParse = vmsvga3dCmdDXDraw(pThisCC, idDXContext, pCmd, cbCmd);
5261 break;
5262 }
5263
5264 case SVGA_3D_CMD_DX_DRAW_INDEXED:
5265 {
5266 SVGA3dCmdDXDrawIndexed *pCmd = (SVGA3dCmdDXDrawIndexed *)pvCmd;
5267 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5268 rcParse = vmsvga3dCmdDXDrawIndexed(pThisCC, idDXContext, pCmd, cbCmd);
5269 break;
5270 }
5271
5272 case SVGA_3D_CMD_DX_DRAW_INSTANCED:
5273 {
5274 SVGA3dCmdDXDrawInstanced *pCmd = (SVGA3dCmdDXDrawInstanced *)pvCmd;
5275 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5276 rcParse = vmsvga3dCmdDXDrawInstanced(pThisCC, idDXContext, pCmd, cbCmd);
5277 break;
5278 }
5279
5280 case SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED:
5281 {
5282 SVGA3dCmdDXDrawIndexedInstanced *pCmd = (SVGA3dCmdDXDrawIndexedInstanced *)pvCmd;
5283 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5284 rcParse = vmsvga3dCmdDXDrawIndexedInstanced(pThisCC, idDXContext, pCmd, cbCmd);
5285 break;
5286 }
5287
5288 case SVGA_3D_CMD_DX_DRAW_AUTO:
5289 {
5290 SVGA3dCmdDXDrawAuto *pCmd = (SVGA3dCmdDXDrawAuto *)pvCmd;
5291 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5292 rcParse = vmsvga3dCmdDXDrawAuto(pThisCC, idDXContext, pCmd, cbCmd);
5293 break;
5294 }
5295
5296 case SVGA_3D_CMD_DX_SET_INPUT_LAYOUT:
5297 {
5298 SVGA3dCmdDXSetInputLayout *pCmd = (SVGA3dCmdDXSetInputLayout *)pvCmd;
5299 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5300 rcParse = vmsvga3dCmdDXSetInputLayout(pThisCC, idDXContext, pCmd, cbCmd);
5301 break;
5302 }
5303
5304 case SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS:
5305 {
5306 SVGA3dCmdDXSetVertexBuffers *pCmd = (SVGA3dCmdDXSetVertexBuffers *)pvCmd;
5307 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5308 rcParse = vmsvga3dCmdDXSetVertexBuffers(pThisCC, idDXContext, pCmd, cbCmd);
5309 break;
5310 }
5311
5312 case SVGA_3D_CMD_DX_SET_INDEX_BUFFER:
5313 {
5314 SVGA3dCmdDXSetIndexBuffer *pCmd = (SVGA3dCmdDXSetIndexBuffer *)pvCmd;
5315 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5316 rcParse = vmsvga3dCmdDXSetIndexBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5317 break;
5318 }
5319
5320 case SVGA_3D_CMD_DX_SET_TOPOLOGY:
5321 {
5322 SVGA3dCmdDXSetTopology *pCmd = (SVGA3dCmdDXSetTopology *)pvCmd;
5323 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5324 rcParse = vmsvga3dCmdDXSetTopology(pThisCC, idDXContext, pCmd, cbCmd);
5325 break;
5326 }
5327
5328 case SVGA_3D_CMD_DX_SET_RENDERTARGETS:
5329 {
5330 SVGA3dCmdDXSetRenderTargets *pCmd = (SVGA3dCmdDXSetRenderTargets *)pvCmd;
5331 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5332 rcParse = vmsvga3dCmdDXSetRenderTargets(pThisCC, idDXContext, pCmd, cbCmd);
5333 break;
5334 }
5335
5336 case SVGA_3D_CMD_DX_SET_BLEND_STATE:
5337 {
5338 SVGA3dCmdDXSetBlendState *pCmd = (SVGA3dCmdDXSetBlendState *)pvCmd;
5339 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5340 rcParse = vmsvga3dCmdDXSetBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5341 break;
5342 }
5343
5344 case SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE:
5345 {
5346 SVGA3dCmdDXSetDepthStencilState *pCmd = (SVGA3dCmdDXSetDepthStencilState *)pvCmd;
5347 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5348 rcParse = vmsvga3dCmdDXSetDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5349 break;
5350 }
5351
5352 case SVGA_3D_CMD_DX_SET_RASTERIZER_STATE:
5353 {
5354 SVGA3dCmdDXSetRasterizerState *pCmd = (SVGA3dCmdDXSetRasterizerState *)pvCmd;
5355 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5356 rcParse = vmsvga3dCmdDXSetRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5357 break;
5358 }
5359
5360 case SVGA_3D_CMD_DX_DEFINE_QUERY:
5361 {
5362 SVGA3dCmdDXDefineQuery *pCmd = (SVGA3dCmdDXDefineQuery *)pvCmd;
5363 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5364 rcParse = vmsvga3dCmdDXDefineQuery(pThisCC, idDXContext, pCmd, cbCmd);
5365 break;
5366 }
5367
5368 case SVGA_3D_CMD_DX_DESTROY_QUERY:
5369 {
5370 SVGA3dCmdDXDestroyQuery *pCmd = (SVGA3dCmdDXDestroyQuery *)pvCmd;
5371 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5372 rcParse = vmsvga3dCmdDXDestroyQuery(pThisCC, idDXContext, pCmd, cbCmd);
5373 break;
5374 }
5375
5376 case SVGA_3D_CMD_DX_BIND_QUERY:
5377 {
5378 SVGA3dCmdDXBindQuery *pCmd = (SVGA3dCmdDXBindQuery *)pvCmd;
5379 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5380 rcParse = vmsvga3dCmdDXBindQuery(pThisCC, idDXContext, pCmd, cbCmd);
5381 break;
5382 }
5383
5384 case SVGA_3D_CMD_DX_SET_QUERY_OFFSET:
5385 {
5386 SVGA3dCmdDXSetQueryOffset *pCmd = (SVGA3dCmdDXSetQueryOffset *)pvCmd;
5387 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5388 rcParse = vmsvga3dCmdDXSetQueryOffset(pThisCC, idDXContext, pCmd, cbCmd);
5389 break;
5390 }
5391
5392 case SVGA_3D_CMD_DX_BEGIN_QUERY:
5393 {
5394 SVGA3dCmdDXBeginQuery *pCmd = (SVGA3dCmdDXBeginQuery *)pvCmd;
5395 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5396 rcParse = vmsvga3dCmdDXBeginQuery(pThisCC, idDXContext, pCmd, cbCmd);
5397 break;
5398 }
5399
5400 case SVGA_3D_CMD_DX_END_QUERY:
5401 {
5402 SVGA3dCmdDXEndQuery *pCmd = (SVGA3dCmdDXEndQuery *)pvCmd;
5403 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5404 rcParse = vmsvga3dCmdDXEndQuery(pThisCC, idDXContext, pCmd, cbCmd);
5405 break;
5406 }
5407
5408 case SVGA_3D_CMD_DX_READBACK_QUERY:
5409 {
5410 SVGA3dCmdDXReadbackQuery *pCmd = (SVGA3dCmdDXReadbackQuery *)pvCmd;
5411 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5412 rcParse = vmsvga3dCmdDXReadbackQuery(pThisCC, idDXContext, pCmd, cbCmd);
5413 break;
5414 }
5415
5416 case SVGA_3D_CMD_DX_SET_PREDICATION:
5417 {
5418 SVGA3dCmdDXSetPredication *pCmd = (SVGA3dCmdDXSetPredication *)pvCmd;
5419 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5420 rcParse = vmsvga3dCmdDXSetPredication(pThisCC, idDXContext, pCmd, cbCmd);
5421 break;
5422 }
5423
5424 case SVGA_3D_CMD_DX_SET_SOTARGETS:
5425 {
5426 SVGA3dCmdDXSetSOTargets *pCmd = (SVGA3dCmdDXSetSOTargets *)pvCmd;
5427 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5428 rcParse = vmsvga3dCmdDXSetSOTargets(pThisCC, idDXContext, pCmd, cbCmd);
5429 break;
5430 }
5431
5432 case SVGA_3D_CMD_DX_SET_VIEWPORTS:
5433 {
5434 SVGA3dCmdDXSetViewports *pCmd = (SVGA3dCmdDXSetViewports *)pvCmd;
5435 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5436 rcParse = vmsvga3dCmdDXSetViewports(pThisCC, idDXContext, pCmd, cbCmd);
5437 break;
5438 }
5439
5440 case SVGA_3D_CMD_DX_SET_SCISSORRECTS:
5441 {
5442 SVGA3dCmdDXSetScissorRects *pCmd = (SVGA3dCmdDXSetScissorRects *)pvCmd;
5443 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5444 rcParse = vmsvga3dCmdDXSetScissorRects(pThisCC, idDXContext, pCmd, cbCmd);
5445 break;
5446 }
5447
5448 case SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW:
5449 {
5450 SVGA3dCmdDXClearRenderTargetView *pCmd = (SVGA3dCmdDXClearRenderTargetView *)pvCmd;
5451 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5452 rcParse = vmsvga3dCmdDXClearRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5453 break;
5454 }
5455
5456 case SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW:
5457 {
5458 SVGA3dCmdDXClearDepthStencilView *pCmd = (SVGA3dCmdDXClearDepthStencilView *)pvCmd;
5459 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5460 rcParse = vmsvga3dCmdDXClearDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5461 break;
5462 }
5463
5464 case SVGA_3D_CMD_DX_PRED_COPY_REGION:
5465 {
5466 SVGA3dCmdDXPredCopyRegion *pCmd = (SVGA3dCmdDXPredCopyRegion *)pvCmd;
5467 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5468 rcParse = vmsvga3dCmdDXPredCopyRegion(pThisCC, idDXContext, pCmd, cbCmd);
5469 break;
5470 }
5471
5472 case SVGA_3D_CMD_DX_PRED_COPY:
5473 {
5474 SVGA3dCmdDXPredCopy *pCmd = (SVGA3dCmdDXPredCopy *)pvCmd;
5475 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5476 rcParse = vmsvga3dCmdDXPredCopy(pThisCC, idDXContext, pCmd, cbCmd);
5477 break;
5478 }
5479
5480 case SVGA_3D_CMD_DX_PRESENTBLT:
5481 {
5482 SVGA3dCmdDXPresentBlt *pCmd = (SVGA3dCmdDXPresentBlt *)pvCmd;
5483 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5484 rcParse = vmsvga3dCmdDXPresentBlt(pThisCC, idDXContext, pCmd, cbCmd);
5485 break;
5486 }
5487
5488 case SVGA_3D_CMD_DX_GENMIPS:
5489 {
5490 SVGA3dCmdDXGenMips *pCmd = (SVGA3dCmdDXGenMips *)pvCmd;
5491 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5492 rcParse = vmsvga3dCmdDXGenMips(pThisCC, idDXContext, pCmd, cbCmd);
5493 break;
5494 }
5495
5496 case SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE:
5497 {
5498 SVGA3dCmdDXUpdateSubResource *pCmd = (SVGA3dCmdDXUpdateSubResource *)pvCmd;
5499 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5500 rcParse = vmsvga3dCmdDXUpdateSubResource(pThisCC, pCmd, cbCmd);
5501 break;
5502 }
5503
5504 case SVGA_3D_CMD_DX_READBACK_SUBRESOURCE:
5505 {
5506 SVGA3dCmdDXReadbackSubResource *pCmd = (SVGA3dCmdDXReadbackSubResource *)pvCmd;
5507 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5508 rcParse = vmsvga3dCmdDXReadbackSubResource(pThisCC, pCmd, cbCmd);
5509 break;
5510 }
5511
5512 case SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE:
5513 {
5514 SVGA3dCmdDXInvalidateSubResource *pCmd = (SVGA3dCmdDXInvalidateSubResource *)pvCmd;
5515 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5516 rcParse = vmsvga3dCmdDXInvalidateSubResource(pThisCC, pCmd, cbCmd);
5517 break;
5518 }
5519
5520 case SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW:
5521 {
5522 SVGA3dCmdDXDefineShaderResourceView *pCmd = (SVGA3dCmdDXDefineShaderResourceView *)pvCmd;
5523 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5524 rcParse = vmsvga3dCmdDXDefineShaderResourceView(pThisCC, idDXContext, pCmd, cbCmd);
5525 break;
5526 }
5527
5528 case SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW:
5529 {
5530 SVGA3dCmdDXDestroyShaderResourceView *pCmd = (SVGA3dCmdDXDestroyShaderResourceView *)pvCmd;
5531 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5532 rcParse = vmsvga3dCmdDXDestroyShaderResourceView(pThisCC, idDXContext, pCmd, cbCmd);
5533 break;
5534 }
5535
5536 case SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW:
5537 {
5538 SVGA3dCmdDXDefineRenderTargetView *pCmd = (SVGA3dCmdDXDefineRenderTargetView *)pvCmd;
5539 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5540 rcParse = vmsvga3dCmdDXDefineRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5541 break;
5542 }
5543
5544 case SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW:
5545 {
5546 SVGA3dCmdDXDestroyRenderTargetView *pCmd = (SVGA3dCmdDXDestroyRenderTargetView *)pvCmd;
5547 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5548 rcParse = vmsvga3dCmdDXDestroyRenderTargetView(pThisCC, idDXContext, pCmd, cbCmd);
5549 break;
5550 }
5551
5552 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW:
5553 {
5554 SVGA3dCmdDXDefineDepthStencilView *pCmd = (SVGA3dCmdDXDefineDepthStencilView *)pvCmd;
5555 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5556 rcParse = vmsvga3dCmdDXDefineDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5557 break;
5558 }
5559
5560 case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW:
5561 {
5562 SVGA3dCmdDXDestroyDepthStencilView *pCmd = (SVGA3dCmdDXDestroyDepthStencilView *)pvCmd;
5563 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5564 rcParse = vmsvga3dCmdDXDestroyDepthStencilView(pThisCC, idDXContext, pCmd, cbCmd);
5565 break;
5566 }
5567
5568 case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
5569 {
5570 SVGA3dCmdDXDefineElementLayout *pCmd = (SVGA3dCmdDXDefineElementLayout *)pvCmd;
5571 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5572 rcParse = vmsvga3dCmdDXDefineElementLayout(pThisCC, idDXContext, pCmd, cbCmd);
5573 break;
5574 }
5575
5576 case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
5577 {
5578 SVGA3dCmdDXDestroyElementLayout *pCmd = (SVGA3dCmdDXDestroyElementLayout *)pvCmd;
5579 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5580 rcParse = vmsvga3dCmdDXDestroyElementLayout(pThisCC, idDXContext, pCmd, cbCmd);
5581 break;
5582 }
5583
5584 case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
5585 {
5586 SVGA3dCmdDXDefineBlendState *pCmd = (SVGA3dCmdDXDefineBlendState *)pvCmd;
5587 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5588 rcParse = vmsvga3dCmdDXDefineBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5589 break;
5590 }
5591
5592 case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
5593 {
5594 SVGA3dCmdDXDestroyBlendState *pCmd = (SVGA3dCmdDXDestroyBlendState *)pvCmd;
5595 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5596 rcParse = vmsvga3dCmdDXDestroyBlendState(pThisCC, idDXContext, pCmd, cbCmd);
5597 break;
5598 }
5599
5600 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
5601 {
5602 SVGA3dCmdDXDefineDepthStencilState *pCmd = (SVGA3dCmdDXDefineDepthStencilState *)pvCmd;
5603 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5604 rcParse = vmsvga3dCmdDXDefineDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5605 break;
5606 }
5607
5608 case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
5609 {
5610 SVGA3dCmdDXDestroyDepthStencilState *pCmd = (SVGA3dCmdDXDestroyDepthStencilState *)pvCmd;
5611 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5612 rcParse = vmsvga3dCmdDXDestroyDepthStencilState(pThisCC, idDXContext, pCmd, cbCmd);
5613 break;
5614 }
5615
5616 case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
5617 {
5618 SVGA3dCmdDXDefineRasterizerState *pCmd = (SVGA3dCmdDXDefineRasterizerState *)pvCmd;
5619 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5620 rcParse = vmsvga3dCmdDXDefineRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5621 break;
5622 }
5623
5624 case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
5625 {
5626 SVGA3dCmdDXDestroyRasterizerState *pCmd = (SVGA3dCmdDXDestroyRasterizerState *)pvCmd;
5627 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5628 rcParse = vmsvga3dCmdDXDestroyRasterizerState(pThisCC, idDXContext, pCmd, cbCmd);
5629 break;
5630 }
5631
5632 case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
5633 {
5634 SVGA3dCmdDXDefineSamplerState *pCmd = (SVGA3dCmdDXDefineSamplerState *)pvCmd;
5635 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5636 rcParse = vmsvga3dCmdDXDefineSamplerState(pThisCC, idDXContext, pCmd, cbCmd);
5637 break;
5638 }
5639
5640 case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
5641 {
5642 SVGA3dCmdDXDestroySamplerState *pCmd = (SVGA3dCmdDXDestroySamplerState *)pvCmd;
5643 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5644 rcParse = vmsvga3dCmdDXDestroySamplerState(pThisCC, idDXContext, pCmd, cbCmd);
5645 break;
5646 }
5647
5648 case SVGA_3D_CMD_DX_DEFINE_SHADER:
5649 {
5650 SVGA3dCmdDXDefineShader *pCmd = (SVGA3dCmdDXDefineShader *)pvCmd;
5651 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5652 rcParse = vmsvga3dCmdDXDefineShader(pThisCC, idDXContext, pCmd, cbCmd);
5653 break;
5654 }
5655
5656 case SVGA_3D_CMD_DX_DESTROY_SHADER:
5657 {
5658 SVGA3dCmdDXDestroyShader *pCmd = (SVGA3dCmdDXDestroyShader *)pvCmd;
5659 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5660 rcParse = vmsvga3dCmdDXDestroyShader(pThisCC, idDXContext, pCmd, cbCmd);
5661 break;
5662 }
5663
5664 case SVGA_3D_CMD_DX_BIND_SHADER:
5665 {
5666 SVGA3dCmdDXBindShader *pCmd = (SVGA3dCmdDXBindShader *)pvCmd;
5667 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5668 rcParse = vmsvga3dCmdDXBindShader(pThisCC, idDXContext, pCmd, cbCmd);
5669 break;
5670 }
5671
5672 case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
5673 {
5674 SVGA3dCmdDXDefineStreamOutput *pCmd = (SVGA3dCmdDXDefineStreamOutput *)pvCmd;
5675 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5676 rcParse = vmsvga3dCmdDXDefineStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5677 break;
5678 }
5679
5680 case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
5681 {
5682 SVGA3dCmdDXDestroyStreamOutput *pCmd = (SVGA3dCmdDXDestroyStreamOutput *)pvCmd;
5683 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5684 rcParse = vmsvga3dCmdDXDestroyStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5685 break;
5686 }
5687
5688 case SVGA_3D_CMD_DX_SET_STREAMOUTPUT:
5689 {
5690 SVGA3dCmdDXSetStreamOutput *pCmd = (SVGA3dCmdDXSetStreamOutput *)pvCmd;
5691 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5692 rcParse = vmsvga3dCmdDXSetStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
5693 break;
5694 }
5695
5696 case SVGA_3D_CMD_DX_SET_COTABLE:
5697 {
5698 SVGA3dCmdDXSetCOTable *pCmd = (SVGA3dCmdDXSetCOTable *)pvCmd;
5699 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5700 rcParse = vmsvga3dCmdDXSetCOTable(pThisCC, pCmd, cbCmd);
5701 break;
5702 }
5703
5704 case SVGA_3D_CMD_DX_READBACK_COTABLE:
5705 {
5706 SVGA3dCmdDXReadbackCOTable *pCmd = (SVGA3dCmdDXReadbackCOTable *)pvCmd;
5707 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5708 rcParse = vmsvga3dCmdDXReadbackCOTable(pThisCC, idDXContext, pCmd, cbCmd);
5709 break;
5710 }
5711
5712 case SVGA_3D_CMD_DX_BUFFER_COPY:
5713 {
5714 SVGA3dCmdDXBufferCopy *pCmd = (SVGA3dCmdDXBufferCopy *)pvCmd;
5715 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5716 rcParse = vmsvga3dCmdDXBufferCopy(pThisCC, idDXContext, pCmd, cbCmd);
5717 break;
5718 }
5719
5720 case SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER:
5721 {
5722 SVGA3dCmdDXTransferFromBuffer *pCmd = (SVGA3dCmdDXTransferFromBuffer *)pvCmd;
5723 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5724 rcParse = vmsvga3dCmdDXTransferFromBuffer(pThisCC, pCmd, cbCmd);
5725 break;
5726 }
5727
5728 case SVGA_3D_CMD_DX_SURFACE_COPY_AND_READBACK:
5729 {
5730 SVGA3dCmdDXSurfaceCopyAndReadback *pCmd = (SVGA3dCmdDXSurfaceCopyAndReadback *)pvCmd;
5731 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5732 rcParse = vmsvga3dCmdDXSurfaceCopyAndReadback(pThisCC, idDXContext, pCmd, cbCmd);
5733 break;
5734 }
5735
5736 case SVGA_3D_CMD_DX_MOVE_QUERY:
5737 {
5738 SVGA3dCmdDXMoveQuery *pCmd = (SVGA3dCmdDXMoveQuery *)pvCmd;
5739 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5740 rcParse = vmsvga3dCmdDXMoveQuery(pThisCC, idDXContext, pCmd, cbCmd);
5741 break;
5742 }
5743
5744 case SVGA_3D_CMD_DX_BIND_ALL_QUERY:
5745 {
5746 SVGA3dCmdDXBindAllQuery *pCmd = (SVGA3dCmdDXBindAllQuery *)pvCmd;
5747 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5748 rcParse = vmsvga3dCmdDXBindAllQuery(pThisCC, idDXContext, pCmd, cbCmd);
5749 break;
5750 }
5751
5752 case SVGA_3D_CMD_DX_READBACK_ALL_QUERY:
5753 {
5754 SVGA3dCmdDXReadbackAllQuery *pCmd = (SVGA3dCmdDXReadbackAllQuery *)pvCmd;
5755 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5756 rcParse = vmsvga3dCmdDXReadbackAllQuery(pThisCC, idDXContext, pCmd, cbCmd);
5757 break;
5758 }
5759
5760 case SVGA_3D_CMD_DX_PRED_TRANSFER_FROM_BUFFER:
5761 {
5762 SVGA3dCmdDXPredTransferFromBuffer *pCmd = (SVGA3dCmdDXPredTransferFromBuffer *)pvCmd;
5763 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5764 rcParse = vmsvga3dCmdDXPredTransferFromBuffer(pThisCC, idDXContext, pCmd, cbCmd);
5765 break;
5766 }
5767
5768 case SVGA_3D_CMD_DX_MOB_FENCE_64:
5769 {
5770 SVGA3dCmdDXMobFence64 *pCmd = (SVGA3dCmdDXMobFence64 *)pvCmd;
5771 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5772 rcParse = vmsvga3dCmdDXMobFence64(pThisCC, pCmd, cbCmd);
5773 break;
5774 }
5775
5776 case SVGA_3D_CMD_DX_BIND_ALL_SHADER:
5777 {
5778 SVGA3dCmdDXBindAllShader *pCmd = (SVGA3dCmdDXBindAllShader *)pvCmd;
5779 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5780 rcParse = vmsvga3dCmdDXBindAllShader(pThisCC, idDXContext, pCmd, cbCmd);
5781 break;
5782 }
5783
5784 case SVGA_3D_CMD_DX_HINT:
5785 {
5786 SVGA3dCmdDXHint *pCmd = (SVGA3dCmdDXHint *)pvCmd;
5787 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5788 rcParse = vmsvga3dCmdDXHint(pThisCC, idDXContext, pCmd, cbCmd);
5789 break;
5790 }
5791
5792 case SVGA_3D_CMD_DX_BUFFER_UPDATE:
5793 {
5794 SVGA3dCmdDXBufferUpdate *pCmd = (SVGA3dCmdDXBufferUpdate *)pvCmd;
5795 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5796 rcParse = vmsvga3dCmdDXBufferUpdate(pThisCC, idDXContext, pCmd, cbCmd);
5797 break;
5798 }
5799
5800 case SVGA_3D_CMD_DX_SET_VS_CONSTANT_BUFFER_OFFSET:
5801 {
5802 SVGA3dCmdDXSetVSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetVSConstantBufferOffset *)pvCmd;
5803 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5804 rcParse = vmsvga3dCmdDXSetVSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5805 break;
5806 }
5807
5808 case SVGA_3D_CMD_DX_SET_PS_CONSTANT_BUFFER_OFFSET:
5809 {
5810 SVGA3dCmdDXSetPSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetPSConstantBufferOffset *)pvCmd;
5811 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5812 rcParse = vmsvga3dCmdDXSetPSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5813 break;
5814 }
5815
5816 case SVGA_3D_CMD_DX_SET_GS_CONSTANT_BUFFER_OFFSET:
5817 {
5818 SVGA3dCmdDXSetGSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetGSConstantBufferOffset *)pvCmd;
5819 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5820 rcParse = vmsvga3dCmdDXSetGSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5821 break;
5822 }
5823
5824 case SVGA_3D_CMD_DX_SET_HS_CONSTANT_BUFFER_OFFSET:
5825 {
5826 SVGA3dCmdDXSetHSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetHSConstantBufferOffset *)pvCmd;
5827 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5828 rcParse = vmsvga3dCmdDXSetHSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5829 break;
5830 }
5831
5832 case SVGA_3D_CMD_DX_SET_DS_CONSTANT_BUFFER_OFFSET:
5833 {
5834 SVGA3dCmdDXSetDSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetDSConstantBufferOffset *)pvCmd;
5835 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5836 rcParse = vmsvga3dCmdDXSetDSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5837 break;
5838 }
5839
5840 case SVGA_3D_CMD_DX_SET_CS_CONSTANT_BUFFER_OFFSET:
5841 {
5842 SVGA3dCmdDXSetCSConstantBufferOffset *pCmd = (SVGA3dCmdDXSetCSConstantBufferOffset *)pvCmd;
5843 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5844 rcParse = vmsvga3dCmdDXSetCSConstantBufferOffset(pThisCC, idDXContext, pCmd, cbCmd);
5845 break;
5846 }
5847
5848 case SVGA_3D_CMD_DX_COND_BIND_ALL_SHADER:
5849 {
5850 SVGA3dCmdDXCondBindAllShader *pCmd = (SVGA3dCmdDXCondBindAllShader *)pvCmd;
5851 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5852 rcParse = vmsvga3dCmdDXCondBindAllShader(pThisCC, idDXContext, pCmd, cbCmd);
5853 break;
5854 }
5855
5856 case SVGA_3D_CMD_SCREEN_COPY:
5857 {
5858 SVGA3dCmdScreenCopy *pCmd = (SVGA3dCmdScreenCopy *)pvCmd;
5859 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5860 rcParse = vmsvga3dCmdScreenCopy(pThisCC, idDXContext, pCmd, cbCmd);
5861 break;
5862 }
5863
5864 case SVGA_3D_CMD_RESERVED1:
5865 {
5866 VMSVGA_3D_CMD_NOTIMPL();
5867 break;
5868 }
5869
5870 case SVGA_3D_CMD_RESERVED2:
5871 {
5872 VMSVGA_3D_CMD_NOTIMPL();
5873 break;
5874 }
5875
5876 case SVGA_3D_CMD_RESERVED3:
5877 {
5878 VMSVGA_3D_CMD_NOTIMPL();
5879 break;
5880 }
5881
5882 case SVGA_3D_CMD_RESERVED4:
5883 {
5884 VMSVGA_3D_CMD_NOTIMPL();
5885 break;
5886 }
5887
5888 case SVGA_3D_CMD_RESERVED5:
5889 {
5890 VMSVGA_3D_CMD_NOTIMPL();
5891 break;
5892 }
5893
5894 case SVGA_3D_CMD_RESERVED6:
5895 {
5896 VMSVGA_3D_CMD_NOTIMPL();
5897 break;
5898 }
5899
5900 case SVGA_3D_CMD_RESERVED7:
5901 {
5902 VMSVGA_3D_CMD_NOTIMPL();
5903 break;
5904 }
5905
5906 case SVGA_3D_CMD_RESERVED8:
5907 {
5908 VMSVGA_3D_CMD_NOTIMPL();
5909 break;
5910 }
5911
5912 case SVGA_3D_CMD_GROW_OTABLE:
5913 {
5914 SVGA3dCmdGrowOTable *pCmd = (SVGA3dCmdGrowOTable *)pvCmd;
5915 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5916 rcParse = vmsvga3dCmdGrowOTable(pThisCC, pCmd, cbCmd);
5917 break;
5918 }
5919
5920 case SVGA_3D_CMD_DX_GROW_COTABLE:
5921 {
5922 SVGA3dCmdDXGrowCOTable *pCmd = (SVGA3dCmdDXGrowCOTable *)pvCmd;
5923 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5924 rcParse = vmsvga3dCmdDXGrowCOTable(pThisCC, pCmd, cbCmd);
5925 break;
5926 }
5927
5928 case SVGA_3D_CMD_INTRA_SURFACE_COPY:
5929 {
5930 SVGA3dCmdIntraSurfaceCopy *pCmd = (SVGA3dCmdIntraSurfaceCopy *)pvCmd;
5931 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5932 rcParse = vmsvga3dCmdIntraSurfaceCopy(pThisCC, idDXContext, pCmd, cbCmd);
5933 break;
5934 }
5935
5936 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V3:
5937 {
5938 SVGA3dCmdDefineGBSurface_v3 *pCmd = (SVGA3dCmdDefineGBSurface_v3 *)pvCmd;
5939 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5940 rcParse = vmsvga3dCmdDefineGBSurface_v3(pThisCC, pCmd);
5941 break;
5942 }
5943
5944 case SVGA_3D_CMD_DX_RESOLVE_COPY:
5945 {
5946 SVGA3dCmdDXResolveCopy *pCmd = (SVGA3dCmdDXResolveCopy *)pvCmd;
5947 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5948 rcParse = vmsvga3dCmdDXResolveCopy(pThisCC, idDXContext, pCmd, cbCmd);
5949 break;
5950 }
5951
5952 case SVGA_3D_CMD_DX_PRED_RESOLVE_COPY:
5953 {
5954 SVGA3dCmdDXPredResolveCopy *pCmd = (SVGA3dCmdDXPredResolveCopy *)pvCmd;
5955 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5956 rcParse = vmsvga3dCmdDXPredResolveCopy(pThisCC, idDXContext, pCmd, cbCmd);
5957 break;
5958 }
5959
5960 case SVGA_3D_CMD_DX_PRED_CONVERT_REGION:
5961 {
5962 SVGA3dCmdDXPredConvertRegion *pCmd = (SVGA3dCmdDXPredConvertRegion *)pvCmd;
5963 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5964 rcParse = vmsvga3dCmdDXPredConvertRegion(pThisCC, idDXContext, pCmd, cbCmd);
5965 break;
5966 }
5967
5968 case SVGA_3D_CMD_DX_PRED_CONVERT:
5969 {
5970 SVGA3dCmdDXPredConvert *pCmd = (SVGA3dCmdDXPredConvert *)pvCmd;
5971 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5972 rcParse = vmsvga3dCmdDXPredConvert(pThisCC, idDXContext, pCmd, cbCmd);
5973 break;
5974 }
5975
5976 case SVGA_3D_CMD_WHOLE_SURFACE_COPY:
5977 {
5978 SVGA3dCmdWholeSurfaceCopy *pCmd = (SVGA3dCmdWholeSurfaceCopy *)pvCmd;
5979 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5980 rcParse = vmsvga3dCmdWholeSurfaceCopy(pThisCC, idDXContext, pCmd, cbCmd);
5981 break;
5982 }
5983
5984 case SVGA_3D_CMD_DX_DEFINE_UA_VIEW:
5985 {
5986 SVGA3dCmdDXDefineUAView *pCmd = (SVGA3dCmdDXDefineUAView *)pvCmd;
5987 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5988 rcParse = vmsvga3dCmdDXDefineUAView(pThisCC, idDXContext, pCmd, cbCmd);
5989 break;
5990 }
5991
5992 case SVGA_3D_CMD_DX_DESTROY_UA_VIEW:
5993 {
5994 SVGA3dCmdDXDestroyUAView *pCmd = (SVGA3dCmdDXDestroyUAView *)pvCmd;
5995 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
5996 rcParse = vmsvga3dCmdDXDestroyUAView(pThisCC, idDXContext, pCmd, cbCmd);
5997 break;
5998 }
5999
6000 case SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT:
6001 {
6002 SVGA3dCmdDXClearUAViewUint *pCmd = (SVGA3dCmdDXClearUAViewUint *)pvCmd;
6003 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6004 rcParse = vmsvga3dCmdDXClearUAViewUint(pThisCC, idDXContext, pCmd, cbCmd);
6005 break;
6006 }
6007
6008 case SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT:
6009 {
6010 SVGA3dCmdDXClearUAViewFloat *pCmd = (SVGA3dCmdDXClearUAViewFloat *)pvCmd;
6011 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6012 rcParse = vmsvga3dCmdDXClearUAViewFloat(pThisCC, idDXContext, pCmd, cbCmd);
6013 break;
6014 }
6015
6016 case SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT:
6017 {
6018 SVGA3dCmdDXCopyStructureCount *pCmd = (SVGA3dCmdDXCopyStructureCount *)pvCmd;
6019 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6020 rcParse = vmsvga3dCmdDXCopyStructureCount(pThisCC, idDXContext, pCmd, cbCmd);
6021 break;
6022 }
6023
6024 case SVGA_3D_CMD_DX_SET_UA_VIEWS:
6025 {
6026 SVGA3dCmdDXSetUAViews *pCmd = (SVGA3dCmdDXSetUAViews *)pvCmd;
6027 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6028 rcParse = vmsvga3dCmdDXSetUAViews(pThisCC, idDXContext, pCmd, cbCmd);
6029 break;
6030 }
6031
6032 case SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT:
6033 {
6034 SVGA3dCmdDXDrawIndexedInstancedIndirect *pCmd = (SVGA3dCmdDXDrawIndexedInstancedIndirect *)pvCmd;
6035 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6036 rcParse = vmsvga3dCmdDXDrawIndexedInstancedIndirect(pThisCC, idDXContext, pCmd, cbCmd);
6037 break;
6038 }
6039
6040 case SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT:
6041 {
6042 SVGA3dCmdDXDrawInstancedIndirect *pCmd = (SVGA3dCmdDXDrawInstancedIndirect *)pvCmd;
6043 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6044 rcParse = vmsvga3dCmdDXDrawInstancedIndirect(pThisCC, idDXContext, pCmd, cbCmd);
6045 break;
6046 }
6047
6048 case SVGA_3D_CMD_DX_DISPATCH:
6049 {
6050 SVGA3dCmdDXDispatch *pCmd = (SVGA3dCmdDXDispatch *)pvCmd;
6051 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6052 rcParse = vmsvga3dCmdDXDispatch(pThisCC, idDXContext, pCmd, cbCmd);
6053 break;
6054 }
6055
6056 case SVGA_3D_CMD_DX_DISPATCH_INDIRECT:
6057 {
6058 SVGA3dCmdDXDispatchIndirect *pCmd = (SVGA3dCmdDXDispatchIndirect *)pvCmd;
6059 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6060 rcParse = vmsvga3dCmdDXDispatchIndirect(pThisCC, idDXContext, pCmd, cbCmd);
6061 break;
6062 }
6063
6064 case SVGA_3D_CMD_WRITE_ZERO_SURFACE:
6065 {
6066 SVGA3dCmdWriteZeroSurface *pCmd = (SVGA3dCmdWriteZeroSurface *)pvCmd;
6067 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6068 rcParse = vmsvga3dCmdWriteZeroSurface(pThisCC, idDXContext, pCmd, cbCmd);
6069 break;
6070 }
6071
6072 case SVGA_3D_CMD_HINT_ZERO_SURFACE:
6073 {
6074 SVGA3dCmdHintZeroSurface *pCmd = (SVGA3dCmdHintZeroSurface *)pvCmd;
6075 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6076 rcParse = vmsvga3dCmdHintZeroSurface(pThisCC, idDXContext, pCmd, cbCmd);
6077 break;
6078 }
6079
6080 case SVGA_3D_CMD_DX_TRANSFER_TO_BUFFER:
6081 {
6082 SVGA3dCmdDXTransferToBuffer *pCmd = (SVGA3dCmdDXTransferToBuffer *)pvCmd;
6083 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6084 rcParse = vmsvga3dCmdDXTransferToBuffer(pThisCC, idDXContext, pCmd, cbCmd);
6085 break;
6086 }
6087
6088 case SVGA_3D_CMD_DX_SET_STRUCTURE_COUNT:
6089 {
6090 SVGA3dCmdDXSetStructureCount *pCmd = (SVGA3dCmdDXSetStructureCount *)pvCmd;
6091 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6092 rcParse = vmsvga3dCmdDXSetStructureCount(pThisCC, idDXContext, pCmd, cbCmd);
6093 break;
6094 }
6095
6096 case SVGA_3D_CMD_LOGICOPS_BITBLT:
6097 {
6098 SVGA3dCmdLogicOpsBitBlt *pCmd = (SVGA3dCmdLogicOpsBitBlt *)pvCmd;
6099 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6100 rcParse = vmsvga3dCmdLogicOpsBitBlt(pThisCC, idDXContext, pCmd, cbCmd);
6101 break;
6102 }
6103
6104 case SVGA_3D_CMD_LOGICOPS_TRANSBLT:
6105 {
6106 SVGA3dCmdLogicOpsTransBlt *pCmd = (SVGA3dCmdLogicOpsTransBlt *)pvCmd;
6107 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6108 rcParse = vmsvga3dCmdLogicOpsTransBlt(pThisCC, idDXContext, pCmd, cbCmd);
6109 break;
6110 }
6111
6112 case SVGA_3D_CMD_LOGICOPS_STRETCHBLT:
6113 {
6114 SVGA3dCmdLogicOpsStretchBlt *pCmd = (SVGA3dCmdLogicOpsStretchBlt *)pvCmd;
6115 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6116 rcParse = vmsvga3dCmdLogicOpsStretchBlt(pThisCC, idDXContext, pCmd, cbCmd);
6117 break;
6118 }
6119
6120 case SVGA_3D_CMD_LOGICOPS_COLORFILL:
6121 {
6122 SVGA3dCmdLogicOpsColorFill *pCmd = (SVGA3dCmdLogicOpsColorFill *)pvCmd;
6123 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6124 rcParse = vmsvga3dCmdLogicOpsColorFill(pThisCC, idDXContext, pCmd, cbCmd);
6125 break;
6126 }
6127
6128 case SVGA_3D_CMD_LOGICOPS_ALPHABLEND:
6129 {
6130 SVGA3dCmdLogicOpsAlphaBlend *pCmd = (SVGA3dCmdLogicOpsAlphaBlend *)pvCmd;
6131 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6132 rcParse = vmsvga3dCmdLogicOpsAlphaBlend(pThisCC, idDXContext, pCmd, cbCmd);
6133 break;
6134 }
6135
6136 case SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND:
6137 {
6138 SVGA3dCmdLogicOpsClearTypeBlend *pCmd = (SVGA3dCmdLogicOpsClearTypeBlend *)pvCmd;
6139 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6140 rcParse = vmsvga3dCmdLogicOpsClearTypeBlend(pThisCC, idDXContext, pCmd, cbCmd);
6141 break;
6142 }
6143
6144 case SVGA_3D_CMD_RESERVED2_1:
6145 {
6146 VMSVGA_3D_CMD_NOTIMPL();
6147 break;
6148 }
6149
6150 case SVGA_3D_CMD_RESERVED2_2:
6151 {
6152 VMSVGA_3D_CMD_NOTIMPL();
6153 break;
6154 }
6155
6156 case SVGA_3D_CMD_DEFINE_GB_SURFACE_V4:
6157 {
6158 SVGA3dCmdDefineGBSurface_v4 *pCmd = (SVGA3dCmdDefineGBSurface_v4 *)pvCmd;
6159 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6160 rcParse = vmsvga3dCmdDefineGBSurface_v4(pThisCC, pCmd);
6161 break;
6162 }
6163
6164 case SVGA_3D_CMD_DX_SET_CS_UA_VIEWS:
6165 {
6166 SVGA3dCmdDXSetCSUAViews *pCmd = (SVGA3dCmdDXSetCSUAViews *)pvCmd;
6167 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6168 rcParse = vmsvga3dCmdDXSetCSUAViews(pThisCC, idDXContext, pCmd, cbCmd);
6169 break;
6170 }
6171
6172 case SVGA_3D_CMD_DX_SET_MIN_LOD:
6173 {
6174 SVGA3dCmdDXSetMinLOD *pCmd = (SVGA3dCmdDXSetMinLOD *)pvCmd;
6175 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6176 rcParse = vmsvga3dCmdDXSetMinLOD(pThisCC, idDXContext, pCmd, cbCmd);
6177 break;
6178 }
6179
6180 case SVGA_3D_CMD_RESERVED2_3:
6181 {
6182 VMSVGA_3D_CMD_NOTIMPL();
6183 break;
6184 }
6185
6186 case SVGA_3D_CMD_RESERVED2_4:
6187 {
6188 VMSVGA_3D_CMD_NOTIMPL();
6189 break;
6190 }
6191
6192 case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2:
6193 {
6194 SVGA3dCmdDXDefineDepthStencilView_v2 *pCmd = (SVGA3dCmdDXDefineDepthStencilView_v2 *)pvCmd;
6195 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6196 rcParse = vmsvga3dCmdDXDefineDepthStencilView_v2(pThisCC, idDXContext, pCmd, cbCmd);
6197 break;
6198 }
6199
6200 case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB:
6201 {
6202 SVGA3dCmdDXDefineStreamOutputWithMob *pCmd = (SVGA3dCmdDXDefineStreamOutputWithMob *)pvCmd;
6203 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6204 rcParse = vmsvga3dCmdDXDefineStreamOutputWithMob(pThisCC, idDXContext, pCmd, cbCmd);
6205 break;
6206 }
6207
6208 case SVGA_3D_CMD_DX_SET_SHADER_IFACE:
6209 {
6210 SVGA3dCmdDXSetShaderIface *pCmd = (SVGA3dCmdDXSetShaderIface *)pvCmd;
6211 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6212 rcParse = vmsvga3dCmdDXSetShaderIface(pThisCC, idDXContext, pCmd, cbCmd);
6213 break;
6214 }
6215
6216 case SVGA_3D_CMD_DX_BIND_STREAMOUTPUT:
6217 {
6218 SVGA3dCmdDXBindStreamOutput *pCmd = (SVGA3dCmdDXBindStreamOutput *)pvCmd;
6219 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6220 rcParse = vmsvga3dCmdDXBindStreamOutput(pThisCC, idDXContext, pCmd, cbCmd);
6221 break;
6222 }
6223
6224 case SVGA_3D_CMD_SURFACE_STRETCHBLT_NON_MS_TO_MS:
6225 {
6226 SVGA3dCmdSurfaceStretchBltNonMSToMS *pCmd = (SVGA3dCmdSurfaceStretchBltNonMSToMS *)pvCmd;
6227 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6228 rcParse = vmsvga3dCmdSurfaceStretchBltNonMSToMS(pThisCC, idDXContext, pCmd, cbCmd);
6229 break;
6230 }
6231
6232 case SVGA_3D_CMD_DX_BIND_SHADER_IFACE:
6233 {
6234 SVGA3dCmdDXBindShaderIface *pCmd = (SVGA3dCmdDXBindShaderIface *)pvCmd;
6235 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6236 rcParse = vmsvga3dCmdDXBindShaderIface(pThisCC, idDXContext, pCmd, cbCmd);
6237 break;
6238 }
6239
6240 case SVGA_3D_CMD_VB_DX_CLEAR_RENDERTARGET_VIEW_REGION:
6241 {
6242 SVGA3dCmdVBDXClearRenderTargetViewRegion *pCmd = (SVGA3dCmdVBDXClearRenderTargetViewRegion *)pvCmd;
6243 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
6244 rcParse = vmsvga3dCmdVBDXClearRenderTargetViewRegion(pThisCC, idDXContext, pCmd, cbCmd);
6245 break;
6246 }
6247
6248 /* Unsupported commands. */
6249 case SVGA_3D_CMD_DEAD4: /* SVGA_3D_CMD_VIDEO_CREATE_DECODER */
6250 case SVGA_3D_CMD_DEAD5: /* SVGA_3D_CMD_VIDEO_DESTROY_DECODER */
6251 case SVGA_3D_CMD_DEAD6: /* SVGA_3D_CMD_VIDEO_CREATE_PROCESSOR */
6252 case SVGA_3D_CMD_DEAD7: /* SVGA_3D_CMD_VIDEO_DESTROY_PROCESSOR */
6253 case SVGA_3D_CMD_DEAD8: /* SVGA_3D_CMD_VIDEO_DECODE_START_FRAME */
6254 case SVGA_3D_CMD_DEAD9: /* SVGA_3D_CMD_VIDEO_DECODE_RENDER */
6255 case SVGA_3D_CMD_DEAD10: /* SVGA_3D_CMD_VIDEO_DECODE_END_FRAME */
6256 case SVGA_3D_CMD_DEAD11: /* SVGA_3D_CMD_VIDEO_PROCESS_FRAME */
6257 /* Prevent the compiler warning. */
6258 case SVGA_3D_CMD_LEGACY_BASE:
6259 case SVGA_3D_CMD_MAX:
6260 case SVGA_3D_CMD_FUTURE_MAX:
6261 /* No 'default' case */
6262 STAM_REL_COUNTER_INC(&pSvgaR3State->StatFifoUnkCmds);
6263 ASSERT_GUEST_MSG_FAILED(("enmCmdId=%d\n", enmCmdId));
6264 LogRelMax(16, ("VMSVGA: unsupported 3D command %d\n", enmCmdId));
6265 rcParse = VERR_NOT_IMPLEMENTED;
6266 break;
6267 }
6268
6269 return VINF_SUCCESS;
6270// return rcParse;
6271}
6272# undef VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK
6273#endif /* VBOX_WITH_VMSVGA3D */
6274
6275
6276/*
6277 *
6278 * Handlers for FIFO commands.
6279 *
6280 * Every handler takes the following parameters:
6281 *
6282 * pThis The shared VGA/VMSVGA state.
6283 * pThisCC The VGA/VMSVGA state for ring-3.
6284 * pCmd The command data.
6285 */
6286
6287
6288/* SVGA_CMD_UPDATE */
6289void vmsvgaR3CmdUpdate(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdate const *pCmd)
6290{
6291 RT_NOREF(pThis);
6292 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6293
6294 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdate);
6295 Log(("SVGA_CMD_UPDATE %d,%d %dx%d\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height));
6296
6297 /** @todo Multiple screens? */
6298 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6299 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
6300 return;
6301
6302 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
6303}
6304
6305
6306/* SVGA_CMD_UPDATE_VERBOSE */
6307void vmsvgaR3CmdUpdateVerbose(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdateVerbose const *pCmd)
6308{
6309 RT_NOREF(pThis);
6310 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6311
6312 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdUpdateVerbose);
6313 Log(("SVGA_CMD_UPDATE_VERBOSE %d,%d %dx%d reason %#x\n", pCmd->x, pCmd->y, pCmd->width, pCmd->height, pCmd->reason));
6314
6315 /** @todo Multiple screens? */
6316 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6317 if (!pScreen) /* Can happen if screen is not defined (aScreens[idScreen].fDefined == false) yet. */
6318 return;
6319
6320 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->x, pCmd->y, pCmd->width, pCmd->height);
6321}
6322
6323
6324/* SVGA_CMD_RECT_FILL */
6325void vmsvgaR3CmdRectFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectFill const *pCmd)
6326{
6327 RT_NOREF(pThis, pCmd);
6328 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6329
6330 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectFill);
6331 Log(("SVGA_CMD_RECT_FILL %08X @ %d,%d (%dx%d)\n", pCmd->pixel, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
6332 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_RECT_FILL command ignored.\n"));
6333}
6334
6335
6336/* SVGA_CMD_RECT_COPY */
6337void vmsvgaR3CmdRectCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectCopy const *pCmd)
6338{
6339 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6340
6341 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectCopy);
6342 Log(("SVGA_CMD_RECT_COPY %d,%d -> %d,%d %dx%d\n", pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height));
6343
6344 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6345 AssertPtrReturnVoid(pScreen);
6346
6347 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
6348 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
6349 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
6350 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
6351 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
6352 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
6353 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
6354
6355 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
6356 pCmd->width, pCmd->height, pThis->vram_size);
6357 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
6358}
6359
6360
6361/* SVGA_CMD_RECT_ROP_COPY */
6362void vmsvgaR3CmdRectRopCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectRopCopy const *pCmd)
6363{
6364 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6365
6366 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRectRopCopy);
6367 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));
6368
6369 if (pCmd->rop != SVGA_ROP_COPY)
6370 {
6371 /* We only support the plain copy ROP which makes SVGA_CMD_RECT_ROP_COPY exactly the same
6372 * as SVGA_CMD_RECT_COPY. XFree86 4.1.0 and 4.2.0 drivers (driver version 10.4.0 and 10.7.0,
6373 * respectively) issue SVGA_CMD_RECT_ROP_COPY when SVGA_CAP_RECT_COPY is present even when
6374 * SVGA_CAP_RASTER_OP is not. However, the ROP will always be SVGA_ROP_COPY.
6375 */
6376 LogRelMax(4, ("VMSVGA: SVGA_CMD_RECT_ROP_COPY %d,%d -> %d,%d (%dx%d) ROP %X unsupported\n",
6377 pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height, pCmd->rop));
6378 return;
6379 }
6380
6381 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
6382 AssertPtrReturnVoid(pScreen);
6383
6384 /* Check that arguments aren't complete junk. A precise check is done in vmsvgaR3RectCopy(). */
6385 ASSERT_GUEST_RETURN_VOID(pCmd->srcX < pThis->svga.u32MaxWidth);
6386 ASSERT_GUEST_RETURN_VOID(pCmd->destX < pThis->svga.u32MaxWidth);
6387 ASSERT_GUEST_RETURN_VOID(pCmd->width < pThis->svga.u32MaxWidth);
6388 ASSERT_GUEST_RETURN_VOID(pCmd->srcY < pThis->svga.u32MaxHeight);
6389 ASSERT_GUEST_RETURN_VOID(pCmd->destY < pThis->svga.u32MaxHeight);
6390 ASSERT_GUEST_RETURN_VOID(pCmd->height < pThis->svga.u32MaxHeight);
6391
6392 vmsvgaR3RectCopy(pThisCC, pScreen, pCmd->srcX, pCmd->srcY, pCmd->destX, pCmd->destY,
6393 pCmd->width, pCmd->height, pThis->vram_size);
6394 vmsvgaR3UpdateScreen(pThisCC, pScreen, pCmd->destX, pCmd->destY, pCmd->width, pCmd->height);
6395}
6396
6397
6398/* SVGA_CMD_DISPLAY_CURSOR */
6399void vmsvgaR3CmdDisplayCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDisplayCursor const *pCmd)
6400{
6401 RT_NOREF(pThis, pCmd);
6402 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6403
6404 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDisplayCursor);
6405 Log(("SVGA_CMD_DISPLAY_CURSOR id=%d state=%d\n", pCmd->id, pCmd->state));
6406 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_DISPLAY_CURSOR command ignored.\n"));
6407}
6408
6409
6410/* SVGA_CMD_MOVE_CURSOR */
6411void vmsvgaR3CmdMoveCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdMoveCursor const *pCmd)
6412{
6413 RT_NOREF(pThis, pCmd);
6414 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6415
6416 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdMoveCursor);
6417 Log(("SVGA_CMD_MOVE_CURSOR to %d,%d\n", pCmd->pos.x, pCmd->pos.y));
6418 LogRelMax(4, ("VMSVGA: Unsupported SVGA_CMD_MOVE_CURSOR command ignored.\n"));
6419}
6420
6421
6422/* SVGA_CMD_DEFINE_CURSOR */
6423void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineCursor const *pCmd)
6424{
6425 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6426
6427 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineCursor);
6428 Log(("SVGA_CMD_DEFINE_CURSOR id=%d size (%dx%d) hotspot (%d,%d) andMaskDepth=%d xorMaskDepth=%d\n",
6429 pCmd->id, pCmd->width, pCmd->height, pCmd->hotspotX, pCmd->hotspotY, pCmd->andMaskDepth, pCmd->xorMaskDepth));
6430
6431 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
6432 ASSERT_GUEST_RETURN_VOID(pCmd->andMaskDepth <= 32);
6433 ASSERT_GUEST_RETURN_VOID(pCmd->xorMaskDepth <= 32);
6434 RT_UNTRUSTED_VALIDATED_FENCE();
6435
6436 uint32_t const cbSrcAndLine = RT_ALIGN_32(pCmd->width * (pCmd->andMaskDepth + (pCmd->andMaskDepth == 15)), 32) / 8;
6437 uint32_t const cbSrcAndMask = cbSrcAndLine * pCmd->height;
6438 uint32_t const cbSrcXorLine = RT_ALIGN_32(pCmd->width * (pCmd->xorMaskDepth + (pCmd->xorMaskDepth == 15)), 32) / 8;
6439
6440 uint8_t const *pbSrcAndMask = (uint8_t const *)(pCmd + 1);
6441 uint8_t const *pbSrcXorMask = (uint8_t const *)(pCmd + 1) + cbSrcAndMask;
6442
6443 uint32_t const cx = pCmd->width;
6444 uint32_t const cy = pCmd->height;
6445
6446 /*
6447 * Convert the input to 1-bit AND mask and a 32-bit BRGA XOR mask.
6448 * The AND data uses 8-bit aligned scanlines.
6449 * The XOR data must be starting on a 32-bit boundrary.
6450 */
6451 uint32_t cbDstAndLine = RT_ALIGN_32(cx, 8) / 8;
6452 uint32_t cbDstAndMask = cbDstAndLine * cy;
6453 uint32_t cbDstXorMask = cx * sizeof(uint32_t) * cy;
6454 uint32_t cbCopy = RT_ALIGN_32(cbDstAndMask, 4) + cbDstXorMask;
6455
6456 uint8_t *pbCopy = (uint8_t *)RTMemAlloc(cbCopy);
6457 AssertReturnVoid(pbCopy);
6458
6459 /* Convert the AND mask. */
6460 uint8_t *pbDst = pbCopy;
6461 uint8_t const *pbSrc = pbSrcAndMask;
6462 switch (pCmd->andMaskDepth)
6463 {
6464 case 1:
6465 if (cbSrcAndLine == cbDstAndLine)
6466 memcpy(pbDst, pbSrc, cbSrcAndLine * cy);
6467 else
6468 {
6469 Assert(cbSrcAndLine > cbDstAndLine); /* lines are dword alined in source, but only byte in destination. */
6470 for (uint32_t y = 0; y < cy; y++)
6471 {
6472 memcpy(pbDst, pbSrc, cbDstAndLine);
6473 pbDst += cbDstAndLine;
6474 pbSrc += cbSrcAndLine;
6475 }
6476 }
6477 break;
6478 /* Should take the XOR mask into account for the multi-bit AND mask. */
6479 case 8:
6480 for (uint32_t y = 0; y < cy; y++)
6481 {
6482 for (uint32_t x = 0; x < cx; )
6483 {
6484 uint8_t bDst = 0;
6485 uint8_t fBit = 0x80;
6486 do
6487 {
6488 uintptr_t const idxPal = pbSrc[x] * 3;
6489 if ((( pThis->last_palette[idxPal]
6490 | (pThis->last_palette[idxPal] >> 8)
6491 | (pThis->last_palette[idxPal] >> 16)) & 0xff) > 0xfc)
6492 bDst |= fBit;
6493 fBit >>= 1;
6494 x++;
6495 } while (x < cx && (x & 7));
6496 pbDst[(x - 1) / 8] = bDst;
6497 }
6498 pbDst += cbDstAndLine;
6499 pbSrc += cbSrcAndLine;
6500 }
6501 break;
6502 case 15:
6503 for (uint32_t y = 0; y < cy; y++)
6504 {
6505 for (uint32_t x = 0; x < cx; )
6506 {
6507 uint8_t bDst = 0;
6508 uint8_t fBit = 0x80;
6509 do
6510 {
6511 if ((pbSrc[x * 2] | (pbSrc[x * 2 + 1] & 0x7f)) >= 0xfc)
6512 bDst |= fBit;
6513 fBit >>= 1;
6514 x++;
6515 } while (x < cx && (x & 7));
6516 pbDst[(x - 1) / 8] = bDst;
6517 }
6518 pbDst += cbDstAndLine;
6519 pbSrc += cbSrcAndLine;
6520 }
6521 break;
6522 case 16:
6523 for (uint32_t y = 0; y < cy; y++)
6524 {
6525 for (uint32_t x = 0; x < cx; )
6526 {
6527 uint8_t bDst = 0;
6528 uint8_t fBit = 0x80;
6529 do
6530 {
6531 if ((pbSrc[x * 2] | pbSrc[x * 2 + 1]) >= 0xfc)
6532 bDst |= fBit;
6533 fBit >>= 1;
6534 x++;
6535 } while (x < cx && (x & 7));
6536 pbDst[(x - 1) / 8] = bDst;
6537 }
6538 pbDst += cbDstAndLine;
6539 pbSrc += cbSrcAndLine;
6540 }
6541 break;
6542 case 24:
6543 for (uint32_t y = 0; y < cy; y++)
6544 {
6545 for (uint32_t x = 0; x < cx; )
6546 {
6547 uint8_t bDst = 0;
6548 uint8_t fBit = 0x80;
6549 do
6550 {
6551 if ((pbSrc[x * 3] | pbSrc[x * 3 + 1] | pbSrc[x * 3 + 2]) >= 0xfc)
6552 bDst |= fBit;
6553 fBit >>= 1;
6554 x++;
6555 } while (x < cx && (x & 7));
6556 pbDst[(x - 1) / 8] = bDst;
6557 }
6558 pbDst += cbDstAndLine;
6559 pbSrc += cbSrcAndLine;
6560 }
6561 break;
6562 case 32:
6563 for (uint32_t y = 0; y < cy; y++)
6564 {
6565 for (uint32_t x = 0; x < cx; )
6566 {
6567 uint8_t bDst = 0;
6568 uint8_t fBit = 0x80;
6569 do
6570 {
6571 if ((pbSrc[x * 4] | pbSrc[x * 4 + 1] | pbSrc[x * 4 + 2] | pbSrc[x * 4 + 3]) >= 0xfc)
6572 bDst |= fBit;
6573 fBit >>= 1;
6574 x++;
6575 } while (x < cx && (x & 7));
6576 pbDst[(x - 1) / 8] = bDst;
6577 }
6578 pbDst += cbDstAndLine;
6579 pbSrc += cbSrcAndLine;
6580 }
6581 break;
6582 default:
6583 RTMemFreeZ(pbCopy, cbCopy);
6584 AssertFailedReturnVoid();
6585 }
6586
6587 /* Convert the XOR mask. */
6588 uint32_t *pu32Dst = (uint32_t *)(pbCopy + RT_ALIGN_32(cbDstAndMask, 4));
6589 pbSrc = pbSrcXorMask;
6590 switch (pCmd->xorMaskDepth)
6591 {
6592 case 1:
6593 for (uint32_t y = 0; y < cy; y++)
6594 {
6595 for (uint32_t x = 0; x < cx; )
6596 {
6597 /* most significant bit is the left most one. */
6598 uint8_t bSrc = pbSrc[x / 8];
6599 do
6600 {
6601 *pu32Dst++ = bSrc & 0x80 ? UINT32_C(0x00ffffff) : 0;
6602 bSrc <<= 1;
6603 x++;
6604 } while ((x & 7) && x < cx);
6605 }
6606 pbSrc += cbSrcXorLine;
6607 }
6608 break;
6609 case 8:
6610 for (uint32_t y = 0; y < cy; y++)
6611 {
6612 for (uint32_t x = 0; x < cx; x++)
6613 {
6614 uint32_t u = pThis->last_palette[pbSrc[x]];
6615 *pu32Dst++ = u;//RT_MAKE_U32_FROM_U8(RT_BYTE1(u), RT_BYTE2(u), RT_BYTE3(u), 0);
6616 }
6617 pbSrc += cbSrcXorLine;
6618 }
6619 break;
6620 case 15: /* Src: RGB-5-5-5 */
6621 for (uint32_t y = 0; y < cy; y++)
6622 {
6623 for (uint32_t x = 0; x < cx; x++)
6624 {
6625 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
6626 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
6627 ((uValue >> 5) & 0x1f) << 3,
6628 ((uValue >> 10) & 0x1f) << 3, 0);
6629 }
6630 pbSrc += cbSrcXorLine;
6631 }
6632 break;
6633 case 16: /* Src: RGB-5-6-5 */
6634 for (uint32_t y = 0; y < cy; y++)
6635 {
6636 for (uint32_t x = 0; x < cx; x++)
6637 {
6638 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
6639 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
6640 ((uValue >> 5) & 0x3f) << 2,
6641 ((uValue >> 11) & 0x1f) << 3, 0);
6642 }
6643 pbSrc += cbSrcXorLine;
6644 }
6645 break;
6646 case 24:
6647 for (uint32_t y = 0; y < cy; y++)
6648 {
6649 for (uint32_t x = 0; x < cx; x++)
6650 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*3], pbSrc[x*3 + 1], pbSrc[x*3 + 2], 0);
6651 pbSrc += cbSrcXorLine;
6652 }
6653 break;
6654 case 32:
6655 for (uint32_t y = 0; y < cy; y++)
6656 {
6657 for (uint32_t x = 0; x < cx; x++)
6658 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*4], pbSrc[x*4 + 1], pbSrc[x*4 + 2], 0);
6659 pbSrc += cbSrcXorLine;
6660 }
6661 break;
6662 default:
6663 RTMemFreeZ(pbCopy, cbCopy);
6664 AssertFailedReturnVoid();
6665 }
6666
6667 /*
6668 * Pass it to the frontend/whatever.
6669 */
6670 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, false /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
6671 cx, cy, pbCopy, cbCopy);
6672}
6673
6674
6675/* SVGA_CMD_DEFINE_ALPHA_CURSOR */
6676void vmsvgaR3CmdDefineAlphaCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineAlphaCursor const *pCmd)
6677{
6678 RT_NOREF(pThis);
6679 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6680
6681 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineAlphaCursor);
6682 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));
6683
6684 /* Check against a reasonable upper limit to prevent integer overflows in the sanity checks below. */
6685 ASSERT_GUEST_RETURN_VOID(pCmd->height < 2048 && pCmd->width < 2048);
6686 RT_UNTRUSTED_VALIDATED_FENCE();
6687
6688 /* The mouse pointer interface always expects an AND mask followed by the color data (XOR mask). */
6689 uint32_t cbAndMask = (pCmd->width + 7) / 8 * pCmd->height; /* size of the AND mask */
6690 cbAndMask = ((cbAndMask + 3) & ~3); /* + gap for alignment */
6691 uint32_t cbXorMask = pCmd->width * sizeof(uint32_t) * pCmd->height; /* + size of the XOR mask (32-bit BRGA format) */
6692 uint32_t cbCursorShape = cbAndMask + cbXorMask;
6693
6694 uint8_t *pCursorCopy = (uint8_t *)RTMemAlloc(cbCursorShape);
6695 AssertPtrReturnVoid(pCursorCopy);
6696
6697 /* Transparency is defined by the alpha bytes, so make the whole bitmap visible. */
6698 memset(pCursorCopy, 0xff, cbAndMask);
6699 /* Colour data */
6700 memcpy(pCursorCopy + cbAndMask, pCmd + 1, cbXorMask);
6701
6702 vmsvgaR3InstallNewCursor(pThisCC, pSvgaR3State, true /*fAlpha*/, pCmd->hotspotX, pCmd->hotspotY,
6703 pCmd->width, pCmd->height, pCursorCopy, cbCursorShape);
6704}
6705
6706
6707/* SVGA_CMD_ESCAPE */
6708void vmsvgaR3CmdEscape(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdEscape const *pCmd)
6709{
6710 RT_NOREF(pThis);
6711 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6712
6713 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdEscape);
6714
6715 if (pCmd->nsid == SVGA_ESCAPE_NSID_VMWARE)
6716 {
6717 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(uint32_t));
6718 RT_UNTRUSTED_VALIDATED_FENCE();
6719
6720 uint32_t const cmd = *(uint32_t *)(pCmd + 1);
6721 Log(("SVGA_CMD_ESCAPE (%#x %#x) VMWARE cmd=%#x\n", pCmd->nsid, pCmd->size, cmd));
6722
6723 switch (cmd)
6724 {
6725 case SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS:
6726 {
6727 SVGAEscapeVideoSetRegs *pVideoCmd = (SVGAEscapeVideoSetRegs *)(pCmd + 1);
6728 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(pVideoCmd->header));
6729 RT_UNTRUSTED_VALIDATED_FENCE();
6730
6731 uint32_t const cRegs = (pCmd->size - sizeof(pVideoCmd->header)) / sizeof(pVideoCmd->items[0]);
6732
6733 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: stream %#x\n", pVideoCmd->header.streamId));
6734 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
6735 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: reg %#x val %#x\n", pVideoCmd->items[iReg].registerId, pVideoCmd->items[iReg].value));
6736 RT_NOREF_PV(pVideoCmd);
6737 break;
6738 }
6739
6740 case SVGA_ESCAPE_VMWARE_VIDEO_FLUSH:
6741 {
6742 SVGAEscapeVideoFlush *pVideoCmd = (SVGAEscapeVideoFlush *)(pCmd + 1);
6743 ASSERT_GUEST_RETURN_VOID(pCmd->size >= sizeof(*pVideoCmd));
6744 Log(("SVGA_ESCAPE_VMWARE_VIDEO_FLUSH: stream %#x\n", pVideoCmd->streamId));
6745 RT_NOREF_PV(pVideoCmd);
6746 break;
6747 }
6748
6749 default:
6750 Log(("SVGA_CMD_ESCAPE: Unknown vmware escape: %#x\n", cmd));
6751 break;
6752 }
6753 }
6754 else
6755 Log(("SVGA_CMD_ESCAPE %#x %#x\n", pCmd->nsid, pCmd->size));
6756}
6757
6758
6759/* SVGA_CMD_DEFINE_SCREEN */
6760void vmsvgaR3CmdDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineScreen const *pCmd)
6761{
6762 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6763
6764 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineScreen);
6765 Log(("SVGA_CMD_DEFINE_SCREEN id=%x flags=%x size=(%d,%d) root=(%d,%d) %d:0x%x 0x%x\n",
6766 pCmd->screen.id, pCmd->screen.flags, pCmd->screen.size.width, pCmd->screen.size.height, pCmd->screen.root.x, pCmd->screen.root.y,
6767 pCmd->screen.backingStore.ptr.gmrId, pCmd->screen.backingStore.ptr.offset, pCmd->screen.backingStore.pitch));
6768
6769 uint32_t const idScreen = pCmd->screen.id;
6770 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
6771
6772 uint32_t const uWidth = pCmd->screen.size.width;
6773 ASSERT_GUEST_RETURN_VOID(uWidth <= pThis->svga.u32MaxWidth);
6774
6775 uint32_t const uHeight = pCmd->screen.size.height;
6776 ASSERT_GUEST_RETURN_VOID(uHeight <= pThis->svga.u32MaxHeight);
6777
6778 uint32_t const cbWidth = uWidth * ((32 + 7) / 8); /** @todo 32? */
6779 uint32_t const cbPitch = pCmd->screen.backingStore.pitch ? pCmd->screen.backingStore.pitch : cbWidth;
6780 ASSERT_GUEST_RETURN_VOID(cbWidth <= cbPitch);
6781
6782 uint32_t const uScreenOffset = pCmd->screen.backingStore.ptr.offset;
6783 ASSERT_GUEST_RETURN_VOID(uScreenOffset < pThis->vram_size);
6784
6785 uint32_t const cbVram = pThis->vram_size - uScreenOffset;
6786 /* If we have a not zero pitch, then height can't exceed the available VRAM. */
6787 ASSERT_GUEST_RETURN_VOID( (uHeight == 0 && cbPitch == 0)
6788 || (cbPitch > 0 && uHeight <= cbVram / cbPitch));
6789 RT_UNTRUSTED_VALIDATED_FENCE();
6790
6791 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
6792 pScreen->fDefined = true;
6793 pScreen->fModified = true;
6794 pScreen->fuScreen = pCmd->screen.flags;
6795 pScreen->idScreen = idScreen;
6796 if (!RT_BOOL(pCmd->screen.flags & (SVGA_SCREEN_DEACTIVATE | SVGA_SCREEN_BLANKING)))
6797 {
6798 /* Not blanked. */
6799 ASSERT_GUEST_RETURN_VOID(uWidth > 0 && uHeight > 0);
6800 RT_UNTRUSTED_VALIDATED_FENCE();
6801
6802 pScreen->xOrigin = pCmd->screen.root.x;
6803 pScreen->yOrigin = pCmd->screen.root.y;
6804 pScreen->cWidth = uWidth;
6805 pScreen->cHeight = uHeight;
6806 pScreen->offVRAM = uScreenOffset;
6807 pScreen->cbPitch = cbPitch;
6808 pScreen->cBpp = 32;
6809 }
6810 else
6811 {
6812 /* Screen blanked. Keep old values. */
6813 }
6814
6815 pThis->svga.fGFBRegisters = false;
6816 vmsvgaR3ChangeMode(pThis, pThisCC);
6817
6818#ifdef VBOX_WITH_VMSVGA3D
6819 if (RT_LIKELY(pThis->svga.f3DEnabled))
6820 vmsvga3dDefineScreen(pThis, pThisCC, pScreen);
6821#endif
6822}
6823
6824
6825/* SVGA_CMD_DESTROY_SCREEN */
6826void vmsvgaR3CmdDestroyScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDestroyScreen const *pCmd)
6827{
6828 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6829
6830 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDestroyScreen);
6831 Log(("SVGA_CMD_DESTROY_SCREEN id=%x\n", pCmd->screenId));
6832
6833 uint32_t const idScreen = pCmd->screenId;
6834 ASSERT_GUEST_RETURN_VOID(idScreen < RT_ELEMENTS(pSvgaR3State->aScreens));
6835 RT_UNTRUSTED_VALIDATED_FENCE();
6836
6837 VMSVGASCREENOBJECT *pScreen = &pSvgaR3State->aScreens[idScreen];
6838 pScreen->fModified = true;
6839 pScreen->fDefined = false;
6840 pScreen->idScreen = idScreen;
6841
6842#ifdef VBOX_WITH_VMSVGA3D
6843 if (RT_LIKELY(pThis->svga.f3DEnabled))
6844 vmsvga3dDestroyScreen(pThisCC, pScreen);
6845#endif
6846 vmsvgaR3ChangeMode(pThis, pThisCC);
6847}
6848
6849
6850/* SVGA_CMD_DEFINE_GMRFB */
6851void vmsvgaR3CmdDefineGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMRFB const *pCmd)
6852{
6853 RT_NOREF(pThis);
6854 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6855
6856 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmrFb);
6857 Log(("SVGA_CMD_DEFINE_GMRFB gmr=%x offset=%x bytesPerLine=%x bpp=%d color depth=%d\n",
6858 pCmd->ptr.gmrId, pCmd->ptr.offset, pCmd->bytesPerLine, pCmd->format.bitsPerPixel, pCmd->format.colorDepth));
6859
6860 pSvgaR3State->GMRFB.ptr = pCmd->ptr;
6861 pSvgaR3State->GMRFB.bytesPerLine = pCmd->bytesPerLine;
6862 pSvgaR3State->GMRFB.format = pCmd->format;
6863}
6864
6865
6866/* SVGA_CMD_BLIT_GMRFB_TO_SCREEN */
6867void vmsvgaR3CmdBlitGMRFBToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitGMRFBToScreen const *pCmd)
6868{
6869 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6870
6871 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitGmrFbToScreen);
6872 Log(("SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n",
6873 pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
6874
6875 ASSERT_GUEST_RETURN_VOID(pCmd->destScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
6876 RT_UNTRUSTED_VALIDATED_FENCE();
6877
6878 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->destScreenId);
6879 AssertPtrReturnVoid(pScreen);
6880
6881 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp ? */
6882 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
6883
6884 /* Clip destRect to the screen dimensions. */
6885 SVGASignedRect screenRect;
6886 screenRect.left = 0;
6887 screenRect.top = 0;
6888 screenRect.right = pScreen->cWidth;
6889 screenRect.bottom = pScreen->cHeight;
6890 SVGASignedRect clipRect = pCmd->destRect;
6891 vmsvgaR3ClipRect(&screenRect, &clipRect);
6892 RT_UNTRUSTED_VALIDATED_FENCE();
6893
6894 uint32_t const width = clipRect.right - clipRect.left;
6895 uint32_t const height = clipRect.bottom - clipRect.top;
6896
6897 if ( width == 0
6898 || height == 0)
6899 return; /* Nothing to do. */
6900
6901 int32_t const srcx = pCmd->srcOrigin.x + (clipRect.left - pCmd->destRect.left);
6902 int32_t const srcy = pCmd->srcOrigin.y + (clipRect.top - pCmd->destRect.top);
6903
6904 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
6905 * Prepare parameters for vmsvgaR3GmrTransfer.
6906 */
6907 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
6908
6909 /* Destination: host buffer which describes the screen 0 VRAM.
6910 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
6911 */
6912 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
6913 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
6914 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
6915 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
6916 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
6917 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
6918 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
6919 + cbScanline * clipRect.top;
6920 int32_t const cbHstPitch = cbScanline;
6921
6922 /* Source: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
6923 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
6924 uint32_t const offGst = (srcx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
6925 + pSvgaR3State->GMRFB.bytesPerLine * srcy;
6926 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
6927
6928 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_WRITE_HOST_VRAM,
6929 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
6930 gstPtr, offGst, cbGstPitch,
6931 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
6932 AssertRC(rc);
6933 vmsvgaR3UpdateScreen(pThisCC, pScreen, clipRect.left, clipRect.top, width, height);
6934}
6935
6936
6937/* SVGA_CMD_BLIT_SCREEN_TO_GMRFB */
6938void vmsvgaR3CmdBlitScreenToGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitScreenToGMRFB const *pCmd)
6939{
6940 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
6941
6942 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdBlitScreentoGmrFb);
6943 /* Note! This can fetch 3d render results as well!! */
6944 Log(("SVGA_CMD_BLIT_SCREEN_TO_GMRFB dest=(%d,%d) src id=%d (%d,%d)(%d,%d)\n",
6945 pCmd->destOrigin.x, pCmd->destOrigin.y, pCmd->srcScreenId, pCmd->srcRect.left, pCmd->srcRect.top, pCmd->srcRect.right, pCmd->srcRect.bottom));
6946
6947 ASSERT_GUEST_RETURN_VOID(pCmd->srcScreenId < RT_ELEMENTS(pSvgaR3State->aScreens));
6948 RT_UNTRUSTED_VALIDATED_FENCE();
6949
6950 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, pCmd->srcScreenId);
6951 AssertPtrReturnVoid(pScreen);
6952
6953 /** @todo Support GMRFB.format.bitsPerPixel != pThis->svga.uBpp ? */
6954 AssertReturnVoid(pSvgaR3State->GMRFB.format.bitsPerPixel == pScreen->cBpp);
6955
6956 /* Clip destRect to the screen dimensions. */
6957 SVGASignedRect screenRect;
6958 screenRect.left = 0;
6959 screenRect.top = 0;
6960 screenRect.right = pScreen->cWidth;
6961 screenRect.bottom = pScreen->cHeight;
6962 SVGASignedRect clipRect = pCmd->srcRect;
6963 vmsvgaR3ClipRect(&screenRect, &clipRect);
6964 RT_UNTRUSTED_VALIDATED_FENCE();
6965
6966 uint32_t const width = clipRect.right - clipRect.left;
6967 uint32_t const height = clipRect.bottom - clipRect.top;
6968
6969 if ( width == 0
6970 || height == 0)
6971 return; /* Nothing to do. */
6972
6973 int32_t const dstx = pCmd->destOrigin.x + (clipRect.left - pCmd->srcRect.left);
6974 int32_t const dsty = pCmd->destOrigin.y + (clipRect.top - pCmd->srcRect.top);
6975
6976 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
6977 * Prepare parameters for vmsvgaR3GmrTransfer.
6978 */
6979 AssertReturnVoid(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
6980
6981 /* Source: host buffer which describes the screen 0 VRAM.
6982 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaR3GmrTransfer.
6983 */
6984 uint8_t * const pbHstBuf = (uint8_t *)pThisCC->pbVRam + pScreen->offVRAM;
6985 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
6986 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
6987 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
6988 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
6989 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
6990 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
6991 + cbScanline * clipRect.top;
6992 int32_t const cbHstPitch = cbScanline;
6993
6994 /* Destination: GMRFB. vmsvgaR3GmrTransfer ensures that no memory outside the GMR is read. */
6995 SVGAGuestPtr const gstPtr = pSvgaR3State->GMRFB.ptr;
6996 uint32_t const offGst = (dstx * RT_ALIGN(pSvgaR3State->GMRFB.format.bitsPerPixel, 8)) / 8
6997 + pSvgaR3State->GMRFB.bytesPerLine * dsty;
6998 int32_t const cbGstPitch = pSvgaR3State->GMRFB.bytesPerLine;
6999
7000 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_READ_HOST_VRAM,
7001 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
7002 gstPtr, offGst, cbGstPitch,
7003 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
7004 AssertRC(rc);
7005}
7006
7007
7008/* SVGA_CMD_ANNOTATION_FILL */
7009void vmsvgaR3CmdAnnotationFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationFill const *pCmd)
7010{
7011 RT_NOREF(pThis);
7012 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
7013
7014 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationFill);
7015 Log(("SVGA_CMD_ANNOTATION_FILL red=%x green=%x blue=%x\n", pCmd->color.r, pCmd->color.g, pCmd->color.b));
7016
7017 pSvgaR3State->colorAnnotation = pCmd->color;
7018}
7019
7020
7021/* SVGA_CMD_ANNOTATION_COPY */
7022void vmsvgaR3CmdAnnotationCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationCopy const *pCmd)
7023{
7024 RT_NOREF(pThis, pCmd);
7025 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
7026
7027 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdAnnotationCopy);
7028 Log(("SVGA_CMD_ANNOTATION_COPY srcOrigin %d,%d, srcScreenId %u\n", pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->srcScreenId));
7029
7030 AssertFailed();
7031}
7032
7033
7034#ifdef VBOX_WITH_VMSVGA3D
7035/* SVGA_CMD_DEFINE_GMR2 */
7036void vmsvgaR3CmdDefineGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMR2 const *pCmd)
7037{
7038 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
7039
7040 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2);
7041 Log(("SVGA_CMD_DEFINE_GMR2 id=%#x %#x pages\n", pCmd->gmrId, pCmd->numPages));
7042
7043 /* Validate current GMR id. */
7044 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
7045 ASSERT_GUEST_RETURN_VOID(pCmd->numPages <= VMSVGA_MAX_GMR_PAGES);
7046 RT_UNTRUSTED_VALIDATED_FENCE();
7047
7048 if (!pCmd->numPages)
7049 {
7050 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Free);
7051 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
7052 }
7053 else
7054 {
7055 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
7056 if (pGMR->cMaxPages)
7057 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdDefineGmr2Modify);
7058
7059 /* Not sure if we should always free the descriptor, but for simplicity
7060 we do so if the new size is smaller than the current. */
7061 /** @todo always free the descriptor in SVGA_CMD_DEFINE_GMR2? */
7062 if (pGMR->cbTotal / X86_PAGE_SIZE > pCmd->numPages)
7063 vmsvgaR3GmrFree(pThisCC, pCmd->gmrId);
7064
7065 pGMR->cMaxPages = pCmd->numPages;
7066 /* The rest is done by the REMAP_GMR2 command. */
7067 }
7068}
7069
7070
7071/* SVGA_CMD_REMAP_GMR2 */
7072void vmsvgaR3CmdRemapGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRemapGMR2 const *pCmd)
7073{
7074 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
7075
7076 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2);
7077 Log(("SVGA_CMD_REMAP_GMR2 id=%#x flags=%#x offset=%#x npages=%#x\n", pCmd->gmrId, pCmd->flags, pCmd->offsetPages, pCmd->numPages));
7078
7079 /* Validate current GMR id and size. */
7080 ASSERT_GUEST_RETURN_VOID(pCmd->gmrId < pThis->svga.cGMR);
7081 RT_UNTRUSTED_VALIDATED_FENCE();
7082 PGMR pGMR = &pSvgaR3State->paGMR[pCmd->gmrId];
7083 ASSERT_GUEST_RETURN_VOID( (uint64_t)pCmd->offsetPages + pCmd->numPages
7084 <= RT_MIN(pGMR->cMaxPages, RT_MIN(VMSVGA_MAX_GMR_PAGES, UINT32_MAX / X86_PAGE_SIZE)));
7085 ASSERT_GUEST_RETURN_VOID(!pCmd->offsetPages || pGMR->paDesc); /** @todo */
7086
7087 if (pCmd->numPages == 0)
7088 return;
7089 RT_UNTRUSTED_VALIDATED_FENCE();
7090
7091 /* Calc new total page count so we can use it instead of cMaxPages for allocations below. */
7092 uint32_t const cNewTotalPages = RT_MAX(pGMR->cbTotal >> X86_PAGE_SHIFT, pCmd->offsetPages + pCmd->numPages);
7093
7094 /*
7095 * We flatten the existing descriptors into a page array, overwrite the
7096 * pages specified in this command and then recompress the descriptor.
7097 */
7098 /** @todo Optimize the GMR remap algorithm! */
7099
7100 /* Save the old page descriptors as an array of page frame numbers (address >> X86_PAGE_SHIFT) */
7101 uint64_t *paNewPage64 = NULL;
7102 if (pGMR->paDesc)
7103 {
7104 STAM_REL_COUNTER_INC(&pSvgaR3State->StatR3CmdRemapGmr2Modify);
7105
7106 paNewPage64 = (uint64_t *)RTMemAllocZ(cNewTotalPages * sizeof(uint64_t));
7107 AssertPtrReturnVoid(paNewPage64);
7108
7109 uint32_t idxPage = 0;
7110 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
7111 for (uint32_t j = 0; j < pGMR->paDesc[i].numPages; j++)
7112 paNewPage64[idxPage++] = (pGMR->paDesc[i].GCPhys + j * X86_PAGE_SIZE) >> X86_PAGE_SHIFT;
7113 AssertReturnVoidStmt(idxPage == pGMR->cbTotal >> X86_PAGE_SHIFT, RTMemFree(paNewPage64));
7114 RT_UNTRUSTED_VALIDATED_FENCE();
7115 }
7116
7117 /* Free the old GMR if present. */
7118 if (pGMR->paDesc)
7119 RTMemFree(pGMR->paDesc);
7120
7121 /* Allocate the maximum amount possible (everything non-continuous) */
7122 PVMSVGAGMRDESCRIPTOR paDescs;
7123 pGMR->paDesc = paDescs = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(cNewTotalPages * sizeof(VMSVGAGMRDESCRIPTOR));
7124 AssertReturnVoidStmt(paDescs, RTMemFree(paNewPage64));
7125
7126 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
7127 {
7128 /** @todo */
7129 AssertFailed();
7130 pGMR->numDescriptors = 0;
7131 }
7132 else
7133 {
7134 uint32_t *paPages32 = (uint32_t *)(pCmd + 1);
7135 uint64_t *paPages64 = (uint64_t *)(pCmd + 1);
7136 bool fGCPhys64 = RT_BOOL(pCmd->flags & SVGA_REMAP_GMR2_PPN64);
7137
7138 uint32_t cPages;
7139 if (paNewPage64)
7140 {
7141 /* Overwrite the old page array with the new page values. */
7142 if (fGCPhys64)
7143 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
7144 paNewPage64[i] = paPages64[i - pCmd->offsetPages];
7145 else
7146 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
7147 paNewPage64[i] = paPages32[i - pCmd->offsetPages];
7148
7149 /* Use the updated page array instead of the command data. */
7150 fGCPhys64 = true;
7151 paPages64 = paNewPage64;
7152 cPages = cNewTotalPages;
7153 }
7154 else
7155 cPages = pCmd->numPages;
7156
7157 /* The first page. */
7158 /** @todo The 0x00000FFFFFFFFFFF mask limits to 44 bits and should not be
7159 * applied to paNewPage64. */
7160 RTGCPHYS GCPhys;
7161 if (fGCPhys64)
7162 GCPhys = (paPages64[0] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
7163 else
7164 GCPhys = (RTGCPHYS)paPages32[0] << GUEST_PAGE_SHIFT;
7165 paDescs[0].GCPhys = GCPhys;
7166 paDescs[0].numPages = 1;
7167
7168 /* Subsequent pages. */
7169 uint32_t iDescriptor = 0;
7170 for (uint32_t i = 1; i < cPages; i++)
7171 {
7172 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
7173 GCPhys = (paPages64[i] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
7174 else
7175 GCPhys = (RTGCPHYS)paPages32[i] << X86_PAGE_SHIFT;
7176
7177 /* Continuous physical memory? */
7178 if (GCPhys == paDescs[iDescriptor].GCPhys + paDescs[iDescriptor].numPages * X86_PAGE_SIZE)
7179 {
7180 Assert(paDescs[iDescriptor].numPages);
7181 paDescs[iDescriptor].numPages++;
7182 Log5Func(("Page %x GCPhys=%RGp successor\n", i, GCPhys));
7183 }
7184 else
7185 {
7186 iDescriptor++;
7187 paDescs[iDescriptor].GCPhys = GCPhys;
7188 paDescs[iDescriptor].numPages = 1;
7189 Log5Func(("Page %x GCPhys=%RGp\n", i, paDescs[iDescriptor].GCPhys));
7190 }
7191 }
7192
7193 pGMR->cbTotal = cNewTotalPages << X86_PAGE_SHIFT;
7194 Log5Func(("Nr of descriptors %x; cbTotal=%#x\n", iDescriptor + 1, cNewTotalPages));
7195 pGMR->numDescriptors = iDescriptor + 1;
7196 }
7197
7198 if (paNewPage64)
7199 RTMemFree(paNewPage64);
7200}
7201
7202
7203/**
7204 * Free the specified GMR
7205 *
7206 * @param pThisCC The VGA/VMSVGA state for ring-3.
7207 * @param idGMR GMR id
7208 */
7209void vmsvgaR3GmrFree(PVGASTATECC pThisCC, uint32_t idGMR)
7210{
7211 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
7212
7213 /* Free the old descriptor if present. */
7214 PGMR pGMR = &pSVGAState->paGMR[idGMR];
7215 if ( pGMR->numDescriptors
7216 || pGMR->paDesc /* needed till we implement SVGA_REMAP_GMR2_VIA_GMR */)
7217 {
7218# ifdef DEBUG_GMR_ACCESS
7219 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThisCC->pDevIns), VMCPUID_ANY, (PFNRT)vmsvgaR3DeregisterGmr, 2, pDevIns, idGMR);
7220# endif
7221
7222 Assert(pGMR->paDesc);
7223 RTMemFree(pGMR->paDesc);
7224 pGMR->paDesc = NULL;
7225 pGMR->numDescriptors = 0;
7226 pGMR->cbTotal = 0;
7227 pGMR->cMaxPages = 0;
7228 }
7229 Assert(!pGMR->cMaxPages);
7230 Assert(!pGMR->cbTotal);
7231}
7232#endif /* VBOX_WITH_VMSVGA3D */
7233
7234
7235/**
7236 * Copy between a GMR and a host memory buffer.
7237 *
7238 * @returns VBox status code.
7239 * @param pThis The shared VGA/VMSVGA instance data.
7240 * @param pThisCC The VGA/VMSVGA state for ring-3.
7241 * @param enmTransferType Transfer type (read/write)
7242 * @param pbHstBuf Host buffer pointer (valid)
7243 * @param cbHstBuf Size of host buffer (valid)
7244 * @param offHst Host buffer offset of the first scanline
7245 * @param cbHstPitch Destination buffer pitch
7246 * @param gstPtr GMR description
7247 * @param offGst Guest buffer offset of the first scanline
7248 * @param cbGstPitch Guest buffer pitch
7249 * @param cbWidth Width in bytes to copy
7250 * @param cHeight Number of scanllines to copy
7251 */
7252int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
7253 uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
7254 SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
7255 uint32_t cbWidth, uint32_t cHeight)
7256{
7257 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
7258 PPDMDEVINS pDevIns = pThisCC->pDevIns; /* simpler */
7259 int rc;
7260
7261 LogFunc(("%s host %p size=%d offset %d pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
7262 enmTransferType == SVGA3D_READ_HOST_VRAM ? "WRITE" : "READ", /* GMR op: READ host VRAM means WRITE GMR */
7263 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
7264 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cbWidth, cHeight));
7265 AssertReturn(cbWidth && cHeight, VERR_INVALID_PARAMETER);
7266
7267 PGMR pGMR;
7268 uint32_t cbGmr; /* The GMR size in bytes. */
7269 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
7270 {
7271 pGMR = NULL;
7272 cbGmr = pThis->vram_size;
7273 }
7274 else
7275 {
7276 AssertReturn(gstPtr.gmrId < pThis->svga.cGMR, VERR_INVALID_PARAMETER);
7277 RT_UNTRUSTED_VALIDATED_FENCE();
7278 pGMR = &pSVGAState->paGMR[gstPtr.gmrId];
7279 cbGmr = pGMR->cbTotal;
7280 }
7281
7282 /*
7283 * GMR
7284 */
7285 /* Calculate GMR offset of the data to be copied. */
7286 AssertMsgReturn(gstPtr.offset < cbGmr,
7287 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7288 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7289 VERR_INVALID_PARAMETER);
7290 RT_UNTRUSTED_VALIDATED_FENCE();
7291 AssertMsgReturn(offGst < cbGmr - gstPtr.offset,
7292 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7293 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7294 VERR_INVALID_PARAMETER);
7295 RT_UNTRUSTED_VALIDATED_FENCE();
7296 uint32_t const offGmr = offGst + gstPtr.offset; /* Offset in the GMR, where the first scanline is located. */
7297
7298 /* Verify that cbWidth is less than scanline and fits into the GMR. */
7299 uint32_t const cbGmrScanline = cbGstPitch > 0 ? cbGstPitch : -cbGstPitch;
7300 AssertMsgReturn(cbGmrScanline != 0,
7301 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7302 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7303 VERR_INVALID_PARAMETER);
7304 RT_UNTRUSTED_VALIDATED_FENCE();
7305 AssertMsgReturn(cbWidth <= cbGmrScanline,
7306 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7307 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7308 VERR_INVALID_PARAMETER);
7309 AssertMsgReturn(cbWidth <= cbGmr - offGmr,
7310 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7311 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7312 VERR_INVALID_PARAMETER);
7313 RT_UNTRUSTED_VALIDATED_FENCE();
7314
7315 /* How many bytes are available for the data in the GMR. */
7316 uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmr - offGmr : offGmr + cbWidth;
7317
7318 /* How many scanlines would fit into the available data. */
7319 uint32_t cGmrScanlines = cbGmrLeft / cbGmrScanline;
7320 uint32_t const cbGmrLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
7321 if (cbWidth <= cbGmrLastScanline)
7322 ++cGmrScanlines;
7323
7324 if (cHeight > cGmrScanlines)
7325 cHeight = cGmrScanlines;
7326
7327 AssertMsgReturn(cHeight > 0,
7328 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
7329 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
7330 VERR_INVALID_PARAMETER);
7331 RT_UNTRUSTED_VALIDATED_FENCE();
7332
7333 /*
7334 * Host buffer.
7335 */
7336 AssertMsgReturn(offHst < cbHstBuf,
7337 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7338 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7339 VERR_INVALID_PARAMETER);
7340
7341 /* Verify that cbWidth is less than scanline and fits into the buffer. */
7342 uint32_t const cbHstScanline = cbHstPitch > 0 ? cbHstPitch : -cbHstPitch;
7343 AssertMsgReturn(cbHstScanline != 0,
7344 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7345 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7346 VERR_INVALID_PARAMETER);
7347 AssertMsgReturn(cbWidth <= cbHstScanline,
7348 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7349 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7350 VERR_INVALID_PARAMETER);
7351 AssertMsgReturn(cbWidth <= cbHstBuf - offHst,
7352 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7353 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7354 VERR_INVALID_PARAMETER);
7355
7356 /* How many bytes are available for the data in the buffer. */
7357 uint32_t const cbHstLeft = cbHstPitch > 0 ? cbHstBuf - offHst : offHst + cbWidth;
7358
7359 /* How many scanlines would fit into the available data. */
7360 uint32_t cHstScanlines = cbHstLeft / cbHstScanline;
7361 uint32_t const cbHstLastScanline = cbHstLeft - cHstScanlines * cbHstScanline; /* Slack space. */
7362 if (cbWidth <= cbHstLastScanline)
7363 ++cHstScanlines;
7364
7365 if (cHeight > cHstScanlines)
7366 cHeight = cHstScanlines;
7367
7368 AssertMsgReturn(cHeight > 0,
7369 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
7370 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
7371 VERR_INVALID_PARAMETER);
7372
7373 uint8_t *pbHst = pbHstBuf + offHst;
7374
7375 /* Shortcut for the framebuffer. */
7376 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
7377 {
7378 uint8_t *pbGst = pThisCC->pbVRam + offGmr;
7379
7380 uint8_t const *pbSrc;
7381 int32_t cbSrcPitch;
7382 uint8_t *pbDst;
7383 int32_t cbDstPitch;
7384
7385 if (enmTransferType == SVGA3D_READ_HOST_VRAM)
7386 {
7387 pbSrc = pbHst;
7388 cbSrcPitch = cbHstPitch;
7389 pbDst = pbGst;
7390 cbDstPitch = cbGstPitch;
7391 }
7392 else
7393 {
7394 pbSrc = pbGst;
7395 cbSrcPitch = cbGstPitch;
7396 pbDst = pbHst;
7397 cbDstPitch = cbHstPitch;
7398 }
7399
7400 if ( cbWidth == (uint32_t)cbGstPitch
7401 && cbGstPitch == cbHstPitch)
7402 {
7403 /* Entire scanlines, positive pitch. */
7404 memcpy(pbDst, pbSrc, cbWidth * cHeight);
7405 }
7406 else
7407 {
7408 for (uint32_t i = 0; i < cHeight; ++i)
7409 {
7410 memcpy(pbDst, pbSrc, cbWidth);
7411
7412 pbDst += cbDstPitch;
7413 pbSrc += cbSrcPitch;
7414 }
7415 }
7416 return VINF_SUCCESS;
7417 }
7418
7419 AssertPtrReturn(pGMR, VERR_INVALID_PARAMETER);
7420 AssertReturn(pGMR->numDescriptors > 0, VERR_INVALID_PARAMETER);
7421
7422 PVMSVGAGMRDESCRIPTOR const paDesc = pGMR->paDesc; /* Local copy of the pointer. */
7423 uint32_t iDesc = 0; /* Index in the descriptor array. */
7424 uint32_t offDesc = 0; /* GMR offset of the current descriptor. */
7425 uint32_t offGmrScanline = offGmr; /* GMR offset of the scanline which is being copied. */
7426 uint8_t *pbHstScanline = pbHst; /* Host address of the scanline which is being copied. */
7427 for (uint32_t i = 0; i < cHeight; ++i)
7428 {
7429 uint32_t cbCurrentWidth = cbWidth;
7430 uint32_t offGmrCurrent = offGmrScanline;
7431 uint8_t *pbCurrentHost = pbHstScanline;
7432
7433 /* Find the right descriptor */
7434 while (offDesc + paDesc[iDesc].numPages * GUEST_PAGE_SIZE <= offGmrCurrent)
7435 {
7436 offDesc += paDesc[iDesc].numPages * GUEST_PAGE_SIZE;
7437 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
7438 ++iDesc;
7439 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
7440 }
7441
7442 while (cbCurrentWidth)
7443 {
7444 uint32_t cbToCopy;
7445
7446 if (offGmrCurrent + cbCurrentWidth <= offDesc + paDesc[iDesc].numPages * GUEST_PAGE_SIZE)
7447 cbToCopy = cbCurrentWidth;
7448 else
7449 {
7450 cbToCopy = (offDesc + paDesc[iDesc].numPages * GUEST_PAGE_SIZE - offGmrCurrent);
7451 AssertReturn(cbToCopy <= cbCurrentWidth, VERR_INVALID_PARAMETER);
7452 }
7453
7454 RTGCPHYS const GCPhys = paDesc[iDesc].GCPhys + offGmrCurrent - offDesc;
7455
7456 Log5Func(("%s phys=%RGp\n", (enmTransferType == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", GCPhys));
7457
7458 /*
7459 * We are deliberately using the non-PCI version of PDMDevHlpPCIPhys[Read|Write] as the
7460 * guest-side VMSVGA driver seems to allocate non-DMA (physical memory) addresses,
7461 * see @bugref{9654#c75}.
7462 */
7463 if (enmTransferType == SVGA3D_WRITE_HOST_VRAM)
7464 rc = PDMDevHlpPhysRead(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
7465 else
7466 rc = PDMDevHlpPhysWrite(pDevIns, GCPhys, pbCurrentHost, cbToCopy);
7467 AssertRCBreak(rc);
7468
7469 cbCurrentWidth -= cbToCopy;
7470 offGmrCurrent += cbToCopy;
7471 pbCurrentHost += cbToCopy;
7472
7473 /* Go to the next descriptor if there's anything left. */
7474 if (cbCurrentWidth)
7475 {
7476 offDesc += paDesc[iDesc].numPages * GUEST_PAGE_SIZE;
7477 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR);
7478 ++iDesc;
7479 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
7480 }
7481 }
7482
7483 offGmrScanline += cbGstPitch;
7484 pbHstScanline += cbHstPitch;
7485 }
7486
7487 return VINF_SUCCESS;
7488}
7489
7490
7491/**
7492 * Unsigned coordinates in pBox. Clip to [0; pSizeSrc), [0; pSizeDest).
7493 *
7494 * @param pSizeSrc Source surface dimensions.
7495 * @param pSizeDest Destination surface dimensions.
7496 * @param pBox Coordinates to be clipped.
7497 */
7498void vmsvgaR3ClipCopyBox(const SVGA3dSize *pSizeSrc, const SVGA3dSize *pSizeDest, SVGA3dCopyBox *pBox)
7499{
7500 /* Src x, w */
7501 if (pBox->srcx > pSizeSrc->width)
7502 pBox->srcx = pSizeSrc->width;
7503 if (pBox->w > pSizeSrc->width - pBox->srcx)
7504 pBox->w = pSizeSrc->width - pBox->srcx;
7505
7506 /* Src y, h */
7507 if (pBox->srcy > pSizeSrc->height)
7508 pBox->srcy = pSizeSrc->height;
7509 if (pBox->h > pSizeSrc->height - pBox->srcy)
7510 pBox->h = pSizeSrc->height - pBox->srcy;
7511
7512 /* Src z, d */
7513 if (pBox->srcz > pSizeSrc->depth)
7514 pBox->srcz = pSizeSrc->depth;
7515 if (pBox->d > pSizeSrc->depth - pBox->srcz)
7516 pBox->d = pSizeSrc->depth - pBox->srcz;
7517
7518 /* Dest x, w */
7519 if (pBox->x > pSizeDest->width)
7520 pBox->x = pSizeDest->width;
7521 if (pBox->w > pSizeDest->width - pBox->x)
7522 pBox->w = pSizeDest->width - pBox->x;
7523
7524 /* Dest y, h */
7525 if (pBox->y > pSizeDest->height)
7526 pBox->y = pSizeDest->height;
7527 if (pBox->h > pSizeDest->height - pBox->y)
7528 pBox->h = pSizeDest->height - pBox->y;
7529
7530 /* Dest z, d */
7531 if (pBox->z > pSizeDest->depth)
7532 pBox->z = pSizeDest->depth;
7533 if (pBox->d > pSizeDest->depth - pBox->z)
7534 pBox->d = pSizeDest->depth - pBox->z;
7535}
7536
7537
7538/**
7539 * Unsigned coordinates in pBox. Clip to [0; pSize).
7540 *
7541 * @param pSize Source surface dimensions.
7542 * @param pBox Coordinates to be clipped.
7543 */
7544void vmsvgaR3ClipBox(const SVGA3dSize *pSize, SVGA3dBox *pBox)
7545{
7546 /* x, w */
7547 if (pBox->x > pSize->width)
7548 pBox->x = pSize->width;
7549 if (pBox->w > pSize->width - pBox->x)
7550 pBox->w = pSize->width - pBox->x;
7551
7552 /* y, h */
7553 if (pBox->y > pSize->height)
7554 pBox->y = pSize->height;
7555 if (pBox->h > pSize->height - pBox->y)
7556 pBox->h = pSize->height - pBox->y;
7557
7558 /* z, d */
7559 if (pBox->z > pSize->depth)
7560 pBox->z = pSize->depth;
7561 if (pBox->d > pSize->depth - pBox->z)
7562 pBox->d = pSize->depth - pBox->z;
7563}
7564
7565
7566/**
7567 * Clip.
7568 *
7569 * @param pBound Bounding rectangle.
7570 * @param pRect Rectangle to be clipped.
7571 */
7572void vmsvgaR3ClipRect(SVGASignedRect const *pBound, SVGASignedRect *pRect)
7573{
7574 int32_t left;
7575 int32_t top;
7576 int32_t right;
7577 int32_t bottom;
7578
7579 /* Right order. */
7580 Assert(pBound->left <= pBound->right && pBound->top <= pBound->bottom);
7581 if (pRect->left < pRect->right)
7582 {
7583 left = pRect->left;
7584 right = pRect->right;
7585 }
7586 else
7587 {
7588 left = pRect->right;
7589 right = pRect->left;
7590 }
7591 if (pRect->top < pRect->bottom)
7592 {
7593 top = pRect->top;
7594 bottom = pRect->bottom;
7595 }
7596 else
7597 {
7598 top = pRect->bottom;
7599 bottom = pRect->top;
7600 }
7601
7602 if (left < pBound->left)
7603 left = pBound->left;
7604 if (right < pBound->left)
7605 right = pBound->left;
7606
7607 if (left > pBound->right)
7608 left = pBound->right;
7609 if (right > pBound->right)
7610 right = pBound->right;
7611
7612 if (top < pBound->top)
7613 top = pBound->top;
7614 if (bottom < pBound->top)
7615 bottom = pBound->top;
7616
7617 if (top > pBound->bottom)
7618 top = pBound->bottom;
7619 if (bottom > pBound->bottom)
7620 bottom = pBound->bottom;
7621
7622 pRect->left = left;
7623 pRect->right = right;
7624 pRect->top = top;
7625 pRect->bottom = bottom;
7626}
7627
7628
7629/**
7630 * Clip.
7631 *
7632 * @param pBound Bounding rectangle.
7633 * @param pRect Rectangle to be clipped.
7634 */
7635void vmsvgaR3Clip3dRect(SVGA3dRect const *pBound, SVGA3dRect RT_UNTRUSTED_GUEST *pRect)
7636{
7637 uint32_t const leftBound = pBound->x;
7638 uint32_t const rightBound = pBound->x + pBound->w;
7639 uint32_t const topBound = pBound->y;
7640 uint32_t const bottomBound = pBound->y + pBound->h;
7641
7642 uint32_t x = pRect->x;
7643 uint32_t y = pRect->y;
7644 uint32_t w = pRect->w;
7645 uint32_t h = pRect->h;
7646
7647 /* Make sure that right and bottom coordinates can be safely computed. */
7648 if (x > rightBound)
7649 x = rightBound;
7650 if (w > rightBound - x)
7651 w = rightBound - x;
7652 if (y > bottomBound)
7653 y = bottomBound;
7654 if (h > bottomBound - y)
7655 h = bottomBound - y;
7656
7657 /* Switch from x, y, w, h to left, top, right, bottom. */
7658 uint32_t left = x;
7659 uint32_t right = x + w;
7660 uint32_t top = y;
7661 uint32_t bottom = y + h;
7662
7663 /* A standard left, right, bottom, top clipping. */
7664 if (left < leftBound)
7665 left = leftBound;
7666 if (right < leftBound)
7667 right = leftBound;
7668
7669 if (left > rightBound)
7670 left = rightBound;
7671 if (right > rightBound)
7672 right = rightBound;
7673
7674 if (top < topBound)
7675 top = topBound;
7676 if (bottom < topBound)
7677 bottom = topBound;
7678
7679 if (top > bottomBound)
7680 top = bottomBound;
7681 if (bottom > bottomBound)
7682 bottom = bottomBound;
7683
7684 /* Back to x, y, w, h representation. */
7685 pRect->x = left;
7686 pRect->y = top;
7687 pRect->w = right - left;
7688 pRect->h = bottom - top;
7689}
7690
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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