Module: Mesa Branch: main Commit: 8f621174da089e87e2bdd48e683defc83a3472c9 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f621174da089e87e2bdd48e683defc83a3472c9
Author: Juan A. Suarez Romero <jasua...@igalia.com> Date: Thu Nov 2 11:36:02 2023 +0100 v3d: use kmsro to create drm screen on real hw When using `MESA_LOADER_DRIVER_OVERRIDE=v3d` in real hw, use kmsro to create the drm screen, which is actually what happens when not exporting such variable. This avoids confusions when using the envvar in real hardware and starts to fail. Reviewed-by: Alejandro PiƱeiro <apinhe...@igalia.com> Signed-off-by: Juan A. Suarez Romero <jasua...@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26007> --- src/gallium/winsys/v3d/drm/meson.build | 14 +++++++++++++- src/gallium/winsys/v3d/drm/v3d_drm_winsys.c | 25 +++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/gallium/winsys/v3d/drm/meson.build b/src/gallium/winsys/v3d/drm/meson.build index 3d3cc5b3f01..36a1ee1e4cc 100644 --- a/src/gallium/winsys/v3d/drm/meson.build +++ b/src/gallium/winsys/v3d/drm/meson.build @@ -18,13 +18,25 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +dep_v3dv3 = dependency('v3dv3', required: false) + +v3d_winsys_c_args = [] +if with_gallium_kmsro + v3d_winsys_c_args += '-DGALLIUM_KMSRO' +endif + +if (dep_v3dv3.found()) + v3d_winsys_c_args += '-DUSE_V3D_SIMULATOR' +endif + libv3dwinsys = static_library( 'v3dwinsys', files('v3d_drm_winsys.c'), include_directories : [ inc_src, inc_include, - inc_gallium, inc_gallium_aux, inc_gallium_drivers, + inc_gallium, inc_gallium_aux, inc_gallium_drivers, inc_gallium_winsys, ], + c_args: [v3d_winsys_c_args], gnu_symbol_visibility : 'hidden', dependencies : idep_mesautil, ) diff --git a/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c b/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c index 0386cde886e..2c438e855e5 100644 --- a/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c +++ b/src/gallium/winsys/v3d/drm/v3d_drm_winsys.c @@ -23,19 +23,40 @@ #include <unistd.h> #include <fcntl.h> +#include <sys/ioctl.h> #include "util/os_file.h" #include "util/u_screen.h" +#include "kmsro/drm/kmsro_drm_public.h" #include "v3d_drm_public.h" #include "v3d/v3d_screen.h" +#include "drm-uapi/v3d_drm.h" struct pipe_screen * v3d_drm_screen_create(int fd, const struct pipe_screen_config *config) { - return u_pipe_screen_lookup_or_create(os_dupfd_cloexec(fd), config, - NULL, v3d_screen_create); + bool v3d_present = false; + +#ifndef USE_V3D_SIMULATOR + struct drm_v3d_get_param ident0 = { + .param = DRM_V3D_PARAM_V3D_CORE0_IDENT0, + }; + + int ret = ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0); + v3d_present = (ret != 0); +#endif + + if (!v3d_present) + return u_pipe_screen_lookup_or_create(os_dupfd_cloexec(fd), config, + NULL, v3d_screen_create); + +#ifdef GALLIUM_KMSRO + return kmsro_drm_screen_create(fd, config); +#endif + + return NULL; } struct pipe_screen *