From 0b36bcb629d521b407e586c3e7d5d6c1886cc9fb Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:05:49 +0200 Subject: [PATCH 1/7] update to latest webgpu --- wgpu/resources/webgpu.idl | 110 ++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/wgpu/resources/webgpu.idl b/wgpu/resources/webgpu.idl index 7fd95d0e..64001dcb 100644 --- a/wgpu/resources/webgpu.idl +++ b/wgpu/resources/webgpu.idl @@ -21,7 +21,7 @@ dictionary GPUObjectDescriptorBase { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUSupportedLimits { readonly attribute unsigned long maxTextureDimension1D; readonly attribute unsigned long maxTextureDimension2D; @@ -35,8 +35,8 @@ interface GPUSupportedLimits { readonly attribute unsigned long maxStorageBuffersPerShaderStage; readonly attribute unsigned long maxStorageTexturesPerShaderStage; readonly attribute unsigned long maxUniformBuffersPerShaderStage; - readonly attribute unsigned long maxUniformBufferBindingSize; - readonly attribute unsigned long maxStorageBufferBindingSize; + readonly attribute unsigned long long maxUniformBufferBindingSize; + readonly attribute unsigned long long maxStorageBufferBindingSize; readonly attribute unsigned long minUniformBufferOffsetAlignment; readonly attribute unsigned long minStorageBufferOffsetAlignment; readonly attribute unsigned long maxVertexBuffers; @@ -45,11 +45,12 @@ interface GPUSupportedLimits { readonly attribute unsigned long maxInterStageShaderComponents; readonly attribute unsigned long maxComputeWorkgroupStorageSize; readonly attribute unsigned long maxComputeWorkgroupInvocations; + readonly attribute GPUExtent3D maxComputeWorkgroupSize; readonly attribute unsigned long maxComputePerDimensionDispatchSize; }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUSupportedFeatures { readonly setlike; }; @@ -85,7 +86,7 @@ enum GPUPowerPreference { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUAdapter { readonly attribute DOMString name; [SameObject] readonly attribute GPUSupportedFeatures features; @@ -112,7 +113,7 @@ enum GPUFeatureName { }; -[Exposed=(Window, DedicatedWorker), Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUDevice : EventTarget { [SameObject] readonly attribute GPUSupportedFeatures features; [SameObject] readonly attribute GPUSupportedLimits limits; @@ -144,7 +145,7 @@ interface GPUDevice : EventTarget { GPUDevice includes GPUObjectBase; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUBuffer { Promise mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size); ArrayBuffer getMappedRange(optional GPUSize64 offset = 0, optional GPUSize64 size); @@ -163,7 +164,7 @@ dictionary GPUBufferDescriptor : GPUObjectDescriptorBase { typedef [EnforceRange] unsigned long GPUBufferUsageFlags; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUBufferUsage { const GPUFlagsConstant MAP_READ = 0x0001; const GPUFlagsConstant MAP_WRITE = 0x0002; @@ -179,14 +180,14 @@ interface GPUBufferUsage { typedef [EnforceRange] unsigned long GPUMapModeFlags; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUMapMode { const GPUFlagsConstant READ = 0x0001; const GPUFlagsConstant WRITE = 0x0002; }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUTexture { GPUTextureView createView(optional GPUTextureViewDescriptor descriptor = {}); @@ -213,17 +214,17 @@ enum GPUTextureDimension { typedef [EnforceRange] unsigned long GPUTextureUsageFlags; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUTextureUsage { const GPUFlagsConstant COPY_SRC = 0x01; const GPUFlagsConstant COPY_DST = 0x02; - const GPUFlagsConstant SAMPLED = 0x04; - const GPUFlagsConstant STORAGE = 0x08; + const GPUFlagsConstant TEXTURE_BINDING = 0x04; + const GPUFlagsConstant STORAGE_BINDING = 0x08; const GPUFlagsConstant RENDER_ATTACHMENT = 0x10; }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUTextureView { }; GPUTextureView includes GPUObjectBase; @@ -337,7 +338,7 @@ enum GPUTextureFormat { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUExternalTexture { }; GPUExternalTexture includes GPUObjectBase; @@ -349,7 +350,7 @@ dictionary GPUExternalTextureDescriptor : GPUObjectDescriptorBase { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUSampler { }; GPUSampler includes GPUObjectBase; @@ -363,7 +364,7 @@ dictionary GPUSamplerDescriptor : GPUObjectDescriptorBase { GPUFilterMode minFilter = "nearest"; GPUFilterMode mipmapFilter = "nearest"; float lodMinClamp = 0; - float lodMaxClamp = 0xffffffff; // TODO: What should this be? Was Number.MAX_VALUE. + float lodMaxClamp = 32; GPUCompareFunction compare; [Clamp] unsigned short maxAnisotropy = 1; }; @@ -394,7 +395,7 @@ enum GPUCompareFunction { }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUBindGroupLayout { }; GPUBindGroupLayout includes GPUObjectBase; @@ -406,7 +407,7 @@ dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase { typedef [EnforceRange] unsigned long GPUShaderStageFlags; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUShaderStage { const GPUFlagsConstant VERTEX = 0x1; const GPUFlagsConstant FRAGMENT = 0x2; @@ -465,12 +466,11 @@ dictionary GPUTextureBindingLayout { enum GPUStorageTextureAccess { - "read-only", "write-only", }; dictionary GPUStorageTextureBindingLayout { - required GPUStorageTextureAccess access; + GPUStorageTextureAccess access = "write-only"; required GPUTextureFormat format; GPUTextureViewDimension viewDimension = "2d"; }; @@ -480,7 +480,7 @@ dictionary GPUExternalTextureBindingLayout { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUBindGroup { }; GPUBindGroup includes GPUObjectBase; @@ -507,7 +507,7 @@ dictionary GPUBufferBinding { }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUPipelineLayout { }; GPUPipelineLayout includes GPUObjectBase; @@ -518,7 +518,7 @@ dictionary GPUPipelineLayoutDescriptor : GPUObjectDescriptorBase { }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUShaderModule { Promise compilationInfo(); }; @@ -537,7 +537,7 @@ enum GPUCompilationMessageType { "info" }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker), Serializable] interface GPUCompilationMessage { readonly attribute DOMString message; readonly attribute GPUCompilationMessageType type; @@ -547,7 +547,7 @@ interface GPUCompilationMessage { readonly attribute unsigned long long length; }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker), Serializable] interface GPUCompilationInfo { readonly attribute FrozenArray messages; }; @@ -571,7 +571,7 @@ dictionary GPUProgrammableStage { typedef double GPUPipelineConstantValue; // May represent WGSL's bool, f32, i32, u32. -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPUComputePipeline { }; GPUComputePipeline includes GPUObjectBase; @@ -583,7 +583,7 @@ dictionary GPUComputePipelineDescriptor : GPUPipelineDescriptorBase { }; -[Exposed=Window, Serializable] +[Exposed=(Window, DedicatedWorker)] interface GPURenderPipeline { }; GPURenderPipeline includes GPUObjectBase; @@ -659,7 +659,7 @@ dictionary GPUBlendState { typedef [EnforceRange] unsigned long GPUColorWriteFlags; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUColorWrite { const GPUFlagsConstant RED = 0x1; const GPUFlagsConstant GREEN = 0x2; @@ -780,7 +780,7 @@ enum GPUVertexFormat { }; -enum GPUInputStepMode { +enum GPUVertexStepMode { "vertex", "instance" }; @@ -793,7 +793,7 @@ dictionary GPUVertexState: GPUProgrammableStage { dictionary GPUVertexBufferLayout { required GPUSize64 arrayStride; - GPUInputStepMode stepMode = "vertex"; + GPUVertexStepMode stepMode = "vertex"; required sequence attributes; }; @@ -806,7 +806,7 @@ dictionary GPUVertexAttribute { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUCommandBuffer { readonly attribute Promise executionTime; }; @@ -817,7 +817,7 @@ dictionary GPUCommandBufferDescriptor : GPUObjectDescriptorBase { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUCommandEncoder { GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor); GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor = {}); @@ -864,8 +864,6 @@ GPUCommandEncoder includes GPUObjectBase; dictionary GPUCommandEncoderDescriptor : GPUObjectDescriptorBase { boolean measureExecutionTime = false; - - // TODO: reusability flag? }; @@ -917,7 +915,7 @@ interface mixin GPUProgrammablePassEncoder { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUComputePassEncoder { undefined setPipeline(GPUComputePipeline pipeline); undefined dispatch(GPUSize32 x, optional GPUSize32 y = 1, optional GPUSize32 z = 1); @@ -955,7 +953,7 @@ interface mixin GPURenderEncoderBase { undefined drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPURenderPassEncoder { undefined setViewport(float x, float y, float width, float height, @@ -1023,7 +1021,14 @@ enum GPUStoreOp { }; -[Exposed=Window] +dictionary GPURenderPassLayout: GPUObjectDescriptorBase { + required sequence colorFormats; + GPUTextureFormat depthStencilFormat; + GPUSize32 sampleCount = 1; +}; + + +[Exposed=(Window, DedicatedWorker)] interface GPURenderBundle { }; GPURenderBundle includes GPUObjectBase; @@ -1033,7 +1038,7 @@ dictionary GPURenderBundleDescriptor : GPUObjectDescriptorBase { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPURenderBundleEncoder { GPURenderBundle finish(optional GPURenderBundleDescriptor descriptor = {}); }; @@ -1042,14 +1047,13 @@ GPURenderBundleEncoder includes GPUProgrammablePassEncoder; GPURenderBundleEncoder includes GPURenderEncoderBase; -dictionary GPURenderBundleEncoderDescriptor : GPUObjectDescriptorBase { - required sequence colorFormats; - GPUTextureFormat depthStencilFormat; - GPUSize32 sampleCount = 1; +dictionary GPURenderBundleEncoderDescriptor : GPURenderPassLayout { + boolean depthReadOnly = false; + boolean stencilReadOnly = false; }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUQueue { undefined submit(sequence commandBuffers); @@ -1076,7 +1080,7 @@ interface GPUQueue { GPUQueue includes GPUObjectBase; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUQuerySet { undefined destroy(); }; @@ -1106,9 +1110,11 @@ enum GPUPipelineStatisticName { }; -[Exposed=Window] -interface GPUPresentationContext { - undefined configure(GPUPresentationConfiguration configuration); +[Exposed=(Window, DedicatedWorker)] +interface GPUCanvasContext { + readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas; + + undefined configure(GPUCanvasConfiguration configuration); undefined unconfigure(); GPUTextureFormat getPreferredFormat(GPUAdapter adapter); @@ -1122,7 +1128,7 @@ enum GPUCanvasCompositingAlphaMode { "premultiplied", }; -dictionary GPUPresentationConfiguration { +dictionary GPUCanvasConfiguration { required GPUDevice device; required GPUTextureFormat format; GPUTextureUsageFlags usage = 0x10; // GPUTextureUsage.RENDER_ATTACHMENT @@ -1136,7 +1142,7 @@ enum GPUDeviceLostReason { "destroyed", }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUDeviceLostInfo { readonly attribute (GPUDeviceLostReason or undefined) reason; readonly attribute DOMString message; @@ -1153,12 +1159,12 @@ enum GPUErrorFilter { }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUOutOfMemoryError { constructor(); }; -[Exposed=Window] +[Exposed=(Window, DedicatedWorker)] interface GPUValidationError { constructor(DOMString message); readonly attribute DOMString message; From 29e49a0f17353a4d2cb05021d3a1977d5fcb62d0 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:06:49 +0200 Subject: [PATCH 2/7] adjust to new api --- codegen/rspatcher.py | 29 +++++++++++++------- wgpu/backends/rs.py | 46 +++++++++++++++++--------------- wgpu/backends/rs_mappings.py | 9 +++---- wgpu/base.py | 22 ++++++++++----- wgpu/enums.py | 5 ++-- wgpu/flags.py | 4 +-- wgpu/gui/base.py | 4 +-- wgpu/gui/offscreen.py | 6 ++--- wgpu/resources/codegen_report.md | 10 +++---- wgpu/structs.py | 18 ++++++++++--- 10 files changed, 90 insertions(+), 63 deletions(-) diff --git a/codegen/rspatcher.py b/codegen/rspatcher.py index 580cb3c8..af24ccc3 100644 --- a/codegen/rspatcher.py +++ b/codegen/rspatcher.py @@ -41,7 +41,11 @@ def compare_flags(): idl = get_idl_parser() hp = get_h_parser() - name_map = {"ColorWrite": "ColorWriteMask"} + name_map = { + "ColorWrite": "ColorWriteMask", + "TextureUsage.TextureBinding": "Sampled", + "TextureUsage.StorageBinding": "Storage", + } for name, flag in idl.flags.items(): name = name_map.get(name, name) @@ -50,6 +54,7 @@ def compare_flags(): else: for key, val in flag.items(): key = key.title().replace("_", "") # MAP_READ -> MapRead + key = name_map.get(f"{name}.{key}") or key if key not in hp.flags[name]: print(f"Flag field {name}.{key} missing in wgpu.h") elif val != hp.flags[name][key]: @@ -65,7 +70,11 @@ def write_mappings(): idl = get_idl_parser() hp = get_h_parser() - field_map = {"discard": "clear"} + name_map = { + "VertexStepMode": "InputStepMode", + "StoreOp.discard": "clear", + } + name_map_i = {v: k for k, v in name_map.items()} # Init generated code pylines = [mappings_preamble] @@ -74,15 +83,14 @@ def write_mappings(): # to the corresponding integer value. enummap = {} for name in idl.enums: - if name not in hp.enums: - print(f"Enum {name} missing in wgpu.h") + hname = name_map.get(name, name) + if hname not in hp.enums: + print(f"Enum {hname} missing in wgpu.h") continue - hp_enum = {key.lower(): val for key, val in hp.enums[name].items()} + hp_enum = {key.lower(): val for key, val in hp.enums[hname].items()} for ikey in idl.enums[name].values(): - if ikey in field_map: - hkey = field_map[ikey] - else: - hkey = ikey.lower().replace("-", "") + hkey = ikey.lower().replace("-", "") + hkey = name_map.get(f"{name}.{hkey}") or hkey if hkey in hp_enum: enummap[name + "." + ikey] = hp_enum[hkey] else: @@ -101,7 +109,8 @@ def write_mappings(): for structname, struct in hp.structs.items(): for key, val in struct.items(): if isinstance(val, str) and val.startswith("WGPU"): - enumname = val[4:].split("/")[0] + henumname = val[4:].split("/")[0] + enumname = name_map_i.get(henumname, henumname) if enumname in idl.enums: cstructfield2enum[f"{structname[4:]}.{key}"] = enumname else: diff --git a/wgpu/backends/rs.py b/wgpu/backends/rs.py index 291ac055..bd33050a 100644 --- a/wgpu/backends/rs.py +++ b/wgpu/backends/rs.py @@ -319,7 +319,7 @@ async def request_adapter_async(self, *, canvas, power_preference=None): ) # no-cover -class GPUPresentationContext(base.GPUPresentationContext): +class GPUCanvasContext(base.GPUCanvasContext): def __init__(self, canvas): super().__init__(canvas) self._surface_size = (-1, -1) @@ -338,7 +338,7 @@ def get_current_texture(self): return GPUTextureView("swap_chain", view_id, self._device, None, size) def present(self): - if self._internal is not None: + if self._internal is not None and lib is not None: # H: void f(WGPUSwapChain swapChain) lib.wgpuSwapChainPresent(self._internal) @@ -486,7 +486,7 @@ async def request_device_async( ) # no-cover def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_adapter_destroy(internal) @@ -601,7 +601,7 @@ def create_sampler( min_filter: "enums.FilterMode" = "nearest", mipmap_filter: "enums.FilterMode" = "nearest", lod_min_clamp: float = 0, - lod_max_clamp: float = 0xFFFFFFFF, + lod_max_clamp: float = 32, compare: "enums.CompareFunction" = None, max_anisotropy: int = 1, ): @@ -1123,6 +1123,8 @@ def create_render_bundle_encoder( color_formats: "List[enums.TextureFormat]", depth_stencil_format: "enums.TextureFormat" = None, sample_count: int = 1, + depth_read_only: bool = False, + stencil_read_only: bool = False, ): raise NotImplementedError() @@ -1138,7 +1140,7 @@ def create_query_set( raise NotImplementedError() def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_device_destroy(internal) @@ -1227,7 +1229,7 @@ def destroy(self): self._destroy() # no-cover def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal # H: void f(WGPUBuffer buffer) lib.wgpuBufferDestroy(internal) @@ -1284,7 +1286,7 @@ def destroy(self): self._destroy() # no-cover def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal # H: void f(WGPUTexture texture) lib.wgpuTextureDestroy(internal) @@ -1292,35 +1294,35 @@ def _destroy(self): class GPUTextureView(base.GPUTextureView, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_texture_view_destroy(internal, False) class GPUSampler(base.GPUSampler, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_sampler_destroy(internal) class GPUBindGroupLayout(base.GPUBindGroupLayout, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_bind_group_layout_destroy(internal) class GPUBindGroup(base.GPUBindGroup, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_bind_group_destroy(internal) class GPUPipelineLayout(base.GPUPipelineLayout, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_pipeline_layout_destroy(internal) @@ -1330,7 +1332,7 @@ def compilation_info(self): return super().compilation_info() def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_shader_module_destroy(internal) @@ -1341,21 +1343,21 @@ class GPUPipelineBase(base.GPUPipelineBase): class GPUComputePipeline(base.GPUComputePipeline, GPUPipelineBase, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_compute_pipeline_destroy(internal) class GPURenderPipeline(base.GPURenderPipeline, GPUPipelineBase, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_render_pipeline_destroy(internal) class GPUCommandBuffer(base.GPUCommandBuffer, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_command_buffer_destroy(internal) @@ -1698,7 +1700,7 @@ def resolve_query_set( raise NotImplementedError() def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_command_encoder_destroy(internal) @@ -1803,7 +1805,7 @@ def write_timestamp(self, query_set, query_index): raise NotImplementedError() def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_compute_pass_destroy(internal) @@ -1872,7 +1874,7 @@ def draw_indexed_indirect(self, indirect_buffer, indirect_offset): ) def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_render_pass_destroy(internal) @@ -2140,7 +2142,7 @@ def on_submitted_work_done(self): class GPURenderBundle(base.GPURenderBundle, GPUObjectBase): def _destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal internal # doesnotexist.wgpu_render_bundle_destroy(internal) @@ -2169,7 +2171,7 @@ class GPUQuerySet(base.GPUQuerySet, GPUObjectBase): pass def destroy(self): - if self._internal is not None: + if self._internal is not None and lib is not None: self._internal, internal = None, self._internal # H: void f(WGPUQuerySet querySet) lib.wgpuQuerySetDestroy(internal) @@ -2187,7 +2189,7 @@ class GPUExternalTexture(base.GPUExternalTexture, GPUObjectBase): def _copy_docstrings(): - base_classes = GPUObjectBase, GPUPresentationContext + base_classes = GPUObjectBase, GPUCanvasContext for ob in globals().values(): if not (isinstance(ob, type) and issubclass(ob, base_classes)): continue diff --git a/wgpu/backends/rs_mappings.py b/wgpu/backends/rs_mappings.py index f6b1e63e..6790c8e9 100644 --- a/wgpu/backends/rs_mappings.py +++ b/wgpu/backends/rs_mappings.py @@ -4,7 +4,7 @@ # flake8: noqa -# There are 175 enum mappings +# There are 174 enum mappings enummap = { "AddressMode.clamp-to-edge": 2, @@ -50,8 +50,6 @@ "FrontFace.cw": 1, "IndexFormat.uint16": 1, "IndexFormat.uint32": 2, - "InputStepMode.instance": 1, - "InputStepMode.vertex": 0, "LoadOp.load": 1, "PipelineStatisticName.clipper-invocations": 1, "PipelineStatisticName.clipper-primitives-out": 2, @@ -77,7 +75,6 @@ "StencilOperation.keep": 0, "StencilOperation.replace": 2, "StencilOperation.zero": 1, - "StorageTextureAccess.read-only": 1, "StorageTextureAccess.write-only": 2, "StoreOp.discard": 1, "StoreOp.store": 0, @@ -182,6 +179,8 @@ "VertexFormat.unorm16x4": 14, "VertexFormat.unorm8x2": 5, "VertexFormat.unorm8x4": 6, + "VertexStepMode.instance": 1, + "VertexStepMode.vertex": 0, } # There are 45 struct-field enum mappings @@ -231,7 +230,7 @@ "TextureViewDescriptor.dimension": "TextureViewDimension", "TextureViewDescriptor.format": "TextureFormat", "VertexAttribute.format": "VertexFormat", - "VertexBufferLayout.stepMode": "InputStepMode", + "VertexBufferLayout.stepMode": "VertexStepMode", } enum_str2int = { diff --git a/wgpu/base.py b/wgpu/base.py index 0ab2b865..305d8995 100644 --- a/wgpu/base.py +++ b/wgpu/base.py @@ -51,7 +51,7 @@ "GPURenderBundleEncoder", "GPUQueue", "GPUQuerySet", - "GPUPresentationContext", + "GPUCanvasContext", "GPUDeviceLostInfo", "GPUOutOfMemoryError", "GPUValidationError", @@ -114,17 +114,23 @@ async def request_adapter_async(self, *, canvas, power_preference=None): ) # no-cover -class GPUPresentationContext: +class GPUCanvasContext: """A context object associated with a canvas, to present what has been drawn.""" def __init__(self, canvas): self._canvas_ref = weakref.ref(canvas) def _get_canvas(self): - """Allows subclasses to obtain the canvas object.""" + """Getter method for internal use.""" return self._canvas_ref() - # IDL: undefined configure(GPUPresentationConfiguration configuration); + # IDL: readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas; + @property + def canvas(self): + """The associated canvas object.""" + return self._canvas_ref() + + # IDL: undefined configure(GPUCanvasConfiguration configuration); def configure( self, *, @@ -442,7 +448,7 @@ def create_sampler( min_filter: "enums.FilterMode" = "nearest", mipmap_filter: "enums.FilterMode" = "nearest", lod_min_clamp: float = 0, - lod_max_clamp: float = 0xFFFFFFFF, + lod_max_clamp: float = 32, compare: "enums.CompareFunction" = None, max_anisotropy: int = 1, ): @@ -460,7 +466,7 @@ def create_sampler( min_filter (FilterMode): Interpolation when zoomed out. Default 'nearest'. mipmap_filter: (FilterMode): Interpolation between mip levels. Default 'nearest'. lod_min_clamp (float): The minimum level of detail. Default 0. - lod_max_clamp (float): The maxium level of detail. Default inf. + lod_max_clamp (float): The maxium level of detail. Default 32. compare (CompareFunction): The sample compare operation for depth textures. Only specify this for depth textures. Default None. max_anisotropy (int): The maximum anisotropy value clamp used by the sample, @@ -675,7 +681,7 @@ def create_render_pipeline( "buffers": [ { "array_stride": 8, - "step_mode": wgpu.InputStepMode.vertex, # optional + "step_mode": wgpu.VertexStepMode.vertex, # optional "attributes": [ { "format": wgpu.VertexFormat.float2, @@ -804,6 +810,8 @@ def create_render_bundle_encoder( color_formats: "List[enums.TextureFormat]", depth_stencil_format: "enums.TextureFormat" = None, sample_count: int = 1, + depth_read_only: bool = False, + stencil_read_only: bool = False, ): """Create a :class:`GPURenderBundle` object. diff --git a/wgpu/enums.py b/wgpu/enums.py index 9ac13b4a..fafe16c9 100644 --- a/wgpu/enums.py +++ b/wgpu/enums.py @@ -183,7 +183,6 @@ def __repr__(self): StorageTextureAccess = Enum( "StorageTextureAccess", - read_only="read-only", write_only="write-only", ) #: @@ -294,8 +293,8 @@ def __repr__(self): sint32x4="sint32x4", ) #: -InputStepMode = Enum( - "InputStepMode", +VertexStepMode = Enum( + "VertexStepMode", vertex="vertex", instance="instance", ) #: diff --git a/wgpu/flags.py b/wgpu/flags.py index a5007a25..100aa51a 100644 --- a/wgpu/flags.py +++ b/wgpu/flags.py @@ -49,8 +49,8 @@ def __repr__(self): "TextureUsage", COPY_SRC=1, COPY_DST=2, - SAMPLED=4, - STORAGE=8, + TEXTURE_BINDING=4, + STORAGE_BINDING=8, RENDER_ATTACHMENT=16, ) #: diff --git a/wgpu/gui/base.py b/wgpu/gui/base.py index 4a2bbf5a..34051f35 100644 --- a/wgpu/gui/base.py +++ b/wgpu/gui/base.py @@ -53,7 +53,7 @@ def get_physical_size(self): raise NotImplementedError() def get_context(self, kind="gpupresent"): - """Get the GPUPresentationContext object corresponding to this canvas, + """Get the GPUCanvasContext object corresponding to this canvas, which can be used to e.g. obtain a texture to render to. """ # Note that this function is analog to HtmlCanvas.get_context(), except @@ -63,7 +63,7 @@ def get_context(self, kind="gpupresent"): # Get the active wgpu backend module backend_module = sys.modules["wgpu"].GPU.__module__ # Instantiate the context - PC = sys.modules[backend_module].GPUPresentationContext # noqa: N806 + PC = sys.modules[backend_module].GPUCanvasContext # noqa: N806 self._present_context = PC(self) return self._present_context diff --git a/wgpu/gui/offscreen.py b/wgpu/gui/offscreen.py index 7b59eaf8..55539a71 100644 --- a/wgpu/gui/offscreen.py +++ b/wgpu/gui/offscreen.py @@ -13,10 +13,10 @@ def get_window_id(self): return None def get_context(self, kind="gpupresent"): - """Get the GPUPresentationContext object to obtain a texture to render to.""" + """Get the GPUCanvasContext object to obtain a texture to render to.""" assert kind == "gpupresent" if self._present_context is None: - self._present_context = GPUPresentationContextOffline(self) + self._present_context = GPUCanvasContextOffline(self) return self._present_context def present(self, texture_view): @@ -26,7 +26,7 @@ def present(self, texture_view): pass -class GPUPresentationContextOffline(base.GPUPresentationContext): +class GPUCanvasContextOffline(base.GPUCanvasContext): """Helper class for canvases that render to a texture.""" def __init__(self, canvas): diff --git a/wgpu/resources/codegen_report.md b/wgpu/resources/codegen_report.md index ca600140..21e14e77 100644 --- a/wgpu/resources/codegen_report.md +++ b/wgpu/resources/codegen_report.md @@ -1,16 +1,16 @@ # Code generatation report ## Preparing * The webgpu.idl defines 33 classes with 83 functions -* The webgpu.idl defines 5 flags, 31 enums, 53 structs +* The webgpu.idl defines 5 flags, 31 enums, 54 structs * The wgpu.h defines 106 functions * The wgpu.h defines 5 flags, 37 enums, 60 structs ## Updating API * Wrote 5 flags to flags.py * Wrote 31 enums to enums.py -* Wrote 53 structs to structs.py +* Wrote 54 structs to structs.py ### Patching API for base.py * Diffs for GPU: change request_adapter, change request_adapter_async -* Diffs for GPUPresentationContext: add present +* Diffs for GPUCanvasContext: add present * Diffs for GPUAdapter: add properties * Diffs for GPUDevice: add adapter, add create_buffer_with_data, hide import_external_texture, hide pop_error_scope, hide push_error_scope * Diffs for GPUBuffer: add map_read, add map_write, add size, add usage, hide get_mapped_range, hide map_async, hide unmap @@ -19,7 +19,7 @@ * Diffs for GPUComputePassEncoder: hide begin_pipeline_statistics_query, hide end_pipeline_statistics_query * Diffs for GPURenderPassEncoder: hide begin_pipeline_statistics_query, hide end_pipeline_statistics_query * Diffs for GPUQueue: add read_buffer, add read_texture, hide copy_external_image_to_texture -* Validated 33 classes, 110 methods, 34 properties +* Validated 33 classes, 110 methods, 35 properties ### Patching API for backends/rs.py * Diffs for GPUAdapter: add request_device_tracing * Validated 33 classes, 95 methods, 0 properties @@ -33,7 +33,7 @@ * Enum CompilationMessageType missing in wgpu.h * Enum CanvasCompositingAlphaMode missing in wgpu.h * Enum DeviceLostReason missing in wgpu.h -* Wrote 175 enum mappings and 45 struct-field mappings to rs_mappings.py +* Wrote 174 enum mappings and 45 struct-field mappings to rs_mappings.py * Validated 65 C function calls * Not using 46 C functions * Validated 66 C structs diff --git a/wgpu/structs.py b/wgpu/structs.py index b97099cf..7a36dc04 100644 --- a/wgpu/structs.py +++ b/wgpu/structs.py @@ -23,7 +23,7 @@ def __repr__(self): return f"<{self.__class__.__name__} {self._name}: {options}>" -# There are 53 structs +# There are 54 structs RequestAdapterOptions = Struct( "RequestAdapterOptions", @@ -273,7 +273,7 @@ def __repr__(self): VertexBufferLayout = Struct( "VertexBufferLayout", array_stride="int", - step_mode="enums.InputStepMode", + step_mode="enums.VertexStepMode", attributes="List[structs.VertexAttribute]", ) #: @@ -356,6 +356,14 @@ def __repr__(self): stencil_read_only="bool", ) #: +RenderPassLayout = Struct( + "RenderPassLayout", + label="str", + color_formats="List[enums.TextureFormat]", + depth_stencil_format="enums.TextureFormat", + sample_count="int", +) #: + RenderBundleDescriptor = Struct( "RenderBundleDescriptor", label="str", @@ -367,6 +375,8 @@ def __repr__(self): color_formats="List[enums.TextureFormat]", depth_stencil_format="enums.TextureFormat", sample_count="int", + depth_read_only="bool", + stencil_read_only="bool", ) #: QuerySetDescriptor = Struct( @@ -377,8 +387,8 @@ def __repr__(self): pipeline_statistics="List[enums.PipelineStatisticName]", ) #: -PresentationConfiguration = Struct( - "PresentationConfiguration", +CanvasConfiguration = Struct( + "CanvasConfiguration", device="GPUDevice", format="enums.TextureFormat", usage="flags.TextureUsage", From 8d2bb5a17cb0d32d074b29c597a2b5e82422cfe4 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:07:11 +0200 Subject: [PATCH 3/7] update docs/tests/examples --- docs/reference_wgpu.rst | 2 +- examples/compute_noop.py | 6 +-- examples/cube_glfw.py | 4 +- tests/test_compute.py | 18 ++++---- tests/test_gui_base.py | 4 +- tests/test_gui_glfw.py | 2 +- tests/test_rs_basics.py | 4 +- tests/test_rs_compute_tex.py | 89 +++++++++++++++++++----------------- tests/test_rs_render_tex.py | 2 +- 9 files changed, 68 insertions(+), 63 deletions(-) diff --git a/docs/reference_wgpu.rst b/docs/reference_wgpu.rst index 087bdbe0..1d98030d 100644 --- a/docs/reference_wgpu.rst +++ b/docs/reference_wgpu.rst @@ -216,7 +216,7 @@ Command buffers and encoders Other ----- -.. autoclass:: wgpu.GPUPresentationContext +.. autoclass:: wgpu.GPUCanvasContext :members: .. autoclass:: wgpu.GPUQueue diff --git a/examples/compute_noop.py b/examples/compute_noop.py index d510b26f..d8b20337 100644 --- a/examples/compute_noop.py +++ b/examples/compute_noop.py @@ -18,10 +18,10 @@ }; [[group(0), binding(0)]] -var data1: [[access(read)]] DataContainer; +var data1: DataContainer; [[group(0), binding(1)]] -var data2: [[access(write)]] DataContainer; +var data2: DataContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { @@ -77,7 +77,7 @@ "binding": 0, "visibility": wgpu.ShaderStage.COMPUTE, "buffer": { - "type": wgpu.BufferBindingType.storage, + "type": wgpu.BufferBindingType.read_only_storage, }, }, { diff --git a/examples/cube_glfw.py b/examples/cube_glfw.py index de25ca14..4b6c0841 100644 --- a/examples/cube_glfw.py +++ b/examples/cube_glfw.py @@ -119,7 +119,7 @@ # Create texture, and upload data texture = device.create_texture( size=texture_size, - usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.SAMPLED, + usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.TEXTURE_BINDING, dimension=wgpu.TextureDimension.d2, format=wgpu.TextureFormat.r8unorm, mip_level_count=1, @@ -267,7 +267,7 @@ "buffers": [ { "array_stride": 4 * 6, - "step_mode": wgpu.InputStepMode.vertex, + "step_mode": wgpu.VertexStepMode.vertex, "attributes": [ { "format": wgpu.VertexFormat.float32x4, diff --git a/tests/test_compute.py b/tests/test_compute.py index 1186edf9..a6461c01 100644 --- a/tests/test_compute.py +++ b/tests/test_compute.py @@ -19,7 +19,7 @@ struct DataContainer { data: [[stride(4)]] array; }; [[group(0), binding(0)]] - var data2: [[access(write)]] DataContainer; + var data2: DataContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { @@ -121,13 +121,13 @@ def test_compute_1_3(): struct DataContainer { data: [[stride(4)]] array; }; [[group(0), binding(0)]] - var data0: [[access(read)]] DataContainer; + var data0: DataContainer; [[group(0), binding(1)]] - var data1: [[access(write)]] DataContainer; + var data1: DataContainer; [[group(0), binding(2)]] - var data2: [[access(write)]] DataContainer; + var data2: DataContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { @@ -157,10 +157,10 @@ def test_compute_indirect(): struct DataContainer { data: [[stride(4)]] array; }; [[group(0), binding(0)]] - var data1: [[access(read)]] DataContainer; + var data1: DataContainer; [[group(0), binding(1)]] - var data2: [[access(write)]] DataContainer; + var data2: DataContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { @@ -200,7 +200,7 @@ def test_compute_indirect(): "binding": 0, "visibility": wgpu.ShaderStage.COMPUTE, "buffer": { - "type": wgpu.BufferBindingType.storage, + "type": wgpu.BufferBindingType.read_only_storage, }, }, { @@ -264,10 +264,10 @@ def test_compute_fails(): struct DataContainer { data: [[stride(4)]] array; }; [[group(0), binding(0)]] - var data1: [[access(read)]] DataContainer; + var data1: DataContainer; [[group(0), binding(1)]] - var data2: [[access(write)]] DataContainer; + var data2: DataContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { diff --git a/tests/test_gui_base.py b/tests/test_gui_base.py index ebf8ff95..9aa7196c 100644 --- a/tests/test_gui_base.py +++ b/tests/test_gui_base.py @@ -32,12 +32,12 @@ def spam_method(self): def test_base_canvas_context(): assert not issubclass( - wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUPresentationContext + wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUCanvasContext ) assert hasattr(wgpu.gui.WgpuCanvasInterface, "get_context") # Provides good default already canvas = wgpu.gui.WgpuCanvasInterface() - ctx = wgpu.GPUPresentationContext(canvas) + ctx = wgpu.GPUCanvasContext(canvas) assert ctx.get_preferred_format(None) == "bgra8unorm-srgb" diff --git a/tests/test_gui_glfw.py b/tests/test_gui_glfw.py index 3a248d21..72a0693d 100644 --- a/tests/test_gui_glfw.py +++ b/tests/test_gui_glfw.py @@ -162,7 +162,7 @@ def get_physical_size(self): def get_context(self): if self._present_context is None: backend_module = sys.modules["wgpu"].GPU.__module__ - PC = sys.modules[backend_module].GPUPresentationContext # noqa N806 + PC = sys.modules[backend_module].GPUCanvasContext # noqa N806 self._present_context = PC(self) return self._present_context diff --git a/tests/test_rs_basics.py b/tests/test_rs_basics.py index 77eeda7e..f84e17bf 100644 --- a/tests/test_rs_basics.py +++ b/tests/test_rs_basics.py @@ -82,7 +82,7 @@ def test_tuple_from_tuple_or_dict(): struct ArrayContainer { data: [[stride(4)]] array; }; [[group(0), binding(0)]] -var out1: [[access(write)]] ArrayContainer; +var out1: ArrayContainer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { @@ -257,7 +257,7 @@ def test_do_a_copy_roundtrip(): texture_dim = wgpu.TextureDimension.d1 # Create buffers and textures - stubusage = wgpu.TextureUsage.STORAGE + stubusage = wgpu.TextureUsage.STORAGE_BINDING buf1 = device.create_buffer( size=nbytes, usage=wgpu.BufferUsage.COPY_DST | wgpu.BufferUsage.COPY_SRC ) diff --git a/tests/test_rs_compute_tex.py b/tests/test_rs_compute_tex.py index e6b6d27c..eede0250 100644 --- a/tests/test_rs_compute_tex.py +++ b/tests/test_rs_compute_tex.py @@ -22,15 +22,15 @@ def test_compute_tex_1d_rgba8uint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_1d; + var r_tex1: texture_1d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_1d; + var r_tex2: texture_storage_1d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i: i32 = i32(index.x); - let color1 = vec4(textureLoad(r_tex1, i)); + let color1 = vec4(textureLoad(r_tex1, i, 0)); let color2 = vec4(color1.x + i, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, vec4(color2)); } @@ -57,15 +57,15 @@ def test_compute_tex_1d_rgba16sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_1d; + var r_tex1: texture_1d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_1d; + var r_tex2: texture_storage_1d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i: i32 = i32(index.x); - let color1 : vec4 = textureLoad(r_tex1, i); + let color1 : vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -92,15 +92,15 @@ def test_compute_tex_1d_r32sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_1d; + var r_tex1: texture_1d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_1d; + var r_tex2: texture_storage_1d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i: i32 = i32(index.x); - let color1 : vec4 = textureLoad(r_tex1, i); + let color1 : vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -127,15 +127,15 @@ def test_compute_tex_1d_r32float(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_1d; + var r_tex1: texture_1d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_1d; + var r_tex2: texture_storage_1d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i: i32 = i32(index.x); - let color1 : vec4 = textureLoad(r_tex1, i); + let color1 : vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + f32(i), color1.y + 1.0, color1.z * 2.0, color1.a); textureStore(r_tex2, i, color2); } @@ -165,15 +165,15 @@ def test_compute_tex_2d_rgba8uint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_2d; + var r_tex1: texture_2d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_2d; + var r_tex2: texture_storage_2d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec2(index.xy); - let color1 = vec4(textureLoad(r_tex1, i)); + let color1 = vec4(textureLoad(r_tex1, i, 0)); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, vec4(color2)); } @@ -201,15 +201,15 @@ def test_compute_tex_2d_rgba16sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_2d; + var r_tex1: texture_2d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_2d; + var r_tex2: texture_storage_2d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec2(index.xy); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -236,15 +236,15 @@ def test_compute_tex_2d_rgba16sint(): def test_compute_tex_2d_r32sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_2d; + var r_tex1: texture_2d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_2d; + var r_tex2: texture_storage_2d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec2(index.xy); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -272,15 +272,15 @@ def test_compute_tex_2d_r32float(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_2d; + var r_tex1:texture_2d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_2d; + var r_tex2: texture_storage_2d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec2(index.xy); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + f32(i.x), color1.y + 1.0, color1.z * 2.0, color1.a); textureStore(r_tex2, i, color2); } @@ -311,15 +311,15 @@ def test_compute_tex_3d_rgba8uint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_3d; + var r_tex1: texture_3d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_3d; + var r_tex2: texture_storage_3d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec3(index); - let color1 = vec4(textureLoad(r_tex1, i)); + let color1 = vec4(textureLoad(r_tex1, i, 0)); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, vec4(color2)); } @@ -348,15 +348,15 @@ def test_compute_tex_3d_rgba16sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_3d; + var r_tex1: texture_3d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_3d; + var r_tex2: texture_storage_3d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec3(index); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -385,15 +385,15 @@ def test_compute_tex_3d_r32sint(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_3d; + var r_tex1: texture_3d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_3d; + var r_tex2: texture_storage_3d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec3(index); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + i.x, color1.y + 1, color1.z * 2, color1.a); textureStore(r_tex2, i, color2); } @@ -422,15 +422,15 @@ def test_compute_tex_3d_r32float(): compute_shader = """ [[group(0), binding(0)]] - var r_tex1: [[access(read)]] texture_storage_3d; + var r_tex1: texture_3d; [[group(0), binding(1)]] - var r_tex2: [[access(write)]] texture_storage_3d; + var r_tex2: texture_storage_3d; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] index: vec3) { let i = vec3(index); - let color1: vec4 = textureLoad(r_tex1, i); + let color1: vec4 = textureLoad(r_tex1, i, 0); let color2 = vec4(color1.x + f32(i.x), color1.y + 1.0, color1.z * 2.0, color1.a); textureStore(r_tex2, i, color2); } @@ -482,13 +482,13 @@ def _compute_texture(compute_shader, texture_format, texture_dim, texture_size, size=(nx, ny, nz), dimension=texture_dim, format=texture_format, - usage=wgpu.TextureUsage.STORAGE | wgpu.TextureUsage.COPY_DST, + usage=wgpu.TextureUsage.TEXTURE_BINDING | wgpu.TextureUsage.COPY_DST, ) texture2 = device.create_texture( size=(nx, ny, nz), dimension=texture_dim, format=texture_format, - usage=wgpu.TextureUsage.STORAGE | wgpu.TextureUsage.COPY_SRC, + usage=wgpu.TextureUsage.STORAGE_BINDING | wgpu.TextureUsage.COPY_SRC, ) texture_view1 = texture1.create_view() texture_view2 = texture2.create_view() @@ -498,6 +498,12 @@ def _compute_texture(compute_shader, texture_format, texture_dim, texture_size, buffer = device.create_buffer_with_data(data=data1, usage=buffer_usage) assert buffer.usage == buffer_usage + texture_sample_type = "float" + if "uint" in texture_format: + texture_sample_type = "uint" + elif "sint" in texture_format: + texture_sample_type = "sint" + # Define bindings # One can see here why we need 2 textures: one is readonly, one writeonly bindings = [ @@ -508,9 +514,8 @@ def _compute_texture(compute_shader, texture_format, texture_dim, texture_size, { "binding": 0, "visibility": wgpu.ShaderStage.COMPUTE, - "storage_texture": { - "access": wgpu.StorageTextureAccess.read_only, # <- - "format": texture_format, + "texture": { + "sample_type": texture_sample_type, "view_dimension": texture_dim, }, }, @@ -518,7 +523,7 @@ def _compute_texture(compute_shader, texture_format, texture_dim, texture_size, "binding": 1, "visibility": wgpu.ShaderStage.COMPUTE, "storage_texture": { - "access": wgpu.StorageTextureAccess.write_only, # <- + "access": wgpu.StorageTextureAccess.write_only, "format": texture_format, "view_dimension": texture_dim, }, diff --git a/tests/test_rs_render_tex.py b/tests/test_rs_render_tex.py index d5e8bd41..7dbc12e2 100644 --- a/tests/test_rs_render_tex.py +++ b/tests/test_rs_render_tex.py @@ -468,7 +468,7 @@ def render_textured_square(fragment_shader, texture_format, texture_size, textur size=(nx, ny, nz), dimension=wgpu.TextureDimension.d2, format=texture_format, - usage=wgpu.TextureUsage.SAMPLED | wgpu.TextureUsage.COPY_DST, + usage=wgpu.TextureUsage.TEXTURE_BINDING | wgpu.TextureUsage.COPY_DST, ) upload_to_texture(device, texture, texture_data, nx, ny, nz) From 665f3389d97b94b860988916d9cd9bc5d0021c85 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:15:59 +0200 Subject: [PATCH 4/7] flake --- tests/test_gui_base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_gui_base.py b/tests/test_gui_base.py index 9aa7196c..daaa844e 100644 --- a/tests/test_gui_base.py +++ b/tests/test_gui_base.py @@ -31,9 +31,7 @@ def spam_method(self): def test_base_canvas_context(): - assert not issubclass( - wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUCanvasContext - ) + assert not issubclass(wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUCanvasContext) assert hasattr(wgpu.gui.WgpuCanvasInterface, "get_context") # Provides good default already canvas = wgpu.gui.WgpuCanvasInterface() From 9afb3702e82faca0f738a36532e9137d5f08dddc Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:41:59 +0200 Subject: [PATCH 5/7] update changelog --- CHANGELOG.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee5f14c..313178dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,9 +18,31 @@ Possible sections in each release: * Security: in case of vulnerabilities. -### [v0.6] - (upcoming) +### [v0.5.5] - (upcoming) -No changes yet. +Added: + +* The wgpu backend can be forced using the `WGPU_BACKEND_TYPE` env variable. + Values can be e.g. "D3D12", "Metal", "Vulkan". +* Initial support for off-screen canvases. +* Adds `adapter.is_software` property. + +Changed: + +* The `GPUPresentationContext` class has been renamed to `GPUCanvasContext`. +* The functionality of the swap-chain has moved to the `GPUCanvasContext`. +* The now removed `GPUSwapChain` was used as a context manager. Instead, + the frame is presented (ala GL swapbuffers) automatically at the end of a draw. +* The `canvas.configure_swap_chain()` method has been removed. Instead, + `canvas.get_context()` should be used, to obtain a present/canvas context. +* The `adapter.request_device()` method has its arguments `non_guaranteed_features` + and `non_guaranteed_limits` replaced with `required_features` and `required_limits`. +* The enum field `StoreOp.clear` is now `StoreOp.discard`. +* The flag field `TextureUsage.SAMPLED ` is now `TextureUsage.TEXTURE_BINDING `. +* The flag field `TextureUsage.STORAGE ` is now `TextureUsage.STORAGE_BINDING `. +* The enum `InputStepMode` is now `VertexStepMode`. +* WGSL: `var arrays` need a type annotation. +* WGSL: storage classes are written differently. ### [v0.5.4] - 11-06-2021 @@ -85,6 +107,7 @@ Added: * Added `GPUQueue.read_buffer` as extra API (next to `write_buffer` which is original WebGPU API). * Added `GPUQueue.read_texture` as extra API. +y Removed: * Removed `GPUBuffer.read_data()`. Use `device.queue.read_buffer()` instead. Note that `usage` `MAP_READ` should be replaced with `COPY_SRC`. From 69356fd1de15b95317f48558b84cba20bb98b043 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 15:43:27 +0200 Subject: [PATCH 6/7] update idl again (no effect for our code) --- wgpu/resources/webgpu.idl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wgpu/resources/webgpu.idl b/wgpu/resources/webgpu.idl index 64001dcb..f2933a03 100644 --- a/wgpu/resources/webgpu.idl +++ b/wgpu/resources/webgpu.idl @@ -44,9 +44,11 @@ interface GPUSupportedLimits { readonly attribute unsigned long maxVertexBufferArrayStride; readonly attribute unsigned long maxInterStageShaderComponents; readonly attribute unsigned long maxComputeWorkgroupStorageSize; - readonly attribute unsigned long maxComputeWorkgroupInvocations; - readonly attribute GPUExtent3D maxComputeWorkgroupSize; - readonly attribute unsigned long maxComputePerDimensionDispatchSize; + readonly attribute unsigned long maxComputeInvocationsPerWorkgroup; + readonly attribute unsigned long maxComputeWorkgroupSizeX; + readonly attribute unsigned long maxComputeWorkgroupSizeY; + readonly attribute unsigned long maxComputeWorkgroupSizeZ; + readonly attribute unsigned long maxComputeWorkgroupsPerDimension; }; @@ -99,7 +101,7 @@ interface GPUAdapter { dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase { sequence requiredFeatures = []; - record requiredLimits = {}; + record requiredLimits = {}; }; From 25dffaa7a628dea15b12234f6026403d4ce20566 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Aug 2021 18:03:43 +0200 Subject: [PATCH 7/7] bump wgpu-native again --- wgpu/backends/rs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/backends/rs.py b/wgpu/backends/rs.py index bd33050a..412d1753 100644 --- a/wgpu/backends/rs.py +++ b/wgpu/backends/rs.py @@ -53,8 +53,8 @@ apidiff = ApiDiff() # The wgpu-native version that we target/expect -__version__ = "0.9.2.1" -__commit_sha__ = "aaa5dcc8ae8fbac8fdcd445016dd643fdab3cfba" +__version__ = "0.9.2.2" +__commit_sha__ = "b10496e7eed9349f0fd541e6dfe5029cb436de74" version_info = tuple(map(int, __version__.split("."))) check_expected_version(version_info) # produces a warning on mismatch