VirtualBox

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

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

Devices/Graphics: shader signatures: bugref:9830

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

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