v3d: compute appropriate VPM memory configuration for geometry shader workloads
[mesa.git] / src / gallium / drivers / v3d / v3d_simulator.c
1 /*
2 * Copyright © 2014-2017 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file v3d_simulator.c
26 *
27 * Implements VC5 simulation on top of a non-VC5 GEM fd.
28 *
29 * This file's goal is to emulate the VC5 ioctls' behavior in the kernel on
30 * top of the simpenrose software simulator. Generally, VC5 driver BOs have a
31 * GEM-side copy of their contents and a simulator-side memory area that the
32 * GEM contents get copied into during simulation. Once simulation is done,
33 * the simulator's data is copied back out to the GEM BOs, so that rendering
34 * appears on the screen as if actual hardware rendering had been done.
35 *
36 * One of the limitations of this code is that we shouldn't really need a
37 * GEM-side BO for non-window-system BOs. However, do we need unique BO
38 * handles for each of our GEM bos so that this file can look up its state
39 * from the handle passed in at submit ioctl time (also, a couple of places
40 * outside of this file still call ioctls directly on the fd).
41 *
42 * Another limitation is that BO import doesn't work unless the underlying
43 * window system's BO size matches what VC5 is going to use, which of course
44 * doesn't work out in practice. This means that for now, only DRI3 (VC5
45 * makes the winsys BOs) is supported, not DRI2 (window system makes the winys
46 * BOs).
47 */
48
49 #ifdef USE_V3D_SIMULATOR
50
51 #include <sys/mman.h>
52 #include "util/hash_table.h"
53 #include "util/ralloc.h"
54 #include "util/set.h"
55 #include "util/u_dynarray.h"
56 #include "util/u_memory.h"
57 #include "util/u_mm.h"
58 #include "drm-uapi/i915_drm.h"
59 #include "v3d_simulator_wrapper.h"
60
61 #include "v3d_screen.h"
62 #include "v3d_context.h"
63
64 /** Global (across GEM fds) state for the simulator */
65 static struct v3d_simulator_state {
66 mtx_t mutex;
67 mtx_t submit_lock;
68
69 struct v3d_hw *v3d;
70 int ver;
71
72 /* Base virtual address of the heap. */
73 void *mem;
74 /* Base hardware address of the heap. */
75 uint32_t mem_base;
76 /* Size of the heap. */
77 size_t mem_size;
78
79 struct mem_block *heap;
80 struct mem_block *overflow;
81
82 /** Mapping from GEM fd to struct v3d_simulator_file * */
83 struct hash_table *fd_map;
84
85 struct util_dynarray bin_oom;
86 int refcount;
87 } sim_state = {
88 .mutex = _MTX_INITIALIZER_NP,
89 };
90
91 /** Per-GEM-fd state for the simulator. */
92 struct v3d_simulator_file {
93 int fd;
94
95 /** Mapping from GEM handle to struct v3d_simulator_bo * */
96 struct hash_table *bo_map;
97
98 struct mem_block *gmp;
99 void *gmp_vaddr;
100
101 /** Actual GEM fd is i915, so we should use their create ioctl. */
102 bool is_i915;
103 };
104
105 /** Wrapper for drm_v3d_bo tracking the simulator-specific state. */
106 struct v3d_simulator_bo {
107 struct v3d_simulator_file *file;
108
109 /** Area for this BO within sim_state->mem */
110 struct mem_block *block;
111 uint32_t size;
112 uint64_t mmap_offset;
113 void *sim_vaddr;
114 void *gem_vaddr;
115
116 int handle;
117 };
118
119 static void *
120 int_to_key(int key)
121 {
122 return (void *)(uintptr_t)key;
123 }
124
125 static struct v3d_simulator_file *
126 v3d_get_simulator_file_for_fd(int fd)
127 {
128 struct hash_entry *entry = _mesa_hash_table_search(sim_state.fd_map,
129 int_to_key(fd + 1));
130 return entry ? entry->data : NULL;
131 }
132
133 /* A marker placed just after each BO, then checked after rendering to make
134 * sure it's still there.
135 */
136 #define BO_SENTINEL 0xfedcba98
137
138 /* 128kb */
139 #define GMP_ALIGN2 17
140
141 /**
142 * Sets the range of GPU virtual address space to have the given GMP
143 * permissions (bit 0 = read, bit 1 = write, write-only forbidden).
144 */
145 static void
146 set_gmp_flags(struct v3d_simulator_file *file,
147 uint32_t offset, uint32_t size, uint32_t flag)
148 {
149 assert((offset & ((1 << GMP_ALIGN2) - 1)) == 0);
150 int gmp_offset = offset >> GMP_ALIGN2;
151 int gmp_count = align(size, 1 << GMP_ALIGN2) >> GMP_ALIGN2;
152 uint32_t *gmp = file->gmp_vaddr;
153
154 assert(flag <= 0x3);
155
156 for (int i = gmp_offset; i < gmp_offset + gmp_count; i++) {
157 int32_t bitshift = (i % 16) * 2;
158 gmp[i / 16] &= ~(0x3 << bitshift);
159 gmp[i / 16] |= flag << bitshift;
160 }
161 }
162
163 /**
164 * Allocates space in simulator memory and returns a tracking struct for it
165 * that also contains the drm_gem_cma_object struct.
166 */
167 static struct v3d_simulator_bo *
168 v3d_create_simulator_bo(int fd, unsigned size)
169 {
170 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
171 struct v3d_simulator_bo *sim_bo = rzalloc(file,
172 struct v3d_simulator_bo);
173 size = align(size, 4096);
174
175 sim_bo->file = file;
176
177 mtx_lock(&sim_state.mutex);
178 sim_bo->block = u_mmAllocMem(sim_state.heap, size + 4, GMP_ALIGN2, 0);
179 mtx_unlock(&sim_state.mutex);
180 assert(sim_bo->block);
181
182 set_gmp_flags(file, sim_bo->block->ofs, size, 0x3);
183
184 sim_bo->size = size;
185
186 /* Allocate space for the buffer in simulator memory. */
187 sim_bo->sim_vaddr = sim_state.mem + sim_bo->block->ofs - sim_state.mem_base;
188 memset(sim_bo->sim_vaddr, 0xd0, size);
189
190 *(uint32_t *)(sim_bo->sim_vaddr + sim_bo->size) = BO_SENTINEL;
191
192 return sim_bo;
193 }
194
195 static struct v3d_simulator_bo *
196 v3d_create_simulator_bo_for_gem(int fd, int handle, unsigned size)
197 {
198 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
199 struct v3d_simulator_bo *sim_bo =
200 v3d_create_simulator_bo(fd, size);
201
202 sim_bo->handle = handle;
203
204 /* Map the GEM buffer for copy in/out to the simulator. i915 blocks
205 * dumb mmap on render nodes, so use their ioctl directly if we're on
206 * one.
207 */
208 int ret;
209 if (file->is_i915) {
210 struct drm_i915_gem_mmap_gtt map = {
211 .handle = handle,
212 };
213
214 /* We could potentially use non-gtt (cached) for LLC systems,
215 * but the copy-in/out won't be the limiting factor on
216 * simulation anyway.
217 */
218 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &map);
219 sim_bo->mmap_offset = map.offset;
220 } else {
221 struct drm_mode_map_dumb map = {
222 .handle = handle,
223 };
224
225 ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &map);
226 sim_bo->mmap_offset = map.offset;
227 }
228 if (ret) {
229 fprintf(stderr, "Failed to get MMAP offset: %d\n", ret);
230 abort();
231 }
232
233 sim_bo->gem_vaddr = mmap(NULL, sim_bo->size,
234 PROT_READ | PROT_WRITE, MAP_SHARED,
235 fd, sim_bo->mmap_offset);
236 if (sim_bo->gem_vaddr == MAP_FAILED) {
237 fprintf(stderr, "mmap of bo %d (offset 0x%016llx, size %d) failed\n",
238 handle, (long long)sim_bo->mmap_offset, sim_bo->size);
239 abort();
240 }
241
242 /* A handle of 0 is used for v3d_gem.c internal allocations that
243 * don't need to go in the lookup table.
244 */
245 if (handle != 0) {
246 mtx_lock(&sim_state.mutex);
247 _mesa_hash_table_insert(file->bo_map, int_to_key(handle),
248 sim_bo);
249 mtx_unlock(&sim_state.mutex);
250 }
251
252 return sim_bo;
253 }
254
255 static int bin_fd;
256
257 uint32_t
258 v3d_simulator_get_spill(uint32_t spill_size)
259 {
260 struct v3d_simulator_bo *sim_bo =
261 v3d_create_simulator_bo(bin_fd, spill_size);
262
263 util_dynarray_append(&sim_state.bin_oom, struct v3d_simulator_bo *,
264 sim_bo);
265
266 return sim_bo->block->ofs;
267 }
268
269 static void
270 v3d_free_simulator_bo(struct v3d_simulator_bo *sim_bo)
271 {
272 struct v3d_simulator_file *sim_file = sim_bo->file;
273
274 set_gmp_flags(sim_file, sim_bo->block->ofs, sim_bo->size, 0x0);
275
276 if (sim_bo->gem_vaddr)
277 munmap(sim_bo->gem_vaddr, sim_bo->size);
278
279 mtx_lock(&sim_state.mutex);
280 u_mmFreeMem(sim_bo->block);
281 if (sim_bo->handle) {
282 _mesa_hash_table_remove_key(sim_file->bo_map,
283 int_to_key(sim_bo->handle));
284 }
285 mtx_unlock(&sim_state.mutex);
286 ralloc_free(sim_bo);
287 }
288
289 static struct v3d_simulator_bo *
290 v3d_get_simulator_bo(struct v3d_simulator_file *file, int gem_handle)
291 {
292 if (gem_handle == 0)
293 return NULL;
294
295 mtx_lock(&sim_state.mutex);
296 struct hash_entry *entry =
297 _mesa_hash_table_search(file->bo_map, int_to_key(gem_handle));
298 mtx_unlock(&sim_state.mutex);
299
300 return entry ? entry->data : NULL;
301 }
302
303 static void
304 v3d_simulator_copy_in_handle(struct v3d_simulator_file *file, int handle)
305 {
306 struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file, handle);
307
308 if (!sim_bo)
309 return;
310
311 memcpy(sim_bo->sim_vaddr, sim_bo->gem_vaddr, sim_bo->size);
312 }
313
314 static void
315 v3d_simulator_copy_out_handle(struct v3d_simulator_file *file, int handle)
316 {
317 struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file, handle);
318
319 if (!sim_bo)
320 return;
321
322 memcpy(sim_bo->gem_vaddr, sim_bo->sim_vaddr, sim_bo->size);
323
324 if (*(uint32_t *)(sim_bo->sim_vaddr +
325 sim_bo->size) != BO_SENTINEL) {
326 fprintf(stderr, "Buffer overflow in handle %d\n",
327 handle);
328 }
329 }
330
331 static int
332 v3d_simulator_pin_bos(struct v3d_simulator_file *file,
333 struct drm_v3d_submit_cl *submit)
334 {
335 uint32_t *bo_handles = (uint32_t *)(uintptr_t)submit->bo_handles;
336
337 for (int i = 0; i < submit->bo_handle_count; i++)
338 v3d_simulator_copy_in_handle(file, bo_handles[i]);
339
340 return 0;
341 }
342
343 static int
344 v3d_simulator_unpin_bos(struct v3d_simulator_file *file,
345 struct drm_v3d_submit_cl *submit)
346 {
347 uint32_t *bo_handles = (uint32_t *)(uintptr_t)submit->bo_handles;
348
349 for (int i = 0; i < submit->bo_handle_count; i++)
350 v3d_simulator_copy_out_handle(file, bo_handles[i]);
351
352 return 0;
353 }
354
355 static int
356 v3d_simulator_submit_cl_ioctl(int fd, struct drm_v3d_submit_cl *submit)
357 {
358 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
359 int ret;
360
361 ret = v3d_simulator_pin_bos(file, submit);
362 if (ret)
363 return ret;
364
365 mtx_lock(&sim_state.submit_lock);
366 bin_fd = fd;
367 if (sim_state.ver >= 41)
368 v3d41_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs);
369 else
370 v3d33_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs);
371
372 util_dynarray_foreach(&sim_state.bin_oom, struct v3d_simulator_bo *,
373 sim_bo) {
374 v3d_free_simulator_bo(*sim_bo);
375 }
376 util_dynarray_clear(&sim_state.bin_oom);
377
378 mtx_unlock(&sim_state.submit_lock);
379
380 ret = v3d_simulator_unpin_bos(file, submit);
381 if (ret)
382 return ret;
383
384 return 0;
385 }
386
387 /**
388 * Do fixups after a BO has been opened from a handle.
389 *
390 * This could be done at DRM_IOCTL_GEM_OPEN/DRM_IOCTL_GEM_PRIME_FD_TO_HANDLE
391 * time, but we're still using drmPrimeFDToHandle() so we have this helper to
392 * be called afterward instead.
393 */
394 void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size)
395 {
396 v3d_create_simulator_bo_for_gem(fd, handle, size);
397 }
398
399 /**
400 * Simulated ioctl(fd, DRM_VC5_CREATE_BO) implementation.
401 *
402 * Making a VC5 BO is just a matter of making a corresponding BO on the host.
403 */
404 static int
405 v3d_simulator_create_bo_ioctl(int fd, struct drm_v3d_create_bo *args)
406 {
407 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
408
409 /* i915 bans dumb create on render nodes, so we have to use their
410 * native ioctl in case we're on a render node.
411 */
412 int ret;
413 if (file->is_i915) {
414 struct drm_i915_gem_create create = {
415 .size = args->size,
416 };
417 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
418
419 args->handle = create.handle;
420 } else {
421 struct drm_mode_create_dumb create = {
422 .width = 128,
423 .bpp = 8,
424 .height = (args->size + 127) / 128,
425 };
426
427 ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &create);
428 assert(ret != 0 || create.size >= args->size);
429
430 args->handle = create.handle;
431 }
432
433 if (ret == 0) {
434 struct v3d_simulator_bo *sim_bo =
435 v3d_create_simulator_bo_for_gem(fd, args->handle,
436 args->size);
437
438 args->offset = sim_bo->block->ofs;
439 }
440
441 return ret;
442 }
443
444 /**
445 * Simulated ioctl(fd, DRM_VC5_MMAP_BO) implementation.
446 *
447 * We've already grabbed the mmap offset when we created the sim bo, so just
448 * return it.
449 */
450 static int
451 v3d_simulator_mmap_bo_ioctl(int fd, struct drm_v3d_mmap_bo *args)
452 {
453 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
454 struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
455 args->handle);
456
457 args->offset = sim_bo->mmap_offset;
458
459 return 0;
460 }
461
462 static int
463 v3d_simulator_get_bo_offset_ioctl(int fd, struct drm_v3d_get_bo_offset *args)
464 {
465 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
466 struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
467 args->handle);
468
469 args->offset = sim_bo->block->ofs;
470
471 return 0;
472 }
473
474 static int
475 v3d_simulator_gem_close_ioctl(int fd, struct drm_gem_close *args)
476 {
477 /* Free the simulator's internal tracking. */
478 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
479 struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
480 args->handle);
481
482 v3d_free_simulator_bo(sim_bo);
483
484 /* Pass the call on down. */
485 return drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, args);
486 }
487
488 static int
489 v3d_simulator_get_param_ioctl(int fd, struct drm_v3d_get_param *args)
490 {
491 if (sim_state.ver >= 41)
492 return v3d41_simulator_get_param_ioctl(sim_state.v3d, args);
493 else
494 return v3d33_simulator_get_param_ioctl(sim_state.v3d, args);
495 }
496
497 static int
498 v3d_simulator_submit_tfu_ioctl(int fd, struct drm_v3d_submit_tfu *args)
499 {
500 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
501 int ret;
502
503 v3d_simulator_copy_in_handle(file, args->bo_handles[0]);
504 v3d_simulator_copy_in_handle(file, args->bo_handles[1]);
505 v3d_simulator_copy_in_handle(file, args->bo_handles[2]);
506 v3d_simulator_copy_in_handle(file, args->bo_handles[3]);
507
508 if (sim_state.ver >= 41)
509 ret = v3d41_simulator_submit_tfu_ioctl(sim_state.v3d, args);
510 else
511 ret = v3d33_simulator_submit_tfu_ioctl(sim_state.v3d, args);
512
513 v3d_simulator_copy_out_handle(file, args->bo_handles[0]);
514
515 return ret;
516 }
517
518 static int
519 v3d_simulator_submit_csd_ioctl(int fd, struct drm_v3d_submit_csd *args)
520 {
521 struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
522 uint32_t *bo_handles = (uint32_t *)(uintptr_t)args->bo_handles;
523 int ret;
524
525 for (int i = 0; i < args->bo_handle_count; i++)
526 v3d_simulator_copy_in_handle(file, bo_handles[i]);
527
528 if (sim_state.ver >= 41)
529 ret = v3d41_simulator_submit_csd_ioctl(sim_state.v3d, args,
530 file->gmp->ofs);
531 else
532 ret = -1;
533
534 for (int i = 0; i < args->bo_handle_count; i++)
535 v3d_simulator_copy_out_handle(file, bo_handles[i]);
536
537 return ret;
538 }
539
540 int
541 v3d_simulator_ioctl(int fd, unsigned long request, void *args)
542 {
543 switch (request) {
544 case DRM_IOCTL_V3D_SUBMIT_CL:
545 return v3d_simulator_submit_cl_ioctl(fd, args);
546 case DRM_IOCTL_V3D_CREATE_BO:
547 return v3d_simulator_create_bo_ioctl(fd, args);
548 case DRM_IOCTL_V3D_MMAP_BO:
549 return v3d_simulator_mmap_bo_ioctl(fd, args);
550 case DRM_IOCTL_V3D_GET_BO_OFFSET:
551 return v3d_simulator_get_bo_offset_ioctl(fd, args);
552
553 case DRM_IOCTL_V3D_WAIT_BO:
554 /* We do all of the v3d rendering synchronously, so we just
555 * return immediately on the wait ioctls. This ignores any
556 * native rendering to the host BO, so it does mean we race on
557 * front buffer rendering.
558 */
559 return 0;
560
561 case DRM_IOCTL_V3D_GET_PARAM:
562 return v3d_simulator_get_param_ioctl(fd, args);
563
564 case DRM_IOCTL_GEM_CLOSE:
565 return v3d_simulator_gem_close_ioctl(fd, args);
566
567 case DRM_IOCTL_V3D_SUBMIT_TFU:
568 return v3d_simulator_submit_tfu_ioctl(fd, args);
569
570 case DRM_IOCTL_V3D_SUBMIT_CSD:
571 return v3d_simulator_submit_csd_ioctl(fd, args);
572
573 case DRM_IOCTL_GEM_OPEN:
574 case DRM_IOCTL_GEM_FLINK:
575 return drmIoctl(fd, request, args);
576 default:
577 fprintf(stderr, "Unknown ioctl 0x%08x\n", (int)request);
578 abort();
579 }
580 }
581
582 static void
583 v3d_simulator_init_global(const struct v3d_device_info *devinfo)
584 {
585 mtx_lock(&sim_state.mutex);
586 if (sim_state.refcount++) {
587 mtx_unlock(&sim_state.mutex);
588 return;
589 }
590
591 sim_state.v3d = v3d_hw_auto_new(NULL);
592 v3d_hw_alloc_mem(sim_state.v3d, 1024 * 1024 * 1024);
593 sim_state.mem_base =
594 v3d_hw_get_mem(sim_state.v3d, &sim_state.mem_size,
595 &sim_state.mem);
596
597 /* Allocate from anywhere from 4096 up. We don't allocate at 0,
598 * because for OQs and some other addresses in the HW, 0 means
599 * disabled.
600 */
601 sim_state.heap = u_mmInit(4096, sim_state.mem_size - 4096);
602
603 /* Make a block of 0xd0 at address 0 to make sure we don't screw up
604 * and land there.
605 */
606 struct mem_block *b = u_mmAllocMem(sim_state.heap, 4096, GMP_ALIGN2, 0);
607 memset(sim_state.mem + b->ofs - sim_state.mem_base, 0xd0, 4096);
608
609 sim_state.ver = v3d_hw_get_version(sim_state.v3d);
610
611 mtx_unlock(&sim_state.mutex);
612
613 sim_state.fd_map =
614 _mesa_hash_table_create(NULL,
615 _mesa_hash_pointer,
616 _mesa_key_pointer_equal);
617
618 util_dynarray_init(&sim_state.bin_oom, NULL);
619
620 if (sim_state.ver >= 41)
621 v3d41_simulator_init_regs(sim_state.v3d);
622 else
623 v3d33_simulator_init_regs(sim_state.v3d);
624 }
625
626 void
627 v3d_simulator_init(struct v3d_screen *screen)
628 {
629 v3d_simulator_init_global(&screen->devinfo);
630
631 screen->sim_file = rzalloc(screen, struct v3d_simulator_file);
632 struct v3d_simulator_file *sim_file = screen->sim_file;
633
634 drmVersionPtr version = drmGetVersion(screen->fd);
635 if (version && strncmp(version->name, "i915", version->name_len) == 0)
636 sim_file->is_i915 = true;
637 drmFreeVersion(version);
638
639 screen->sim_file->bo_map =
640 _mesa_hash_table_create(screen->sim_file,
641 _mesa_hash_pointer,
642 _mesa_key_pointer_equal);
643
644 mtx_lock(&sim_state.mutex);
645 _mesa_hash_table_insert(sim_state.fd_map, int_to_key(screen->fd + 1),
646 screen->sim_file);
647 mtx_unlock(&sim_state.mutex);
648
649 sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0);
650 sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs -
651 sim_state.mem_base);
652 memset(sim_file->gmp_vaddr, 0, 8096);
653 }
654
655 void
656 v3d_simulator_destroy(struct v3d_screen *screen)
657 {
658 mtx_lock(&sim_state.mutex);
659 if (!--sim_state.refcount) {
660 _mesa_hash_table_destroy(sim_state.fd_map, NULL);
661 util_dynarray_fini(&sim_state.bin_oom);
662 u_mmDestroy(sim_state.heap);
663 /* No memsetting the struct, because it contains the mutex. */
664 sim_state.mem = NULL;
665 }
666 mtx_unlock(&sim_state.mutex);
667 }
668
669 #endif /* USE_V3D_SIMULATOR */