ris-framework 0.2.0-dev.11 → 0.2.0-dev.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/CHANGELOG.md +22 -29
  2. package/README.md +13 -1
  3. package/dist/Framework.d.ts +26 -8
  4. package/dist/Framework.d.ts.map +1 -1
  5. package/dist/api/IFramework.d.ts +43 -0
  6. package/dist/api/IFramework.d.ts.map +1 -1
  7. package/dist/api/_export.d.ts +1 -1
  8. package/dist/api/_export.d.ts.map +1 -1
  9. package/dist/api/content/ContentManager.d.ts +5 -57
  10. package/dist/api/content/ContentManager.d.ts.map +1 -1
  11. package/dist/api/content/IContentManager.d.ts +24 -21
  12. package/dist/api/content/IContentManager.d.ts.map +1 -1
  13. package/dist/api/lights/LightsBuffer.d.ts +13 -6
  14. package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
  15. package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
  16. package/dist/api/loaders/ObjLoader.d.ts +61 -0
  17. package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
  18. package/dist/api/loaders/_export.d.ts +1 -0
  19. package/dist/api/loaders/_export.d.ts.map +1 -1
  20. package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
  21. package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
  22. package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
  23. package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
  24. package/dist/api/loaders/obj/index.d.ts +1 -1
  25. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
  26. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
  27. package/dist/api/material/ICameraMaterial.d.ts +18 -0
  28. package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
  29. package/dist/api/material/ILightsMaterial.d.ts +26 -0
  30. package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
  31. package/dist/api/material/IMaterial.d.ts +2 -8
  32. package/dist/api/material/IMaterial.d.ts.map +1 -1
  33. package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
  34. package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
  35. package/dist/api/material/SpriteMaterial.d.ts +2 -2
  36. package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
  37. package/dist/api/material/UnlitMaterial.d.ts +4 -3
  38. package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
  39. package/dist/api/material/_export.d.ts +2 -0
  40. package/dist/api/material/_export.d.ts.map +1 -1
  41. package/dist/api/meshes/IMesh.d.ts +29 -34
  42. package/dist/api/meshes/IMesh.d.ts.map +1 -1
  43. package/dist/api/meshes/IMeshFactory.d.ts +13 -8
  44. package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
  45. package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
  46. package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
  47. package/dist/api/meshes/Mesh.d.ts +11 -57
  48. package/dist/api/meshes/Mesh.d.ts.map +1 -1
  49. package/dist/api/meshes/MeshFactory.d.ts +6 -3
  50. package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
  51. package/dist/api/meshes/QuadMesh.d.ts +3 -5
  52. package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
  53. package/dist/api/meshes/RenderableMesh.d.ts +95 -0
  54. package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
  55. package/dist/api/meshes/_export.d.ts +2 -1
  56. package/dist/api/meshes/_export.d.ts.map +1 -1
  57. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
  58. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
  59. package/dist/api/rendering/IRenderer.d.ts +28 -1
  60. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  61. package/dist/api/rendering/enums.d.ts +7 -0
  62. package/dist/api/rendering/enums.d.ts.map +1 -1
  63. package/dist/api/rendering/renderer-interface.d.ts +1 -31
  64. package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
  65. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
  66. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
  67. package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
  68. package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
  69. package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
  70. package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
  71. package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
  72. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  73. package/dist/api/scene/Scene.d.ts +30 -21
  74. package/dist/api/scene/Scene.d.ts.map +1 -1
  75. package/dist/api/scene/SceneMesh.d.ts +27 -0
  76. package/dist/api/scene/SceneMesh.d.ts.map +1 -0
  77. package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
  78. package/dist/api/window/WindowManager.d.ts.map +1 -1
  79. package/dist/core/rendering/ARenderer.d.ts +5 -5
  80. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  81. package/dist/index.d.ts +0 -1
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +4006 -1355
  84. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
  85. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
  86. package/dist/webgl/WebGlRenderer.d.ts +1 -3
  87. package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
  88. package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
  89. package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
  90. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
  91. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
  92. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
  93. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
  94. package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
  95. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  96. package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
  97. package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
  98. package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
  99. package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
  100. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
  101. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
  102. package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
  103. package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
  104. package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
  105. package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
  106. package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
  107. package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
  108. package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
  109. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
  110. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
  111. package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
  112. package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
  113. package/dist/webgpu/WebGpuTypes.d.ts +355 -0
  114. package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
  115. package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
  116. package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
  117. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
  118. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
  119. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
  120. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
  121. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
  122. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
  123. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
  124. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
  125. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
  126. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
  127. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
  128. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
  129. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
  130. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
  131. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
  132. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
  133. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
  134. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
  135. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
  136. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
  137. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
  138. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
  139. package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
  140. package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
  141. package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
  142. package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
  143. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
  144. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
  145. package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
  146. package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
  147. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
  148. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
  149. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
  150. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
  151. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
  152. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
  153. package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
  154. package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
  155. package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
  156. package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
  157. package/package.json +2 -2
  158. package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
  159. package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
  160. package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
  161. package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
  162. package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
  163. package/shaders/wgsl/sprite.wgsl +40 -0
  164. package/shaders/wgsl/unlit_material.wgsl +49 -0
  165. package/src/Framework.ts +121 -37
  166. package/src/api/IFramework.ts +55 -0
  167. package/src/api/_export.ts +1 -1
  168. package/src/api/content/ContentManager.ts +46 -180
  169. package/src/api/content/IContentManager.ts +25 -21
  170. package/src/api/lights/LightsBuffer.ts +13 -6
  171. package/src/api/loaders/ObjGeometryMapper.ts +2 -2
  172. package/src/api/loaders/ObjLoader.ts +126 -0
  173. package/src/api/loaders/_export.ts +1 -0
  174. package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
  175. package/src/api/loaders/obj/ObjTypes.ts +19 -1
  176. package/src/api/loaders/obj/index.ts +1 -1
  177. package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
  178. package/src/api/material/ICameraMaterial.ts +22 -0
  179. package/src/api/material/ILightsMaterial.ts +32 -0
  180. package/src/api/material/IMaterial.ts +2 -9
  181. package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
  182. package/src/api/material/SpriteMaterial.ts +2 -2
  183. package/src/api/material/UnlitMaterial.ts +4 -3
  184. package/src/api/material/_export.ts +2 -0
  185. package/src/api/meshes/IMesh.ts +32 -37
  186. package/src/api/meshes/IMeshFactory.ts +14 -8
  187. package/src/api/meshes/IRenderableMesh.ts +58 -0
  188. package/src/api/meshes/Mesh.ts +17 -132
  189. package/src/api/meshes/MeshFactory.ts +14 -5
  190. package/src/api/meshes/QuadMesh.ts +4 -6
  191. package/src/api/meshes/RenderableMesh.ts +207 -0
  192. package/src/api/meshes/_export.ts +6 -5
  193. package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
  194. package/src/api/rendering/IRenderer.ts +34 -1
  195. package/src/api/rendering/enums.ts +10 -0
  196. package/src/api/rendering/renderer-interface.ts +1 -36
  197. package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
  198. package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
  199. package/src/api/rendering/texture/TextureFormat.ts +128 -14
  200. package/src/api/rendering/texture/TextureUtilities.ts +225 -10
  201. package/src/api/scene/Scene.ts +102 -69
  202. package/src/api/scene/SceneMesh.ts +61 -0
  203. package/src/api/sprites/SpriteBatchMesh.ts +1 -1
  204. package/src/api/utilities/AlignUtilities.ts +2 -1
  205. package/src/api/window/WindowManager.ts +1 -1
  206. package/src/core/rendering/ARenderer.ts +24 -15
  207. package/src/index.ts +0 -1
  208. package/src/main.ts +2 -3
  209. package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
  210. package/src/webgl/WebGlGpuInfo.ts +1 -1
  211. package/src/webgl/WebGlRenderer.ts +2 -5
  212. package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
  213. package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
  214. package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
  215. package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
  216. package/src/webgl/utilities/WebGlConstants.ts +136 -0
  217. package/src/webgl/utilities/WebGlConverter.ts +91 -22
  218. package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
  219. package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
  220. package/src/webgl/utilities/WebGlUtilities.ts +4 -0
  221. package/src/webgpu/WebGpuGpuInfo.ts +61 -0
  222. package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
  223. package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
  224. package/src/webgpu/WebGpuRenderer.ts +49 -0
  225. package/src/webgpu/WebGpuTypes.ts +288 -0
  226. package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
  227. package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
  228. package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
  229. package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
  230. package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
  231. package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
  232. package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
  233. package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
  234. package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
  235. package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
  236. package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
  237. package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
  238. package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
  239. package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
  240. package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
  241. package/src/webgpu/shader/WgslShaderContent.ts +20 -0
  242. package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
  243. package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
  244. package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
  245. package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
  246. package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
  247. package/src/wgsl-raw.d.ts +4 -0
  248. package/dist/api/FrameworkConfiguration.d.ts +0 -23
  249. package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
  250. package/dist/api/IFrameworkConfiguration.d.ts +0 -25
  251. package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
  252. package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
  253. package/dist/api/meshes/SubMesh.d.ts +0 -47
  254. package/dist/api/meshes/SubMesh.d.ts.map +0 -1
  255. package/src/api/FrameworkConfiguration.ts +0 -29
  256. package/src/api/IFrameworkConfiguration.ts +0 -30
  257. package/src/api/meshes/SubMesh.ts +0 -71
@@ -0,0 +1,118 @@
1
+ import {BufferUsage, type IFramework, type IIndexBuffer, IndexBufferType} from "../../api/index.ts";
2
+ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
3
+ import {GpuBufferUsage, type GpuBuffer, type GpuIndexFormat} from "../WebGpuTypes.ts";
4
+
5
+ /**
6
+ * The WebGPU index buffer. Uses uint16 when every index fits, otherwise uint32.
7
+ * The allocation and the write are padded to 4 bytes, because WebGPU requires it (odd uint16 counts).
8
+ * @internal
9
+ */
10
+ export class WebGpuIndexBuffer implements IIndexBuffer {
11
+
12
+ private readonly _graphicsDevice: WebGpuGraphicsDevice;
13
+ private readonly _label?: string;
14
+ private _type = IndexBufferType.UINT_16;
15
+ private _elementByteSize = 0;
16
+ private _indicesCount = 0;
17
+ private _byteSize = 0;
18
+ private _gpuBuffer: GpuBuffer | null = null;
19
+
20
+ /**
21
+ * The constructor.
22
+ * @param framework The framework.
23
+ * @param label The label.
24
+ */
25
+ public constructor(framework: IFramework, label?: string) {
26
+ this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
27
+ this._label = label;
28
+ }
29
+
30
+ /** @inheritDoc */
31
+ public readonly usage: BufferUsage = BufferUsage.INDEX;
32
+
33
+ /** The WebGPU buffer. */
34
+ public get gpuBuffer(): GpuBuffer {
35
+ if (!this._gpuBuffer) {
36
+ throw new Error("WebGpuIndexBuffer: the buffer is not initialized or is disposed.");
37
+ }
38
+ return this._gpuBuffer;
39
+ }
40
+
41
+ /** The WebGPU index format. */
42
+ public get gpuIndexFormat(): GpuIndexFormat {
43
+ return this._type === IndexBufferType.UINT_16 ? "uint16" : "uint32";
44
+ }
45
+
46
+ /** The buffer size padded to 4 bytes, as used for `setIndexBuffer`. */
47
+ public get paddedByteSize(): number {
48
+ return (this._byteSize + 3) & ~3;
49
+ }
50
+
51
+ /** @inheritDoc */
52
+ public get type(): IndexBufferType {
53
+ return this._type;
54
+ }
55
+
56
+ /** @inheritDoc */
57
+ public get elementByteSize(): number {
58
+ return this._elementByteSize;
59
+ }
60
+
61
+ /** @inheritDoc */
62
+ public get label(): string {
63
+ return this._label ?? "";
64
+ }
65
+
66
+ /** @inheritDoc */
67
+ public get indicesCount(): number {
68
+ return this._indicesCount;
69
+ }
70
+
71
+ /** @inheritDoc */
72
+ public get byteSize(): number {
73
+ return this._byteSize;
74
+ }
75
+
76
+ private static _canUseUint16(values: ArrayLike<number>): boolean {
77
+ for (let i = 0; i < values.length; i++) {
78
+ const v = values[i];
79
+ if (v < 0 || v > 0xFFFF) {
80
+ return false;
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+
86
+ /** @inheritDoc */
87
+ public initialize(data: ArrayLike<number>): void {
88
+ this._gpuBuffer?.destroy();
89
+ const use16 = WebGpuIndexBuffer._canUseUint16(data);
90
+ this._type = use16 ? IndexBufferType.UINT_16 : IndexBufferType.UINT_32;
91
+ this._elementByteSize = use16 ? 2 : 4;
92
+ this._indicesCount = data.length;
93
+ this._byteSize = this._indicesCount * this._elementByteSize;
94
+
95
+ const padded = Math.max(4, this.paddedByteSize);
96
+ // Allocate the padded size so the write below can include the padding.
97
+ const bytes = new ArrayBuffer(padded);
98
+ if (use16) {
99
+ new Uint16Array(bytes, 0, data.length).set(data);
100
+ } else {
101
+ new Uint32Array(bytes, 0, data.length).set(data);
102
+ }
103
+
104
+ const device = this._graphicsDevice.device;
105
+ this._gpuBuffer = device.createBuffer({
106
+ label: this._label,
107
+ size: padded,
108
+ usage: GpuBufferUsage.INDEX | GpuBufferUsage.COPY_DST,
109
+ });
110
+ device.queue.writeBuffer(this._gpuBuffer, 0, bytes, 0, padded);
111
+ }
112
+
113
+ /** @inheritDoc */
114
+ public dispose(): void {
115
+ this._gpuBuffer?.destroy();
116
+ this._gpuBuffer = null;
117
+ }
118
+ }
@@ -0,0 +1,102 @@
1
+ import {type BufferUsage, type IFramework, type IUniformBuffer} from "../../api/index.ts";
2
+ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
3
+ import {GpuBufferUsage, type GpuBuffer} from "../WebGpuTypes.ts";
4
+ import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
5
+
6
+ /**
7
+ * The WebGPU uniform buffer. The size is aligned to 16 bytes and the buffer always has UNIFORM | COPY_DST.
8
+ * @internal
9
+ */
10
+ export class WebGpuUniformBuffer implements IUniformBuffer {
11
+
12
+ private static _nextId = 1;
13
+
14
+ private readonly _graphicsDevice: WebGpuGraphicsDevice;
15
+ private readonly _data: Float32Array;
16
+ private readonly _byteSize: number;
17
+ private _gpuBuffer: GpuBuffer | null = null;
18
+
19
+ /**
20
+ * The constructor.
21
+ * @param framework The framework.
22
+ * @param dataOrFloatCount The initial float data, or the number of floats.
23
+ * @param bufferUsage The buffer usage.
24
+ * @param label The label.
25
+ */
26
+ public constructor(framework: IFramework, dataOrFloatCount: ArrayLike<number> | number, bufferUsage: BufferUsage, label?: string) {
27
+ this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
28
+ this.usage = bufferUsage;
29
+ this.label = label;
30
+ this.id = WebGpuUniformBuffer._nextId++;
31
+ const floatCount = typeof dataOrFloatCount === "number" ? dataOrFloatCount : dataOrFloatCount.length;
32
+ // Uniform buffer bindings must be a multiple of 16 bytes.
33
+ const alignedFloats = Math.max(4, Math.ceil(floatCount / 4) * 4);
34
+ this._data = new Float32Array(alignedFloats);
35
+ if (typeof dataOrFloatCount !== "number") {
36
+ this._data.set(dataOrFloatCount);
37
+ }
38
+ this._byteSize = this._data.byteLength;
39
+ }
40
+
41
+ /** A unique id, used to cache bind groups. */
42
+ public readonly id: number;
43
+
44
+ /** @inheritDoc */
45
+ public readonly label?: string;
46
+
47
+ /** @inheritDoc */
48
+ public readonly usage: BufferUsage;
49
+
50
+ /** @inheritDoc */
51
+ public get byteSize(): number {
52
+ return this._byteSize;
53
+ }
54
+
55
+ /** The WebGPU buffer. */
56
+ public get gpuBuffer(): GpuBuffer {
57
+ if (!this._gpuBuffer) {
58
+ throw new Error("WebGpuUniformBuffer: the buffer is not initialized or is disposed.");
59
+ }
60
+ return this._gpuBuffer;
61
+ }
62
+
63
+ /** @inheritDoc */
64
+ public initialize(): void {
65
+ const device = this._graphicsDevice.device;
66
+ this._gpuBuffer = device.createBuffer({
67
+ label: this.label,
68
+ size: this._byteSize,
69
+ usage: WebGpuConverter.convertBufferUsage(this.usage) | GpuBufferUsage.UNIFORM | GpuBufferUsage.COPY_DST,
70
+ });
71
+ device.queue.writeBuffer(this._gpuBuffer, 0, this._data.buffer, this._data.byteOffset, this._data.byteLength);
72
+ }
73
+
74
+ /**
75
+ * Updates the buffer. Only the data's length is written.
76
+ * @param data The float data.
77
+ * @param offset The first float to write.
78
+ * @param length The number of floats to write; defaults to the data's length after the offset.
79
+ */
80
+ public update(data: ArrayLike<number>, offset: number = 0, length?: number): void {
81
+ let count = length ?? data.length - offset;
82
+ count = Math.min(count, this._data.length - offset, data.length - offset);
83
+ if (count <= 0) {
84
+ return;
85
+ }
86
+ for (let i = 0; i < count; i++) {
87
+ this._data[offset + i] = data[offset + i];
88
+ }
89
+ this._graphicsDevice.device.queue.writeBuffer(
90
+ this.gpuBuffer,
91
+ offset * Float32Array.BYTES_PER_ELEMENT,
92
+ this._data.buffer,
93
+ this._data.byteOffset + offset * Float32Array.BYTES_PER_ELEMENT,
94
+ count * Float32Array.BYTES_PER_ELEMENT);
95
+ }
96
+
97
+ /** @inheritDoc */
98
+ public dispose(): void {
99
+ this._gpuBuffer?.destroy();
100
+ this._gpuBuffer = null;
101
+ }
102
+ }
@@ -0,0 +1,119 @@
1
+ import {BufferUsage, type IFramework, type IVertexBuffer} from "../../api/index.ts";
2
+ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
3
+ import {GpuBufferUsage, type GpuBuffer} from "../WebGpuTypes.ts";
4
+ import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
5
+
6
+ /**
7
+ * The WebGPU vertex buffer. Always created with COPY_DST so it can be updated.
8
+ * @internal
9
+ */
10
+ export class WebGpuVertexBuffer implements IVertexBuffer {
11
+
12
+ private readonly _graphicsDevice: WebGpuGraphicsDevice;
13
+ private readonly _data: Float32Array;
14
+ private readonly _vertexCount: number;
15
+ private readonly _byteSize: number;
16
+ private _gpuBuffer: GpuBuffer | null = null;
17
+
18
+ /**
19
+ * The constructor.
20
+ * @param framework The framework.
21
+ * @param dataOrVertexCount The float vertex data, or the number of vertices to allocate.
22
+ * @param _byteStride The vertex stride in bytes.
23
+ * @param _bufferUsage The buffer usage.
24
+ * @param _label The label.
25
+ */
26
+ public constructor(framework: IFramework,
27
+ dataOrVertexCount: ArrayLike<number> | number,
28
+ private readonly _byteStride: number,
29
+ private readonly _bufferUsage: BufferUsage,
30
+ private readonly _label?: string) {
31
+ this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
32
+ if (typeof dataOrVertexCount === "number") {
33
+ this._vertexCount = dataOrVertexCount;
34
+ this._byteSize = dataOrVertexCount * this._byteStride;
35
+ this._data = new Float32Array(this._byteSize / Float32Array.BYTES_PER_ELEMENT);
36
+ } else {
37
+ this._data = new Float32Array(dataOrVertexCount);
38
+ this._byteSize = this._data.byteLength;
39
+ this._vertexCount = this._byteSize / this._byteStride;
40
+ }
41
+ }
42
+
43
+ /** The WebGPU buffer. */
44
+ public get gpuBuffer(): GpuBuffer {
45
+ if (!this._gpuBuffer) {
46
+ throw new Error("WebGpuVertexBuffer: the buffer is not initialized or is disposed.");
47
+ }
48
+ return this._gpuBuffer;
49
+ }
50
+
51
+ /** @inheritDoc */
52
+ public get label(): string | undefined {
53
+ return this._label;
54
+ }
55
+
56
+ /** @inheritDoc */
57
+ public get vertexCount(): number {
58
+ return this._vertexCount;
59
+ }
60
+
61
+ /** @inheritDoc */
62
+ public get byteSize(): number {
63
+ return this._byteSize;
64
+ }
65
+
66
+ /** @inheritDoc */
67
+ public get byteStride(): number {
68
+ return this._byteStride;
69
+ }
70
+
71
+ /** @inheritDoc */
72
+ public get usage(): BufferUsage {
73
+ return this._bufferUsage;
74
+ }
75
+
76
+ /** @inheritDoc */
77
+ public initialize(): void {
78
+ const device = this._graphicsDevice.device;
79
+ // WebGPU buffer sizes must be a multiple of 4; float data always is.
80
+ this._gpuBuffer = device.createBuffer({
81
+ label: this._label,
82
+ size: Math.max(4, this._byteSize),
83
+ usage: WebGpuConverter.convertBufferUsage(this._bufferUsage) | GpuBufferUsage.VERTEX | GpuBufferUsage.COPY_DST,
84
+ });
85
+ if (this._data.length > 0) {
86
+ device.queue.writeBuffer(this._gpuBuffer, 0, this._data.buffer, this._data.byteOffset, this._data.byteLength);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Updates the buffer.
92
+ * @param data The float data.
93
+ * @param offset The first float to write (in floats, like WebGL).
94
+ * @param length The number of floats to write; 0 writes the whole data.
95
+ */
96
+ public update(data: number[], offset: number = 0, length: number = 0): void {
97
+ length = length > 0 ? length : data.length - offset;
98
+ length = Math.min(length, this._data.length - offset, data.length - offset);
99
+ if (length <= 0) {
100
+ return;
101
+ }
102
+ for (let i = 0; i < length; ++i) {
103
+ this._data[offset + i] = data[offset + i];
104
+ }
105
+ // Write only the changed range, not the whole buffer.
106
+ this._graphicsDevice.device.queue.writeBuffer(
107
+ this.gpuBuffer,
108
+ offset * Float32Array.BYTES_PER_ELEMENT,
109
+ this._data.buffer,
110
+ this._data.byteOffset + offset * Float32Array.BYTES_PER_ELEMENT,
111
+ length * Float32Array.BYTES_PER_ELEMENT);
112
+ }
113
+
114
+ /** @inheritDoc */
115
+ public dispose(): void {
116
+ this._gpuBuffer?.destroy();
117
+ this._gpuBuffer = null;
118
+ }
119
+ }
@@ -0,0 +1,52 @@
1
+ import {
2
+ type CullMode,
3
+ type FrontFace,
4
+ type IPrimitiveState,
5
+ type PrimitiveStateDescriptor,
6
+ type PrimitiveTopology,
7
+ } from "../../api/index.ts";
8
+ import type {GpuCullMode, GpuFrontFace, GpuPrimitiveTopology} from "../WebGpuTypes.ts";
9
+ import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
10
+
11
+ /**
12
+ * The WebGPU primitive state. WebGPU bakes it into the render pipeline, so this only holds the converted values.
13
+ * @internal
14
+ */
15
+ export class WebGpuPrimitiveState implements IPrimitiveState {
16
+
17
+ /**
18
+ * The constructor.
19
+ * @param descriptor The primitive state descriptor.
20
+ */
21
+ public constructor(descriptor: PrimitiveStateDescriptor) {
22
+ this.topology = descriptor.topology;
23
+ this.cullFace = descriptor.cullFace;
24
+ this.frontFace = descriptor.frontFace;
25
+ this.gpuTopology = WebGpuConverter.convertTopology(this.topology);
26
+ this.gpuCullMode = WebGpuConverter.convertCullMode(this.cullFace);
27
+ this.gpuFrontFace = WebGpuConverter.convertFrontFace(this.frontFace);
28
+ }
29
+
30
+ /** @inheritDoc */
31
+ public readonly topology: PrimitiveTopology;
32
+
33
+ /** @inheritDoc */
34
+ public readonly cullFace: CullMode;
35
+
36
+ /** @inheritDoc */
37
+ public readonly frontFace: FrontFace;
38
+
39
+ /** The WebGPU topology. */
40
+ public readonly gpuTopology: GpuPrimitiveTopology;
41
+
42
+ /** The WebGPU cull mode. */
43
+ public readonly gpuCullMode: GpuCullMode;
44
+
45
+ /** The WebGPU front face. */
46
+ public readonly gpuFrontFace: GpuFrontFace;
47
+
48
+ /** The `GPUPrimitiveState` for a render pipeline. */
49
+ public get gpuPrimitiveState(): { topology: GpuPrimitiveTopology; cullMode: GpuCullMode; frontFace: GpuFrontFace } {
50
+ return {topology: this.gpuTopology, cullMode: this.gpuCullMode, frontFace: this.gpuFrontFace};
51
+ }
52
+ }
@@ -0,0 +1,131 @@
1
+ import {
2
+ type IRenderPass,
3
+ LoadAction,
4
+ type RenderPassDescriptor,
5
+ StoreAction,
6
+ } from "../../api/index.ts";
7
+ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
8
+ import type {
9
+ GpuCommandEncoder,
10
+ GpuRenderPassColorAttachment,
11
+ GpuRenderPassDepthStencilAttachment,
12
+ GpuRenderPassDescriptor,
13
+ } from "../WebGpuTypes.ts";
14
+ import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
15
+ import {WebGpuTexture2D} from "../texture/WebGpuTexture2D.ts";
16
+ import {WebGpuTextureView} from "../texture/WebGpuTextureView.ts";
17
+ import type {WebGpuSwapChain} from "../swap-chain/WebGpuSwapChain.ts";
18
+
19
+ /**
20
+ * The WebGPU render pass. `beginPass` creates a command encoder and begins a render pass,
21
+ * `endPass` ends it and submits the command buffer, like the C# `WebGPURenderPass`.
22
+ * @internal
23
+ */
24
+ export class WebGpuRenderPass implements IRenderPass {
25
+
26
+ private readonly _graphicsDevice: WebGpuGraphicsDevice;
27
+ private readonly _descriptor: RenderPassDescriptor;
28
+ private _commandEncoder: GpuCommandEncoder | null = null;
29
+
30
+ /**
31
+ * The constructor.
32
+ * @param graphicsDevice The graphics device.
33
+ * @param descriptor The render pass descriptor.
34
+ */
35
+ public constructor(graphicsDevice: WebGpuGraphicsDevice, descriptor: RenderPassDescriptor) {
36
+ this._graphicsDevice = graphicsDevice;
37
+ this._descriptor = descriptor;
38
+ if (!descriptor.colorAttachments || descriptor.colorAttachments.length === 0) {
39
+ throw new Error("WebGpuRenderPass: at least one color attachment is required.");
40
+ }
41
+ }
42
+
43
+ private _buildDescriptor(): GpuRenderPassDescriptor {
44
+ const colorAttachments: GpuRenderPassColorAttachment[] = this._descriptor.colorAttachments!.map(attachment => {
45
+ let view;
46
+ if (attachment.swapChain) {
47
+ view = (attachment.swapChain as WebGpuSwapChain).currentTextureView;
48
+ } else if (attachment.view) {
49
+ view = (attachment.view as WebGpuTextureView).gpuTextureView;
50
+ } else if (attachment.texture) {
51
+ view = (attachment.texture as WebGpuTexture2D).gpuDefaultView;
52
+ } else {
53
+ throw new Error("WebGpuRenderPass: a color attachment needs a swap chain, view or texture.");
54
+ }
55
+ const c = attachment.clearColor;
56
+ return {
57
+ view,
58
+ resolveTarget: attachment.resolveView
59
+ ? (attachment.resolveView as WebGpuTextureView).gpuTextureView
60
+ : attachment.resolveTexture ? (attachment.resolveTexture as WebGpuTexture2D).gpuDefaultView : undefined,
61
+ clearValue: {r: c.r, g: c.g, b: c.b, a: c.a},
62
+ loadOp: WebGpuConverter.convertLoadAction(attachment.loadAction),
63
+ storeOp: WebGpuConverter.convertStoreAction(attachment.storeAction),
64
+ };
65
+ });
66
+
67
+ const result: GpuRenderPassDescriptor = {
68
+ label: this._descriptor.label,
69
+ colorAttachments,
70
+ };
71
+
72
+ const depth = this._descriptor.depthStencilAttachment;
73
+ if (depth && (depth.texture || depth.view)) {
74
+ const texture = depth.texture as WebGpuTexture2D | undefined;
75
+ const format = depth.view?.textureFormat ?? texture!.textureFormat;
76
+ const attachment: GpuRenderPassDepthStencilAttachment = {
77
+ view: depth.view ? (depth.view as WebGpuTextureView).gpuTextureView : texture!.gpuDefaultView,
78
+ depthClearValue: depth.depthClearValue,
79
+ depthLoadOp: WebGpuConverter.convertLoadAction(depth.depthLoadAction),
80
+ depthStoreOp: WebGpuConverter.convertStoreAction(depth.depthStoreAction),
81
+ };
82
+ // Stencil ops are only valid when the format has a stencil aspect.
83
+ if (WebGpuConverter.hasStencil(format)) {
84
+ attachment.stencilClearValue = depth.stencilClearValue;
85
+ attachment.stencilLoadOp = depth.stencilLoadAction === LoadAction.LOAD ? "load" : "clear";
86
+ attachment.stencilStoreOp = depth.stencilStoreAction === StoreAction.DISCARD ? "discard" : "store";
87
+ }
88
+ result.depthStencilAttachment = attachment;
89
+ }
90
+ // A depth attachment without a texture would need an internal depth buffer (WebGL uses a renderbuffer).
91
+ // TODO: create an internal depth texture for that case.
92
+
93
+ return result;
94
+ }
95
+
96
+ /** Whether the pass has a depth attachment. */
97
+ public get hasDepthStencil(): boolean {
98
+ const depth = this._descriptor.depthStencilAttachment;
99
+ return !!depth && !!(depth.texture || depth.view);
100
+ }
101
+
102
+ /** @inheritDoc */
103
+ public beginPass(): void {
104
+ if (this._commandEncoder) {
105
+ throw new Error("WebGpuRenderPass: the pass is already open.");
106
+ }
107
+ const device = this._graphicsDevice.device;
108
+ this._commandEncoder = device.createCommandEncoder({label: this._descriptor.label});
109
+ this._graphicsDevice.currentRenderPassEncoder = this._commandEncoder.beginRenderPass(this._buildDescriptor());
110
+ }
111
+
112
+ /** @inheritDoc */
113
+ public endPass(): void {
114
+ if (!this._commandEncoder) {
115
+ return;
116
+ }
117
+ this._graphicsDevice.currentRenderPassEncoder?.end();
118
+ this._graphicsDevice.currentRenderPassEncoder = null;
119
+ this._graphicsDevice.device.queue.submit([this._commandEncoder.finish()]);
120
+ this._commandEncoder = null;
121
+ }
122
+
123
+ /** @inheritDoc */
124
+ public dispose(): void {
125
+ if (this._commandEncoder) {
126
+ this._graphicsDevice.currentRenderPassEncoder?.end();
127
+ this._graphicsDevice.currentRenderPassEncoder = null;
128
+ this._commandEncoder = null;
129
+ }
130
+ }
131
+ }
@@ -0,0 +1,123 @@
1
+ import {
2
+ GeometryFormat,
3
+ type IBlendState,
4
+ type IFramework,
5
+ type IIndexBuffer,
6
+ type IPrimitiveState,
7
+ type IRenderPipeline,
8
+ type IVertexBuffer,
9
+ TextureFormat,
10
+ } from "../../api/index.ts";
11
+ import type {VertexBufferLayout} from "../../core/rendering/vertex-buffer-layout.ts";
12
+ import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
13
+ import type {WebGpuBlendState} from "../blending/WebGpuBlendState.ts";
14
+ import type {WebGpuPrimitiveState} from "../primitive/WebGpuPrimitiveState.ts";
15
+ import type {WebGpuSampler} from "../sampler/WebGpuSampler.ts";
16
+ import type {
17
+ GpuBindGroupLayout,
18
+ GpuPipelineLayout,
19
+ GpuRenderPipeline,
20
+ GpuShaderModule,
21
+ } from "../WebGpuTypes.ts";
22
+ import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
23
+
24
+ /**
25
+ * The base WebGPU render pipeline. Holds the device, the states and the vertex layouts,
26
+ * and builds the `GPURenderPipeline` from them.
27
+ * @internal
28
+ */
29
+ export abstract class AWebGpuRenderPipeline implements IRenderPipeline {
30
+
31
+ protected readonly _framework: IFramework;
32
+ protected readonly _graphicsDevice: WebGpuGraphicsDevice;
33
+ protected readonly _defaultTextureSampler: WebGpuSampler;
34
+ protected _blendState: WebGpuBlendState;
35
+ protected _gpuPipeline: GpuRenderPipeline | null = null;
36
+ protected _pipelineLayout: GpuPipelineLayout | null = null;
37
+
38
+ /**
39
+ * The constructor.
40
+ * @param framework The framework.
41
+ * @param primitiveState The optional primitive state; defaults to the device's.
42
+ */
43
+ protected constructor(framework: IFramework, primitiveState?: IPrimitiveState) {
44
+ this._framework = framework;
45
+ this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
46
+ this._blendState = this._graphicsDevice.defaultBlendState as WebGpuBlendState;
47
+ this._defaultTextureSampler = this._graphicsDevice.defaultTextureSampler as WebGpuSampler;
48
+ this.primitiveState = (primitiveState ?? this._graphicsDevice.defaultPrimitiveState) as WebGpuPrimitiveState;
49
+ }
50
+
51
+ /** @inheritDoc */
52
+ public abstract readonly geometryFormat: GeometryFormat;
53
+
54
+ /** @inheritDoc */
55
+ public get blendState(): IBlendState {
56
+ return this._blendState;
57
+ }
58
+
59
+ /** @inheritDoc */
60
+ public readonly primitiveState: WebGpuPrimitiveState;
61
+
62
+ /** @inheritDoc */
63
+ public vertexBufferLayouts: VertexBufferLayout[] = null!;
64
+
65
+ /** @inheritDoc */
66
+ public abstract initialize(): void;
67
+
68
+ /** @inheritDoc */
69
+ public abstract render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount?: number, indicesOffset?: number): void;
70
+
71
+ /**
72
+ * Creates the pipeline layout and the render pipeline.
73
+ * @param label The label.
74
+ * @param module The WGSL module with `main_vs` and `main_fs`.
75
+ * @param bindGroupLayouts The bind group layouts, in group order.
76
+ * @param colorFormat The color target format.
77
+ * @param depthStencilFormat The depth format, or undefined when the pass has no depth attachment.
78
+ */
79
+ protected _createGpuPipeline(
80
+ label: string,
81
+ module: GpuShaderModule,
82
+ bindGroupLayouts: GpuBindGroupLayout[],
83
+ colorFormat: TextureFormat,
84
+ depthStencilFormat?: TextureFormat): void {
85
+
86
+ if (!this.vertexBufferLayouts || this.vertexBufferLayouts.length === 0) {
87
+ throw new Error("At least one vertex buffer layout must be provided for the render pipeline.");
88
+ }
89
+ const device = this._graphicsDevice.device;
90
+ this._pipelineLayout = device.createPipelineLayout({label: `${label} layout`, bindGroupLayouts});
91
+ this._gpuPipeline = device.createRenderPipeline({
92
+ label,
93
+ layout: this._pipelineLayout,
94
+ vertex: {
95
+ module,
96
+ entryPoint: "main_vs",
97
+ buffers: this.vertexBufferLayouts.map(l => WebGpuConverter.convertVertexBufferLayout(l)),
98
+ },
99
+ fragment: {
100
+ module,
101
+ entryPoint: "main_fs",
102
+ targets: [{
103
+ format: WebGpuConverter.convertTextureFormat(colorFormat),
104
+ blend: this._blendState.gpuBlendState,
105
+ }],
106
+ },
107
+ primitive: this.primitiveState.gpuPrimitiveState,
108
+ depthStencil: depthStencilFormat !== undefined ? {
109
+ format: WebGpuConverter.convertTextureFormat(depthStencilFormat),
110
+ depthWriteEnabled: true,
111
+ // Matches the WebGL backend's LEQUAL.
112
+ depthCompare: "less-equal",
113
+ } : undefined,
114
+ });
115
+ }
116
+
117
+ /** @inheritDoc */
118
+ public dispose(): void {
119
+ // Pipelines and layouts have no destroy() in WebGPU.
120
+ this._gpuPipeline = null;
121
+ this._pipelineLayout = null;
122
+ }
123
+ }