diff --git a/AUTHORS b/AUTHORS index 73df633b3dd9..3583acc116e2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -448,3 +448,5 @@ a license to everyone to use it as detailed in LICENSE.) * Niklas Fiekas * Martín Lucas Golini * Bumsik Kim +* Corentin Wallez (copyright owned by Google, Inc.) +* Austin Eng (copyright owned by Google, Inc.) diff --git a/src/library_html5.js b/src/library_html5.js index bc7803a765fb..dfe96d7378c5 100644 --- a/src/library_html5.js +++ b/src/library_html5.js @@ -2759,6 +2759,16 @@ var LibraryJSEvents = { return !GL.contexts[target] || GL.contexts[target].GLctx.isContextLost(); // No context ~> lost context. }, +#if USE_WEBGPU + // TODO(kainino0x): make it possible to actually create devices through webgpu.h + emscripten_webgpu_get_device__deps: ['$WebGPU'], + emscripten_webgpu_get_device__postset: 'WebGPU.initManagers();', + emscripten_webgpu_get_device: function() { + assert(Module['preinitializedWebGPUDevice']); + return WebGPU["mgrDevice"].create(Module['preinitializedWebGPUDevice']); + }, +#endif + #if USE_PTHREADS emscripten_set_canvas_element_size_calling_thread__deps: ['$JSEvents', 'emscripten_set_offscreencanvas_size_on_target_thread', '_findCanvasEventTarget'], emscripten_set_canvas_element_size_calling_thread: function(target, width, height) { diff --git a/src/library_webgpu.js b/src/library_webgpu.js new file mode 100644 index 000000000000..91e024a98d70 --- /dev/null +++ b/src/library_webgpu.js @@ -0,0 +1,1451 @@ +/* + * Copyright 2019 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + * + * WebGPU support. + * + * This file implements the common C header on top of the + * browser's native JS WebGPU implementation. This allows applications targeting + * wgpu-native (https://github.com/gfx-rs/wgpu) or + * Dawn (https://dawn.googlesource.com/dawn/) to also target the Web with the + * same graphics API and fairly minimal changes - similar to OpenGL ES 2.0/3.0 + * on WebGL 1.0/2.0. + */ + +{{{ (function() { + // Helper functions for code generation + global.gpu = { + makeInitManager: function(type) { + var mgr = 'this.mgr' + type + return mgr + ' = ' + mgr + ' || makeManager();'; + }, + + makeReferenceRelease: function(type) { + var s = ''; + s += 'wgpu' + type + 'Reference: function(id) {\n'; + s += ' WebGPU.mgr' + type + '.reference(id);\n' + s += '},\n'; + s += 'wgpu' + type + 'Release: function(id) {\n'; + s += ' WebGPU.mgr' + type + '.release(id);\n' + s += '},'; + return s; + }, + + makeU64ToNumber: function(lowName, highName) { + var ret = '(' + if (ASSERTIONS) { + ret += 'assert(' + highName + ' < 0x200000), '; + } + ret += highName + ' * 0x100000000 + ' + lowName + ')\n' + return ret; + }, + + makeGetBool: function(struct, offset) { + // In an actual build, bool seems to be i8. But on the off-chance it's i32, on little-endian + // this will still work as long as the value of 'true' isn't zero in the lowest byte. + return '(' + makeGetValue(struct, offset, 'i8') + ' !== 0)'; + }, + makeGetU32: function(struct, offset) { + return makeGetValue(struct, offset, 'i32', false, true); + }, + makeGetU64: function(struct, offset) { + var l = makeGetValue(struct, offset, 'i32', false, true); + var h = makeGetValue('(' + struct + ' + 4)', offset, 'i32', false, true) + return h + ' * 0x100000000 + ' + l + }, + makeCheck: function(str) { + if (!ASSERTIONS) return ''; + return 'assert(' + str + ');'; + }, + makeCheckDefined: function(name) { + return this.makeCheck('typeof ' + name + ' !== "undefined"'); + }, + makeCheckDescriptor: function(descriptor) { + // Assert descriptor is non-null, then that its nextInChain is null. + var OffsetOfNextInChainMember = 0; + return this.makeCheck(descriptor) + this.makeCheck(makeGetValue(descriptor, OffsetOfNextInChainMember, '*') + ' === 0'); + }, + + // Must be in sync with webgpu.h. + PresentMode: { + VSync: 1, + }, + SType: { + SurfaceDescriptorFromHTMLCanvasId: 4, + }, + }; + return null; +})(); }}} + +var LibraryWebGPU = { + $WebGPU: { + initManagers: function() { + if (this["mgrDevice"]) return; + + function makeManager() { + return { + objects: [undefined], + create: function(object, wrapper /* = {} */) { + wrapper = wrapper || {}; + + var id = this.objects.length; + {{{ gpu.makeCheck("typeof this.objects[id] === 'undefined'") }}} + wrapper.refcount = 1; + wrapper.object = object; + this.objects[id] = wrapper; + return id; + }, + get: function(id) { + if (id === 0) return undefined; + var o = this.objects[id]; + {{{ gpu.makeCheckDefined('o') }}} + return o.object; + }, + reference: function(id) { + var o = this.objects[id]; + {{{ gpu.makeCheckDefined('o') }}} + o.refcount++; + }, + release: function(id) { + var o = this.objects[id]; + {{{ gpu.makeCheckDefined('o') }}} + {{{ gpu.makeCheck('o.refcount > 0') }}} + o.refcount--; + if (o.refcount <= 0) { + delete this.objects[id]; + } + }, + }; + } + + {{{ gpu.makeInitManager('Surface') }}} + {{{ gpu.makeInitManager('SwapChain') }}} + + this["mgrDevice"] = this["mgrDevice"] || makeManager(); + {{{ gpu.makeInitManager('Queue') }}} + {{{ gpu.makeInitManager('Fence') }}} + + {{{ gpu.makeInitManager('CommandBuffer') }}} + {{{ gpu.makeInitManager('CommandEncoder') }}} + {{{ gpu.makeInitManager('RenderPassEncoder') }}} + + {{{ gpu.makeInitManager('BindGroup') }}} + {{{ gpu.makeInitManager('Buffer') }}} + {{{ gpu.makeInitManager('Sampler') }}} + {{{ gpu.makeInitManager('Texture') }}} + {{{ gpu.makeInitManager('TextureView') }}} + + {{{ gpu.makeInitManager('BindGroupLayout') }}} + {{{ gpu.makeInitManager('PipelineLayout') }}} + {{{ gpu.makeInitManager('RenderPipeline') }}} + {{{ gpu.makeInitManager('ShaderModule') }}} + + {{{ gpu.makeInitManager('RenderBundleEncoder') }}} + {{{ gpu.makeInitManager('RenderBundle') }}} + }, + + trackMapWrite: function(obj, mapped) { + var data = _malloc(mapped.byteLength); + HEAPU8.fill(0, data, mapped.byteLength); + obj.mapWriteSrc = data; + obj.mapWriteDst = mapped; + }, + trackUnmap: function(obj) { + if (obj.mapWriteSrc) { + new Uint8Array(obj.mapWriteDst).set(HEAPU8.subarray(obj.mapWriteSrc, obj.mapWriteSrc + obj.mapWriteDst.byteLength)); + _free(obj.mapWriteSrc); + } + obj.mapWriteSrc = undefined; + obj.mapWriteDst = undefined; + }, + + makeColor: function(ptr) { + return { + "r": {{{ makeGetValue('ptr', 0, 'float') }}}, + "g": {{{ makeGetValue('ptr', 4, 'float') }}}, + "b": {{{ makeGetValue('ptr', 8, 'float') }}}, + "a": {{{ makeGetValue('ptr', 12, 'float') }}}, + }; + }, + + makeExtent3D: function(ptr) { + return { + "width": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUExtent3D.width) }}}, + "height": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUExtent3D.height) }}}, + "depth": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUExtent3D.depth) }}}, + }; + }, + + makeOrigin3D: function(ptr) { + return { + "x": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUOrigin3D.x) }}}, + "y": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUOrigin3D.y) }}}, + "z": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUOrigin3D.z) }}}, + }; + }, + + makeTextureCopyView: function(ptr) { + {{{ gpu.makeCheckDescriptor('ptr') }}} + return { + "texture": this.mgrTexture.get( + {{{ makeGetValue('ptr', C_STRUCTS.WGPUTextureCopyView.texture, '*') }}}), + "mipLevel": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUTextureCopyView.mipLevel, '*') }}}, + "arrayLayer": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUTextureCopyView.arrayLayer, '*') }}}, + "origin": WebGPU.makeOrigin3D(ptr + {{{ C_STRUCTS.WGPUTextureCopyView.origin }}}), + }; + }, + + makeBufferCopyView: function(ptr) { + {{{ gpu.makeCheckDescriptor('ptr') }}} + return { + "buffer": this.mgrBuffer.get( + {{{ makeGetValue('ptr', C_STRUCTS.WGPUBufferCopyView.buffer, '*') }}}), + "offset": {{{ gpu.makeGetU64('ptr', C_STRUCTS.WGPUBufferCopyView.offset) }}}, + "rowPitch": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUBufferCopyView.rowPitch) }}}, + "imageHeight": {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUBufferCopyView.imageHeight) }}}, + }; + }, + + makeProgrammableStageDescriptor: function(ptr) { + if (ptr === 0) return undefined; + {{{ gpu.makeCheckDescriptor('ptr') }}} + return { + "module": WebGPU.mgrShaderModule.get( + {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.module, '*') }}}), + "entryPoint": UTF8ToString( + {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.entryPoint, '*') }}}), + }; + }, + + // This section is auto-generated: + // https://dawn.googlesource.com/dawn/+/refs/heads/master/generator/templates/library_webgpu_enum_tables.json + AddressMode: [ + 'repeat', + 'mirror-repeat', + 'clamp-to-edge', + ], + BindingType: [ + 'uniform-buffer', + 'storage-buffer', + 'readonly-storage-buffer', + 'sampler', + 'sampled-texture', + 'storage-texture', + ], + BlendFactor: [ + 'zero', + 'one', + 'src-color', + 'one-minus-src-color', + 'src-alpha', + 'one-minus-src-alpha', + 'dst-color', + 'one-minus-dst-color', + 'dst-alpha', + 'one-minus-dst-alpha', + 'src-alpha-saturated', + 'blend-color', + 'one-minus-blend-color', + ], + BlendOperation: [ + 'add', + 'subtract', + 'reverse-subtract', + 'min', + 'max', + ], + BufferMapAsyncStatus: [ + 'success', + 'error', + 'unknown', + 'device-lost', + ], + CompareFunction: [ + 'never', + 'less', + 'less-equal', + 'greater', + 'greater-equal', + 'equal', + 'not-equal', + 'always', + ], + CullMode: [ + 'none', + 'front', + 'back', + ], + ErrorFilter: [ + 'none', + 'validation', + 'out-of-memory', + ], + ErrorType: [ + 'no-error', + 'validation', + 'out-of-memory', + 'unknown', + 'device-lost', + ], + FenceCompletionStatus: [ + 'success', + 'error', + 'unknown', + 'device-lost', + ], + FilterMode: [ + 'nearest', + 'linear', + ], + FrontFace: [ + 'ccw', + 'cw', + ], + IndexFormat: [ + 'uint16', + 'uint32', + ], + InputStepMode: [ + 'vertex', + 'instance', + ], + LoadOp: [ + 'clear', + 'load', + ], + PresentMode: [ + 'no-v-sync', + 'v-sync', + ], + PrimitiveTopology: [ + 'point-list', + 'line-list', + 'line-strip', + 'triangle-list', + 'triangle-strip', + ], + StencilOperation: [ + 'keep', + 'zero', + 'replace', + 'invert', + 'increment-clamp', + 'decrement-clamp', + 'increment-wrap', + 'decrement-wrap', + ], + StoreOp: [ + 'store', + 'clear', + ], + TextureAspect: [ + 'all', + 'stencil-only', + 'depth-only', + ], + TextureComponentType: [ + 'float', + 'sint', + 'uint', + ], + TextureDimension: [ + '1d', + '2d', + '3d', + ], + TextureFormat: [ + undefined, + 'r8unorm', + 'r8snorm', + 'r8uint', + 'r8sint', + 'r16uint', + 'r16sint', + 'r16float', + 'rg8unorm', + 'rg8snorm', + 'rg8uint', + 'rg8sint', + 'r32float', + 'r32uint', + 'r32sint', + 'rg16uint', + 'rg16sint', + 'rg16float', + 'rgba8unorm', + 'rgba8unorm-srgb', + 'rgba8snorm', + 'rgba8uint', + 'rgba8sint', + 'bgra8unorm', + 'bgra8unorm-srgb', + 'rgb10a2unorm', + 'rg11b10float', + 'rg32float', + 'rg32uint', + 'rg32sint', + 'rgba16uint', + 'rgba16sint', + 'rgba16float', + 'rgba32float', + 'rgba32uint', + 'rgba32sint', + 'depth32float', + 'depth24plus', + 'depth24plus-stencil8', + 'bc1rgba-unorm', + 'bc1rgba-unorm-srgb', + 'bc2rgba-unorm', + 'bc2rgba-unorm-srgb', + 'bc3rgba-unorm', + 'bc3rgba-unorm-srgb', + 'bc4r-unorm', + 'bc4r-snorm', + 'bc5rg-unorm', + 'bc5rg-snorm', + 'bc6h-rgb-ufloat', + 'bc6h-rgb-sfloat', + 'bc7rgba-unorm', + 'bc7rgba-unorm-srgb', + ], + TextureViewDimension: [ + undefined, + '1d', + '2d', + '2d-array', + 'cube', + 'cube-array', + '3d', + ], + VertexFormat: [ + 'uchar2', + 'uchar4', + 'char2', + 'char4', + 'uchar2norm', + 'uchar4norm', + 'char2norm', + 'char4norm', + 'ushort2', + 'ushort4', + 'short2', + 'short4', + 'ushort2norm', + 'ushort4norm', + 'short2norm', + 'short4norm', + 'half2', + 'half4', + 'float', + 'float2', + 'float3', + 'float4', + 'uint', + 'uint2', + 'uint3', + 'uint4', + 'int', + 'int2', + 'int3', + 'int4', + ], + }, + + // *Reference/*Release + + {{{ gpu.makeReferenceRelease('Surface') }}} + {{{ gpu.makeReferenceRelease('SwapChain') }}} + + {{{ gpu.makeReferenceRelease('Device') }}} + {{{ gpu.makeReferenceRelease('Queue') }}} + {{{ gpu.makeReferenceRelease('Fence') }}} + + {{{ gpu.makeReferenceRelease('CommandBuffer') }}} + {{{ gpu.makeReferenceRelease('CommandEncoder') }}} + {{{ gpu.makeReferenceRelease('RenderPassEncoder') }}} + + {{{ gpu.makeReferenceRelease('BindGroup') }}} + {{{ gpu.makeReferenceRelease('Buffer') }}} + {{{ gpu.makeReferenceRelease('Sampler') }}} + {{{ gpu.makeReferenceRelease('Texture') }}} + {{{ gpu.makeReferenceRelease('TextureView') }}} + + {{{ gpu.makeReferenceRelease('BindGroupLayout') }}} + {{{ gpu.makeReferenceRelease('PipelineLayout') }}} + {{{ gpu.makeReferenceRelease('RenderPipeline') }}} + {{{ gpu.makeReferenceRelease('ShaderModule') }}} + + {{{ gpu.makeReferenceRelease('RenderBundleEncoder') }}} + {{{ gpu.makeReferenceRelease('RenderBundle') }}} + + // *Destroy + + wgpuBufferDestroy: function(bufferId) { WebGPU.mgrBuffer.get(bufferId).destroy(); }, + wgpuTextureDestroy: function(textureId) { WebGPU.mgrTexture.get(textureId).destroy(); }, + + // wgpuDevice + + // wgpuDeviceCreate* + + wgpuDeviceCreateQueue: function(deviceId) { + assert(WebGPU.mgrQueue.objects.length === 1, 'there is only one queue'); + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrQueue.create(device["defaultQueue"]); + }, + + wgpuDeviceCreateCommandEncoder: function(deviceId, descriptor) { + var desc; + if (descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + desc = { + "label": undefined, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUCommandEncoderDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + } + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrCommandEncoder.create(device["createCommandEncoder"](desc)); + }, + + wgpuDeviceCreateBuffer: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var desc = { + "label": undefined, + "usage": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUBufferDescriptor.usage) }}}, + "size": {{{ gpu.makeGetU64('descriptor', C_STRUCTS.WGPUBufferDescriptor.size) }}}, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBufferDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrBuffer.create(device["createBuffer"](desc)); + }, + + wgpuDeviceCreateBufferMapped: function(returnPtr, deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var desc = { + "usage": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUBufferDescriptor.usage) }}}, + "size": {{{ gpu.makeGetU64('descriptor', C_STRUCTS.WGPUBufferDescriptor.size) }}}, + }; + + var device = WebGPU["mgrDevice"].get(deviceId); + var bufferMapped = device["createBufferMapped"](desc); + var buffer = bufferMapped[0]; + var mapped = bufferMapped[1]; + + var bufferWrapper = {}; + var bufferId = WebGPU.mgrBuffer.create(buffer, bufferWrapper); + WebGPU.trackMapWrite(bufferWrapper, mapped); + + var dataLength_h = (mapped.byteLength / 0x100000000) | 0; + var dataLength_l = mapped.byteLength | 0; + + {{{ makeSetValue('returnPtr', C_STRUCTS.WGPUCreateBufferMappedResult.buffer, 'bufferId', '*') }}} + {{{ makeSetValue('returnPtr', C_STRUCTS.WGPUCreateBufferMappedResult.dataLength + 0, 'dataLength_l', 'i32') }}} + {{{ makeSetValue('returnPtr', C_STRUCTS.WGPUCreateBufferMappedResult.dataLength + 4, 'dataLength_h', 'i32') }}} + {{{ makeSetValue('returnPtr', C_STRUCTS.WGPUCreateBufferMappedResult.data, 'bufferWrapper.mapWriteSrc', '*') }}} + }, + + wgpuDeviceCreateTexture: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + var desc = { + "label": undefined, + "size": WebGPU.makeExtent3D(descriptor + {{{ C_STRUCTS.WGPUTextureDescriptor.size }}}), + "arrayLayerCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.arrayLayerCount) }}}, + "mipLevelCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.mipLevelCount) }}}, + "sampleCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.sampleCount) }}}, + "dimension": WebGPU.TextureDimension[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.dimension) }}}], + "format": WebGPU.TextureFormat[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.format) }}}], + "usage": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureDescriptor.usage) }}}, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUTextureDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrTexture.create(device["createTexture"](desc)); + }, + + wgpuDeviceCreateSampler: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + var desc = { + "label": undefined, + "addressModeU": WebGPU.AddressMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.addressModeU) }}}], + "addressModeV": WebGPU.AddressMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.addressModeV) }}}], + "addressModeW": WebGPU.AddressMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.addressModeW) }}}], + "magFilter": WebGPU.FilterMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.magFilter) }}}], + "minFilter": WebGPU.FilterMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.minFilter) }}}], + "mipmapFilter": WebGPU.FilterMode[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.mipmapFilter) }}}], + "lodMinClamp": {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSamplerDescriptor.lodMinClamp, 'float') }}}, + "lodMaxClamp": {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSamplerDescriptor.lodMaxClamp, 'float') }}}, + "compare": WebGPU.CompareFunction[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSamplerDescriptor.compare) }}}], + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSamplerDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrSampler.create(device["createSampler"](desc)); + }, + + wgpuDeviceCreateBindGroupLayout: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + function makeBinding(bindingPtr) { + {{{ gpu.makeCheck('bindingPtr') }}} + + return { + "binding": + {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.binding) }}}, + "visibility": + {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.visibility) }}}, + "type": WebGPU.BindingType[ + {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.type) }}}], + "textureDimension": WebGPU.TextureViewDimension[ + {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.textureDimension) }}}], + "textureComponentType": WebGPU.TextureComponentType[ + {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.textureComponentType) }}}], + "multisampled": + {{{ gpu.makeGetBool('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.multisampled) }}}, + "hasDynamicOffset": + {{{ gpu.makeGetBool('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.hasDynamicOffset) }}}, + }; + } + + function makeBindings(count, bindingsPtrs) { + var bindings = []; + for (var i = 0; i < count; ++i) { + bindings.push(makeBinding(bindingsPtrs + + {{{ C_STRUCTS.WGPUBindGroupLayoutBinding.__size__ }}} * i)); + } + return bindings; + } + + var desc = { + "bindings": makeBindings( + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUBindGroupLayoutDescriptor.bindingCount) }}}, + {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBindGroupLayoutDescriptor.bindings, '*') }}} + ), + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBindGroupLayoutDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrBindGroupLayout.create(device["createBindGroupLayout"](desc)); + }, + + wgpuDeviceCreateBindGroup: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + function makeBinding(bindingPtr) { + {{{ gpu.makeCheck('bindingPtr') }}} + + var bufferId = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.buffer) }}}; + var samplerId = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.sampler) }}}; + var textureViewId = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.textureView) }}}; +#if ASSERTIONS + assert((bufferId != 0) + (samplerId != 0) + (textureViewId != 0) == 1); +#endif + + var binding = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupLayoutBinding.binding) }}}; + + if (bufferId != 0) { + var size = undefined; + + // Handle WGPU_WHOLE_SIZE. + var sizePart1 = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.size) }}}; + var sizePart2 = {{{ gpu.makeGetU32('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.size + 4) }}}; + if (sizePart1 != 0xFFFFFFFF || sizePart2 != 0xFFFFFFFF) { + size = {{{ gpu.makeGetU64('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.size) }}}; + } + + return { + "binding": binding, + "resource": { + "buffer": WebGPU.mgrBuffer.get(bufferId), + "offset": {{{ gpu.makeGetU64('bindingPtr', C_STRUCTS.WGPUBindGroupBinding.offset) }}}, + "size": size, + }, + }; + } else if (samplerId != 0) { + return { + "binding": binding, + "resource": WebGPU.mgrSampler.get(samplerId), + }; + } else { + return { + "binding": binding, + "resource": WebGPU.mgrTextureView.get(textureViewId), + }; + } + } + + function makeBindings(count, bindingsPtrs) { + var bindings = []; + for (var i = 0; i < count; ++i) { + bindings.push(makeBinding(bindingsPtrs + + {{{C_STRUCTS.WGPUBindGroupBinding.__size__}}} * i)); + } + return bindings; + } + + var desc = { + "label": undefined, + "layout": WebGPU.mgrBindGroupLayout.get( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBindGroupDescriptor.layout, '*') }}}), + "bindings": makeBindings( + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUBindGroupDescriptor.bindingCount) }}}, + {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBindGroupDescriptor.bindings, '*') }}} + ), + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUBindGroupDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrBindGroup.create(device["createBindGroup"](desc)); + }, + + wgpuDeviceCreatePipelineLayout: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var bglCount = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUPipelineLayoutDescriptor.bindGroupLayoutCount) }}}; + var bglPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUPipelineLayoutDescriptor.bindGroupLayouts, '*') }}}; + var bgls = []; + for (var i = 0; i < bglCount; ++i) { + bgls.push(WebGPU.mgrBindGroupLayout.get( + {{{ makeGetValue('bglPtr', '4 * i', '*') }}})); + } + var desc = { + "label": undefined, + "bindGroupLayouts": bgls, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUPipelineLayoutDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrPipelineLayout.create(device["createPipelineLayout"](desc)); + }, + + wgpuDeviceCreateComputePipeline: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + var desc = { + "label": undefined, + "computeStage": WebGPU.makeProgrammableStageDescriptor( + descriptor + {{{ C_STRUCTS.WGPUComputePipelineDescriptor.computeStage }}}), + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUComputePipelineDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrComputePipeline.create(device["createComputePipeline"](desc)); + }, + + wgpuDeviceCreateRenderPipeline: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + + function makeRasterizationState(rsPtr) { + if (rsPtr === 0) return undefined; + {{{ gpu.makeCheckDescriptor('rsPtr') }}} + return { + "frontFace": WebGPU.FrontFace[ + {{{ gpu.makeGetU32('rsPtr', C_STRUCTS.WGPURasterizationStateDescriptor.frontFace) }}}], + "cullMode": WebGPU.CullMode[ + {{{ gpu.makeGetU32('rsPtr', C_STRUCTS.WGPURasterizationStateDescriptor.cullMode) }}}], + }; + } + + function makeBlendDescriptor(bdPtr) { + if (bdPtr === 0) return undefined; + return { + "operation": WebGPU.BlendOperation[ + {{{ gpu.makeGetU32('bdPtr', C_STRUCTS.WGPUBlendDescriptor.operation) }}}], + "srcFactor": WebGPU.BlendFactor[ + {{{ gpu.makeGetU32('bdPtr', C_STRUCTS.WGPUBlendDescriptor.srcFactor) }}}], + "dstFactor": WebGPU.BlendFactor[ + {{{ gpu.makeGetU32('bdPtr', C_STRUCTS.WGPUBlendDescriptor.dstFactor) }}}], + }; + } + + function makeColorState(csPtr) { + {{{ gpu.makeCheckDescriptor('csPtr') }}} + return { + "format": WebGPU.TextureFormat[ + {{{ gpu.makeGetU32('csPtr', C_STRUCTS.WGPUColorStateDescriptor.format) }}}], + "alphaBlend": makeBlendDescriptor(csPtr + {{{ C_STRUCTS.WGPUColorStateDescriptor.alphaBlend }}}), + "colorBlend": makeBlendDescriptor(csPtr + {{{ C_STRUCTS.WGPUColorStateDescriptor.colorBlend }}}), + "writeMask": {{{ gpu.makeGetU32('csPtr', C_STRUCTS.WGPUColorStateDescriptor.writeMask) }}}, + }; + } + + function makeColorStates(count, csPtr) { + if (count === 0) return undefined; + + var states = []; + for (var i = 0; i < count; ++i) { + states.push(makeColorState(csPtr + {{{ C_STRUCTS.WGPUColorStateDescriptor.__size__ }}} * i)); + } + return states; + } + + function makeStencilStateFace(ssfPtr) { + {{{ gpu.makeCheck('ssfPtr') }}} + return { + "compare": WebGPU.CompareFunction[ + {{{ gpu.makeGetU32('ssfPtr', C_STRUCTS.WGPUStencilStateFaceDescriptor.compare) }}}], + "failOp": WebGPU.StencilOperation[ + {{{ gpu.makeGetU32('ssfPtr', C_STRUCTS.WGPUStencilStateFaceDescriptor.failOp) }}}], + "depthFailOp": WebGPU.StencilOperation[ + {{{ gpu.makeGetU32('ssfPtr', C_STRUCTS.WGPUStencilStateFaceDescriptor.depthFailOp) }}}], + "passOp": WebGPU.StencilOperation[ + {{{ gpu.makeGetU32('ssfPtr', C_STRUCTS.WGPUStencilStateFaceDescriptor.passOp) }}}], + }; + } + + function makeDepthStencilState(dssPtr) { + if (dssPtr === 0) return undefined; + + {{{ gpu.makeCheck('dssPtr') }}} + return { + "format": WebGPU.TextureFormat[ + {{{ gpu.makeGetU32('dssPtr', C_STRUCTS.WGPUDepthStencilStateDescriptor.format) }}}], + "depthWriteEnabled": {{{ gpu.makeGetBool('dssPtr', C_STRUCTS.WGPUDepthStencilStateDescriptor.depthWriteEnabled) }}}, + "depthCompare": WebGPU.CompareFunction[ + {{{ gpu.makeGetU32('dssPtr', C_STRUCTS.WGPUDepthStencilStateDescriptor.depthCompare) }}}], + "stencilFront": makeStencilStateFace(dssPtr + {{{ C_STRUCTS.WGPUDepthStencilStateDescriptor.stencilFront }}}), + "stencilBack": makeStencilStateFace(dssPtr + {{{ C_STRUCTS.WGPUDepthStencilStateDescriptor.stencilBack }}}), + "stencilReadMask": {{{ gpu.makeGetU32('dssPtr', C_STRUCTS.WGPUDepthStencilStateDescriptor.stencilReadMask) }}}, + "stencilWriteMask": {{{ gpu.makeGetU32('dssPtr', C_STRUCTS.WGPUDepthStencilStateDescriptor.stencilWriteMask) }}}, + }; + } + + function makeVertexAttribute(vaPtr) { + {{{ gpu.makeCheck('vaPtr') }}} + return { + "format": WebGPU.VertexFormat[ + {{{ gpu.makeGetU32('vaPtr', C_STRUCTS.WGPUVertexAttributeDescriptor.format) }}}], + "offset": {{{ gpu.makeGetU64('vaPtr', C_STRUCTS.WGPUVertexAttributeDescriptor.offset) }}}, + "shaderLocation": {{{ gpu.makeGetU32('vaPtr', C_STRUCTS.WGPUVertexAttributeDescriptor.shaderLocation) }}}, + }; + } + + function makeVertexAttributes(count, vaArrayPtr) { + var vas = []; + for (var i = 0; i < count; ++i) { + vas.push(makeVertexAttribute(vaArrayPtr + i * {{{ C_STRUCTS.WGPUVertexAttributeDescriptor.__size__ }}})); + } + return vas; + } + + function makeVertexBuffer(vbPtr) { + if (vbPtr === 0) return undefined; + + return { + "arrayStride": {{{ gpu.makeGetU64('vbPtr', C_STRUCTS.WGPUVertexBufferLayoutDescriptor.arrayStride) }}}, + "stepMode": WebGPU.InputStepMode[ + {{{ gpu.makeGetU32('vbPtr', C_STRUCTS.WGPUVertexBufferLayoutDescriptor.stepMode) }}}], + "attributes": makeVertexAttributes( + {{{ gpu.makeGetU32('vbPtr', C_STRUCTS.WGPUVertexBufferLayoutDescriptor.attributeCount) }}}, + {{{ makeGetValue('vbPtr', C_STRUCTS.WGPUVertexBufferLayoutDescriptor.attributes, '*') }}}), + }; + } + + function makeVertexBuffers(count, vbArrayPtr) { + if (count === 0) return undefined; + + var vbs = []; + for (var i = 0; i < count; ++i) { + vbs.push(makeVertexBuffer(vbArrayPtr + i * {{{ C_STRUCTS.WGPUVertexBufferLayoutDescriptor.__size__ }}})); + } + return vbs; + } + + function makeVertexState(viPtr) { + if (viPtr === 0) return undefined; + {{{ gpu.makeCheckDescriptor('viPtr') }}} + return { + "indexFormat": WebGPU.IndexFormat[ + {{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexStateDescriptor.indexFormat) }}}], + "vertexBuffers": makeVertexBuffers( + {{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexStateDescriptor.vertexBufferCount) }}}, + {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexStateDescriptor.vertexBuffers, '*') }}}), + }; + } + + var desc = { + "label": undefined, + "layout": WebGPU.mgrPipelineLayout.get( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.layout, '*') }}}), + "vertexStage": WebGPU.makeProgrammableStageDescriptor( + descriptor + {{{ C_STRUCTS.WGPURenderPipelineDescriptor.vertexStage }}}), + "fragmentStage": WebGPU.makeProgrammableStageDescriptor( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.fragmentStage, '*') }}}), + "primitiveTopology": WebGPU.PrimitiveTopology[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.primitiveTopology) }}}], + "rasterizationState": makeRasterizationState( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.rasterizationState, '*') }}}), + "colorStates": makeColorStates( + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.colorStateCount) }}}, + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.colorStates, '*') }}}), + "depthStencilState": makeDepthStencilState( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.depthStencilState, '*') }}}), + "vertexState": makeVertexState( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.vertexState, '*') }}}), + "sampleCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.sampleCount) }}}, + "sampleMask": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.sampleMask) }}}, + "alphaToCoverageEnabled": {{{ gpu.makeGetBool('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.alphaToCoverageEnabled) }}}, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPipelineDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrRenderPipeline.create(device["createRenderPipeline"](desc)); + }, + + wgpuDeviceCreateShaderModule: function(deviceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var count = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUShaderModuleDescriptor.codeSize) }}}; + var start = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUShaderModuleDescriptor.code, '*') }}}; + var desc = { + "label": undefined, + "code": HEAPU32.subarray(start >> 2, (start >> 2) + count), + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUShaderModuleDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrShaderModule.create(device["createShaderModule"](desc)); + }, + + wgpuDeviceSetUncapturedErrorCallback: function(deviceId, callback, userdata) { + var device = WebGPU["mgrDevice"].get(deviceId); + device["onuncapturederror"] = function(ev) { + // WGPUErrorType type, const char* message, void* userdata + var Validation = 0x00000001; + var OutOfMemory = 0x00000002; + var type; +#if ASSERTIONS + assert(typeof GPUValidationError !== 'undefined'); + assert(typeof GPUOutOfMemoryError !== 'undefined'); +#endif + if (ev.error instanceof GPUValidationError) type = Validation; + else if (ev.error instanceof GPUOutOfMemoryError) type = OutOfMemory; + var messagePtr = allocateUTF8(ev.error.message); + dynCall('viii', callback, [type, messagePtr, userdata]); + _free(messagePtr); + }; + }, + + // wgpuFence + + wgpuFenceOnCompletion: function(fenceId, completionValue_l, completionValue_h, callback, userdata) { + var fence = WebGPU.mgrFence.get(fenceId); + var completionValue = {{{ gpu.makeU64ToNumber('completionValue_l', 'completionValue_h') }}}; + + var DAWN_FENCE_COMPLETION_STATUS_SUCCESS = 0; + var DAWN_FENCE_COMPLETION_STATUS_ERROR = 1; + + fence.onCompletion(completionValue).then(function() { + dynCall('vii', callback, [DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata]); + }, function() { + dynCall('vii', callback, [DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata]); + }); + }, + + // wgpuQueue + + wgpuQueueCreateFence: function(queueId, descriptor) { + var queue = WebGPU.mgrQueue.get(queueId); + + var desc; + if (descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + desc = { + "label": UTF8ToString( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPUFenceDescriptor.label, '*') }}}), + "initialValue": {{{ gpu.makeGetU64('descriptor', C_STRUCTS.WGPUFenceDescriptor.initialValue) }}}, + }; + } + + return WebGPU.mgrFence.create(queue.createFence(desc)); + }, + + wgpuQueueSignal: function(queueId, fenceId, signalValue_l, signalValue_h) { + var queue = WebGPU.mgrQueue.get(queueId); + var fence = WebGPU.mgrFence.get(fenceId); + var signalValue = {{{ gpu.makeU64ToNumber('signalValue_l', 'signalValue_h') }}}; + queue.signal(fence, signalValue); + }, + + wgpuQueueSubmit: function(queueId, commandCount, commands) { +#if ASSERTIONS + assert(commands % 4 === 0); +#endif + var queue = WebGPU.mgrQueue.get(queueId); + var cmds = Array.from(HEAP32.subarray(commands >> 2, (commands >> 2) + commandCount), + function(id) { return WebGPU.mgrCommandBuffer.get(id); }); + queue.submit(cmds); + }, + + // wgpuCommandEncoder + + wgpuCommandEncoderFinish: function(encoderId) { + var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId); + return WebGPU.mgrCommandBuffer.create(commandEncoder["finish"]()); + }, + + wgpuDeviceCreateRenderBundleEncoder: function(deviceId, descriptor) { + {{{ gpu.makeCheck('descriptor') }}} + + function makeRenderBundleEncoderDescriptor(descriptor) { + {{{ gpu.makeCheck('descriptor') }}} + + function makeColorFormats(count, formatsPtr) { + var formats = []; + for (var i = 0; i < count; ++i, formatsPtr += 4) { + formats.push(WebGPU.TextureFormat[{{{ gpu.makeGetU32('formatsPtr', 0) }}}]); + } + return formats; + } + + var desc = { + "label": undefined, + "colorFormats": makeColorFormats( + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderBundleEncoderDescriptor.colorFormatsCount) }}}, + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderBundleEncoderDescriptor.colorFormats, '*') }}}), + "depthStencilFormat": WebGPU.TextureFormat[{{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderBundleEncoderDescriptor.depthStencilFormat) }}}], + "sampleCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderBundleEncoderDescriptor.sampleCount) }}}, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderBundleEncoderDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + return desc; + } + + var desc = makeRenderBundleEncoderDescriptor(descriptor); + var device = WebGPU["mgrDevice"].get(deviceId); + return WebGPU.mgrRenderBundleEncoder.create(device["createRenderBundleEncoder"](desc)); + }, + + wgpuCommandEncoderBeginRenderPass: function(encoderId, descriptor) { + {{{ gpu.makeCheck('descriptor') }}} + + function makeColorAttachment(caPtr) { + var loadValue = WebGPU.LoadOp[ + {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.loadOp) }}}]; + if (loadValue === 'clear') { + loadValue = WebGPU.makeColor(caPtr + {{{ C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.clearColor }}}); + } + + return { + "attachment": WebGPU.mgrTextureView.get( + {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.attachment) }}}), + "resolveTarget": WebGPU.mgrTextureView.get( + {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.resolveTarget) }}}), + "storeOp": WebGPU.StoreOp[ + {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.storeOp) }}}], + "loadValue": loadValue, + }; + } + + function makeColorAttachments(count, caPtr) { + var attachments = []; + for (var i = 0; i < count; ++i) { + attachments.push(makeColorAttachment(caPtr + {{{ C_STRUCTS.WGPURenderPassColorAttachmentDescriptor.__size__ }}} * i)); + } + return attachments; + } + + function makeDepthStencilAttachment(dsaPtr) { + if (dsaPtr === 0) return undefined; + + var depthLoadValue = WebGPU.LoadOp[ + {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.depthLoadOp) }}}]; + if (depthLoadValue === 'clear') { + depthLoadValue = {{{ makeGetValue('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.clearDepth, 'float') }}}; + } + + var stencilLoadValue = WebGPU.LoadOp[ + {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.stencilLoadOp) }}}]; + if (stencilLoadValue === 'clear') { + stencilLoadValue = {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.clearStencil) }}}; + } + + return { + "attachment": WebGPU.mgrTextureView.get( + {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.attachment) }}}), + "depthStoreOp": WebGPU.StoreOp[ + {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.depthStoreOp) }}}], + "depthLoadValue": depthLoadValue, + "stencilStoreOp": WebGPU.StoreOp[ + {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachmentDescriptor.stencilStoreOp) }}}], + "stencilLoadValue": stencilLoadValue, + }; + } + + function makeRenderPassDescriptor(descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var desc = { + "label": undefined, + "colorAttachments": makeColorAttachments( + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPURenderPassDescriptor.colorAttachmentCount) }}}, + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPassDescriptor.colorAttachments, '*') }}}), + "depthStencilAttachment": makeDepthStencilAttachment( + {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPassDescriptor.depthStencilAttachment, '*') }}}), + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderPassDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + return desc; + } + + var desc = makeRenderPassDescriptor(descriptor); + + var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId); + return WebGPU.mgrRenderPassEncoder.create(commandEncoder["beginRenderPass"](desc)); + }, + + wgpuCommandEncoderCopyBufferToBuffer: function(encoderId, srcId, srcOffset_l, srcOffset_h, dstId, dstOffset_l, dstOffset_h, size_l, size_h) { + var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId); + var src = WebGPU.mgrBuffer.get(srcId); + var dst = WebGPU.mgrBuffer.get(dstId); + commandEncoder["copyBufferToBuffer"]( + src, {{{ gpu.makeU64ToNumber('srcOffset_l', 'srcOffset_h') }}}, + dst, {{{ gpu.makeU64ToNumber('dstOffset_l', 'dstOffset_h') }}}, + {{{ gpu.makeU64ToNumber('size_l', 'size_h') }}}); + }, + + wgpuCommandEncoderCopyBufferToTexture: function(encoderId, srcPtr, dstPtr, copySizePtr) { + var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId); + var copySize = WebGPU.makeExtent3D(copySizePtr); + commandEncoder["copyBufferToTexture"]( + WebGPU.makeBufferCopyView(srcPtr), WebGPU.makeTextureCopyView(dstPtr), copySize); + }, + + wgpuCommandEncoderCopyTextureToBuffer: function(encoderId, srcPtr, dstPtr, copySizePtr) { + var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId); + var copySize = WebGPU.makeExtent3D(copySizePtr); + commandEncoder["copyTextureToBuffer"]( + WebGPU.makeTextureCopyView(srcPtr), WebGPU.makeBufferCopyView(dstPtr), copySize); + }, + + // wgpuBuffer + + wgpuBufferSetSubData: function(bufferId, start_l, start_h, count_l, count_h, data) { + var buffer = WebGPU.mgrBuffer.get(bufferId); + var start = {{{ gpu.makeU64ToNumber('start_l', 'start_h') }}}; + var count = {{{ gpu.makeU64ToNumber('count_l', 'count_h') }}}; + buffer["setSubData"](start, HEAPU8, data, count); + }, + + wgpuBufferMapReadAsync: function(bufferId, callback, userdata) { + var bufferEntry = WebGPU.mgrBuffer.objects[bufferId]; + bufferEntry.mapped = 'write'; + var buffer = bufferEntry.object; + + buffer["mapReadAsync"]().then(function(mapped) { + var DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS = 0; + var data = _malloc(mapped.byteLength); + HEAPU8.set(new Uint8Array(mapped), data); + var dataLength_h = (mapped.byteLength / 0x100000000) | 0; + var dataLength_l = mapped.byteLength | 0; + // WGPUBufferMapAsyncStatus status, const void* data, uint64_t dataLength, void* userdata + dynCall('viiji', callback, [DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, dataLength_l, dataLength_h, userdata]); + }, function() { + // TODO(kainino0x): Figure out how to pick other error status values. + var DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR = 1; + dynCall('viiji', callback, [DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, 0, 0, 0, userdata]); + }); + }, + + wgpuBufferMapWriteAsync: function(bufferId, callback, userdata) { + var bufferWrapper = WebGPU.mgrBuffer.objects[bufferId]; + var buffer = bufferWrapper.object; + + var DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS = 0; + var DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR = 1; + buffer["mapWriteAsync"]().then(function(mapped) { + WebGPU.trackMapWrite(bufferWrapper, mapped); + + var data = bufferWrapper.mapWriteSrc; + var dataLength_h = (mapped.byteLength / 0x100000000) | 0; + var dataLength_l = mapped.byteLength | 0; + // WGPUBufferMapAsyncStatus status, void* data, uint64_t dataLength, void* userdata + dynCall('viiji', callback, [DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, dataLength_l, dataLength_h, userdata]); + }, function() { + // TODO(kainino0x): Figure out how to pick other error status values. + dynCall('viiji', callback, [DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, 0, 0, 0, userdata]); + }); + }, + + wgpuBufferUnmap: function(bufferId) { + var bufferWrapper = WebGPU.mgrBuffer.objects[bufferId]; + WebGPU.trackUnmap(bufferWrapper); + bufferWrapper.object["unmap"](); + }, + + // wgpuTexture + + wgpuTextureCreateView: function(textureId, descriptor) { + var desc; + if (descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + desc = { + "format": WebGPU.TextureFormat[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.format) }}}], + "dimension": WebGPU.TextureViewDimension[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.dimension) }}}], + "baseMipLevel": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.baseMipLevel) }}}, + "mipLevelCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.mipLevelCount) }}}, + "baseArrayLayer": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.baseArrayLayer) }}}, + "arrayLayerCount": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.arrayLayerCount) }}}, + "aspect": WebGPU.TextureAspect[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.aspect) }}}], + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUTextureViewDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + } + + var texture = WebGPU.mgrTexture.get(textureId); + return WebGPU.mgrTextureView.create(texture["createView"](desc)); + }, + + // wgpuComputePass + + wgpuComputePassEncoderSetPipeline: function(passId, pipelineId) { + var pass = WebGPU.mgrComputePassEncoder.get(passId); + var pipeline = WebGPU.mgrComputePipeline.get(pipelineId); + pass["setPipeline"](pipeline); + }, + wgpuComputePassEncoderDispatch: function(passId, x, y, z) { + var pass = WebGPU.mgrComputePassEncoder.get(passId); + pass["dispatch"](x, y, z); + }, + wgpuComputePassEncoderDispatchIndirect: function(passId, indirectBufferId, indirectOffset_l, indirectOffset_h) { + var indirectBuffer = WebGPU.mgrBuffer.get(indirectBufferId); + var indirectOffset = {{{ gpu.makeU64ToNumber('indirectOffset_l', 'indirectOffset_h') }}}; + var pass = WebGPU.mgrComputePassEncoder.get(passId); + pass["dispatchIndirect"](indirectBuffer, indirectOffset); + }, + wgpuComputePassEncoderEndPass: function(passId) { + var pass = WebGPU.mgrComputePassEncoder.get(passId); + pass["endPass"](); + }, + + // wgpuRenderPass + + wgpuRenderPassEncoderSetBindGroup: function(passId, groupIndex, groupId, dynamicOffsetCount, dynamicOffsetsPtr) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + var group = WebGPU.mgrBindGroup.get(groupId); + if (dynamicOffsetCount == 0) { + pass["setBindGroup"](groupIndex, group); + } else { + var offsets = []; + for (var i = 0; i < dynamicOffsetCount; i++, dynamicOffsetsPtr += 4) { + offsets.push({{{ gpu.makeGetU32('dynamicOffsetsPtr', 0) }}}); + } + pass["setBindGroup"](groupIndex, group, offsets); + } + }, + wgpuRenderPassEncoderSetIndexBuffer: function(passId, bufferId, offset) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + var buffer = WebGPU.mgrBuffer.get(bufferId); + pass["setIndexBuffer"](buffer, offset); + }, + wgpuRenderPassEncoderSetPipeline: function(passId, pipelineId) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + var pipeline = WebGPU.mgrRenderPipeline.get(pipelineId); + pass["setPipeline"](pipeline); + }, + wgpuRenderPassEncoderSetScissorRect: function(passId, x, y, w, h) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["setScissorRect"](x, y, w, h); + }, + wgpuRenderPassEncoderSetViewport: function(passId, x, y, w, h, minDepth, maxDepth) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["setViewport"](x, y, w, h, minDepth, maxDepth); + }, + wgpuRenderPassEncoderSetStencilReference: function(passId, reference) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["setStencilReference"](reference); + }, + wgpuRenderPassEncoderSetVertexBuffer: function(passId, slot, bufferId, offset) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["setVertexBuffer"](slot, WebGPU.mgrBuffer.get(bufferId), offset); + }, + wgpuRenderPassEncoderDraw: function(passId, vertexCount, instanceCount, firstVertex, firstInstance) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["draw"](vertexCount, instanceCount, firstVertex, firstInstance); + }, + wgpuRenderPassEncoderDrawIndexed: function(passId, indexCount, instanceCount, firstIndex, baseVertex, firstInstance) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["drawIndexed"](indexCount, instanceCount, firstIndex, baseVertex, firstInstance); + }, + wgpuRenderPassEncoderDrawIndirect: function(passId, indirectBufferId, indirectOffset_l, indirectOffset_h) { + var indirectBuffer = WebGPU.mgrBuffer.get(indirectBufferId); + var indirectOffset = {{{ gpu.makeU64ToNumber('indirectOffset_l', 'indirectOffset_h') }}}; + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["drawIndirect"](indirectBuffer, indirectOffset); + }, + wgpuRenderPassEncoderDrawIndexedIndirect: function(passId, indirectBufferId, indirectOffset_l, indirectOffset_h) { + var indirectBuffer = WebGPU.mgrBuffer.get(indirectBufferId); + var indirectOffset = {{{ gpu.makeU64ToNumber('indirectOffset_l', 'indirectOffset_h') }}}; + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["drawIndexedIndirect"](indirectBuffer, indirectOffset); + }, + wgpuRenderPassEncoderExecuteBundles: function(passId, count, bundlesPtr) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + +#if ASSERTIONS + assert(bundlesPtr % 4 === 0); +#endif + + var bundles = Array.from(HEAP32.subarray(bundlesPtr >> 2, (bundlesPtr >> 2) + count), + function(id) { return WebGPU.mgrRenderBundle.get(id); }); + pass["executeBundles"](bundles); + }, + wgpuRenderPassEncoderEndPass: function(passId) { + var pass = WebGPU.mgrRenderPassEncoder.get(passId); + pass["endPass"](); + }, + + // Render bundle encoder + + wgpuRenderBundleEncoderSetBindGroup: function(bundleId, groupIndex, groupId, dynamicOffsetCount, dynamicOffsetsPtr) { + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + var group = WebGPU.mgrBindGroup.get(groupId); + if (dynamicOffsetCount == 0) { + pass["setBindGroup"](groupIndex, group); + } else { + var offsets = []; + for (var i = 0; i < dynamicOffsetCount; i++, dynamicOffsetsPtr += 4) { + offsets.push({{{ gpu.makeGetU32('dynamicOffsetsPtr', 0) }}}); + } + pass["setBindGroup"](groupIndex, group, offsets); + } + }, + wgpuRenderBundleEncoderSetIndexBuffer: function(bundleId, bufferId, offset_l, offset_h) { + var offset = {{{ gpu.makeU64ToNumber('offset_l', 'offset_h') }}}; + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + var buffer = WebGPU.mgrBuffer.get(bufferId); + pass["setIndexBuffer"](buffer, offset); + }, + wgpuRenderBundleEncoderSetPipeline: function(bundleId, pipelineId) { + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + var pipeline = WebGPU.mgrRenderPipeline.get(pipelineId); + pass["setPipeline"](pipeline); + }, + wgpuRenderBundleEncoderSetVertexBuffer: function(bundleId, slot, bufferId, offset_l, offset_h) { + var offset = {{{ gpu.makeU64ToNumber('offset_l', 'offset_h') }}}; + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + pass["setVertexBuffer"](slot, WebGPU.mgrBuffer.get(bufferId), offset); + }, + wgpuRenderBundleEncoderDraw: function(bundleId, vertexCount, instanceCount, firstVertex, firstInstance) { + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + pass["draw"](vertexCount, instanceCount, firstVertex, firstInstance); + }, + wgpuRenderBundleEncoderDrawIndexed: function(bundleId, indexCount, instanceCount, firstIndex, baseVertex, firstInstance) { + var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId); + pass["drawIndexed"](indexCount, instanceCount, firstIndex, baseVertex, firstInstance); + }, + wgpuRenderBundleEncoderFinish: function(bundleId, descriptor) { + var desc; + if (descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + desc = {}; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPURenderBundleDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + } + var encoder = WebGPU.mgrRenderBundleEncoder.get(bundleId); + return WebGPU.mgrRenderBundle.create(encoder["finish"](desc)); + }, + + // Instance + + wgpuInstanceReference: function() { +#if ASSERTIONS + assert(false, 'No WGPUInstance object should exist.'); +#endif + }, + wgpuInstanceRelease: function() { +#if ASSERTIONS + assert(false, 'No WGPUInstance object should exist.'); +#endif + }, + + wgpuInstanceCreateSurface: function(instanceId, descriptor) { + {{{ gpu.makeCheck('descriptor') }}} + {{{ gpu.makeCheck('instanceId === 0, "WGPUInstance is ignored"') }}} + var nextInChainPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSurfaceDescriptor.nextInChain, '*') }}}; +#if ASSERTIONS + assert(nextInChainPtr !== 0); + assert({{{ gpu.SType.SurfaceDescriptorFromHTMLCanvasId }}} === + {{{ gpu.makeGetU32('nextInChainPtr', C_STRUCTS.WGPUChainedStruct.sType) }}}); +#endif + var descriptorFromHTMLCanvasId = nextInChainPtr; + + {{{ gpu.makeCheckDescriptor('descriptorFromHTMLCanvasId') }}} + var idPtr = {{{ makeGetValue('descriptorFromHTMLCanvasId', C_STRUCTS.WGPUSurfaceDescriptorFromHTMLCanvasId.id, '*') }}}; + {{{ gpu.makeCheck('idPtr') }}} + var id = UTF8ToString(idPtr); + var canvas = document.getElementById(id); + assert(canvas instanceof HTMLCanvasElement); + + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSurfaceDescriptor.label, '*') }}}; + if (labelPtr) canvas.surfaceLabelWebGPU = UTF8ToString(labelPtr); + + return WebGPU.mgrSurface.create(canvas); + }, + + // wgpuDeviceCreateSwapChain + WGPUSwapChain + + wgpuDeviceCreateSwapChain: function(deviceId, surfaceId, descriptor) { + {{{ gpu.makeCheckDescriptor('descriptor') }}} + var device = WebGPU["mgrDevice"].get(deviceId); + var canvas = WebGPU.mgrSurface.get(surfaceId); + + canvas.width = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.width) }}}; + canvas.height = {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.height) }}}; + + var ctx = canvas.getContext('gpupresent'); + assert({{{ gpu.PresentMode.VSync }}} === + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.presentMode) }}}); + + var desc = { + "label": undefined, + "device": device, + "format": WebGPU.TextureFormat[ + {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.format) }}}], + "usage": {{{ gpu.makeGetU32('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.usage) }}}, + }; + var labelPtr = {{{ makeGetValue('descriptor', C_STRUCTS.WGPUSwapChainDescriptor.label, '*') }}}; + if (labelPtr) desc["label"] = UTF8ToString(labelPtr); + var swapChain = ctx["configureSwapChain"](desc); + + return WebGPU.mgrSwapChain.create(swapChain); + }, + wgpuSwapChainGetCurrentTextureView: function(swapChainId) { + var swapChain = WebGPU.mgrSwapChain.get(swapChainId); + return WebGPU.mgrTextureView.create(swapChain["getCurrentTexture"]()["createView"]()); + }, + + // Unsupported (won't be implemented) + + wgpuDeviceTick: function() { + assert(false, 'wgpuDeviceTick is unsupported (use requestAnimationFrame via html5.h instead)'); + }, + wgpuSwapChainPresent: function() { + assert(false, 'wgpuSwapChainPresent is unsupported (use requestAnimationFrame via html5.h instead)'); + }, +}; + +autoAddDeps(LibraryWebGPU, '$WebGPU'); +mergeInto(LibraryManager.library, LibraryWebGPU); diff --git a/src/modules.js b/src/modules.js index 915d25541f1f..fb83f46446b8 100644 --- a/src/modules.js +++ b/src/modules.js @@ -142,6 +142,10 @@ var LibraryManager = { libraries.push('library_glemu.js'); } + if (USE_WEBGPU) { + libraries.push('library_webgpu.js'); + } + if (BOOTSTRAPPING_STRUCT_INFO) libraries = ['library_bootstrap_structInfo.js', 'library_formatString.js']; // TODO: deduplicate libraries (not needed for correctness, but avoids unnecessary work) diff --git a/src/settings.js b/src/settings.js index 28fdcb58b677..79fd318c6c22 100644 --- a/src/settings.js +++ b/src/settings.js @@ -499,6 +499,9 @@ var GL_FFP_ONLY = 0; // WebGL initialization afterwards will use this GL context to render. var GL_PREINITIALIZED_CONTEXT = 0; +// Enables support for WebGPU (via "webgpu/webgpu.h"). +var USE_WEBGPU = 0; + // Enables building of stb-image, a tiny public-domain library for decoding // images, allowing decoding of images without using the browser's built-in // decoders. The benefit is that this can be done synchronously, however, it diff --git a/src/struct_info.json b/src/struct_info.json index f52d024a2da8..53f8add4ae67 100644 --- a/src/struct_info.json +++ b/src/struct_info.json @@ -1648,5 +1648,303 @@ ] }, "defines": [] + }, + // =========================================== + // WebGPU + // This is auto-generated: + // https://dawn.googlesource.com/dawn/+/refs/heads/master/generator/templates/api_struct_info.json + // =========================================== + { + "file": "webgpu/webgpu.h", + "defines": [], + "structs": { + "WGPUChainedStruct": [ + "nextInChain", + "sType" + ], + "WGPUAdapterProperties": [ + "nextInChain", + "deviceID", + "vendorID", + "name", + "adapterType", + "backendType" + ], + "WGPUBindGroupBinding": [ + "binding", + "buffer", + "offset", + "size", + "sampler", + "textureView" + ], + "WGPUBindGroupLayoutBinding": [ + "binding", + "visibility", + "type", + "hasDynamicOffset", + "multisampled", + "textureDimension", + "textureComponentType" + ], + "WGPUBlendDescriptor": [ + "operation", + "srcFactor", + "dstFactor" + ], + "WGPUBufferCopyView": [ + "nextInChain", + "buffer", + "offset", + "rowPitch", + "imageHeight" + ], + "WGPUBufferDescriptor": [ + "nextInChain", + "label", + "usage", + "size" + ], + "WGPUColor": [ + "r", + "g", + "b", + "a" + ], + "WGPUCommandBufferDescriptor": [ + "nextInChain", + "label" + ], + "WGPUCommandEncoderDescriptor": [ + "nextInChain", + "label" + ], + "WGPUComputePassDescriptor": [ + "nextInChain", + "label" + ], + "WGPUCreateBufferMappedResult": [ + "buffer", + "dataLength", + "data" + ], + "WGPUDeviceProperties": [ + "textureCompressionBC" + ], + "WGPUExtent3D": [ + "width", + "height", + "depth" + ], + "WGPUFenceDescriptor": [ + "nextInChain", + "label", + "initialValue" + ], + "WGPUInstanceDescriptor": [ + "nextInChain" + ], + "WGPUOrigin3D": [ + "x", + "y", + "z" + ], + "WGPUPipelineLayoutDescriptor": [ + "nextInChain", + "label", + "bindGroupLayoutCount", + "bindGroupLayouts" + ], + "WGPUProgrammableStageDescriptor": [ + "nextInChain", + "module", + "entryPoint" + ], + "WGPURasterizationStateDescriptor": [ + "nextInChain", + "frontFace", + "cullMode", + "depthBias", + "depthBiasSlopeScale", + "depthBiasClamp" + ], + "WGPURenderBundleDescriptor": [ + "nextInChain", + "label" + ], + "WGPURenderBundleEncoderDescriptor": [ + "nextInChain", + "label", + "colorFormatsCount", + "colorFormats", + "depthStencilFormat", + "sampleCount" + ], + "WGPURenderPassDepthStencilAttachmentDescriptor": [ + "attachment", + "depthLoadOp", + "depthStoreOp", + "clearDepth", + "stencilLoadOp", + "stencilStoreOp", + "clearStencil" + ], + "WGPUSamplerDescriptor": [ + "nextInChain", + "label", + "addressModeU", + "addressModeV", + "addressModeW", + "magFilter", + "minFilter", + "mipmapFilter", + "lodMinClamp", + "lodMaxClamp", + "compare" + ], + "WGPUShaderModuleDescriptor": [ + "nextInChain", + "label", + "codeSize", + "code" + ], + "WGPUStencilStateFaceDescriptor": [ + "compare", + "failOp", + "depthFailOp", + "passOp" + ], + "WGPUSurfaceDescriptor": [ + "nextInChain", + "label" + ], + "WGPUSurfaceDescriptorFromHTMLCanvasId": [ + "nextInChain", + "sType", + "id" + ], + "WGPUSwapChainDescriptor": [ + "nextInChain", + "label", + "usage", + "format", + "width", + "height", + "presentMode", + "implementation" + ], + "WGPUTextureViewDescriptor": [ + "nextInChain", + "label", + "format", + "dimension", + "baseMipLevel", + "mipLevelCount", + "baseArrayLayer", + "arrayLayerCount", + "aspect" + ], + "WGPUVertexAttributeDescriptor": [ + "format", + "offset", + "shaderLocation" + ], + "WGPUBindGroupDescriptor": [ + "nextInChain", + "label", + "layout", + "bindingCount", + "bindings" + ], + "WGPUBindGroupLayoutDescriptor": [ + "nextInChain", + "label", + "bindingCount", + "bindings" + ], + "WGPUColorStateDescriptor": [ + "nextInChain", + "format", + "alphaBlend", + "colorBlend", + "writeMask" + ], + "WGPUComputePipelineDescriptor": [ + "nextInChain", + "label", + "layout", + "computeStage" + ], + "WGPUDepthStencilStateDescriptor": [ + "nextInChain", + "format", + "depthWriteEnabled", + "depthCompare", + "stencilFront", + "stencilBack", + "stencilReadMask", + "stencilWriteMask" + ], + "WGPURenderPassColorAttachmentDescriptor": [ + "attachment", + "resolveTarget", + "loadOp", + "storeOp", + "clearColor" + ], + "WGPUTextureCopyView": [ + "nextInChain", + "texture", + "mipLevel", + "arrayLayer", + "origin" + ], + "WGPUTextureDescriptor": [ + "nextInChain", + "label", + "usage", + "dimension", + "size", + "arrayLayerCount", + "format", + "mipLevelCount", + "sampleCount" + ], + "WGPUVertexBufferLayoutDescriptor": [ + "arrayStride", + "stepMode", + "attributeCount", + "attributes" + ], + "WGPURenderPassDescriptor": [ + "nextInChain", + "label", + "colorAttachmentCount", + "colorAttachments", + "depthStencilAttachment" + ], + "WGPUVertexStateDescriptor": [ + "nextInChain", + "indexFormat", + "vertexBufferCount", + "vertexBuffers" + ], + "WGPURenderPipelineDescriptor": [ + "nextInChain", + "label", + "layout", + "vertexStage", + "fragmentStage", + "vertexState", + "primitiveTopology", + "rasterizationState", + "sampleCount", + "depthStencilState", + "colorStateCount", + "colorStates", + "sampleMask", + "alphaToCoverageEnabled" + ] + } } - ] +] diff --git a/system/include/emscripten/html5.h b/system/include/emscripten/html5.h index d80154813cdc..0c8a7d89f02d 100644 --- a/system/include/emscripten/html5.h +++ b/system/include/emscripten/html5.h @@ -500,6 +500,9 @@ extern void *emscripten_webgl2_get_proc_address(const char *name); // Combines emscripten_webgl1_get_proc_address() and emscripten_webgl2_get_proc_address() to return function pointers to both WebGL1 and WebGL2 functions. Same drawbacks apply. extern void *emscripten_webgl_get_proc_address(const char *name); +typedef struct WGPUDeviceImpl* WGPUDevice; +extern WGPUDevice emscripten_webgpu_get_device(); + extern EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height); extern EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height); diff --git a/system/include/webgpu/webgpu.h b/system/include/webgpu/webgpu.h new file mode 100644 index 000000000000..aea7a6bb9614 --- /dev/null +++ b/system/include/webgpu/webgpu.h @@ -0,0 +1,1168 @@ +// BSD 3-Clause License +// +// Copyright (c) 2019, "WebGPU native" developers +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#ifndef WEBGPU_H_ +#define WEBGPU_H_ + +#if defined(WGPU_SHARED_LIBRARY) +# if defined(_WIN32) +# if defined(WGPU_IMPLEMENTATION) +# define WGPU_EXPORT __declspec(dllexport) +# else +# define WGPU_EXPORT __declspec(dllimport) +# endif +# else // defined(_WIN32) +# if defined(WGPU_IMPLEMENTATION) +# define WGPU_EXPORT __attribute__((visibility("default"))) +# else +# define WGPU_EXPORT +# endif +# endif // defined(_WIN32) +#else // defined(WGPU_SHARED_LIBRARY) +# define WGPU_EXPORT +#endif // defined(WGPU_SHARED_LIBRARY) + +#include +#include +#include + +const uint64_t WGPU_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX + +typedef uint32_t WGPUFlags; + +typedef struct WGPUBindGroupImpl* WGPUBindGroup; +typedef struct WGPUBindGroupLayoutImpl* WGPUBindGroupLayout; +typedef struct WGPUBufferImpl* WGPUBuffer; +typedef struct WGPUCommandBufferImpl* WGPUCommandBuffer; +typedef struct WGPUCommandEncoderImpl* WGPUCommandEncoder; +typedef struct WGPUComputePassEncoderImpl* WGPUComputePassEncoder; +typedef struct WGPUComputePipelineImpl* WGPUComputePipeline; +typedef struct WGPUDeviceImpl* WGPUDevice; +typedef struct WGPUFenceImpl* WGPUFence; +typedef struct WGPUInstanceImpl* WGPUInstance; +typedef struct WGPUPipelineLayoutImpl* WGPUPipelineLayout; +typedef struct WGPUQueueImpl* WGPUQueue; +typedef struct WGPURenderBundleImpl* WGPURenderBundle; +typedef struct WGPURenderBundleEncoderImpl* WGPURenderBundleEncoder; +typedef struct WGPURenderPassEncoderImpl* WGPURenderPassEncoder; +typedef struct WGPURenderPipelineImpl* WGPURenderPipeline; +typedef struct WGPUSamplerImpl* WGPUSampler; +typedef struct WGPUShaderModuleImpl* WGPUShaderModule; +typedef struct WGPUSurfaceImpl* WGPUSurface; +typedef struct WGPUSwapChainImpl* WGPUSwapChain; +typedef struct WGPUTextureImpl* WGPUTexture; +typedef struct WGPUTextureViewImpl* WGPUTextureView; + +typedef enum WGPUAdapterType { + WGPUAdapterType_DiscreteGPU = 0x00000000, + WGPUAdapterType_IntegratedGPU = 0x00000001, + WGPUAdapterType_CPU = 0x00000002, + WGPUAdapterType_Unknown = 0x00000003, + WGPUAdapterType_Force32 = 0x7FFFFFFF +} WGPUAdapterType; + +typedef enum WGPUAddressMode { + WGPUAddressMode_Repeat = 0x00000000, + WGPUAddressMode_MirrorRepeat = 0x00000001, + WGPUAddressMode_ClampToEdge = 0x00000002, + WGPUAddressMode_Force32 = 0x7FFFFFFF +} WGPUAddressMode; + +typedef enum WGPUBackendType { + WGPUBackendType_Null = 0x00000000, + WGPUBackendType_D3D11 = 0x00000001, + WGPUBackendType_D3D12 = 0x00000002, + WGPUBackendType_Metal = 0x00000003, + WGPUBackendType_Vulkan = 0x00000004, + WGPUBackendType_OpenGL = 0x00000005, + WGPUBackendType_OpenGLES = 0x00000006, + WGPUBackendType_Force32 = 0x7FFFFFFF +} WGPUBackendType; + +typedef enum WGPUBindingType { + WGPUBindingType_UniformBuffer = 0x00000000, + WGPUBindingType_StorageBuffer = 0x00000001, + WGPUBindingType_ReadonlyStorageBuffer = 0x00000002, + WGPUBindingType_Sampler = 0x00000003, + WGPUBindingType_SampledTexture = 0x00000004, + WGPUBindingType_StorageTexture = 0x00000005, + WGPUBindingType_Force32 = 0x7FFFFFFF +} WGPUBindingType; + +typedef enum WGPUBlendFactor { + WGPUBlendFactor_Zero = 0x00000000, + WGPUBlendFactor_One = 0x00000001, + WGPUBlendFactor_SrcColor = 0x00000002, + WGPUBlendFactor_OneMinusSrcColor = 0x00000003, + WGPUBlendFactor_SrcAlpha = 0x00000004, + WGPUBlendFactor_OneMinusSrcAlpha = 0x00000005, + WGPUBlendFactor_DstColor = 0x00000006, + WGPUBlendFactor_OneMinusDstColor = 0x00000007, + WGPUBlendFactor_DstAlpha = 0x00000008, + WGPUBlendFactor_OneMinusDstAlpha = 0x00000009, + WGPUBlendFactor_SrcAlphaSaturated = 0x0000000A, + WGPUBlendFactor_BlendColor = 0x0000000B, + WGPUBlendFactor_OneMinusBlendColor = 0x0000000C, + WGPUBlendFactor_Force32 = 0x7FFFFFFF +} WGPUBlendFactor; + +typedef enum WGPUBlendOperation { + WGPUBlendOperation_Add = 0x00000000, + WGPUBlendOperation_Subtract = 0x00000001, + WGPUBlendOperation_ReverseSubtract = 0x00000002, + WGPUBlendOperation_Min = 0x00000003, + WGPUBlendOperation_Max = 0x00000004, + WGPUBlendOperation_Force32 = 0x7FFFFFFF +} WGPUBlendOperation; + +typedef enum WGPUBufferMapAsyncStatus { + WGPUBufferMapAsyncStatus_Success = 0x00000000, + WGPUBufferMapAsyncStatus_Error = 0x00000001, + WGPUBufferMapAsyncStatus_Unknown = 0x00000002, + WGPUBufferMapAsyncStatus_DeviceLost = 0x00000003, + WGPUBufferMapAsyncStatus_Force32 = 0x7FFFFFFF +} WGPUBufferMapAsyncStatus; + +typedef enum WGPUCompareFunction { + WGPUCompareFunction_Never = 0x00000000, + WGPUCompareFunction_Less = 0x00000001, + WGPUCompareFunction_LessEqual = 0x00000002, + WGPUCompareFunction_Greater = 0x00000003, + WGPUCompareFunction_GreaterEqual = 0x00000004, + WGPUCompareFunction_Equal = 0x00000005, + WGPUCompareFunction_NotEqual = 0x00000006, + WGPUCompareFunction_Always = 0x00000007, + WGPUCompareFunction_Force32 = 0x7FFFFFFF +} WGPUCompareFunction; + +typedef enum WGPUCullMode { + WGPUCullMode_None = 0x00000000, + WGPUCullMode_Front = 0x00000001, + WGPUCullMode_Back = 0x00000002, + WGPUCullMode_Force32 = 0x7FFFFFFF +} WGPUCullMode; + +typedef enum WGPUErrorFilter { + WGPUErrorFilter_None = 0x00000000, + WGPUErrorFilter_Validation = 0x00000001, + WGPUErrorFilter_OutOfMemory = 0x00000002, + WGPUErrorFilter_Force32 = 0x7FFFFFFF +} WGPUErrorFilter; + +typedef enum WGPUErrorType { + WGPUErrorType_NoError = 0x00000000, + WGPUErrorType_Validation = 0x00000001, + WGPUErrorType_OutOfMemory = 0x00000002, + WGPUErrorType_Unknown = 0x00000003, + WGPUErrorType_DeviceLost = 0x00000004, + WGPUErrorType_Force32 = 0x7FFFFFFF +} WGPUErrorType; + +typedef enum WGPUFenceCompletionStatus { + WGPUFenceCompletionStatus_Success = 0x00000000, + WGPUFenceCompletionStatus_Error = 0x00000001, + WGPUFenceCompletionStatus_Unknown = 0x00000002, + WGPUFenceCompletionStatus_DeviceLost = 0x00000003, + WGPUFenceCompletionStatus_Force32 = 0x7FFFFFFF +} WGPUFenceCompletionStatus; + +typedef enum WGPUFilterMode { + WGPUFilterMode_Nearest = 0x00000000, + WGPUFilterMode_Linear = 0x00000001, + WGPUFilterMode_Force32 = 0x7FFFFFFF +} WGPUFilterMode; + +typedef enum WGPUFrontFace { + WGPUFrontFace_CCW = 0x00000000, + WGPUFrontFace_CW = 0x00000001, + WGPUFrontFace_Force32 = 0x7FFFFFFF +} WGPUFrontFace; + +typedef enum WGPUIndexFormat { + WGPUIndexFormat_Uint16 = 0x00000000, + WGPUIndexFormat_Uint32 = 0x00000001, + WGPUIndexFormat_Force32 = 0x7FFFFFFF +} WGPUIndexFormat; + +typedef enum WGPUInputStepMode { + WGPUInputStepMode_Vertex = 0x00000000, + WGPUInputStepMode_Instance = 0x00000001, + WGPUInputStepMode_Force32 = 0x7FFFFFFF +} WGPUInputStepMode; + +typedef enum WGPULoadOp { + WGPULoadOp_Clear = 0x00000000, + WGPULoadOp_Load = 0x00000001, + WGPULoadOp_Force32 = 0x7FFFFFFF +} WGPULoadOp; + +typedef enum WGPUPresentMode { + WGPUPresentMode_NoVSync = 0x00000000, + WGPUPresentMode_VSync = 0x00000001, + WGPUPresentMode_Force32 = 0x7FFFFFFF +} WGPUPresentMode; + +typedef enum WGPUPrimitiveTopology { + WGPUPrimitiveTopology_PointList = 0x00000000, + WGPUPrimitiveTopology_LineList = 0x00000001, + WGPUPrimitiveTopology_LineStrip = 0x00000002, + WGPUPrimitiveTopology_TriangleList = 0x00000003, + WGPUPrimitiveTopology_TriangleStrip = 0x00000004, + WGPUPrimitiveTopology_Force32 = 0x7FFFFFFF +} WGPUPrimitiveTopology; + +typedef enum WGPUSType { + WGPUSType_Invalid = 0x00000000, + WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001, + WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002, + WGPUSType_SurfaceDescriptorFromXlib = 0x00000003, + WGPUSType_SurfaceDescriptorFromHTMLCanvasId = 0x00000004, + WGPUSType_Force32 = 0x7FFFFFFF +} WGPUSType; + +typedef enum WGPUStencilOperation { + WGPUStencilOperation_Keep = 0x00000000, + WGPUStencilOperation_Zero = 0x00000001, + WGPUStencilOperation_Replace = 0x00000002, + WGPUStencilOperation_Invert = 0x00000003, + WGPUStencilOperation_IncrementClamp = 0x00000004, + WGPUStencilOperation_DecrementClamp = 0x00000005, + WGPUStencilOperation_IncrementWrap = 0x00000006, + WGPUStencilOperation_DecrementWrap = 0x00000007, + WGPUStencilOperation_Force32 = 0x7FFFFFFF +} WGPUStencilOperation; + +typedef enum WGPUStoreOp { + WGPUStoreOp_Store = 0x00000000, + WGPUStoreOp_Clear = 0x00000001, + WGPUStoreOp_Force32 = 0x7FFFFFFF +} WGPUStoreOp; + +typedef enum WGPUTextureAspect { + WGPUTextureAspect_All = 0x00000000, + WGPUTextureAspect_StencilOnly = 0x00000001, + WGPUTextureAspect_DepthOnly = 0x00000002, + WGPUTextureAspect_Force32 = 0x7FFFFFFF +} WGPUTextureAspect; + +typedef enum WGPUTextureComponentType { + WGPUTextureComponentType_Float = 0x00000000, + WGPUTextureComponentType_Sint = 0x00000001, + WGPUTextureComponentType_Uint = 0x00000002, + WGPUTextureComponentType_Force32 = 0x7FFFFFFF +} WGPUTextureComponentType; + +typedef enum WGPUTextureDimension { + WGPUTextureDimension_1D = 0x00000000, + WGPUTextureDimension_2D = 0x00000001, + WGPUTextureDimension_3D = 0x00000002, + WGPUTextureDimension_Force32 = 0x7FFFFFFF +} WGPUTextureDimension; + +typedef enum WGPUTextureFormat { + WGPUTextureFormat_Undefined = 0x00000000, + WGPUTextureFormat_R8Unorm = 0x00000001, + WGPUTextureFormat_R8Snorm = 0x00000002, + WGPUTextureFormat_R8Uint = 0x00000003, + WGPUTextureFormat_R8Sint = 0x00000004, + WGPUTextureFormat_R16Uint = 0x00000005, + WGPUTextureFormat_R16Sint = 0x00000006, + WGPUTextureFormat_R16Float = 0x00000007, + WGPUTextureFormat_RG8Unorm = 0x00000008, + WGPUTextureFormat_RG8Snorm = 0x00000009, + WGPUTextureFormat_RG8Uint = 0x0000000A, + WGPUTextureFormat_RG8Sint = 0x0000000B, + WGPUTextureFormat_R32Float = 0x0000000C, + WGPUTextureFormat_R32Uint = 0x0000000D, + WGPUTextureFormat_R32Sint = 0x0000000E, + WGPUTextureFormat_RG16Uint = 0x0000000F, + WGPUTextureFormat_RG16Sint = 0x00000010, + WGPUTextureFormat_RG16Float = 0x00000011, + WGPUTextureFormat_RGBA8Unorm = 0x00000012, + WGPUTextureFormat_RGBA8UnormSrgb = 0x00000013, + WGPUTextureFormat_RGBA8Snorm = 0x00000014, + WGPUTextureFormat_RGBA8Uint = 0x00000015, + WGPUTextureFormat_RGBA8Sint = 0x00000016, + 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_Force32 = 0x7FFFFFFF +} WGPUTextureFormat; + +typedef enum WGPUTextureViewDimension { + WGPUTextureViewDimension_Undefined = 0x00000000, + WGPUTextureViewDimension_1D = 0x00000001, + WGPUTextureViewDimension_2D = 0x00000002, + WGPUTextureViewDimension_2DArray = 0x00000003, + WGPUTextureViewDimension_Cube = 0x00000004, + WGPUTextureViewDimension_CubeArray = 0x00000005, + WGPUTextureViewDimension_3D = 0x00000006, + WGPUTextureViewDimension_Force32 = 0x7FFFFFFF +} WGPUTextureViewDimension; + +typedef enum WGPUVertexFormat { + WGPUVertexFormat_UChar2 = 0x00000000, + WGPUVertexFormat_UChar4 = 0x00000001, + WGPUVertexFormat_Char2 = 0x00000002, + WGPUVertexFormat_Char4 = 0x00000003, + WGPUVertexFormat_UChar2Norm = 0x00000004, + WGPUVertexFormat_UChar4Norm = 0x00000005, + WGPUVertexFormat_Char2Norm = 0x00000006, + WGPUVertexFormat_Char4Norm = 0x00000007, + WGPUVertexFormat_UShort2 = 0x00000008, + WGPUVertexFormat_UShort4 = 0x00000009, + WGPUVertexFormat_Short2 = 0x0000000A, + WGPUVertexFormat_Short4 = 0x0000000B, + WGPUVertexFormat_UShort2Norm = 0x0000000C, + WGPUVertexFormat_UShort4Norm = 0x0000000D, + WGPUVertexFormat_Short2Norm = 0x0000000E, + WGPUVertexFormat_Short4Norm = 0x0000000F, + WGPUVertexFormat_Half2 = 0x00000010, + WGPUVertexFormat_Half4 = 0x00000011, + WGPUVertexFormat_Float = 0x00000012, + WGPUVertexFormat_Float2 = 0x00000013, + WGPUVertexFormat_Float3 = 0x00000014, + WGPUVertexFormat_Float4 = 0x00000015, + WGPUVertexFormat_UInt = 0x00000016, + WGPUVertexFormat_UInt2 = 0x00000017, + WGPUVertexFormat_UInt3 = 0x00000018, + WGPUVertexFormat_UInt4 = 0x00000019, + WGPUVertexFormat_Int = 0x0000001A, + WGPUVertexFormat_Int2 = 0x0000001B, + WGPUVertexFormat_Int3 = 0x0000001C, + WGPUVertexFormat_Int4 = 0x0000001D, + WGPUVertexFormat_Force32 = 0x7FFFFFFF +} WGPUVertexFormat; + +typedef enum WGPUBufferUsage { + WGPUBufferUsage_None = 0x00000000, + WGPUBufferUsage_MapRead = 0x00000001, + WGPUBufferUsage_MapWrite = 0x00000002, + WGPUBufferUsage_CopySrc = 0x00000004, + WGPUBufferUsage_CopyDst = 0x00000008, + WGPUBufferUsage_Index = 0x00000010, + WGPUBufferUsage_Vertex = 0x00000020, + WGPUBufferUsage_Uniform = 0x00000040, + WGPUBufferUsage_Storage = 0x00000080, + WGPUBufferUsage_Indirect = 0x00000100, + WGPUBufferUsage_Force32 = 0x7FFFFFFF +} WGPUBufferUsage; +typedef WGPUFlags WGPUBufferUsageFlags; + +typedef enum WGPUColorWriteMask { + WGPUColorWriteMask_None = 0x00000000, + WGPUColorWriteMask_Red = 0x00000001, + WGPUColorWriteMask_Green = 0x00000002, + WGPUColorWriteMask_Blue = 0x00000004, + WGPUColorWriteMask_Alpha = 0x00000008, + WGPUColorWriteMask_All = 0x0000000F, + WGPUColorWriteMask_Force32 = 0x7FFFFFFF +} WGPUColorWriteMask; +typedef WGPUFlags WGPUColorWriteMaskFlags; + +typedef enum WGPUShaderStage { + WGPUShaderStage_None = 0x00000000, + WGPUShaderStage_Vertex = 0x00000001, + WGPUShaderStage_Fragment = 0x00000002, + WGPUShaderStage_Compute = 0x00000004, + WGPUShaderStage_Force32 = 0x7FFFFFFF +} WGPUShaderStage; +typedef WGPUFlags WGPUShaderStageFlags; + +typedef enum WGPUTextureUsage { + WGPUTextureUsage_None = 0x00000000, + WGPUTextureUsage_CopySrc = 0x00000001, + WGPUTextureUsage_CopyDst = 0x00000002, + WGPUTextureUsage_Sampled = 0x00000004, + WGPUTextureUsage_Storage = 0x00000008, + WGPUTextureUsage_OutputAttachment = 0x00000010, + WGPUTextureUsage_Present = 0x00000020, + WGPUTextureUsage_Force32 = 0x7FFFFFFF +} WGPUTextureUsage; +typedef WGPUFlags WGPUTextureUsageFlags; + + +typedef struct WGPUChainedStruct { + struct WGPUChainedStruct const * nextInChain; + WGPUSType sType; +} WGPUChainedStruct; + +typedef struct WGPUAdapterProperties { + WGPUChainedStruct const * nextInChain; + uint32_t deviceID; + uint32_t vendorID; + char const * name; + WGPUAdapterType adapterType; + WGPUBackendType backendType; +} WGPUAdapterProperties; + +typedef struct WGPUBindGroupBinding { + uint32_t binding; + WGPUBuffer buffer; + uint64_t offset; + uint64_t size; + WGPUSampler sampler; + WGPUTextureView textureView; +} WGPUBindGroupBinding; + +typedef struct WGPUBindGroupLayoutBinding { + uint32_t binding; + WGPUShaderStageFlags visibility; + WGPUBindingType type; + bool hasDynamicOffset; + bool multisampled; + WGPUTextureViewDimension textureDimension; + WGPUTextureComponentType textureComponentType; +} WGPUBindGroupLayoutBinding; + +typedef struct WGPUBlendDescriptor { + WGPUBlendOperation operation; + WGPUBlendFactor srcFactor; + WGPUBlendFactor dstFactor; +} WGPUBlendDescriptor; + +typedef struct WGPUBufferCopyView { + WGPUChainedStruct const * nextInChain; + WGPUBuffer buffer; + uint64_t offset; + uint32_t rowPitch; + uint32_t imageHeight; +} WGPUBufferCopyView; + +typedef struct WGPUBufferDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUBufferUsageFlags usage; + uint64_t size; +} WGPUBufferDescriptor; + +typedef struct WGPUColor { + float r; + float g; + float b; + float a; +} WGPUColor; + +typedef struct WGPUCommandBufferDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; +} WGPUCommandBufferDescriptor; + +typedef struct WGPUCommandEncoderDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; +} WGPUCommandEncoderDescriptor; + +typedef struct WGPUComputePassDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; +} WGPUComputePassDescriptor; + +typedef struct WGPUCreateBufferMappedResult { + WGPUBuffer buffer; + uint64_t dataLength; + void * data; +} WGPUCreateBufferMappedResult; + +typedef struct WGPUDeviceProperties { + bool textureCompressionBC; +} WGPUDeviceProperties; + +typedef struct WGPUExtent3D { + uint32_t width; + uint32_t height; + uint32_t depth; +} WGPUExtent3D; + +typedef struct WGPUFenceDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint64_t initialValue; +} WGPUFenceDescriptor; + +typedef struct WGPUInstanceDescriptor { + WGPUChainedStruct const * nextInChain; +} WGPUInstanceDescriptor; + +typedef struct WGPUOrigin3D { + uint32_t x; + uint32_t y; + uint32_t z; +} WGPUOrigin3D; + +typedef struct WGPUPipelineLayoutDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint32_t bindGroupLayoutCount; + WGPUBindGroupLayout const * bindGroupLayouts; +} WGPUPipelineLayoutDescriptor; + +typedef struct WGPUProgrammableStageDescriptor { + WGPUChainedStruct const * nextInChain; + WGPUShaderModule module; + char const * entryPoint; +} WGPUProgrammableStageDescriptor; + +typedef struct WGPURasterizationStateDescriptor { + WGPUChainedStruct const * nextInChain; + WGPUFrontFace frontFace; + WGPUCullMode cullMode; + int32_t depthBias; + float depthBiasSlopeScale; + float depthBiasClamp; +} WGPURasterizationStateDescriptor; + +typedef struct WGPURenderBundleDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; +} WGPURenderBundleDescriptor; + +typedef struct WGPURenderBundleEncoderDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint32_t colorFormatsCount; + WGPUTextureFormat const * colorFormats; + WGPUTextureFormat depthStencilFormat; + uint32_t sampleCount; +} WGPURenderBundleEncoderDescriptor; + +typedef struct WGPURenderPassDepthStencilAttachmentDescriptor { + WGPUTextureView attachment; + WGPULoadOp depthLoadOp; + WGPUStoreOp depthStoreOp; + float clearDepth; + WGPULoadOp stencilLoadOp; + WGPUStoreOp stencilStoreOp; + uint32_t clearStencil; +} WGPURenderPassDepthStencilAttachmentDescriptor; + +typedef struct WGPUSamplerDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUAddressMode addressModeU; + WGPUAddressMode addressModeV; + WGPUAddressMode addressModeW; + WGPUFilterMode magFilter; + WGPUFilterMode minFilter; + WGPUFilterMode mipmapFilter; + float lodMinClamp; + float lodMaxClamp; + WGPUCompareFunction compare; +} WGPUSamplerDescriptor; + +typedef struct WGPUShaderModuleDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint32_t codeSize; + uint32_t const * code; +} WGPUShaderModuleDescriptor; + +typedef struct WGPUStencilStateFaceDescriptor { + WGPUCompareFunction compare; + WGPUStencilOperation failOp; + WGPUStencilOperation depthFailOp; + WGPUStencilOperation passOp; +} WGPUStencilStateFaceDescriptor; + +typedef struct WGPUSurfaceDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; +} WGPUSurfaceDescriptor; + +typedef struct WGPUSurfaceDescriptorFromHTMLCanvasId { + WGPUChainedStruct const * nextInChain; + WGPUSType sType; + char const * id; +} WGPUSurfaceDescriptorFromHTMLCanvasId; + +typedef struct WGPUSurfaceDescriptorFromMetalLayer { + WGPUChainedStruct const * nextInChain; + WGPUSType sType; + void * layer; +} WGPUSurfaceDescriptorFromMetalLayer; + +typedef struct WGPUSurfaceDescriptorFromWindowsHWND { + WGPUChainedStruct const * nextInChain; + WGPUSType sType; + void * hinstance; + void * hwnd; +} WGPUSurfaceDescriptorFromWindowsHWND; + +typedef struct WGPUSurfaceDescriptorFromXlib { + WGPUChainedStruct const * nextInChain; + WGPUSType sType; + void * display; + uint32_t window; +} WGPUSurfaceDescriptorFromXlib; + +typedef struct WGPUSwapChainDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUTextureUsageFlags usage; + WGPUTextureFormat format; + uint32_t width; + uint32_t height; + WGPUPresentMode presentMode; + uint64_t implementation; +} WGPUSwapChainDescriptor; + +typedef struct WGPUTextureViewDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUTextureFormat format; + WGPUTextureViewDimension dimension; + uint32_t baseMipLevel; + uint32_t mipLevelCount; + uint32_t baseArrayLayer; + uint32_t arrayLayerCount; + WGPUTextureAspect aspect; +} WGPUTextureViewDescriptor; + +typedef struct WGPUVertexAttributeDescriptor { + WGPUVertexFormat format; + uint64_t offset; + uint32_t shaderLocation; +} WGPUVertexAttributeDescriptor; + +typedef struct WGPUBindGroupDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUBindGroupLayout layout; + uint32_t bindingCount; + WGPUBindGroupBinding const * bindings; +} WGPUBindGroupDescriptor; + +typedef struct WGPUBindGroupLayoutDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint32_t bindingCount; + WGPUBindGroupLayoutBinding const * bindings; +} WGPUBindGroupLayoutDescriptor; + +typedef struct WGPUColorStateDescriptor { + WGPUChainedStruct const * nextInChain; + WGPUTextureFormat format; + WGPUBlendDescriptor alphaBlend; + WGPUBlendDescriptor colorBlend; + WGPUColorWriteMaskFlags writeMask; +} WGPUColorStateDescriptor; + +typedef struct WGPUComputePipelineDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUPipelineLayout layout; + WGPUProgrammableStageDescriptor computeStage; +} WGPUComputePipelineDescriptor; + +typedef struct WGPUDepthStencilStateDescriptor { + WGPUChainedStruct const * nextInChain; + WGPUTextureFormat format; + bool depthWriteEnabled; + WGPUCompareFunction depthCompare; + WGPUStencilStateFaceDescriptor stencilFront; + WGPUStencilStateFaceDescriptor stencilBack; + uint32_t stencilReadMask; + uint32_t stencilWriteMask; +} WGPUDepthStencilStateDescriptor; + +typedef struct WGPURenderPassColorAttachmentDescriptor { + WGPUTextureView attachment; + WGPUTextureView resolveTarget; + WGPULoadOp loadOp; + WGPUStoreOp storeOp; + WGPUColor clearColor; +} WGPURenderPassColorAttachmentDescriptor; + +typedef struct WGPUTextureCopyView { + WGPUChainedStruct const * nextInChain; + WGPUTexture texture; + uint32_t mipLevel; + uint32_t arrayLayer; + WGPUOrigin3D origin; +} WGPUTextureCopyView; + +typedef struct WGPUTextureDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUTextureUsageFlags usage; + WGPUTextureDimension dimension; + WGPUExtent3D size; + uint32_t arrayLayerCount; + WGPUTextureFormat format; + uint32_t mipLevelCount; + uint32_t sampleCount; +} WGPUTextureDescriptor; + +typedef struct WGPUVertexBufferLayoutDescriptor { + uint64_t arrayStride; + WGPUInputStepMode stepMode; + uint32_t attributeCount; + WGPUVertexAttributeDescriptor const * attributes; +} WGPUVertexBufferLayoutDescriptor; + +typedef struct WGPURenderPassDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + uint32_t colorAttachmentCount; + WGPURenderPassColorAttachmentDescriptor const * colorAttachments; + WGPURenderPassDepthStencilAttachmentDescriptor const * depthStencilAttachment; +} WGPURenderPassDescriptor; + +typedef struct WGPUVertexStateDescriptor { + WGPUChainedStruct const * nextInChain; + WGPUIndexFormat indexFormat; + uint32_t vertexBufferCount; + WGPUVertexBufferLayoutDescriptor const * vertexBuffers; +} WGPUVertexStateDescriptor; + +typedef struct WGPURenderPipelineDescriptor { + WGPUChainedStruct const * nextInChain; + char const * label; + WGPUPipelineLayout layout; + WGPUProgrammableStageDescriptor vertexStage; + WGPUProgrammableStageDescriptor const * fragmentStage; + WGPUVertexStateDescriptor const * vertexState; + WGPUPrimitiveTopology primitiveTopology; + WGPURasterizationStateDescriptor const * rasterizationState; + uint32_t sampleCount; + WGPUDepthStencilStateDescriptor const * depthStencilState; + uint32_t colorStateCount; + WGPUColorStateDescriptor const * colorStates; + uint32_t sampleMask; + bool alphaToCoverageEnabled; +} WGPURenderPipelineDescriptor; + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*WGPUBufferCreateMappedCallback)(WGPUBufferMapAsyncStatus status, WGPUCreateBufferMappedResult result, void * userdata); +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 (*WGPUDeviceLostCallback)(char const * message, void * userdata); +typedef void (*WGPUErrorCallback)(WGPUErrorType type, char const * message, void * userdata); +typedef void (*WGPUFenceOnCompletionCallback)(WGPUFenceCompletionStatus status, void * userdata); + +typedef void (*WGPUProc)(); + +#if !defined(WGPU_SKIP_PROCS) + +typedef WGPUInstance (*WGPUProcCreateInstance)(WGPUInstanceDescriptor const * descriptor); +typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procName); + +// Procs of BindGroup +typedef void (*WGPUProcBindGroupReference)(WGPUBindGroup bindGroup); +typedef void (*WGPUProcBindGroupRelease)(WGPUBindGroup bindGroup); + +// Procs of BindGroupLayout +typedef void (*WGPUProcBindGroupLayoutReference)(WGPUBindGroupLayout bindGroupLayout); +typedef void (*WGPUProcBindGroupLayoutRelease)(WGPUBindGroupLayout bindGroupLayout); + +// 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 (*WGPUProcBufferUnmap)(WGPUBuffer buffer); +typedef void (*WGPUProcBufferReference)(WGPUBuffer buffer); +typedef void (*WGPUProcBufferRelease)(WGPUBuffer buffer); + +// Procs of CommandBuffer +typedef void (*WGPUProcCommandBufferReference)(WGPUCommandBuffer commandBuffer); +typedef void (*WGPUProcCommandBufferRelease)(WGPUCommandBuffer commandBuffer); + +// Procs of CommandEncoder +typedef WGPUComputePassEncoder (*WGPUProcCommandEncoderBeginComputePass)(WGPUCommandEncoder commandEncoder, WGPUComputePassDescriptor const * descriptor); +typedef WGPURenderPassEncoder (*WGPUProcCommandEncoderBeginRenderPass)(WGPUCommandEncoder commandEncoder, WGPURenderPassDescriptor const * descriptor); +typedef void (*WGPUProcCommandEncoderCopyBufferToBuffer)(WGPUCommandEncoder commandEncoder, WGPUBuffer source, uint64_t sourceOffset, WGPUBuffer destination, uint64_t destinationOffset, uint64_t size); +typedef void (*WGPUProcCommandEncoderCopyBufferToTexture)(WGPUCommandEncoder commandEncoder, WGPUBufferCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize); +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 (*WGPUProcCommandEncoderPopDebugGroup)(WGPUCommandEncoder commandEncoder); +typedef void (*WGPUProcCommandEncoderPushDebugGroup)(WGPUCommandEncoder commandEncoder, char const * groupLabel); +typedef void (*WGPUProcCommandEncoderReference)(WGPUCommandEncoder commandEncoder); +typedef void (*WGPUProcCommandEncoderRelease)(WGPUCommandEncoder commandEncoder); + +// Procs of ComputePassEncoder +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 (*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 (*WGPUProcComputePassEncoderReference)(WGPUComputePassEncoder computePassEncoder); +typedef void (*WGPUProcComputePassEncoderRelease)(WGPUComputePassEncoder computePassEncoder); + +// Procs of ComputePipeline +typedef WGPUBindGroupLayout (*WGPUProcComputePipelineGetBindGroupLayout)(WGPUComputePipeline computePipeline, uint32_t group); +typedef void (*WGPUProcComputePipelineReference)(WGPUComputePipeline computePipeline); +typedef void (*WGPUProcComputePipelineRelease)(WGPUComputePipeline computePipeline); + +// Procs of Device +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 void (*WGPUProcDeviceCreateBufferMappedAsync)(WGPUDevice device, WGPUBufferDescriptor const * descriptor, WGPUBufferCreateMappedCallback callback, void * userdata); +typedef WGPUCommandEncoder (*WGPUProcDeviceCreateCommandEncoder)(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor); +typedef WGPUComputePipeline (*WGPUProcDeviceCreateComputePipeline)(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor); +typedef WGPUPipelineLayout (*WGPUProcDeviceCreatePipelineLayout)(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor); +typedef WGPUQueue (*WGPUProcDeviceCreateQueue)(WGPUDevice device); +typedef WGPURenderBundleEncoder (*WGPUProcDeviceCreateRenderBundleEncoder)(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor); +typedef WGPURenderPipeline (*WGPUProcDeviceCreateRenderPipeline)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor); +typedef WGPUSampler (*WGPUProcDeviceCreateSampler)(WGPUDevice device, WGPUSamplerDescriptor const * descriptor); +typedef WGPUShaderModule (*WGPUProcDeviceCreateShaderModule)(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor); +typedef WGPUSwapChain (*WGPUProcDeviceCreateSwapChain)(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor); +typedef WGPUTexture (*WGPUProcDeviceCreateTexture)(WGPUDevice device, WGPUTextureDescriptor const * descriptor); +typedef void (*WGPUProcDeviceInjectError)(WGPUDevice device, WGPUErrorType type, char const * message); +typedef void (*WGPUProcDeviceLoseForTesting)(WGPUDevice device); +typedef bool (*WGPUProcDevicePopErrorScope)(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +typedef void (*WGPUProcDevicePushErrorScope)(WGPUDevice device, WGPUErrorFilter filter); +typedef void (*WGPUProcDeviceSetDeviceLostCallback)(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata); +typedef void (*WGPUProcDeviceSetUncapturedErrorCallback)(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +typedef void (*WGPUProcDeviceTick)(WGPUDevice device); +typedef void (*WGPUProcDeviceReference)(WGPUDevice device); +typedef void (*WGPUProcDeviceRelease)(WGPUDevice device); + +// Procs of Fence +typedef uint64_t (*WGPUProcFenceGetCompletedValue)(WGPUFence fence); +typedef void (*WGPUProcFenceOnCompletion)(WGPUFence fence, uint64_t value, WGPUFenceOnCompletionCallback callback, void * userdata); +typedef void (*WGPUProcFenceReference)(WGPUFence fence); +typedef void (*WGPUProcFenceRelease)(WGPUFence fence); + +// Procs of Instance +typedef WGPUSurface (*WGPUProcInstanceCreateSurface)(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor); +typedef void (*WGPUProcInstanceReference)(WGPUInstance instance); +typedef void (*WGPUProcInstanceRelease)(WGPUInstance instance); + +// Procs of PipelineLayout +typedef void (*WGPUProcPipelineLayoutReference)(WGPUPipelineLayout pipelineLayout); +typedef void (*WGPUProcPipelineLayoutRelease)(WGPUPipelineLayout pipelineLayout); + +// Procs of Queue +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 (*WGPUProcQueueReference)(WGPUQueue queue); +typedef void (*WGPUProcQueueRelease)(WGPUQueue queue); + +// Procs of RenderBundle +typedef void (*WGPUProcRenderBundleReference)(WGPURenderBundle renderBundle); +typedef void (*WGPUProcRenderBundleRelease)(WGPURenderBundle renderBundle); + +// Procs of RenderBundleEncoder +typedef void (*WGPUProcRenderBundleEncoderDraw)(WGPURenderBundleEncoder renderBundleEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +typedef void (*WGPUProcRenderBundleEncoderDrawIndexed)(WGPURenderBundleEncoder renderBundleEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance); +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 (*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); +typedef void (*WGPUProcRenderBundleEncoderSetPipeline)(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderPipeline pipeline); +typedef void (*WGPUProcRenderBundleEncoderSetVertexBuffer)(WGPURenderBundleEncoder renderBundleEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset); +typedef void (*WGPUProcRenderBundleEncoderReference)(WGPURenderBundleEncoder renderBundleEncoder); +typedef void (*WGPUProcRenderBundleEncoderRelease)(WGPURenderBundleEncoder renderBundleEncoder); + +// Procs of RenderPassEncoder +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 (*WGPUProcRenderPassEncoderEndPass)(WGPURenderPassEncoder renderPassEncoder); +typedef void (*WGPUProcRenderPassEncoderExecuteBundles)(WGPURenderPassEncoder renderPassEncoder, uint32_t bundlesCount, WGPURenderBundle const * bundles); +typedef void (*WGPUProcRenderPassEncoderInsertDebugMarker)(WGPURenderPassEncoder renderPassEncoder, char const * groupLabel); +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); +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); +typedef void (*WGPUProcRenderPassEncoderSetViewport)(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth); +typedef void (*WGPUProcRenderPassEncoderReference)(WGPURenderPassEncoder renderPassEncoder); +typedef void (*WGPUProcRenderPassEncoderRelease)(WGPURenderPassEncoder renderPassEncoder); + +// Procs of RenderPipeline +typedef WGPUBindGroupLayout (*WGPUProcRenderPipelineGetBindGroupLayout)(WGPURenderPipeline renderPipeline, uint32_t group); +typedef void (*WGPUProcRenderPipelineReference)(WGPURenderPipeline renderPipeline); +typedef void (*WGPUProcRenderPipelineRelease)(WGPURenderPipeline renderPipeline); + +// Procs of Sampler +typedef void (*WGPUProcSamplerReference)(WGPUSampler sampler); +typedef void (*WGPUProcSamplerRelease)(WGPUSampler sampler); + +// Procs of ShaderModule +typedef void (*WGPUProcShaderModuleReference)(WGPUShaderModule shaderModule); +typedef void (*WGPUProcShaderModuleRelease)(WGPUShaderModule shaderModule); + +// Procs of Surface +typedef void (*WGPUProcSurfaceReference)(WGPUSurface surface); +typedef void (*WGPUProcSurfaceRelease)(WGPUSurface surface); + +// Procs of SwapChain +typedef WGPUTextureView (*WGPUProcSwapChainGetCurrentTextureView)(WGPUSwapChain swapChain); +typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain); +typedef void (*WGPUProcSwapChainReference)(WGPUSwapChain swapChain); +typedef void (*WGPUProcSwapChainRelease)(WGPUSwapChain swapChain); + +// Procs of Texture +typedef WGPUTextureView (*WGPUProcTextureCreateView)(WGPUTexture texture, WGPUTextureViewDescriptor const * descriptor); +typedef void (*WGPUProcTextureDestroy)(WGPUTexture texture); +typedef void (*WGPUProcTextureReference)(WGPUTexture texture); +typedef void (*WGPUProcTextureRelease)(WGPUTexture texture); + +// Procs of TextureView +typedef void (*WGPUProcTextureViewReference)(WGPUTextureView textureView); +typedef void (*WGPUProcTextureViewRelease)(WGPUTextureView textureView); + +#endif // !defined(WGPU_SKIP_PROCS) + +#if !defined(WGPU_SKIP_DECLARATIONS) + +WGPU_EXPORT WGPUInstance wgpuCreateInstance(WGPUInstanceDescriptor const * descriptor); +WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName); + +// Methods of BindGroup +WGPU_EXPORT void wgpuBindGroupReference(WGPUBindGroup bindGroup); +WGPU_EXPORT void wgpuBindGroupRelease(WGPUBindGroup bindGroup); + +// Methods of BindGroupLayout +WGPU_EXPORT void wgpuBindGroupLayoutReference(WGPUBindGroupLayout bindGroupLayout); +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 wgpuBufferUnmap(WGPUBuffer buffer); +WGPU_EXPORT void wgpuBufferReference(WGPUBuffer buffer); +WGPU_EXPORT void wgpuBufferRelease(WGPUBuffer buffer); + +// Methods of CommandBuffer +WGPU_EXPORT void wgpuCommandBufferReference(WGPUCommandBuffer commandBuffer); +WGPU_EXPORT void wgpuCommandBufferRelease(WGPUCommandBuffer commandBuffer); + +// Methods of CommandEncoder +WGPU_EXPORT WGPUComputePassEncoder wgpuCommandEncoderBeginComputePass(WGPUCommandEncoder commandEncoder, WGPUComputePassDescriptor const * descriptor); +WGPU_EXPORT WGPURenderPassEncoder wgpuCommandEncoderBeginRenderPass(WGPUCommandEncoder commandEncoder, WGPURenderPassDescriptor const * descriptor); +WGPU_EXPORT void wgpuCommandEncoderCopyBufferToBuffer(WGPUCommandEncoder commandEncoder, WGPUBuffer source, uint64_t sourceOffset, WGPUBuffer destination, uint64_t destinationOffset, uint64_t size); +WGPU_EXPORT void wgpuCommandEncoderCopyBufferToTexture(WGPUCommandEncoder commandEncoder, WGPUBufferCopyView const * source, WGPUTextureCopyView const * destination, WGPUExtent3D const * copySize); +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 wgpuCommandEncoderPopDebugGroup(WGPUCommandEncoder commandEncoder); +WGPU_EXPORT void wgpuCommandEncoderPushDebugGroup(WGPUCommandEncoder commandEncoder, char const * groupLabel); +WGPU_EXPORT void wgpuCommandEncoderReference(WGPUCommandEncoder commandEncoder); +WGPU_EXPORT void wgpuCommandEncoderRelease(WGPUCommandEncoder commandEncoder); + +// Methods of ComputePassEncoder +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 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 wgpuComputePassEncoderReference(WGPUComputePassEncoder computePassEncoder); +WGPU_EXPORT void wgpuComputePassEncoderRelease(WGPUComputePassEncoder computePassEncoder); + +// Methods of ComputePipeline +WGPU_EXPORT WGPUBindGroupLayout wgpuComputePipelineGetBindGroupLayout(WGPUComputePipeline computePipeline, uint32_t group); +WGPU_EXPORT void wgpuComputePipelineReference(WGPUComputePipeline computePipeline); +WGPU_EXPORT void wgpuComputePipelineRelease(WGPUComputePipeline computePipeline); + +// Methods of Device +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 void wgpuDeviceCreateBufferMappedAsync(WGPUDevice device, WGPUBufferDescriptor const * descriptor, WGPUBufferCreateMappedCallback callback, void * userdata); +WGPU_EXPORT WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor); +WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor); +WGPU_EXPORT WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor); +WGPU_EXPORT WGPUQueue wgpuDeviceCreateQueue(WGPUDevice device); +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); +WGPU_EXPORT WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor); +WGPU_EXPORT WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor); +WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor); +WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message); +WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device); +WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter); +WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata); +WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device); +WGPU_EXPORT void wgpuDeviceReference(WGPUDevice device); +WGPU_EXPORT void wgpuDeviceRelease(WGPUDevice device); + +// Methods of Fence +WGPU_EXPORT uint64_t wgpuFenceGetCompletedValue(WGPUFence fence); +WGPU_EXPORT void wgpuFenceOnCompletion(WGPUFence fence, uint64_t value, WGPUFenceOnCompletionCallback callback, void * userdata); +WGPU_EXPORT void wgpuFenceReference(WGPUFence fence); +WGPU_EXPORT void wgpuFenceRelease(WGPUFence fence); + +// Methods of Instance +WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor); +WGPU_EXPORT void wgpuInstanceReference(WGPUInstance instance); +WGPU_EXPORT void wgpuInstanceRelease(WGPUInstance instance); + +// Methods of PipelineLayout +WGPU_EXPORT void wgpuPipelineLayoutReference(WGPUPipelineLayout pipelineLayout); +WGPU_EXPORT void wgpuPipelineLayoutRelease(WGPUPipelineLayout pipelineLayout); + +// Methods of Queue +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 wgpuQueueReference(WGPUQueue queue); +WGPU_EXPORT void wgpuQueueRelease(WGPUQueue queue); + +// Methods of RenderBundle +WGPU_EXPORT void wgpuRenderBundleReference(WGPURenderBundle renderBundle); +WGPU_EXPORT void wgpuRenderBundleRelease(WGPURenderBundle renderBundle); + +// Methods of RenderBundleEncoder +WGPU_EXPORT void wgpuRenderBundleEncoderDraw(WGPURenderBundleEncoder renderBundleEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +WGPU_EXPORT void wgpuRenderBundleEncoderDrawIndexed(WGPURenderBundleEncoder renderBundleEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance); +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 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); +WGPU_EXPORT void wgpuRenderBundleEncoderSetPipeline(WGPURenderBundleEncoder renderBundleEncoder, WGPURenderPipeline pipeline); +WGPU_EXPORT void wgpuRenderBundleEncoderSetVertexBuffer(WGPURenderBundleEncoder renderBundleEncoder, uint32_t slot, WGPUBuffer buffer, uint64_t offset); +WGPU_EXPORT void wgpuRenderBundleEncoderReference(WGPURenderBundleEncoder renderBundleEncoder); +WGPU_EXPORT void wgpuRenderBundleEncoderRelease(WGPURenderBundleEncoder renderBundleEncoder); + +// Methods of RenderPassEncoder +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 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 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); +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); +WGPU_EXPORT void wgpuRenderPassEncoderSetViewport(WGPURenderPassEncoder renderPassEncoder, float x, float y, float width, float height, float minDepth, float maxDepth); +WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder); +WGPU_EXPORT void wgpuRenderPassEncoderRelease(WGPURenderPassEncoder renderPassEncoder); + +// Methods of RenderPipeline +WGPU_EXPORT WGPUBindGroupLayout wgpuRenderPipelineGetBindGroupLayout(WGPURenderPipeline renderPipeline, uint32_t group); +WGPU_EXPORT void wgpuRenderPipelineReference(WGPURenderPipeline renderPipeline); +WGPU_EXPORT void wgpuRenderPipelineRelease(WGPURenderPipeline renderPipeline); + +// Methods of Sampler +WGPU_EXPORT void wgpuSamplerReference(WGPUSampler sampler); +WGPU_EXPORT void wgpuSamplerRelease(WGPUSampler sampler); + +// Methods of ShaderModule +WGPU_EXPORT void wgpuShaderModuleReference(WGPUShaderModule shaderModule); +WGPU_EXPORT void wgpuShaderModuleRelease(WGPUShaderModule shaderModule); + +// Methods of Surface +WGPU_EXPORT void wgpuSurfaceReference(WGPUSurface surface); +WGPU_EXPORT void wgpuSurfaceRelease(WGPUSurface surface); + +// Methods of SwapChain +WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain); +WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain); +WGPU_EXPORT void wgpuSwapChainReference(WGPUSwapChain swapChain); +WGPU_EXPORT void wgpuSwapChainRelease(WGPUSwapChain swapChain); + +// Methods of Texture +WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPUTextureViewDescriptor const * descriptor); +WGPU_EXPORT void wgpuTextureDestroy(WGPUTexture texture); +WGPU_EXPORT void wgpuTextureReference(WGPUTexture texture); +WGPU_EXPORT void wgpuTextureRelease(WGPUTexture texture); + +// Methods of TextureView +WGPU_EXPORT void wgpuTextureViewReference(WGPUTextureView textureView); +WGPU_EXPORT void wgpuTextureViewRelease(WGPUTextureView textureView); + +#endif // !defined(WGPU_SKIP_DECLARATIONS) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBGPU_H_ diff --git a/tests/test_other.py b/tests/test_other.py index ddc387ecc06c..839e8b71af23 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -10265,3 +10265,8 @@ def test(args): self.assertNotContained('hello, world!', test([])) # but work with it self.assertContained('hello, world!', test(['-s', 'LEGACY_VM_SUPPORT'])) + + # Compile-test for -s USE_WEBGPU=1 and library_webgpu.js. + def test_webgpu_compiletest(self): + for args in [[], ['-s', 'ASSERTIONS=1']]: + run_process([PYTHON, EMCC, path_from_root('tests', 'webgpu_dummy.cpp'), '-s', 'USE_WEBGPU=1'] + args) diff --git a/tests/webgpu_dummy.cpp b/tests/webgpu_dummy.cpp new file mode 100644 index 000000000000..f08ed4cba4e6 --- /dev/null +++ b/tests/webgpu_dummy.cpp @@ -0,0 +1,16 @@ +// Copyright 2020 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +// Make sure these headers exist. +#include + +#include +#include + +int main() { +#ifdef REPORT_RESULT + REPORT_RESULT(0); +#endif +}