[virglrenderer-devel] [PATCH 3/4] vrenderer: Add function to obtain host GL and virglrend info

Gert Wollny gert.wollny at collabora.com
Wed Jun 13 09:03:39 UTC 2018


For debugging purposes it is desirable to know the exact version of
virglrenderer from within the guest, including the git commit sha 
for builds that don't stem from a release.

Add a script to obtain the git sha and add a function to obtain the
host GL version and the virglrenderer version.

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
 src/Makefile.am     | 15 ++++++++++++++-
 src/git_sha1.h.in   |  1 +
 src/git_sha1_gen.py | 46 +++++++++++++++++++++++++++++++++++++++++++++
 src/virglrenderer.c |  9 ++++++++-
 src/virglrenderer.h |  2 ++
 5 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 src/git_sha1.h.in
 create mode 100644 src/git_sha1_gen.py

diff --git a/src/Makefile.am b/src/Makefile.am
index 76f4162..43a5fbc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,8 @@
 SUBDIRS := gallium/auxiliary
+
+BUILT_SOURCES = git_sha1.h
+CLEANFILES = $(BUILT_SOURCES)
+
 AM_LDFLAGS = -lm \
 	$(GBM_LIBS) \
 	$(EPOXY_LIBS) \
@@ -21,6 +25,7 @@ libvrend_la_SOURCES = \
         virgl_hw.h \
         virgl_protocol.h \
         vrend_iov.h \
+        git_sha1.h \
         vrend_renderer.c \
         vrend_renderer.h \
         vrend_shader.c \
@@ -58,6 +63,14 @@ libvirglrenderer_la_LDFLAGS = $(GM_LDFLAGS) $(EPOXY_LDFLAGS) $(X11_LDFLAGS)
 libvirglrendererincludedir = ${includedir}/virgl
 libvirglrendererinclude_HEADERS = virglrenderer.h
 
-EXTRA_DIST = gallium/include
+.PHONY: git_version
+
+git_sha1.h: git_version
+
+git_version:
+	@echo "updating $@"
+	$(PYTHON) $(top_srcdir)/src/git_sha1_gen.py --output git_sha1.h
+
+EXTRA_DIST = gallium/include git_sha1.h.in git_sha1.h git_sha1_gen.py
 
 -include $(top_srcdir)/git.mk
diff --git a/src/git_sha1.h.in b/src/git_sha1.h.in
new file mode 100644
index 0000000..d6ead33
--- /dev/null
+++ b/src/git_sha1.h.in
@@ -0,0 +1 @@
+#define VREND_VCS_TAG "@VCS_TAG@"
diff --git a/src/git_sha1_gen.py b/src/git_sha1_gen.py
new file mode 100644
index 0000000..4ea6f68
--- /dev/null
+++ b/src/git_sha1_gen.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+"""
+Generate the contents of the git_sha1.h file.
+The output of this script goes to stdout.
+"""
+
+
+import argparse
+import os
+import os.path
+import subprocess
+import sys
+
+
+def get_git_sha1():
+    """Try to get the git SHA1 with git rev-parse."""
+    git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git')
+    try:
+        git_sha1 = " (git-"+ subprocess.check_output([
+            'git',
+            '--git-dir=' + git_dir,
+            'rev-parse',
+            'HEAD',
+        ], stderr=open(os.devnull, 'w')).decode("ascii")[:8] + ")"
+    except:
+        # don't print anything if it fails
+        git_sha1 = ''
+    return git_sha1
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--output', help='File to write the #define in',
+        required=True)
+args = parser.parse_args()
+
+git_sha1 = os.environ.get('VIRGL_GIT_SHA1_OVERRIDE', get_git_sha1())
+git_sha1_h_in_path = os.path.join(os.path.dirname(sys.argv[0]),
+                                  '..', 'src', 'git_sha1.h.in')
+with open(git_sha1_h_in_path , 'r') as git_sha1_h_in:
+    new_sha1 = git_sha1_h_in.read().replace('@VCS_TAG@', git_sha1)
+    if os.path.isfile(args.output):
+        with open(args.output, 'r') as git_sha1_h:
+            if git_sha1_h.read() == new_sha1:
+                quit()
+    with open(args.output, 'w') as git_sha1_h:
+        git_sha1_h.write(new_sha1)
diff --git a/src/virglrenderer.c b/src/virglrenderer.c
index c2ef019..5586241 100644
--- a/src/virglrenderer.c
+++ b/src/virglrenderer.c
@@ -35,8 +35,8 @@
 #include "util/u_format.h"
 #include "util/u_math.h"
 #include "vrend_renderer.h"
-
 #include "virglrenderer.h"
+#include "git_sha1.h"
 
 #ifdef HAVE_EPOXY_EGL_H
 #include "virgl_egl.h"
@@ -194,6 +194,13 @@ void virgl_renderer_get_rect(int resource_id, struct iovec *iov, unsigned int nu
    vrend_renderer_get_rect(resource_id, iov, num_iovs, offset, x, y, width, height);
 }
 
+const char *virgl_renderer_get_host_info(void)
+{
+   static char host_version[256];
+   snprintf(host_version, 255, "HOST: %s vrend: %s%s",
+            glGetString(GL_VERSION), PACKAGE_VERSION, VREND_VCS_TAG);
+   return host_version;
+}
 
 static struct virgl_renderer_callbacks *rcbs;
 
diff --git a/src/virglrenderer.h b/src/virglrenderer.h
index 9596dce..9b7e0ff 100644
--- a/src/virglrenderer.h
+++ b/src/virglrenderer.h
@@ -74,6 +74,8 @@ VIRGL_EXPORT void virgl_renderer_get_rect(int resource_id, struct iovec *iov, un
 
 VIRGL_EXPORT int virgl_renderer_get_fd_for_texture(uint32_t tex_id, int *fd);
 
+VIRGL_EXPORT const char *virgl_renderer_get_host_info(void);
+
 /* virgl bind flags - these are compatible with mesa 10.5 gallium.
    but are fixed, no other should be passed to virgl either. */
 #define VIRGL_RES_BIND_DEPTH_STENCIL (1 << 0)
-- 
2.17.1



More information about the virglrenderer-devel mailing list