init the command bounce buffer details when the driver initializes since it can be...
[AROS.git] / workbench / hidds / vmwaresvga / vmwaresvga_gallium_ctx.c
blob5fbd40ab41ed9f40290bf2f56766cd27dd046862
1 /*
2 Copyright 2019, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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;
29 static void
30 VMWareSVGA_WSCtx_Destroy(struct svga_winsys_context *swc)
32 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
35 static void *
36 VMWareSVGA_WSCtx_Reserve(struct svga_winsys_context *swc,
37 uint32_t nr_bytes, uint32_t nr_relocs )
39 void *retval;
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)
47 return NULL;
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__));
54 return NULL;
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));
67 return retval;
70 static unsigned
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;
81 static void
82 VMWareSVGA_WSCtx_SurfaceReloc(struct svga_winsys_context *swc,
83 uint32 *where,
84 uint32 *mobid,
85 struct svga_winsys_surface *surface,
86 unsigned flags)
88 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
90 if (!surface) {
91 *where = SVGA3D_INVALID_ID;
92 if (mobid)
93 *mobid = SVGA3D_INVALID_ID;
94 return;
98 static void
99 VMWareSVGA_WSCtx_RegionReloc(struct svga_winsys_context *swc,
100 struct SVGAGuestPtr *where,
101 struct svga_winsys_buffer *buffer,
102 uint32 offset,
103 unsigned flags)
105 struct HIDDGalliumVMWareSVGACtx *hiddwsctx = VMWareSVGA_WSCtx_HiddDataFromWinSys(swc);
106 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
107 ++hiddwsctx->region.staged;
110 static void
111 VMWareSVGA_WSCtx_MObReloc(struct svga_winsys_context *swc,
112 SVGAMobId *id,
113 uint32 *offset_into_mob,
114 struct svga_winsys_buffer *buffer,
115 uint32 offset,
116 unsigned flags)
118 struct HIDDGalliumVMWareSVGACtx *hiddwsctx = VMWareSVGA_WSCtx_HiddDataFromWinSys(swc);
119 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
121 if (id) {
122 ++hiddwsctx->region.staged;
126 static void
127 VMWareSVGA_WSCtx_QueryReloc(struct svga_winsys_context *swc,
128 SVGAMobId *id,
129 struct svga_winsys_gb_query *query)
131 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
132 #if (0)
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);
136 #endif
139 static void
140 VMWareSVGA_WSCtx_ContextReloc(struct svga_winsys_context *swc,
141 uint32 *cid)
143 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
146 static void
147 VMWareSVGA_WSCtx_ShaderReloc(struct svga_winsys_context *swc,
148 uint32 *shid,
149 uint32 *mobid,
150 uint32 *offset,
151 struct svga_winsys_gb_shader *shader,
152 unsigned flags)
154 struct HIDDGalliumVMWareSVGACtx *hiddwsctx = VMWareSVGA_WSCtx_HiddDataFromWinSys(swc);
155 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, swc));
156 ++hiddwsctx->shader.staged;
159 static void
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;
189 enum pipe_error ret;
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;
210 return PIPE_OK;
213 static struct svga_winsys_gb_shader *
214 VMWareSVGA_WSCtx_ShaderCreate(struct svga_winsys_context *swc,
215 uint32 shaderId,
216 SVGA3dShaderType shaderType,
217 const uint32 *bytecode,
218 uint32 bytecodeLen)
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,
225 bytecodeLen);
228 static void
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,
243 unsigned flags)
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;
250 if (surface)
251 VMWareSVGA_WSCtx_SurfaceReloc(swc, NULL, NULL, surface, flags);
252 else if (shader)
253 VMWareSVGA_WSCtx_ShaderReloc(swc, NULL, NULL, NULL, shader, flags);
255 VMWareSVGA_WSCtx_Commit(swc);
257 return PIPE_OK;
260 ULONG VMWareSVGA_DefineContext(struct HIDDGalliumVMWareSVGAData *data, struct svga_winsys_context *wsctx)
262 D(bug("[VMWareSVGA:Gallium] %s()\n", __func__));
264 wsctx->cid = ++data->ctxcnt;
265 if ((SVGA3D_DefineContext(wsctx)) != PIPE_OK)
266 wsctx->cid = -1;
268 D(bug("[VMWareSVGA:Gallium] %s: returning %d\n", __func__, wsctx->cid));
270 return wsctx->cid;
273 ULONG VMWareSVGA_DefineExtContext(struct HIDDGalliumVMWareSVGAData *data, struct svga_winsys_context *wsctx, BOOL hasvgpu10)
275 D(bug("[VMWareSVGA:Gallium] %s()\n", __func__));
277 wsctx->cid = ++data->ctxcnt;
278 if ((SVGA3D_DefineContext(wsctx)) != PIPE_OK)
279 wsctx->cid = -1;
281 D(bug("[VMWareSVGA:Gallium] %s: returning %d\n", __func__, wsctx->cid));
282 return wsctx->cid;
285 void VMWareSVGA_WSCtx_WinSysInit(struct HIDDGalliumVMWareSVGAData *data, struct HIDDGalliumVMWareSVGACtx *hiddwsctx)
287 struct svga_winsys_context *wsctx;
289 D(bug("[VMWareSVGA:Gallium] %s(0x%p)\n", __func__, hiddwsctx));
291 wsctx = &hiddwsctx->wscbase;
293 D(bug("[VMWareSVGA:Gallium] %s: svga_winsys_context @ 0x%p\n", __func__, wsctx));
295 wsctx->destroy = VMWareSVGA_WSCtx_Destroy;
296 wsctx->reserve = VMWareSVGA_WSCtx_Reserve;
297 wsctx->get_command_buffer_size = VMWareSVGA_WSCtx_GetCmdBuffSize;
298 wsctx->surface_relocation = VMWareSVGA_WSCtx_SurfaceReloc;
299 wsctx->region_relocation = VMWareSVGA_WSCtx_RegionReloc;
300 wsctx->mob_relocation = VMWareSVGA_WSCtx_MObReloc;
301 wsctx->query_relocation = VMWareSVGA_WSCtx_QueryReloc;
303 wsctx->context_relocation = VMWareSVGA_WSCtx_ContextReloc;
304 wsctx->shader_relocation = VMWareSVGA_WSCtx_ShaderReloc;
305 wsctx->commit = VMWareSVGA_WSCtx_Commit;
306 wsctx->flush = VMWareSVGA_WSCtx_Flush;
308 wsctx->surface_map = VMWareSVGA_WSSurf_SurfaceMap;
309 wsctx->surface_unmap = VMWareSVGA_WSSurf_SurfaceUnMap;
310 wsctx->surface_invalidate = VMWareSVGA_WSSurf_SurfaceInvalidate;
312 wsctx->shader_create = VMWareSVGA_WSCtx_ShaderCreate;
313 wsctx->shader_destroy = VMWareSVGA_WSCtx_ShaderDestroy;
315 wsctx->resource_rebind = VMWareSVGA_WSCtx_RebindResource;
317 if (data->wssbase.have_vgpu10)
318 wsctx->cid = VMWareSVGA_DefineExtContext(data, wsctx, data->wssbase.have_vgpu10);
319 else
320 wsctx->cid = VMWareSVGA_DefineContext(data, wsctx);
322 wsctx->imported_fence_fd = -1;
324 wsctx->have_gb_objects = data->wssbase.have_gb_objects;
326 hiddwsctx->surface.size = VMW_SURFACE_RELOCS;
327 hiddwsctx->shader.size = VMW_SHADER_RELOCS;
328 hiddwsctx->region.size = VMW_REGION_RELOCS;