Skip to content

Commit

Permalink
Fix features and default backend
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Oct 4, 2023
1 parent a54dc76 commit fa60c9e
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions wgpu/backends/rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,13 @@
WGPU_LIMIT_U64_UNDEFINED = 0xFFFFFFFFFFFFFFFF


# Features in WebGPU that don't map to wgpu-native yet
KNOWN_MISSING_FEATURES = [
"bgra8unorm-storage",
"float32-filterable",
]

# Features that wgpu-native supports that are not part of WebGPU
NATIVE_FEATURES = (
"multi_draw_indirect",
"push_constants",
"texture_adapter_specific_format_features",
"multi_draw_indirect",
"multi_draw_indirect_count",
"vertex_writable_storage",
"PushConstants",
"TextureAdapterSpecificFormatFeatures",
"MultiDrawIndirect",
"MultiDrawIndirectCount",
"VertexWritableStorage",
)

# Object to be able to bind the lifetime of objects to other objects
Expand Down Expand Up @@ -238,7 +231,7 @@ def request_adapter(self, *, canvas, power_preference=None):
# See https://github.com/gfx-rs/wgpu/issues/1416
# todo: for the moment we default to forcing Vulkan on Windows
force_backend = os.getenv("WGPU_BACKEND_TYPE", None)
backend = enum_str2int["BackendType"]["Null"]
backend = enum_str2int["BackendType"]["Undefined"]
if force_backend is None: # Allow OUR defaults
if sys.platform.startswith("win"):
backend = enum_str2int["BackendType"]["Vulkan"]
Expand Down Expand Up @@ -342,18 +335,14 @@ def to_py_str(key):
features = set()
for f in sorted(enums.FeatureName):
key = f"FeatureName.{f}"
if key not in enummap:
if f not in KNOWN_MISSING_FEATURES: # pragma: no cover
raise RuntimeError(f"Unexpected feature {f}")
continue
i = enummap[key]
# H: bool f(WGPUAdapter adapter, WGPUFeatureName feature)
if lib.wgpuAdapterHasFeature(adapter_id, i):
features.add(f)

# Native features
for f in NATIVE_FEATURES:
i = getattr(lib, f"WGPUNativeFeature_{f.upper()}")
i = getattr(lib, f"WGPUNativeFeature_{f}")
# H: bool f(WGPUAdapter adapter, WGPUFeatureName feature)
if lib.wgpuAdapterHasFeature(adapter_id, i):
features.add(f)
Expand Down Expand Up @@ -760,18 +749,14 @@ def callback(status, result, message, userdata):
features = set()
for f in sorted(enums.FeatureName):
key = f"FeatureName.{f}"
if key not in enummap:
if f not in KNOWN_MISSING_FEATURES: # pragma: no cover
raise RuntimeError(f"Unexpected feature {f}")
continue
i = enummap[key]
# H: bool f(WGPUDevice device, WGPUFeatureName feature)
if lib.wgpuDeviceHasFeature(device_id, i):
features.add(f)

# Native features
for f in NATIVE_FEATURES:
i = getattr(lib, f"WGPUNativeFeature_{f.upper()}")
i = getattr(lib, f"WGPUNativeFeature_{f}")
# H: bool f(WGPUDevice device, WGPUFeatureName feature)
if lib.wgpuDeviceHasFeature(device_id, i):
features.add(f)
Expand Down

0 comments on commit fa60c9e

Please sign in to comment.