Browse Source

WebGPU update (#2364)

* Update WebGPU renderer to match new state of API

* Update WebGPU files
Hugo Amnov 4 years ago
parent
commit
a515dd3c3d

+ 267 - 112
3rdparty/webgpu/include/webgpu/webgpu.h

@@ -53,6 +53,9 @@
 #include <stdbool.h>
 
 #define WGPU_WHOLE_SIZE (0xffffffffffffffffULL)
+// TODO(crbug.com/520): Remove WGPU_STRIDE_UNDEFINED in favor of WGPU_COPY_STRIDE_UNDEFINED.
+#define WGPU_STRIDE_UNDEFINED (0xffffffffUL)
+#define WGPU_COPY_STRIDE_UNDEFINED (0xffffffffUL)
 
 typedef uint32_t WGPUFlags;
 
@@ -67,6 +70,7 @@ typedef struct WGPUDeviceImpl* WGPUDevice;
 typedef struct WGPUFenceImpl* WGPUFence;
 typedef struct WGPUInstanceImpl* WGPUInstance;
 typedef struct WGPUPipelineLayoutImpl* WGPUPipelineLayout;
+typedef struct WGPUQuerySetImpl* WGPUQuerySet;
 typedef struct WGPUQueueImpl* WGPUQueue;
 typedef struct WGPURenderBundleImpl* WGPURenderBundle;
 typedef struct WGPURenderBundleEncoderImpl* WGPURenderBundleEncoder;
@@ -106,15 +110,16 @@ typedef enum WGPUBackendType {
 } WGPUBackendType;
 
 typedef enum WGPUBindingType {
-    WGPUBindingType_UniformBuffer = 0x00000000,
-    WGPUBindingType_StorageBuffer = 0x00000001,
-    WGPUBindingType_ReadonlyStorageBuffer = 0x00000002,
-    WGPUBindingType_Sampler = 0x00000003,
-    WGPUBindingType_ComparisonSampler = 0x00000004,
-    WGPUBindingType_SampledTexture = 0x00000005,
-    WGPUBindingType_StorageTexture = 0x00000006,
-    WGPUBindingType_ReadonlyStorageTexture = 0x00000007,
-    WGPUBindingType_WriteonlyStorageTexture = 0x00000008,
+    WGPUBindingType_Undefined = 0x00000000,
+    WGPUBindingType_UniformBuffer = 0x00000001,
+    WGPUBindingType_StorageBuffer = 0x00000002,
+    WGPUBindingType_ReadonlyStorageBuffer = 0x00000003,
+    WGPUBindingType_Sampler = 0x00000004,
+    WGPUBindingType_ComparisonSampler = 0x00000005,
+    WGPUBindingType_SampledTexture = 0x00000006,
+    WGPUBindingType_MultisampledTexture = 0x00000007,
+    WGPUBindingType_ReadonlyStorageTexture = 0x00000008,
+    WGPUBindingType_WriteonlyStorageTexture = 0x00000009,
     WGPUBindingType_Force32 = 0x7FFFFFFF
 } WGPUBindingType;
 
@@ -144,11 +149,21 @@ typedef enum WGPUBlendOperation {
     WGPUBlendOperation_Force32 = 0x7FFFFFFF
 } WGPUBlendOperation;
 
+typedef enum WGPUBufferBindingType {
+    WGPUBufferBindingType_Undefined = 0x00000000,
+    WGPUBufferBindingType_Uniform = 0x00000001,
+    WGPUBufferBindingType_Storage = 0x00000002,
+    WGPUBufferBindingType_ReadOnlyStorage = 0x00000003,
+    WGPUBufferBindingType_Force32 = 0x7FFFFFFF
+} WGPUBufferBindingType;
+
 typedef enum WGPUBufferMapAsyncStatus {
     WGPUBufferMapAsyncStatus_Success = 0x00000000,
     WGPUBufferMapAsyncStatus_Error = 0x00000001,
     WGPUBufferMapAsyncStatus_Unknown = 0x00000002,
     WGPUBufferMapAsyncStatus_DeviceLost = 0x00000003,
+    WGPUBufferMapAsyncStatus_DestroyedBeforeCallback = 0x00000004,
+    WGPUBufferMapAsyncStatus_UnmappedBeforeCallback = 0x00000005,
     WGPUBufferMapAsyncStatus_Force32 = 0x7FFFFFFF
 } WGPUBufferMapAsyncStatus;
 
@@ -165,6 +180,15 @@ typedef enum WGPUCompareFunction {
     WGPUCompareFunction_Force32 = 0x7FFFFFFF
 } WGPUCompareFunction;
 
+typedef enum WGPUCreateReadyPipelineStatus {
+    WGPUCreateReadyPipelineStatus_Success = 0x00000000,
+    WGPUCreateReadyPipelineStatus_Error = 0x00000001,
+    WGPUCreateReadyPipelineStatus_DeviceLost = 0x00000002,
+    WGPUCreateReadyPipelineStatus_DeviceDestroyed = 0x00000003,
+    WGPUCreateReadyPipelineStatus_Unknown = 0x00000004,
+    WGPUCreateReadyPipelineStatus_Force32 = 0x7FFFFFFF
+} WGPUCreateReadyPipelineStatus;
+
 typedef enum WGPUCullMode {
     WGPUCullMode_None = 0x00000000,
     WGPUCullMode_Front = 0x00000001,
@@ -209,8 +233,9 @@ typedef enum WGPUFrontFace {
 } WGPUFrontFace;
 
 typedef enum WGPUIndexFormat {
-    WGPUIndexFormat_Uint16 = 0x00000000,
-    WGPUIndexFormat_Uint32 = 0x00000001,
+    WGPUIndexFormat_Undefined = 0x00000000,
+    WGPUIndexFormat_Uint16 = 0x00000001,
+    WGPUIndexFormat_Uint32 = 0x00000002,
     WGPUIndexFormat_Force32 = 0x7FFFFFFF
 } WGPUIndexFormat;
 
@@ -226,6 +251,15 @@ typedef enum WGPULoadOp {
     WGPULoadOp_Force32 = 0x7FFFFFFF
 } WGPULoadOp;
 
+typedef enum WGPUPipelineStatisticName {
+    WGPUPipelineStatisticName_VertexShaderInvocations = 0x00000000,
+    WGPUPipelineStatisticName_ClipperInvocations = 0x00000001,
+    WGPUPipelineStatisticName_ClipperPrimitivesOut = 0x00000002,
+    WGPUPipelineStatisticName_FragmentShaderInvocations = 0x00000003,
+    WGPUPipelineStatisticName_ComputeShaderInvocations = 0x00000004,
+    WGPUPipelineStatisticName_Force32 = 0x7FFFFFFF
+} WGPUPipelineStatisticName;
+
 typedef enum WGPUPresentMode {
     WGPUPresentMode_Immediate = 0x00000000,
     WGPUPresentMode_Mailbox = 0x00000001,
@@ -242,12 +276,19 @@ typedef enum WGPUPrimitiveTopology {
     WGPUPrimitiveTopology_Force32 = 0x7FFFFFFF
 } WGPUPrimitiveTopology;
 
+typedef enum WGPUQueryType {
+    WGPUQueryType_Occlusion = 0x00000000,
+    WGPUQueryType_PipelineStatistics = 0x00000001,
+    WGPUQueryType_Timestamp = 0x00000002,
+    WGPUQueryType_Force32 = 0x7FFFFFFF
+} WGPUQueryType;
+
 typedef enum WGPUSType {
     WGPUSType_Invalid = 0x00000000,
     WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001,
     WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002,
     WGPUSType_SurfaceDescriptorFromXlib = 0x00000003,
-    WGPUSType_SurfaceDescriptorFromHTMLCanvasId = 0x00000004,
+    WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
     WGPUSType_ShaderModuleSPIRVDescriptor = 0x00000005,
     WGPUSType_ShaderModuleWGSLDescriptor = 0x00000006,
     WGPUSType_SamplerDescriptorDummyAnisotropicFiltering = 0x00000007,
@@ -255,6 +296,14 @@ typedef enum WGPUSType {
     WGPUSType_Force32 = 0x7FFFFFFF
 } WGPUSType;
 
+typedef enum WGPUSamplerBindingType {
+    WGPUSamplerBindingType_Undefined = 0x00000000,
+    WGPUSamplerBindingType_Filtering = 0x00000001,
+    WGPUSamplerBindingType_NonFiltering = 0x00000002,
+    WGPUSamplerBindingType_Comparison = 0x00000003,
+    WGPUSamplerBindingType_Force32 = 0x7FFFFFFF
+} WGPUSamplerBindingType;
+
 typedef enum WGPUStencilOperation {
     WGPUStencilOperation_Keep = 0x00000000,
     WGPUStencilOperation_Zero = 0x00000001,
@@ -267,6 +316,13 @@ typedef enum WGPUStencilOperation {
     WGPUStencilOperation_Force32 = 0x7FFFFFFF
 } WGPUStencilOperation;
 
+typedef enum WGPUStorageTextureAccess {
+    WGPUStorageTextureAccess_Undefined = 0x00000000,
+    WGPUStorageTextureAccess_ReadOnly = 0x00000001,
+    WGPUStorageTextureAccess_WriteOnly = 0x00000002,
+    WGPUStorageTextureAccess_Force32 = 0x7FFFFFFF
+} WGPUStorageTextureAccess;
+
 typedef enum WGPUStoreOp {
     WGPUStoreOp_Store = 0x00000000,
     WGPUStoreOp_Clear = 0x00000001,
@@ -284,6 +340,7 @@ typedef enum WGPUTextureComponentType {
     WGPUTextureComponentType_Float = 0x00000000,
     WGPUTextureComponentType_Sint = 0x00000001,
     WGPUTextureComponentType_Uint = 0x00000002,
+    WGPUTextureComponentType_DepthComparison = 0x00000003,
     WGPUTextureComponentType_Force32 = 0x7FFFFFFF
 } WGPUTextureComponentType;
 
@@ -321,36 +378,47 @@ typedef enum WGPUTextureFormat {
     WGPUTextureFormat_BGRA8Unorm = 0x00000017,
     WGPUTextureFormat_BGRA8UnormSrgb = 0x00000018,
     WGPUTextureFormat_RGB10A2Unorm = 0x00000019,
-    WGPUTextureFormat_RG11B10Float = 0x0000001A,
-    WGPUTextureFormat_RG32Float = 0x0000001B,
-    WGPUTextureFormat_RG32Uint = 0x0000001C,
-    WGPUTextureFormat_RG32Sint = 0x0000001D,
-    WGPUTextureFormat_RGBA16Uint = 0x0000001E,
-    WGPUTextureFormat_RGBA16Sint = 0x0000001F,
-    WGPUTextureFormat_RGBA16Float = 0x00000020,
-    WGPUTextureFormat_RGBA32Float = 0x00000021,
-    WGPUTextureFormat_RGBA32Uint = 0x00000022,
-    WGPUTextureFormat_RGBA32Sint = 0x00000023,
-    WGPUTextureFormat_Depth32Float = 0x00000024,
-    WGPUTextureFormat_Depth24Plus = 0x00000025,
-    WGPUTextureFormat_Depth24PlusStencil8 = 0x00000026,
-    WGPUTextureFormat_BC1RGBAUnorm = 0x00000027,
-    WGPUTextureFormat_BC1RGBAUnormSrgb = 0x00000028,
-    WGPUTextureFormat_BC2RGBAUnorm = 0x00000029,
-    WGPUTextureFormat_BC2RGBAUnormSrgb = 0x0000002A,
-    WGPUTextureFormat_BC3RGBAUnorm = 0x0000002B,
-    WGPUTextureFormat_BC3RGBAUnormSrgb = 0x0000002C,
-    WGPUTextureFormat_BC4RUnorm = 0x0000002D,
-    WGPUTextureFormat_BC4RSnorm = 0x0000002E,
-    WGPUTextureFormat_BC5RGUnorm = 0x0000002F,
-    WGPUTextureFormat_BC5RGSnorm = 0x00000030,
-    WGPUTextureFormat_BC6HRGBUfloat = 0x00000031,
-    WGPUTextureFormat_BC6HRGBSfloat = 0x00000032,
-    WGPUTextureFormat_BC7RGBAUnorm = 0x00000033,
-    WGPUTextureFormat_BC7RGBAUnormSrgb = 0x00000034,
+    WGPUTextureFormat_RG11B10Ufloat = 0x0000001A,
+    WGPUTextureFormat_RGB9E5Ufloat = 0x0000001B,
+    WGPUTextureFormat_RG32Float = 0x0000001C,
+    WGPUTextureFormat_RG32Uint = 0x0000001D,
+    WGPUTextureFormat_RG32Sint = 0x0000001E,
+    WGPUTextureFormat_RGBA16Uint = 0x0000001F,
+    WGPUTextureFormat_RGBA16Sint = 0x00000020,
+    WGPUTextureFormat_RGBA16Float = 0x00000021,
+    WGPUTextureFormat_RGBA32Float = 0x00000022,
+    WGPUTextureFormat_RGBA32Uint = 0x00000023,
+    WGPUTextureFormat_RGBA32Sint = 0x00000024,
+    WGPUTextureFormat_Depth32Float = 0x00000025,
+    WGPUTextureFormat_Depth24Plus = 0x00000026,
+    WGPUTextureFormat_Depth24PlusStencil8 = 0x00000027,
+    WGPUTextureFormat_BC1RGBAUnorm = 0x00000028,
+    WGPUTextureFormat_BC1RGBAUnormSrgb = 0x00000029,
+    WGPUTextureFormat_BC2RGBAUnorm = 0x0000002A,
+    WGPUTextureFormat_BC2RGBAUnormSrgb = 0x0000002B,
+    WGPUTextureFormat_BC3RGBAUnorm = 0x0000002C,
+    WGPUTextureFormat_BC3RGBAUnormSrgb = 0x0000002D,
+    WGPUTextureFormat_BC4RUnorm = 0x0000002E,
+    WGPUTextureFormat_BC4RSnorm = 0x0000002F,
+    WGPUTextureFormat_BC5RGUnorm = 0x00000030,
+    WGPUTextureFormat_BC5RGSnorm = 0x00000031,
+    WGPUTextureFormat_BC6HRGBUfloat = 0x00000032,
+    WGPUTextureFormat_BC6HRGBFloat = 0x00000033,
+    WGPUTextureFormat_BC7RGBAUnorm = 0x00000034,
+    WGPUTextureFormat_BC7RGBAUnormSrgb = 0x00000035,
     WGPUTextureFormat_Force32 = 0x7FFFFFFF
 } WGPUTextureFormat;
 
+typedef enum WGPUTextureSampleType {
+    WGPUTextureSampleType_Undefined = 0x00000000,
+    WGPUTextureSampleType_Float = 0x00000001,
+    WGPUTextureSampleType_UnfilterableFloat = 0x00000002,
+    WGPUTextureSampleType_Depth = 0x00000003,
+    WGPUTextureSampleType_Sint = 0x00000004,
+    WGPUTextureSampleType_Uint = 0x00000005,
+    WGPUTextureSampleType_Force32 = 0x7FFFFFFF
+} WGPUTextureSampleType;
+
 typedef enum WGPUTextureViewDimension {
     WGPUTextureViewDimension_Undefined = 0x00000000,
     WGPUTextureViewDimension_1D = 0x00000001,
@@ -407,6 +475,7 @@ typedef enum WGPUBufferUsage {
     WGPUBufferUsage_Uniform = 0x00000040,
     WGPUBufferUsage_Storage = 0x00000080,
     WGPUBufferUsage_Indirect = 0x00000100,
+    WGPUBufferUsage_QueryResolve = 0x00000200,
     WGPUBufferUsage_Force32 = 0x7FFFFFFF
 } WGPUBufferUsage;
 typedef WGPUFlags WGPUBufferUsageFlags;
@@ -422,6 +491,14 @@ typedef enum WGPUColorWriteMask {
 } WGPUColorWriteMask;
 typedef WGPUFlags WGPUColorWriteMaskFlags;
 
+typedef enum WGPUMapMode {
+    WGPUMapMode_None = 0x00000000,
+    WGPUMapMode_Read = 0x00000001,
+    WGPUMapMode_Write = 0x00000002,
+    WGPUMapMode_Force32 = 0x7FFFFFFF
+} WGPUMapMode;
+typedef WGPUFlags WGPUMapModeFlags;
+
 typedef enum WGPUShaderStage {
     WGPUShaderStage_None = 0x00000000,
     WGPUShaderStage_Vertex = 0x00000001,
@@ -438,6 +515,7 @@ typedef enum WGPUTextureUsage {
     WGPUTextureUsage_Sampled = 0x00000004,
     WGPUTextureUsage_Storage = 0x00000008,
     WGPUTextureUsage_OutputAttachment = 0x00000010,
+    WGPUTextureUsage_RenderAttachment = 0x00000010,
     WGPUTextureUsage_Present = 0x00000020,
     WGPUTextureUsage_Force32 = 0x7FFFFFFF
 } WGPUTextureUsage;
@@ -454,6 +532,7 @@ typedef struct WGPUAdapterProperties {
     uint32_t deviceID;
     uint32_t vendorID;
     char const * name;
+    char const * driverDescription;
     WGPUAdapterType adapterType;
     WGPUBackendType backendType;
 } WGPUAdapterProperties;
@@ -467,46 +546,32 @@ typedef struct WGPUBindGroupEntry {
     WGPUTextureView textureView;
 } WGPUBindGroupEntry;
 
-typedef struct WGPUBindGroupLayoutEntry {
-    uint32_t binding;
-    WGPUShaderStageFlags visibility;
-    WGPUBindingType type;
-    bool hasDynamicOffset;
-    bool multisampled;
-    WGPUTextureViewDimension textureDimension;
-    WGPUTextureViewDimension viewDimension;
-    WGPUTextureComponentType textureComponentType;
-    WGPUTextureFormat storageTextureFormat;
-} WGPUBindGroupLayoutEntry;
-
 typedef struct WGPUBlendDescriptor {
     WGPUBlendOperation operation;
     WGPUBlendFactor srcFactor;
     WGPUBlendFactor dstFactor;
 } WGPUBlendDescriptor;
 
-typedef struct WGPUBufferCopyView {
+typedef struct WGPUBufferBindingLayout {
     WGPUChainedStruct const * nextInChain;
-    WGPUBuffer buffer;
-    uint64_t offset;
-    uint32_t rowPitch;
-    uint32_t imageHeight;
-    uint32_t bytesPerRow;
-    uint32_t rowsPerImage;
-} WGPUBufferCopyView;
+    WGPUBufferBindingType type;
+    bool hasDynamicOffset;
+    uint64_t minBindingSize;
+} WGPUBufferBindingLayout;
 
 typedef struct WGPUBufferDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
     WGPUBufferUsageFlags usage;
     uint64_t size;
+    bool mappedAtCreation;
 } WGPUBufferDescriptor;
 
 typedef struct WGPUColor {
-    float r;
-    float g;
-    float b;
-    float a;
+    double r;
+    double g;
+    double b;
+    double a;
 } WGPUColor;
 
 typedef struct WGPUCommandBufferDescriptor {
@@ -524,14 +589,16 @@ typedef struct WGPUComputePassDescriptor {
     char const * label;
 } WGPUComputePassDescriptor;
 
-typedef struct WGPUCreateBufferMappedResult {
-    WGPUBuffer buffer;
-    uint64_t dataLength;
-    void * data;
-} WGPUCreateBufferMappedResult;
+typedef struct WGPUCopyTextureForBrowserOptions {
+    WGPUChainedStruct const * nextInChain;
+    bool flipY;
+} WGPUCopyTextureForBrowserOptions;
 
 typedef struct WGPUDeviceProperties {
     bool textureCompressionBC;
+    bool shaderFloat16;
+    bool pipelineStatisticsQuery;
+    bool timestampQuery;
 } WGPUDeviceProperties;
 
 typedef struct WGPUExtent3D {
@@ -569,6 +636,15 @@ typedef struct WGPUProgrammableStageDescriptor {
     char const * entryPoint;
 } WGPUProgrammableStageDescriptor;
 
+typedef struct WGPUQuerySetDescriptor {
+    WGPUChainedStruct const * nextInChain;
+    char const * label;
+    WGPUQueryType type;
+    uint32_t count;
+    WGPUPipelineStatisticName const * pipelineStatistics;
+    uint32_t pipelineStatisticsCount;
+} WGPUQuerySetDescriptor;
+
 typedef struct WGPURasterizationStateDescriptor {
     WGPUChainedStruct const * nextInChain;
     WGPUFrontFace frontFace;
@@ -597,11 +673,18 @@ typedef struct WGPURenderPassDepthStencilAttachmentDescriptor {
     WGPULoadOp depthLoadOp;
     WGPUStoreOp depthStoreOp;
     float clearDepth;
+    bool depthReadOnly;
     WGPULoadOp stencilLoadOp;
     WGPUStoreOp stencilStoreOp;
     uint32_t clearStencil;
+    bool stencilReadOnly;
 } WGPURenderPassDepthStencilAttachmentDescriptor;
 
+typedef struct WGPUSamplerBindingLayout {
+    WGPUChainedStruct const * nextInChain;
+    WGPUSamplerBindingType type;
+} WGPUSamplerBindingLayout;
+
 typedef struct WGPUSamplerDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
@@ -614,6 +697,7 @@ typedef struct WGPUSamplerDescriptor {
     float lodMinClamp;
     float lodMaxClamp;
     WGPUCompareFunction compare;
+    uint16_t maxAnisotropy;
 } WGPUSamplerDescriptor;
 
 typedef struct WGPUSamplerDescriptorDummyAnisotropicFiltering {
@@ -624,8 +708,6 @@ typedef struct WGPUSamplerDescriptorDummyAnisotropicFiltering {
 typedef struct WGPUShaderModuleDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
-    uint32_t codeSize;
-    uint32_t const * code;
 } WGPUShaderModuleDescriptor;
 
 typedef struct WGPUShaderModuleSPIRVDescriptor {
@@ -646,15 +728,22 @@ typedef struct WGPUStencilStateFaceDescriptor {
     WGPUStencilOperation passOp;
 } WGPUStencilStateFaceDescriptor;
 
+typedef struct WGPUStorageTextureBindingLayout {
+    WGPUChainedStruct const * nextInChain;
+    WGPUStorageTextureAccess access;
+    WGPUTextureFormat format;
+    WGPUTextureViewDimension viewDimension;
+} WGPUStorageTextureBindingLayout;
+
 typedef struct WGPUSurfaceDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
 } WGPUSurfaceDescriptor;
 
-typedef struct WGPUSurfaceDescriptorFromHTMLCanvasId {
+typedef struct WGPUSurfaceDescriptorFromCanvasHTMLSelector {
     WGPUChainedStruct chain;
-    char const * id;
-} WGPUSurfaceDescriptorFromHTMLCanvasId;
+    char const * selector;
+} WGPUSurfaceDescriptorFromCanvasHTMLSelector;
 
 typedef struct WGPUSurfaceDescriptorFromMetalLayer {
     WGPUChainedStruct chain;
@@ -684,6 +773,20 @@ typedef struct WGPUSwapChainDescriptor {
     uint64_t implementation;
 } WGPUSwapChainDescriptor;
 
+typedef struct WGPUTextureBindingLayout {
+    WGPUChainedStruct const * nextInChain;
+    WGPUTextureSampleType sampleType;
+    WGPUTextureViewDimension viewDimension;
+    bool multisampled;
+} WGPUTextureBindingLayout;
+
+typedef struct WGPUTextureDataLayout {
+    WGPUChainedStruct const * nextInChain;
+    uint64_t offset;
+    uint32_t bytesPerRow;
+    uint32_t rowsPerImage;
+} WGPUTextureDataLayout;
+
 typedef struct WGPUTextureViewDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
@@ -706,20 +809,30 @@ typedef struct WGPUBindGroupDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
     WGPUBindGroupLayout layout;
-    uint32_t bindingCount;
-    WGPUBindGroupEntry const * bindings;
     uint32_t entryCount;
     WGPUBindGroupEntry const * entries;
 } WGPUBindGroupDescriptor;
 
-typedef struct WGPUBindGroupLayoutDescriptor {
+typedef struct WGPUBindGroupLayoutEntry {
+    uint32_t binding;
+    WGPUShaderStageFlags visibility;
+    WGPUBindingType type;
+    bool hasDynamicOffset;
+    uint64_t minBufferBindingSize;
+    WGPUTextureViewDimension viewDimension;
+    WGPUTextureComponentType textureComponentType;
+    WGPUTextureFormat storageTextureFormat;
+    WGPUBufferBindingLayout buffer;
+    WGPUSamplerBindingLayout sampler;
+    WGPUTextureBindingLayout texture;
+    WGPUStorageTextureBindingLayout storageTexture;
+} WGPUBindGroupLayoutEntry;
+
+typedef struct WGPUBufferCopyView {
     WGPUChainedStruct const * nextInChain;
-    char const * label;
-    uint32_t bindingCount;
-    WGPUBindGroupLayoutEntry const * bindings;
-    uint32_t entryCount;
-    WGPUBindGroupLayoutEntry const * entries;
-} WGPUBindGroupLayoutDescriptor;
+    WGPUTextureDataLayout layout;
+    WGPUBuffer buffer;
+} WGPUBufferCopyView;
 
 typedef struct WGPUColorStateDescriptor {
     WGPUChainedStruct const * nextInChain;
@@ -764,8 +877,8 @@ typedef struct WGPUTextureCopyView {
     WGPUChainedStruct const * nextInChain;
     WGPUTexture texture;
     uint32_t mipLevel;
-    uint32_t arrayLayer;
     WGPUOrigin3D origin;
+    WGPUTextureAspect aspect;
 } WGPUTextureCopyView;
 
 typedef struct WGPUTextureDescriptor {
@@ -774,7 +887,6 @@ typedef struct WGPUTextureDescriptor {
     WGPUTextureUsageFlags usage;
     WGPUTextureDimension dimension;
     WGPUExtent3D size;
-    uint32_t arrayLayerCount;
     WGPUTextureFormat format;
     uint32_t mipLevelCount;
     uint32_t sampleCount;
@@ -787,12 +899,20 @@ typedef struct WGPUVertexBufferLayoutDescriptor {
     WGPUVertexAttributeDescriptor const * attributes;
 } WGPUVertexBufferLayoutDescriptor;
 
+typedef struct WGPUBindGroupLayoutDescriptor {
+    WGPUChainedStruct const * nextInChain;
+    char const * label;
+    uint32_t entryCount;
+    WGPUBindGroupLayoutEntry const * entries;
+} WGPUBindGroupLayoutDescriptor;
+
 typedef struct WGPURenderPassDescriptor {
     WGPUChainedStruct const * nextInChain;
     char const * label;
     uint32_t colorAttachmentCount;
     WGPURenderPassColorAttachmentDescriptor const * colorAttachments;
     WGPURenderPassDepthStencilAttachmentDescriptor const * depthStencilAttachment;
+    WGPUQuerySet occlusionQuerySet;
 } WGPURenderPassDescriptor;
 
 typedef struct WGPUVertexStateDescriptor {
@@ -820,16 +940,13 @@ typedef struct WGPURenderPipelineDescriptor {
 } WGPURenderPipelineDescriptor;
 
 
-// TODO(dawn:22): Remove this once users use the "Entry" version.
-typedef WGPUBindGroupEntry WGPUBindGroupBinding;
-typedef WGPUBindGroupLayoutEntry WGPUBindGroupLayoutBinding;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, void const * data, uint64_t dataLength, void * userdata);
-typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status, void * data, uint64_t dataLength, void * userdata);
+typedef void (*WGPUBufferMapCallback)(WGPUBufferMapAsyncStatus status, void * userdata);
+typedef void (*WGPUCreateReadyComputePipelineCallback)(WGPUCreateReadyPipelineStatus status, WGPUComputePipeline pipeline, char const * message, void * userdata);
+typedef void (*WGPUCreateReadyRenderPipelineCallback)(WGPUCreateReadyPipelineStatus status, WGPURenderPipeline pipeline, char const * message, void * userdata);
 typedef void (*WGPUDeviceLostCallback)(char const * message, void * userdata);
 typedef void (*WGPUErrorCallback)(WGPUErrorType type, char const * message, void * userdata);
 typedef void (*WGPUFenceOnCompletionCallback)(WGPUFenceCompletionStatus status, void * userdata);
@@ -851,9 +968,9 @@ typedef void (*WGPUProcBindGroupLayoutRelease)(WGPUBindGroupLayout bindGroupLayo
 
 // Procs of Buffer
 typedef void (*WGPUProcBufferDestroy)(WGPUBuffer buffer);
-typedef void (*WGPUProcBufferMapReadAsync)(WGPUBuffer buffer, WGPUBufferMapReadCallback callback, void * userdata);
-typedef void (*WGPUProcBufferMapWriteAsync)(WGPUBuffer buffer, WGPUBufferMapWriteCallback callback, void * userdata);
-typedef void (*WGPUProcBufferSetSubData)(WGPUBuffer buffer, uint64_t start, uint64_t count, void const * data);
+typedef void const * (*WGPUProcBufferGetConstMappedRange)(WGPUBuffer buffer, size_t offset, size_t size);
+typedef void * (*WGPUProcBufferGetMappedRange)(WGPUBuffer buffer, size_t offset, size_t size);
+typedef void (*WGPUProcBufferMapAsync)(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata);
 typedef void (*WGPUProcBufferUnmap)(WGPUBuffer buffer);
 typedef void (*WGPUProcBufferReference)(WGPUBuffer buffer);
 typedef void (*WGPUProcBufferRelease)(WGPUBuffer buffer);
@@ -870,9 +987,12 @@ typedef void (*WGPUProcCommandEncoderCopyBufferToTexture)(WGPUCommandEncoder com
 typedef void (*WGPUProcCommandEncoderCopyTextureToBuffer)(WGPUCommandEncoder commandEncoder, WGPUTextureCopyView const * source, WGPUBufferCopyView const * destination, WGPUExtent3D const * copySize);
 typedef void (*WGPUProcCommandEncoderCopyTextureToTexture)(WGPUCommandEncoder commandEncoder, WGPUTextureCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize);
 typedef WGPUCommandBuffer (*WGPUProcCommandEncoderFinish)(WGPUCommandEncoder commandEncoder, WGPUCommandBufferDescriptor const * descriptor);
-typedef void (*WGPUProcCommandEncoderInsertDebugMarker)(WGPUCommandEncoder commandEncoder, char const * groupLabel);
+typedef void (*WGPUProcCommandEncoderInjectValidationError)(WGPUCommandEncoder commandEncoder, char const * message);
+typedef void (*WGPUProcCommandEncoderInsertDebugMarker)(WGPUCommandEncoder commandEncoder, char const * markerLabel);
 typedef void (*WGPUProcCommandEncoderPopDebugGroup)(WGPUCommandEncoder commandEncoder);
 typedef void (*WGPUProcCommandEncoderPushDebugGroup)(WGPUCommandEncoder commandEncoder, char const * groupLabel);
+typedef void (*WGPUProcCommandEncoderResolveQuerySet)(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t firstQuery, uint32_t queryCount, WGPUBuffer destination, uint64_t destinationOffset);
+typedef void (*WGPUProcCommandEncoderWriteTimestamp)(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 typedef void (*WGPUProcCommandEncoderReference)(WGPUCommandEncoder commandEncoder);
 typedef void (*WGPUProcCommandEncoderRelease)(WGPUCommandEncoder commandEncoder);
 
@@ -880,11 +1000,12 @@ typedef void (*WGPUProcCommandEncoderRelease)(WGPUCommandEncoder commandEncoder)
 typedef void (*WGPUProcComputePassEncoderDispatch)(WGPUComputePassEncoder computePassEncoder, uint32_t x, uint32_t y, uint32_t z);
 typedef void (*WGPUProcComputePassEncoderDispatchIndirect)(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 typedef void (*WGPUProcComputePassEncoderEndPass)(WGPUComputePassEncoder computePassEncoder);
-typedef void (*WGPUProcComputePassEncoderInsertDebugMarker)(WGPUComputePassEncoder computePassEncoder, char const * groupLabel);
+typedef void (*WGPUProcComputePassEncoderInsertDebugMarker)(WGPUComputePassEncoder computePassEncoder, char const * markerLabel);
 typedef void (*WGPUProcComputePassEncoderPopDebugGroup)(WGPUComputePassEncoder computePassEncoder);
 typedef void (*WGPUProcComputePassEncoderPushDebugGroup)(WGPUComputePassEncoder computePassEncoder, char const * groupLabel);
 typedef void (*WGPUProcComputePassEncoderSetBindGroup)(WGPUComputePassEncoder computePassEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
 typedef void (*WGPUProcComputePassEncoderSetPipeline)(WGPUComputePassEncoder computePassEncoder, WGPUComputePipeline pipeline);
+typedef void (*WGPUProcComputePassEncoderWriteTimestamp)(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 typedef void (*WGPUProcComputePassEncoderReference)(WGPUComputePassEncoder computePassEncoder);
 typedef void (*WGPUProcComputePassEncoderRelease)(WGPUComputePassEncoder computePassEncoder);
 
@@ -897,11 +1018,13 @@ typedef void (*WGPUProcComputePipelineRelease)(WGPUComputePipeline computePipeli
 typedef WGPUBindGroup (*WGPUProcDeviceCreateBindGroup)(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor);
 typedef WGPUBindGroupLayout (*WGPUProcDeviceCreateBindGroupLayout)(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor);
 typedef WGPUBuffer (*WGPUProcDeviceCreateBuffer)(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
-typedef WGPUCreateBufferMappedResult (*WGPUProcDeviceCreateBufferMapped)(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
 typedef WGPUCommandEncoder (*WGPUProcDeviceCreateCommandEncoder)(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor);
 typedef WGPUComputePipeline (*WGPUProcDeviceCreateComputePipeline)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor);
+typedef WGPUBuffer (*WGPUProcDeviceCreateErrorBuffer)(WGPUDevice device);
 typedef WGPUPipelineLayout (*WGPUProcDeviceCreatePipelineLayout)(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor);
-typedef WGPUQueue (*WGPUProcDeviceCreateQueue)(WGPUDevice device);
+typedef WGPUQuerySet (*WGPUProcDeviceCreateQuerySet)(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor);
+typedef void (*WGPUProcDeviceCreateReadyComputePipeline)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateReadyComputePipelineCallback callback, void * userdata);
+typedef void (*WGPUProcDeviceCreateReadyRenderPipeline)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateReadyRenderPipelineCallback callback, void * userdata);
 typedef WGPURenderBundleEncoder (*WGPUProcDeviceCreateRenderBundleEncoder)(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor);
 typedef WGPURenderPipeline (*WGPUProcDeviceCreateRenderPipeline)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor);
 typedef WGPUSampler (*WGPUProcDeviceCreateSampler)(WGPUDevice device, WGPUSamplerDescriptor const * descriptor);
@@ -934,10 +1057,18 @@ typedef void (*WGPUProcInstanceRelease)(WGPUInstance instance);
 typedef void (*WGPUProcPipelineLayoutReference)(WGPUPipelineLayout pipelineLayout);
 typedef void (*WGPUProcPipelineLayoutRelease)(WGPUPipelineLayout pipelineLayout);
 
+// Procs of QuerySet
+typedef void (*WGPUProcQuerySetDestroy)(WGPUQuerySet querySet);
+typedef void (*WGPUProcQuerySetReference)(WGPUQuerySet querySet);
+typedef void (*WGPUProcQuerySetRelease)(WGPUQuerySet querySet);
+
 // Procs of Queue
+typedef void (*WGPUProcQueueCopyTextureForBrowser)(WGPUQueue queue, WGPUTextureCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize, WGPUCopyTextureForBrowserOptions const * options);
 typedef WGPUFence (*WGPUProcQueueCreateFence)(WGPUQueue queue, WGPUFenceDescriptor const * descriptor);
 typedef void (*WGPUProcQueueSignal)(WGPUQueue queue, WGPUFence fence, uint64_t signalValue);
 typedef void (*WGPUProcQueueSubmit)(WGPUQueue queue, uint32_t commandCount, WGPUCommandBuffer const * commands);
+typedef void (*WGPUProcQueueWriteBuffer)(WGPUQueue queue, WGPUBuffer buffer, uint64_t bufferOffset, void const * data, size_t size);
+typedef void (*WGPUProcQueueWriteTexture)(WGPUQueue queue, WGPUTextureCopyView const * destination, void const * data, size_t dataSize, WGPUTextureDataLayout const * dataLayout, WGPUExtent3D const * writeSize);
 typedef void (*WGPUProcQueueReference)(WGPUQueue queue);
 typedef void (*WGPUProcQueueRelease)(WGPUQueue queue);
 
@@ -951,34 +1082,39 @@ typedef void (*WGPUProcRenderBundleEncoderDrawIndexed)(WGPURenderBundleEncoder r
 typedef void (*WGPUProcRenderBundleEncoderDrawIndexedIndirect)(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 typedef void (*WGPUProcRenderBundleEncoderDrawIndirect)(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 typedef WGPURenderBundle (*WGPUProcRenderBundleEncoderFinish)(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderBundleDescriptor const * descriptor);
-typedef void (*WGPUProcRenderBundleEncoderInsertDebugMarker)(WGPURenderBundleEncoder renderBundleEncoder, char const * groupLabel);
+typedef void (*WGPUProcRenderBundleEncoderInsertDebugMarker)(WGPURenderBundleEncoder renderBundleEncoder, char const * markerLabel);
 typedef void (*WGPUProcRenderBundleEncoderPopDebugGroup)(WGPURenderBundleEncoder renderBundleEncoder);
 typedef void (*WGPUProcRenderBundleEncoderPushDebugGroup)(WGPURenderBundleEncoder renderBundleEncoder, char const * groupLabel);
 typedef void (*WGPUProcRenderBundleEncoderSetBindGroup)(WGPURenderBundleEncoder renderBundleEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
-typedef void (*WGPUProcRenderBundleEncoderSetIndexBuffer)(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size);
+typedef void (*WGPUProcRenderBundleEncoderSetIndexBuffer)(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
+typedef void (*WGPUProcRenderBundleEncoderSetIndexBufferWithFormat)(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
 typedef void (*WGPUProcRenderBundleEncoderSetPipeline)(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderPipeline pipeline);
 typedef void (*WGPUProcRenderBundleEncoderSetVertexBuffer)(WGPURenderBundleEncoder renderBundleEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset, uint64_t size);
 typedef void (*WGPUProcRenderBundleEncoderReference)(WGPURenderBundleEncoder renderBundleEncoder);
 typedef void (*WGPUProcRenderBundleEncoderRelease)(WGPURenderBundleEncoder renderBundleEncoder);
 
 // Procs of RenderPassEncoder
+typedef void (*WGPUProcRenderPassEncoderBeginOcclusionQuery)(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex);
 typedef void (*WGPUProcRenderPassEncoderDraw)(WGPURenderPassEncoder renderPassEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
 typedef void (*WGPUProcRenderPassEncoderDrawIndexed)(WGPURenderPassEncoder renderPassEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
 typedef void (*WGPUProcRenderPassEncoderDrawIndexedIndirect)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 typedef void (*WGPUProcRenderPassEncoderDrawIndirect)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
+typedef void (*WGPUProcRenderPassEncoderEndOcclusionQuery)(WGPURenderPassEncoder renderPassEncoder);
 typedef void (*WGPUProcRenderPassEncoderEndPass)(WGPURenderPassEncoder renderPassEncoder);
 typedef void (*WGPUProcRenderPassEncoderExecuteBundles)(WGPURenderPassEncoder renderPassEncoder, uint32_t bundlesCount, WGPURenderBundle const * bundles);
-typedef void (*WGPUProcRenderPassEncoderInsertDebugMarker)(WGPURenderPassEncoder renderPassEncoder, char const * groupLabel);
+typedef void (*WGPUProcRenderPassEncoderInsertDebugMarker)(WGPURenderPassEncoder renderPassEncoder, char const * markerLabel);
 typedef void (*WGPUProcRenderPassEncoderPopDebugGroup)(WGPURenderPassEncoder renderPassEncoder);
 typedef void (*WGPUProcRenderPassEncoderPushDebugGroup)(WGPURenderPassEncoder renderPassEncoder, char const * groupLabel);
 typedef void (*WGPUProcRenderPassEncoderSetBindGroup)(WGPURenderPassEncoder renderPassEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
 typedef void (*WGPUProcRenderPassEncoderSetBlendColor)(WGPURenderPassEncoder renderPassEncoder, WGPUColor const * color);
-typedef void (*WGPUProcRenderPassEncoderSetIndexBuffer)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size);
+typedef void (*WGPUProcRenderPassEncoderSetIndexBuffer)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
+typedef void (*WGPUProcRenderPassEncoderSetIndexBufferWithFormat)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
 typedef void (*WGPUProcRenderPassEncoderSetPipeline)(WGPURenderPassEncoder renderPassEncoder, WGPURenderPipeline pipeline);
 typedef void (*WGPUProcRenderPassEncoderSetScissorRect)(WGPURenderPassEncoder renderPassEncoder, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
 typedef void (*WGPUProcRenderPassEncoderSetStencilReference)(WGPURenderPassEncoder renderPassEncoder, uint32_t reference);
 typedef void (*WGPUProcRenderPassEncoderSetVertexBuffer)(WGPURenderPassEncoder renderPassEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset, uint64_t size);
 typedef void (*WGPUProcRenderPassEncoderSetViewport)(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth);
+typedef void (*WGPUProcRenderPassEncoderWriteTimestamp)(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 typedef void (*WGPUProcRenderPassEncoderReference)(WGPURenderPassEncoder renderPassEncoder);
 typedef void (*WGPUProcRenderPassEncoderRelease)(WGPURenderPassEncoder renderPassEncoder);
 
@@ -1033,9 +1169,9 @@ WGPU_EXPORT void wgpuBindGroupLayoutRelease(WGPUBindGroupLayout bindGroupLayout)
 
 // Methods of Buffer
 WGPU_EXPORT void wgpuBufferDestroy(WGPUBuffer buffer);
-WGPU_EXPORT void wgpuBufferMapReadAsync(WGPUBuffer buffer, WGPUBufferMapReadCallback callback, void * userdata);
-WGPU_EXPORT void wgpuBufferMapWriteAsync(WGPUBuffer buffer, WGPUBufferMapWriteCallback callback, void * userdata);
-WGPU_EXPORT void wgpuBufferSetSubData(WGPUBuffer buffer, uint64_t start, uint64_t count, void const * data);
+WGPU_EXPORT void const * wgpuBufferGetConstMappedRange(WGPUBuffer buffer, size_t offset, size_t size);
+WGPU_EXPORT void * wgpuBufferGetMappedRange(WGPUBuffer buffer, size_t offset, size_t size);
+WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata);
 WGPU_EXPORT void wgpuBufferUnmap(WGPUBuffer buffer);
 WGPU_EXPORT void wgpuBufferReference(WGPUBuffer buffer);
 WGPU_EXPORT void wgpuBufferRelease(WGPUBuffer buffer);
@@ -1052,9 +1188,12 @@ WGPU_EXPORT void wgpuCommandEncoderCopyBufferToTexture(WGPUCommandEncoder comman
 WGPU_EXPORT void wgpuCommandEncoderCopyTextureToBuffer(WGPUCommandEncoder commandEncoder, WGPUTextureCopyView const * source, WGPUBufferCopyView const * destination, WGPUExtent3D const * copySize);
 WGPU_EXPORT void wgpuCommandEncoderCopyTextureToTexture(WGPUCommandEncoder commandEncoder, WGPUTextureCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize);
 WGPU_EXPORT WGPUCommandBuffer wgpuCommandEncoderFinish(WGPUCommandEncoder commandEncoder, WGPUCommandBufferDescriptor const * descriptor);
-WGPU_EXPORT void wgpuCommandEncoderInsertDebugMarker(WGPUCommandEncoder commandEncoder, char const * groupLabel);
+WGPU_EXPORT void wgpuCommandEncoderInjectValidationError(WGPUCommandEncoder commandEncoder, char const * message);
+WGPU_EXPORT void wgpuCommandEncoderInsertDebugMarker(WGPUCommandEncoder commandEncoder, char const * markerLabel);
 WGPU_EXPORT void wgpuCommandEncoderPopDebugGroup(WGPUCommandEncoder commandEncoder);
 WGPU_EXPORT void wgpuCommandEncoderPushDebugGroup(WGPUCommandEncoder commandEncoder, char const * groupLabel);
+WGPU_EXPORT void wgpuCommandEncoderResolveQuerySet(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t firstQuery, uint32_t queryCount, WGPUBuffer destination, uint64_t destinationOffset);
+WGPU_EXPORT void wgpuCommandEncoderWriteTimestamp(WGPUCommandEncoder commandEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 WGPU_EXPORT void wgpuCommandEncoderReference(WGPUCommandEncoder commandEncoder);
 WGPU_EXPORT void wgpuCommandEncoderRelease(WGPUCommandEncoder commandEncoder);
 
@@ -1062,11 +1201,12 @@ WGPU_EXPORT void wgpuCommandEncoderRelease(WGPUCommandEncoder commandEncoder);
 WGPU_EXPORT void wgpuComputePassEncoderDispatch(WGPUComputePassEncoder computePassEncoder, uint32_t x, uint32_t y, uint32_t z);
 WGPU_EXPORT void wgpuComputePassEncoderDispatchIndirect(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 WGPU_EXPORT void wgpuComputePassEncoderEndPass(WGPUComputePassEncoder computePassEncoder);
-WGPU_EXPORT void wgpuComputePassEncoderInsertDebugMarker(WGPUComputePassEncoder computePassEncoder, char const * groupLabel);
+WGPU_EXPORT void wgpuComputePassEncoderInsertDebugMarker(WGPUComputePassEncoder computePassEncoder, char const * markerLabel);
 WGPU_EXPORT void wgpuComputePassEncoderPopDebugGroup(WGPUComputePassEncoder computePassEncoder);
 WGPU_EXPORT void wgpuComputePassEncoderPushDebugGroup(WGPUComputePassEncoder computePassEncoder, char const * groupLabel);
 WGPU_EXPORT void wgpuComputePassEncoderSetBindGroup(WGPUComputePassEncoder computePassEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
 WGPU_EXPORT void wgpuComputePassEncoderSetPipeline(WGPUComputePassEncoder computePassEncoder, WGPUComputePipeline pipeline);
+WGPU_EXPORT void wgpuComputePassEncoderWriteTimestamp(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 WGPU_EXPORT void wgpuComputePassEncoderReference(WGPUComputePassEncoder computePassEncoder);
 WGPU_EXPORT void wgpuComputePassEncoderRelease(WGPUComputePassEncoder computePassEncoder);
 
@@ -1079,11 +1219,13 @@ WGPU_EXPORT void wgpuComputePipelineRelease(WGPUComputePipeline computePipeline)
 WGPU_EXPORT WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor);
 WGPU_EXPORT WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor);
 WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
-WGPU_EXPORT WGPUCreateBufferMappedResult wgpuDeviceCreateBufferMapped(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
 WGPU_EXPORT WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor);
 WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor);
+WGPU_EXPORT WGPUBuffer wgpuDeviceCreateErrorBuffer(WGPUDevice device);
 WGPU_EXPORT WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor);
-WGPU_EXPORT WGPUQueue wgpuDeviceCreateQueue(WGPUDevice device);
+WGPU_EXPORT WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor);
+WGPU_EXPORT void wgpuDeviceCreateReadyComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateReadyComputePipelineCallback callback, void * userdata);
+WGPU_EXPORT void wgpuDeviceCreateReadyRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateReadyRenderPipelineCallback callback, void * userdata);
 WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor);
 WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor);
 WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor);
@@ -1116,10 +1258,18 @@ WGPU_EXPORT void wgpuInstanceRelease(WGPUInstance instance);
 WGPU_EXPORT void wgpuPipelineLayoutReference(WGPUPipelineLayout pipelineLayout);
 WGPU_EXPORT void wgpuPipelineLayoutRelease(WGPUPipelineLayout pipelineLayout);
 
+// Methods of QuerySet
+WGPU_EXPORT void wgpuQuerySetDestroy(WGPUQuerySet querySet);
+WGPU_EXPORT void wgpuQuerySetReference(WGPUQuerySet querySet);
+WGPU_EXPORT void wgpuQuerySetRelease(WGPUQuerySet querySet);
+
 // Methods of Queue
+WGPU_EXPORT void wgpuQueueCopyTextureForBrowser(WGPUQueue queue, WGPUTextureCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize, WGPUCopyTextureForBrowserOptions const * options);
 WGPU_EXPORT WGPUFence wgpuQueueCreateFence(WGPUQueue queue, WGPUFenceDescriptor const * descriptor);
 WGPU_EXPORT void wgpuQueueSignal(WGPUQueue queue, WGPUFence fence, uint64_t signalValue);
 WGPU_EXPORT void wgpuQueueSubmit(WGPUQueue queue, uint32_t commandCount, WGPUCommandBuffer const * commands);
+WGPU_EXPORT void wgpuQueueWriteBuffer(WGPUQueue queue, WGPUBuffer buffer, uint64_t bufferOffset, void const * data, size_t size);
+WGPU_EXPORT void wgpuQueueWriteTexture(WGPUQueue queue, WGPUTextureCopyView const * destination, void const * data, size_t dataSize, WGPUTextureDataLayout const * dataLayout, WGPUExtent3D const * writeSize);
 WGPU_EXPORT void wgpuQueueReference(WGPUQueue queue);
 WGPU_EXPORT void wgpuQueueRelease(WGPUQueue queue);
 
@@ -1133,34 +1283,39 @@ WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndexed(WGPURenderBundleEncoder rend
 WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndexedIndirect(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndirect(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 WGPU_EXPORT WGPURenderBundle wgpuRenderBundleEncoderFinish(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderBundleDescriptor const * descriptor);
-WGPU_EXPORT void wgpuRenderBundleEncoderInsertDebugMarker(WGPURenderBundleEncoder renderBundleEncoder, char const * groupLabel);
+WGPU_EXPORT void wgpuRenderBundleEncoderInsertDebugMarker(WGPURenderBundleEncoder renderBundleEncoder, char const * markerLabel);
 WGPU_EXPORT void wgpuRenderBundleEncoderPopDebugGroup(WGPURenderBundleEncoder renderBundleEncoder);
 WGPU_EXPORT void wgpuRenderBundleEncoderPushDebugGroup(WGPURenderBundleEncoder renderBundleEncoder, char const * groupLabel);
 WGPU_EXPORT void wgpuRenderBundleEncoderSetBindGroup(WGPURenderBundleEncoder renderBundleEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
-WGPU_EXPORT void wgpuRenderBundleEncoderSetIndexBuffer(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size);
+WGPU_EXPORT void wgpuRenderBundleEncoderSetIndexBuffer(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
+WGPU_EXPORT void wgpuRenderBundleEncoderSetIndexBufferWithFormat(WGPURenderBundleEncoder renderBundleEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
 WGPU_EXPORT void wgpuRenderBundleEncoderSetPipeline(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderPipeline pipeline);
 WGPU_EXPORT void wgpuRenderBundleEncoderSetVertexBuffer(WGPURenderBundleEncoder renderBundleEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset, uint64_t size);
 WGPU_EXPORT void wgpuRenderBundleEncoderReference(WGPURenderBundleEncoder renderBundleEncoder);
 WGPU_EXPORT void wgpuRenderBundleEncoderRelease(WGPURenderBundleEncoder renderBundleEncoder);
 
 // Methods of RenderPassEncoder
+WGPU_EXPORT void wgpuRenderPassEncoderBeginOcclusionQuery(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex);
 WGPU_EXPORT void wgpuRenderPassEncoderDraw(WGPURenderPassEncoder renderPassEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
 WGPU_EXPORT void wgpuRenderPassEncoderDrawIndexed(WGPURenderPassEncoder renderPassEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
 WGPU_EXPORT void wgpuRenderPassEncoderDrawIndexedIndirect(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
 WGPU_EXPORT void wgpuRenderPassEncoderDrawIndirect(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset);
+WGPU_EXPORT void wgpuRenderPassEncoderEndOcclusionQuery(WGPURenderPassEncoder renderPassEncoder);
 WGPU_EXPORT void wgpuRenderPassEncoderEndPass(WGPURenderPassEncoder renderPassEncoder);
 WGPU_EXPORT void wgpuRenderPassEncoderExecuteBundles(WGPURenderPassEncoder renderPassEncoder, uint32_t bundlesCount, WGPURenderBundle const * bundles);
-WGPU_EXPORT void wgpuRenderPassEncoderInsertDebugMarker(WGPURenderPassEncoder renderPassEncoder, char const * groupLabel);
+WGPU_EXPORT void wgpuRenderPassEncoderInsertDebugMarker(WGPURenderPassEncoder renderPassEncoder, char const * markerLabel);
 WGPU_EXPORT void wgpuRenderPassEncoderPopDebugGroup(WGPURenderPassEncoder renderPassEncoder);
 WGPU_EXPORT void wgpuRenderPassEncoderPushDebugGroup(WGPURenderPassEncoder renderPassEncoder, char const * groupLabel);
 WGPU_EXPORT void wgpuRenderPassEncoderSetBindGroup(WGPURenderPassEncoder renderPassEncoder, uint32_t groupIndex, WGPUBindGroup group, uint32_t dynamicOffsetCount, uint32_t const * dynamicOffsets);
 WGPU_EXPORT void wgpuRenderPassEncoderSetBlendColor(WGPURenderPassEncoder renderPassEncoder, WGPUColor const * color);
-WGPU_EXPORT void wgpuRenderPassEncoderSetIndexBuffer(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size);
+WGPU_EXPORT void wgpuRenderPassEncoderSetIndexBuffer(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
+WGPU_EXPORT void wgpuRenderPassEncoderSetIndexBufferWithFormat(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer buffer, WGPUIndexFormat format, uint64_t offset, uint64_t size);
 WGPU_EXPORT void wgpuRenderPassEncoderSetPipeline(WGPURenderPassEncoder renderPassEncoder, WGPURenderPipeline pipeline);
 WGPU_EXPORT void wgpuRenderPassEncoderSetScissorRect(WGPURenderPassEncoder renderPassEncoder, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
 WGPU_EXPORT void wgpuRenderPassEncoderSetStencilReference(WGPURenderPassEncoder renderPassEncoder, uint32_t reference);
 WGPU_EXPORT void wgpuRenderPassEncoderSetVertexBuffer(WGPURenderPassEncoder renderPassEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset, uint64_t size);
 WGPU_EXPORT void wgpuRenderPassEncoderSetViewport(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth);
+WGPU_EXPORT void wgpuRenderPassEncoderWriteTimestamp(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
 WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder);
 WGPU_EXPORT void wgpuRenderPassEncoderRelease(WGPURenderPassEncoder renderPassEncoder);
 

+ 264 - 119
3rdparty/webgpu/include/webgpu/webgpu_cpp.h

@@ -1,13 +1,15 @@
-
 #ifndef WEBGPU_CPP_H_
 #define WEBGPU_CPP_H_
 
-#include "webgpu/webgpu.h"
-#include "webgpu/EnumClassBitmasks.h"
+#include "dawn/webgpu.h"
+#include "dawn/EnumClassBitmasks.h"
 
 namespace wgpu {
 
     static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
+    // TODO(crbug.com/520): Remove kStrideUndefined in favor of kCopyStrideUndefined.
+    static constexpr uint32_t kStrideUndefined = WGPU_STRIDE_UNDEFINED;
+    static constexpr uint32_t kCopyStrideUndefined = WGPU_COPY_STRIDE_UNDEFINED;
 
     enum class AdapterType : uint32_t {
         DiscreteGPU = 0x00000000,
@@ -33,15 +35,16 @@ namespace wgpu {
     };
 
     enum class BindingType : uint32_t {
-        UniformBuffer = 0x00000000,
-        StorageBuffer = 0x00000001,
-        ReadonlyStorageBuffer = 0x00000002,
-        Sampler = 0x00000003,
-        ComparisonSampler = 0x00000004,
-        SampledTexture = 0x00000005,
-        StorageTexture = 0x00000006,
-        ReadonlyStorageTexture = 0x00000007,
-        WriteonlyStorageTexture = 0x00000008,
+        Undefined = 0x00000000,
+        UniformBuffer = 0x00000001,
+        StorageBuffer = 0x00000002,
+        ReadonlyStorageBuffer = 0x00000003,
+        Sampler = 0x00000004,
+        ComparisonSampler = 0x00000005,
+        SampledTexture = 0x00000006,
+        MultisampledTexture = 0x00000007,
+        ReadonlyStorageTexture = 0x00000008,
+        WriteonlyStorageTexture = 0x00000009,
     };
 
     enum class BlendFactor : uint32_t {
@@ -68,11 +71,20 @@ namespace wgpu {
         Max = 0x00000004,
     };
 
+    enum class BufferBindingType : uint32_t {
+        Undefined = 0x00000000,
+        Uniform = 0x00000001,
+        Storage = 0x00000002,
+        ReadOnlyStorage = 0x00000003,
+    };
+
     enum class BufferMapAsyncStatus : uint32_t {
         Success = 0x00000000,
         Error = 0x00000001,
         Unknown = 0x00000002,
         DeviceLost = 0x00000003,
+        DestroyedBeforeCallback = 0x00000004,
+        UnmappedBeforeCallback = 0x00000005,
     };
 
     enum class CompareFunction : uint32_t {
@@ -87,6 +99,14 @@ namespace wgpu {
         Always = 0x00000008,
     };
 
+    enum class CreateReadyPipelineStatus : uint32_t {
+        Success = 0x00000000,
+        Error = 0x00000001,
+        DeviceLost = 0x00000002,
+        DeviceDestroyed = 0x00000003,
+        Unknown = 0x00000004,
+    };
+
     enum class CullMode : uint32_t {
         None = 0x00000000,
         Front = 0x00000001,
@@ -125,8 +145,9 @@ namespace wgpu {
     };
 
     enum class IndexFormat : uint32_t {
-        Uint16 = 0x00000000,
-        Uint32 = 0x00000001,
+        Undefined = 0x00000000,
+        Uint16 = 0x00000001,
+        Uint32 = 0x00000002,
     };
 
     enum class InputStepMode : uint32_t {
@@ -139,6 +160,14 @@ namespace wgpu {
         Load = 0x00000001,
     };
 
+    enum class PipelineStatisticName : uint32_t {
+        VertexShaderInvocations = 0x00000000,
+        ClipperInvocations = 0x00000001,
+        ClipperPrimitivesOut = 0x00000002,
+        FragmentShaderInvocations = 0x00000003,
+        ComputeShaderInvocations = 0x00000004,
+    };
+
     enum class PresentMode : uint32_t {
         Immediate = 0x00000000,
         Mailbox = 0x00000001,
@@ -153,18 +182,31 @@ namespace wgpu {
         TriangleStrip = 0x00000004,
     };
 
+    enum class QueryType : uint32_t {
+        Occlusion = 0x00000000,
+        PipelineStatistics = 0x00000001,
+        Timestamp = 0x00000002,
+    };
+
     enum class SType : uint32_t {
         Invalid = 0x00000000,
         SurfaceDescriptorFromMetalLayer = 0x00000001,
         SurfaceDescriptorFromWindowsHWND = 0x00000002,
         SurfaceDescriptorFromXlib = 0x00000003,
-        SurfaceDescriptorFromHTMLCanvasId = 0x00000004,
+        SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
         ShaderModuleSPIRVDescriptor = 0x00000005,
         ShaderModuleWGSLDescriptor = 0x00000006,
         SamplerDescriptorDummyAnisotropicFiltering = 0x00000007,
         RenderPipelineDescriptorDummyExtension = 0x00000008,
     };
 
+    enum class SamplerBindingType : uint32_t {
+        Undefined = 0x00000000,
+        Filtering = 0x00000001,
+        NonFiltering = 0x00000002,
+        Comparison = 0x00000003,
+    };
+
     enum class StencilOperation : uint32_t {
         Keep = 0x00000000,
         Zero = 0x00000001,
@@ -176,6 +218,12 @@ namespace wgpu {
         DecrementWrap = 0x00000007,
     };
 
+    enum class StorageTextureAccess : uint32_t {
+        Undefined = 0x00000000,
+        ReadOnly = 0x00000001,
+        WriteOnly = 0x00000002,
+    };
+
     enum class StoreOp : uint32_t {
         Store = 0x00000000,
         Clear = 0x00000001,
@@ -191,6 +239,7 @@ namespace wgpu {
         Float = 0x00000000,
         Sint = 0x00000001,
         Uint = 0x00000002,
+        DepthComparison = 0x00000003,
     };
 
     enum class TextureDimension : uint32_t {
@@ -226,33 +275,43 @@ namespace wgpu {
         BGRA8Unorm = 0x00000017,
         BGRA8UnormSrgb = 0x00000018,
         RGB10A2Unorm = 0x00000019,
-        RG11B10Float = 0x0000001A,
-        RG32Float = 0x0000001B,
-        RG32Uint = 0x0000001C,
-        RG32Sint = 0x0000001D,
-        RGBA16Uint = 0x0000001E,
-        RGBA16Sint = 0x0000001F,
-        RGBA16Float = 0x00000020,
-        RGBA32Float = 0x00000021,
-        RGBA32Uint = 0x00000022,
-        RGBA32Sint = 0x00000023,
-        Depth32Float = 0x00000024,
-        Depth24Plus = 0x00000025,
-        Depth24PlusStencil8 = 0x00000026,
-        BC1RGBAUnorm = 0x00000027,
-        BC1RGBAUnormSrgb = 0x00000028,
-        BC2RGBAUnorm = 0x00000029,
-        BC2RGBAUnormSrgb = 0x0000002A,
-        BC3RGBAUnorm = 0x0000002B,
-        BC3RGBAUnormSrgb = 0x0000002C,
-        BC4RUnorm = 0x0000002D,
-        BC4RSnorm = 0x0000002E,
-        BC5RGUnorm = 0x0000002F,
-        BC5RGSnorm = 0x00000030,
-        BC6HRGBUfloat = 0x00000031,
-        BC6HRGBSfloat = 0x00000032,
-        BC7RGBAUnorm = 0x00000033,
-        BC7RGBAUnormSrgb = 0x00000034,
+        RG11B10Ufloat = 0x0000001A,
+        RGB9E5Ufloat = 0x0000001B,
+        RG32Float = 0x0000001C,
+        RG32Uint = 0x0000001D,
+        RG32Sint = 0x0000001E,
+        RGBA16Uint = 0x0000001F,
+        RGBA16Sint = 0x00000020,
+        RGBA16Float = 0x00000021,
+        RGBA32Float = 0x00000022,
+        RGBA32Uint = 0x00000023,
+        RGBA32Sint = 0x00000024,
+        Depth32Float = 0x00000025,
+        Depth24Plus = 0x00000026,
+        Depth24PlusStencil8 = 0x00000027,
+        BC1RGBAUnorm = 0x00000028,
+        BC1RGBAUnormSrgb = 0x00000029,
+        BC2RGBAUnorm = 0x0000002A,
+        BC2RGBAUnormSrgb = 0x0000002B,
+        BC3RGBAUnorm = 0x0000002C,
+        BC3RGBAUnormSrgb = 0x0000002D,
+        BC4RUnorm = 0x0000002E,
+        BC4RSnorm = 0x0000002F,
+        BC5RGUnorm = 0x00000030,
+        BC5RGSnorm = 0x00000031,
+        BC6HRGBUfloat = 0x00000032,
+        BC6HRGBFloat = 0x00000033,
+        BC7RGBAUnorm = 0x00000034,
+        BC7RGBAUnormSrgb = 0x00000035,
+    };
+
+    enum class TextureSampleType : uint32_t {
+        Undefined = 0x00000000,
+        Float = 0x00000001,
+        UnfilterableFloat = 0x00000002,
+        Depth = 0x00000003,
+        Sint = 0x00000004,
+        Uint = 0x00000005,
     };
 
     enum class TextureViewDimension : uint32_t {
@@ -310,6 +369,7 @@ namespace wgpu {
         Uniform = 0x00000040,
         Storage = 0x00000080,
         Indirect = 0x00000100,
+        QueryResolve = 0x00000200,
     };
 
     enum class ColorWriteMask : uint32_t {
@@ -321,6 +381,12 @@ namespace wgpu {
         All = 0x0000000F,
     };
 
+    enum class MapMode : uint32_t {
+        None = 0x00000000,
+        Read = 0x00000001,
+        Write = 0x00000002,
+    };
+
     enum class ShaderStage : uint32_t {
         None = 0x00000000,
         Vertex = 0x00000001,
@@ -335,6 +401,7 @@ namespace wgpu {
         Sampled = 0x00000004,
         Storage = 0x00000008,
         OutputAttachment = 0x00000010,
+        RenderAttachment = 0x00000010,
         Present = 0x00000020,
     };
 
@@ -349,6 +416,11 @@ namespace wgpu {
         static constexpr bool enable = true;
     };
 
+    template<>
+    struct IsDawnBitmask<MapMode> {
+        static constexpr bool enable = true;
+    };
+
     template<>
     struct IsDawnBitmask<ShaderStage> {
         static constexpr bool enable = true;
@@ -361,8 +433,9 @@ namespace wgpu {
 
 
     using Proc = WGPUProc;
-    using BufferMapReadCallback = WGPUBufferMapReadCallback;
-    using BufferMapWriteCallback = WGPUBufferMapWriteCallback;
+    using BufferMapCallback = WGPUBufferMapCallback;
+    using CreateReadyComputePipelineCallback = WGPUCreateReadyComputePipelineCallback;
+    using CreateReadyRenderPipelineCallback = WGPUCreateReadyRenderPipelineCallback;
     using DeviceLostCallback = WGPUDeviceLostCallback;
     using ErrorCallback = WGPUErrorCallback;
     using FenceOnCompletionCallback = WGPUFenceOnCompletionCallback;
@@ -378,6 +451,7 @@ namespace wgpu {
     class Fence;
     class Instance;
     class PipelineLayout;
+    class QuerySet;
     class Queue;
     class RenderBundle;
     class RenderBundleEncoder;
@@ -392,15 +466,14 @@ namespace wgpu {
 
     struct AdapterProperties;
     struct BindGroupEntry;
-    struct BindGroupLayoutEntry;
     struct BlendDescriptor;
-    struct BufferCopyView;
+    struct BufferBindingLayout;
     struct BufferDescriptor;
     struct Color;
     struct CommandBufferDescriptor;
     struct CommandEncoderDescriptor;
     struct ComputePassDescriptor;
-    struct CreateBufferMappedResult;
+    struct CopyTextureForBrowserOptions;
     struct DeviceProperties;
     struct Extent3D;
     struct FenceDescriptor;
@@ -408,26 +481,32 @@ namespace wgpu {
     struct Origin3D;
     struct PipelineLayoutDescriptor;
     struct ProgrammableStageDescriptor;
+    struct QuerySetDescriptor;
     struct RasterizationStateDescriptor;
     struct RenderBundleDescriptor;
     struct RenderBundleEncoderDescriptor;
     struct RenderPassDepthStencilAttachmentDescriptor;
+    struct SamplerBindingLayout;
     struct SamplerDescriptor;
     struct SamplerDescriptorDummyAnisotropicFiltering;
     struct ShaderModuleDescriptor;
     struct ShaderModuleSPIRVDescriptor;
     struct ShaderModuleWGSLDescriptor;
     struct StencilStateFaceDescriptor;
+    struct StorageTextureBindingLayout;
     struct SurfaceDescriptor;
-    struct SurfaceDescriptorFromHTMLCanvasId;
+    struct SurfaceDescriptorFromCanvasHTMLSelector;
     struct SurfaceDescriptorFromMetalLayer;
     struct SurfaceDescriptorFromWindowsHWND;
     struct SurfaceDescriptorFromXlib;
     struct SwapChainDescriptor;
+    struct TextureBindingLayout;
+    struct TextureDataLayout;
     struct TextureViewDescriptor;
     struct VertexAttributeDescriptor;
     struct BindGroupDescriptor;
-    struct BindGroupLayoutDescriptor;
+    struct BindGroupLayoutEntry;
+    struct BufferCopyView;
     struct ColorStateDescriptor;
     struct ComputePipelineDescriptor;
     struct DepthStencilStateDescriptor;
@@ -436,6 +515,7 @@ namespace wgpu {
     struct TextureCopyView;
     struct TextureDescriptor;
     struct VertexBufferLayoutDescriptor;
+    struct BindGroupLayoutDescriptor;
     struct RenderPassDescriptor;
     struct VertexStateDescriptor;
     struct RenderPipelineDescriptor;
@@ -547,9 +627,9 @@ namespace wgpu {
         using ObjectBase::operator=;
 
         void Destroy() const;
-        void MapReadAsync(BufferMapReadCallback callback, void * userdata) const;
-        void MapWriteAsync(BufferMapWriteCallback callback, void * userdata) const;
-        void SetSubData(uint64_t start, uint64_t count, void const * data) const;
+        void const * GetConstMappedRange(size_t offset = 0, size_t size = 0) const;
+        void * GetMappedRange(size_t offset = 0, size_t size = 0) const;
+        void MapAsync(MapMode mode, size_t offset, size_t size, BufferMapCallback callback, void * userdata) const;
         void Unmap() const;
 
       private:
@@ -582,9 +662,12 @@ namespace wgpu {
         void CopyTextureToBuffer(TextureCopyView const * source, BufferCopyView const * destination, Extent3D const * copySize) const;
         void CopyTextureToTexture(TextureCopyView const * source, TextureCopyView const * destination, Extent3D const * copySize) const;
         CommandBuffer Finish(CommandBufferDescriptor const * descriptor = nullptr) const;
-        void InsertDebugMarker(char const * groupLabel) const;
+        void InjectValidationError(char const * message) const;
+        void InsertDebugMarker(char const * markerLabel) const;
         void PopDebugGroup() const;
         void PushDebugGroup(char const * groupLabel) const;
+        void ResolveQuerySet(QuerySet const& querySet, uint32_t firstQuery, uint32_t queryCount, Buffer const& destination, uint64_t destinationOffset) const;
+        void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
 
       private:
         friend ObjectBase<CommandEncoder, WGPUCommandEncoder>;
@@ -600,11 +683,12 @@ namespace wgpu {
         void Dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) const;
         void DispatchIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
         void EndPass() const;
-        void InsertDebugMarker(char const * groupLabel) const;
+        void InsertDebugMarker(char const * markerLabel) const;
         void PopDebugGroup() const;
         void PushDebugGroup(char const * groupLabel) const;
         void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
         void SetPipeline(ComputePipeline const& pipeline) const;
+        void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
 
       private:
         friend ObjectBase<ComputePassEncoder, WGPUComputePassEncoder>;
@@ -633,11 +717,13 @@ namespace wgpu {
         BindGroup CreateBindGroup(BindGroupDescriptor const * descriptor) const;
         BindGroupLayout CreateBindGroupLayout(BindGroupLayoutDescriptor const * descriptor) const;
         Buffer CreateBuffer(BufferDescriptor const * descriptor) const;
-        CreateBufferMappedResult CreateBufferMapped(BufferDescriptor const * descriptor) const;
         CommandEncoder CreateCommandEncoder(CommandEncoderDescriptor const * descriptor = nullptr) const;
         ComputePipeline CreateComputePipeline(ComputePipelineDescriptor const * descriptor) const;
+        Buffer CreateErrorBuffer() const;
         PipelineLayout CreatePipelineLayout(PipelineLayoutDescriptor const * descriptor) const;
-        Queue CreateQueue() const;
+        QuerySet CreateQuerySet(QuerySetDescriptor const * descriptor) const;
+        void CreateReadyComputePipeline(ComputePipelineDescriptor const * descriptor, CreateReadyComputePipelineCallback callback, void * userdata) const;
+        void CreateReadyRenderPipeline(RenderPipelineDescriptor const * descriptor, CreateReadyRenderPipelineCallback callback, void * userdata) const;
         RenderBundleEncoder CreateRenderBundleEncoder(RenderBundleEncoderDescriptor const * descriptor) const;
         RenderPipeline CreateRenderPipeline(RenderPipelineDescriptor const * descriptor) const;
         Sampler CreateSampler(SamplerDescriptor const * descriptor) const;
@@ -698,14 +784,30 @@ namespace wgpu {
         static void WGPURelease(WGPUPipelineLayout handle);
     };
 
+    class QuerySet : public ObjectBase<QuerySet, WGPUQuerySet> {
+      public:
+        using ObjectBase::ObjectBase;
+        using ObjectBase::operator=;
+
+        void Destroy() const;
+
+      private:
+        friend ObjectBase<QuerySet, WGPUQuerySet>;
+        static void WGPUReference(WGPUQuerySet handle);
+        static void WGPURelease(WGPUQuerySet handle);
+    };
+
     class Queue : public ObjectBase<Queue, WGPUQueue> {
       public:
         using ObjectBase::ObjectBase;
         using ObjectBase::operator=;
 
-        Fence CreateFence(FenceDescriptor const * descriptor) const;
+        void CopyTextureForBrowser(TextureCopyView const * source, TextureCopyView const * destination, Extent3D const * copySize, CopyTextureForBrowserOptions const * options) const;
+        Fence CreateFence(FenceDescriptor const * descriptor = nullptr) const;
         void Signal(Fence const& fence, uint64_t signalValue) const;
         void Submit(uint32_t commandCount, CommandBuffer const * commands) const;
+        void WriteBuffer(Buffer const& buffer, uint64_t bufferOffset, void const * data, size_t size) const;
+        void WriteTexture(TextureCopyView const * destination, void const * data, size_t dataSize, TextureDataLayout const * dataLayout, Extent3D const * writeSize) const;
 
       private:
         friend ObjectBase<Queue, WGPUQueue>;
@@ -735,11 +837,12 @@ namespace wgpu {
         void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
         void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
         RenderBundle Finish(RenderBundleDescriptor const * descriptor = nullptr) const;
-        void InsertDebugMarker(char const * groupLabel) const;
+        void InsertDebugMarker(char const * markerLabel) const;
         void PopDebugGroup() const;
         void PushDebugGroup(char const * groupLabel) const;
         void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
-        void SetIndexBuffer(Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
+        void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
+        void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
         void SetPipeline(RenderPipeline const& pipeline) const;
         void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
 
@@ -754,23 +857,27 @@ namespace wgpu {
         using ObjectBase::ObjectBase;
         using ObjectBase::operator=;
 
+        void BeginOcclusionQuery(uint32_t queryIndex) const;
         void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t firstVertex = 0, uint32_t firstInstance = 0) const;
         void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t firstIndex = 0, int32_t baseVertex = 0, uint32_t firstInstance = 0) const;
         void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
         void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
+        void EndOcclusionQuery() const;
         void EndPass() const;
         void ExecuteBundles(uint32_t bundlesCount, RenderBundle const * bundles) const;
-        void InsertDebugMarker(char const * groupLabel) const;
+        void InsertDebugMarker(char const * markerLabel) const;
         void PopDebugGroup() const;
         void PushDebugGroup(char const * groupLabel) const;
         void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
         void SetBlendColor(Color const * color) const;
-        void SetIndexBuffer(Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
+        void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
+        void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
         void SetPipeline(RenderPipeline const& pipeline) const;
         void SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height) const;
         void SetStencilReference(uint32_t reference) const;
         void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
         void SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth) const;
+        void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
 
       private:
         friend ObjectBase<RenderPassEncoder, WGPURenderPassEncoder>;
@@ -882,29 +989,18 @@ namespace wgpu {
         uint32_t deviceID;
         uint32_t vendorID;
         char const * name;
+        char const * driverDescription;
         AdapterType adapterType;
         BackendType backendType;
     };
 
     struct BindGroupEntry {
         uint32_t binding;
-        Buffer buffer;
+        Buffer buffer = nullptr;
         uint64_t offset = 0;
         uint64_t size;
-        Sampler sampler;
-        TextureView textureView;
-    };
-
-    struct BindGroupLayoutEntry {
-        uint32_t binding;
-        ShaderStage visibility;
-        BindingType type;
-        bool hasDynamicOffset = false;
-        bool multisampled = false;
-        TextureViewDimension textureDimension = TextureViewDimension::Undefined;
-        TextureViewDimension viewDimension = TextureViewDimension::Undefined;
-        TextureComponentType textureComponentType = TextureComponentType::Float;
-        TextureFormat storageTextureFormat = TextureFormat::Undefined;
+        Sampler sampler = nullptr;
+        TextureView textureView = nullptr;
     };
 
     struct BlendDescriptor {
@@ -913,14 +1009,11 @@ namespace wgpu {
         BlendFactor dstFactor = BlendFactor::Zero;
     };
 
-    struct BufferCopyView {
+    struct BufferBindingLayout {
         ChainedStruct const * nextInChain = nullptr;
-        Buffer buffer;
-        uint64_t offset = 0;
-        uint32_t rowPitch = 0;
-        uint32_t imageHeight = 0;
-        uint32_t bytesPerRow = 0;
-        uint32_t rowsPerImage = 0;
+        BufferBindingType type = BufferBindingType::Undefined;
+        bool hasDynamicOffset = false;
+        uint64_t minBindingSize = 0;
     };
 
     struct BufferDescriptor {
@@ -928,13 +1021,14 @@ namespace wgpu {
         char const * label = nullptr;
         BufferUsage usage;
         uint64_t size;
+        bool mappedAtCreation = false;
     };
 
     struct Color {
-        float r;
-        float g;
-        float b;
-        float a;
+        double r;
+        double g;
+        double b;
+        double a;
     };
 
     struct CommandBufferDescriptor {
@@ -952,20 +1046,22 @@ namespace wgpu {
         char const * label = nullptr;
     };
 
-    struct CreateBufferMappedResult {
-        Buffer buffer;
-        uint64_t dataLength;
-        void * data;
+    struct CopyTextureForBrowserOptions {
+        ChainedStruct const * nextInChain = nullptr;
+        bool flipY = false;
     };
 
     struct DeviceProperties {
         bool textureCompressionBC = false;
+        bool shaderFloat16 = false;
+        bool pipelineStatisticsQuery = false;
+        bool timestampQuery = false;
     };
 
     struct Extent3D {
-        uint32_t width;
-        uint32_t height;
-        uint32_t depth;
+        uint32_t width = 1;
+        uint32_t height = 1;
+        uint32_t depth = 1;
     };
 
     struct FenceDescriptor {
@@ -997,6 +1093,15 @@ namespace wgpu {
         char const * entryPoint;
     };
 
+    struct QuerySetDescriptor {
+        ChainedStruct const * nextInChain = nullptr;
+        char const * label = nullptr;
+        QueryType type;
+        uint32_t count;
+        PipelineStatisticName const * pipelineStatistics;
+        uint32_t pipelineStatisticsCount = 0;
+    };
+
     struct RasterizationStateDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         FrontFace frontFace = FrontFace::CCW;
@@ -1025,9 +1130,16 @@ namespace wgpu {
         LoadOp depthLoadOp;
         StoreOp depthStoreOp;
         float clearDepth;
+        bool depthReadOnly = false;
         LoadOp stencilLoadOp;
         StoreOp stencilStoreOp;
         uint32_t clearStencil = 0;
+        bool stencilReadOnly = false;
+    };
+
+    struct SamplerBindingLayout {
+        ChainedStruct const * nextInChain = nullptr;
+        SamplerBindingType type = SamplerBindingType::Undefined;
     };
 
     struct SamplerDescriptor {
@@ -1042,6 +1154,7 @@ namespace wgpu {
         float lodMinClamp = 0.0f;
         float lodMaxClamp = 1000.0f;
         CompareFunction compare = CompareFunction::Undefined;
+        uint16_t maxAnisotropy = 1;
     };
 
     struct SamplerDescriptorDummyAnisotropicFiltering : ChainedStruct {
@@ -1054,8 +1167,6 @@ namespace wgpu {
     struct ShaderModuleDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
-        uint32_t codeSize = 0;
-        uint32_t const * code = nullptr;
     };
 
     struct ShaderModuleSPIRVDescriptor : ChainedStruct {
@@ -1080,16 +1191,23 @@ namespace wgpu {
         StencilOperation passOp = StencilOperation::Keep;
     };
 
+    struct StorageTextureBindingLayout {
+        ChainedStruct const * nextInChain = nullptr;
+        StorageTextureAccess access = StorageTextureAccess::Undefined;
+        TextureFormat format = TextureFormat::Undefined;
+        TextureViewDimension viewDimension = TextureViewDimension::Undefined;
+    };
+
     struct SurfaceDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
     };
 
-    struct SurfaceDescriptorFromHTMLCanvasId : ChainedStruct {
-        SurfaceDescriptorFromHTMLCanvasId() {
-            sType = SType::SurfaceDescriptorFromHTMLCanvasId;
+    struct SurfaceDescriptorFromCanvasHTMLSelector : ChainedStruct {
+        SurfaceDescriptorFromCanvasHTMLSelector() {
+            sType = SType::SurfaceDescriptorFromCanvasHTMLSelector;
         }
-        alignas(ChainedStruct) char const * id;
+        alignas(ChainedStruct) char const * selector;
     };
 
     struct SurfaceDescriptorFromMetalLayer : ChainedStruct {
@@ -1126,6 +1244,20 @@ namespace wgpu {
         uint64_t implementation = 0;
     };
 
+    struct TextureBindingLayout {
+        ChainedStruct const * nextInChain = nullptr;
+        TextureSampleType sampleType = TextureSampleType::Undefined;
+        TextureViewDimension viewDimension = TextureViewDimension::Undefined;
+        bool multisampled = false;
+    };
+
+    struct TextureDataLayout {
+        ChainedStruct const * nextInChain = nullptr;
+        uint64_t offset = 0;
+        uint32_t bytesPerRow = WGPU_COPY_STRIDE_UNDEFINED;
+        uint32_t rowsPerImage = WGPU_COPY_STRIDE_UNDEFINED;
+    };
+
     struct TextureViewDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
@@ -1148,19 +1280,29 @@ namespace wgpu {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
         BindGroupLayout layout;
-        uint32_t bindingCount = 0;
-        BindGroupEntry const * bindings;
-        uint32_t entryCount = 0;
+        uint32_t entryCount;
         BindGroupEntry const * entries;
     };
 
-    struct BindGroupLayoutDescriptor {
+    struct BindGroupLayoutEntry {
+        uint32_t binding;
+        ShaderStage visibility;
+        BindingType type = BindingType::Undefined;
+        bool hasDynamicOffset = false;
+        uint64_t minBufferBindingSize = 0;
+        TextureViewDimension viewDimension = TextureViewDimension::Undefined;
+        TextureComponentType textureComponentType = TextureComponentType::Float;
+        TextureFormat storageTextureFormat = TextureFormat::Undefined;
+        BufferBindingLayout buffer;
+        SamplerBindingLayout sampler;
+        TextureBindingLayout texture;
+        StorageTextureBindingLayout storageTexture;
+    };
+
+    struct BufferCopyView {
         ChainedStruct const * nextInChain = nullptr;
-        char const * label = nullptr;
-        uint32_t bindingCount = 0;
-        BindGroupLayoutEntry const * bindings;
-        uint32_t entryCount = 0;
-        BindGroupLayoutEntry const * entries;
+        TextureDataLayout layout;
+        Buffer buffer;
     };
 
     struct ColorStateDescriptor {
@@ -1174,7 +1316,7 @@ namespace wgpu {
     struct ComputePipelineDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
-        PipelineLayout layout;
+        PipelineLayout layout = nullptr;
         ProgrammableStageDescriptor computeStage;
     };
 
@@ -1191,7 +1333,7 @@ namespace wgpu {
 
     struct RenderPassColorAttachmentDescriptor {
         TextureView attachment;
-        TextureView resolveTarget;
+        TextureView resolveTarget = nullptr;
         LoadOp loadOp;
         StoreOp storeOp;
         Color clearColor;
@@ -1208,8 +1350,8 @@ namespace wgpu {
         ChainedStruct const * nextInChain = nullptr;
         Texture texture;
         uint32_t mipLevel = 0;
-        uint32_t arrayLayer = 0;
         Origin3D origin;
+        TextureAspect aspect = TextureAspect::All;
     };
 
     struct TextureDescriptor {
@@ -1218,7 +1360,6 @@ namespace wgpu {
         TextureUsage usage;
         TextureDimension dimension = TextureDimension::e2D;
         Extent3D size;
-        uint32_t arrayLayerCount = 1;
         TextureFormat format;
         uint32_t mipLevelCount = 1;
         uint32_t sampleCount = 1;
@@ -1231,17 +1372,25 @@ namespace wgpu {
         VertexAttributeDescriptor const * attributes;
     };
 
+    struct BindGroupLayoutDescriptor {
+        ChainedStruct const * nextInChain = nullptr;
+        char const * label = nullptr;
+        uint32_t entryCount;
+        BindGroupLayoutEntry const * entries;
+    };
+
     struct RenderPassDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
         uint32_t colorAttachmentCount;
         RenderPassColorAttachmentDescriptor const * colorAttachments;
         RenderPassDepthStencilAttachmentDescriptor const * depthStencilAttachment = nullptr;
+        QuerySet occlusionQuerySet = nullptr;
     };
 
     struct VertexStateDescriptor {
         ChainedStruct const * nextInChain = nullptr;
-        IndexFormat indexFormat = IndexFormat::Uint32;
+        IndexFormat indexFormat = IndexFormat::Undefined;
         uint32_t vertexBufferCount = 0;
         VertexBufferLayoutDescriptor const * vertexBuffers;
     };
@@ -1249,7 +1398,7 @@ namespace wgpu {
     struct RenderPipelineDescriptor {
         ChainedStruct const * nextInChain = nullptr;
         char const * label = nullptr;
-        PipelineLayout layout;
+        PipelineLayout layout = nullptr;
         ProgrammableStageDescriptor vertexStage;
         ProgrammableStageDescriptor const * fragmentStage = nullptr;
         VertexStateDescriptor const * vertexState = nullptr;
@@ -1264,10 +1413,6 @@ namespace wgpu {
     };
 
 
-    // TODO(dawn:22): Remove this once users use the "Entry" version.
-    using BindGroupBinding = BindGroupEntry;
-    using BindGroupLayoutBinding = BindGroupLayoutEntry;
-
 }  // namespace wgpu
 
 #endif // WEBGPU_CPP_H_

File diff suppressed because it is too large
+ 332 - 83
3rdparty/webgpu/webgpu_cpp.cpp


+ 3 - 11
scripts/bgfx.lua

@@ -184,9 +184,10 @@ function bgfxProjectBase(_kind, _defines)
 	if _OPTIONS["with-webgpu"] then
 		defines {
 			"BGFX_CONFIG_RENDERER_WEBGPU=1",
+			"BGFX_CONFIG_DEBUG_ANNOTATION=0", -- does not work
 		}
 
-		local generator = "out/VS2019"
+		local generator = "out/Default"
 
 		configuration { "wasm*" }
 			defines {
@@ -196,10 +197,8 @@ function bgfxProjectBase(_kind, _defines)
 
 		configuration { "not wasm*" }
 			includedirs {
-				path.join(DAWN_DIR, "src"),
 				path.join(DAWN_DIR, "src/include"),
 				path.join(DAWN_DIR, "third_party/vulkan-headers/include"),
-				path.join(DAWN_DIR, generator, "gen/src"),
 				path.join(DAWN_DIR, generator, "gen/src/include"),
 			}
 
@@ -297,13 +296,10 @@ if _OPTIONS["with-webgpu"] then
 			}
 
 		configuration { "not wasm*" }
-			--local generator = "out/Default"
-			local generator = "out/VS2019"
+			local generator = "out/Default"
 
 			includedirs {
-				path.join(DAWN_DIR, "src"),
 				path.join(DAWN_DIR, "src/include"),
-				path.join(DAWN_DIR, generator, "gen/src"),
 				path.join(DAWN_DIR, generator, "gen/src/include"),
 			}
 
@@ -312,10 +308,6 @@ if _OPTIONS["with-webgpu"] then
 				path.join(DAWN_DIR, generator, "lib/Debug"),
 			}
 
-			files {
-				path.join(DAWN_DIR, generator, "gen/src/dawn/webgpu_cpp.cpp"),
-			}
-
 			links {
 				-- shared
 				"dawn_proc_shared",

+ 1 - 1
scripts/genie.lua

@@ -178,7 +178,7 @@ if _OPTIONS["with-webgpu"] then
 		DAWN_DIR = path.getabsolute(path.join(BGFX_DIR, "../dawn"))
 	end
 
-	if not os.isdir(DAWN_DIR) then
+	if not os.isdir(DAWN_DIR) and "wasm*" ~= _OPTIONS["gcc"] then
 		print("Dawn not found at \"" .. DAWN_DIR .. "\". git clone https://dawn.googlesource.com/dawn?")
 
 		print("For more info see: https://bkaradzic.github.io/bgfx/build.html")

+ 159 - 126
src/renderer_webgpu.cpp

@@ -14,7 +14,25 @@
 #	include "debug_renderdoc.h"
 #	include "emscripten.h"
 
-#	if !BX_PLATFORM_EMSCRIPTEN
+#	if BX_PLATFORM_ANDROID
+#		define VK_USE_PLATFORM_ANDROID_KHR
+#	elif BX_PLATFORM_LINUX
+#		define VK_USE_PLATFORM_XLIB_KHR
+#		define VK_USE_PLATFORM_XCB_KHR
+#	elif BX_PLATFORM_WINDOWS
+#		define VK_USE_PLATFORM_WIN32_KHR
+#	elif BX_PLATFORM_OSX
+#		define VK_USE_PLATFORM_MACOS_MVK
+#	endif // BX_PLATFORM_*
+
+#	define VK_NO_STDINT_H
+#	define VK_NO_PROTOTYPES
+#	include <vulkan-local/vulkan.h>
+
+#	if BX_PLATFORM_EMSCRIPTEN
+#		include "emscripten.h"
+#		include "emscripten/html5_webgpu.h"
+#	else
 #		ifdef DAWN_ENABLE_BACKEND_D3D12
 #			include <dawn_native/D3D12Backend.h>
 #		endif // !BX_PLATFORM_EMSCRIPTEN
@@ -37,7 +55,7 @@ namespace bgfx { namespace webgpu
 	template <> wgpu::BlendDescriptor              defaultDescriptor() { return { wgpu::BlendOperation::Add, wgpu::BlendFactor::One, wgpu::BlendFactor::Zero }; }
 	template <> wgpu::ColorStateDescriptor         defaultDescriptor() { return { NULL, wgpu::TextureFormat::RGBA8Unorm, defaultDescriptor<wgpu::BlendDescriptor>(), defaultDescriptor<wgpu::BlendDescriptor>(), wgpu::ColorWriteMask::All }; }
 	template <> wgpu::StencilStateFaceDescriptor   defaultDescriptor() { return { wgpu::CompareFunction::Always, wgpu::StencilOperation::Keep, wgpu::StencilOperation::Keep, wgpu::StencilOperation::Keep }; }
-	template <> wgpu::VertexStateDescriptor        defaultDescriptor() { return { NULL, wgpu::IndexFormat::Uint32, 0, NULL }; }
+	template <> wgpu::VertexStateDescriptor        defaultDescriptor() { return { NULL, wgpu::IndexFormat::Undefined, 0, NULL }; }
 	template <> wgpu::VertexBufferLayoutDescriptor defaultDescriptor() { return { 0, wgpu::InputStepMode::Vertex, 0, NULL }; }
 	template <> wgpu::VertexAttributeDescriptor    defaultDescriptor() { return { wgpu::VertexFormat::Float, 0, 0 }; }
 	template <> wgpu::RasterizationStateDescriptor defaultDescriptor() { return { NULL, wgpu::FrontFace::CCW, wgpu::CullMode::None, 0, 0.f, 0.f }; }
@@ -47,7 +65,7 @@ namespace bgfx { namespace webgpu
 	template <> wgpu::TextureViewDescriptor        defaultDescriptor() { return {}; }
 
 	template <> wgpu::RenderPassColorAttachmentDescriptor defaultDescriptor() { return { {}, {}, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, { 0.0f, 0.0f, 0.0f, 0.0f } }; }
-	template <> wgpu::RenderPassDepthStencilAttachmentDescriptor defaultDescriptor() { return { {}, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 1.0f, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 0 }; }
+	template <> wgpu::RenderPassDepthStencilAttachmentDescriptor defaultDescriptor() { return { {}, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 1.0f, false, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 0, false }; }
 
 	RenderPassDescriptor::RenderPassDescriptor()
 	{
@@ -341,7 +359,7 @@ namespace bgfx { namespace webgpu
 		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGBA4
 		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB5A1
 		{ wgpu::TextureFormat::RGB10A2Unorm,        wgpu::TextureFormat::Undefined        },  // RGB10A2
-		{ wgpu::TextureFormat::RG11B10Float,        wgpu::TextureFormat::Undefined        },  // RG11B10F
+		{ wgpu::TextureFormat::RG11B10Ufloat,       wgpu::TextureFormat::Undefined        },  // RG11B10F
 		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // UnknownDepth
 		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D16
 		{ wgpu::TextureFormat::Depth24Plus,         wgpu::TextureFormat::Undefined        },  // D24
@@ -442,13 +460,13 @@ namespace bgfx { namespace webgpu
 			// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on
 			// their respective platforms, and Vulkan is preferred to OpenGL
 #	if defined(DAWN_ENABLE_BACKEND_D3D12)
-			static dawn_native::BackendType backendType = dawn_native::BackendType::D3D12;
+			static wgpu::BackendType backendType = wgpu::BackendType::D3D12;
 #	elif defined(DAWN_ENABLE_BACKEND_METAL)
-			static dawn_native::BackendType backendType = dawn_native::BackendType::Metal;
+			static wgpu::BackendType backendType = wgpu::BackendType::Metal;
 #	elif defined(DAWN_ENABLE_BACKEND_OPENGL)
-			static dawn_native::BackendType backendType = dawn_native::BackendType::OpenGL;
+			static wgpu::BackendType backendType = wgpu::BackendType::OpenGL;
 #	elif defined(DAWN_ENABLE_BACKEND_VULKAN)
-			static dawn_native::BackendType backendType = dawn_native::BackendType::Vulkan;
+			static wgpu::BackendType backendType = wgpu::BackendType::Vulkan;
 #	else
 #		error "Unknown platform."
 #	endif // defined(DAWN_ENABLE_BACKEND_*)
@@ -464,7 +482,9 @@ namespace bgfx { namespace webgpu
 			std::vector<dawn_native::Adapter> adapters = m_instance.GetAdapters();
 			for (dawn_native::Adapter& adapter : adapters)
 			{
-				if (adapter.GetBackendType() == backendType)
+				wgpu::AdapterProperties properties;
+				adapter.GetProperties(&properties);
+				if (properties.backendType == backendType)
 				{
 					backendAdapter = adapter;
 					break;
@@ -473,7 +493,13 @@ namespace bgfx { namespace webgpu
 
 			//BX_ASSERT(adapterIt != adapters.end());
 
-			WGPUDevice backendDevice = backendAdapter.CreateDevice();
+			dawn_native::DeviceDescriptor desc;
+#	if defined(DAWN_ENABLE_BACKEND_D3D12)
+			desc.forceEnabledToggles.push_back("use_dxc");
+#	endif
+
+
+			WGPUDevice backendDevice = backendAdapter.CreateDevice(&desc);
 			DawnProcTable backendProcs = dawn_native::GetProcs();
 
 			using CreateSwapChain = DawnSwapChainImplementation (*)(wgpu::Device device, void* nwh);
@@ -515,14 +541,14 @@ namespace bgfx { namespace webgpu
 				s_ignoreError = false;
 			};
 
-			m_device.SetUncapturedErrorCallback(PrintDeviceError, NULL);
-
 			if (!m_device)
 			{
 				BX_WARN(!m_device, "Unable to create WebGPU device.");
 				return false;
 			}
 
+			m_device.SetUncapturedErrorCallback(PrintDeviceError, NULL);
+
 			bool success = m_mainFrameBuffer.create(
 				  0
 				, g_platformData.nwh
@@ -835,12 +861,13 @@ namespace bgfx { namespace webgpu
 			const uint32_t pitch = srcWidth * bpp / 8;
 
 			const uint32_t dstpitch = bx::strideAlign(pitch, kMinBufferOffsetAlignment);
+			const uint32_t size = dstpitch * srcHeight;
 
 			// TODO move inside ReadbackWgpu::create
 			if (!readback.m_buffer)
 			{
 				wgpu::BufferDescriptor desc;
-				desc.size = dstpitch * srcHeight;
+				desc.size = size;
 				desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
 
 				readback.m_buffer = m_device.CreateBuffer(&desc);
@@ -852,16 +879,18 @@ namespace bgfx { namespace webgpu
 
 			wgpu::BufferCopyView bufferCopyView;
 			bufferCopyView.buffer = readback.m_buffer;
-			bufferCopyView.bytesPerRow = dstpitch;
-			bufferCopyView.rowsPerImage = srcHeight;
+			bufferCopyView.layout.bytesPerRow = dstpitch;
+			bufferCopyView.layout.rowsPerImage = srcHeight;
 
 			wgpu::Extent3D extent3D = { srcWidth, srcHeight, 1 };
 			getBlitCommandEncoder().CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &extent3D);
 
-			auto finish = [](WGPUBufferMapAsyncStatus status, void const* data, uint64_t dataLength, void* userdata)
+			auto finish = [](WGPUBufferMapAsyncStatus status, void* userdata)
 			{
+				ReadbackWgpu* readback = static_cast<ReadbackWgpu*>(userdata);
+				void const* data = readback->m_buffer.GetConstMappedRange();
 				if(status == WGPUBufferMapAsyncStatus_Success)
-					static_cast<ReadbackWgpu*>(userdata)->readback(data, dataLength);
+					readback->readback(data);
 			};
 
 			m_cmd.finish();
@@ -872,7 +901,7 @@ namespace bgfx { namespace webgpu
 			readback.m_data = _data;
 			readback.m_size = pitch * srcHeight;
 
-			readback.m_buffer.MapReadAsync(finish, &readback);
+			readback.m_buffer.MapAsync(wgpu::MapMode::Read, 0, size, finish, &readback);
 		}
 
 		void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override
@@ -1176,7 +1205,8 @@ namespace bgfx { namespace webgpu
 				VertexBufferWgpu& vb = m_vertexBuffers[_blitter.m_vb->handle.idx];
 				rce.SetVertexBuffer(0, vb.m_ptr);
 
-				rce.SetIndexBuffer(m_indexBuffers[_blitter.m_ib->handle.idx].m_ptr);
+				IndexBufferWgpu& ib = m_indexBuffers[_blitter.m_ib->handle.idx];
+				rce.SetIndexBuffer(ib.m_ptr, ib.m_format);
 				rce.DrawIndexed(_numIndices, 1, 0, 0, 0);
 			}
 		}
@@ -1356,7 +1386,7 @@ namespace bgfx { namespace webgpu
 							uint32_t flags = bind.m_samplerFlags;
 
 							wgpu::TextureViewDescriptor viewDesc = defaultDescriptor<wgpu::TextureViewDescriptor>();
-							viewDesc.dimension = program.m_textures[bindInfo.m_index].viewDimension;
+							viewDesc.dimension = program.m_textures[bindInfo.m_index].texture.viewDimension;
 
 							wgpu::BindGroupEntry& textureEntry = b.m_entries[b.numEntries++];
 							textureEntry.binding = bindInfo.m_binding;
@@ -1376,8 +1406,8 @@ namespace bgfx { namespace webgpu
 					case Binding::VertexBuffer:
 					{
 						const BufferWgpu& buffer = Binding::IndexBuffer == bind.m_type
-							? m_indexBuffers[bind.m_idx]
-							: m_vertexBuffers[bind.m_idx]
+							? (const BufferWgpu&) m_indexBuffers[bind.m_idx]
+							: (const BufferWgpu&) m_vertexBuffers[bind.m_idx]
 							;
 
 						wgpu::BindGroupEntry& entry = b.m_entries[b.numEntries++];
@@ -1418,20 +1448,6 @@ namespace bgfx { namespace webgpu
 			setShaderUniform(_flags, _loc, _val, _numRegs);
 		}
 
-		void commitShaderConstants(ScratchBufferWgpu& _scratchBuffer, const ProgramWgpu& _program, uint32_t _vertexOffset, uint32_t _fragmentOffset)
-		{
-			const uint32_t size = _program.m_vsh->m_gpuSize;
-			if (0 != size)
-				_scratchBuffer.write(m_vsScratch, size);
-
-			if(NULL != _program.m_fsh)
-			{
-				const uint32_t size = _program.m_fsh->m_gpuSize;
-				if(0 != size)
-					_scratchBuffer.write(m_fsScratch, size);
-			}
-		}
-
 		void commit(UniformBuffer& _uniformBuffer)
 		{
 			_uniformBuffer.reset();
@@ -2103,7 +2119,12 @@ namespace bgfx { namespace webgpu
 					input.vertexBuffers[stream].attributes = &input.attributes[firstAttrib];
 				}
 
-				input.desc.indexFormat = _isIndex16 ? wgpu::IndexFormat::Uint16 : wgpu::IndexFormat::Uint32;
+				bool isStrip = prim.m_type == wgpu::PrimitiveTopology::LineStrip
+				 			|| prim.m_type == wgpu::PrimitiveTopology::TriangleStrip;
+				if (isStrip)
+					input.desc.indexFormat = _isIndex16 ? wgpu::IndexFormat::Uint16 : wgpu::IndexFormat::Uint32;
+				else
+					input.desc.indexFormat = wgpu::IndexFormat::Undefined;
 
 				pd.desc.vertexState = &input.desc;
 
@@ -2530,21 +2551,21 @@ namespace bgfx { namespace webgpu
 					m_bindInfo[stage].m_binding = regIndex;
 					m_bindInfo[stage].m_uniform = { 0 };
 
-					m_buffers[m_numBuffers] = wgpu::BindGroupLayoutBinding();
+					m_buffers[m_numBuffers] = wgpu::BindGroupLayoutEntry();
 					m_buffers[m_numBuffers].binding = regIndex;
 					m_buffers[m_numBuffers].visibility = shaderStage;
 
 					if (buffer)
 					{
-						m_buffers[m_numBuffers].type = readonly
-							? wgpu::BindingType::ReadonlyStorageBuffer
-							: wgpu::BindingType::StorageBuffer;
+						m_buffers[m_numBuffers].buffer.type = readonly
+							? wgpu::BufferBindingType::ReadOnlyStorage
+							: wgpu::BufferBindingType::Storage;
 					}
 					else
 					{
-						m_buffers[m_numBuffers].type = readonly
-							? wgpu::BindingType::ReadonlyStorageTexture
-							: wgpu::BindingType::WriteonlyStorageTexture;
+						m_buffers[m_numBuffers].storageTexture.access = readonly
+							? wgpu::StorageTextureAccess::ReadOnly
+							: wgpu::StorageTextureAccess::WriteOnly;
 					}
 
 					m_numBuffers++;
@@ -2562,21 +2583,37 @@ namespace bgfx { namespace webgpu
 					m_bindInfo[stage].m_binding = regIndex;
 					m_bindInfo[stage].m_uniform = info->m_handle;
 
-					m_textures[m_numSamplers] = wgpu::BindGroupLayoutBinding();
+					auto textureComponentToSampleType = [](wgpu::TextureComponentType componentType)
+					{
+						switch (componentType)
+						{
+						case wgpu::TextureComponentType::Float:
+							return wgpu::TextureSampleType::Float;
+						case wgpu::TextureComponentType::Sint:
+							return wgpu::TextureSampleType::Sint;
+						case wgpu::TextureComponentType::Uint:
+							return wgpu::TextureSampleType::Uint;
+						case wgpu::TextureComponentType::DepthComparison:
+							return wgpu::TextureSampleType::UnfilterableFloat;
+						default:
+							return wgpu::TextureSampleType::Float;
+						}
+					};
+
+					m_textures[m_numSamplers] = wgpu::BindGroupLayoutEntry();
 					m_textures[m_numSamplers].binding = regIndex;
 					m_textures[m_numSamplers].visibility = shaderStage;
-					m_textures[m_numSamplers].type = wgpu::BindingType::SampledTexture;
-					m_textures[m_numSamplers].viewDimension = wgpu::TextureViewDimension(texDimension);
-					m_textures[m_numSamplers].textureComponentType = wgpu::TextureComponentType(texComponent);
+					m_textures[m_numSamplers].texture.viewDimension = wgpu::TextureViewDimension(texDimension);
+					m_textures[m_numSamplers].texture.sampleType = textureComponentToSampleType(wgpu::TextureComponentType(texComponent));
 
 					const bool comparisonSampler = (type & kUniformCompareBit) != 0;
 
-					m_samplers[m_numSamplers] = wgpu::BindGroupLayoutBinding();
+					m_samplers[m_numSamplers] = wgpu::BindGroupLayoutEntry();
 					m_samplers[m_numSamplers].binding = regIndex + 16;
 					m_samplers[m_numSamplers].visibility = shaderStage;
-					m_samplers[m_numSamplers].type = comparisonSampler
-						? wgpu::BindingType::ComparisonSampler
-						: wgpu::BindingType::Sampler;
+					m_samplers[m_numSamplers].sampler.type = comparisonSampler
+						? wgpu::SamplerBindingType::Comparison
+						: wgpu::SamplerBindingType::Filtering;
 
 					m_numSamplers++;
 
@@ -2596,12 +2633,14 @@ namespace bgfx { namespace webgpu
 					m_constantBuffer->writeUniformHandle((UniformType::Enum)(type | fragmentBit), regIndex, info->m_handle, regCount);
 				}
 
-				BX_TRACE("\t%s: %s (%s), r.index %3d, r.count %2d"
+				BX_TRACE("\t%s: %s (%s), r.index %3d, r.count %2d, r.texComponent %1d, r.texDimension %1d"
 					, kind
 					, name
 					, getUniformTypeName(UniformType::Enum(type&~kUniformMask) )
 					, regIndex
 					, regCount
+					, texComponent
+					, texDimension
 					);
 				BX_UNUSED(kind);
 			}
@@ -2707,7 +2746,7 @@ namespace bgfx { namespace webgpu
 		bx::read(&reader, m_size);
 
 		const uint32_t align = kMinBufferOffsetAlignment;
-		m_gpuSize = bx::strideAlign(m_size, align);
+		m_gpuSize = (uint16_t) bx::strideAlign(m_size, align);
 
 		BX_TRACE("shader size %d (used=%d) (prev=%d)", (int)m_size, (int)m_gpuSize, (int)bx::strideAlign(roundUp(m_size, 4), align));
 	}
@@ -2741,16 +2780,16 @@ namespace bgfx { namespace webgpu
 		// bind uniform buffer at slot 0
 		bindings[numBindings].binding = 0;
 		bindings[numBindings].visibility = _vsh->m_stage;
-		bindings[numBindings].type = wgpu::BindingType::UniformBuffer;
-		bindings[numBindings].hasDynamicOffset = true;
+		bindings[numBindings].buffer.type = wgpu::BufferBindingType::Uniform;
+		bindings[numBindings].buffer.hasDynamicOffset = true;
 		numBindings++;
 
 		if (m_numUniforms > 1)
 		{
 			bindings[numBindings].binding = 48;
 			bindings[numBindings].visibility = wgpu::ShaderStage::Fragment;
-			bindings[numBindings].type = wgpu::BindingType::UniformBuffer;
-			bindings[numBindings].hasDynamicOffset = true;
+			bindings[numBindings].buffer.type = wgpu::BufferBindingType::Uniform;
+			bindings[numBindings].buffer.hasDynamicOffset = true;
 			numBindings++;
 		}
 
@@ -2848,17 +2887,14 @@ namespace bgfx { namespace webgpu
 		desc.usage |= (storage || indirect) ? wgpu::BufferUsage::Storage : wgpu::BufferUsage::None;
 		desc.usage |= indirect ? wgpu::BufferUsage::Indirect : wgpu::BufferUsage::None;
 		desc.usage |= NULL == _data ? wgpu::BufferUsage::CopyDst : wgpu::BufferUsage::None;
+		desc.mappedAtCreation = NULL != _data;
+
+		m_ptr = s_renderWgpu->m_device.CreateBuffer(&desc);
 
 		if(NULL != _data)
 		{
-			wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&desc);
-			m_ptr = mapped.buffer;
-			bx::memCopy(mapped.data, _data, _size);
-			mapped.buffer.Unmap();
-		}
-		else
-		{
-			m_ptr = s_renderWgpu->m_device.CreateBuffer(&desc);
+			bx::memCopy(m_ptr.GetMappedRange(), _data, _size);
+			m_ptr.Unmap();
 		}
 	}
 
@@ -2880,11 +2916,11 @@ namespace bgfx { namespace webgpu
 			wgpu::BufferDescriptor desc;
 			desc.size = end - start;
 			desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
+			desc.mappedAtCreation = true;
 
-			wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&desc);
-			wgpu::Buffer staging = mapped.buffer;
-			bx::memCopy(mapped.data, m_dynamic, end - start);
-			mapped.buffer.Unmap();
+			wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc);
+			bx::memCopy(staging.GetMappedRange(), m_dynamic, end - start);
+			staging.Unmap();
 
 			// TODO pad to 4 bytes
 			bce.CopyBufferToBuffer(staging, 0, m_ptr, start, end - start);
@@ -2895,17 +2931,26 @@ namespace bgfx { namespace webgpu
 			wgpu::BufferDescriptor desc;
 			desc.size = _size;
 			desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
+			desc.mappedAtCreation = true;
 
-			wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&desc);
-			wgpu::Buffer staging = mapped.buffer;
-			bx::memCopy(mapped.data, _data, _size);
-			mapped.buffer.Unmap();
+			wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc);
+			bx::memCopy(staging.GetMappedRange(), _data, _size);
+			staging.Unmap();
 
 			bce.CopyBufferToBuffer(staging, 0, m_ptr, _offset, _size);
 			s_renderWgpu->m_cmd.release(staging);
 		}
 	}
 
+	void IndexBufferWgpu::create(uint32_t _size, void* _data, uint16_t _flags)
+	{
+		m_format = (_flags & BGFX_BUFFER_INDEX32) != 0
+			? wgpu::IndexFormat::Uint32
+			: wgpu::IndexFormat::Uint16;
+
+		BufferWgpu::create(_size, _data, _flags);
+	}
+
 	void VertexBufferWgpu::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags)
 	{
 		m_layoutHandle = _layoutHandle;
@@ -3041,10 +3086,9 @@ namespace bgfx { namespace webgpu
 			desc.format = format;
 			desc.size.width  = m_width;
 			desc.size.height = m_height;
-			desc.size.depth  = bx::uint32_max(1,imageContainer.m_depth);
+			desc.size.depth  = m_numSides * bx::uint32_max(1,imageContainer.m_depth);
 			desc.mipLevelCount    = m_numMips;
 			desc.sampleCount      = 1;
-			desc.arrayLayerCount  = m_numSides;
 
 			desc.usage = wgpu::TextureUsage::Sampled;
 			desc.usage |= wgpu::TextureUsage::CopyDst;
@@ -3193,9 +3237,10 @@ namespace bgfx { namespace webgpu
 				wgpu::BufferDescriptor staginBufferDesc;
 				staginBufferDesc.size = totalMemSize;
 				staginBufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
+				staginBufferDesc.mappedAtCreation = true;
 
-				wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&staginBufferDesc);
-				stagingBuffer = mapped.buffer;
+				stagingBuffer = s_renderWgpu->m_device.CreateBuffer(&staginBufferDesc);
+				void* stagingData = stagingBuffer.GetMappedRange();
 
 				uint64_t offset = 0;
 
@@ -3204,7 +3249,7 @@ namespace bgfx { namespace webgpu
 					const uint32_t dstpitch = bx::strideAlign(imageInfos[ii].pitch, kMinBufferOffsetAlignment);
 
 					const uint8_t* src = (uint8_t*)imageInfos[ii].data;
-					uint8_t* dst = (uint8_t*)mapped.data;
+					uint8_t* dst = (uint8_t*)stagingData;
 
 					for (uint32_t yy = 0; yy < imageInfos[ii].height; ++yy, src += imageInfos[ii].pitch, offset += dstpitch)
 					{
@@ -3215,7 +3260,7 @@ namespace bgfx { namespace webgpu
 					//offset += imageInfos[ii].size;
 				}
 
-				mapped.buffer.Unmap();
+				stagingBuffer.Unmap();
 			}
 
 			wgpu::BufferCopyView* bufferCopyView = (wgpu::BufferCopyView*)BX_ALLOC(g_allocator, sizeof(wgpu::BufferCopyView) * numSrd);
@@ -3233,16 +3278,13 @@ namespace bgfx { namespace webgpu
 				BX_PLACEMENT_NEW(&bufferCopyView[ii], wgpu::BufferCopyView)();
 				BX_PLACEMENT_NEW(&textureCopyView[ii], wgpu::TextureCopyView)();
 				BX_PLACEMENT_NEW(&textureCopySize[ii], wgpu::Extent3D)();
-				bufferCopyView[ii].buffer      = stagingBuffer;
-				bufferCopyView[ii].offset      = offset;
-				bufferCopyView[ii].bytesPerRow = dstpitch; // assume that image data are tightly aligned
-				bufferCopyView[ii].rowsPerImage = 0; // assume that image data are tightly aligned
-				textureCopyView[ii].texture        = m_ptr;
-				//textureCopyView[ii].imageSubresource.aspectMask     = m_vkTextureAspect;
+				bufferCopyView[ii].buffer              = stagingBuffer;
+				bufferCopyView[ii].layout.offset       = offset;
+				bufferCopyView[ii].layout.bytesPerRow  = dstpitch; // assume that image data are tightly aligned
+				bufferCopyView[ii].layout.rowsPerImage = 0; // assume that image data are tightly aligned
+				textureCopyView[ii].texture            = m_ptr;
 				textureCopyView[ii].mipLevel       = imageInfos[ii].mipLevel;
-				textureCopyView[ii].arrayLayer     = imageInfos[ii].layer;
-				//textureCopyView[ii].layerCount     = 1;
-				textureCopyView[ii].origin = { 0, 0, 0 };
+				textureCopyView[ii].origin         = { 0, 0, imageInfos[ii].layer };
 				textureCopySize[ii] = { idealWidth, idealHeight, imageInfos[ii].depth };
 
 				offset += dstpitch * imageInfos[ii].height;
@@ -3288,13 +3330,11 @@ namespace bgfx { namespace webgpu
 
 	void TextureWgpu::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
 	{
-		BX_UNUSED(_side); BX_UNUSED(_mip); BX_UNUSED(_depth); BX_UNUSED(_z);
-
 		const uint32_t bpp       = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) );
 		const uint32_t rectpitch = _rect.m_width*bpp/8;
 		const uint32_t srcpitch  = UINT16_MAX == _pitch ? rectpitch : _pitch;
-		const uint32_t slice     = ( (m_type == Texture3D) ? 0 : _side + _z * (m_type == TextureCube ? 6 : 1) );
-		const uint16_t zz        = (m_type == Texture3D) ? _z : 0 ;
+		const uint16_t zz        = (m_type == Texture3D) ? _z : _side;
+		// TODO (hugoam) This won't work for 3D texture arrays, but do we even support that
 
 		const bool convert = m_textureFormat != m_requestedFormat;
 
@@ -3321,12 +3361,12 @@ namespace bgfx { namespace webgpu
 		wgpu::BufferDescriptor desc;
 		desc.size = dstpitch * _rect.m_height;
 		desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
+		desc.mappedAtCreation = true;
 
-		wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&desc);
-		wgpu::Buffer staging = mapped.buffer;
+		wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc);
 
 		const uint8_t* src = (uint8_t*)data;
-		uint8_t* dst = (uint8_t*)mapped.data;
+		uint8_t* dst = (uint8_t*)staging.GetMappedRange();
 		uint64_t offset = 0;
 
 		for (uint32_t yy = 0; yy < _rect.m_height; ++yy, src += srcpitch, offset += dstpitch)
@@ -3335,21 +3375,17 @@ namespace bgfx { namespace webgpu
 			bx::memCopy(dst + offset, src, size);
 		}
 
-		mapped.buffer.Unmap();
+		staging.Unmap();
 
 		wgpu::BufferCopyView srcView;
 		srcView.buffer = staging;
-		srcView.offset = 0;
-		srcView.bytesPerRow = dstpitch;
-		srcView.rowsPerImage = 0;
+		srcView.layout.bytesPerRow = dstpitch;
+		srcView.layout.rowsPerImage = 0;
 
 		wgpu::TextureCopyView destView;
 		destView.texture = m_ptr;
 		destView.mipLevel = _mip;
-		destView.arrayLayer = _side;
 		destView.origin = { _rect.m_x, _rect.m_y, zz };
-		//destView.origin = { _rect.m_x, _rect.m_y, _z };
-
 
 		wgpu::Extent3D destExtent = { _rect.m_width, _rect.m_height, _depth };
 
@@ -3378,39 +3414,41 @@ namespace bgfx { namespace webgpu
 
 	void StagingBufferWgpu::create(uint32_t _size, bool mapped)
 	{
+		m_size = _size;
+
 		wgpu::BufferDescriptor desc;
-		desc.size = BGFX_CONFIG_MAX_DRAW_CALLS * 128;
+		desc.size = _size;
 		desc.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
+		desc.mappedAtCreation = mapped;
+
+		m_buffer = s_renderWgpu->m_device.CreateBuffer(&desc);
 
 		if (mapped)
 		{
-			wgpu::CreateBufferMappedResult mapped = s_renderWgpu->m_device.CreateBufferMapped(&desc);
-			m_buffer = mapped.buffer;
-			m_data = mapped.data;
-			m_size = mapped.dataLength;
+			m_data = m_buffer.GetMappedRange();
 		}
 		else
 		{
-			m_buffer = s_renderWgpu->m_device.CreateBuffer(&desc);
 			map();
 		}
 	}
 
 	void StagingBufferWgpu::map()
 	{
-		auto ready = [](WGPUBufferMapAsyncStatus status, void* data, uint64_t dataLength, void* userdata)
+		auto ready = [](WGPUBufferMapAsyncStatus status, void* userdata)
 		{
+			StagingBufferWgpu* staging = static_cast<StagingBufferWgpu*>(userdata);
+			void* data = staging->m_buffer.GetMappedRange();
 			if (status == WGPUBufferMapAsyncStatus_Success)
-				static_cast<StagingBufferWgpu*>(userdata)->mapped(data, dataLength);
+				staging->mapped(data);
 		};
 
-		m_buffer.MapWriteAsync(ready, this);
+		m_buffer.MapAsync(wgpu::MapMode::Write, 0, m_size, ready, this);
 	}
 
 	void StagingBufferWgpu::unmap()
 	{
 		m_data = NULL;
-		m_size = 0;
 		m_buffer.Unmap();
 	}
 
@@ -3419,10 +3457,9 @@ namespace bgfx { namespace webgpu
 		m_buffer = NULL;
 	}
 
-	void StagingBufferWgpu::mapped(void* _data, uint64_t _size)
+	void StagingBufferWgpu::mapped(void* _data)
 	{
 		m_data = _data;
-		m_size = _size;
 	}
 
 	void ScratchBufferWgpu::create(uint32_t _size)
@@ -3566,8 +3603,8 @@ namespace bgfx { namespace webgpu
 		desc.implementation = reinterpret_cast<uint64_t>(&m_impl);
 		m_swapChain = _device.CreateSwapChain(nullptr, &desc);
 #else
-		wgpu::SurfaceDescriptorFromHTMLCanvasId canvasDesc{};
-		canvasDesc.id = "canvas";
+		wgpu::SurfaceDescriptorFromCanvasHTMLSelector canvasDesc{};
+		canvasDesc.selector = "#canvas";
 
 		wgpu::SurfaceDescriptor surfDesc{};
 		surfDesc.nextInChain = &canvasDesc;
@@ -3622,7 +3659,6 @@ namespace bgfx { namespace webgpu
 		desc.size.depth  = 1;
 		desc.mipLevelCount = 1;
 		desc.sampleCount = sampleCount;
-		desc.arrayLayerCount = 1;
 		desc.usage = wgpu::TextureUsage::OutputAttachment;
 
 		if (m_backBufferDepth)
@@ -3953,15 +3989,13 @@ namespace bgfx { namespace webgpu
 
 			wgpu::TextureCopyView srcView;
 			srcView.texture = src.m_ptr;
-			srcView.origin = { blit.m_srcX, blit.m_srcY, 0 };
+			srcView.origin = { blit.m_srcX, blit.m_srcY, blit.m_srcZ };
 			srcView.mipLevel = blit.m_srcMip;
-			srcView.arrayLayer = blit.m_srcZ;
 
 			wgpu::TextureCopyView dstView;
 			dstView.texture = dst.m_ptr;
-			dstView.origin = { blit.m_dstX, blit.m_dstY, 0 };
+			dstView.origin = { blit.m_dstX, blit.m_dstY, blit.m_dstZ };
 			dstView.mipLevel = blit.m_dstMip;
-			dstView.arrayLayer = blit.m_dstZ;
 
 			if (blit.m_depth == 0)
 			{
@@ -4552,7 +4586,6 @@ namespace bgfx { namespace webgpu
 					||  hasPredefined)
 					{
 						//viewState.setPredefined<4>(this, view, program, _render, draw, programChanged || viewChanged);
-						//commitShaderConstants(scratchBuffer, program, voffset, foffset);
 
 						const uint32_t vsize = program.m_vsh->m_gpuSize;
 						const uint32_t fsize = (NULL != program.m_fsh ? program.m_fsh->m_gpuSize : 0);
@@ -4615,7 +4648,7 @@ namespace bgfx { namespace webgpu
 
 							for (uint32_t ii = 0; ii < numDrawIndirect; ++ii)
 							{
-								rce.SetIndexBuffer(ib.m_ptr, 0);
+								rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0);
 								rce.DrawIndexedIndirect(vb.m_ptr, (draw.m_startIndirect + ii)* BGFX_CONFIG_DRAW_INDIRECT_STRIDE);
 							}
 						}
@@ -4645,7 +4678,7 @@ namespace bgfx { namespace webgpu
 								numInstances      = draw.m_numInstances;
 								numPrimsRendered  = numPrimsSubmitted*draw.m_numInstances;
 
-								rce.SetIndexBuffer(ib.m_ptr, 0);
+								rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0);
 								rce.DrawIndexed(numIndices, draw.m_numInstances, 0, 0, 0);
 							}
 							else if (prim.m_min <= draw.m_numIndices)
@@ -4655,7 +4688,7 @@ namespace bgfx { namespace webgpu
 								numInstances      = draw.m_numInstances;
 								numPrimsRendered  = numPrimsSubmitted*draw.m_numInstances;
 
-								rce.SetIndexBuffer(ib.m_ptr, 0);
+								rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0);
 								rce.DrawIndexed(numIndices, numInstances, draw.m_startIndex, 0, 0);
 							}
 						}

+ 9 - 4
src/renderer_webgpu.h

@@ -113,7 +113,12 @@ namespace bgfx { namespace webgpu
 		uint8_t*     m_dynamic = NULL;
 	};
 
-	typedef BufferWgpu IndexBufferWgpu;
+	struct IndexBufferWgpu : public BufferWgpu
+	{
+		void create(uint32_t _size, void* _data, uint16_t _flags);
+
+		wgpu::IndexFormat m_format;
+	};
 
 	struct VertexBufferWgpu : public BufferWgpu
 	{
@@ -293,7 +298,7 @@ namespace bgfx { namespace webgpu
 		void unmap();
 		void destroy();
 
-		void mapped(void* _data, uint64_t _size);
+		void mapped(void* _data);
 
 		wgpu::Buffer m_buffer;
 		void* m_data = NULL;
@@ -339,9 +344,9 @@ namespace bgfx { namespace webgpu
 			m_buffer.Destroy();
 		}
 
-		void readback(void const* data, uint64_t size)
+		void readback(void const* data)
 		{
-			bx::memCopy(m_data, data, m_size < size ? m_size : size);
+			bx::memCopy(m_data, data, m_size);
 			m_buffer.Unmap();
 			m_mapped = false;
 		}

Some files were not shown because too many files changed in this diff