summaryrefslogtreecommitdiff
path: root/.gitlab-ci/tracie/renderdoc_dump_images.py
diff options
context:
space:
mode:
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>2020-01-08 17:46:46 +0200
committerTomeu Vizoso <tomeu.vizoso@collabora.com>2020-02-20 08:06:13 +0100
commit803ab5d6be6bc63e3eae827d7297e0cd98cc61dd (patch)
treeac1b9974160a7c2970d6cc9104e4252499a7f360 /.gitlab-ci/tracie/renderdoc_dump_images.py
parent50f1950ac0b52d291ac70bc1ce871a03ed88ba4a (diff)
downloadmesa-803ab5d6be6bc63e3eae827d7297e0cd98cc61dd.tar.gz
gitlab-ci: Automated testing with OpenGL traces
Introduce automated testing of Mesa by replaying traces with Renderdoc or Apitrace. For now only LLVMPipe is tested, but other drivers can be tested if there's runners with the necessary hardware. Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Reviewed-by: Eric Anholt <eric@anholt.net> Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2935> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2935>
Diffstat (limited to '.gitlab-ci/tracie/renderdoc_dump_images.py')
-rwxr-xr-x.gitlab-ci/tracie/renderdoc_dump_images.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/.gitlab-ci/tracie/renderdoc_dump_images.py b/.gitlab-ci/tracie/renderdoc_dump_images.py
new file mode 100755
index 00000000000..f1252c11f25
--- /dev/null
+++ b/.gitlab-ci/tracie/renderdoc_dump_images.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2019 Collabora Ltd
+#
+# 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.
+#
+# SPDX-License-Identifier: MIT
+
+import sys
+from pathlib import Path
+
+import renderdoc as rd
+
+def findDrawWithEventId(controller, eventId):
+ for d in controller.GetDrawcalls():
+ if d.eventId == eventId:
+ return d
+
+ return None
+
+def dumpImage(controller, eventId, outputDir, tracefile):
+ draw = findDrawWithEventId(controller, eventId)
+ if draw is None:
+ raise RuntimeError("Couldn't find draw call with eventId " + str(eventId))
+
+ controller.SetFrameEvent(draw.eventId, True)
+
+ texsave = rd.TextureSave()
+
+ # Select the first color output
+ texsave.resourceId = draw.outputs[0]
+
+ if texsave.resourceId == rd.ResourceId.Null():
+ return
+
+ filepath = Path(outputDir)
+ filepath.mkdir(parents = True, exist_ok = True)
+ filepath = filepath / (tracefile + "-" + str(int(draw.eventId)) + ".png")
+
+ print("Saving image at eventId %d: %s to %s" % (draw.eventId, draw.name, filepath))
+
+ # Most formats can only display a single image per file, so we select the
+ # first mip and first slice
+ texsave.mip = 0
+ texsave.slice.sliceIndex = 0
+
+ # For formats with an alpha channel, preserve it
+ texsave.alpha = rd.AlphaMapping.Preserve
+ texsave.destType = rd.FileType.PNG
+ controller.SaveTexture(texsave, str(filepath))
+
+def loadCapture(filename):
+ cap = rd.OpenCaptureFile()
+
+ status = cap.OpenFile(filename, '', None)
+
+ if status != rd.ReplayStatus.Succeeded:
+ raise RuntimeError("Couldn't open file: " + str(status))
+ if not cap.LocalReplaySupport():
+ raise RuntimeError("Capture cannot be replayed")
+
+ status,controller = cap.OpenCapture(rd.ReplayOptions(), None)
+
+ if status != rd.ReplayStatus.Succeeded:
+ raise RuntimeError("Couldn't initialise replay: " + str(status))
+
+ return (cap, controller)
+
+def renderdoc_dump_images(filename, eventIds, outputDir):
+ rd.InitGlobalEnv(rd.GlobalEnvironment(), [])
+ cap,controller = loadCapture(filename);
+
+ tracefile = Path(filename).name
+
+ if len(eventIds) == 0:
+ eventIds.append(controller.GetDrawcalls()[-1].eventId)
+
+ for eventId in eventIds:
+ dumpImage(controller, eventId, outputDir, tracefile)
+
+ controller.Shutdown()
+ cap.Shutdown()
+
+if __name__ == "__main__":
+ if len(sys.argv) < 3:
+ raise RuntimeError("Usage: renderdoc_dump_images.py <trace> <outputdir> [<draw-id>...]")
+
+ eventIds = [int(e) for e in sys.argv[3:]]
+
+ renderdoc_dump_images(sys.argv[1], eventIds, sys.argv[2])