Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions wgpu/backends/wgpu_native/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,9 @@ def _get_capabilities_screen(self, adapter):
capabilities["formats"] = formats = []
Copy link
Contributor

Choose a reason for hiding this comment

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

just a side note on this syntax... the list mutability gets exploited here like a pointer. formats isn't used below this anymore... yet it still works.

I found this sorta confusing in python.

Copy link
Collaborator

@Korijn Korijn Dec 17, 2025

Choose a reason for hiding this comment

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

Everything is pass by reference in python. It would be weird if capabilities["formats"] and formats were independent copies though right?

capabilities["formats"] = formats = [] is not short for:

capabilities["formats"] = []
formats = []

It's short for:

formats = []
capabilities["formats"] = formats

That's how I think about it at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this particular case the formats is indeed a temporary variable, to avoid the repetitive dict lookup for doing capabilities["formats"].append(str_val).

for i in range(c_capabilities.formatCount):
int_val = c_capabilities.formats[i]
formats.append(enum_int2str["TextureFormat"][int_val])
str_val = enum_int2str["TextureFormat"].get(int_val)
if str_val:
formats.append(str_val)

else:
capabilities["formats"] = minimal_capabilities["formats"]
Expand All @@ -779,17 +781,19 @@ def _get_capabilities_screen(self, adapter):
capabilities["alpha_modes"] = alpha_modes = []
for i in range(c_capabilities.alphaModeCount):
int_val = c_capabilities.alphaModes[i]
str_val = enum_int2str["CompositeAlphaMode"][int_val]
alpha_modes.append(str_val.lower())
str_val = enum_int2str["CompositeAlphaMode"].get(int_val)
if str_val:
alpha_modes.append(str_val.lower())
else:
capabilities["alpha_modes"] = minimal_capabilities["alpha_modes"]

if c_capabilities.presentModes:
capabilities["present_modes"] = present_modes = []
for i in range(c_capabilities.presentModeCount):
int_val = c_capabilities.presentModes[i]
str_val = enum_int2str["PresentMode"][int_val]
present_modes.append(str_val.lower())
str_val = enum_int2str["PresentMode"].get(int_val)
if str_val:
present_modes.append(str_val.lower())
else:
capabilities["present_modes"] = minimal_capabilities["present_modes"]

Expand Down