2 Copyright 2019, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #include <proto/exec.h>
9 #include <proto/graphics.h>
10 #include <proto/utility.h>
11 #include <proto/oop.h>
13 #include <aros/libcall.h>
14 #include <aros/asmcall.h>
15 #include <aros/symbolsets.h>
16 #include <utility/tagitem.h>
18 #include <hidd/gallium.h>
19 #include <gallium/gallium.h>
21 #include "vmwaresvga_intern.h"
24 static struct HIDDGalliumVMWareSVGACtx
*VMWareSVGA_WSCtx_HiddDataFromWinSys(struct svga_winsys_context
*swc
)
26 return (struct HIDDGalliumVMWareSVGACtx
*)swc
;
30 VMWareSVGA_WSCtx_Destroy(struct svga_winsys_context
*swc
)
32 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
36 VMWareSVGA_WSCtx_Reserve(struct svga_winsys_context
*swc
,
37 uint32_t nr_bytes
, uint32_t nr_relocs
)
41 D(bug("[VMWareSVGA:Gallium] %s(0x%p, %d, %d)\n", __func__
, swc
, nr_bytes
, nr_relocs
));
43 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
44 struct HIDDGalliumVMWareSVGAData
*data
= VMWareSVGA_WSScr_HiddDataFromWinSys(hiddwsctx
->wscsws
);
46 if(nr_bytes
> hiddwsctx
->command
->size
)
49 if(hiddwsctx
->command
->used
+ nr_bytes
> hiddwsctx
->command
->size
||
50 hiddwsctx
->surface
.used
+ nr_relocs
> hiddwsctx
->surface
.size
||
51 hiddwsctx
->shader
.used
+ nr_relocs
> hiddwsctx
->shader
.size
||
52 hiddwsctx
->region
.used
+ nr_relocs
> hiddwsctx
->region
.size
) {
53 D(bug("[VMWareSVGA:Gallium] %s: not enough free space\n", __func__
));
57 hiddwsctx
->surface
.reserved
= nr_relocs
;
58 hiddwsctx
->surface
.staged
= 0;
59 hiddwsctx
->shader
.reserved
= nr_relocs
;
60 hiddwsctx
->shader
.staged
= 0;
61 hiddwsctx
->region
.reserved
= nr_relocs
;
62 hiddwsctx
->region
.staged
= 0;
64 retval
= reserveVMWareSVGAFIFO(data
->hwdata
, nr_bytes
);
65 D(bug("[VMWareSVGA:Gallium] %s: returning 0x%p\n", __func__
, retval
));
71 VMWareSVGA_WSCtx_GetCmdBuffSize(struct svga_winsys_context
*swc
)
73 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
75 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
77 D(bug("[VMWareSVGA:Gallium] %s: returning %d\n", __func__
, hiddwsctx
->command
->used
));
78 return hiddwsctx
->command
->used
;
82 VMWareSVGA_WSCtx_SurfaceReloc(struct svga_winsys_context
*swc
,
85 struct svga_winsys_surface
*surface
,
88 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
91 *where
= SVGA3D_INVALID_ID
;
93 *mobid
= SVGA3D_INVALID_ID
;
99 VMWareSVGA_WSCtx_RegionReloc(struct svga_winsys_context
*swc
,
100 struct SVGAGuestPtr
*where
,
101 struct svga_winsys_buffer
*buffer
,
105 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
106 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
107 ++hiddwsctx
->region
.staged
;
111 VMWareSVGA_WSCtx_MObReloc(struct svga_winsys_context
*swc
,
113 uint32
*offset_into_mob
,
114 struct svga_winsys_buffer
*buffer
,
118 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
119 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
122 ++hiddwsctx
->region
.staged
;
127 VMWareSVGA_WSCtx_QueryReloc(struct svga_winsys_context
*swc
,
129 struct svga_winsys_gb_query
*query
)
131 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
133 /* Queries are backed by one big MOB */
134 VMWareSVGA_WSCtx_MObReloc(swc
, id
, NULL
, query
->buf
, 0,
135 SVGA_RELOC_READ
| SVGA_RELOC_WRITE
);
140 VMWareSVGA_WSCtx_ContextReloc(struct svga_winsys_context
*swc
,
143 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
147 VMWareSVGA_WSCtx_ShaderReloc(struct svga_winsys_context
*swc
,
151 struct svga_winsys_gb_shader
*shader
,
154 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
155 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
156 ++hiddwsctx
->shader
.staged
;
160 VMWareSVGA_WSCtx_Commit(struct svga_winsys_context
*swc
)
162 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
163 struct HIDDGalliumVMWareSVGAData
*data
= VMWareSVGA_WSScr_HiddDataFromWinSys(hiddwsctx
->wscsws
);
165 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
167 hiddwsctx
->surface
.used
+= hiddwsctx
->surface
.staged
;
168 hiddwsctx
->surface
.staged
= 0;
169 hiddwsctx
->surface
.reserved
= 0;
171 hiddwsctx
->shader
.used
+= hiddwsctx
->shader
.staged
;
172 hiddwsctx
->shader
.staged
= 0;
173 hiddwsctx
->shader
.reserved
= 0;
175 hiddwsctx
->region
.used
+= hiddwsctx
->region
.staged
;
176 hiddwsctx
->region
.staged
= 0;
177 hiddwsctx
->region
.reserved
= 0;
179 commitVMWareSVGAFIFO(data
->hwdata
, hiddwsctx
->command
->reserved
);
182 static enum pipe_error
183 VMWareSVGA_WSCtx_Flush(struct svga_winsys_context
*swc
,
184 struct pipe_fence_handle
**pfence
)
186 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
187 struct HIDDGalliumVMWareSVGAData
*data
= VMWareSVGA_WSScr_HiddDataFromWinSys(hiddwsctx
->wscsws
);
188 struct pipe_fence_handle
*fence
= NULL
;
191 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
194 if (hiddwsctx
->command
->used
|| pfence
!= NULL
)
195 flushVMWareSVGAFIFO(data
->hwdata
, (ULONG
*)(IPTR
)&fence
);
197 syncfenceVMWareSVGAFIFO(data
->hwdata
, (ULONG
)(IPTR
)fence
);
199 hiddwsctx
->command
->used
= 0;
201 hiddwsctx
->surface
.used
= 0;
202 hiddwsctx
->surface
.reserved
= 0;
204 hiddwsctx
->shader
.used
= 0;
205 hiddwsctx
->shader
.reserved
= 0;
207 hiddwsctx
->region
.used
= 0;
208 hiddwsctx
->region
.reserved
= 0;
213 static struct svga_winsys_gb_shader
*
214 VMWareSVGA_WSCtx_ShaderCreate(struct svga_winsys_context
*swc
,
216 SVGA3dShaderType shaderType
,
217 const uint32
*bytecode
,
220 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
222 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
224 return hiddwsctx
->wscsws
->shader_create(hiddwsctx
->wscsws
, shaderType
, bytecode
,
229 VMWareSVGA_WSCtx_ShaderDestroy(struct svga_winsys_context
*swc
,
230 struct svga_winsys_gb_shader
*shader
)
232 struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
= VMWareSVGA_WSCtx_HiddDataFromWinSys(swc
);
234 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
236 hiddwsctx
->wscsws
->shader_destroy(hiddwsctx
->wscsws
, shader
);
239 static enum pipe_error
240 VMWareSVGA_WSCtx_RebindResource(struct svga_winsys_context
*swc
,
241 struct svga_winsys_surface
*surface
,
242 struct svga_winsys_gb_shader
*shader
,
245 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, swc
));
247 if (!VMWareSVGA_WSCtx_Reserve(swc
, 0, 1))
248 return PIPE_ERROR_OUT_OF_MEMORY
;
251 VMWareSVGA_WSCtx_SurfaceReloc(swc
, NULL
, NULL
, surface
, flags
);
253 VMWareSVGA_WSCtx_ShaderReloc(swc
, NULL
, NULL
, NULL
, shader
, flags
);
255 VMWareSVGA_WSCtx_Commit(swc
);
260 void VMWareSVGA_WSCtx_WinSysInit(struct HIDDGalliumVMWareSVGAData
* data
, struct HIDDGalliumVMWareSVGACtx
*hiddwsctx
)
262 struct svga_winsys_context
*wsctx
;
264 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__
, hiddwsctx
));
266 wsctx
= &hiddwsctx
->wscbase
;
268 D(bug("[VMWareSVGA:Gallium] %s: svga_winsys_context @ 0x%p\n", __func__
, wsctx
));
270 wsctx
->destroy
= VMWareSVGA_WSCtx_Destroy
;
271 wsctx
->reserve
= VMWareSVGA_WSCtx_Reserve
;
272 wsctx
->get_command_buffer_size
= VMWareSVGA_WSCtx_GetCmdBuffSize
;
273 wsctx
->surface_relocation
= VMWareSVGA_WSCtx_SurfaceReloc
;
274 wsctx
->region_relocation
= VMWareSVGA_WSCtx_RegionReloc
;
275 wsctx
->mob_relocation
= VMWareSVGA_WSCtx_MObReloc
;
276 wsctx
->query_relocation
= VMWareSVGA_WSCtx_QueryReloc
;
278 wsctx
->context_relocation
= VMWareSVGA_WSCtx_ContextReloc
;
279 wsctx
->shader_relocation
= VMWareSVGA_WSCtx_ShaderReloc
;
280 wsctx
->commit
= VMWareSVGA_WSCtx_Commit
;
281 wsctx
->flush
= VMWareSVGA_WSCtx_Flush
;
283 wsctx
->surface_map
= VMWareSVGA_WSSurf_SurfaceMap
;
284 wsctx
->surface_unmap
= VMWareSVGA_WSSurf_SurfaceUnMap
;
285 wsctx
->surface_invalidate
= VMWareSVGA_WSSurf_SurfaceInvalidate
;
287 wsctx
->shader_create
= VMWareSVGA_WSCtx_ShaderCreate
;
288 wsctx
->shader_destroy
= VMWareSVGA_WSCtx_ShaderDestroy
;
290 wsctx
->resource_rebind
= VMWareSVGA_WSCtx_RebindResource
;
292 wsctx
->imported_fence_fd
= -1;
294 wsctx
->have_gb_objects
= data
->wssbase
.have_gb_objects
;
296 hiddwsctx
->command
->size
= VMW_COMMAND_SIZE
;
297 hiddwsctx
->surface
.size
= VMW_SURFACE_RELOCS
;
298 hiddwsctx
->shader
.size
= VMW_SHADER_RELOCS
;
299 hiddwsctx
->region
.size
= VMW_REGION_RELOCS
;