Mesa (master): v3d: moving v3d simulator to src/broadcom

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jun 27 00:20:36 UTC 2020


Module: Mesa
Branch: master
Commit: 583d7d3d8d0d14d636340b0f12f72db7b0148ceb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=583d7d3d8d0d14d636340b0f12f72db7b0148ceb

Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date:   Fri Nov 29 11:17:18 2019 +0100

v3d: moving v3d simulator to src/broadcom

So it could be used by both the OpenGL and the Vulkan driver.

In addition to the move, some small changes were needed to be made on
the API. For example, the simulator was receiving v3d_screen on
initialization, and that code setted v3d_screen->sim_file. Now it
returns the new sim_file created.

Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5666>

---

 src/broadcom/drm-shim/meson.build                  |  6 +--
 src/broadcom/meson.build                           |  1 +
 src/broadcom/simulator/meson.build                 | 63 ++++++++++++++++++++++
 .../v3d => broadcom/simulator}/v3d_simulator.c     | 37 +++++++------
 src/broadcom/simulator/v3d_simulator.h             | 55 +++++++++++++++++++
 .../simulator}/v3d_simulator_wrapper.cpp           |  0
 .../simulator}/v3d_simulator_wrapper.h             |  0
 .../v3d => broadcom/simulator}/v3dx_simulator.c    | 12 +++--
 src/broadcom/simulator/v3dx_simulator.h            | 46 ++++++++++++++++
 src/gallium/drivers/v3d/meson.build                |  5 +-
 src/gallium/drivers/v3d/v3d_context.h              |  8 +--
 src/gallium/drivers/v3d/v3d_screen.c               |  4 +-
 src/gallium/drivers/v3d/v3dx_context.h             | 11 ----
 13 files changed, 204 insertions(+), 44 deletions(-)

diff --git a/src/broadcom/drm-shim/meson.build b/src/broadcom/drm-shim/meson.build
index ab474b648ee..cbad07067c1 100644
--- a/src/broadcom/drm-shim/meson.build
+++ b/src/broadcom/drm-shim/meson.build
@@ -41,7 +41,7 @@ if dep_v3dv3.found()
                             'v3dx.c',
                             v3d_xml_pack
         ],
-        include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_gallium_v3d],
+        include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_gallium_v3d, inc_simulator],
         c_args : [no_override_init_args, '-DV3D_VERSION=' + ver, v3dv3_c_args],
         gnu_symbol_visibility : 'hidden',
         dependencies: [dep_valgrind, dep_thread, dep_v3dv3],
@@ -52,11 +52,11 @@ if dep_v3dv3.found()
     ['v3d_drm_shim'],
     [
       'v3d.c',
-      '../../gallium/drivers/v3d/v3d_simulator_wrapper.cpp',
+      '../simulator/v3d_simulator_wrapper.cpp',
     ],
     dependencies: [idep_mesautil, dep_dl, dep_drm_shim, dep_v3dv3],
     link_with: per_version_libs,
-    include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_gallium_v3d],
+    include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_gallium_v3d, inc_simulator],
     c_args : [no_override_init_args, '-std=gnu99', v3dv3_c_args],
     gnu_symbol_visibility : 'hidden',
     cpp_args : [v3dv3_c_args]
diff --git a/src/broadcom/meson.build b/src/broadcom/meson.build
index 15177c5f99c..70406b2f1fb 100644
--- a/src/broadcom/meson.build
+++ b/src/broadcom/meson.build
@@ -28,6 +28,7 @@ v3d_libs = []
 if with_gallium_v3d
   subdir('compiler')
   subdir('qpu')
+  subdir('simulator')
 endif
 
 if with_tools.contains('drm-shim')
diff --git a/src/broadcom/simulator/meson.build b/src/broadcom/simulator/meson.build
new file mode 100644
index 00000000000..51f311bb094
--- /dev/null
+++ b/src/broadcom/simulator/meson.build
@@ -0,0 +1,63 @@
+# Copyright © 2019 Raspberry Pi
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+inc_simulator = include_directories('.')
+
+libbroadcom_simulator_files = files(
+  'v3d_simulator.c',
+  'v3d_simulator_wrapper.cpp',
+)
+
+files_per_version = files(
+    'v3dx_simulator.c',
+)
+
+v3d_args = []
+dep_v3dv3 = dependency('v3dv3', required: false)
+if dep_v3dv3.found()
+  v3d_args += '-DUSE_V3D_SIMULATOR'
+endif
+
+per_version_libs = []
+foreach ver : v3d_versions
+  per_version_libs += static_library(
+    'v3d-simulator-v' + ver,
+    [files_per_version, v3d_xml_pack],
+    include_directories : [
+      inc_src, inc_include, inc_gallium_aux, inc_broadcom,
+    ],
+    c_args : [v3d_args, '-DV3D_VERSION=' + ver],
+    gnu_symbol_visibility: 'hidden',
+    dependencies : [dep_v3dv3, dep_libdrm, dep_valgrind],
+)
+endforeach
+
+libbroadcom_simulator = static_library(
+  'broadcom_simulator',
+  [libbroadcom_simulator_files],
+  include_directories : [inc_src, inc_include, inc_gallium, inc_gallium_aux],
+  c_args : [v3d_args, no_override_init_args],
+  cpp_args : [v3d_args],
+  gnu_symbol_visibility : 'hidden', 
+  dependencies : [dep_v3dv3, dep_libdrm, dep_valgrind],
+  link_with : [per_version_libs],
+  build_by_default : false,
+)
+
+v3d_libs += libbroadcom_simulator
diff --git a/src/gallium/drivers/v3d/v3d_simulator.c b/src/broadcom/simulator/v3d_simulator.c
similarity index 96%
rename from src/gallium/drivers/v3d/v3d_simulator.c
rename to src/broadcom/simulator/v3d_simulator.c
index 7b6709887dc..c5d81208d9a 100644
--- a/src/gallium/drivers/v3d/v3d_simulator.c
+++ b/src/broadcom/simulator/v3d_simulator.c
@@ -48,18 +48,23 @@
 
 #ifdef USE_V3D_SIMULATOR
 
+#include <stdio.h>
 #include <sys/mman.h>
+#include "c11/threads.h"
 #include "util/hash_table.h"
 #include "util/ralloc.h"
 #include "util/set.h"
 #include "util/u_dynarray.h"
 #include "util/u_memory.h"
 #include "util/u_mm.h"
+#include "util/u_math.h"
+
+#include <xf86drm.h>
 #include "drm-uapi/i915_drm.h"
-#include "v3d_simulator_wrapper.h"
+#include "drm-uapi/v3d_drm.h"
 
-#include "v3d_screen.h"
-#include "v3d_context.h"
+#include "v3d_simulator.h"
+#include "v3d_simulator_wrapper.h"
 
 /** Global (across GEM fds) state for the simulator */
 static struct v3d_simulator_state {
@@ -580,7 +585,7 @@ v3d_simulator_ioctl(int fd, unsigned long request, void *args)
 }
 
 static void
-v3d_simulator_init_global(const struct v3d_device_info *devinfo)
+v3d_simulator_init_global()
 {
         mtx_lock(&sim_state.mutex);
         if (sim_state.refcount++) {
@@ -623,37 +628,38 @@ v3d_simulator_init_global(const struct v3d_device_info *devinfo)
                 v3d33_simulator_init_regs(sim_state.v3d);
 }
 
-void
-v3d_simulator_init(struct v3d_screen *screen)
+struct v3d_simulator_file *
+v3d_simulator_init(int fd)
 {
-        v3d_simulator_init_global(&screen->devinfo);
+        v3d_simulator_init_global();
 
-        screen->sim_file = rzalloc(screen, struct v3d_simulator_file);
-        struct v3d_simulator_file *sim_file = screen->sim_file;
+        struct v3d_simulator_file *sim_file = rzalloc(NULL, struct v3d_simulator_file);
 
-        drmVersionPtr version = drmGetVersion(screen->fd);
+        drmVersionPtr version = drmGetVersion(fd);
         if (version && strncmp(version->name, "i915", version->name_len) == 0)
                 sim_file->is_i915 = true;
         drmFreeVersion(version);
 
-        screen->sim_file->bo_map =
-                _mesa_hash_table_create(screen->sim_file,
+        sim_file->bo_map =
+                _mesa_hash_table_create(sim_file,
                                         _mesa_hash_pointer,
                                         _mesa_key_pointer_equal);
 
         mtx_lock(&sim_state.mutex);
-        _mesa_hash_table_insert(sim_state.fd_map, int_to_key(screen->fd + 1),
-                                screen->sim_file);
+        _mesa_hash_table_insert(sim_state.fd_map, int_to_key(fd + 1),
+                                sim_file);
         mtx_unlock(&sim_state.mutex);
 
         sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0);
         sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs -
                                sim_state.mem_base);
         memset(sim_file->gmp_vaddr, 0, 8096);
+
+        return sim_file;
 }
 
 void
-v3d_simulator_destroy(struct v3d_screen *screen)
+v3d_simulator_destroy(struct v3d_simulator_file *sim_file)
 {
         mtx_lock(&sim_state.mutex);
         if (!--sim_state.refcount) {
@@ -664,6 +670,7 @@ v3d_simulator_destroy(struct v3d_screen *screen)
                 sim_state.mem = NULL;
         }
         mtx_unlock(&sim_state.mutex);
+        ralloc_free(sim_file);
 }
 
 #endif /* USE_V3D_SIMULATOR */
diff --git a/src/broadcom/simulator/v3d_simulator.h b/src/broadcom/simulator/v3d_simulator.h
new file mode 100644
index 00000000000..dfd5b9648f8
--- /dev/null
+++ b/src/broadcom/simulator/v3d_simulator.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2019 Raspberry Pi
+ * Copyright © 2014-2017 Broadcom
+ * Copyright (C) 2012 Rob Clark <robclark at freedesktop.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef V3D_SIMULATOR_H
+#define V3D_SIMULATOR_H
+
+#ifdef V3D_VERSION
+#include "broadcom/common/v3d_macros.h"
+#endif
+
+#include <stdint.h>
+
+struct v3d_simulator_file;
+
+struct v3d_simulator_file* v3d_simulator_init(int fd);
+void v3d_simulator_destroy(struct v3d_simulator_file *sim_file);
+uint32_t v3d_simulator_get_spill(uint32_t spill_size);
+int v3d_simulator_ioctl(int fd, unsigned long request, void *arg);
+void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size);
+
+#ifdef v3dX
+#  include "v3dx_simulator.h"
+#else
+#  define v3dX(x) v3d33_##x
+#  include "v3dx_simulator.h"
+#  undef v3dX
+
+#  define v3dX(x) v3d41_##x
+#  include "v3dx_simulator.h"
+#  undef v3dX
+#endif
+
+#endif
diff --git a/src/gallium/drivers/v3d/v3d_simulator_wrapper.cpp b/src/broadcom/simulator/v3d_simulator_wrapper.cpp
similarity index 100%
rename from src/gallium/drivers/v3d/v3d_simulator_wrapper.cpp
rename to src/broadcom/simulator/v3d_simulator_wrapper.cpp
diff --git a/src/gallium/drivers/v3d/v3d_simulator_wrapper.h b/src/broadcom/simulator/v3d_simulator_wrapper.h
similarity index 100%
rename from src/gallium/drivers/v3d/v3d_simulator_wrapper.h
rename to src/broadcom/simulator/v3d_simulator_wrapper.h
diff --git a/src/gallium/drivers/v3d/v3dx_simulator.c b/src/broadcom/simulator/v3dx_simulator.c
similarity index 98%
rename from src/gallium/drivers/v3d/v3dx_simulator.c
rename to src/broadcom/simulator/v3dx_simulator.c
index a9d3d8cd780..dee3e67992c 100644
--- a/src/gallium/drivers/v3d/v3dx_simulator.c
+++ b/src/broadcom/simulator/v3dx_simulator.c
@@ -22,7 +22,7 @@
  */
 
 /**
- * @file v3d_simulator_hw.c
+ * @file v3dx_simulator.c
  *
  * Implements the actual HW interaction betweeh the GL driver's VC5 simulator and the simulator.
  *
@@ -33,10 +33,16 @@
 
 #ifdef USE_V3D_SIMULATOR
 
-#include "v3d_screen.h"
-#include "v3d_context.h"
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+#include "v3d_simulator.h"
 #include "v3d_simulator_wrapper.h"
 
+#include "util/macros.h"
+#include "drm-uapi/v3d_drm.h"
+
 #define HW_REGISTER_RO(x) (x)
 #define HW_REGISTER_RW(x) (x)
 #if V3D_VERSION >= 41
diff --git a/src/broadcom/simulator/v3dx_simulator.h b/src/broadcom/simulator/v3dx_simulator.h
new file mode 100644
index 00000000000..2c623d79a83
--- /dev/null
+++ b/src/broadcom/simulator/v3dx_simulator.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2019 Raspberry Pi
+ * Copyright © 2014-2017 Broadcom
+ * Copyright (C) 2012 Rob Clark <robclark at freedesktop.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/* This file generates the per-v3d-version function prototypes.  It must only
+ * be included from v3d_simulator.h.
+ */
+
+struct v3d_hw;
+struct drm_v3d_get_param;
+struct drm_v3d_submit_cl;
+struct drm_v3d_submit_tfu;
+struct drm_v3d_submit_csd;
+
+void v3dX(simulator_init_regs)(struct v3d_hw *v3d);
+int v3dX(simulator_get_param_ioctl)(struct v3d_hw *v3d,
+                                    struct drm_v3d_get_param *args);
+void v3dX(simulator_submit_cl_ioctl)(struct v3d_hw *v3d,
+                                     struct drm_v3d_submit_cl *args,
+                                     uint32_t gmp_offset);
+int v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d,
+                                     struct drm_v3d_submit_tfu *args);
+int v3dX(simulator_submit_csd_ioctl)(struct v3d_hw *v3d,
+                                     struct drm_v3d_submit_csd *args,
+                                     uint32_t gmp_offset);
diff --git a/src/gallium/drivers/v3d/meson.build b/src/gallium/drivers/v3d/meson.build
index 64e6cb0789a..093eb12e01b 100644
--- a/src/gallium/drivers/v3d/meson.build
+++ b/src/gallium/drivers/v3d/meson.build
@@ -35,8 +35,6 @@ files_libv3d = files(
   'v3d_resource.h',
   'v3d_screen.c',
   'v3d_screen.h',
-  'v3d_simulator.c',
-  'v3d_simulator_wrapper.cpp',
   'v3d_uniforms.c',
 )
 
@@ -46,7 +44,6 @@ files_per_version = files(
   'v3dx_format_table.c',
   'v3dx_job.c',
   'v3dx_rcl.c',
-  'v3dx_simulator.c',
   'v3dx_state.c',
 )
 
@@ -111,7 +108,7 @@ libv3d = static_library(
   ],
   include_directories : [
     inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom,
-    inc_gallium_drivers,
+    inc_simulator, inc_gallium_drivers,
   ],
   c_args : [v3d_args],
   cpp_args : [v3d_args],
diff --git a/src/gallium/drivers/v3d/v3d_context.h b/src/gallium/drivers/v3d/v3d_context.h
index 3a18a0c4fc4..55bc96bed9d 100644
--- a/src/gallium/drivers/v3d/v3d_context.h
+++ b/src/gallium/drivers/v3d/v3d_context.h
@@ -40,6 +40,8 @@
 #include "v3d_screen.h"
 #include "broadcom/common/v3d_limits.h"
 
+#include "broadcom/simulator/v3d_simulator.h"
+
 struct v3d_job;
 struct v3d_bo;
 void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *bo);
@@ -615,12 +617,6 @@ void v3d_program_init(struct pipe_context *pctx);
 void v3d_program_fini(struct pipe_context *pctx);
 void v3d_query_init(struct pipe_context *pctx);
 
-void v3d_simulator_init(struct v3d_screen *screen);
-void v3d_simulator_destroy(struct v3d_screen *screen);
-uint32_t v3d_simulator_get_spill(uint32_t spill_size);
-int v3d_simulator_ioctl(int fd, unsigned long request, void *arg);
-void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size);
-
 static inline int
 v3d_ioctl(int fd, unsigned long request, void *arg)
 {
diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c
index 503573e36bc..bafe7301266 100644
--- a/src/gallium/drivers/v3d/v3d_screen.c
+++ b/src/gallium/drivers/v3d/v3d_screen.c
@@ -78,7 +78,7 @@ v3d_screen_destroy(struct pipe_screen *pscreen)
         free(screen->ro);
 
         if (using_v3d_simulator)
-                v3d_simulator_destroy(screen);
+                v3d_simulator_destroy(screen->sim_file);
 
         v3d_compiler_free(screen->compiler);
         u_transfer_helper_destroy(pscreen->transfer_helper);
@@ -682,7 +682,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config,
         screen->bo_handles = util_hash_table_create_ptr_keys();
 
 #if defined(USE_V3D_SIMULATOR)
-        v3d_simulator_init(screen);
+        screen->sim_file = v3d_simulator_init(screen->fd);
 #endif
 
         if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl))
diff --git a/src/gallium/drivers/v3d/v3dx_context.h b/src/gallium/drivers/v3d/v3dx_context.h
index 64643411b5d..72441e85a20 100644
--- a/src/gallium/drivers/v3d/v3dx_context.h
+++ b/src/gallium/drivers/v3d/v3dx_context.h
@@ -36,17 +36,6 @@ void v3dX(state_init)(struct pipe_context *pctx);
 
 void v3dX(bcl_epilogue)(struct v3d_context *v3d, struct v3d_job *job);
 
-void v3dX(simulator_init_regs)(struct v3d_hw *v3d);
-int v3dX(simulator_get_param_ioctl)(struct v3d_hw *v3d,
-                                    struct drm_v3d_get_param *args);
-void v3dX(simulator_submit_cl_ioctl)(struct v3d_hw *v3d,
-                                     struct drm_v3d_submit_cl *args,
-                                     uint32_t gmp_offset);
-int v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d,
-                                     struct drm_v3d_submit_tfu *args);
-int v3dX(simulator_submit_csd_ioctl)(struct v3d_hw *v3d,
-                                     struct drm_v3d_submit_csd *args,
-                                     uint32_t gmp_offset);
 const struct v3d_format *v3dX(get_format_desc)(enum pipe_format f);
 void v3dX(get_internal_type_bpp_for_output_format)(uint32_t format,
                                                    uint32_t *type,



More information about the mesa-commit mailing list