From 709ac20907e04d8d6f31b040e883e500c070e672 Mon Sep 17 00:00:00 2001 From: soywiz Date: Thu, 4 Jul 2024 11:15:30 +0200 Subject: [PATCH] inline class for string-based enums --- .../ygdrasil/wgpu/internal/js/WebGPUTypes.kt | 352 +++++++++++++++--- korge-core/src@js/korlibs/webgpu/WebGPUAG.kt | 79 ++-- .../test@js/korlibs/webgpu/WebGPUTest.kt | 6 +- 3 files changed, 332 insertions(+), 105 deletions(-) diff --git a/korge-core/src@js/io/ygdrasil/wgpu/internal/js/WebGPUTypes.kt b/korge-core/src@js/io/ygdrasil/wgpu/internal/js/WebGPUTypes.kt index 4855f785ea..cee41f8ddf 100644 --- a/korge-core/src@js/io/ygdrasil/wgpu/internal/js/WebGPUTypes.kt +++ b/korge-core/src@js/io/ygdrasil/wgpu/internal/js/WebGPUTypes.kt @@ -1,6 +1,6 @@ // From wgpu4k. Eventually it will be used directly // https:github.com/wgpu4k/wgpu4k/blob/main/wgpu4k/src/jsMain/kotlin/io.ygdrasil.wgpu/internal.js/webgpu_types.kt -@file:Suppress("UNUSED_PARAMETER", "UnsafeCastFromDynamic", "unused") +@file:Suppress("UNUSED_PARAMETER", "UnsafeCastFromDynamic", "unused", "INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING") package io.ygdrasil.wgpu.internal.js @@ -77,17 +77,44 @@ fun GPUBindGroupLayoutEntry( externalTexture: GPUExternalTextureBindingLayout? = undefined, ): GPUBindGroupLayoutEntry = js("({binding: binding, visibility: visibility, buffer: buffer, sampler: sampler, texture: texture, storageTexture: storageTexture, externalTexture: externalTexture})") +inline class GPUBlendOperation(val str: String) { + companion object { + inline val ADD get() = GPUBlendOperation("add") + inline val SUBTRACT get() = GPUBlendOperation("subtract") + inline val REVERSE_SUBTRACT get() = GPUBlendOperation("reverse-subtract") + inline val MIN get() = GPUBlendOperation("min") + inline val MAX get() = GPUBlendOperation("max") + } +} + +inline class GPUBlendFactor(val str: String) { + companion object { + inline val ZERO get() = GPUBlendFactor("zero") + inline val ONE get() = GPUBlendFactor("one") + inline val SRC get() = GPUBlendFactor("src") + inline val ONE_MINUS_SRC get() = GPUBlendFactor("one-minus-src") + inline val SRC_ALPHA get() = GPUBlendFactor("src-alpha") + inline val ONE_MINUS_SRC_ALPHA get() = GPUBlendFactor("one-minus-src-alpha") + inline val DST get() = GPUBlendFactor("dst") + inline val ONE_MINUS_DST get() = GPUBlendFactor("one-minus-dst") + inline val DST_ALPHA get() = GPUBlendFactor("dst-alpha") + inline val ONE_MINUS_DST_ALPHA get() = GPUBlendFactor("one-minus-dst-alpha") + inline val SRC_ALPHA_SATURATED get() = GPUBlendFactor("src-alpha-saturated") + inline val CONSTANT get() = GPUBlendFactor("constant") + inline val ONE_MINUS_CONSTANT get() = GPUBlendFactor("one-minus-constant") + } +} external interface GPUBlendComponent { - var operation: String? /* "add" | "subtract" | "reverse-subtract" | "min" | "max" */ - var srcFactor: String? /* "zero" | "one" | "src" | "one-minus-src" | "src-alpha" | "one-minus-src-alpha" | "dst" | "one-minus-dst" | "dst-alpha" | "one-minus-dst-alpha" | "src-alpha-saturated" | "constant" | "one-minus-constant" */ - var dstFactor: String? /* "zero" | "one" | "src" | "one-minus-src" | "src-alpha" | "one-minus-src-alpha" | "dst" | "one-minus-dst" | "dst-alpha" | "one-minus-dst-alpha" | "src-alpha-saturated" | "constant" | "one-minus-constant" */ + var operation: GPUBlendOperation? + var srcFactor: GPUBlendFactor? + var dstFactor: GPUBlendFactor? } fun GPUBlendComponent( - operation: String? = undefined, - srcFactor: String? = undefined, - dstFactor: String? = undefined, + operation: GPUBlendOperation? = undefined, + srcFactor: GPUBlendFactor? = undefined, + dstFactor: GPUBlendFactor? = undefined, ): GPUBlendComponent = js("({operation: operation, srcFactor: srcFactor, dstFactor: dstFactor})") @@ -141,25 +168,129 @@ fun GPUBufferDescriptor( label: String? = undefined, ): GPUBufferDescriptor = js("({size: size, usage: usage, mappedAtCreation: mappedAtCreation, label: label})") +inline class GPUTextureFormat(val str: String) { + companion object { + inline val R8UNORM get() = GPUTextureFormat("r8unorm") + inline val R8SNORM get() = GPUTextureFormat("r8snorm") + inline val R8UINT get() = GPUTextureFormat("r8uint") + inline val R8SINT get() = GPUTextureFormat("r8sint") + inline val R16UINT get() = GPUTextureFormat("r16uint") + inline val R16SINT get() = GPUTextureFormat("r16sint") + inline val R16FLOAT get() = GPUTextureFormat("r16float") + inline val RG8UNORM get() = GPUTextureFormat("rg8unorm") + inline val RG8SNORM get() = GPUTextureFormat("rg8snorm") + inline val RG8UINT get() = GPUTextureFormat("rg8uint") + inline val RG8SINT get() = GPUTextureFormat("rg8sint") + inline val R32UINT get() = GPUTextureFormat("r32uint") + inline val R32SINT get() = GPUTextureFormat("r32sint") + inline val R32FLOAT get() = GPUTextureFormat("r32float") + inline val RG16UINT get() = GPUTextureFormat("rg16uint") + inline val RG16SINT get() = GPUTextureFormat("rg16sint") + inline val RG16FLOAT get() = GPUTextureFormat("rg16float") + inline val RGBA8UNORM get() = GPUTextureFormat("rgba8unorm") + inline val RGBA8UNORM_SRGB get() = GPUTextureFormat("rgba8unorm-srgb") + inline val RGBA8SNORM get() = GPUTextureFormat("rgba8snorm") + inline val RGBA8UINT get() = GPUTextureFormat("rgba8uint") + inline val RGBA8SINT get() = GPUTextureFormat("rgba8sint") + inline val BGRA8UNORM get() = GPUTextureFormat("bgra8unorm") + inline val BGRA8UNORM_SRGB get() = GPUTextureFormat("bgra8unorm-srgb") + inline val RGB9E5UFLOAT get() = GPUTextureFormat("rgb9e5ufloat") + inline val RGB10A2UINT get() = GPUTextureFormat("rgb10a2uint") + inline val RGB10A2UNORM get() = GPUTextureFormat("rgb10a2unorm") + inline val RG11B10UFLOAT get() = GPUTextureFormat("rg11b10ufloat") + inline val RG32UINT get() = GPUTextureFormat("rg32uint") + inline val RG32SINT get() = GPUTextureFormat("rg32sint") + inline val RG32FLOAT get() = GPUTextureFormat("rg32float") + inline val RGBA16UINT get() = GPUTextureFormat("rgba16uint") + inline val RGBA16SINT get() = GPUTextureFormat("rgba16sint") + inline val RGBA16FLOAT get() = GPUTextureFormat("rgba16float") + inline val RGBA32UINT get() = GPUTextureFormat("rgba32uint") + inline val RGBA32SINT get() = GPUTextureFormat("rgba32sint") + inline val RGBA32FLOAT get() = GPUTextureFormat("rgba32float") + inline val STENCIL8 get() = GPUTextureFormat("stencil8") + inline val DEPTH16UNORM get() = GPUTextureFormat("depth16unorm") + inline val DEPTH24PLUS get() = GPUTextureFormat("depth24plus") + inline val DEPTH24PLUS_STENCIL8 get() = GPUTextureFormat("depth24plus-stencil8") + inline val DEPTH32FLOAT get() = GPUTextureFormat("depth32float") + inline val DEPTH32FLOAT_STENCIL8 get() = GPUTextureFormat("depth32float-stencil8") + inline val BC1_RGBA_UNORM get() = GPUTextureFormat("bc1-rgba-unorm") + inline val BC1_RGBA_UNORM_SRGB get() = GPUTextureFormat("bc1-rgba-unorm-srgb") + inline val BC2_RGBA_UNORM get() = GPUTextureFormat("bc2-rgba-unorm") + inline val BC2_RGBA_UNORM_SRGB get() = GPUTextureFormat("bc2-rgba-unorm-srgb") + inline val BC3_RGBA_UNORM get() = GPUTextureFormat("bc3-rgba-unorm") + inline val BC3_RGBA_UNORM_SRGB get() = GPUTextureFormat("bc3-rgba-unorm-srgb") + inline val BC4_R_UNORM get() = GPUTextureFormat("bc4-r-unorm") + inline val BC4_R_SNORM get() = GPUTextureFormat("bc4-r-snorm") + inline val BC5_RG_UNORM get() = GPUTextureFormat("bc5-rg-unorm") + inline val BC5_RG_SNORM get() = GPUTextureFormat("bc5-rg-snorm") + inline val BC6H_RGB_UFLOAT get() = GPUTextureFormat("bc6h-rgb-ufloat") + inline val BC6H_RGB_FLOAT get() = GPUTextureFormat("bc6h-rgb-float") + inline val BC7_RGBA_UNORM get() = GPUTextureFormat("bc7-rgba-unorm") + inline val BC7_RGBA_UNORM_SRGB get() = GPUTextureFormat("bc7-rgba-unorm-srgb") + inline val ETC2_RGB8UNORM get() = GPUTextureFormat("etc2-rgb8unorm") + inline val ETC2_RGB8UNORM_SRGB get() = GPUTextureFormat("etc2-rgb8unorm-srgb") + inline val ETC2_RGB8A1UNORM get() = GPUTextureFormat("etc2-rgb8a1unorm") + inline val ETC2_RGB8A1UNORM_SRGB get() = GPUTextureFormat("etc2-rgb8a1unorm-srgb") + inline val ETC2_RGBA8UNORM get() = GPUTextureFormat("etc2-rgba8unorm") + inline val ETC2_RGBA8UNORM_SRGB get() = GPUTextureFormat("etc2-rgba8unorm-srgb") + inline val EAC_R11UNORM get() = GPUTextureFormat("eac-r11unorm") + inline val EAC_R11SNORM get() = GPUTextureFormat("eac-r11snorm") + inline val EAC_RG11UNORM get() = GPUTextureFormat("eac-rg11unorm") + inline val EAC_RG11SNORM get() = GPUTextureFormat("eac-rg11snorm") + inline val ASTC_4X4_UNORM get() = GPUTextureFormat("astc-4x4-unorm") + inline val ASTC_4X4_UNORM_SRGB get() = GPUTextureFormat("astc-4x4-unorm-srgb") + inline val ASTC_5X4_UNORM get() = GPUTextureFormat("astc-5x4-unorm") + inline val ASTC_5X4_UNORM_SRGB get() = GPUTextureFormat("astc-5x4-unorm-srgb") + inline val ASTC_5X5_UNORM get() = GPUTextureFormat("astc-5x5-unorm") + inline val ASTC_5X5_UNORM_SRGB get() = GPUTextureFormat("astc-5x5-unorm-srgb") + inline val ASTC_6X5_UNORM get() = GPUTextureFormat("astc-6x5-unorm") + inline val ASTC_6X5_UNORM_SRGB get() = GPUTextureFormat("astc-6x5-unorm-srgb") + inline val ASTC_6X6_UNORM get() = GPUTextureFormat("astc-6x6-unorm") + inline val ASTC_6X6_UNORM_SRGB get() = GPUTextureFormat("astc-6x6-unorm-srgb") + inline val ASTC_8X5_UNORM get() = GPUTextureFormat("astc-8x5-unorm") + inline val ASTC_8X5_UNORM_SRGB get() = GPUTextureFormat("astc-8x5-unorm-srgb") + inline val ASTC_8X6_UNORM get() = GPUTextureFormat("astc-8x6-unorm") + inline val ASTC_8X6_UNORM_SRGB get() = GPUTextureFormat("astc-8x6-unorm-srgb") + inline val ASTC_8X8_UNORM get() = GPUTextureFormat("astc-8x8-unorm") + inline val ASTC_8X8_UNORM_SRGB get() = GPUTextureFormat("astc-8x8-unorm-srgb") + inline val ASTC_10X5_UNORM get() = GPUTextureFormat("astc-10x5-unorm") + inline val ASTC_10X5_UNORM_SRGB get() = GPUTextureFormat("astc-10x5-unorm-srgb") + inline val ASTC_10X6_UNORM get() = GPUTextureFormat("astc-10x6-unorm") + inline val ASTC_10X6_UNORM_SRGB get() = GPUTextureFormat("astc-10x6-unorm-srgb") + inline val ASTC_10X8_UNORM get() = GPUTextureFormat("astc-10x8-unorm") + inline val ASTC_10X8_UNORM_SRGB get() = GPUTextureFormat("astc-10x8-unorm-srgb") + inline val ASTC_10X10_UNORM get() = GPUTextureFormat("astc-10x10-unorm") + inline val ASTC_10X10_UNORM_SRGB get() = GPUTextureFormat("astc-10x10-unorm-srgb") + inline val ASTC_12X10_UNORM get() = GPUTextureFormat("astc-12x10-unorm") + inline val ASTC_12X10_UNORM_SRGB get() = GPUTextureFormat("astc-12x10-unorm-srgb") + inline val ASTC_12X12_UNORM get() = GPUTextureFormat("astc-12x12-unorm") + inline val ASTC_12X12_UNORM_SRGB get() = GPUTextureFormat("astc-12x12-unorm-srgb") + } +} + +inline class GPUAlphaMode(val str: String) { + companion object { + inline val OPAQUE get() = GPUAlphaMode("opaque") + inline val PREMULTIPLIED get() = GPUAlphaMode("premultiplied") + } +} external interface GPUCanvasConfiguration { var device: GPUDevice - /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ - var format: String + var format: GPUTextureFormat var usage: GPUTextureUsageFlags? - /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ - var viewFormats: Array? + var viewFormats: Array? var colorSpace: Any? - var alphaMode: String? /* "opaque" | "premultiplied" */ + var alphaMode: GPUAlphaMode? } fun GPUCanvasConfiguration( device: GPUDevice, - format: String, + format: GPUTextureFormat, usage: GPUTextureUsageFlags? = undefined, - viewFormats: Array? = undefined, + viewFormats: Array? = undefined, colorSpace: Any? = undefined, - alphaMode: String? = undefined, + alphaMode: GPUAlphaMode? = undefined, ): GPUCanvasConfiguration = js("({device: device, format: format, usage: usage, viewFormats: viewFormats, colorSpace: colorSpace, alphaMode: alphaMode})") @@ -179,14 +310,13 @@ fun GPUColorDict( external interface GPUColorTargetState { - /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ - var format: String + var format: GPUTextureFormat var blend: GPUBlendState? var writeMask: GPUColorWriteFlags? } fun GPUColorTargetState( - format: String, + format: GPUTextureFormat, blend: GPUBlendState? = undefined, writeMask: GPUColorWriteFlags? = undefined, ): GPUColorTargetState = js("({format: format, blend: blend, writeMask: writeMask})") @@ -229,11 +359,23 @@ fun GPUComputePipelineDescriptor( label: String? = undefined, ): GPUComputePipelineDescriptor = js("({compute: compute, layout: layout, label: label})") +inline class GPUCompare(val str: String) { + companion object { + inline val NEVER get() = GPUCompare("never") + inline val LESS get() = GPUCompare("less") + inline val EQUAL get() = GPUCompare("equal") + inline val LESS_EQUAL get() = GPUCompare("less-equal") + inline val GREATER get() = GPUCompare("greater") + inline val NOT_EQUAL get() = GPUCompare("not-equal") + inline val GREATER_EQUAL get() = GPUCompare("greater-equal") + inline val ALWAYS get() = GPUCompare("always") + } +} external interface GPUDepthStencilState { - var format: String /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ + var format: GPUTextureFormat var depthWriteEnabled: Boolean? - var depthCompare: String? /* "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always" */ + var depthCompare: GPUCompare? var stencilFront: GPUStencilFaceState? var stencilBack: GPUStencilFaceState? var stencilReadMask: GPUStencilValue? @@ -244,9 +386,9 @@ external interface GPUDepthStencilState { } fun GPUDepthStencilState( - format: String, + format: GPUTextureFormat, depthWriteEnabled: Boolean? = undefined, - depthCompare: String? = undefined, + depthCompare: GPUCompare? = undefined, stencilFront: GPUStencilFaceState? = undefined, stencilBack: GPUStencilFaceState? = undefined, stencilReadMask: GPUStencilValue? = undefined, @@ -523,19 +665,43 @@ fun GPURenderPassColorAttachment( storeOp: String, ): GPURenderPassColorAttachment = js("({view: view, depthSlice: depthSlice, resolveTarget: resolveTarget, clearValue: clearValue, loadOp: loadOp, storeOp: storeOp})") +inline class GPULoadOP(val str: String) { + companion object { + inline val LOAD get() = GPULoadOP("load") + inline val CLEAR get() = GPULoadOP("clear") + } +} + +inline class GPUStoreOP(val str: String) { + companion object { + inline val STORE get() = GPUStoreOP("store") + inline val DISCARD get() = GPUStoreOP("discard") + } +} external interface GPURenderPassDepthStencilAttachment { var view: GPUTextureView var depthClearValue: Number? - var depthLoadOp: String? /* "load" | "clear" */ - var depthStoreOp: String? /* "store" | "discard" */ + var depthLoadOp: GPULoadOP? + var depthStoreOp: GPUStoreOP? var depthReadOnly: Boolean? var stencilClearValue: GPUStencilValue? - var stencilLoadOp: String? /* "load" | "clear" */ - var stencilStoreOp: String? /* "store" | "discard" */ + var stencilLoadOp: GPULoadOP? + var stencilStoreOp: GPUStoreOP? var stencilReadOnly: Boolean? } +fun GPURenderPassDepthStencilAttachment( + view: GPUTextureView, + depthClearValue: Number? = undefined, + depthLoadOp: GPULoadOP? = undefined, + depthStoreOp: GPUStoreOP? = undefined, + depthReadOnly: Boolean? = undefined, + stencilClearValue: GPUStencilValue? = undefined, + stencilLoadOp: GPULoadOP? = undefined, + stencilStoreOp: GPUStoreOP? = undefined, + stencilReadOnly: Boolean? = undefined, +): GPURenderPassDepthStencilAttachment = js("({view: view, depthClearValue: depthClearValue, depthLoadOp: depthLoadOp, depthStoreOp: depthStoreOp, depthReadOnly: depthReadOnly, stencilClearValue: stencilClearValue, stencilLoadOp: stencilLoadOp, stencilStoreOp: stencilStoreOp, stencilReadOnly: stencilReadOnly})") external interface GPURenderPassDescriptor : GPUObjectDescriptorBase { var colorAttachments: Array @@ -555,11 +721,17 @@ fun GPURenderPassDescriptor( external interface GPURenderPassLayout : GPUObjectDescriptorBase { - var colorFormats: Iterable - var depthStencilFormat: String? /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ + var colorFormats: Iterable + var depthStencilFormat: GPUTextureFormat? var sampleCount: GPUSize32? } +fun GPURenderPassLayout( + colorFormats: Iterable, + depthStencilFormat: GPUTextureFormat? = undefined, + sampleCount: GPUSize32? = undefined, + label: String? = undefined, +): GPURenderPassLayout = js("({colorFormats: colorFormats, depthStencilFormat: depthStencilFormat, sampleCount: sampleCount, label: label})") external interface GPURenderPassTimestampWrites { var querySet: GPUQuerySet @@ -567,6 +739,11 @@ external interface GPURenderPassTimestampWrites { var endOfPassWriteIndex: GPUSize32? } +fun GPURenderPassTimestampWrites( + querySet: GPUQuerySet, + beginningOfPassWriteIndex: GPUSize32? = undefined, + endOfPassWriteIndex: GPUSize32? = undefined, +): GPURenderPassTimestampWrites = js("({querySet: querySet, beginningOfPassWriteIndex: beginningOfPassWriteIndex, endOfPassWriteIndex: endOfPassWriteIndex})") external interface GPURenderPipelineDescriptor : GPUPipelineDescriptorBase { var vertex: GPUVertexState @@ -586,37 +763,79 @@ fun GPURenderPipelineDescriptor( label: String? = undefined, ): GPURenderPipelineDescriptor = js("({vertex: vertex, primitive: primitive, depthStencil: depthStencil, multisample: multisample, fragment: fragment, layout: layout, label: label})") +inline class GPUPowerPreference(val str: String) { + companion object { + inline val LOW_POWER get() = GPUPowerPreference("low-power") + inline val HIGH_PERFORMANCE get() = GPUPowerPreference("high-performance") + } +} external interface GPURequestAdapterOptions { - var powerPreference: String? /* "low-power" | "high-performance" */ + var powerPreference: GPUPowerPreference? var forceFallbackAdapter: Boolean? } +fun GPURequestAdapterOptions( + powerPreference: GPUPowerPreference? = undefined, + forceFallbackAdapter: Boolean? = undefined, +): GPURequestAdapterOptions = js("({powerPreference: powerPreference, forceFallbackAdapter: forceFallbackAdapter})") + external interface GPUSamplerBindingLayout { var type: String? /* "filtering" | "non-filtering" | "comparison" */ } +inline class GPUAddressMode(val str: String) { + companion object { + inline val CLAMP_TO_EDGE get() = GPUAddressMode("clamp-to-edge") + inline val REPEAT get() = GPUAddressMode("repeat") + inline val MIRROR_REPEAT get() = GPUAddressMode("mirror-repeat") + } +} + +inline class GPUFilterMode(val str: String) { + companion object { + inline val NEAREST get() = GPUFilterMode("nearest") + inline val LINEAR get() = GPUFilterMode("linear") + } +} external interface GPUSamplerDescriptor : GPUObjectDescriptorBase { - var addressModeU: String? /* "clamp-to-edge" | "repeat" | "mirror-repeat" */ - var addressModeV: String? /* "clamp-to-edge" | "repeat" | "mirror-repeat" */ - var addressModeW: String? /* "clamp-to-edge" | "repeat" | "mirror-repeat" */ - var magFilter: String? /* "nearest" | "linear" */ - var minFilter: String? /* "nearest" | "linear" */ - var mipmapFilter: String? /* "nearest" | "linear" */ + var addressModeU: GPUAddressMode? + var addressModeV: GPUAddressMode? + var addressModeW: GPUAddressMode? + var magFilter: GPUFilterMode? + var minFilter: GPUFilterMode? + var mipmapFilter: GPUFilterMode? var lodMinClamp: Number? var lodMaxClamp: Number? - var compare: String? /* "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always" */ + var compare: GPUCompare? var maxAnisotropy: Number? } +fun GPUSamplerDescriptor( + addressModeU: GPUAddressMode? = undefined, + addressModeV: GPUAddressMode? = undefined, + addressModeW: GPUAddressMode? = undefined, + magFilter: GPUFilterMode? = undefined, + minFilter: GPUFilterMode? = undefined, + mipmapFilter: GPUFilterMode? = undefined, + lodMinClamp: Number? = undefined, + lodMaxClamp: Number? = undefined, + compare: GPUCompare? = undefined, + maxAnisotropy: Number? = undefined, + label: String? = undefined, +): GPUSamplerDescriptor = js("({addressModeU: addressModeU, addressModeV: addressModeV, addressModeW: addressModeW, magFilter: magFilter, minFilter: minFilter, mipmapFilter: mipmapFilter, lodMinClamp: lodMinClamp, lodMaxClamp: lodMaxClamp, compare: compare, maxAnisotropy: maxAnisotropy, label: label})") external interface GPUShaderModuleCompilationHint { var entryPoint: String var layout: dynamic /* GPUPipelineLayout? | "auto" */ } +fun GPUShaderModuleCompilationHint( + entryPoint: String, + layout: dynamic = undefined, +): GPUShaderModuleCompilationHint = js("({entryPoint: entryPoint, layout: layout})") external interface GPUShaderModuleDescriptor : GPUObjectDescriptorBase { var code: String @@ -625,6 +844,7 @@ external interface GPUShaderModuleDescriptor : GPUObjectDescriptorBase { } fun GPUShaderModuleDescriptor( + //language=WGSL code: String, sourceMap: Any? = undefined, compilationHints: Array? = undefined, @@ -646,29 +866,47 @@ fun GPUStencilFaceState( passOp: String? = undefined, ): GPUStencilFaceState = js("({compare: compare, failOp: failOp, depthFailOp: depthFailOp, passOp: passOp})") +inline class GPUViewDimension(val str: String) { + companion object { + inline val _1D get() = GPUViewDimension("1d") + inline val _2D get() = GPUViewDimension("2d") + inline val _2D_ARRAY get() = GPUViewDimension("2d-array") + inline val CUBE get() = GPUViewDimension("cube") + inline val CUBE_ARRAY get() = GPUViewDimension("cube-array") + inline val _3D get() = GPUViewDimension("3d") + } +} + +inline class GPUAccess(val str: String) { + companion object { + inline val READ_ONLY get() = GPUAccess("read-only") + inline val WRITE_ONLY get() = GPUAccess("write-only") + inline val READ_WRITE get() = GPUAccess("read-write") + } +} external interface GPUStorageTextureBindingLayout { - var access: String? /* "write-only" | "read-only" | "read-write" */ - var format: String /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ - var viewDimension: String? /* "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d" */ + var access: GPUAccess? + var format: GPUTextureFormat + var viewDimension: GPUViewDimension? } fun GPUStorageTextureBindingLayout( - access: String? = undefined, - format: String, - viewDimension: String, + access: GPUAccess? = undefined, + format: GPUTextureFormat, + viewDimension: GPUViewDimension, ): GPUStorageTextureBindingLayout = js("({access: access, format: format, viewDimension: viewDimension})") external interface GPUTextureBindingLayout { var sampleType: String? /* "float" | "unfilterable-float" | "depth" | "sint" | "uint" */ - var viewDimension: String? /* "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d" */ + var viewDimension: GPUViewDimension? var multisampled: Boolean? } fun GPUTextureBindingLayout( sampleType: String? = undefined, - viewDimension: String? = undefined, + viewDimension: GPUViewDimension? = undefined, multisampled: Boolean? = undefined, ): GPUTextureBindingLayout = js("({sampleType: sampleType, viewDimension: viewDimension, multisampled: multisampled})") @@ -678,9 +916,9 @@ external interface GPUTextureDescriptor : GPUObjectDescriptorBase { var mipLevelCount: GPUIntegerCoordinate? var sampleCount: GPUSize32? var dimension: String? /* "1d" | "2d" | "3d" */ - var format: String /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ + var format: GPUTextureFormat var usage: GPUTextureUsageFlags - var viewFormats: Array? + var viewFormats: Array? } fun GPUTextureDescriptor( @@ -688,16 +926,16 @@ fun GPUTextureDescriptor( mipLevelCount: GPUIntegerCoordinate? = undefined, sampleCount: GPUSize32? = undefined, dimension: String? = undefined, - format: String, + format: GPUTextureFormat, usage: GPUTextureUsageFlags, - viewFormats: Array? = undefined, + viewFormats: Array? = undefined, label: String? = undefined, ): GPUTextureDescriptor = js("({size: size, mipLevelCount: mipLevelCount, sampleCount: sampleCount, dimension: dimension, format: format, usage: usage, viewFormats: viewFormats, label: label})") external interface GPUTextureViewDescriptor : GPUObjectDescriptorBase { - var format: String? /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ - var dimension: String? /* "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d" */ + var format: GPUTextureFormat? + var dimension: GPUViewDimension? var aspect: String? /* "all" | "stencil-only" | "depth-only" */ var baseMipLevel: GPUIntegerCoordinate? var mipLevelCount: GPUIntegerCoordinate? @@ -706,8 +944,8 @@ external interface GPUTextureViewDescriptor : GPUObjectDescriptorBase { } fun GPUTextureViewDescriptor( - format: String? = undefined, - dimension: String? = undefined, + format: GPUTextureFormat? = undefined, + dimension: GPUViewDimension? = undefined, aspect: String? = undefined, baseMipLevel: GPUIntegerCoordinate? = undefined, mipLevelCount: GPUIntegerCoordinate? = undefined, @@ -729,15 +967,13 @@ fun GPUUncapturedErrorEventInit( external interface GPUVertexAttribute { - var format: String - - /* "uint8x2" | "uint8x4" | "sint8x2" | "sint8x4" | "unorm8x2" | "unorm8x4" | "snorm8x2" | "snorm8x4" | "uint16x2" | "uint16x4" | "sint16x2" | "sint16x4" | "unorm16x2" | "unorm16x4" | "snorm16x2" | "snorm16x4" | "float16x2" | "float16x4" | "float32" | "float32x2" | "float32x3" | "float32x4" | "uint32" | "uint32x2" | "uint32x3" | "uint32x4" | "sint32" | "sint32x2" | "sint32x3" | "sint32x4" | "unorm10-10-10-2" */ + var format: GPUTextureFormat var offset: GPUSize64 var shaderLocation: GPUIndex32 } fun GPUVertexAttribute( - format: String, + format: GPUTextureFormat, offset: GPUSize64, shaderLocation: GPUIndex32, ): GPUVertexAttribute = js("({format: format, offset: offset, shaderLocation: shaderLocation})") @@ -818,7 +1054,7 @@ external interface NavigatorGPU { external class GPU { var __brand: String /* "GPU" */ fun requestAdapter(options: GPURequestAdapterOptions = definedExternally): Promise - fun getPreferredCanvasFormat(): String /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ + fun getPreferredCanvasFormat(): GPUTextureFormat var wgslLanguageFeatures: WGSLLanguageFeatures companion object { @@ -1314,7 +1550,7 @@ external class GPUTexture : GPUObjectBase { var mipLevelCount: GPUIntegerCoordinateOut var sampleCount: GPUSize32Out var dimension: String /* "1d" | "2d" | "3d" */ - var format: String /* "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb" */ + var format: GPUTextureFormat var usage: GPUFlagsConstant companion object { diff --git a/korge-core/src@js/korlibs/webgpu/WebGPUAG.kt b/korge-core/src@js/korlibs/webgpu/WebGPUAG.kt index cc653498e6..f1cbb69f9e 100644 --- a/korge-core/src@js/korlibs/webgpu/WebGPUAG.kt +++ b/korge-core/src@js/korlibs/webgpu/WebGPUAG.kt @@ -12,9 +12,8 @@ private external val navigator: NavigatorGPU class WebGPUAG(val device: GPUDevice) : AG() { val dimensions = SizeInt(320, 240) - val shaderModule = device.createShaderModule( - jsObjectOf("code" to - """ + val shaderModule = device.createShaderModule(GPUShaderModuleDescriptor( + code = """ @vertex fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4 { let x = f32(i32(in_vertex_index) - 1); @@ -26,33 +25,31 @@ class WebGPUAG(val device: GPUDevice) : AG() { fn fs_main() -> @location(0) vec4 { return vec4(1.0, 0.0, 0.0, 1.0); } - """) - ); + """.trimIndent() + )) - val pipelineLayout = device.createPipelineLayout( - jsObjectOf( - "bindGroupLayouts" to jsEmptyArray(), - ) - ); + val pipelineLayout = device.createPipelineLayout(GPUPipelineLayoutDescriptor( + bindGroupLayouts = arrayOf(), + )) val renderPipeline = device.createRenderPipeline( - jsObjectOf( - "layout" to pipelineLayout, - "vertex" to jsObjectOf( - "module" to shaderModule, - "entryPoint" to "vs_main", + GPURenderPipelineDescriptor( + layout = pipelineLayout, + vertex = GPUVertexState( + module = shaderModule, + entryPoint = "vs_main", ), - "fragment" to jsObjectOf( - "module" to shaderModule, - "entryPoint" to "fs_main", - "targets" to arrayOf( - jsObjectOf( - "format" to "rgba8unorm-srgb", + fragment = GPUFragmentState( + module = shaderModule, + entryPoint = "fs_main", + targets = arrayOf( + GPUColorTargetState( + format = GPUTextureFormat.RGBA8UNORM_SRGB, ), ), ), ) - ); + ) val captureInfo = createCapture( device, @@ -116,14 +113,9 @@ class WebGPUAG(val device: GPUDevice) : AG() { val padded = getRowPadding(dimensions.width).padded; encoder.copyTextureToBuffer( - jsObjectOf( - "texture" to texture, - ).unsafeCast(), - jsObjectOf( - "buffer" to outputBuffer, - "bytesPerRow" to padded, - ).unsafeCast(), - jsObjectOf("width" to dimensions.width, "height" to dimensions.height).unsafeCast(), + GPUImageCopyTexture(texture = texture,), + GPUImageCopyBuffer(buffer = outputBuffer, bytesPerRow = padded), + GPUExtent3DDictStrict(width = dimensions.width, height = dimensions.height), ); } @@ -135,20 +127,19 @@ class WebGPUAG(val device: GPUDevice) : AG() { height: Int, ): CreateCapture { val padded = getRowPadding(width).padded; - val outputBuffer = device.createBuffer(jsObjectOf( - "label" to "Capture", - "size" to padded * height, - "usage" to (GPUBufferUsage.MAP_READ or GPUBufferUsage.COPY_DST), - )); - val texture = device.createTexture(jsObjectOf( - "label" to "Capture", - "size" to jsObjectOf( - "width" to width, - "height" to height, - ), - "format" to "rgba8unorm-srgb", - "usage" to (GPUTextureUsage.RENDER_ATTACHMENT or GPUTextureUsage.COPY_SRC), - )); + val outputBuffer = device.createBuffer(GPUBufferDescriptor( + label = "Capture", + size = padded * height, + usage = (GPUBufferUsage.MAP_READ or GPUBufferUsage.COPY_DST + ))) + val texture = device.createTexture( + GPUTextureDescriptor( + label = "Capture", + size = GPUExtent3DDictStrict(width = width, height = height), + format = GPUTextureFormat.RGBA8UNORM_SRGB, + usage = (GPUTextureUsage.RENDER_ATTACHMENT or GPUTextureUsage.COPY_SRC), + ) + ) return CreateCapture(texture, outputBuffer) } diff --git a/korge-core/test@js/korlibs/webgpu/WebGPUTest.kt b/korge-core/test@js/korlibs/webgpu/WebGPUTest.kt index a1f6d5a1d7..3433db4404 100644 --- a/korge-core/test@js/korlibs/webgpu/WebGPUTest.kt +++ b/korge-core/test@js/korlibs/webgpu/WebGPUTest.kt @@ -30,7 +30,7 @@ class WebGPUTest { GPUCanvasConfiguration( device = device, format = presentationFormat, - alphaMode = "premultiplied" + alphaMode = GPUAlphaMode.PREMULTIPLIED ) ) @@ -158,7 +158,7 @@ class WebGPUTest { entryPoint = "fs_main", targets = arrayOf( GPUColorTargetState( - format = "rgba8unorm-srgb", + format = GPUTextureFormat.RGBA8UNORM_SRGB, ), ), ), @@ -217,7 +217,7 @@ class WebGPUTest { width = width, height = height, ), - format = "rgba8unorm-srgb", + format = GPUTextureFormat.RGBA8UNORM_SRGB, usage = (GPUTextureUsage.RENDER_ATTACHMENT or GPUTextureUsage.COPY_SRC), ) );