2 * Copyright © 2014 Broadcom
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:
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
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
25 * @file vc4_simulator.c
27 * Implements VC4 simulation on top of a non-VC4 GEM fd.
29 * This file's goal is to emulate the VC4 ioctls' behavior in the kernel on
30 * top of the simpenrose software simulator. Generally, VC4 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.
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).
42 * Another limitation is that BO import doesn't work unless the underlying
43 * window system's BO size matches what VC4 is going to use, which of course
44 * doesn't work out in practice. This means that for now, only DRI3 (VC4
45 * makes the winsys BOs) is supported, not DRI2 (window system makes the winys
49 #ifdef USE_VC4_SIMULATOR
53 #include "util/u_memory.h"
54 #include "util/u_mm.h"
55 #include "util/ralloc.h"
57 #include "vc4_screen.h"
58 #include "vc4_context.h"
59 #include "kernel/vc4_drv.h"
60 #include "vc4_simulator_validate.h"
61 #include "simpenrose/simpenrose.h"
63 /** Global (across GEM fds) state for the simulator */
64 static struct vc4_simulator_state
{
69 struct mem_block
*heap
;
70 struct mem_block
*overflow
;
72 /** Mapping from GEM handle to struct vc4_simulator_bo * */
73 struct hash_table
*fd_map
;
77 .mutex
= _MTX_INITIALIZER_NP
,
80 /** Per-GEM-fd state for the simulator. */
81 struct vc4_simulator_file
{
84 /* This is weird -- we make a "vc4_device" per file, even though on
85 * the kernel side this is a global. We do this so that kernel code
86 * calling us for BO allocation can get to our screen.
88 struct drm_device dev
;
90 /** Mapping from GEM handle to struct vc4_simulator_bo * */
91 struct hash_table
*bo_map
;
94 /** Wrapper for drm_vc4_bo tracking the simulator-specific state. */
95 struct vc4_simulator_bo
{
96 struct drm_vc4_bo base
;
97 struct vc4_simulator_file
*file
;
99 /** Area for this BO within sim_state->mem */
100 struct mem_block
*block
;
102 uint32_t winsys_stride
;
110 return (void *)(uintptr_t)key
;
113 static struct vc4_simulator_file
*
114 vc4_get_simulator_file_for_fd(int fd
)
116 struct hash_entry
*entry
= _mesa_hash_table_search(sim_state
.fd_map
,
118 return entry
? entry
->data
: NULL
;
121 /* A marker placed just after each BO, then checked after rendering to make
122 * sure it's still there.
124 #define BO_SENTINEL 0xfedcba98
126 #define PAGE_ALIGN2 12
129 * Allocates space in simulator memory and returns a tracking struct for it
130 * that also contains the drm_gem_cma_object struct.
132 static struct vc4_simulator_bo
*
133 vc4_create_simulator_bo(int fd
, int handle
, unsigned size
)
135 struct vc4_simulator_file
*file
= vc4_get_simulator_file_for_fd(fd
);
136 struct vc4_simulator_bo
*sim_bo
= rzalloc(file
,
137 struct vc4_simulator_bo
);
138 struct drm_vc4_bo
*bo
= &sim_bo
->base
;
139 struct drm_gem_cma_object
*obj
= &bo
->base
;
140 size
= align(size
, 4096);
143 sim_bo
->handle
= handle
;
145 mtx_lock(&sim_state
.mutex
);
146 sim_bo
->block
= u_mmAllocMem(sim_state
.heap
, size
+ 4, PAGE_ALIGN2
, 0);
147 mtx_unlock(&sim_state
.mutex
);
148 assert(sim_bo
->block
);
150 obj
->base
.size
= size
;
151 obj
->base
.dev
= &file
->dev
;
152 obj
->vaddr
= sim_state
.mem
+ sim_bo
->block
->ofs
;
153 obj
->paddr
= simpenrose_hw_addr(obj
->vaddr
);
155 *(uint32_t *)(obj
->vaddr
+ size
) = BO_SENTINEL
;
157 /* A handle of 0 is used for vc4_gem.c internal allocations that
158 * don't need to go in the lookup table.
161 mtx_lock(&sim_state
.mutex
);
162 _mesa_hash_table_insert(file
->bo_map
, int_to_key(handle
), bo
);
163 mtx_unlock(&sim_state
.mutex
);
170 vc4_free_simulator_bo(struct vc4_simulator_bo
*sim_bo
)
172 struct vc4_simulator_file
*sim_file
= sim_bo
->file
;
173 struct drm_vc4_bo
*bo
= &sim_bo
->base
;
174 struct drm_gem_cma_object
*obj
= &bo
->base
;
176 if (sim_bo
->winsys_map
)
177 munmap(sim_bo
->winsys_map
, obj
->base
.size
);
179 mtx_lock(&sim_state
.mutex
);
180 u_mmFreeMem(sim_bo
->block
);
181 if (sim_bo
->handle
) {
182 struct hash_entry
*entry
=
183 _mesa_hash_table_search(sim_file
->bo_map
,
184 int_to_key(sim_bo
->handle
));
185 _mesa_hash_table_remove(sim_file
->bo_map
, entry
);
187 mtx_unlock(&sim_state
.mutex
);
191 static struct vc4_simulator_bo
*
192 vc4_get_simulator_bo(struct vc4_simulator_file
*file
, int gem_handle
)
194 mtx_lock(&sim_state
.mutex
);
195 struct hash_entry
*entry
=
196 _mesa_hash_table_search(file
->bo_map
, int_to_key(gem_handle
));
197 mtx_unlock(&sim_state
.mutex
);
199 return entry
? entry
->data
: NULL
;
202 struct drm_gem_cma_object
*
203 drm_gem_cma_create(struct drm_device
*dev
, size_t size
)
205 struct vc4_screen
*screen
= dev
->screen
;
206 struct vc4_simulator_bo
*sim_bo
= vc4_create_simulator_bo(screen
->fd
,
208 return &sim_bo
->base
.base
;
212 vc4_simulator_pin_bos(struct drm_device
*dev
, struct vc4_job
*job
,
213 struct vc4_exec_info
*exec
)
215 int fd
= dev
->screen
->fd
;
216 struct vc4_simulator_file
*file
= vc4_get_simulator_file_for_fd(fd
);
217 struct drm_vc4_submit_cl
*args
= exec
->args
;
218 struct vc4_bo
**bos
= job
->bo_pointers
.base
;
220 exec
->bo_count
= args
->bo_handle_count
;
221 exec
->bo
= calloc(exec
->bo_count
, sizeof(void *));
222 for (int i
= 0; i
< exec
->bo_count
; i
++) {
223 struct vc4_bo
*bo
= bos
[i
];
224 struct vc4_simulator_bo
*sim_bo
=
225 vc4_get_simulator_bo(file
, bo
->handle
);
226 struct drm_vc4_bo
*drm_bo
= &sim_bo
->base
;
227 struct drm_gem_cma_object
*obj
= &drm_bo
->base
;
231 fprintf(stderr
, "bo hindex %d: %s\n", i
, bo
->name
);
235 memcpy(obj
->vaddr
, bo
->map
, bo
->size
);
239 /* The kernel does this validation at shader create ioctl
242 if (strcmp(bo
->name
, "code") == 0) {
243 drm_bo
->validated_shader
= vc4_validate_shader(obj
);
244 if (!drm_bo
->validated_shader
)
252 vc4_simulator_unpin_bos(struct vc4_exec_info
*exec
)
254 for (int i
= 0; i
< exec
->bo_count
; i
++) {
255 struct drm_gem_cma_object
*obj
= exec
->bo
[i
];
256 struct drm_vc4_bo
*drm_bo
= to_vc4_bo(&obj
->base
);
257 struct vc4_bo
*bo
= drm_bo
->bo
;
259 assert(*(uint32_t *)(obj
->vaddr
+
260 obj
->base
.size
) == BO_SENTINEL
);
261 memcpy(bo
->map
, obj
->vaddr
, bo
->size
);
263 if (drm_bo
->validated_shader
) {
264 free(drm_bo
->validated_shader
->texture_samples
);
265 free(drm_bo
->validated_shader
);
275 vc4_dump_to_file(struct vc4_exec_info
*exec
)
277 static int dumpno
= 0;
278 struct drm_vc4_get_hang_state
*state
;
279 struct drm_vc4_get_hang_state_bo
*bo_state
;
280 unsigned int dump_version
= 0;
282 if (!(vc4_debug
& VC4_DEBUG_DUMP
))
285 state
= calloc(1, sizeof(*state
));
288 list_for_each_entry_safe(struct drm_vc4_bo
, bo
, &exec
->unref_list
,
293 /* Add one more for the overflow area that isn't wrapped in a BO. */
294 state
->bo_count
= exec
->bo_count
+ unref_count
+ 1;
295 bo_state
= calloc(state
->bo_count
, sizeof(*bo_state
));
297 char *filename
= NULL
;
298 asprintf(&filename
, "vc4-dri-%d.dump", dumpno
++);
299 FILE *f
= fopen(filename
, "w+");
301 fprintf(stderr
, "Couldn't open %s: %s", filename
,
306 fwrite(&dump_version
, sizeof(dump_version
), 1, f
);
308 state
->ct0ca
= exec
->ct0ca
;
309 state
->ct0ea
= exec
->ct0ea
;
310 state
->ct1ca
= exec
->ct1ca
;
311 state
->ct1ea
= exec
->ct1ea
;
312 state
->start_bin
= exec
->ct0ca
;
313 state
->start_render
= exec
->ct1ca
;
314 fwrite(state
, sizeof(*state
), 1, f
);
317 for (i
= 0; i
< exec
->bo_count
; i
++) {
318 struct drm_gem_cma_object
*cma_bo
= exec
->bo
[i
];
319 bo_state
[i
].handle
= i
; /* Not used by the parser. */
320 bo_state
[i
].paddr
= cma_bo
->paddr
;
321 bo_state
[i
].size
= cma_bo
->base
.size
;
324 list_for_each_entry_safe(struct drm_vc4_bo
, bo
, &exec
->unref_list
,
326 struct drm_gem_cma_object
*cma_bo
= &bo
->base
;
327 bo_state
[i
].handle
= 0;
328 bo_state
[i
].paddr
= cma_bo
->paddr
;
329 bo_state
[i
].size
= cma_bo
->base
.size
;
333 /* Add the static overflow memory area. */
334 bo_state
[i
].handle
= exec
->bo_count
;
335 bo_state
[i
].paddr
= sim_state
.overflow
->ofs
;
336 bo_state
[i
].size
= sim_state
.overflow
->size
;
339 fwrite(bo_state
, sizeof(*bo_state
), state
->bo_count
, f
);
341 for (int i
= 0; i
< exec
->bo_count
; i
++) {
342 struct drm_gem_cma_object
*cma_bo
= exec
->bo
[i
];
343 fwrite(cma_bo
->vaddr
, cma_bo
->base
.size
, 1, f
);
346 list_for_each_entry_safe(struct drm_vc4_bo
, bo
, &exec
->unref_list
,
348 struct drm_gem_cma_object
*cma_bo
= &bo
->base
;
349 fwrite(cma_bo
->vaddr
, cma_bo
->base
.size
, 1, f
);
352 void *overflow
= calloc(1, sim_state
.overflow
->size
);
353 fwrite(overflow
, 1, sim_state
.overflow
->size
, f
);
362 vc4_simulator_flush(struct vc4_context
*vc4
,
363 struct drm_vc4_submit_cl
*args
, struct vc4_job
*job
)
365 struct vc4_screen
*screen
= vc4
->screen
;
367 struct vc4_simulator_file
*file
= vc4_get_simulator_file_for_fd(fd
);
368 struct vc4_surface
*csurf
= vc4_surface(vc4
->framebuffer
.cbufs
[0]);
369 struct vc4_resource
*ctex
= csurf
? vc4_resource(csurf
->base
.texture
) : NULL
;
370 struct vc4_simulator_bo
*csim_bo
= ctex
? vc4_get_simulator_bo(file
, ctex
->bo
->handle
) : NULL
;
371 uint32_t winsys_stride
= ctex
? csim_bo
->winsys_stride
: 0;
372 uint32_t sim_stride
= ctex
? ctex
->slices
[0].stride
: 0;
373 uint32_t row_len
= MIN2(sim_stride
, winsys_stride
);
374 struct vc4_exec_info exec
;
375 struct drm_device
*dev
= &file
->dev
;
378 memset(&exec
, 0, sizeof(exec
));
379 list_inithead(&exec
.unref_list
);
381 if (ctex
&& csim_bo
->winsys_map
) {
383 fprintf(stderr
, "%dx%d %d %d %d\n",
384 ctex
->base
.b
.width0
, ctex
->base
.b
.height0
,
390 for (int y
= 0; y
< ctex
->base
.b
.height0
; y
++) {
391 memcpy(ctex
->bo
->map
+ y
* sim_stride
,
392 csim_bo
->winsys_map
+ y
* winsys_stride
,
399 ret
= vc4_simulator_pin_bos(dev
, job
, &exec
);
403 ret
= vc4_cl_validate(dev
, &exec
);
407 if (vc4_debug
& VC4_DEBUG_CL
) {
408 fprintf(stderr
, "RCL:\n");
409 vc4_dump_cl(sim_state
.mem
+ exec
.ct1ca
,
410 exec
.ct1ea
- exec
.ct1ca
, true);
413 vc4_dump_to_file(&exec
);
415 if (exec
.ct0ca
!= exec
.ct0ea
) {
416 int bfc
= simpenrose_do_binning(exec
.ct0ca
, exec
.ct0ea
);
418 fprintf(stderr
, "Binning returned %d flushes, should be 1.\n",
420 fprintf(stderr
, "Relocated binning command list:\n");
421 vc4_dump_cl(sim_state
.mem
+ exec
.ct0ca
,
422 exec
.ct0ea
- exec
.ct0ca
, false);
426 int rfc
= simpenrose_do_rendering(exec
.ct1ca
, exec
.ct1ea
);
428 fprintf(stderr
, "Rendering returned %d frames, should be 1.\n",
430 fprintf(stderr
, "Relocated render command list:\n");
431 vc4_dump_cl(sim_state
.mem
+ exec
.ct1ca
,
432 exec
.ct1ea
- exec
.ct1ca
, true);
436 ret
= vc4_simulator_unpin_bos(&exec
);
440 list_for_each_entry_safe(struct drm_vc4_bo
, bo
, &exec
.unref_list
,
442 struct vc4_simulator_bo
*sim_bo
= (struct vc4_simulator_bo
*)bo
;
443 struct drm_gem_cma_object
*obj
= &sim_bo
->base
.base
;
444 list_del(&bo
->unref_head
);
445 assert(*(uint32_t *)(obj
->vaddr
+ obj
->base
.size
) ==
447 vc4_free_simulator_bo(sim_bo
);
450 if (ctex
&& csim_bo
->winsys_map
) {
451 for (int y
= 0; y
< ctex
->base
.b
.height0
; y
++) {
452 memcpy(csim_bo
->winsys_map
+ y
* winsys_stride
,
453 ctex
->bo
->map
+ y
* sim_stride
,
462 * Map the underlying GEM object from the real hardware GEM handle.
465 vc4_simulator_map_winsys_bo(int fd
, struct vc4_simulator_bo
*sim_bo
)
467 struct drm_vc4_bo
*bo
= &sim_bo
->base
;
468 struct drm_gem_cma_object
*obj
= &bo
->base
;
472 struct drm_mode_map_dumb map_dumb
= {
473 .handle
= sim_bo
->handle
,
475 ret
= drmIoctl(fd
, DRM_IOCTL_MODE_MAP_DUMB
, &map_dumb
);
477 fprintf(stderr
, "map ioctl failure\n");
481 map
= mmap(NULL
, obj
->base
.size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
482 fd
, map_dumb
.offset
);
483 if (map
== MAP_FAILED
) {
485 "mmap of bo %d (offset 0x%016llx, size %d) failed\n",
486 sim_bo
->handle
, (long long)map_dumb
.offset
,
487 (int)obj
->base
.size
);
495 * Do fixups after a BO has been opened from a handle.
497 * This could be done at DRM_IOCTL_GEM_OPEN/DRM_IOCTL_GEM_PRIME_FD_TO_HANDLE
498 * time, but we're still using drmPrimeFDToHandle() so we have this helper to
499 * be called afterward instead.
501 void vc4_simulator_open_from_handle(int fd
, uint32_t winsys_stride
,
502 int handle
, uint32_t size
)
504 struct vc4_simulator_bo
*sim_bo
=
505 vc4_create_simulator_bo(fd
, handle
, size
);
507 sim_bo
->winsys_stride
= winsys_stride
;
508 sim_bo
->winsys_map
= vc4_simulator_map_winsys_bo(fd
, sim_bo
);
512 * Simulated ioctl(fd, DRM_VC4_CREATE_BO) implementation.
514 * Making a VC4 BO is just a matter of making a corresponding BO on the host.
517 vc4_simulator_create_bo_ioctl(int fd
, struct drm_vc4_create_bo
*args
)
520 struct drm_mode_create_dumb create
= {
523 .height
= (args
->size
+ 127) / 128,
526 ret
= drmIoctl(fd
, DRM_IOCTL_MODE_CREATE_DUMB
, &create
);
527 assert(create
.size
>= args
->size
);
529 args
->handle
= create
.handle
;
531 vc4_create_simulator_bo(fd
, create
.handle
, args
->size
);
537 * Simulated ioctl(fd, DRM_VC4_CREATE_SHADER_BO) implementation.
539 * In simulation we defer shader validation until exec time. Just make a host
540 * BO and memcpy the contents in.
543 vc4_simulator_create_shader_bo_ioctl(int fd
,
544 struct drm_vc4_create_shader_bo
*args
)
547 struct drm_mode_create_dumb create
= {
550 .height
= (args
->size
+ 127) / 128,
553 ret
= drmIoctl(fd
, DRM_IOCTL_MODE_CREATE_DUMB
, &create
);
556 assert(create
.size
>= args
->size
);
558 args
->handle
= create
.handle
;
560 vc4_create_simulator_bo(fd
, create
.handle
, args
->size
);
562 struct drm_mode_map_dumb map
= {
563 .handle
= create
.handle
565 ret
= drmIoctl(fd
, DRM_IOCTL_MODE_MAP_DUMB
, &map
);
569 void *shader
= mmap(NULL
, args
->size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
571 memcpy(shader
, (void *)(uintptr_t)args
->data
, args
->size
);
572 munmap(shader
, args
->size
);
578 * Simulated ioctl(fd, DRM_VC4_MMAP_BO) implementation.
580 * We just pass this straight through to dumb mmap.
583 vc4_simulator_mmap_bo_ioctl(int fd
, struct drm_vc4_mmap_bo
*args
)
586 struct drm_mode_map_dumb map
= {
587 .handle
= args
->handle
,
590 ret
= drmIoctl(fd
, DRM_IOCTL_MODE_MAP_DUMB
, &map
);
591 args
->offset
= map
.offset
;
597 vc4_simulator_gem_close_ioctl(int fd
, struct drm_gem_close
*args
)
599 /* Free the simulator's internal tracking. */
600 struct vc4_simulator_file
*file
= vc4_get_simulator_file_for_fd(fd
);
601 struct vc4_simulator_bo
*sim_bo
= vc4_get_simulator_bo(file
,
604 vc4_free_simulator_bo(sim_bo
);
606 /* Pass the call on down. */
607 return drmIoctl(fd
, DRM_IOCTL_GEM_CLOSE
, args
);
611 vc4_simulator_get_param_ioctl(int fd
, struct drm_vc4_get_param
*args
)
613 switch (args
->param
) {
614 case DRM_VC4_PARAM_SUPPORTS_BRANCHES
:
615 case DRM_VC4_PARAM_SUPPORTS_ETC1
:
616 case DRM_VC4_PARAM_SUPPORTS_THREADED_FS
:
620 case DRM_VC4_PARAM_V3D_IDENT0
:
621 args
->value
= 0x02000000;
624 case DRM_VC4_PARAM_V3D_IDENT1
:
625 args
->value
= 0x00000001;
629 fprintf(stderr
, "Unknown DRM_IOCTL_VC4_GET_PARAM(%lld)\n",
630 (long long)args
->param
);
636 vc4_simulator_ioctl(int fd
, unsigned long request
, void *args
)
639 case DRM_IOCTL_VC4_CREATE_BO
:
640 return vc4_simulator_create_bo_ioctl(fd
, args
);
641 case DRM_IOCTL_VC4_CREATE_SHADER_BO
:
642 return vc4_simulator_create_shader_bo_ioctl(fd
, args
);
643 case DRM_IOCTL_VC4_MMAP_BO
:
644 return vc4_simulator_mmap_bo_ioctl(fd
, args
);
646 case DRM_IOCTL_VC4_WAIT_BO
:
647 case DRM_IOCTL_VC4_WAIT_SEQNO
:
648 /* We do all of the vc4 rendering synchronously, so we just
649 * return immediately on the wait ioctls. This ignores any
650 * native rendering to the host BO, so it does mean we race on
651 * front buffer rendering.
655 case DRM_IOCTL_VC4_GET_PARAM
:
656 return vc4_simulator_get_param_ioctl(fd
, args
);
658 case DRM_IOCTL_GEM_CLOSE
:
659 return vc4_simulator_gem_close_ioctl(fd
, args
);
661 case DRM_IOCTL_GEM_OPEN
:
662 case DRM_IOCTL_GEM_FLINK
:
663 return drmIoctl(fd
, request
, args
);
665 fprintf(stderr
, "Unknown ioctl 0x%08x\n", (int)request
);
671 vc4_simulator_init_global(void)
673 mtx_lock(&sim_state
.mutex
);
674 if (sim_state
.refcount
++) {
675 mtx_unlock(&sim_state
.mutex
);
679 sim_state
.mem_size
= 256 * 1024 * 1024;
680 sim_state
.mem
= calloc(sim_state
.mem_size
, 1);
683 sim_state
.heap
= u_mmInit(0, sim_state
.mem_size
);
685 /* We supply our own memory so that we can have more aperture
686 * available (256MB instead of simpenrose's default 64MB).
688 simpenrose_init_hardware_supply_mem(sim_state
.mem
, sim_state
.mem_size
);
690 /* Carve out low memory for tile allocation overflow. The kernel
691 * should be automatically handling overflow memory setup on real
692 * hardware, but for simulation we just get one shot to set up enough
693 * overflow memory before execution. This overflow mem will be used
694 * up over the whole lifetime of simpenrose (not reused on each
695 * flush), so it had better be big.
697 sim_state
.overflow
= u_mmAllocMem(sim_state
.heap
, 32 * 1024 * 1024,
699 simpenrose_supply_overflow_mem(sim_state
.overflow
->ofs
,
700 sim_state
.overflow
->size
);
702 mtx_unlock(&sim_state
.mutex
);
705 _mesa_hash_table_create(NULL
,
707 _mesa_key_pointer_equal
);
711 vc4_simulator_init(struct vc4_screen
*screen
)
713 vc4_simulator_init_global();
715 screen
->sim_file
= rzalloc(screen
, struct vc4_simulator_file
);
717 screen
->sim_file
->bo_map
=
718 _mesa_hash_table_create(screen
->sim_file
,
720 _mesa_key_pointer_equal
);
722 mtx_lock(&sim_state
.mutex
);
723 _mesa_hash_table_insert(sim_state
.fd_map
, int_to_key(screen
->fd
+ 1),
725 mtx_unlock(&sim_state
.mutex
);
727 screen
->sim_file
->dev
.screen
= screen
;
731 vc4_simulator_destroy(struct vc4_screen
*screen
)
733 mtx_lock(&sim_state
.mutex
);
734 if (!--sim_state
.refcount
) {
735 _mesa_hash_table_destroy(sim_state
.fd_map
, NULL
);
736 u_mmDestroy(sim_state
.heap
);
738 /* No memsetting it, because it contains the mutex. */
740 mtx_unlock(&sim_state
.mutex
);
743 #endif /* USE_VC4_SIMULATOR */