diff --git a/codegen/apipatcher.py b/codegen/apipatcher.py index 8bb973f5..7958082a 100644 --- a/codegen/apipatcher.py +++ b/codegen/apipatcher.py @@ -454,7 +454,7 @@ def get_method_def(self, classname, methodname) -> str: # Get arg names and types idl_line = functions[name_idl] args = idl_line.split("(", 1)[1].split(")", 1)[0].split(",") - args = [Attribute(arg) for arg in args if arg.strip()] + args = [Attribute(arg, struct=False) for arg in args if arg.strip()] return_type = idl_line.split()[0] if return_type.startswith("[NewObject]"): # [NewObject] can be skipped: https://webidl.spec.whatwg.org/#NewObject @@ -471,8 +471,10 @@ def get_method_def(self, classname, methodname) -> str: if len(args) == 1 and args[0].typename.endswith( ("Options", "Descriptor", "Configuration") ): + if not args[0].required: + args[0].typename = args[0].typename.removeprefix("optional ") assert args[0].typename.startswith("GPU") - des_is_optional = bool(args[0].default) + des_is_optional = bool(args[0].default) # part of the logic above? attributes = self.idl.structs[args[0].typename[3:]].values() py_args = [ self._arg_from_attribute(methodname, attr, des_is_optional) @@ -583,7 +585,7 @@ def get_method_comment(self, classname, methodname): idl_line = functions[name_idl] args = idl_line.split("(", 1)[1].split(")", 1)[0].split(",") - args = [Attribute(arg) for arg in args if arg.strip()] + args = [Attribute(arg, struct=False) for arg in args if arg.strip()] # If one arg that is a dict, flatten dict to kwargs if len(args) == 1 and args[0].typename.endswith( diff --git a/codegen/idlparser.py b/codegen/idlparser.py index dfbe6f00..5fb608ef 100644 --- a/codegen/idlparser.py +++ b/codegen/idlparser.py @@ -35,24 +35,33 @@ def get_idl_parser(*, allow_cache=True): class Attribute: """A little object to hold a function argument or struct field.""" - def __init__(self, line): + def __init__(self, line: str, struct: bool = True): self.line = line.strip().strip(",;").strip() default = None # None means 'no default' and "None" kinda means "auto". - required = False + required = False # as opposed to optional, https://webidl.spec.whatwg.org/#required-dictionary-member but struct members? + # function args can be optional https://webidl.spec.whatwg.org/#dfn-optional-argument and a required if not arg = self.line if "=" in arg: arg, default = arg.rsplit("=", 1) arg, default = arg.strip(), default.strip() arg_type, arg_name = arg.strip().rsplit(" ", 1) - if arg_type.startswith("required "): - required = True - arg_type = arg_type.split(" ", 1)[1] - # required args should not have a default - assert default is None - elif arg_type.startswith("optional "): - arg_type = arg_type.split(" ", 1)[1] - default = default or "None" + if struct: + # some struct members might be required + if arg_type.startswith("required "): + required = True + arg_type = arg_type.split(" ", 1)[1] + # required args should not have a default + assert default is None + else: + # some function args might be optional + if arg_type.startswith("optional "): + required = False + arg_type = arg_type.split(" ", 1)[1] + default = default or "None" + else: + # but otherwise they are reuired + required = True if default: if default in ["false", "true"]: @@ -66,7 +75,7 @@ def __init__(self, line): def __repr__(self): return f"" - def to_str(self): + def to_str(self) -> str: return self.line diff --git a/wgpu/_classes.py b/wgpu/_classes.py index c14555ce..c1e6a502 100644 --- a/wgpu/_classes.py +++ b/wgpu/_classes.py @@ -1262,7 +1262,7 @@ def create_query_set( # IDL: undefined pushErrorScope(GPUErrorFilter filter); @apidiff.hide - def push_error_scope(self, filter: enums.ErrorFilterEnum | None = None) -> None: + def push_error_scope(self, filter: enums.ErrorFilterEnum) -> None: """Pushes a new GPU error scope onto the stack.""" raise NotImplementedError() @@ -1350,10 +1350,7 @@ def map_state(self) -> enums.BufferMapStateEnum: # IDL: Promise mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size); def map_sync( - self, - mode: flags.MapModeFlags | None = None, - offset: int = 0, - size: int | None = None, + self, mode: flags.MapModeFlags, offset: int = 0, size: int | None = None ) -> None: """Sync version of `map_async()`. @@ -1364,10 +1361,7 @@ def map_sync( # IDL: Promise mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size); def map_async( - self, - mode: flags.MapModeFlags | None = None, - offset: int = 0, - size: int | None = None, + self, mode: flags.MapModeFlags, offset: int = 0, size: int | None = None ) -> GPUPromise[None]: """Maps the given range of the GPUBuffer. @@ -1698,7 +1692,7 @@ class GPUPipelineBase: """A mixin class for render and compute pipelines.""" # IDL: [NewObject] GPUBindGroupLayout getBindGroupLayout(unsigned long index); - def get_bind_group_layout(self, index: int | None = None) -> GPUBindGroupLayout: + def get_bind_group_layout(self, index: int) -> GPUBindGroupLayout: """Get the bind group layout at the given index.""" raise NotImplementedError() @@ -1772,7 +1766,7 @@ class GPUDebugCommandsMixin: """Mixin for classes that support debug groups and markers.""" # IDL: undefined pushDebugGroup(USVString groupLabel); - def push_debug_group(self, group_label: str | None = None) -> None: + def push_debug_group(self, group_label: str) -> None: """Push a named debug group into the command stream.""" raise NotImplementedError() @@ -1782,7 +1776,7 @@ def pop_debug_group(self) -> None: raise NotImplementedError() # IDL: undefined insertDebugMarker(USVString markerLabel); - def insert_debug_marker(self, marker_label: str | None = None) -> None: + def insert_debug_marker(self, marker_label: str) -> None: """Insert the given message into the debug message queue.""" raise NotImplementedError() @@ -1791,7 +1785,7 @@ class GPURenderCommandsMixin: """Mixin for classes that provide rendering commands.""" # IDL: undefined setPipeline(GPURenderPipeline pipeline); - def set_pipeline(self, pipeline: GPURenderPipeline | None = None) -> None: + def set_pipeline(self, pipeline: GPURenderPipeline) -> None: """Set the pipeline for this render pass. Arguments: @@ -1802,8 +1796,8 @@ def set_pipeline(self, pipeline: GPURenderPipeline | None = None) -> None: # IDL: undefined setIndexBuffer(GPUBuffer buffer, GPUIndexFormat indexFormat, optional GPUSize64 offset = 0, optional GPUSize64 size); def set_index_buffer( self, - buffer: GPUBuffer | None = None, - index_format: enums.IndexFormatEnum | None = None, + buffer: GPUBuffer, + index_format: enums.IndexFormatEnum, offset: int = 0, size: int | None = None, ) -> None: @@ -1822,11 +1816,7 @@ def set_index_buffer( # IDL: undefined setVertexBuffer(GPUIndex32 slot, GPUBuffer? buffer, optional GPUSize64 offset = 0, optional GPUSize64 size); def set_vertex_buffer( - self, - slot: int | None = None, - buffer: GPUBuffer | None = None, - offset: int = 0, - size: int | None = None, + self, slot: int, buffer: GPUBuffer, offset: int = 0, size: int | None = None ) -> None: """Associate a vertex buffer with a bind slot. @@ -1844,7 +1834,7 @@ def set_vertex_buffer( # IDL: undefined draw(GPUSize32 vertexCount, optional GPUSize32 instanceCount = 1, optional GPUSize32 firstVertex = 0, optional GPUSize32 firstInstance = 0); def draw( self, - vertex_count: int | None = None, + vertex_count: int, instance_count: int = 1, first_vertex: int = 0, first_instance: int = 0, @@ -1860,11 +1850,7 @@ def draw( raise NotImplementedError() # IDL: undefined drawIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); - def draw_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, - ) -> None: + def draw_indirect(self, indirect_buffer: GPUBuffer, indirect_offset: int) -> None: """Like `draw()`, but the function arguments are in a buffer. Arguments: @@ -1878,7 +1864,7 @@ def draw_indirect( # IDL: undefined drawIndexed(GPUSize32 indexCount, optional GPUSize32 instanceCount = 1, optional GPUSize32 firstIndex = 0, optional GPUSignedOffset32 baseVertex = 0, optional GPUSize32 firstInstance = 0); def draw_indexed( self, - index_count: int | None = None, + index_count: int, instance_count: int = 1, first_index: int = 0, base_vertex: int = 0, @@ -1899,9 +1885,7 @@ def draw_indexed( # IDL: undefined drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); def draw_indexed_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, + self, indirect_buffer: GPUBuffer, indirect_offset: int ) -> None: """ Like `draw_indexed()`, but the function arguments are in a buffer. @@ -1961,7 +1945,7 @@ def begin_render_pass( # IDL: undefined clearBuffer( GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size); def clear_buffer( - self, buffer: GPUBuffer | None = None, offset: int = 0, size: int | None = None + self, buffer: GPUBuffer, offset: int = 0, size: int | None = None ) -> None: """Set (part of) the given buffer to zeros. @@ -1977,10 +1961,10 @@ def clear_buffer( # IDL: undefined copyBufferToBuffer( GPUBuffer source, GPUSize64 sourceOffset, GPUBuffer destination, GPUSize64 destinationOffset, optional GPUSize64 size); def copy_buffer_to_buffer( self, - source: GPUBuffer | None = None, - source_offset: int | None = None, - destination: GPUBuffer | None = None, - destination_offset: int | None = None, + source: GPUBuffer, + source_offset: int, + destination: GPUBuffer, + destination_offset: int, size: int | None = None, ) -> None: """Copy the contents of a buffer to another buffer. @@ -1999,9 +1983,9 @@ def copy_buffer_to_buffer( # IDL: undefined copyBufferToTexture( GPUTexelCopyBufferInfo source, GPUTexelCopyTextureInfo destination, GPUExtent3D copySize); def copy_buffer_to_texture( self, - source: structs.TexelCopyBufferInfoStruct | None = None, - destination: structs.TexelCopyTextureInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyBufferInfoStruct, + destination: structs.TexelCopyTextureInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: """Copy the contents of a buffer to a texture (view). @@ -2017,9 +2001,9 @@ def copy_buffer_to_texture( # IDL: undefined copyTextureToBuffer( GPUTexelCopyTextureInfo source, GPUTexelCopyBufferInfo destination, GPUExtent3D copySize); def copy_texture_to_buffer( self, - source: structs.TexelCopyTextureInfoStruct | None = None, - destination: structs.TexelCopyBufferInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyTextureInfoStruct, + destination: structs.TexelCopyBufferInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: """Copy the contents of a texture (view) to a buffer. @@ -2035,9 +2019,9 @@ def copy_texture_to_buffer( # IDL: undefined copyTextureToTexture( GPUTexelCopyTextureInfo source, GPUTexelCopyTextureInfo destination, GPUExtent3D copySize); def copy_texture_to_texture( self, - source: structs.TexelCopyTextureInfoStruct | None = None, - destination: structs.TexelCopyTextureInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyTextureInfoStruct, + destination: structs.TexelCopyTextureInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: """Copy the contents of a texture (view) to another texture (view). @@ -2060,11 +2044,11 @@ def finish(self, *, label: str = "") -> GPUCommandBuffer: # IDL: undefined resolveQuerySet( GPUQuerySet querySet, GPUSize32 firstQuery, GPUSize32 queryCount, GPUBuffer destination, GPUSize64 destinationOffset); def resolve_query_set( self, - query_set: GPUQuerySet | None = None, - first_query: int | None = None, - query_count: int | None = None, - destination: GPUBuffer | None = None, - destination_offset: int | None = None, + query_set: GPUQuerySet, + first_query: int, + query_count: int, + destination: GPUBuffer, + destination_offset: int, ) -> None: """ Resolves query results from a ``GPUQuerySet`` out into a range of a ``GPUBuffer``. @@ -2090,7 +2074,7 @@ class GPUComputePassEncoder( """ # IDL: undefined setPipeline(GPUComputePipeline pipeline); - def set_pipeline(self, pipeline: GPUComputePipeline | None = None) -> None: + def set_pipeline(self, pipeline: GPUComputePipeline) -> None: """Set the pipeline for this compute pass. Arguments: @@ -2101,7 +2085,7 @@ def set_pipeline(self, pipeline: GPUComputePipeline | None = None) -> None: # IDL: undefined dispatchWorkgroups(GPUSize32 workgroupCountX, optional GPUSize32 workgroupCountY = 1, optional GPUSize32 workgroupCountZ = 1); def dispatch_workgroups( self, - workgroup_count_x: int | None = None, + workgroup_count_x: int, workgroup_count_y: int = 1, workgroup_count_z: int = 1, ) -> None: @@ -2116,9 +2100,7 @@ def dispatch_workgroups( # IDL: undefined dispatchWorkgroupsIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); def dispatch_workgroups_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, + self, indirect_buffer: GPUBuffer, indirect_offset: int ) -> None: """Like `dispatch_workgroups()`, but the function arguments are in a buffer. @@ -2149,12 +2131,12 @@ class GPURenderPassEncoder( # IDL: undefined setViewport(float x, float y, float width, float height, float minDepth, float maxDepth); def set_viewport( self, - x: float | None = None, - y: float | None = None, - width: float | None = None, - height: float | None = None, - min_depth: float | None = None, - max_depth: float | None = None, + x: float, + y: float, + width: float, + height: float, + min_depth: float, + max_depth: float, ) -> None: """Set the viewport for this render pass. The whole scene is rendered to this sub-rectangle. @@ -2171,13 +2153,7 @@ def set_viewport( raise NotImplementedError() # IDL: undefined setScissorRect(GPUIntegerCoordinate x, GPUIntegerCoordinate y, GPUIntegerCoordinate width, GPUIntegerCoordinate height); - def set_scissor_rect( - self, - x: int | None = None, - y: int | None = None, - width: int | None = None, - height: int | None = None, - ) -> None: + def set_scissor_rect(self, x: int, y: int, width: int, height: int) -> None: """Set the scissor rectangle for this render pass. The scene is rendered as usual, but is only applied to this sub-rectangle. @@ -2191,8 +2167,7 @@ def set_scissor_rect( # IDL: undefined setBlendConstant(GPUColor color); def set_blend_constant( - self, - color: tuple[float, float, float, float] | structs.ColorStruct | None = None, + self, color: tuple[float, float, float, float] | structs.ColorStruct ) -> None: """Set the blend color for the render pass. @@ -2202,7 +2177,7 @@ def set_blend_constant( raise NotImplementedError() # IDL: undefined setStencilReference(GPUStencilValue reference); - def set_stencil_reference(self, reference: int | None = None) -> None: + def set_stencil_reference(self, reference: int) -> None: """Set the reference stencil value for this render pass. Arguments: @@ -2211,7 +2186,7 @@ def set_stencil_reference(self, reference: int | None = None) -> None: raise NotImplementedError() # IDL: undefined executeBundles(sequence bundles); - def execute_bundles(self, bundles: Sequence[GPURenderBundle] | None = None) -> None: + def execute_bundles(self, bundles: Sequence[GPURenderBundle]) -> None: """Executes commands previously recorded into the render bundles as part of this render pass. @@ -2226,7 +2201,7 @@ def end(self) -> None: raise NotImplementedError() # IDL: undefined beginOcclusionQuery(GPUSize32 queryIndex); - def begin_occlusion_query(self, query_index: int | None = None) -> None: + def begin_occlusion_query(self, query_index: int) -> None: """Begins an occlusion query. Arguments: @@ -2275,7 +2250,7 @@ class GPUQueue(GPUObjectBase): """ # IDL: undefined submit(sequence commandBuffers); - def submit(self, command_buffers: Sequence[GPUCommandBuffer] | None = None) -> None: + def submit(self, command_buffers: Sequence[GPUCommandBuffer]) -> None: """Submit a `GPUCommandBuffer` to the queue. Arguments: @@ -2286,9 +2261,9 @@ def submit(self, command_buffers: Sequence[GPUCommandBuffer] | None = None) -> N # IDL: undefined writeBuffer( GPUBuffer buffer, GPUSize64 bufferOffset, AllowSharedBufferSource data, optional GPUSize64 dataOffset = 0, optional GPUSize64 size); def write_buffer( self, - buffer: GPUBuffer | None = None, - buffer_offset: int | None = None, - data: ArrayLike | None = None, + buffer: GPUBuffer, + buffer_offset: int, + data: ArrayLike, data_offset: int = 0, size: int | None = None, ) -> None: @@ -2338,10 +2313,10 @@ def read_buffer( # IDL: undefined writeTexture( GPUTexelCopyTextureInfo destination, AllowSharedBufferSource data, GPUTexelCopyBufferLayout dataLayout, GPUExtent3D size); def write_texture( self, - destination: structs.TexelCopyTextureInfoStruct | None = None, - data: ArrayLike | None = None, - data_layout: structs.TexelCopyBufferLayoutStruct | None = None, - size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + destination: structs.TexelCopyTextureInfoStruct, + data: ArrayLike, + data_layout: structs.TexelCopyBufferLayoutStruct, + size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: """Takes the data contents and schedules a write operation of these contents to the destination texture in the queue. A @@ -2388,9 +2363,9 @@ def read_texture( @apidiff.hide("Specific to browsers") def copy_external_image_to_texture( self, - source: structs.CopyExternalImageSourceInfoStruct | None = None, - destination: structs.CopyExternalImageDestInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.CopyExternalImageSourceInfoStruct, + destination: structs.CopyExternalImageDestInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: raise NotImplementedError() @@ -2451,7 +2426,7 @@ class GPUOutOfMemoryError(GPUError, MemoryError): """An error raised when the GPU is out of memory.""" # IDL: constructor(DOMString message); - def __init__(self, message: str | None = None): + def __init__(self, message: str): super().__init__(message or "GPU is out of memory.") @@ -2459,7 +2434,7 @@ class GPUValidationError(GPUError): """An error raised when the pipeline could not be validated.""" # IDL: constructor(DOMString message); - def __init__(self, message: str | None = None): + def __init__(self, message: str): super().__init__(message) @@ -2467,9 +2442,7 @@ class GPUPipelineError(Exception): """An error raised when a pipeline could not be created.""" # IDL: constructor(optional DOMString message = "", GPUPipelineErrorInit options); - def __init__( - self, message: str = "", options: structs.PipelineErrorInitStruct | None = None - ): + def __init__(self, message: str, options: structs.PipelineErrorInitStruct): super().__init__(message or "") self._options = options @@ -2488,7 +2461,7 @@ class GPUInternalError(GPUError): """ # IDL: constructor(DOMString message); - def __init__(self, message: str | None = None): + def __init__(self, message: str): super().__init__(message) diff --git a/wgpu/backends/wgpu_native/_api.py b/wgpu/backends/wgpu_native/_api.py index 725c5f33..c96ff973 100644 --- a/wgpu/backends/wgpu_native/_api.py +++ b/wgpu/backends/wgpu_native/_api.py @@ -2528,10 +2528,7 @@ def _check_range(self, offset, size): return offset, size def map_async( - self, - mode: flags.MapModeFlags | None = None, - offset: int = 0, - size: int | None = None, + self, mode: flags.MapModeFlags, offset: int = 0, size: int | None = None ) -> GPUPromise[None]: sync_on_read = True @@ -2867,7 +2864,7 @@ def get_compilation_info_async(self) -> GPUPromise[GPUCompilationInfo]: class GPUPipelineBase(classes.GPUPipelineBase): - def get_bind_group_layout(self, index: int | None = None) -> GPUBindGroupLayout: + def get_bind_group_layout(self, index: int) -> GPUBindGroupLayout: # H: WGPUBindGroupLayout wgpuComputePipelineGetBindGroupLayout(WGPUComputePipeline computePipeline, uint32_t groupIndex) # H: WGPUBindGroupLayout wgpuRenderPipelineGetBindGroupLayout(WGPURenderPipeline renderPipeline, uint32_t groupIndex) function = type(self)._get_bind_group_layout_function @@ -3000,7 +2997,7 @@ def _not_implemented(self, name) -> NoReturn: class GPUDebugCommandsMixin(classes.GPUDebugCommandsMixin): # whole class is likely going to be solved better: https://github.com/pygfx/wgpu-py/pull/546 - def push_debug_group(self, group_label: str | None = None) -> None: + def push_debug_group(self, group_label: str) -> None: c_group_label = to_c_string_view(group_label) # H: void wgpuCommandEncoderPushDebugGroup(WGPUCommandEncoder commandEncoder, WGPUStringView groupLabel) # H: void wgpuComputePassEncoderPushDebugGroup(WGPUComputePassEncoder computePassEncoder, WGPUStringView groupLabel) @@ -3017,7 +3014,7 @@ def pop_debug_group(self) -> None: function = type(self)._pop_debug_group_function function(self._internal) - def insert_debug_marker(self, marker_label: str | None = None) -> None: + def insert_debug_marker(self, marker_label: str) -> None: c_marker_label = to_c_string_view(marker_label) # H: void wgpuCommandEncoderInsertDebugMarker(WGPUCommandEncoder commandEncoder, WGPUStringView markerLabel) # H: void wgpuComputePassEncoderInsertDebugMarker(WGPUComputePassEncoder computePassEncoder, WGPUStringView markerLabel) @@ -3039,7 +3036,7 @@ def _write_timestamp(self, query_set, query_index): class GPURenderCommandsMixin(classes.GPURenderCommandsMixin): - def set_pipeline(self, pipeline: GPURenderPipeline | None = None) -> None: + def set_pipeline(self, pipeline: GPURenderPipeline) -> None: self._maybe_keep_alive(pipeline) pipeline_id = pipeline._internal # H: void wgpuRenderPassEncoderSetPipeline(WGPURenderPassEncoder renderPassEncoder, WGPURenderPipeline pipeline) @@ -3049,8 +3046,8 @@ def set_pipeline(self, pipeline: GPURenderPipeline | None = None) -> None: def set_index_buffer( self, - buffer: GPUBuffer | None = None, - index_format: enums.IndexFormatEnum | None = None, + buffer: GPUBuffer, + index_format: enums.IndexFormatEnum, offset: int = 0, size: int | None = None, ) -> None: @@ -3066,11 +3063,7 @@ def set_index_buffer( ) def set_vertex_buffer( - self, - slot: int | None = None, - buffer: GPUBuffer | None = None, - offset: int = 0, - size: int | None = None, + self, slot: int, buffer: GPUBuffer, offset: int = 0, size: int | None = None ) -> None: self._maybe_keep_alive(buffer) if not size: @@ -3082,7 +3075,7 @@ def set_vertex_buffer( def draw( self, - vertex_count: int | None = None, + vertex_count: int, instance_count: int = 1, first_vertex: int = 0, first_instance: int = 0, @@ -3094,11 +3087,7 @@ def draw( self._internal, vertex_count, instance_count, first_vertex, first_instance ) - def draw_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, - ) -> None: + def draw_indirect(self, indirect_buffer: GPUBuffer, indirect_offset: int) -> None: # self._maybe_keep_alive(indirect_buffer) buffer_id = indirect_buffer._internal # H: void wgpuRenderPassEncoderDrawIndirect(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) @@ -3108,7 +3097,7 @@ def draw_indirect( def draw_indexed( self, - index_count: int | None = None, + index_count: int, instance_count: int = 1, first_index: int = 0, base_vertex: int = 0, @@ -3127,9 +3116,7 @@ def draw_indexed( ) def draw_indexed_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, + self, indirect_buffer: GPUBuffer, indirect_offset: int ) -> None: self._maybe_keep_alive(indirect_buffer) buffer_id = indirect_buffer._internal @@ -3342,7 +3329,7 @@ def _create_render_pass_stencil_attachment(self, ds_attachment): return c_depth_stencil_attachment def clear_buffer( - self, buffer: GPUBuffer | None = None, offset: int = 0, size: int | None = None + self, buffer: GPUBuffer, offset: int = 0, size: int | None = None ) -> None: offset = int(offset) if offset % 4 != 0: # pragma: no cover @@ -3367,10 +3354,10 @@ def clear_buffer( def copy_buffer_to_buffer( self, - source: GPUBuffer | None = None, - source_offset: int | None = None, - destination: GPUBuffer | None = None, - destination_offset: int | None = None, + source: GPUBuffer, + source_offset: int, + destination: GPUBuffer, + destination_offset: int, size: int | None = None, ) -> None: if source_offset % 4 != 0: # pragma: no cover @@ -3398,9 +3385,9 @@ def copy_buffer_to_buffer( def copy_buffer_to_texture( self, - source: structs.TexelCopyBufferInfoStruct | None = None, - destination: structs.TexelCopyTextureInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyBufferInfoStruct, + destination: structs.TexelCopyTextureInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: check_struct("TexelCopyBufferInfo", source) check_struct("TexelCopyTextureInfo", destination) @@ -3464,9 +3451,9 @@ def copy_buffer_to_texture( def copy_texture_to_buffer( self, - source: structs.TexelCopyTextureInfoStruct | None = None, - destination: structs.TexelCopyBufferInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyTextureInfoStruct, + destination: structs.TexelCopyBufferInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: check_struct("TexelCopyTextureInfo", source) check_struct("TexelCopyBufferInfo", destination) @@ -3530,9 +3517,9 @@ def copy_texture_to_buffer( def copy_texture_to_texture( self, - source: structs.TexelCopyTextureInfoStruct | None = None, - destination: structs.TexelCopyTextureInfoStruct | None = None, - copy_size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + source: structs.TexelCopyTextureInfoStruct, + destination: structs.TexelCopyTextureInfoStruct, + copy_size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: check_struct("TexelCopyTextureInfo", source) check_struct("TexelCopyTextureInfo", destination) @@ -3607,11 +3594,11 @@ def finish(self, *, label: str = "") -> GPUCommandBuffer: def resolve_query_set( self, - query_set: GPUQuerySet | None = None, - first_query: int | None = None, - query_count: int | None = None, - destination: GPUBuffer | None = None, - destination_offset: int | None = None, + query_set: GPUQuerySet, + first_query: int, + query_count: int, + destination: GPUBuffer, + destination_offset: int, ) -> None: # H: void f(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t firstQuery, uint32_t queryCount, WGPUBuffer destination, uint64_t destinationOffset) libf.wgpuCommandEncoderResolveQuerySet( @@ -3646,14 +3633,14 @@ class GPUComputePassEncoder( # GPUObjectBaseMixin _release_function = libf.wgpuComputePassEncoderRelease - def set_pipeline(self, pipeline: GPUComputePipeline | None = None) -> None: + def set_pipeline(self, pipeline: GPUComputePipeline) -> None: pipeline_id = pipeline._internal # H: void f(WGPUComputePassEncoder computePassEncoder, WGPUComputePipeline pipeline) libf.wgpuComputePassEncoderSetPipeline(self._internal, pipeline_id) def dispatch_workgroups( self, - workgroup_count_x: int | None = None, + workgroup_count_x: int, workgroup_count_y: int = 1, workgroup_count_z: int = 1, ) -> None: @@ -3663,9 +3650,7 @@ def dispatch_workgroups( ) def dispatch_workgroups_indirect( - self, - indirect_buffer: GPUBuffer | None = None, - indirect_offset: int | None = None, + self, indirect_buffer: GPUBuffer, indirect_offset: int ) -> None: buffer_id = indirect_buffer._internal # H: void f(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) @@ -3715,12 +3700,12 @@ class GPURenderPassEncoder( def set_viewport( self, - x: float | None = None, - y: float | None = None, - width: float | None = None, - height: float | None = None, - min_depth: float | None = None, - max_depth: float | None = None, + x: float, + y: float, + width: float, + height: float, + min_depth: float, + max_depth: float, ) -> None: # H: void f(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth) libf.wgpuRenderPassEncoderSetViewport( @@ -3733,21 +3718,14 @@ def set_viewport( float(max_depth), ) - def set_scissor_rect( - self, - x: int | None = None, - y: int | None = None, - width: int | None = None, - height: int | None = None, - ) -> None: + def set_scissor_rect(self, x: int, y: int, width: int, height: int) -> None: # H: void f(WGPURenderPassEncoder renderPassEncoder, uint32_t x, uint32_t y, uint32_t width, uint32_t height) libf.wgpuRenderPassEncoderSetScissorRect( self._internal, int(x), int(y), int(width), int(height) ) def set_blend_constant( - self, - color: tuple[float, float, float, float] | structs.ColorStruct | None = None, + self, color: tuple[float, float, float, float] | structs.ColorStruct ) -> None: if isinstance(color, dict): check_struct("Color", color) @@ -3763,7 +3741,7 @@ def set_blend_constant( # H: void f(WGPURenderPassEncoder renderPassEncoder, WGPUColor const * color) libf.wgpuRenderPassEncoderSetBlendConstant(self._internal, c_color) - def set_stencil_reference(self, reference: int | None = None) -> None: + def set_stencil_reference(self, reference: int) -> None: # H: void f(WGPURenderPassEncoder renderPassEncoder, uint32_t reference) libf.wgpuRenderPassEncoderSetStencilReference(self._internal, int(reference)) @@ -3771,7 +3749,7 @@ def end(self) -> None: # H: void f(WGPURenderPassEncoder renderPassEncoder) libf.wgpuRenderPassEncoderEnd(self._internal) - def execute_bundles(self, bundles: Sequence[GPURenderBundle] | None = None) -> None: + def execute_bundles(self, bundles: Sequence[GPURenderBundle]) -> None: bundle_ids = [bundle._internal for bundle in bundles] c_bundle_info = new_array("WGPURenderBundle[]", bundle_ids) # H: void f(WGPURenderPassEncoder renderPassEncoder, size_t bundleCount, WGPURenderBundle const * bundles) @@ -3779,7 +3757,7 @@ def execute_bundles(self, bundles: Sequence[GPURenderBundle] | None = None) -> N self._internal, len(bundles), c_bundle_info ) - def begin_occlusion_query(self, query_index: int | None = None) -> None: + def begin_occlusion_query(self, query_index: int) -> None: # H: void f(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex) libf.wgpuRenderPassEncoderBeginOcclusionQuery(self._internal, int(query_index)) @@ -3884,7 +3862,7 @@ class GPUQueue(classes.GPUQueue, GPUObjectBase): # GPUObjectBaseMixin _release_function = libf.wgpuQueueRelease - def submit(self, command_buffers: Sequence[GPUCommandBuffer] | None = None) -> None: + def submit(self, command_buffers: Sequence[GPUCommandBuffer]) -> None: command_buffer_ids = [cb._internal for cb in command_buffers] c_command_buffers = new_array("WGPUCommandBuffer[]", command_buffer_ids) # H: void f(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands) @@ -3892,9 +3870,9 @@ def submit(self, command_buffers: Sequence[GPUCommandBuffer] | None = None) -> N def write_buffer( self, - buffer: GPUBuffer | None = None, - buffer_offset: int | None = None, - data: ArrayLike | None = None, + buffer: GPUBuffer, + buffer_offset: int, + data: ArrayLike, data_offset: int = 0, size: int | None = None, ) -> None: @@ -3969,10 +3947,10 @@ def read_buffer( def write_texture( self, - destination: structs.TexelCopyTextureInfoStruct | None = None, - data: ArrayLike | None = None, - data_layout: structs.TexelCopyBufferLayoutStruct | None = None, - size: tuple[int, int, int] | structs.Extent3DStruct | None = None, + destination: structs.TexelCopyTextureInfoStruct, + data: ArrayLike, + data_layout: structs.TexelCopyBufferLayoutStruct, + size: tuple[int, int, int] | structs.Extent3DStruct, ) -> None: # Note that the bytes_per_row restriction does not apply for # this function; wgpu-native deals with it.