Repository navigation
Expand file tree
/
Copy pathevent_filter.py
More file actions
62 lines (49 loc) · 2.08 KB
/
Copy pathevent_filter.py
File metadata and controls
62 lines (49 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# these imports are not strictly necessary, but are convenient
import renderdoc
import qrenderdoc
# this is here to give autocomplete when editing the example
# in VS Code where it doesn't know about this global
from typing import TYPE_CHECKING
if TYPE_CHECKING:
pyrenderdoc = qrenderdoc.CaptureContext()
if not pyrenderdoc.IsCaptureLoaded():
filename = pyrenderdoc.Extensions().OpenFileName("Choose a capture", "", "*.rdc")
pyrenderdoc.LoadCapture(filename, renderdoc.ReplayOptions(), filename, False, True)
# prime numbers have exactly 2 integer factors.
# note the // operator in python does integer-division
def isprime(n):
return len([x for x in range(1, n + 1) if (n / x) == (n // x)]) == 2
# our main filter function. Could use the params or other things passed in
# to do more complex filtering
def filter_func(
ctx: qrenderdoc.CaptureContext,
filter: str,
params: str,
eventId: int,
chunk: renderdoc.SDChunk,
action: renderdoc.ActionDescription,
eventName: str,
):
return isprime(eventId)
# the parser gives us a chance to parse the params and cache the data,
# this is only called when the filter is modified. It also lets us
# error-check any params we want
def parser_func(ctx: qrenderdoc.CaptureContext, filter: str, params: str):
if "error" in params:
return f"You shouldn't put 'error' in ${filter}()"
return ""
# the completer can take the current params string and dynamically
# provide auto-complete suggestions for what to add.
def completer_func(ctx: qrenderdoc.CaptureContext, filter: str, params: str):
return ["foo", "bar", "error"]
# In a UI extension we'd register and unregister over the lifetime of the extension.
# But we can also just unregister unconditionally, and then re-register. Note if you
# do not unregister then this will fail and will refuse to overwrite an existing filter.
pyrenderdoc.GetEventBrowser().UnregisterEventFilterFunction("prime")
pyrenderdoc.GetEventBrowser().RegisterEventFilterFunction(
"prime",
"Show only events with prime EIDs.",
filter_func,
parser_func,
completer_func,
)