|
41 | 41 | from .._coreutils import ApiDiff |
42 | 42 |
|
43 | 43 | from .rs_ffi import ffi, lib, check_expected_version |
44 | | -from .rs_mappings import cstructfield2enum, enummap |
| 44 | +from .rs_mappings import cstructfield2enum, enummap, enum_str2int, enum_int2str |
45 | 45 | from .rs_helpers import ( |
46 | 46 | get_surface_id_from_canvas, |
47 | 47 | get_memoryview_from_address, |
|
53 | 53 | apidiff = ApiDiff() |
54 | 54 |
|
55 | 55 | # The wgpu-native version that we target/expect |
56 | | -__version__ = "0.8.0.1" |
57 | | -__commit_sha__ = "691468c9817b51a81530fb277a9b30fcc4a71ea7" |
| 56 | +__version__ = "0.8.0.2" |
| 57 | +__commit_sha__ = "66a4139579f2499a67b7ade1a6c3bcb414046c64" |
58 | 58 | version_info = tuple(map(int, __version__.split("."))) |
59 | 59 | check_expected_version(version_info) # produces a warning on mismatch |
60 | 60 |
|
@@ -212,12 +212,27 @@ def request_adapter(self, *, canvas, power_preference=None): |
212 | 212 | else: |
213 | 213 | surface_id = get_surface_id_from_canvas(canvas) |
214 | 214 |
|
| 215 | + # Force Vulkan on Windows, to avoid DX12 which seems to ignore |
| 216 | + # the NVidia control panel settings. I guess Vulkan is more |
| 217 | + # mature than Metal too, so let's just force that for now. |
| 218 | + # See https://github.com/gfx-rs/wgpu/issues/1416 |
| 219 | + # force_backend = lib.WGPUBackendType_Vulkan |
| 220 | + force_backend = enum_str2int["BackendType"]["Vulkan"] |
| 221 | + |
| 222 | + # H: chain: WGPUChainedStruct, backend: WGPUBackendType |
| 223 | + extras = new_struct_p( |
| 224 | + "WGPUAdapterExtras *", |
| 225 | + backend=force_backend, |
| 226 | + # not used: chain |
| 227 | + ) |
| 228 | + extras.chain.sType = lib.WGPUSType_AdapterExtras |
| 229 | + |
215 | 230 | # Convert the descriptor |
216 | 231 | # H: nextInChain: WGPUChainedStruct *, compatibleSurface: WGPUSurface |
217 | 232 | struct = new_struct_p( |
218 | 233 | "WGPURequestAdapterOptions *", |
219 | 234 | compatibleSurface=surface_id, |
220 | | - # not used: nextInChain |
| 235 | + nextInChain=ffi.cast("WGPUChainedStruct * ", extras), |
221 | 236 | ) |
222 | 237 |
|
223 | 238 | # Do the API call and get the adapter id |
@@ -251,16 +266,19 @@ def callback(received, userdata): |
251 | 266 | # not used: backendType |
252 | 267 | ) |
253 | 268 |
|
254 | | - # todo: This function exists in the headerfile but not in the lib (yet) |
255 | 269 | # H: void f(WGPUAdapter adapter, WGPUAdapterProperties * properties) |
256 | | - # lib.wgpuAdapterGetProperties(adapter_id, c_properties) |
| 270 | + lib.wgpuAdapterGetProperties(adapter_id, c_properties) |
257 | 271 | properties = { |
258 | 272 | "name": "", |
259 | 273 | "vendorID": c_properties.vendorID, |
260 | 274 | "deviceID": c_properties.deviceID, |
261 | 275 | "driverDescription": "", |
262 | | - "adapterType": c_properties.adapterType, |
263 | | - "backendType": c_properties.backendType, |
| 276 | + "adapterType": enum_int2str["AdapterType"].get( |
| 277 | + c_properties.adapterType, "unknown" |
| 278 | + ), |
| 279 | + "backendType": enum_int2str["BackendType"].get( |
| 280 | + c_properties.backendType, "unknown" |
| 281 | + ), |
264 | 282 | } |
265 | 283 | if c_properties.name: |
266 | 284 | properties["name"] = ffi.string(c_properties.name).decode(errors="ignore") |
@@ -335,13 +353,26 @@ def _request_device(self, label, features, limits, trace_path): |
335 | 353 | limits2 = base.DEFAULT_ADAPTER_LIMITS.copy() |
336 | 354 | limits2.update(limits or {}) |
337 | 355 |
|
338 | | - # H: chain: WGPUChainedStruct, maxBindGroups: int, label: char*, tracePath: char* |
| 356 | + # Vanilla WGPU does not support interpolating samplers for float32 textures, |
| 357 | + # which is sad for scientific data in particular. We can enable it |
| 358 | + # (on the hardware were wgpu-py likely runs) using the feature: |
| 359 | + # WGPUNativeFeature_TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES |
| 360 | + |
| 361 | + # H: chain: WGPUChainedStruct, maxTextureDimension1D: int, maxTextureDimension2D: int, maxTextureDimension3D: int, maxTextureArrayLayers: int, maxBindGroups: int, maxDynamicStorageBuffersPerPipelineLayout: int, maxStorageBuffersPerShaderStage: int, maxStorageBufferBindingSize: int, nativeFeatures: WGPUNativeFeature, label: char*, tracePath: char* |
339 | 362 | extras = new_struct_p( |
340 | 363 | "WGPUDeviceExtras *", |
341 | 364 | label=to_c_label(label), |
342 | 365 | maxBindGroups=limits2["max_bind_groups"], |
| 366 | + maxStorageBuffersPerShaderStage=6, |
343 | 367 | tracePath=c_trace_path, |
| 368 | + nativeFeatures=lib.WGPUNativeFeature_TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, |
344 | 369 | # not used: chain |
| 370 | + # not used: maxTextureDimension1D |
| 371 | + # not used: maxTextureDimension2D |
| 372 | + # not used: maxTextureDimension3D |
| 373 | + # not used: maxTextureArrayLayers |
| 374 | + # not used: maxDynamicStorageBuffersPerPipelineLayout |
| 375 | + # not used: maxStorageBufferBindingSize |
345 | 376 | ) |
346 | 377 | extras.chain.sType = lib.WGPUSType_DeviceExtras |
347 | 378 |
|
@@ -917,34 +948,37 @@ def create_render_pipeline( |
917 | 948 | if fragment is not None: |
918 | 949 | c_color_targets_list = [] |
919 | 950 | for target in fragment["targets"]: |
920 | | - alpha_blend = _tuple_from_tuple_or_dict( |
921 | | - target["blend"]["alpha"], |
922 | | - ("src_factor", "dst_factor", "operation"), |
923 | | - ) |
924 | | - # H: srcFactor: WGPUBlendFactor, dstFactor: WGPUBlendFactor, operation: WGPUBlendOperation |
925 | | - c_alpha_blend = new_struct( |
926 | | - "WGPUBlendComponent", |
927 | | - srcFactor=alpha_blend[0], |
928 | | - dstFactor=alpha_blend[1], |
929 | | - operation=alpha_blend[2], |
930 | | - ) |
931 | | - color_blend = _tuple_from_tuple_or_dict( |
932 | | - target["blend"]["color"], |
933 | | - ("src_factor", "dst_factor", "operation"), |
934 | | - ) |
935 | | - # H: srcFactor: WGPUBlendFactor, dstFactor: WGPUBlendFactor, operation: WGPUBlendOperation |
936 | | - c_color_blend = new_struct( |
937 | | - "WGPUBlendComponent", |
938 | | - srcFactor=color_blend[0], |
939 | | - dstFactor=color_blend[1], |
940 | | - operation=color_blend[2], |
941 | | - ) |
942 | | - # H: color: WGPUBlendComponent, alpha: WGPUBlendComponent |
943 | | - c_blend = new_struct_p( |
944 | | - "WGPUBlendState *", |
945 | | - color=c_color_blend, |
946 | | - alpha=c_alpha_blend, |
947 | | - ) |
| 951 | + if not target.get("blend", None): |
| 952 | + c_blend = ffi.NULL |
| 953 | + else: |
| 954 | + alpha_blend = _tuple_from_tuple_or_dict( |
| 955 | + target["blend"]["alpha"], |
| 956 | + ("src_factor", "dst_factor", "operation"), |
| 957 | + ) |
| 958 | + # H: srcFactor: WGPUBlendFactor, dstFactor: WGPUBlendFactor, operation: WGPUBlendOperation |
| 959 | + c_alpha_blend = new_struct( |
| 960 | + "WGPUBlendComponent", |
| 961 | + srcFactor=alpha_blend[0], |
| 962 | + dstFactor=alpha_blend[1], |
| 963 | + operation=alpha_blend[2], |
| 964 | + ) |
| 965 | + color_blend = _tuple_from_tuple_or_dict( |
| 966 | + target["blend"]["color"], |
| 967 | + ("src_factor", "dst_factor", "operation"), |
| 968 | + ) |
| 969 | + # H: srcFactor: WGPUBlendFactor, dstFactor: WGPUBlendFactor, operation: WGPUBlendOperation |
| 970 | + c_color_blend = new_struct( |
| 971 | + "WGPUBlendComponent", |
| 972 | + srcFactor=color_blend[0], |
| 973 | + dstFactor=color_blend[1], |
| 974 | + operation=color_blend[2], |
| 975 | + ) |
| 976 | + # H: color: WGPUBlendComponent, alpha: WGPUBlendComponent |
| 977 | + c_blend = new_struct_p( |
| 978 | + "WGPUBlendState *", |
| 979 | + color=c_color_blend, |
| 980 | + alpha=c_alpha_blend, |
| 981 | + ) |
948 | 982 | # H: nextInChain: WGPUChainedStruct *, format: WGPUTextureFormat, blend: WGPUBlendState *, writeMask: WGPUColorWriteMaskFlags/int |
949 | 983 | c_color_state = new_struct( |
950 | 984 | "WGPUColorTargetState", |
|
0 commit comments