Skip to content

Commit

Permalink
fix code gen test
Browse files Browse the repository at this point in the history
  • Loading branch information
dskkato committed Nov 13, 2023
1 parent 7ecc16d commit d2aa6eb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 34 deletions.
8 changes: 6 additions & 2 deletions examples/compute_noop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %%
"""
Example compute shader that does ... nothing but copy a value from one
buffer into another.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -133,3 +135,5 @@
result = out.tolist()
print(result)
assert result == list(range(20))

# %%
1 change: 0 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rs_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions wgpu/backends/rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down
14 changes: 0 additions & 14 deletions wgpu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
def request_device(
self,
Expand Down
6 changes: 3 additions & 3 deletions wgpu/resources/codegen_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d2aa6eb

Please sign in to comment.