diff --git a/download-wgpu-native.py b/download-wgpu-native.py index 659240af..83a584e3 100644 --- a/download-wgpu-native.py +++ b/download-wgpu-native.py @@ -103,6 +103,8 @@ def get_arch(): def main(version, os_string, arch, upstream): for build in ["release"]: # ["release", "debug"] + if os_string == "windows": + arch += "-msvc" # -gnu is also available. filename = f"wgpu-{os_string}-{arch}-{build}.zip" url = f"https://github.com/{upstream}/releases/download/v{version}/{filename}" tmp = tempfile.gettempdir() diff --git a/examples/cube.py b/examples/cube.py index 59c4cbcc..c1b1a81c 100644 --- a/examples/cube.py +++ b/examples/cube.py @@ -30,7 +30,6 @@ render_texture_format = present_context.get_preferred_format(device.adapter) present_context.configure(device=device, format=render_texture_format) - # %% Generate data # pos texcoord diff --git a/tests/test_wgpu_native_errors.py b/tests/test_wgpu_native_errors.py index b021cde7..7931f44d 100644 --- a/tests/test_wgpu_native_errors.py +++ b/tests/test_wgpu_native_errors.py @@ -29,7 +29,7 @@ def test_parse_shader_error1(caplog): Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule Shader '' parsing error: invalid field accessor `invalid_attr` ┌─ wgsl:9:9 @@ -38,7 +38,7 @@ def test_parse_shader_error1(caplog): │ ^^^^^^^^^^^^ invalid accessor - invalid field accessor `invalid_attr` + invalid field accessor `invalid_attr` """ code = dedent(code) @@ -65,7 +65,7 @@ def test_parse_shader_error2(caplog): Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule Shader '' parsing error: expected ',', found ';' ┌─ wgsl:2:38 @@ -74,7 +74,7 @@ def test_parse_shader_error2(caplog): │ ^ expected ',' - expected ',', found ';' + expected ',', found ';' """ code = dedent(code) @@ -101,7 +101,7 @@ def test_parse_shader_error3(caplog): Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule Shader '' parsing error: unknown scalar type: 'f3' ┌─ wgsl:3:39 @@ -112,7 +112,7 @@ def test_parse_shader_error3(caplog): = note: Valid scalar types are f32, f64, i32, u32, bool - unknown scalar type: 'f3' + unknown scalar type: 'f3' """ code = dedent(code) @@ -139,12 +139,12 @@ def test_parse_shader_error4(caplog): Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule - Shader '' parsing error: Index 4 is out of bounds for expression [11] + Shader '' parsing error: Index 4 is out of bounds for expression [10] - Index 4 is out of bounds for expression [11] + Index 4 is out of bounds for expression [10] """ code = dedent(code) @@ -175,24 +175,24 @@ def test_validate_shader_error1(caplog): } """ - expected1 = """Left: Load { pointer: [3] } of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }""" - expected2 = """Right: Load { pointer: [6] } of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }""" + expected1 = """Left: Load { pointer: [2] } of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }""" + expected2 = """Right: Load { pointer: [5] } of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }""" expected3 = """ Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule Shader validation error: ┌─ :10:20 │ 10 │ out.position = matrics * out.position; - │ ^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [8] + │ ^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [7] - Entry point vs_main at Vertex is invalid - Expression [8] is invalid - Operation Multiply can't work with [5] and [7] + Entry point vs_main at Vertex is invalid + Expression [7] is invalid + Operation Multiply can't work with [4] and [6] """ code = dedent(code) @@ -231,17 +231,17 @@ def test_validate_shader_error2(caplog): Validation Error Caused by: - In wgpuDeviceCreateShaderModule + In wgpuDeviceCreateShaderModule Shader validation error: ┌─ :9:16 │ 9 │ return vec3(1.0, 0.0, 1.0); - │ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [9] + │ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [8] - Entry point fs_main at Vertex is invalid - The `return` value Some([9]) does not match the function return value + Entry point fs_main at Vertex is invalid + The `return` value Some([8]) does not match the function return value """ code = dedent(code) diff --git a/tests_mem/test_gui.py b/tests_mem/test_gui.py index 482967f8..1ddb1576 100644 --- a/tests_mem/test_gui.py +++ b/tests_mem/test_gui.py @@ -61,6 +61,7 @@ def test_release_canvas_context(n): "expected_counts_after_create": { "CanvasContext": (n, 0), }, + "ignore": {"CommandBuffer"}, } canvases = weakref.WeakSet() @@ -80,13 +81,6 @@ def test_release_canvas_context(n): # Check that the canvas objects are really deleted assert not canvases - # This is a bit weird, but somehow this tests produces a dangling - # CommandBuffer for reasons likely related to the internals of - # wgpu-core. The lines below allocate and release a new - # CommandBuffer, which solves the issue :) - command_encoder = DEVICE.create_command_encoder() - command_encoder.finish() - TEST_FUNCS = [test_release_canvas_context] diff --git a/tests_mem/test_gui_glfw.py b/tests_mem/test_gui_glfw.py index 01b25f95..2cad4181 100644 --- a/tests_mem/test_gui_glfw.py +++ b/tests_mem/test_gui_glfw.py @@ -40,7 +40,9 @@ def test_release_canvas_context(n): from wgpu.gui.glfw import WgpuCanvas # noqa - yield {} + yield { + "ignore": {"CommandBuffer"}, + } canvases = weakref.WeakSet() @@ -61,10 +63,6 @@ def test_release_canvas_context(n): # Check that the canvas objects are really deleted assert not canvases, f"Still {len(canvases)} canvases" - # Help clear dangling CommandBuffer, see test_gui.py - command_encoder = DEVICE.create_command_encoder() - command_encoder.finish() - if __name__ == "__main__": # testutils.TEST_ITERS = 40 # Uncomment for a mem-usage test run diff --git a/tests_mem/test_objects.py b/tests_mem/test_objects.py index c67a1992..6aee8068 100644 --- a/tests_mem/test_objects.py +++ b/tests_mem/test_objects.py @@ -106,7 +106,6 @@ def test_release_command_buffer(n): # Note: a command encoder can only be used once (it gets destroyed on finish()) yield { "expected_counts_after_create": { - "CommandEncoder": (n, 0), "CommandBuffer": (n, n), }, } @@ -144,7 +143,10 @@ def test_release_compute_pass_encoder(n): } for i in range(n): - yield command_encoder.begin_compute_pass() + pass_encoder = command_encoder.begin_compute_pass() + yield pass_encoder + pass_encoder.end() + del pass_encoder @create_and_release @@ -217,7 +219,6 @@ def test_release_render_bundle_encoder(n): def test_release_render_bundle(n): yield { "expected_counts_after_create": { - "RenderBundleEncoder": (n, 0), "RenderBundle": (n, n), }, } @@ -230,7 +231,19 @@ def test_release_render_bundle(n): def test_release_render_pass_encoder(n): # Note: RenderPassEncoder does not really exist in wgpu-core # -> Check gpu.diagnostics.wgpu_native_counts.print_report(), nothing there that ends with "Encoder". + # Also, release() is called in end() - not sure if this will be forever. + command_encoder = DEVICE.create_command_encoder() + texture_view = DEVICE.create_texture( + size=(16, 16, 1), + usage=wgpu.TextureUsage.RENDER_ATTACHMENT, + format="rgba8unorm", + ).create_view() + ca = { + "view": texture_view, + "load_op": wgpu.LoadOp.load, + "store_op": wgpu.StoreOp.store, + } yield { "expected_counts_after_create": { @@ -239,7 +252,10 @@ def test_release_render_pass_encoder(n): } for i in range(n): - yield command_encoder.begin_render_pass(color_attachments=[]) + pass_encoder = command_encoder.begin_render_pass(color_attachments=[ca]) + yield pass_encoder + pass_encoder.end() + del pass_encoder @create_and_release diff --git a/tests_mem/testutils.py b/tests_mem/testutils.py index 09072962..b71d7eb6 100644 --- a/tests_mem/testutils.py +++ b/tests_mem/testutils.py @@ -104,11 +104,10 @@ def get_counts(): counts_native.get(key, default)["count"], ) counts.pop("total") - return counts -def get_excess_counts(counts1, counts2): +def get_excess_counts(counts1, counts2, ignore=()): """Compare two counts dicts, and return a new dict with the fields that have increased counts. """ @@ -126,6 +125,8 @@ def get_excess_counts(counts1, counts2): more_native = c2 - c1 if more_py or more_native: more[name] = more_py, more_native + for key in ignore: + more.pop(key, None) return more @@ -167,6 +168,7 @@ def core_test_func(): options = { "expected_counts_after_create": {ob_name: (n_objects, n_objects)}, "expected_counts_after_release": {}, + "ignore": (), } func_options = next(generator) @@ -198,7 +200,7 @@ def core_test_func(): # Measure peak object counts counts2 = get_counts() - more2 = get_excess_counts(counts1, counts2) + more2 = get_excess_counts(counts1, counts2, options["ignore"]) if not TEST_ITERS: print(" more after create:", more2) @@ -206,7 +208,7 @@ def core_test_func(): assert more2 # not empty assert ( more2 == options["expected_counts_after_create"] - ), f"Exepected:\n{options['expected_counts_after_create']}\nGot:\n{more2}" + ), f"Expected:\n{options['expected_counts_after_create']}\nGot:\n{more2}" # It's ok if other objects are created too ... @@ -218,7 +220,7 @@ def core_test_func(): # Measure after-release object counts counts3 = get_counts() - more3 = get_excess_counts(counts1, counts3) + more3 = get_excess_counts(counts1, counts3, options["ignore"]) if not TEST_ITERS: print(" more after release:", more3) diff --git a/wgpu/_classes.py b/wgpu/_classes.py index 0ed536f7..0dcde929 100644 --- a/wgpu/_classes.py +++ b/wgpu/_classes.py @@ -205,6 +205,7 @@ def configure( usage: "flags.TextureUsage" = 0x10, view_formats: "List[enums.TextureFormat]" = [], color_space: str = "srgb", + tone_mapping: "structs.CanvasToneMapping" = {}, alpha_mode: "enums.CanvasAlphaMode" = "opaque", ): """Configures the presentation context for the associated canvas. @@ -222,7 +223,8 @@ def configure( color_space (PredefinedColorSpace): The color space that values written into textures returned by ``get_current_texture()`` should be displayed with. Default "srgb". - alpha_mode (enums.CanvasAlphaMode): Determines the effect that alpha values + tone_mapping (enums.CanvasToneMappingMode): Not yet supported. + alpha_mode (structs.CanvasAlphaMode): Determines the effect that alpha values will have on the content of textures returned by ``get_current_texture()`` when read, displayed, or used as an image source. Default "opaque". """ @@ -380,16 +382,16 @@ def is_fallback_adapter(self): # IDL: [SameObject] readonly attribute GPUAdapterInfo info; @property def info(self): - """A dict with information about this adapter, such as the vendor and devicen name.""" + """A dict with information about this adapter, such as the vendor and device name.""" # Note: returns a dict rather than an GPUAdapterInfo instance. return self._adapter_info @apidiff.add("Useful in multi-gpu environments") @property def summary(self): - """A one-line summary of the info of this adapter (name, adapter_type, backend_type).""" + """A one-line summary of the info of this adapter (description, adapter_type, backend_type).""" d = self._adapter_info - return f"{d['device']} ({d['adapter_type']}) via {d['backend_type']}" + return f"{d['description']} ({d['adapter_type']}) via {d['backend_type']}" class GPUObjectBase: diff --git a/wgpu/backends/wgpu_native/__init__.py b/wgpu/backends/wgpu_native/__init__.py index c956fde9..69687101 100644 --- a/wgpu/backends/wgpu_native/__init__.py +++ b/wgpu/backends/wgpu_native/__init__.py @@ -9,8 +9,8 @@ # The wgpu-native version that we target/expect -__version__ = "0.19.4.1" -__commit_sha__ = "d89e5a93f5fd0bb3ce28f09571dbbefea37712c9" +__version__ = "22.1.0.2" +__commit_sha__ = "3e18e3d3e5fd433053875464447c36d980625f0b" version_info = tuple(map(int, __version__.split("."))) _check_expected_version(version_info) # produces a warning on mismatch diff --git a/wgpu/backends/wgpu_native/_api.py b/wgpu/backends/wgpu_native/_api.py index 46cdab28..67001826 100644 --- a/wgpu/backends/wgpu_native/_api.py +++ b/wgpu/backends/wgpu_native/_api.py @@ -279,7 +279,7 @@ def callback(status, result, message, userdata): nonlocal adapter_id adapter_id = result - # H: void f(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) + # H: void f(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPUInstanceRequestAdapterCallback callback, void * userdata) libf.wgpuInstanceRequestAdapter(get_wgpu_instance(), struct, callback, ffi.NULL) # For now, Rust will call the callback immediately @@ -320,48 +320,53 @@ def enumerate_adapters(self): def _create_adapter(self, adapter_id): # ----- Get adapter info - # H: nextInChain: WGPUChainedStructOut *, vendorID: int, vendorName: char *, architecture: char *, deviceID: int, name: char *, driverDescription: char *, adapterType: WGPUAdapterType, backendType: WGPUBackendType - c_properties = new_struct_p( - "WGPUAdapterProperties *", + # H: nextInChain: WGPUChainedStructOut *, vendor: char *, architecture: char *, device: char *, description: char *, backendType: WGPUBackendType, adapterType: WGPUAdapterType, vendorID: int, deviceID: int + c_info = new_struct_p( + "WGPUAdapterInfo *", # not used: nextInChain - # not used: deviceID - # not used: vendorID - # not used: name - # not used: driverDescription - # not used: adapterType - # not used: backendType - # not used: vendorName + # not used: vendor # not used: architecture + # not used: device + # not used: description + # not used: backendType + # not used: adapterType + # not used: vendorID + # not used: deviceID ) - # H: void f(WGPUAdapter adapter, WGPUAdapterProperties * properties) - libf.wgpuAdapterGetProperties(adapter_id, c_properties) + # H: void f(WGPUAdapter adapter, WGPUAdapterInfo * info) + libf.wgpuAdapterGetInfo(adapter_id, c_info) def to_py_str(key): - char_p = getattr(c_properties, key) + char_p = getattr(c_info, key) if char_p: return ffi.string(char_p).decode(errors="ignore") return "" # Populate a dict according to the WebGPU spec: https://gpuweb.github.io/gpuweb/#gpuadapterinfo # And add all other info we get from wgpu-native too. + # note: description is human readable. device is a PCI ID. adapter_info = { # Spec - "vendor": to_py_str("vendorName"), + "vendor": to_py_str("vendor"), "architecture": to_py_str("architecture"), - "device": to_py_str("name"), - "description": to_py_str("driverDescription"), + "device": to_py_str("device"), + "description": to_py_str("description"), # Extra - "vendor_id": c_properties.vendorID, - "device_id": c_properties.deviceID, + "vendor_id": int(c_info.vendorID), + "device_id": int(c_info.deviceID), "adapter_type": enum_int2str["AdapterType"].get( - c_properties.adapterType, "unknown" + c_info.adapterType, "unknown" ), "backend_type": enum_int2str["BackendType"].get( - c_properties.backendType, "unknown" + c_info.backendType, "unknown" ), } + # Allow Rust to release its string objects + # H: void f(WGPUAdapterInfo adapterInfo) + libf.wgpuAdapterInfoFreeMembers(c_info[0]) + # ----- Get adapter limits # H: nextInChain: WGPUChainedStructOut *, limits: WGPULimits @@ -380,7 +385,11 @@ def to_py_str(key): # WebGPU features features = set() for f in sorted(enums.FeatureName): - if f in ["clip-distances"]: + if f in [ + "clip-distances", + "dual-source-blending", + "texture-compression-bc-sliced-3d", + ]: continue # not supported by wgpu-native yet key = f"FeatureName.{f}" i = enummap[key] @@ -432,6 +441,7 @@ def configure( usage: "flags.TextureUsage" = 0x10, view_formats: "List[enums.TextureFormat]" = [], color_space: str = "srgb", + tone_mapping: "structs.CanvasToneMapping" = {}, alpha_mode: "enums.CanvasAlphaMode" = "opaque", ): # Handle inputs @@ -453,55 +463,10 @@ def configure( format = self.get_preferred_format(device.adapter) # The color_space is not used for now color_space - - # Get what's supported - - # H: nextInChain: WGPUChainedStructOut *, formatCount: int, formats: WGPUTextureFormat *, presentModeCount: int, presentModes: WGPUPresentMode *, alphaModeCount: int, alphaModes: WGPUCompositeAlphaMode * - capabilities = new_struct_p( - "WGPUSurfaceCapabilities *", - # not used: formatCount - # not used: formats - # not used: presentModeCount - # not used: presentModes - # not used: alphaModeCount - # not used: alphaModes - # not used: nextInChain - ) - # H: void f(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) - libf.wgpuSurfaceGetCapabilities( - self._get_surface_id(), self._device.adapter._internal, capabilities - ) - - capable_formats = [] - for i in range(capabilities.formatCount): - int_val = capabilities.formats[i] - capable_formats.append(enum_int2str["TextureFormat"][int_val]) - - capable_present_modes = [] - for i in range(capabilities.presentModeCount): - int_val = capabilities.presentModes[i] - str_val = enum_int2str["PresentMode"][int_val] - capable_present_modes.append(str_val.lower()) - - capable_alpha_modes = [] - for i in range(capabilities.alphaModeCount): - int_val = capabilities.alphaModes[i] - str_val = enum_int2str["CompositeAlphaMode"][int_val] - capable_alpha_modes.append(str_val.lower()) - - # H: void f(WGPUSurfaceCapabilities capabilities) - libf.wgpuSurfaceCapabilitiesFreeMembers(capabilities[0]) - - # Check if input is supported - - if format not in capable_formats: - raise ValueError( - f"Given format '{format}' is not in supported formats {capable_formats}" - ) - if alpha_mode not in capable_alpha_modes: - raise ValueError( - f"Given format '{alpha_mode}' is not in supported formats {capable_alpha_modes}" - ) + # Same for tone mapping + check_struct("CanvasToneMapping", tone_mapping) + tone_mapping_mode = tone_mapping.get("mode", "standard") + tone_mapping_mode # Select the present mode to determine vsync behavior. # * https://docs.rs/wgpu/latest/wgpu/enum.PresentMode.html @@ -520,8 +485,26 @@ def configure( present_mode_pref = ["fifo", "mailbox"] else: present_mode_pref = ["immediate", "mailbox", "fifo"] - present_modes = [p for p in present_mode_pref if p in capable_present_modes] - present_mode = (present_modes or capable_present_modes)[0] + + # Get what's supported + + capabilities = self._get_surface_capabilities(self._device.adapter) + + if format not in capabilities["formats"]: + raise ValueError( + f"Given format '{format}' is not in supported formats {capabilities['formats']}" + ) + + if alpha_mode not in capabilities["alpha_modes"]: + raise ValueError( + f"Given format '{alpha_mode}' is not in supported formats {capabilities['alpha_modes']}" + ) + + # Select present mode + present_modes = [ + p for p in present_mode_pref if p in capabilities["present_modes"] + ] + present_mode = (present_modes or capabilities["present_modes"])[0] c_present_mode = getattr(lib, f"WGPUPresentMode_{present_mode.capitalize()}") # Prepare config object @@ -717,11 +700,78 @@ def present(self): self._drop_texture() def get_preferred_format(self, adapter): - # H: WGPUTextureFormat f(WGPUSurface surface, WGPUAdapter adapter) - format = libf.wgpuSurfaceGetPreferredFormat( - self._get_surface_id(), adapter._internal + if self._config is not None: + # this shortcut might not be correct if a different format is specified during .configure() + return enum_int2str["TextureFormat"][self._config.format] + else: + return self._get_surface_capabilities(adapter)["formats"][0] + + def _get_surface_capabilities(self, adapter): + adapter_id = adapter._internal + + # H: nextInChain: WGPUChainedStructOut *, usages: WGPUTextureUsageFlags/int, formatCount: int, formats: WGPUTextureFormat *, presentModeCount: int, presentModes: WGPUPresentMode *, alphaModeCount: int, alphaModes: WGPUCompositeAlphaMode * + c_capabilities = new_struct_p( + "WGPUSurfaceCapabilities *", + # not used: nextInChain + # not used: usages + # not used: formatCount + # not used: formats + # not used: presentModeCount + # not used: presentModes + # not used: alphaModeCount + # not used: alphaModes ) - return enum_int2str["TextureFormat"][format] + + # H: void f(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) + libf.wgpuSurfaceGetCapabilities( + self._get_surface_id(), adapter_id, c_capabilities + ) + + # Convert to Python. + capabilities = {} + + # When the surface is found not to be compatible, the fields below may + # be null pointers. This probably means that the surface won't work, + # and trying to use it will result in an error (or Rust panic). Since + # I'm not sure what the best time/place to error would be, we pretend + # that everything is fine here, and populate the fields with values + # that wgpu-core claims are guaranteed to exist on any (compatible) + # surface. + + if c_capabilities.formats: + capabilities["formats"] = formats = [] + for i in range(c_capabilities.formatCount): + int_val = c_capabilities.formats[i] + formats.append(enum_int2str["TextureFormat"][int_val]) + + else: + capabilities["formats"] = [ + enums.TextureFormat.bgra8unorm_srgb, + enums.TextureFormat.bgra8unorm, + ] + + if c_capabilities.alphaModes: + 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()) + else: + capabilities["alpha_modes"] = [enums.CanvasAlphaMode.opaque] + + 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()) + else: + capabilities["present_modes"] = ["fifo"] + + # H: void f(WGPUSurfaceCapabilities surfaceCapabilities) + libf.wgpuSurfaceCapabilitiesFreeMembers(c_capabilities[0]) + + return capabilities def _release(self): self._drop_texture() @@ -827,14 +877,35 @@ def _request_device( def device_lost_callback(c_reason, c_message, userdata): reason = enum_int2str["DeviceLostReason"].get(c_reason, "Unknown") message = ffi.string(c_message).decode(errors="ignore") - error_handler.log_error(f"The WGPU device was lost ({reason}):\n{message}") + msg = f"The WGPU device was lost ({reason}):\n{message}" + # This is afaik an error that cannot usually be attributed to a specific call, + # so we cannot raise it as an error. We log it instead. + # WebGPU provides (promise-based) API for user-code to handle the error. + # We might want to do something similar, once we have async figured out. + error_handler.log_error(msg) + + # ----- Uncaptured error + + # TODO: For some errors (seen for errors in wgsl, but not for some others) the error gets logged via the logger as well (duplicate). Probably an issue with wgpu-core. + + @ffi.callback("void(WGPUErrorType, char *, void *)") + def uncaptured_error_callback(c_type, c_message, userdata): + error_type = enum_int2str["ErrorType"].get(c_type, "Unknown") + message = ffi.string(c_message).decode(errors="ignore") + message = "\n".join(line.rstrip() for line in message.splitlines()) + error_handler.handle_error(error_type, message) - # Keep the ref alive - self._device_lost_callback = device_lost_callback + # H: nextInChain: WGPUChainedStruct *, callback: WGPUErrorCallback, userdata: void * + uncaptured_error_callback_info = new_struct( + "WGPUUncapturedErrorCallbackInfo", + callback=uncaptured_error_callback, + userdata=ffi.NULL, + # not used: nextInChain + ) # ----- Request device - # H: nextInChain: WGPUChainedStruct *, label: char *, requiredFeatureCount: int, requiredFeatures: WGPUFeatureName *, requiredLimits: WGPURequiredLimits *, defaultQueue: WGPUQueueDescriptor, deviceLostCallback: WGPUDeviceLostCallback, deviceLostUserdata: void * + # H: nextInChain: WGPUChainedStruct *, label: char *, requiredFeatureCount: int, requiredFeatures: WGPUFeatureName *, requiredLimits: WGPURequiredLimits *, defaultQueue: WGPUQueueDescriptor, deviceLostCallback: WGPUDeviceLostCallback, deviceLostUserdata: void *, uncapturedErrorCallbackInfo: WGPUUncapturedErrorCallbackInfo struct = new_struct_p( "WGPUDeviceDescriptor *", label=to_c_label(label), @@ -844,6 +915,7 @@ def device_lost_callback(c_reason, c_message, userdata): requiredLimits=c_required_limits, defaultQueue=queue_struct, deviceLostCallback=device_lost_callback, + uncapturedErrorCallbackInfo=uncaptured_error_callback_info, # not used: deviceLostUserdata ) @@ -860,7 +932,7 @@ def callback(status, result, message, userdata): nonlocal device_id device_id = result - # H: void f(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) + # H: void f(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPUAdapterRequestDeviceCallback callback, void * userdata) libf.wgpuAdapterRequestDevice(self._internal, struct, callback, ffi.NULL) if device_id is None: # pragma: no cover @@ -885,7 +957,11 @@ def callback(status, result, message, userdata): # WebGPU features features = set() for f in sorted(enums.FeatureName): - if f in ["clip-distances"]: + if f in [ + "clip-distances", + "dual-source-blending", + "texture-compression-bc-sliced-3d", + ]: continue # not supported by wgpu-native yet key = f"FeatureName.{f}" i = enummap[key] @@ -907,7 +983,13 @@ def callback(status, result, message, userdata): # ----- Done - return GPUDevice(label, device_id, self, features, limits, queue) + device = GPUDevice(label, device_id, self, features, limits, queue) + + # Bind some things to the lifetime of the device + device._uncaptured_error_callback = uncaptured_error_callback + device._device_lost_callback = device_lost_callback + + return device async def request_device_async( self, @@ -934,21 +1016,6 @@ class GPUDevice(classes.GPUDevice, GPUObjectBase): def __init__(self, label, internal, adapter, features, limits, queue): super().__init__(label, internal, adapter, features, limits, queue) - @ffi.callback("void(WGPUErrorType, char *, void *)") - def uncaptured_error_callback(c_type, c_message, userdata): - error_type = enum_int2str["ErrorType"].get(c_type, "Unknown") - message = ffi.string(c_message).decode(errors="ignore") - message = "\n".join(line.rstrip() for line in message.splitlines()) - error_handler.handle_error(error_type, message) - - # Keep the ref alive - self._uncaptured_error_callback = uncaptured_error_callback - - # H: void f(WGPUDevice device, WGPUErrorCallback callback, void * userdata) - libf.wgpuDeviceSetUncapturedErrorCallback( - self._internal, uncaptured_error_callback, ffi.NULL - ) - def _poll(self): # Internal function if self._internal: @@ -1818,7 +1885,7 @@ def callback(status_, user_data_p): # Map it self._map_state = enums.BufferMapState.pending - # H: void f(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata) + # H: void f(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapAsyncCallback callback, void * userdata) libf.wgpuBufferMapAsync( self._internal, map_mode, offset, size, callback, ffi.NULL ) @@ -2095,7 +2162,7 @@ def get_compilation_info(self): # else: # pass # - # H: void f(WGPUShaderModule shaderModule, WGPUCompilationInfoCallback callback, void * userdata) + # H: void f(WGPUShaderModule shaderModule, WGPUShaderModuleGetCompilationInfoCallback callback, void * userdata) # libf.wgpuShaderModuleGetCompilationInfo(self._internal, callback, ffi.NULL) # # self._device._poll() @@ -2201,6 +2268,7 @@ def set_bind_group( class GPUDebugCommandsMixin(classes.GPUDebugCommandsMixin): + # whole class is likely going to solved better: https://github.com/pygfx/wgpu-py/pull/546 def push_debug_group(self, group_label): c_group_label = ffi.new("char []", group_label.encode()) # H: void wgpuCommandEncoderPushDebugGroup(WGPUCommandEncoder commandEncoder, char const * groupLabel) @@ -2332,8 +2400,9 @@ def begin_compute_pass( # not used: nextInChain ) # H: WGPUComputePassEncoder f(WGPUCommandEncoder commandEncoder, WGPUComputePassDescriptor const * descriptor) - raw_pass = libf.wgpuCommandEncoderBeginComputePass(self._internal, struct) - return GPUComputePassEncoder(label, raw_pass, self) + raw_encoder = libf.wgpuCommandEncoderBeginComputePass(self._internal, struct) + encoder = GPUComputePassEncoder(label, raw_encoder, self) + return encoder def begin_render_pass( self, @@ -2389,7 +2458,7 @@ def begin_render_pass( b=clear_value[2], a=clear_value[3], ) - # H: nextInChain: WGPUChainedStruct *, view: WGPUTextureView, resolveTarget: WGPUTextureView, loadOp: WGPULoadOp, storeOp: WGPUStoreOp, clearValue: WGPUColor + # H: nextInChain: WGPUChainedStruct *, view: WGPUTextureView, depthSlice: int, resolveTarget: WGPUTextureView, loadOp: WGPULoadOp, storeOp: WGPUStoreOp, clearValue: WGPUColor c_attachment = new_struct( "WGPURenderPassColorAttachment", view=texture_view_id, @@ -2397,6 +2466,7 @@ def begin_render_pass( loadOp=color_attachment["load_op"], storeOp=color_attachment["store_op"], clearValue=c_clear_value, + depthSlice=lib.WGPU_DEPTH_SLICE_UNDEFINED, # not implemented yet # not used: resolveTarget # not used: nextInChain ) @@ -2444,8 +2514,8 @@ def begin_render_pass( ) # H: WGPURenderPassEncoder f(WGPUCommandEncoder commandEncoder, WGPURenderPassDescriptor const * descriptor) - raw_pass = libf.wgpuCommandEncoderBeginRenderPass(self._internal, struct) - encoder = GPURenderPassEncoder(label, raw_pass, self) + raw_encoder = libf.wgpuCommandEncoderBeginRenderPass(self._internal, struct) + encoder = GPURenderPassEncoder(label, raw_encoder, self) encoder._objects_to_keep_alive = objects_to_keep_alive return encoder @@ -2681,7 +2751,7 @@ def finish(self, *, label=""): ) # H: WGPUCommandBuffer f(WGPUCommandEncoder commandEncoder, WGPUCommandBufferDescriptor const * descriptor) id = libf.wgpuCommandEncoderFinish(self._internal, struct) - return GPUCommandBuffer(label, id, self) + return GPUCommandBuffer(label, id, self._device) def resolve_query_set( self, query_set, first_query, query_count, destination, destination_offset @@ -2712,7 +2782,6 @@ class GPUComputePassEncoder( GPUBindingCommandsMixin, GPUObjectBase, ): - """ """ # GPUDebugCommandsMixin _push_debug_group_function = libf.wgpuComputePassEncoderPushDebugGroup @@ -2722,6 +2791,8 @@ class GPUComputePassEncoder( # GPUBindingCommandsMixin _set_bind_group_function = libf.wgpuComputePassEncoderSetBindGroup + _ended = False + def set_pipeline(self, pipeline): pipeline_id = pipeline._internal # H: void f(WGPUComputePassEncoder computePassEncoder, WGPUComputePipeline pipeline) @@ -2745,6 +2816,9 @@ def dispatch_workgroups_indirect(self, indirect_buffer, indirect_offset): def end(self): # H: void f(WGPUComputePassEncoder computePassEncoder) libf.wgpuComputePassEncoderEnd(self._internal) + self._ended = True + # Need to release, see https://github.com/gfx-rs/wgpu-native/issues/412 + self._release() def _release(self): if self._internal is not None and libf is not None: @@ -2778,6 +2852,8 @@ class GPURenderPassEncoder( _draw_indexed_function = libf.wgpuRenderPassEncoderDrawIndexed _draw_indexed_indirect_function = libf.wgpuRenderPassEncoderDrawIndexedIndirect + _ended = False + def set_viewport(self, x, y, width, height, min_depth, max_depth): # H: void f(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth) libf.wgpuRenderPassEncoderSetViewport( @@ -2816,6 +2892,9 @@ def set_stencil_reference(self, reference): def end(self): # H: void f(WGPURenderPassEncoder renderPassEncoder) libf.wgpuRenderPassEncoderEnd(self._internal) + self._ended = True + # Need to release, see https://github.com/gfx-rs/wgpu-native/issues/412 + self._release() def execute_bundles(self, bundles): bundle_ids = [bundle._internal for bundle in bundles] @@ -2874,7 +2953,7 @@ def finish(self, *, label=""): ) # H: WGPURenderBundle f(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderBundleDescriptor const * descriptor) id = libf.wgpuRenderBundleEncoderFinish(self._internal, struct) - return GPURenderBundle(label, id, self) + return GPURenderBundle(label, id, self._device) def _release(self): if self._internal is not None and libf is not None: @@ -3079,8 +3158,29 @@ def read_texture(self, source, data_layout, size): return data def on_submitted_work_done(self): + # In JS, this returns a Promise that can be awaited to (async) wait + # for the work that is currently in the pipeline. We need to figure out + # how to expose these async parts. raise NotImplementedError() + status = 999 + + @ffi.callback("void(WGPUQueueWorkDoneStatus, void*)") + def callback(status_, user_data_p): + nonlocal status + status = status_ + # -> here we must resolve the promise, or something + + # H: void f(WGPUQueue queue, WGPUQueueOnSubmittedWorkDoneCallback callback, void * userdata) + libf.wgpuQueueOnSubmittedWorkDone(self._internal, callback, ffi.NULL) + + # Wait for the queue to process all tasks (including the mapping of the buffer). + # Also see WebGPU's onSubmittedWorkDone() and C's WGPUQueueWorkDoneCallback. + self._device._poll() + + if status != 0: + raise RuntimeError(f"Queue work done status: {status}") + def _release(self): if self._internal is not None and libf is not None: self._internal, internal = None, self._internal diff --git a/wgpu/backends/wgpu_native/_helpers.py b/wgpu/backends/wgpu_native/_helpers.py index 1386ab8d..24c5cda5 100644 --- a/wgpu/backends/wgpu_native/_helpers.py +++ b/wgpu/backends/wgpu_native/_helpers.py @@ -5,7 +5,7 @@ import ctypes from queue import deque -from ._ffi import ffi, lib +from ._ffi import ffi, lib, lib_path from ..._diagnostics import DiagnosticsBase from ...classes import ( GPUError, @@ -107,8 +107,9 @@ def get_surface_id_from_canvas(canvas): surface_info = canvas.get_surface_info() if sys.platform.startswith("win"): # no-cover + GetModuleHandle = ctypes.windll.kernel32.GetModuleHandleW # noqa struct = ffi.new("WGPUSurfaceDescriptorFromWindowsHWND *") - struct.hinstance = ffi.NULL + struct.hinstance = ffi.cast("void *", GetModuleHandle(lib_path)) struct.hwnd = ffi.cast("void *", int(surface_info["window"])) struct.chain.sType = lib.WGPUSType_SurfaceDescriptorFromWindowsHWND diff --git a/wgpu/backends/wgpu_native/_mappings.py b/wgpu/backends/wgpu_native/_mappings.py index 43be8070..b33712b9 100644 --- a/wgpu/backends/wgpu_native/_mappings.py +++ b/wgpu/backends/wgpu_native/_mappings.py @@ -4,7 +4,7 @@ # flake8: noqa -# There are 235 enum mappings +# There are 236 enum mappings enummap = { "AddressMode.clamp-to-edge": 2, @@ -48,7 +48,8 @@ "CullMode.back": 2, "CullMode.front": 1, "CullMode.none": 0, - "DeviceLostReason.destroyed": 1, + "DeviceLostReason.destroyed": 2, + "DeviceLostReason.unknown": 1, "ErrorFilter.internal": 2, "ErrorFilter.out-of-memory": 1, "ErrorFilter.validation": 0, @@ -319,6 +320,19 @@ "pipeline-statistics-query": 196616, "storage-resource-binding-array": 196617, "partially-bound-binding-array": 196618, + "texture-format16bit-norm": 196619, + "texture-compression-astc-hdr": 196620, + "mappable-primary-buffers": 196622, + "buffer-binding-array": 196623, + "uniform-buffer-and-storage-texture-array-non-uniform-indexing": 196624, + "vertex-attribute64bit": 196633, + "texture-format-nv12": 196634, + "ray-tracing-acceleration-structure": 196635, + "ray-query": 196636, + "shader-f64": 196637, + "shader-i16": 196638, + "shader-primitive-index": 196639, + "shader-early-depth-test": 196640, }, } enum_int2str = { @@ -348,8 +362,8 @@ 5: "DeviceLost", }, "DeviceLostReason": { - 0: "unknown", - 1: "destroyed", + 1: "unknown", + 2: "destroyed", }, "TextureFormat": { 0: "Undefined", diff --git a/wgpu/enums.py b/wgpu/enums.py index bd8f7699..5a713341 100644 --- a/wgpu/enums.py +++ b/wgpu/enums.py @@ -18,7 +18,7 @@ class Enum(_BaseEnum): # CODE BELOW THIS POINT IS AUTOGENERATED - DO NOT EDIT -# There are 33 enums +# There are 34 enums __all__ = [ "PowerPreference", @@ -52,6 +52,7 @@ class Enum(_BaseEnum): "StoreOp", "QueryType", "CanvasAlphaMode", + "CanvasToneMappingMode", "DeviceLostReason", "ErrorFilter", ] @@ -68,6 +69,7 @@ class FeatureName(Enum): depth_clip_control = "depth-clip-control" depth32float_stencil8 = "depth32float-stencil8" texture_compression_bc = "texture-compression-bc" + texture_compression_bc_sliced_d3 = "texture-compression-bc-sliced-3d" texture_compression_etc2 = "texture-compression-etc2" texture_compression_astc = "texture-compression-astc" timestamp_query = "timestamp-query" @@ -77,6 +79,7 @@ class FeatureName(Enum): bgra8unorm_storage = "bgra8unorm-storage" float32_filterable = "float32-filterable" clip_distances = "clip-distances" + dual_source_blending = "dual-source-blending" class BufferMapState(Enum): @@ -325,6 +328,10 @@ class BlendFactor(Enum): src_alpha_saturated = "src-alpha-saturated" constant = "constant" one_minus_constant = "one-minus-constant" + src1 = "src1" + one_minus_src1 = "one-minus-src1" + src1_alpha = "src1-alpha" + one_minus_src1_alpha = "one-minus-src1-alpha" class BlendOperation(Enum): @@ -419,6 +426,12 @@ class CanvasAlphaMode(Enum): premultiplied = "premultiplied" +class CanvasToneMappingMode(Enum): + + standard = "standard" + extended = "extended" + + class DeviceLostReason(Enum): unknown = "unknown" diff --git a/wgpu/resources/codegen_report.md b/wgpu/resources/codegen_report.md index 44bd9b44..ce53a383 100644 --- a/wgpu/resources/codegen_report.md +++ b/wgpu/resources/codegen_report.md @@ -1,13 +1,13 @@ # Code generatation report ## Preparing * The webgpu.idl defines 37 classes with 75 functions -* The webgpu.idl defines 5 flags, 33 enums, 59 structs -* The wgpu.h defines 198 functions -* The wgpu.h defines 7 flags, 50 enums, 93 structs +* The webgpu.idl defines 5 flags, 34 enums, 60 structs +* The wgpu.h defines 199 functions +* The wgpu.h defines 7 flags, 52 enums, 93 structs ## Updating API * Wrote 5 flags to flags.py -* Wrote 33 enums to enums.py -* Wrote 59 structs to structs.py +* Wrote 34 enums to enums.py +* Wrote 60 structs to structs.py ### Patching API for _classes.py * Diffs for GPU: add enumerate_adapters, add enumerate_adapters_async, change get_preferred_canvas_format, change request_adapter, change request_adapter_async * Diffs for GPUCanvasContext: add get_preferred_format, add present @@ -20,15 +20,21 @@ * Diffs for GPUQueue: add read_buffer, add read_texture, hide copy_external_image_to_texture * Validated 37 classes, 112 methods, 45 properties ### Patching API for backends/wgpu_native/_api.py -* Validated 37 classes, 111 methods, 0 properties +* Validated 37 classes, 112 methods, 0 properties ## Validating backends/wgpu_native/_api.py +* Enum field FeatureName.texture-compression-bc-sliced-3d missing in wgpu.h * Enum field FeatureName.clip-distances missing in wgpu.h +* Enum field FeatureName.dual-source-blending missing in wgpu.h * Enum PipelineErrorReason missing in wgpu.h * Enum AutoLayoutMode missing in wgpu.h +* Enum field BlendFactor.src1 missing in wgpu.h +* Enum field BlendFactor.one-minus-src1 missing in wgpu.h +* Enum field BlendFactor.src1-alpha missing in wgpu.h +* Enum field BlendFactor.one-minus-src1-alpha missing in wgpu.h * Enum field VertexFormat.unorm10-10-10-2 missing in wgpu.h * Enum CanvasAlphaMode missing in wgpu.h -* Enum field DeviceLostReason.unknown missing in wgpu.h -* Wrote 235 enum mappings and 47 struct-field mappings to wgpu_native/_mappings.py +* Enum CanvasToneMappingMode missing in wgpu.h +* Wrote 236 enum mappings and 47 struct-field mappings to wgpu_native/_mappings.py * Validated 132 C function calls -* Not using 72 C functions -* Validated 77 C structs +* Not using 73 C functions +* Validated 78 C structs diff --git a/wgpu/resources/webgpu.h b/wgpu/resources/webgpu.h index d2533513..cb423fc0 100644 --- a/wgpu/resources/webgpu.h +++ b/wgpu/resources/webgpu.h @@ -1,32 +1,20 @@ -// BSD 3-Clause License -// -// Copyright (c) 2019, "WebGPU native" developers -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/** + * Copyright 2019-2023 WebGPU-Native developers + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** @file */ + +/** + * \mainpage + * + * **Important:** *This documentation is a Work In Progress.* + * + * This is the home of WebGPU C API specification. We define here the standard + * `webgpu.h` header that all implementations should provide. + */ + #ifndef WEBGPU_H_ #define WEBGPU_H_ @@ -67,18 +55,44 @@ #include #include + +/** + * \defgroup Constants + * \brief Constants. + * + * @{ + */ #define WGPU_ARRAY_LAYER_COUNT_UNDEFINED (0xffffffffUL) #define WGPU_COPY_STRIDE_UNDEFINED (0xffffffffUL) +#define WGPU_DEPTH_SLICE_UNDEFINED (0xffffffffUL) #define WGPU_LIMIT_U32_UNDEFINED (0xffffffffUL) #define WGPU_LIMIT_U64_UNDEFINED (0xffffffffffffffffULL) #define WGPU_MIP_LEVEL_COUNT_UNDEFINED (0xffffffffUL) #define WGPU_QUERY_SET_INDEX_UNDEFINED (0xffffffffUL) -#define WGPU_WHOLE_MAP_SIZE SIZE_MAX +#define WGPU_WHOLE_MAP_SIZE (SIZE_MAX) #define WGPU_WHOLE_SIZE (0xffffffffffffffffULL) + +/** @} */ + +/** + * \defgroup Typedefs + * \brief Utility typedefs. + * + * @{ + */ typedef uint32_t WGPUFlags; typedef uint32_t WGPUBool; + +/** @} */ + +/** + * \defgroup Objects + * \brief Opaque, non-dispatchable handles to WebGPU objects. + * + * @{ + */ typedef struct WGPUAdapterImpl* WGPUAdapter WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUBindGroupImpl* WGPUBindGroup WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUBindGroupLayoutImpl* WGPUBindGroupLayout WGPU_OBJECT_ATTRIBUTE; @@ -102,8 +116,10 @@ typedef struct WGPUSurfaceImpl* WGPUSurface WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUTextureImpl* WGPUTexture WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUTextureViewImpl* WGPUTextureView WGPU_OBJECT_ATTRIBUTE; + +/** @} */ // Structure forward declarations -struct WGPUAdapterProperties; +struct WGPUAdapterInfo; struct WGPUBindGroupEntry; struct WGPUBlendComponent; struct WGPUBufferBindingLayout; @@ -151,6 +167,7 @@ struct WGPUSurfaceTexture; struct WGPUTextureBindingLayout; struct WGPUTextureDataLayout; struct WGPUTextureViewDescriptor; +struct WGPUUncapturedErrorCallbackInfo; struct WGPUVertexAttribute; struct WGPUBindGroupDescriptor; struct WGPUBindGroupLayoutEntry; @@ -176,6 +193,13 @@ struct WGPUVertexState; struct WGPUFragmentState; struct WGPURenderPipelineDescriptor; + +/** + * \defgroup Enumerations + * \brief Enums. + * + * @{ + */ typedef enum WGPUAdapterType { WGPUAdapterType_DiscreteGPU = 0x00000000, WGPUAdapterType_IntegratedGPU = 0x00000001, @@ -313,8 +337,8 @@ typedef enum WGPUCullMode { } WGPUCullMode WGPU_ENUM_ATTRIBUTE; typedef enum WGPUDeviceLostReason { - WGPUDeviceLostReason_Undefined = 0x00000000, - WGPUDeviceLostReason_Destroyed = 0x00000001, + WGPUDeviceLostReason_Unknown = 0x00000001, + WGPUDeviceLostReason_Destroyed = 0x00000002, WGPUDeviceLostReason_Force32 = 0x7FFFFFFF } WGPUDeviceLostReason WGPU_ENUM_ATTRIBUTE; @@ -674,6 +698,24 @@ typedef enum WGPUVertexStepMode { WGPUVertexStepMode_Force32 = 0x7FFFFFFF } WGPUVertexStepMode WGPU_ENUM_ATTRIBUTE; +typedef enum WGPUWGSLFeatureName { + WGPUWGSLFeatureName_Undefined = 0x00000000, + WGPUWGSLFeatureName_ReadonlyAndReadwriteStorageTextures = 0x00000001, + WGPUWGSLFeatureName_Packed4x8IntegerDotProduct = 0x00000002, + WGPUWGSLFeatureName_UnrestrictedPointerParameters = 0x00000003, + WGPUWGSLFeatureName_PointerCompositeAccess = 0x00000004, + WGPUWGSLFeatureName_Force32 = 0x7FFFFFFF +} WGPUWGSLFeatureName WGPU_ENUM_ATTRIBUTE; + + +/** @} */ + +/** + * \defgroup Bitflags + * \brief Enum used as bit flags. + * + * @{ + */ typedef enum WGPUBufferUsage { WGPUBufferUsage_None = 0x00000000, WGPUBufferUsage_MapRead = 0x00000001, @@ -696,7 +738,7 @@ typedef enum WGPUColorWriteMask { WGPUColorWriteMask_Green = 0x00000002, WGPUColorWriteMask_Blue = 0x00000004, WGPUColorWriteMask_Alpha = 0x00000008, - WGPUColorWriteMask_All = 0x0000000F, + WGPUColorWriteMask_All = WGPUColorWriteMask_None | WGPUColorWriteMask_Red | WGPUColorWriteMask_Green | WGPUColorWriteMask_Blue | WGPUColorWriteMask_Alpha, WGPUColorWriteMask_Force32 = 0x7FFFFFFF } WGPUColorWriteMask WGPU_ENUM_ATTRIBUTE; typedef WGPUFlags WGPUColorWriteMaskFlags WGPU_ENUM_ATTRIBUTE; @@ -729,16 +771,36 @@ typedef enum WGPUTextureUsage { } WGPUTextureUsage WGPU_ENUM_ATTRIBUTE; typedef WGPUFlags WGPUTextureUsageFlags WGPU_ENUM_ATTRIBUTE; -typedef void (*WGPUBufferMapCallback)(WGPUBufferMapAsyncStatus status, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUCompilationInfoCallback)(WGPUCompilationInfoRequestStatus status, struct WGPUCompilationInfo const * compilationInfo, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUCreateComputePipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUCreateRenderPipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; + +/** @} */ +typedef void (*WGPUProc)(void) WGPU_FUNCTION_ATTRIBUTE; + typedef void (*WGPUDeviceLostCallback)(WGPUDeviceLostReason reason, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUErrorCallback)(WGPUErrorType type, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProc)(void) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUQueueWorkDoneCallback)(WGPUQueueWorkDoneStatus status, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPURequestAdapterCallback)(WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPURequestDeviceCallback)(WGPURequestDeviceStatus status, WGPUDevice device, char const * message, void * userdata) WGPU_FUNCTION_ATTRIBUTE; + +/** + * \defgroup Callbacks + * \brief Callbacks through which asynchronous functions return. + * + * @{ + */ + +typedef void (*WGPUAdapterRequestDeviceCallback)(WGPURequestDeviceStatus status, WGPUDevice device, char const * message, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUBufferMapAsyncCallback)(WGPUBufferMapAsyncStatus status, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUDeviceCreateComputePipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, char const * message, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUDeviceCreateRenderPipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, char const * message, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUInstanceRequestAdapterCallback)(WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUQueueOnSubmittedWorkDoneCallback)(WGPUQueueWorkDoneStatus status, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUShaderModuleGetCompilationInfoCallback)(WGPUCompilationInfoRequestStatus status, struct WGPUCompilationInfo const * compilationInfo, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; + + +/** @} */ +/** + * \defgroup ChainedStructures Chained Structures + * \brief Structures used to extend descriptors. + * + * @{ + */ typedef struct WGPUChainedStruct { struct WGPUChainedStruct const * next; @@ -750,17 +812,26 @@ typedef struct WGPUChainedStructOut { WGPUSType sType; } WGPUChainedStructOut WGPU_STRUCTURE_ATTRIBUTE; -typedef struct WGPUAdapterProperties { +/** @} */ + + +/** + * \defgroup Structures + * \brief Descriptors and other transparent structures. + * + * @{ + */ +typedef struct WGPUAdapterInfo { WGPUChainedStructOut * nextInChain; - uint32_t vendorID; - char const * vendorName; + char const * vendor; char const * architecture; - uint32_t deviceID; - char const * name; - char const * driverDescription; - WGPUAdapterType adapterType; + char const * device; + char const * description; WGPUBackendType backendType; -} WGPUAdapterProperties WGPU_STRUCTURE_ATTRIBUTE; + WGPUAdapterType adapterType; + uint32_t vendorID; + uint32_t deviceID; +} WGPUAdapterInfo WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUBindGroupEntry { WGPUChainedStruct const * nextInChain; @@ -900,7 +971,6 @@ typedef struct WGPUPipelineLayoutDescriptor { WGPUBindGroupLayout const * bindGroupLayouts; } WGPUPipelineLayoutDescriptor WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUPrimitiveState typedef struct WGPUPrimitiveDepthClipControl { WGPUChainedStruct chain; WGPUBool unclippedDepth; @@ -954,7 +1024,6 @@ typedef struct WGPURenderPassDepthStencilAttachment { WGPUBool stencilReadOnly; } WGPURenderPassDepthStencilAttachment WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPURenderPassDescriptor typedef struct WGPURenderPassDescriptorMaxDrawCount { WGPUChainedStruct chain; uint64_t maxDrawCount; @@ -1000,14 +1069,12 @@ typedef struct WGPUShaderModuleCompilationHint { WGPUPipelineLayout layout; } WGPUShaderModuleCompilationHint WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUShaderModuleDescriptor typedef struct WGPUShaderModuleSPIRVDescriptor { WGPUChainedStruct chain; uint32_t codeSize; uint32_t const * code; } WGPUShaderModuleSPIRVDescriptor WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUShaderModuleDescriptor typedef struct WGPUShaderModuleWGSLDescriptor { WGPUChainedStruct chain; char const * code; @@ -1029,12 +1096,13 @@ typedef struct WGPUStorageTextureBindingLayout { typedef struct WGPUSurfaceCapabilities { WGPUChainedStructOut * nextInChain; + WGPUTextureUsageFlags usages; size_t formatCount; - WGPUTextureFormat * formats; + WGPUTextureFormat const * formats; size_t presentModeCount; - WGPUPresentMode * presentModes; + WGPUPresentMode const * presentModes; size_t alphaModeCount; - WGPUCompositeAlphaMode * alphaModes; + WGPUCompositeAlphaMode const * alphaModes; } WGPUSurfaceCapabilities WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUSurfaceConfiguration { @@ -1055,46 +1123,39 @@ typedef struct WGPUSurfaceDescriptor { WGPU_NULLABLE char const * label; } WGPUSurfaceDescriptor WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromAndroidNativeWindow { WGPUChainedStruct chain; void * window; } WGPUSurfaceDescriptorFromAndroidNativeWindow WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromCanvasHTMLSelector { WGPUChainedStruct chain; char const * selector; } WGPUSurfaceDescriptorFromCanvasHTMLSelector WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromMetalLayer { WGPUChainedStruct chain; void * layer; } WGPUSurfaceDescriptorFromMetalLayer WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromWaylandSurface { WGPUChainedStruct chain; void * display; void * surface; } WGPUSurfaceDescriptorFromWaylandSurface WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromWindowsHWND { WGPUChainedStruct chain; void * hinstance; void * hwnd; } WGPUSurfaceDescriptorFromWindowsHWND WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromXcbWindow { WGPUChainedStruct chain; void * connection; uint32_t window; } WGPUSurfaceDescriptorFromXcbWindow WGPU_STRUCTURE_ATTRIBUTE; -// Can be chained in WGPUSurfaceDescriptor typedef struct WGPUSurfaceDescriptorFromXlibWindow { WGPUChainedStruct chain; void * display; @@ -1133,6 +1194,12 @@ typedef struct WGPUTextureViewDescriptor { WGPUTextureAspect aspect; } WGPUTextureViewDescriptor WGPU_STRUCTURE_ATTRIBUTE; +typedef struct WGPUUncapturedErrorCallbackInfo { + WGPUChainedStruct const * nextInChain; + WGPUErrorCallback callback; + void * userdata; +} WGPUUncapturedErrorCallbackInfo WGPU_STRUCTURE_ATTRIBUTE; + typedef struct WGPUVertexAttribute { WGPUVertexFormat format; uint64_t offset; @@ -1213,6 +1280,7 @@ typedef struct WGPUProgrammableStageDescriptor { typedef struct WGPURenderPassColorAttachment { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE WGPUTextureView view; + uint32_t depthSlice; WGPU_NULLABLE WGPUTextureView resolveTarget; WGPULoadOp loadOp; WGPUStoreOp storeOp; @@ -1286,6 +1354,7 @@ typedef struct WGPUDeviceDescriptor { WGPUQueueDescriptor defaultQueue; WGPUDeviceLostCallback deviceLostCallback; void * deviceLostUserdata; + WGPUUncapturedErrorCallbackInfo uncapturedErrorCallbackInfo; } WGPUDeviceDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPURenderPassDescriptor { @@ -1329,6 +1398,8 @@ typedef struct WGPURenderPipelineDescriptor { WGPU_NULLABLE WGPUFragmentState const * fragment; } WGPURenderPipelineDescriptor WGPU_STRUCTURE_ATTRIBUTE; +/** @} */ + #ifdef __cplusplus extern "C" { #endif @@ -1340,13 +1411,16 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procN // Procs of Adapter typedef size_t (*WGPUProcAdapterEnumerateFeatures)(WGPUAdapter adapter, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcAdapterGetInfo)(WGPUAdapter adapter, WGPUAdapterInfo * info) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUBool (*WGPUProcAdapterGetLimits)(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcAdapterGetProperties)(WGPUAdapter adapter, WGPUAdapterProperties * properties) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUBool (*WGPUProcAdapterHasFeature)(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcAdapterRequestDevice)(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcAdapterRequestDevice)(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPUAdapterRequestDeviceCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterReference)(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterRelease)(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; +// Procs of AdapterInfo +typedef void (*WGPUProcAdapterInfoFreeMembers)(WGPUAdapterInfo adapterInfo) WGPU_FUNCTION_ATTRIBUTE; + // Procs of BindGroup typedef void (*WGPUProcBindGroupSetLabel)(WGPUBindGroup bindGroup, char const * label) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcBindGroupReference)(WGPUBindGroup bindGroup) WGPU_FUNCTION_ATTRIBUTE; @@ -1364,7 +1438,7 @@ typedef WGPUBufferMapState (*WGPUProcBufferGetMapState)(WGPUBuffer buffer) WGPU_ typedef void * (*WGPUProcBufferGetMappedRange)(WGPUBuffer buffer, size_t offset, size_t size) WGPU_FUNCTION_ATTRIBUTE; typedef uint64_t (*WGPUProcBufferGetSize)(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUBufferUsageFlags (*WGPUProcBufferGetUsage)(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcBufferMapAsync)(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcBufferMapAsync)(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcBufferSetLabel)(WGPUBuffer buffer, char const * label) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcBufferUnmap)(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcBufferReference)(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; @@ -1418,12 +1492,12 @@ typedef WGPUBindGroupLayout (*WGPUProcDeviceCreateBindGroupLayout)(WGPUDevice de typedef WGPUBuffer (*WGPUProcDeviceCreateBuffer)(WGPUDevice device, WGPUBufferDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUCommandEncoder (*WGPUProcDeviceCreateCommandEncoder)(WGPUDevice device, WGPU_NULLABLE WGPUCommandEncoderDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUComputePipeline (*WGPUProcDeviceCreateComputePipeline)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcDeviceCreateComputePipelineAsync)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcDeviceCreateComputePipelineAsync)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUDeviceCreateComputePipelineAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUPipelineLayout (*WGPUProcDeviceCreatePipelineLayout)(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUQuerySet (*WGPUProcDeviceCreateQuerySet)(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPURenderBundleEncoder (*WGPUProcDeviceCreateRenderBundleEncoder)(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPURenderPipeline (*WGPUProcDeviceCreateRenderPipeline)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcDeviceCreateRenderPipelineAsync)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcDeviceCreateRenderPipelineAsync)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUDeviceCreateRenderPipelineAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUSampler (*WGPUProcDeviceCreateSampler)(WGPUDevice device, WGPU_NULLABLE WGPUSamplerDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUShaderModule (*WGPUProcDeviceCreateShaderModule)(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUTexture (*WGPUProcDeviceCreateTexture)(WGPUDevice device, WGPUTextureDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; @@ -1435,14 +1509,14 @@ typedef WGPUBool (*WGPUProcDeviceHasFeature)(WGPUDevice device, WGPUFeatureName typedef void (*WGPUProcDevicePopErrorScope)(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDevicePushErrorScope)(WGPUDevice device, WGPUErrorFilter filter) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDeviceSetLabel)(WGPUDevice device, char const * label) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcDeviceSetUncapturedErrorCallback)(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDeviceReference)(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDeviceRelease)(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; // Procs of Instance typedef WGPUSurface (*WGPUProcInstanceCreateSurface)(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUBool (*WGPUProcInstanceHasWGSLLanguageFeature)(WGPUInstance instance, WGPUWGSLFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcInstanceProcessEvents)(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcInstanceRequestAdapter)(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcInstanceRequestAdapter)(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPUInstanceRequestAdapterCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcInstanceReference)(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcInstanceRelease)(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; @@ -1460,7 +1534,7 @@ typedef void (*WGPUProcQuerySetReference)(WGPUQuerySet querySet) WGPU_FUNCTION_A typedef void (*WGPUProcQuerySetRelease)(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; // Procs of Queue -typedef void (*WGPUProcQueueOnSubmittedWorkDone)(WGPUQueue queue, WGPUQueueWorkDoneCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcQueueOnSubmittedWorkDone)(WGPUQueue queue, WGPUQueueOnSubmittedWorkDoneCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcQueueSetLabel)(WGPUQueue queue, char const * label) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcQueueSubmit)(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcQueueWriteBuffer)(WGPUQueue queue, WGPUBuffer buffer, uint64_t bufferOffset, void const * data, size_t size) WGPU_FUNCTION_ATTRIBUTE; @@ -1526,7 +1600,7 @@ typedef void (*WGPUProcSamplerReference)(WGPUSampler sampler) WGPU_FUNCTION_ATTR typedef void (*WGPUProcSamplerRelease)(WGPUSampler sampler) WGPU_FUNCTION_ATTRIBUTE; // Procs of ShaderModule -typedef void (*WGPUProcShaderModuleGetCompilationInfo)(WGPUShaderModule shaderModule, WGPUCompilationInfoCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcShaderModuleGetCompilationInfo)(WGPUShaderModule shaderModule, WGPUShaderModuleGetCompilationInfoCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcShaderModuleSetLabel)(WGPUShaderModule shaderModule, char const * label) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcShaderModuleReference)(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcShaderModuleRelease)(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; @@ -1535,14 +1609,14 @@ typedef void (*WGPUProcShaderModuleRelease)(WGPUShaderModule shaderModule) WGPU_ typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUSurfaceConfiguration const * config) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceGetCapabilities)(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceGetCurrentTexture)(WGPUSurface surface, WGPUSurfaceTexture * surfaceTexture) WGPU_FUNCTION_ATTRIBUTE; -typedef WGPUTextureFormat (*WGPUProcSurfaceGetPreferredFormat)(WGPUSurface surface, WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfacePresent)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfaceSetLabel)(WGPUSurface surface, char const * label) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceUnconfigure)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceReference)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceRelease)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; // Procs of SurfaceCapabilities -typedef void (*WGPUProcSurfaceCapabilitiesFreeMembers)(WGPUSurfaceCapabilities capabilities) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfaceCapabilitiesFreeMembers)(WGPUSurfaceCapabilities surfaceCapabilities) WGPU_FUNCTION_ATTRIBUTE; // Procs of Texture typedef WGPUTextureView (*WGPUProcTextureCreateView)(WGPUTexture texture, WGPU_NULLABLE WGPUTextureViewDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; @@ -1567,48 +1641,119 @@ typedef void (*WGPUProcTextureViewRelease)(WGPUTextureView textureView) WGPU_FUN #endif // !defined(WGPU_SKIP_PROCS) #if !defined(WGPU_SKIP_DECLARATIONS) - +/** + * \defgroup GlobalFunctions Global Functions + * \brief Functions that are not specific to an object. + * + * @{ + */ WGPU_EXPORT WGPUInstance wgpuCreateInstance(WGPU_NULLABLE WGPUInstanceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName) WGPU_FUNCTION_ATTRIBUTE; -// Methods of Adapter + +/** @} */ + +/** + * \defgroup Methods + * \brief Functions that are relative to a specific object. + * + * @{ + */ + +/** + * \defgroup WGPUAdapterMethods WGPUAdapter methods + * \brief Functions whose first argument has type WGPUAdapter. + * + * @{ + */ WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuAdapterGetInfo(WGPUAdapter adapter, WGPUAdapterInfo * info) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPUAdapterRequestDeviceCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterReference(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterRelease(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + + +/** + * \defgroup WGPUAdapterInfoMethods WGPUAdapterInfo methods + * \brief Functions whose first argument has type WGPUAdapterInfo. + * + * @{ + */ +WGPU_EXPORT void wgpuAdapterInfoFreeMembers(WGPUAdapterInfo adapterInfo) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of BindGroup + +/** + * \defgroup WGPUBindGroupMethods WGPUBindGroup methods + * \brief Functions whose first argument has type WGPUBindGroup. + * + * @{ + */ WGPU_EXPORT void wgpuBindGroupSetLabel(WGPUBindGroup bindGroup, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBindGroupReference(WGPUBindGroup bindGroup) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBindGroupRelease(WGPUBindGroup bindGroup) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of BindGroupLayout +/** + * \defgroup WGPUBindGroupLayoutMethods WGPUBindGroupLayout methods + * \brief Functions whose first argument has type WGPUBindGroupLayout. + * + * @{ + */ WGPU_EXPORT void wgpuBindGroupLayoutSetLabel(WGPUBindGroupLayout bindGroupLayout, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBindGroupLayoutReference(WGPUBindGroupLayout bindGroupLayout) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBindGroupLayoutRelease(WGPUBindGroupLayout bindGroupLayout) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of Buffer +/** + * \defgroup WGPUBufferMethods WGPUBuffer methods + * \brief Functions whose first argument has type WGPUBuffer. + * + * @{ + */ WGPU_EXPORT void wgpuBufferDestroy(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void const * wgpuBufferGetConstMappedRange(WGPUBuffer buffer, size_t offset, size_t size) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBufferMapState wgpuBufferGetMapState(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void * wgpuBufferGetMappedRange(WGPUBuffer buffer, size_t offset, size_t size) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT uint64_t wgpuBufferGetSize(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBufferUsageFlags wgpuBufferGetUsage(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBufferSetLabel(WGPUBuffer buffer, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBufferUnmap(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBufferReference(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuBufferRelease(WGPUBuffer buffer) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ -// Methods of CommandBuffer + + +/** + * \defgroup WGPUCommandBufferMethods WGPUCommandBuffer methods + * \brief Functions whose first argument has type WGPUCommandBuffer. + * + * @{ + */ WGPU_EXPORT void wgpuCommandBufferSetLabel(WGPUCommandBuffer commandBuffer, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuCommandBufferReference(WGPUCommandBuffer commandBuffer) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuCommandBufferRelease(WGPUCommandBuffer commandBuffer) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of CommandEncoder + +/** + * \defgroup WGPUCommandEncoderMethods WGPUCommandEncoder methods + * \brief Functions whose first argument has type WGPUCommandEncoder. + * + * @{ + */ WGPU_EXPORT WGPUComputePassEncoder wgpuCommandEncoderBeginComputePass(WGPUCommandEncoder commandEncoder, WGPU_NULLABLE WGPUComputePassDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPURenderPassEncoder wgpuCommandEncoderBeginRenderPass(WGPUCommandEncoder commandEncoder, WGPURenderPassDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuCommandEncoderClearBuffer(WGPUCommandEncoder commandEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size) WGPU_FUNCTION_ATTRIBUTE; @@ -1625,8 +1770,16 @@ WGPU_EXPORT void wgpuCommandEncoderSetLabel(WGPUCommandEncoder commandEncoder, c WGPU_EXPORT void wgpuCommandEncoderWriteTimestamp(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuCommandEncoderReference(WGPUCommandEncoder commandEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuCommandEncoderRelease(WGPUCommandEncoder commandEncoder) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of ComputePassEncoder + +/** + * \defgroup WGPUComputePassEncoderMethods WGPUComputePassEncoder methods + * \brief Functions whose first argument has type WGPUComputePassEncoder. + * + * @{ + */ WGPU_EXPORT void wgpuComputePassEncoderDispatchWorkgroups(WGPUComputePassEncoder computePassEncoder, uint32_t workgroupCountX, uint32_t workgroupCountY, uint32_t workgroupCountZ) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderDispatchWorkgroupsIndirect(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderEnd(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; @@ -1638,25 +1791,41 @@ WGPU_EXPORT void wgpuComputePassEncoderSetLabel(WGPUComputePassEncoder computePa WGPU_EXPORT void wgpuComputePassEncoderSetPipeline(WGPUComputePassEncoder computePassEncoder, WGPUComputePipeline pipeline) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderReference(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderRelease(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of ComputePipeline +/** + * \defgroup WGPUComputePipelineMethods WGPUComputePipeline methods + * \brief Functions whose first argument has type WGPUComputePipeline. + * + * @{ + */ WGPU_EXPORT WGPUBindGroupLayout wgpuComputePipelineGetBindGroupLayout(WGPUComputePipeline computePipeline, uint32_t groupIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePipelineSetLabel(WGPUComputePipeline computePipeline, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePipelineReference(WGPUComputePipeline computePipeline) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePipelineRelease(WGPUComputePipeline computePipeline) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of Device +/** + * \defgroup WGPUDeviceMethods WGPUDevice methods + * \brief Functions whose first argument has type WGPUDevice. + * + * @{ + */ WGPU_EXPORT WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, WGPU_NULLABLE WGPUCommandEncoderDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUDeviceCreateComputePipelineAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUDeviceCreateRenderPipelineAsyncCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPU_NULLABLE WGPUSamplerDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; @@ -1668,45 +1837,93 @@ WGPU_EXPORT WGPUBool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName fea WGPU_EXPORT void wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDeviceSetLabel(WGPUDevice device, char const * label) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDeviceReference(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDeviceRelease(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ -// Methods of Instance + + +/** + * \defgroup WGPUInstanceMethods WGPUInstance methods + * \brief Functions whose first argument has type WGPUInstance. + * + * @{ + */ WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUBool wgpuInstanceHasWGSLLanguageFeature(WGPUInstance instance, WGPUWGSLFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuInstanceProcessEvents(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPUInstanceRequestAdapterCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuInstanceReference(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuInstanceRelease(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of PipelineLayout + +/** + * \defgroup WGPUPipelineLayoutMethods WGPUPipelineLayout methods + * \brief Functions whose first argument has type WGPUPipelineLayout. + * + * @{ + */ WGPU_EXPORT void wgpuPipelineLayoutSetLabel(WGPUPipelineLayout pipelineLayout, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuPipelineLayoutReference(WGPUPipelineLayout pipelineLayout) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuPipelineLayoutRelease(WGPUPipelineLayout pipelineLayout) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of QuerySet + +/** + * \defgroup WGPUQuerySetMethods WGPUQuerySet methods + * \brief Functions whose first argument has type WGPUQuerySet. + * + * @{ + */ WGPU_EXPORT void wgpuQuerySetDestroy(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT uint32_t wgpuQuerySetGetCount(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUQueryType wgpuQuerySetGetType(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQuerySetSetLabel(WGPUQuerySet querySet, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQuerySetReference(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQuerySetRelease(WGPUQuerySet querySet) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of Queue -WGPU_EXPORT void wgpuQueueOnSubmittedWorkDone(WGPUQueue queue, WGPUQueueWorkDoneCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +/** + * \defgroup WGPUQueueMethods WGPUQueue methods + * \brief Functions whose first argument has type WGPUQueue. + * + * @{ + */ +WGPU_EXPORT void wgpuQueueOnSubmittedWorkDone(WGPUQueue queue, WGPUQueueOnSubmittedWorkDoneCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueSetLabel(WGPUQueue queue, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueSubmit(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueWriteBuffer(WGPUQueue queue, WGPUBuffer buffer, uint64_t bufferOffset, void const * data, size_t size) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueWriteTexture(WGPUQueue queue, WGPUImageCopyTexture const * destination, void const * data, size_t dataSize, WGPUTextureDataLayout const * dataLayout, WGPUExtent3D const * writeSize) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueReference(WGPUQueue queue) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuQueueRelease(WGPUQueue queue) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of RenderBundle +/** + * \defgroup WGPURenderBundleMethods WGPURenderBundle methods + * \brief Functions whose first argument has type WGPURenderBundle. + * + * @{ + */ WGPU_EXPORT void wgpuRenderBundleSetLabel(WGPURenderBundle renderBundle, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleReference(WGPURenderBundle renderBundle) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleRelease(WGPURenderBundle renderBundle) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ -// Methods of RenderBundleEncoder + + +/** + * \defgroup WGPURenderBundleEncoderMethods WGPURenderBundleEncoder methods + * \brief Functions whose first argument has type WGPURenderBundleEncoder. + * + * @{ + */ WGPU_EXPORT void wgpuRenderBundleEncoderDraw(WGPURenderBundleEncoder renderBundleEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndexed(WGPURenderBundleEncoder renderBundleEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndexedIndirect(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; @@ -1722,8 +1939,16 @@ WGPU_EXPORT void wgpuRenderBundleEncoderSetPipeline(WGPURenderBundleEncoder rend WGPU_EXPORT void wgpuRenderBundleEncoderSetVertexBuffer(WGPURenderBundleEncoder renderBundleEncoder, uint32_t slot, WGPU_NULLABLE WGPUBuffer buffer, uint64_t offset, uint64_t size) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleEncoderReference(WGPURenderBundleEncoder renderBundleEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderBundleEncoderRelease(WGPURenderBundleEncoder renderBundleEncoder) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of RenderPassEncoder + +/** + * \defgroup WGPURenderPassEncoderMethods WGPURenderPassEncoder methods + * \brief Functions whose first argument has type WGPURenderPassEncoder. + * + * @{ + */ WGPU_EXPORT void wgpuRenderPassEncoderBeginOcclusionQuery(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDraw(WGPURenderPassEncoder renderPassEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDrawIndexed(WGPURenderPassEncoder renderPassEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; @@ -1746,38 +1971,86 @@ WGPU_EXPORT void wgpuRenderPassEncoderSetVertexBuffer(WGPURenderPassEncoder rend WGPU_EXPORT void wgpuRenderPassEncoderSetViewport(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderRelease(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + -// Methods of RenderPipeline + +/** + * \defgroup WGPURenderPipelineMethods WGPURenderPipeline methods + * \brief Functions whose first argument has type WGPURenderPipeline. + * + * @{ + */ WGPU_EXPORT WGPUBindGroupLayout wgpuRenderPipelineGetBindGroupLayout(WGPURenderPipeline renderPipeline, uint32_t groupIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPipelineSetLabel(WGPURenderPipeline renderPipeline, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPipelineReference(WGPURenderPipeline renderPipeline) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPipelineRelease(WGPURenderPipeline renderPipeline) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of Sampler +/** + * \defgroup WGPUSamplerMethods WGPUSampler methods + * \brief Functions whose first argument has type WGPUSampler. + * + * @{ + */ WGPU_EXPORT void wgpuSamplerSetLabel(WGPUSampler sampler, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSamplerReference(WGPUSampler sampler) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSamplerRelease(WGPUSampler sampler) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of ShaderModule -WGPU_EXPORT void wgpuShaderModuleGetCompilationInfo(WGPUShaderModule shaderModule, WGPUCompilationInfoCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; +/** + * \defgroup WGPUShaderModuleMethods WGPUShaderModule methods + * \brief Functions whose first argument has type WGPUShaderModule. + * + * @{ + */ +WGPU_EXPORT void wgpuShaderModuleGetCompilationInfo(WGPUShaderModule shaderModule, WGPUShaderModuleGetCompilationInfoCallback callback, WGPU_NULLABLE void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuShaderModuleSetLabel(WGPUShaderModule shaderModule, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuShaderModuleReference(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuShaderModuleRelease(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ -// Methods of Surface + + +/** + * \defgroup WGPUSurfaceMethods WGPUSurface methods + * \brief Functions whose first argument has type WGPUSurface. + * + * @{ + */ WGPU_EXPORT void wgpuSurfaceConfigure(WGPUSurface surface, WGPUSurfaceConfiguration const * config) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceGetCapabilities(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceGetCurrentTexture(WGPUSurface surface, WGPUSurfaceTexture * surfaceTexture) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT WGPUTextureFormat wgpuSurfaceGetPreferredFormat(WGPUSurface surface, WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfacePresent(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuSurfaceSetLabel(WGPUSurface surface, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceUnconfigure(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceReference(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceRelease(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + + +/** + * \defgroup WGPUSurfaceCapabilitiesMethods WGPUSurfaceCapabilities methods + * \brief Functions whose first argument has type WGPUSurfaceCapabilities. + * + * @{ + */ +WGPU_EXPORT void wgpuSurfaceCapabilitiesFreeMembers(WGPUSurfaceCapabilities surfaceCapabilities) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ -// Methods of SurfaceCapabilities -WGPU_EXPORT void wgpuSurfaceCapabilitiesFreeMembers(WGPUSurfaceCapabilities capabilities) WGPU_FUNCTION_ATTRIBUTE; -// Methods of Texture + +/** + * \defgroup WGPUTextureMethods WGPUTexture methods + * \brief Functions whose first argument has type WGPUTexture. + * + * @{ + */ WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPU_NULLABLE WGPUTextureViewDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuTextureDestroy(WGPUTexture texture) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT uint32_t wgpuTextureGetDepthOrArrayLayers(WGPUTexture texture) WGPU_FUNCTION_ATTRIBUTE; @@ -1791,11 +2064,23 @@ WGPU_EXPORT uint32_t wgpuTextureGetWidth(WGPUTexture texture) WGPU_FUNCTION_ATTR WGPU_EXPORT void wgpuTextureSetLabel(WGPUTexture texture, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuTextureReference(WGPUTexture texture) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuTextureRelease(WGPUTexture texture) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + -// Methods of TextureView +/** + * \defgroup WGPUTextureViewMethods WGPUTextureView methods + * \brief Functions whose first argument has type WGPUTextureView. + * + * @{ + */ WGPU_EXPORT void wgpuTextureViewSetLabel(WGPUTextureView textureView, char const * label) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuTextureViewReference(WGPUTextureView textureView) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuTextureViewRelease(WGPUTextureView textureView) WGPU_FUNCTION_ATTRIBUTE; +/** @} */ + + +/** @} */ #endif // !defined(WGPU_SKIP_DECLARATIONS) diff --git a/wgpu/resources/webgpu.idl b/wgpu/resources/webgpu.idl index 7b9d0d79..95f93322 100644 --- a/wgpu/resources/webgpu.idl +++ b/wgpu/resources/webgpu.idl @@ -117,6 +117,7 @@ enum GPUFeatureName { "depth-clip-control", "depth32float-stencil8", "texture-compression-bc", + "texture-compression-bc-sliced-3d", "texture-compression-etc2", "texture-compression-astc", "timestamp-query", @@ -126,6 +127,7 @@ enum GPUFeatureName { "bgra8unorm-storage", "float32-filterable", "clip-distances", + "dual-source-blending", }; [Exposed=(Window, Worker), SecureContext] @@ -759,6 +761,10 @@ enum GPUBlendFactor { "src-alpha-saturated", "constant", "one-minus-constant", + "src1", + "one-minus-src1", + "src1-alpha", + "one-minus-src1-alpha", }; enum GPUBlendOperation { @@ -1192,12 +1198,22 @@ enum GPUCanvasAlphaMode { "premultiplied", }; +enum GPUCanvasToneMappingMode { + "standard", + "extended", +}; + +dictionary GPUCanvasToneMapping { + GPUCanvasToneMappingMode mode = "standard"; +}; + dictionary GPUCanvasConfiguration { required GPUDevice device; required GPUTextureFormat format; GPUTextureUsageFlags usage = 0x10; // GPUTextureUsage.RENDER_ATTACHMENT sequence viewFormats = []; PredefinedColorSpace colorSpace = "srgb"; + GPUCanvasToneMapping toneMapping = {}; GPUCanvasAlphaMode alphaMode = "opaque"; }; diff --git a/wgpu/resources/wgpu.h b/wgpu/resources/wgpu.h index ce9c7589..28a51f62 100644 --- a/wgpu/resources/wgpu.h +++ b/wgpu/resources/wgpu.h @@ -29,6 +29,30 @@ typedef enum WGPUNativeFeature { WGPUNativeFeature_PipelineStatisticsQuery = 0x00030008, WGPUNativeFeature_StorageResourceBindingArray = 0x00030009, WGPUNativeFeature_PartiallyBoundBindingArray = 0x0003000A, + WGPUNativeFeature_TextureFormat16bitNorm = 0x0003000B, + WGPUNativeFeature_TextureCompressionAstcHdr = 0x0003000C, + // TODO: requires wgpu.h api change + // WGPUNativeFeature_TimestampQueryInsidePasses = 0x0003000D, + WGPUNativeFeature_MappablePrimaryBuffers = 0x0003000E, + WGPUNativeFeature_BufferBindingArray = 0x0003000F, + WGPUNativeFeature_UniformBufferAndStorageTextureArrayNonUniformIndexing = 0x00030010, + // TODO: requires wgpu.h api change + // WGPUNativeFeature_AddressModeClampToZero = 0x00030011, + // WGPUNativeFeature_AddressModeClampToBorder = 0x00030012, + // WGPUNativeFeature_PolygonModeLine = 0x00030013, + // WGPUNativeFeature_PolygonModePoint = 0x00030014, + // WGPUNativeFeature_ConservativeRasterization = 0x00030015, + // WGPUNativeFeature_ClearTexture = 0x00030016, + // WGPUNativeFeature_SpirvShaderPassthrough = 0x00030017, + // WGPUNativeFeature_Multiview = 0x00030018, + WGPUNativeFeature_VertexAttribute64bit = 0x00030019, + WGPUNativeFeature_TextureFormatNv12 = 0x0003001A, + WGPUNativeFeature_RayTracingAccelerationStructure = 0x0003001B, + WGPUNativeFeature_RayQuery = 0x0003001C, + WGPUNativeFeature_ShaderF64 = 0x0003001D, + WGPUNativeFeature_ShaderI16 = 0x0003001E, + WGPUNativeFeature_ShaderPrimitiveIndex = 0x0003001F, + WGPUNativeFeature_ShaderEarlyDepthTest = 0x00030020, WGPUNativeFeature_Force32 = 0x7FFFFFFF } WGPUNativeFeature; @@ -222,11 +246,23 @@ typedef struct WGPUQuerySetDescriptorExtras { typedef struct WGPUSurfaceConfigurationExtras { WGPUChainedStruct chain; - WGPUBool desiredMaximumFrameLatency; + uint32_t desiredMaximumFrameLatency; } WGPUSurfaceConfigurationExtras WGPU_STRUCTURE_ATTRIBUTE; typedef void (*WGPULogCallback)(WGPULogLevel level, char const * message, void * userdata); +typedef enum WGPUNativeTextureFormat { + // From Features::TEXTURE_FORMAT_16BIT_NORM + WGPUNativeTextureFormat_R16Unorm = 0x00030001, + WGPUNativeTextureFormat_R16Snorm = 0x00030002, + WGPUNativeTextureFormat_Rg16Unorm = 0x00030003, + WGPUNativeTextureFormat_Rg16Snorm = 0x00030004, + WGPUNativeTextureFormat_Rgba16Unorm = 0x00030005, + WGPUNativeTextureFormat_Rgba16Snorm = 0x00030006, + // From Features::TEXTURE_FORMAT_NV12 + WGPUNativeTextureFormat_NV12 = 0x00030007, +} WGPUNativeTextureFormat; + #ifdef __cplusplus extern "C" { #endif diff --git a/wgpu/structs.py b/wgpu/structs.py index 447a6d74..2d8b02a8 100644 --- a/wgpu/structs.py +++ b/wgpu/structs.py @@ -27,7 +27,7 @@ def __repr__(self): # CODE BELOW THIS POINT IS AUTOGENERATED - DO NOT EDIT -# There are 59 structs +# There are 60 structs __all__ = [ "RequestAdapterOptions", @@ -82,6 +82,7 @@ def __repr__(self): "RenderBundleEncoderDescriptor", "QueueDescriptor", "QuerySetDescriptor", + "CanvasToneMapping", "CanvasConfiguration", "UncapturedErrorEventInit", "Color", @@ -685,11 +686,18 @@ def __repr__(self): count="int", ) +#: * mode :: :obj:`enums.CanvasToneMappingMode ` = "standard" +CanvasToneMapping = Struct( + "CanvasToneMapping", + mode="enums.CanvasToneMappingMode", +) + #: * device :: :class:`GPUDevice ` #: * format :: :obj:`enums.TextureFormat ` #: * usage :: :obj:`flags.TextureUsage ` = 0x10 #: * viewFormats :: List[:obj:`enums.TextureFormat `] = [] #: * colorSpace :: str = "srgb" +#: * toneMapping :: :obj:`structs.CanvasToneMapping ` = {} #: * alphaMode :: :obj:`enums.CanvasAlphaMode ` = "opaque" CanvasConfiguration = Struct( "CanvasConfiguration", @@ -698,6 +706,7 @@ def __repr__(self): usage="flags.TextureUsage", view_formats="List[enums.TextureFormat]", color_space="str", + tone_mapping="structs.CanvasToneMapping", alpha_mode="enums.CanvasAlphaMode", )