Skip to content

Add examples for instance extras #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Add examples for instance extras #728

wants to merge 14 commits into from

Conversation

Vipitis
Copy link
Contributor

@Vipitis Vipitis commented Jul 23, 2025

This was mentioned in reply #718 (review)

PR adds two examples regarding instance extras:

  • Using DXC(over FXC) on Windows, includes a script to download the required library files.
  • Debugging using a graphics debugger like RenderDoc, includes a portable variant with a .cap file: works when your OS is setup to open .cap file with RenderDoc. Adds annotation and labels to the cube example.
  • documents the function in docs.

todos:

  • insert debug markers for the example
  • add labels to the example so they show up during debugging
  • fix more typos
  • add hyperlinks to other parts of the docs
  • update guide docs debug section?
  • file issue with Dxc not using debug flags in wgpu-core (perhaps in v26?) ref: unable to get debug flags with Dxc gfx-rs/wgpu-native#487
  • resolve arch, if needed?

@Vipitis
Copy link
Contributor Author

Vipitis commented Jul 27, 2025

while renderdoc has a python api, it's complex to build and package with modern python versions. So this might look like a workaround but I feel like that is actually quite convenient to use... making it work on linux sounds plausible.

if __name__ == "__main__":
# awful hack: if the script is run by a user, we write the tempfile to then run the launcher and auto catpure
# while the capture itself has an envvar to launch the gui instead.
is_renderdoc = os.environ.get("RENDERDOC_CAPTURE", "0") == "1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an alternative idea I have had is to use an arg and check sys.argv[1] not sure which one makes more sense - if at all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you trying to detect if you are running by the pytest test suite?

I think you can use the trick I used:
https://github.com/pygfx/pygfx/blob/main/examples/feature_demo/video_yuv.py#L79

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is not for the test suite, but I guess this syntax makes a bit more sense.
"0" evaluating to False definitely shouldn't be used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i guess you are doing something quite similar, where RENDERDOR_CAPTURE is set by the tool, to help you identify that it is being run by the documentation tool, and not interactively.

^_^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renderdoc is actually a graphics debugger (not the best name). if you haven't seen or used it - you might enjoy to go really low and step a single pixel of a decompiled shader or inspect all intermediate stages of the render pipeline and resources along the way.

I came up with this dual use script to make it a bit portable and avoid the complicated scripting API. Also didn't want to write as much text.

Let me know what your experience is as I want to improve on the example anyway. For example inserting debug markers, using more labels...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try to run it now.

Though a screencast of what you can do could help me understand what a "graphical debugger" can do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm cool. i clicked enough, and edited a few things, but eventually https://renderdoc.org/ "detected" the demo.

I'll have to try to recreate the things you do in a tiny screencast, but seems useful...

@@ -158,7 +175,7 @@ def create_pipeline_layout(device):
)

# Create a sampler
sampler = device.create_sampler()
sampler = device.create_sampler(label="Cube Example sampler")

# We always have two bind groups, so we can play distributing our
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still accurate? It seems to be from over 5 years ago when this example was first added

examples/cube.py Outdated
device.create_bind_group(
layout=bind_group_layout,
entries=entries,
label=f"Cube Example bind group {entries[0]['binding']}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to do something like f"Cube Example {entries[0]['resource'].__name__} bind group" so it says like buffer, texture, sampler; but it would be a really clunkly inline expression as the buffer has a nested structure. And I don't feel like adding and then popping a label arg above as that might confuse users.

But it seems like they all show up as part of one group in RenderDoc anyway (or it's optimized somewhere):
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out there is only one item in the list, whole nested structure isn't needed. You can put a label on the bind group but not the individual entries, same for the layout.

@Vipitis Vipitis marked this pull request as ready for review August 9, 2025 21:06
@Vipitis Vipitis requested a review from Korijn as a code owner August 9, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants