Repository navigation
Expand file tree
/
Copy pathshow_buffer.py
More file actions
57 lines (40 loc) · 1.75 KB
/
Copy pathshow_buffer.py
File metadata and controls
57 lines (40 loc) · 1.75 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
import struct
# 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)
mybuf = renderdoc.ResourceId.Null()
for buf in pyrenderdoc.GetBuffers():
print(f"buf {buf.resourceId} is {pyrenderdoc.GetResourceName(buf.resourceId)}")
mybuf = buf.resourceId
# here put your actual selection criteria - i.e. look for a particular name
if "Vertex" in pyrenderdoc.GetResourceName(buf.resourceId):
break
print(f"selected {pyrenderdoc.GetResourceName(mybuf)}")
formatter = """
float3 pos;
half norms[6];
uint flags;
"""
if mybuf != renderdoc.ResourceId.Null():
# Open a new buffer viewer for this buffer, with the given format
bufview = pyrenderdoc.ViewBuffer(0, 0, mybuf, formatter)
# Show the buffer viewer on the main tool area
pyrenderdoc.AddDockWindow(
bufview.Widget(), qrenderdoc.DockReference.MainToolArea, None
)
# Get access to a controller to get the buffer data.
# We use the blocking controller for simplicity, but a better option
# might be to invoke onto the replay thread with
# pyrenderdoc.Replay().AsyncInvoke()
controller = pyrenderdoc.GetBlockingController()
data_bytes = controller.GetBufferData(mybuf, 0, 8)
data_decoded = struct.unpack_from("8B", data_bytes)
print(f"The first 8 bytes of the buffer are: {data_decoded}")