Commit 583d7d3d authored by Alejandro Piñeiro's avatar Alejandro Piñeiro Committed by Marge Bot

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's avatarEric Anholt <eric@anholt.net>
Part-of: <!5666>
parent 4fccbd0e
Pipeline #168241 passed with stages
in 8 minutes and 54 seconds
...@@ -41,7 +41,7 @@ if dep_v3dv3.found() ...@@ -41,7 +41,7 @@ if dep_v3dv3.found()
'v3dx.c', 'v3dx.c',
v3d_xml_pack 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], c_args : [no_override_init_args, '-DV3D_VERSION=' + ver, v3dv3_c_args],
gnu_symbol_visibility : 'hidden', gnu_symbol_visibility : 'hidden',
dependencies: [dep_valgrind, dep_thread, dep_v3dv3], dependencies: [dep_valgrind, dep_thread, dep_v3dv3],
...@@ -52,11 +52,11 @@ if dep_v3dv3.found() ...@@ -52,11 +52,11 @@ if dep_v3dv3.found()
['v3d_drm_shim'], ['v3d_drm_shim'],
[ [
'v3d.c', 'v3d.c',
'../../gallium/drivers/v3d/v3d_simulator_wrapper.cpp', '../simulator/v3d_simulator_wrapper.cpp',
], ],
dependencies: [idep_mesautil, dep_dl, dep_drm_shim, dep_v3dv3], dependencies: [idep_mesautil, dep_dl, dep_drm_shim, dep_v3dv3],
link_with: per_version_libs, 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], c_args : [no_override_init_args, '-std=gnu99', v3dv3_c_args],
gnu_symbol_visibility : 'hidden', gnu_symbol_visibility : 'hidden',
cpp_args : [v3dv3_c_args] cpp_args : [v3dv3_c_args]
......
...@@ -28,6 +28,7 @@ v3d_libs = [] ...@@ -28,6 +28,7 @@ v3d_libs = []
if with_gallium_v3d if with_gallium_v3d
subdir('compiler') subdir('compiler')
subdir('qpu') subdir('qpu')
subdir('simulator')
endif endif
if with_tools.contains('drm-shim') if with_tools.contains('drm-shim')
......
# 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
...@@ -48,18 +48,23 @@ ...@@ -48,18 +48,23 @@
#ifdef USE_V3D_SIMULATOR #ifdef USE_V3D_SIMULATOR
#include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "c11/threads.h"
#include "util/hash_table.h" #include "util/hash_table.h"
#include "util/ralloc.h" #include "util/ralloc.h"
#include "util/set.h" #include "util/set.h"
#include "util/u_dynarray.h" #include "util/u_dynarray.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_mm.h" #include "util/u_mm.h"
#include "util/u_math.h"
#include <xf86drm.h>
#include "drm-uapi/i915_drm.h" #include "drm-uapi/i915_drm.h"
#include "v3d_simulator_wrapper.h" #include "drm-uapi/v3d_drm.h"
#include "v3d_screen.h" #include "v3d_simulator.h"
#include "v3d_context.h" #include "v3d_simulator_wrapper.h"
/** Global (across GEM fds) state for the simulator */ /** Global (across GEM fds) state for the simulator */
static struct v3d_simulator_state { static struct v3d_simulator_state {
...@@ -580,7 +585,7 @@ v3d_simulator_ioctl(int fd, unsigned long request, void *args) ...@@ -580,7 +585,7 @@ v3d_simulator_ioctl(int fd, unsigned long request, void *args)
} }
static void static void
v3d_simulator_init_global(const struct v3d_device_info *devinfo) v3d_simulator_init_global()
{ {
mtx_lock(&sim_state.mutex); mtx_lock(&sim_state.mutex);
if (sim_state.refcount++) { if (sim_state.refcount++) {
...@@ -623,37 +628,38 @@ v3d_simulator_init_global(const struct v3d_device_info *devinfo) ...@@ -623,37 +628,38 @@ v3d_simulator_init_global(const struct v3d_device_info *devinfo)
v3d33_simulator_init_regs(sim_state.v3d); v3d33_simulator_init_regs(sim_state.v3d);
} }
void struct v3d_simulator_file *
v3d_simulator_init(struct v3d_screen *screen) 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 = rzalloc(NULL, struct v3d_simulator_file);
struct v3d_simulator_file *sim_file = screen->sim_file;
drmVersionPtr version = drmGetVersion(screen->fd); drmVersionPtr version = drmGetVersion(fd);
if (version && strncmp(version->name, "i915", version->name_len) == 0) if (version && strncmp(version->name, "i915", version->name_len) == 0)
sim_file->is_i915 = true; sim_file->is_i915 = true;
drmFreeVersion(version); drmFreeVersion(version);
screen->sim_file->bo_map = sim_file->bo_map =
_mesa_hash_table_create(screen->sim_file, _mesa_hash_table_create(sim_file,
_mesa_hash_pointer, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
mtx_lock(&sim_state.mutex); mtx_lock(&sim_state.mutex);
_mesa_hash_table_insert(sim_state.fd_map, int_to_key(screen->fd + 1), _mesa_hash_table_insert(sim_state.fd_map, int_to_key(fd + 1),
screen->sim_file); sim_file);
mtx_unlock(&sim_state.mutex); mtx_unlock(&sim_state.mutex);
sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0); sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0);
sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs - sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs -
sim_state.mem_base); sim_state.mem_base);
memset(sim_file->gmp_vaddr, 0, 8096); memset(sim_file->gmp_vaddr, 0, 8096);
return sim_file;
} }
void void
v3d_simulator_destroy(struct v3d_screen *screen) v3d_simulator_destroy(struct v3d_simulator_file *sim_file)
{ {
mtx_lock(&sim_state.mutex); mtx_lock(&sim_state.mutex);
if (!--sim_state.refcount) { if (!--sim_state.refcount) {
...@@ -664,6 +670,7 @@ v3d_simulator_destroy(struct v3d_screen *screen) ...@@ -664,6 +670,7 @@ v3d_simulator_destroy(struct v3d_screen *screen)
sim_state.mem = NULL; sim_state.mem = NULL;
} }
mtx_unlock(&sim_state.mutex); mtx_unlock(&sim_state.mutex);
ralloc_free(sim_file);
} }
#endif /* USE_V3D_SIMULATOR */ #endif /* USE_V3D_SIMULATOR */
/*
* Copyright © 2019 Raspberry Pi
* Copyright © 2014-2017 Broadcom
* Copyright (C) 2012 Rob Clark <robclark@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
...@@ -22,7 +22,7 @@ ...@@ -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. * Implements the actual HW interaction betweeh the GL driver's VC5 simulator and the simulator.
* *
...@@ -33,10 +33,16 @@ ...@@ -33,10 +33,16 @@
#ifdef USE_V3D_SIMULATOR #ifdef USE_V3D_SIMULATOR
#include "v3d_screen.h" #include <assert.h>
#include "v3d_context.h" #include <stdbool.h>
#include <stdio.h>
#include "v3d_simulator.h"
#include "v3d_simulator_wrapper.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_RO(x) (x)
#define HW_REGISTER_RW(x) (x) #define HW_REGISTER_RW(x) (x)
#if V3D_VERSION >= 41 #if V3D_VERSION >= 41
......
/*
* Copyright © 2019 Raspberry Pi
* Copyright © 2014-2017 Broadcom
* Copyright (C) 2012 Rob Clark <robclark@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);
...@@ -35,8 +35,6 @@ files_libv3d = files( ...@@ -35,8 +35,6 @@ files_libv3d = files(
'v3d_resource.h', 'v3d_resource.h',
'v3d_screen.c', 'v3d_screen.c',
'v3d_screen.h', 'v3d_screen.h',
'v3d_simulator.c',
'v3d_simulator_wrapper.cpp',
'v3d_uniforms.c', 'v3d_uniforms.c',
) )
...@@ -46,7 +44,6 @@ files_per_version = files( ...@@ -46,7 +44,6 @@ files_per_version = files(
'v3dx_format_table.c', 'v3dx_format_table.c',
'v3dx_job.c', 'v3dx_job.c',
'v3dx_rcl.c', 'v3dx_rcl.c',
'v3dx_simulator.c',
'v3dx_state.c', 'v3dx_state.c',
) )
...@@ -111,7 +108,7 @@ libv3d = static_library( ...@@ -111,7 +108,7 @@ libv3d = static_library(
], ],
include_directories : [ include_directories : [
inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom, inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom,
inc_gallium_drivers, inc_simulator, inc_gallium_drivers,
], ],
c_args : [v3d_args], c_args : [v3d_args],
cpp_args : [v3d_args], cpp_args : [v3d_args],
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include "v3d_screen.h" #include "v3d_screen.h"
#include "broadcom/common/v3d_limits.h" #include "broadcom/common/v3d_limits.h"
#include "broadcom/simulator/v3d_simulator.h"
struct v3d_job; struct v3d_job;
struct v3d_bo; struct v3d_bo;
void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *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); ...@@ -615,12 +617,6 @@ void v3d_program_init(struct pipe_context *pctx);
void v3d_program_fini(struct pipe_context *pctx); void v3d_program_fini(struct pipe_context *pctx);
void v3d_query_init(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 static inline int
v3d_ioctl(int fd, unsigned long request, void *arg) v3d_ioctl(int fd, unsigned long request, void *arg)
{ {
......
...@@ -78,7 +78,7 @@ v3d_screen_destroy(struct pipe_screen *pscreen) ...@@ -78,7 +78,7 @@ v3d_screen_destroy(struct pipe_screen *pscreen)
free(screen->ro); free(screen->ro);
if (using_v3d_simulator) if (using_v3d_simulator)
v3d_simulator_destroy(screen); v3d_simulator_destroy(screen->sim_file);
v3d_compiler_free(screen->compiler); v3d_compiler_free(screen->compiler);
u_transfer_helper_destroy(pscreen->transfer_helper); u_transfer_helper_destroy(pscreen->transfer_helper);
...@@ -682,7 +682,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config, ...@@ -682,7 +682,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config,
screen->bo_handles = util_hash_table_create_ptr_keys(); screen->bo_handles = util_hash_table_create_ptr_keys();
#if defined(USE_V3D_SIMULATOR) #if defined(USE_V3D_SIMULATOR)
v3d_simulator_init(screen); screen->sim_file = v3d_simulator_init(screen->fd);
#endif #endif
if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl)) if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl))
......
...@@ -36,17 +36,6 @@ void v3dX(state_init)(struct pipe_context *pctx); ...@@ -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(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); const struct v3d_format *v3dX(get_format_desc)(enum pipe_format f);
void v3dX(get_internal_type_bpp_for_output_format)(uint32_t format, void v3dX(get_internal_type_bpp_for_output_format)(uint32_t format,
uint32_t *type, uint32_t *type,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment