WebGPU
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# PSA for Chromium / Dawn WebGPU API updates 2020-07-28 Chromium's WebGPU implementation and Dawn's API try to closely follow changes to the WebGPU specification. When the WebGPU IDL changes, Chromium and Dawn will try to support both the "old" and the "new" version of the IDL at the same time so prototypes can be updated. In JavaScript, uses of the "old" path will result in a console warning, while when using Dawn directly, the "old" path will print a warning to stderr. Note that all changes to Dawn's API make it closer to [`webgpu.h`](https://github.com/webgpu-native/webgpu-headers/blob/master/webgpu.h) that we hope will allow applications to target both [Dawn](https://dawn.googlesource.com/dawn), and [wgpu](https://github.com/gfx-rs/wgpu/) in native before being compiled in WASM. Emscripten will also be updated from the "old" to the "new" API but won't have the smooth transition since developers control which version of emscripten they use. A couple weeks after an update like this one, the "old" version will be removed. This means that the "old" version of the items below will start being removed from Chromium/Dawn starting on 2020-08-11. Previous PSAs: - [PSA for Chromium / Dawn WebGPU API updates 2020-04-28](https://hackmd.io/Et7xlhoaThmi8dEX_s-xSw) ## Breaking changes ### Mapping changes WebGPU [PR](https://github.com/gpuweb/gpuweb/pull/708) #### Mapping at creation Instead of using `GPUDevice.createBufferMapped`, creating a buffer mapped at creation is done by setting `GPUBufferDescriptor.mappedAtCreation` to `true`. Then the mapping of the buffer can be retrieved by calling `GPUBuffer.getMappedRange`. In JavaScript, creation of buffers mapped at creation must be updated: ```diff -const [buffer, mapping] = device.createBufferMapped({ +const buffer = device.createBuffer({ + mappedAtCreation: true, size: 4, usage: GPUBufferUsage.UNIFORM, }); +const mapping = buffer.getMappedRange(); ``` Likewise when using Dawn’s API, changes are needed: ```diff wgpu::BufferDescriptor descriptor; descriptor.size = 4; descriptor.usage = wgpu::BufferUsage::Uniform; +descriptor.mappedAtCreation = true; +wgpu::Buffer buffer = device.CreateBuffer(&descriptor); +void* mapping = buffer.GetMappedRange(); -wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor); -wgpu::Buffer buffer = result.buffer; -void* mapping = result.data; ``` #### Mapping asynchronously Instead of using `GPUBuffer.mapReadAsync` and `GPUBuffer.mapWriteAsync`, both forms of asynchronous buffer mapping are now done through the `GPUBuffer.mapAsync` call. `GPUBuffer.mapAsync` takes additional parameters to select the type of mapping operation to do (`GPUMapMode.READ` or `GPUMapMode.WRITE`) as well as optional arguments to select which range of the buffer to map. Mapping any range of the buffer marks the whole buffer as mapped, but allows Web engines to move data only for the selected range. Calling `GPUBuffer.mapAsync` returns a `Promise` that resolves when the buffer is mapped, at which point it is possible to get the mapped range with `GPUBuffer.getMappedRange()`. In JavaScript uses of `mapReadAsync` and `mapWriteAsync` must be updated to use `mapAsync` instead: ```diff -await data = buffer.mapReadAsync(); +await buffer.mapAsync(GPUMapMode.READ); +const data = buffer.getMappedRange(); -await data = buffer.mapWriteAsync(); +await buffer.mapAsync(GPUMapMode.WRITE); +const data = buffer.getMappedRange(); ``` Likewise when using Dawn's API, changes are needed: ```diff -void OnBufferMapped(wgpu::BufferMapAsyncStatus status, - const void* data, - uint64_t dataLength, - void* userdata) { - // Do something with `data` -} -buffer.MapReadAsync(OnBufferMapped, myUserdata); +void OnBufferMapped(wgpu::BufferMapAsyncStatus status, + void* userdata) { + const void* data = buffer.GetConstMappedRange(); +} +buffer.MapAsync(wgpu::MapMode::Read, 0, bufferSize, + OnBufferMapped, myUserdata); ``` Note that in `webgpu.h`, for type safety, there are two ways to get the mapped range: - `wgpu::Buffer::GetConstMappedRange` that returns a `const void*` that can be called with both `Read` and `Write` mapping modes, and - `wgpu::Buffer::GetMappedRange` that returns a `void*` and can only be called when the mapping mode is `Write`. ### `GPUBuffer.setSubData` -> `GPUQueue.writeBuffer` WebGPU [PR](https://github.com/gpuweb/gpuweb/pull/749) In JavaScript uses the method on `GPUBuffer` needs to be updated to use the default queue instead: ```diff -buffer.setSubData(0, 4, Uint32Array([42])); +queue.writeBuffer(buffer, 0, 4, Uint32Array([42])); ``` Likewise when using Dawn's API, changes are needed: ```diff -buffer.SetSubData(0, 4, &data); +queue.WriteBuffer(buffer, 0, 4, &data); ``` ### `GPUTextureDescriptor` `.arrayLayerCount` -> `.size.depth` WebGPU [PR](https://github.com/gpuweb/gpuweb/pull/730) For 2D textures, the texture's depth now represents how many array layer it contains. In JavaScript texture creation code needs to be updated: ```diff const texture = device.createTexture({ format: "rgba8unorm", usage: GPUTextureUsage.SAMPLED | GPUTextureUsage.COPY_SRC, - arrayLayerCount: 10, - size: { width: 16, height: 16, depth: 1 }, + size: { width: 16, height: 16, depth: 10 }, }); ``` Likewise when using Dawn’s API, changes are needed: ```diff wgpu::TextureDescriptor descriptor; descriptor.format = wgpu::TextureFormat::RGBA8Unorm; descriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc; -descriptor.arrayLayerCount = 10; -descriptor.size = {16, 16, 1}; +descriptor.size = {16, 16, 10}; wgpu::Texture texture = device.CreateTexture(&descriptor); ``` ### `GPUTextureCopyView` `.arrayLayer` -> `.origin.z` WebGPU [PR](https://github.com/gpuweb/gpuweb/pull/730) To match the change in `GPUTextureDescriptor`, the Z component of a copy from or to a texture now encodes the array layer to copy to. In JavaScript copies need to be updated: ```diff encoder.copyBufferToTexture({ buffer, bytesPerRow: 256, }, { texture, - arrayLayer: 9, - origin: {x: 0, y: 0, z: 0}, + origin: {x: 0, y: 0, z: 9}, }, {width: 16, height: 16, depth: 1}); ``` Likewise when using Dawn’s API, changes are needed: ```diff wgpu::BufferCopyView srcView; srcView.buffer = buffer; srcView.layout.bytesPerRow = 256; wgpu::TextureCopyView dstView; dstView.texture = texture; -dstView.arrayLayer = 9; -dstView.origin = {0, 0, 0}; +dstView.origin = {0, 0, 9}; wgpu::Extent3D copySize = {16, 16, 9}; encoder.CopyBufferToTexture(&srcView, &dstView, &copySize); ``` ### `wgpu::BufferCopyView` containing a `wgpu::TextureDataLayout` WebGPU [PR](https://github.com/gpuweb/gpuweb/pull/761) To reuse the layout concepts of `GPUBufferCopyView` between `writeTexture` and copies between buffers and textures, all the members of `wgpu::BufferCopyView` that deal with layout (i.e. all but `buffer`) have been moved to a `layout` member of type `wgpu::TextureDataLayout`. No changes are needed in JavaScript but when using Dawn the following changes are needed: ```diff wgpu::BufferCopyView srcView; srcView.buffer = buffer; -srcView.offset = 0; -srcView.bytesPerRow = 256; -srcView.rowsPerImage = 16; +srcView.layout.offset = 0; +srcView.layout.bytesPerRow = 256; +srcView.layout.rowsPerImage = 16; ``` ## New features and improvements ### `GPUBindGroupLayoutEntry.minBufferBindingSize` WebGPU now requires that at each draw / dispatch call validates that the uniform and storage bindings are big enough for what's declared in the pipeline. This can add non-trivial overhead to each draw / dispatch, so `GPUBindGroupLayoutEntry` gained a new `minBufferBindingSize`. This members guarantees that each bind group with that layout will contain at least that many bytes, and guarantees that the pipeline using this layout won't use more than that many bytes. It allows skipping the size check for that buffer binding so it is strongly encouraged you use it. `GPURender/ComputePipeline.getBindGroupLayout` now returns `GPUBindGroupLayouts` with `minBufferBindingSize` set automatically so these bind group layouts are efficient to use. Here's an example using `minBufferBindingSize`: ```js const bgLayout = device.createBindGroupLayout({ entries: [{ binding: 0, visibility: GPUShaderStage.COMPUTE, type: "uniform-buffer", minBufferBindingSize: 16, }], }); const bindgroup = device.createBindGroup({ layout: bgLayout, entries: [{ binding: 0, // Below size, or the default value computed for size, must // be at least 16. Otherwise a validation error occurs. resource: {buffer, offset: 64, size: 16}, }], }); const pipeline = device.createComputePipeline({ // The "main" entry point of the module must not use more than // 16 bytes of the uniform at group=0 binding=0. Otherwise a // validation error occurs. layout: device.createPipelineLayout({bindGroupLayouts: [bgLayout]}), module, entryPoint: "main", }) ``` ### Subresource usage tracking Previously Chromium / Dawn enforced the [WebGPU resource usage validation](https://gpuweb.github.io/gpuweb/#programming-model-resource-usages) at resource granularity. This meant that if one mip-level of a texture was used an attachment for a render pass, the whole texture was unavailable to be sampled inside the render pass. This limitation has been lifted! This means it is now possible to generate mipmaps of a texture with render passes sampling from larger mip-levels. See [this (old-ish) example of a mipmap generation function](https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83). ### Sampling of depth and multisampled textures The depth component of depth-stencil textures can now be sampled in shaders as if they were `r32float` textures. In addition it is possible to use comparison sampling (useful for shadow mapping techniques like PCF) by setting `GPUSamplerDescriptor.compare` and using it as a `comparison-sampler` binding. ### Limitation of 16 bindings per group is lifted Previously Chromium / Dawn enforced a limit of at most 16 bindings in `GPUBindGroupLayoutDescriptor.entries` between all stages and all binding types. This was overly restrictive and more complex applications would run into it regularly. Dawn now has the same validation as in the WebGPU specification with per-stage and per-binding-type limits. ### `GPURenderPipelineDescriptor` `sampleMask` and `alphaToCoverageEnabled` These two members of the render pipeline descriptor allow controlling more precisely what happens when rendering to a multisampled texture. Please see the [`alphaToCoverageEnabled` section of the spec](https://gpuweb.github.io/gpuweb/#alpha-to-coverage) and the [`sampleMask` section of the spec](https://gpuweb.github.io/gpuweb/#sample-masking).

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully