From d2aa6eb77ee736bbb596af767cb25767aadc5739 Mon Sep 17 00:00:00 2001 From: dskkato Date: Mon, 13 Nov 2023 10:46:56 +0900 Subject: [PATCH] fix code gen test --- examples/compute_noop.py | 8 ++++++-- tests/test_api.py | 1 - tests/test_rs_basics.py | 2 +- wgpu/backends/rs.py | 27 ++++++++++++++------------- wgpu/base.py | 14 -------------- wgpu/resources/codegen_report.md | 6 +++--- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/examples/compute_noop.py b/examples/compute_noop.py index bbb8ce7d..8ad8e997 100644 --- a/examples/compute_noop.py +++ b/examples/compute_noop.py @@ -1,3 +1,4 @@ +# %% """ Example compute shader that does ... nothing but copy a value from one buffer into another. @@ -63,10 +64,11 @@ device = wgpu.utils.get_default_device() # Or, you can select GPU by requesting all available adapters -# adapters = wgpu.GPU.enumerate_adapters() +# adapters = wgpu.backends.rs.enumerate_adapters() # adapter = None # for adap in adapters: -# if "NVIDIA" in adap.adapter_info["device"]: +# adapter_info = adap.request_adapter_info() +# if "NVIDIA" in adapter_info["device"]: # adapter = adap # break # assert adapter is not None @@ -133,3 +135,5 @@ result = out.tolist() print(result) assert result == list(range(20)) + +# %% diff --git a/tests/test_api.py b/tests/test_api.py index 7d90ea7c..fa6f990c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -83,7 +83,6 @@ def test_base_wgpu_api(): assert isinstance(adapter.features, set) assert adapter.features == set() assert isinstance(adapter.limits, dict) - assert isinstance(adapter.adapter_info, dict) assert set(device.limits.keys()) == set() assert isinstance(device, wgpu.base.GPUObjectBase) diff --git a/tests/test_rs_basics.py b/tests/test_rs_basics.py index e67f9bb3..5d9c3896 100644 --- a/tests/test_rs_basics.py +++ b/tests/test_rs_basics.py @@ -149,7 +149,7 @@ def test_rs_tracer(): @mark.skipif(not can_use_wgpu_lib, reason="Needs wgpu lib") def test_rs_enumerate_adapters(): # Get all available adapters - adapters = wgpu.GPU.enumerate_adapters() + adapters = wgpu.backends.rs.enumerate_adapters() assert len(adapters) > 0 # Check that we can get a device from each adapter diff --git a/wgpu/backends/rs.py b/wgpu/backends/rs.py index 6ef06bb4..ae1b12df 100644 --- a/wgpu/backends/rs.py +++ b/wgpu/backends/rs.py @@ -176,6 +176,20 @@ def check_struct(struct_name, d): libf = SafeLibCalls(lib, error_handler) +def enumerate_adapters(): + """Return a list of all available adapters.""" + # The first call is to get the number of adapters, and + # the second call is to get the actual adapters + + # H: size_t f(WGPUInstance instance, WGPUInstanceEnumerateAdapterOptions const * options, WGPUAdapter * adapters) + adapter_count = libf.wgpuInstanceEnumerateAdapters( + get_wgpu_instance(), ffi.NULL, ffi.NULL + ) + adapters = ffi.new("WGPUAdapter[]", adapter_count) + libf.wgpuInstanceEnumerateAdapters(get_wgpu_instance(), ffi.NULL, adapters) + return [GPUAdapter(adapter) for adapter in adapters] + + # %% The API @@ -275,19 +289,6 @@ async def request_adapter_async( force_fallback_adapter=force_fallback_adapter, ) # no-cover - @staticmethod - def enumerate_adapters() -> List["GPUAdapter"]: - """Return a list of all available adapters.""" - # H: size_t f(WGPUInstance instance, WGPUInstanceEnumerateAdapterOptions const * options, WGPUAdapter * adapters); - # The first call is to get the number of adapters - adapter_count = libf.wgpuInstanceEnumerateAdapters( - get_wgpu_instance(), ffi.NULL, ffi.NULL - ) - # The second call is to get the actual adapters - adapters = ffi.new("WGPUAdapter[]", adapter_count) - libf.wgpuInstanceEnumerateAdapters(get_wgpu_instance(), ffi.NULL, adapters) - return [GPUAdapter(adapter) for adapter in adapters] - class GPUCanvasContext(base.GPUCanvasContext): def __init__(self, canvas): diff --git a/wgpu/base.py b/wgpu/base.py index 2adf7d31..9528c34a 100644 --- a/wgpu/base.py +++ b/wgpu/base.py @@ -278,14 +278,6 @@ def __init__(self, internal, features, limits, adapter_info): self._limits = limits self._adapter_info = adapter_info - def __repr__(self): - return ( - f"<{self.__class__.__name__} at 0x{hex(id(self))}>\n" - f" features: {self.features}\n" - f" limits: {self.limits}\n" - f" adapter_info: {self.adapter_info}" - ) - # IDL: [SameObject] readonly attribute GPUSupportedFeatures features; @property def features(self): @@ -298,12 +290,6 @@ def limits(self): """A dict with limits for the adapter.""" return self._limits - # IDL: [SameObject] readonly attribute GPUAdapterInfo adapter_info; - @property - def adapter_info(self): - """A dict with information about the adapter, such as the vendor and device name.""" - return self._adapter_info - # IDL: Promise requestDevice(optional GPUDeviceDescriptor descriptor = {}); def request_device( self, diff --git a/wgpu/resources/codegen_report.md b/wgpu/resources/codegen_report.md index acf83431..30986ded 100644 --- a/wgpu/resources/codegen_report.md +++ b/wgpu/resources/codegen_report.md @@ -19,7 +19,7 @@ * Validated 37 classes, 113 methods, 43 properties ### Patching API for backends/rs.py * Diffs for GPUAdapter: add request_device_tracing -* Validated 37 classes, 101 methods, 0 properties +* Validated 37 classes, 102 methods, 0 properties ## Validating rs.py * Enum field TextureFormat.rgb10a2uint missing in wgpu.h * Enum PipelineErrorReason missing in wgpu.h @@ -28,6 +28,6 @@ * Enum CanvasAlphaMode missing in wgpu.h * Enum field DeviceLostReason.unknown missing in wgpu.h * Wrote 232 enum mappings and 47 struct-field mappings to rs_mappings.py -* Validated 89 C function calls -* Not using 113 C functions +* Validated 91 C function calls +* Not using 112 C functions * Validated 71 C structs