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.
- package/CHANGELOG.md +22 -29
- package/README.md +13 -1
- package/dist/Framework.d.ts +26 -8
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +43 -0
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +1 -1
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +5 -57
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +24 -21
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/lights/LightsBuffer.d.ts +13 -6
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -1
- package/dist/api/loaders/ObjGeometryMapper.d.ts +2 -2
- package/dist/api/loaders/ObjLoader.d.ts +61 -0
- package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +1 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/{ObjLoader.d.ts → ObjParser.d.ts} +20 -5
- package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +17 -1
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -1
- package/dist/api/loaders/obj/index.d.ts +1 -1
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +22 -11
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
- package/dist/api/material/ICameraMaterial.d.ts +18 -0
- package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
- package/dist/api/material/ILightsMaterial.d.ts +26 -0
- package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +2 -8
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +2 -2
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +2 -2
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
- package/dist/api/material/UnlitMaterial.d.ts +4 -3
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +2 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +29 -34
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +13 -8
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/Mesh.d.ts +11 -57
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +6 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +3 -5
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +95 -0
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +2 -1
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +28 -1
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +7 -0
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/renderer-interface.d.ts +1 -31
- package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
- package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
- package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
- package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +30 -21
- package/dist/api/scene/Scene.d.ts.map +1 -1
- package/dist/api/scene/SceneMesh.d.ts +27 -0
- package/dist/api/scene/SceneMesh.d.ts.map +1 -0
- package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +5 -5
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4006 -1355
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/webgl/WebGlRenderer.d.ts +1 -3
- package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +8 -4
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +2 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
- package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
- package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
- package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
- package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
- package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
- package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
- package/dist/webgpu/WebGpuTypes.d.ts +355 -0
- package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
- package/package.json +2 -2
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
- package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
- package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
- package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
- package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
- package/shaders/wgsl/sprite.wgsl +40 -0
- package/shaders/wgsl/unlit_material.wgsl +49 -0
- package/src/Framework.ts +121 -37
- package/src/api/IFramework.ts +55 -0
- package/src/api/_export.ts +1 -1
- package/src/api/content/ContentManager.ts +46 -180
- package/src/api/content/IContentManager.ts +25 -21
- package/src/api/lights/LightsBuffer.ts +13 -6
- package/src/api/loaders/ObjGeometryMapper.ts +2 -2
- package/src/api/loaders/ObjLoader.ts +126 -0
- package/src/api/loaders/_export.ts +1 -0
- package/src/api/loaders/obj/{ObjLoader.ts → ObjParser.ts} +35 -4
- package/src/api/loaders/obj/ObjTypes.ts +19 -1
- package/src/api/loaders/obj/index.ts +1 -1
- package/src/api/material/ForwardBlinnPhongMaterial.ts +48 -22
- package/src/api/material/ICameraMaterial.ts +22 -0
- package/src/api/material/ILightsMaterial.ts +32 -0
- package/src/api/material/IMaterial.ts +2 -9
- package/src/api/material/InspectTextureMipsMaterial.ts +2 -2
- package/src/api/material/SpriteMaterial.ts +2 -2
- package/src/api/material/UnlitMaterial.ts +4 -3
- package/src/api/material/_export.ts +2 -0
- package/src/api/meshes/IMesh.ts +32 -37
- package/src/api/meshes/IMeshFactory.ts +14 -8
- package/src/api/meshes/IRenderableMesh.ts +58 -0
- package/src/api/meshes/Mesh.ts +17 -132
- package/src/api/meshes/MeshFactory.ts +14 -5
- package/src/api/meshes/QuadMesh.ts +4 -6
- package/src/api/meshes/RenderableMesh.ts +207 -0
- package/src/api/meshes/_export.ts +6 -5
- package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
- package/src/api/rendering/IRenderer.ts +34 -1
- package/src/api/rendering/enums.ts +10 -0
- package/src/api/rendering/renderer-interface.ts +1 -36
- package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
- package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
- package/src/api/rendering/texture/TextureFormat.ts +128 -14
- package/src/api/rendering/texture/TextureUtilities.ts +225 -10
- package/src/api/scene/Scene.ts +102 -69
- package/src/api/scene/SceneMesh.ts +61 -0
- package/src/api/sprites/SpriteBatchMesh.ts +1 -1
- package/src/api/utilities/AlignUtilities.ts +2 -1
- package/src/api/window/WindowManager.ts +1 -1
- package/src/core/rendering/ARenderer.ts +24 -15
- package/src/index.ts +0 -1
- package/src/main.ts +2 -3
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
- package/src/webgl/WebGlGpuInfo.ts +1 -1
- package/src/webgl/WebGlRenderer.ts +2 -5
- package/src/webgl/lights/WebGlLightsBuffer.ts +14 -4
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +18 -1
- package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
- package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
- package/src/webgl/utilities/WebGlConstants.ts +136 -0
- package/src/webgl/utilities/WebGlConverter.ts +91 -22
- package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
- package/src/webgl/utilities/WebGlUtilities.ts +4 -0
- package/src/webgpu/WebGpuGpuInfo.ts +61 -0
- package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
- package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
- package/src/webgpu/WebGpuRenderer.ts +49 -0
- package/src/webgpu/WebGpuTypes.ts +288 -0
- package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
- package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
- package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
- package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
- package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
- package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
- package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
- package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
- package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
- package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
- package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
- package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
- package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
- package/src/webgpu/shader/WgslShaderContent.ts +20 -0
- package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
- package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
- package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
- package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
- package/src/wgsl-raw.d.ts +4 -0
- package/dist/api/FrameworkConfiguration.d.ts +0 -23
- package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/IFrameworkConfiguration.d.ts +0 -25
- package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/loaders/obj/ObjLoader.d.ts.map +0 -1
- package/dist/api/meshes/SubMesh.d.ts +0 -47
- package/dist/api/meshes/SubMesh.d.ts.map +0 -1
- package/src/api/FrameworkConfiguration.ts +0 -29
- package/src/api/IFrameworkConfiguration.ts +0 -30
- package/src/api/meshes/SubMesh.ts +0 -71
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {AGraphicsDevice, type IGraphicsDeviceDescriptor} from "../core/rendering/AGraphicsDevice.ts";
|
|
2
|
+
import type {BlendStateDescriptor} from "../core/rendering/blending/blend-state-descriptor.ts";
|
|
3
|
+
import type {SamplerDescriptor} from "../core/rendering/sampler/sampler-descriptor.ts";
|
|
4
|
+
import {
|
|
5
|
+
type IBlendState,
|
|
6
|
+
type IGPUInfo,
|
|
7
|
+
type IPrimitiveState,
|
|
8
|
+
type IRenderPass,
|
|
9
|
+
type ISampler,
|
|
10
|
+
type ISwapChain,
|
|
11
|
+
type IWindowManager,
|
|
12
|
+
PrimitiveStateDescriptor,
|
|
13
|
+
RenderPassDescriptor,
|
|
14
|
+
SwapChainDescriptor,
|
|
15
|
+
} from "../api/index.ts";
|
|
16
|
+
import {getNavigatorGpu, type GpuAdapter, type GpuDevice, type GpuRenderPassEncoder} from "./WebGpuTypes.ts";
|
|
17
|
+
import {PowerPreferenceType} from "../api/rendering/PowerPreference.ts";
|
|
18
|
+
import {WebGpuGraphicsDeviceFeatures} from "./WebGpuGraphicsDeviceFeatures.ts";
|
|
19
|
+
import {WebGpuGpuInfo} from "./WebGpuGpuInfo.ts";
|
|
20
|
+
import {WebGpuSwapChain} from "./swap-chain/WebGpuSwapChain.ts";
|
|
21
|
+
import {WebGpuSampler} from "./sampler/WebGpuSampler.ts";
|
|
22
|
+
import {WebGpuRenderPass} from "./render-pass/WebGpuRenderPass.ts";
|
|
23
|
+
import {WebGpuBlendState} from "./blending/WebGpuBlendState.ts";
|
|
24
|
+
import {WebGpuPrimitiveState} from "./primitive/WebGpuPrimitiveState.ts";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The WebGPU graphics device. It requests its own adapter and device in {@link createAsync},
|
|
28
|
+
* so everything after creation is synchronous like WebGL.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export class WebGpuGraphicsDevice extends AGraphicsDevice {
|
|
32
|
+
|
|
33
|
+
private readonly _windowManager: IWindowManager;
|
|
34
|
+
private readonly _adapter: GpuAdapter;
|
|
35
|
+
private readonly _device: GpuDevice;
|
|
36
|
+
private _features: WebGpuGraphicsDeviceFeatures = null!;
|
|
37
|
+
private _gpuInfo: WebGpuGpuInfo = null!;
|
|
38
|
+
private _swapChain: WebGpuSwapChain | null = null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The render pass encoder of the pass that is currently open, or null between passes.
|
|
42
|
+
* Set by {@link WebGpuRenderPass.beginPass}, like `currentRenderPassEncoder` in the C# device.
|
|
43
|
+
*/
|
|
44
|
+
public currentRenderPassEncoder: GpuRenderPassEncoder | null = null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates the graphics device: requests the WebGPU adapter and device.
|
|
48
|
+
* Throws when WebGPU is unavailable or no adapter is found.
|
|
49
|
+
* @param windowManager The window manager.
|
|
50
|
+
* @param descriptor The device descriptor.
|
|
51
|
+
* @returns The created graphics device.
|
|
52
|
+
*/
|
|
53
|
+
public static async createAsync(windowManager: IWindowManager, descriptor: IGraphicsDeviceDescriptor): Promise<WebGpuGraphicsDevice> {
|
|
54
|
+
const gpu = getNavigatorGpu();
|
|
55
|
+
if (!gpu) {
|
|
56
|
+
throw new Error("WebGPU is not supported: navigator.gpu is missing.");
|
|
57
|
+
}
|
|
58
|
+
const preference = descriptor.powerPreference;
|
|
59
|
+
const adapter = await gpu.requestAdapter(
|
|
60
|
+
preference && preference !== PowerPreferenceType.DEFAULT
|
|
61
|
+
? {powerPreference: preference as unknown as "low-power" | "high-performance"}
|
|
62
|
+
: undefined);
|
|
63
|
+
if (!adapter) {
|
|
64
|
+
throw new Error("WebGPU is not supported: no adapter was found.");
|
|
65
|
+
}
|
|
66
|
+
// WebGPU only enables the features that are requested, so ask for every compression family the adapter has.
|
|
67
|
+
const requiredFeatures = ["texture-compression-bc", "texture-compression-etc2", "texture-compression-astc"]
|
|
68
|
+
.filter(feature => adapter.features.has(feature));
|
|
69
|
+
const device = await adapter.requestDevice({label: "RisFramework WebGPU device", requiredFeatures});
|
|
70
|
+
return new WebGpuGraphicsDevice(windowManager, descriptor, adapter, device);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The constructor. Use {@link createAsync} to create the device.
|
|
75
|
+
* @param windowManager The window manager.
|
|
76
|
+
* @param descriptor The device descriptor.
|
|
77
|
+
* @param adapter The WebGPU adapter.
|
|
78
|
+
* @param device The WebGPU device.
|
|
79
|
+
*/
|
|
80
|
+
private constructor(windowManager: IWindowManager, descriptor: IGraphicsDeviceDescriptor, adapter: GpuAdapter, device: GpuDevice) {
|
|
81
|
+
super(descriptor);
|
|
82
|
+
this._windowManager = windowManager;
|
|
83
|
+
this._adapter = adapter;
|
|
84
|
+
this._device = device;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The WebGPU device. */
|
|
88
|
+
public get device(): GpuDevice {
|
|
89
|
+
return this._device;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The WebGPU adapter. */
|
|
93
|
+
public get adapter(): GpuAdapter {
|
|
94
|
+
return this._adapter;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Whether the canvas should keep its alpha channel. */
|
|
98
|
+
public get alpha(): boolean {
|
|
99
|
+
return this._descriptor.alpha;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The swap chain, once created. */
|
|
103
|
+
public get swapChain(): WebGpuSwapChain | null {
|
|
104
|
+
return this._swapChain;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The window manager. */
|
|
108
|
+
public get windowManager(): IWindowManager {
|
|
109
|
+
return this._windowManager;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** @inheritDoc */
|
|
113
|
+
public get features(): WebGpuGraphicsDeviceFeatures {
|
|
114
|
+
return this._features;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @inheritDoc */
|
|
118
|
+
public get gpuInfo(): IGPUInfo {
|
|
119
|
+
return this._gpuInfo;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The current render pass encoder. Throws when no pass is open. */
|
|
123
|
+
public get renderPassEncoder(): GpuRenderPassEncoder {
|
|
124
|
+
if (!this.currentRenderPassEncoder) {
|
|
125
|
+
throw new Error("WebGpuGraphicsDevice: no render pass is open. Draw calls must happen between beginRenderPass and endRenderPass.");
|
|
126
|
+
}
|
|
127
|
+
return this.currentRenderPassEncoder;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @inheritDoc */
|
|
131
|
+
public initialize(): void {
|
|
132
|
+
this._features = new WebGpuGraphicsDeviceFeatures(this._device.features);
|
|
133
|
+
this._gpuInfo = new WebGpuGpuInfo(this._adapter, this._features);
|
|
134
|
+
this.setupDebugCallback();
|
|
135
|
+
super.initialize();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @inheritDoc */
|
|
139
|
+
public createSwapChain(canvas: HTMLCanvasElement, descriptor: SwapChainDescriptor): ISwapChain {
|
|
140
|
+
this._swapChain?.dispose();
|
|
141
|
+
this._swapChain = new WebGpuSwapChain(canvas, this, descriptor);
|
|
142
|
+
return this._swapChain;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @inheritDoc */
|
|
146
|
+
public createSampler(descriptor?: SamplerDescriptor): ISampler {
|
|
147
|
+
return new WebGpuSampler(this, descriptor);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @inheritDoc */
|
|
151
|
+
public createRenderPass(descriptor: RenderPassDescriptor): IRenderPass {
|
|
152
|
+
return new WebGpuRenderPass(this, descriptor);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** @inheritDoc */
|
|
156
|
+
public createBlendState(descriptor: BlendStateDescriptor): IBlendState {
|
|
157
|
+
return new WebGpuBlendState(descriptor);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** @inheritDoc */
|
|
161
|
+
public createPrimitiveState(descriptor?: PrimitiveStateDescriptor): IPrimitiveState {
|
|
162
|
+
return new WebGpuPrimitiveState(descriptor ?? new PrimitiveStateDescriptor());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @inheritDoc */
|
|
166
|
+
public setupDebugCallback(): void {
|
|
167
|
+
this._device.addEventListener("uncapturederror", event => {
|
|
168
|
+
console.error(`WebGPU error: ${event.error.message}`);
|
|
169
|
+
});
|
|
170
|
+
this._device.lost.then(info => {
|
|
171
|
+
if (info.reason !== "destroyed") {
|
|
172
|
+
console.error(`WebGPU device lost (${info.reason}): ${info.message}`);
|
|
173
|
+
}
|
|
174
|
+
}).catch(() => { /* ignore */ });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @inheritDoc */
|
|
178
|
+
public frameEnd(): void {
|
|
179
|
+
// Command buffers are submitted at the end of every render pass, so nothing is pending here.
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** @inheritDoc */
|
|
183
|
+
public pushDebugGroup(groupName: string): void {
|
|
184
|
+
this.currentRenderPassEncoder?.pushDebugGroup(groupName);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @inheritDoc */
|
|
188
|
+
public popDebugGroup(): void {
|
|
189
|
+
this.currentRenderPassEncoder?.popDebugGroup();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @inheritDoc */
|
|
193
|
+
public dispose(): void {
|
|
194
|
+
super.dispose();
|
|
195
|
+
this._swapChain?.dispose();
|
|
196
|
+
this._swapChain = null;
|
|
197
|
+
this._device.destroy();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type {IGraphicsDeviceFeatures} from "../api/index.ts";
|
|
2
|
+
import type {GpuSupportedFeatures} from "./WebGpuTypes.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The WebGPU graphics device features, read from the device's enabled features.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export class WebGpuGraphicsDeviceFeatures implements IGraphicsDeviceFeatures {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The constructor.
|
|
12
|
+
* @param features The device's enabled features.
|
|
13
|
+
*/
|
|
14
|
+
public constructor(features: GpuSupportedFeatures) {
|
|
15
|
+
this.supportsTextureCompressionBC = features.has("texture-compression-bc");
|
|
16
|
+
// S3TC (BC1-BC3) is part of the WebGPU BC feature.
|
|
17
|
+
this.supportsTextureCompressionS3TC = this.supportsTextureCompressionBC;
|
|
18
|
+
this.supportsTextureCompressionS3TCSrgb = this.supportsTextureCompressionBC;
|
|
19
|
+
this.supportsTextureCompressionETC2 = features.has("texture-compression-etc2");
|
|
20
|
+
this.supportsTextureCompressionASTC = features.has("texture-compression-astc");
|
|
21
|
+
this.supportsTextureCompressionPVRTC = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @inheritDoc */
|
|
25
|
+
public readonly supportsTextureCompressionS3TC: boolean;
|
|
26
|
+
|
|
27
|
+
/** @inheritDoc */
|
|
28
|
+
public readonly supportsTextureCompressionS3TCSrgb: boolean;
|
|
29
|
+
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
public readonly supportsTextureCompressionBC: boolean;
|
|
32
|
+
|
|
33
|
+
/** @inheritDoc */
|
|
34
|
+
public readonly supportsTextureCompressionETC2: boolean;
|
|
35
|
+
|
|
36
|
+
/** @inheritDoc */
|
|
37
|
+
public readonly supportsTextureCompressionASTC: boolean;
|
|
38
|
+
|
|
39
|
+
/** @inheritDoc */
|
|
40
|
+
public readonly supportsTextureCompressionPVRTC: boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {ARenderer} from "../core/rendering/ARenderer.ts";
|
|
2
|
+
import {type IFramework, type IGraphicsDevice, type IRendererConfiguration, RenderingBackend} from "../api/index.ts";
|
|
3
|
+
import {WebGpuGraphicsDevice} from "./WebGpuGraphicsDevice.ts";
|
|
4
|
+
import {getNavigatorGpu} from "./WebGpuTypes.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGPU renderer. WebGPU hands out the adapter and device asynchronously, so call
|
|
8
|
+
* {@link acquireDeviceAsync} (done by `Framework.initializeAsync()`) before {@link initialize}.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export class WebGpuRenderer extends ARenderer {
|
|
12
|
+
|
|
13
|
+
private _createdDevice: WebGpuGraphicsDevice | null = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The constructor.
|
|
17
|
+
* @param framework The framework.
|
|
18
|
+
* @param renderConfiguration The renderer configuration.
|
|
19
|
+
*/
|
|
20
|
+
public constructor(framework: IFramework, renderConfiguration: IRendererConfiguration) {
|
|
21
|
+
super(framework, renderConfiguration);
|
|
22
|
+
this.backend = RenderingBackend.WEB_GPU;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Whether the browser exposes `navigator.gpu`. */
|
|
26
|
+
public static isSupported(): boolean {
|
|
27
|
+
return getNavigatorGpu() !== undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates the graphics device, which requests its own adapter and device.
|
|
32
|
+
* Throws when WebGPU is unavailable or no adapter is found.
|
|
33
|
+
*/
|
|
34
|
+
public async acquireDeviceAsync(): Promise<void> {
|
|
35
|
+
this._createdDevice = await WebGpuGraphicsDevice.createAsync(this._framework.windowManager, {
|
|
36
|
+
samplerFilteringPreset: this._renderConfiguration.textureFiltering,
|
|
37
|
+
alpha: this._renderConfiguration.alpha,
|
|
38
|
+
powerPreference: this._renderConfiguration.powerPreference,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @inheritDoc */
|
|
43
|
+
protected createGraphicsDevice(): IGraphicsDevice {
|
|
44
|
+
if (!this._createdDevice) {
|
|
45
|
+
throw new Error("WebGpuRenderer: the device is not created. Use Framework.initializeAsync() for WebGPU.");
|
|
46
|
+
}
|
|
47
|
+
return this._createdDevice;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal hand-written WebGPU type declarations used by the WebGPU backend.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript 5.9's `lib.dom` does not ship the WebGPU API, and the project avoids adding `@webgpu/types`.
|
|
5
|
+
* The types are module-scoped (prefixed with `Gpu`) instead of global, so they never clash with `@webgpu/types`
|
|
6
|
+
* in a consumer's project. Only what the backend uses is declared.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
|
|
12
|
+
/** `GPUBufferUsage` flags. */
|
|
13
|
+
export const GpuBufferUsage = {
|
|
14
|
+
MAP_READ: 0x0001,
|
|
15
|
+
MAP_WRITE: 0x0002,
|
|
16
|
+
COPY_SRC: 0x0004,
|
|
17
|
+
COPY_DST: 0x0008,
|
|
18
|
+
INDEX: 0x0010,
|
|
19
|
+
VERTEX: 0x0020,
|
|
20
|
+
UNIFORM: 0x0040,
|
|
21
|
+
STORAGE: 0x0080,
|
|
22
|
+
INDIRECT: 0x0100,
|
|
23
|
+
QUERY_RESOLVE: 0x0200,
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/** `GPUTextureUsage` flags. */
|
|
27
|
+
export const GpuTextureUsage = {
|
|
28
|
+
COPY_SRC: 0x01,
|
|
29
|
+
COPY_DST: 0x02,
|
|
30
|
+
TEXTURE_BINDING: 0x04,
|
|
31
|
+
STORAGE_BINDING: 0x08,
|
|
32
|
+
RENDER_ATTACHMENT: 0x10,
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
/** `GPUShaderStage` flags. */
|
|
36
|
+
export const GpuShaderStage = {
|
|
37
|
+
VERTEX: 0x1,
|
|
38
|
+
FRAGMENT: 0x2,
|
|
39
|
+
COMPUTE: 0x4,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export type GpuTextureFormat = string;
|
|
43
|
+
export type GpuPowerPreference = "low-power" | "high-performance";
|
|
44
|
+
export type GpuLoadOp = "load" | "clear";
|
|
45
|
+
export type GpuStoreOp = "store" | "discard";
|
|
46
|
+
export type GpuIndexFormat = "uint16" | "uint32";
|
|
47
|
+
export type GpuPrimitiveTopology = "point-list" | "line-list" | "line-strip" | "triangle-list" | "triangle-strip";
|
|
48
|
+
export type GpuCullMode = "none" | "front" | "back";
|
|
49
|
+
export type GpuFrontFace = "ccw" | "cw";
|
|
50
|
+
export type GpuBlendFactor = "zero" | "one" | "src-alpha" | "one-minus-src-alpha" | string;
|
|
51
|
+
export type GpuBlendOperation = "add" | "subtract" | "reverse-subtract" | "min" | "max";
|
|
52
|
+
export type GpuAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat";
|
|
53
|
+
export type GpuFilterMode = "nearest" | "linear";
|
|
54
|
+
export type GpuCompareFunction = "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always";
|
|
55
|
+
export type GpuVertexFormat = "float32" | "float32x2" | "float32x3" | "float32x4" | string;
|
|
56
|
+
export type GpuVertexStepMode = "vertex" | "instance";
|
|
57
|
+
|
|
58
|
+
export interface GpuObjectBase {
|
|
59
|
+
label: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface GpuAdapterInfo {
|
|
63
|
+
readonly vendor: string;
|
|
64
|
+
readonly architecture: string;
|
|
65
|
+
readonly device: string;
|
|
66
|
+
readonly description: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GpuSupportedFeatures {
|
|
70
|
+
has(feature: string): boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Gpu {
|
|
74
|
+
requestAdapter(options?: { powerPreference?: GpuPowerPreference }): Promise<GpuAdapter | null>;
|
|
75
|
+
getPreferredCanvasFormat(): GpuTextureFormat;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface GpuAdapter {
|
|
79
|
+
readonly features: GpuSupportedFeatures;
|
|
80
|
+
readonly info?: GpuAdapterInfo;
|
|
81
|
+
requestDevice(descriptor?: { label?: string; requiredFeatures?: string[] }): Promise<GpuDevice>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface GpuError {
|
|
85
|
+
readonly message: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface GpuDevice extends GpuObjectBase {
|
|
89
|
+
readonly features: GpuSupportedFeatures;
|
|
90
|
+
readonly queue: GpuQueue;
|
|
91
|
+
readonly lost: Promise<{ reason: string; message: string }>;
|
|
92
|
+
createBuffer(descriptor: { label?: string; size: number; usage: number; mappedAtCreation?: boolean }): GpuBuffer;
|
|
93
|
+
createTexture(descriptor: {
|
|
94
|
+
label?: string;
|
|
95
|
+
size: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number };
|
|
96
|
+
mipLevelCount?: number;
|
|
97
|
+
sampleCount?: number;
|
|
98
|
+
dimension?: "1d" | "2d" | "3d";
|
|
99
|
+
format: GpuTextureFormat;
|
|
100
|
+
usage: number;
|
|
101
|
+
}): GpuTexture;
|
|
102
|
+
createSampler(descriptor?: {
|
|
103
|
+
label?: string;
|
|
104
|
+
addressModeU?: GpuAddressMode;
|
|
105
|
+
addressModeV?: GpuAddressMode;
|
|
106
|
+
addressModeW?: GpuAddressMode;
|
|
107
|
+
magFilter?: GpuFilterMode;
|
|
108
|
+
minFilter?: GpuFilterMode;
|
|
109
|
+
mipmapFilter?: GpuFilterMode;
|
|
110
|
+
lodMinClamp?: number;
|
|
111
|
+
lodMaxClamp?: number;
|
|
112
|
+
compare?: GpuCompareFunction;
|
|
113
|
+
maxAnisotropy?: number;
|
|
114
|
+
}): GpuSampler;
|
|
115
|
+
createBindGroupLayout(descriptor: { label?: string; entries: GpuBindGroupLayoutEntry[] }): GpuBindGroupLayout;
|
|
116
|
+
createPipelineLayout(descriptor: { label?: string; bindGroupLayouts: GpuBindGroupLayout[] }): GpuPipelineLayout;
|
|
117
|
+
createBindGroup(descriptor: { label?: string; layout: GpuBindGroupLayout; entries: GpuBindGroupEntry[] }): GpuBindGroup;
|
|
118
|
+
createShaderModule(descriptor: { label?: string; code: string }): GpuShaderModule;
|
|
119
|
+
createRenderPipeline(descriptor: GpuRenderPipelineDescriptor): GpuRenderPipeline;
|
|
120
|
+
createCommandEncoder(descriptor?: { label?: string }): GpuCommandEncoder;
|
|
121
|
+
pushErrorScope(filter: "validation" | "out-of-memory" | "internal"): void;
|
|
122
|
+
popErrorScope(): Promise<GpuError | null>;
|
|
123
|
+
addEventListener(type: "uncapturederror", listener: (event: { error: GpuError }) => void): void;
|
|
124
|
+
destroy(): void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface GpuQueue {
|
|
128
|
+
submit(commandBuffers: GpuCommandBuffer[]): void;
|
|
129
|
+
writeBuffer(buffer: GpuBuffer, bufferOffset: number, data: ArrayBufferLike | ArrayBufferView, dataOffset?: number, size?: number): void;
|
|
130
|
+
writeTexture(
|
|
131
|
+
destination: { texture: GpuTexture; mipLevel?: number; origin?: [number, number, number?] },
|
|
132
|
+
data: ArrayBufferView | ArrayBufferLike,
|
|
133
|
+
dataLayout: { offset?: number; bytesPerRow?: number; rowsPerImage?: number },
|
|
134
|
+
size: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number }): void;
|
|
135
|
+
copyExternalImageToTexture(
|
|
136
|
+
source: { source: any; flipY?: boolean },
|
|
137
|
+
destination: { texture: GpuTexture; mipLevel?: number; premultipliedAlpha?: boolean },
|
|
138
|
+
copySize: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number }): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface GpuBuffer extends GpuObjectBase {
|
|
142
|
+
readonly size: number;
|
|
143
|
+
destroy(): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface GpuTexture extends GpuObjectBase {
|
|
147
|
+
readonly width: number;
|
|
148
|
+
readonly height: number;
|
|
149
|
+
readonly format: GpuTextureFormat;
|
|
150
|
+
createView(descriptor?: { label?: string; format?: GpuTextureFormat; dimension?: string }): GpuTextureView;
|
|
151
|
+
destroy(): void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface GpuTextureView extends GpuObjectBase {
|
|
155
|
+
readonly __brand?: "GPUTextureView";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface GpuSampler extends GpuObjectBase {
|
|
159
|
+
readonly __brand?: "GPUSampler";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface GpuBindGroupLayout extends GpuObjectBase {
|
|
163
|
+
readonly __brand?: "GPUBindGroupLayout";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface GpuPipelineLayout extends GpuObjectBase {
|
|
167
|
+
readonly __brand?: "GPUPipelineLayout";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface GpuBindGroup extends GpuObjectBase {
|
|
171
|
+
readonly __brand?: "GPUBindGroup";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface GpuShaderModule extends GpuObjectBase {
|
|
175
|
+
getCompilationInfo?(): Promise<{ messages: readonly { type: string; message: string; lineNum: number; linePos: number }[] }>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface GpuRenderPipeline extends GpuObjectBase {
|
|
179
|
+
readonly __brand?: "GPURenderPipeline";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface GpuCommandBuffer extends GpuObjectBase {
|
|
183
|
+
readonly __brand?: "GPUCommandBuffer";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface GpuBindGroupLayoutEntry {
|
|
187
|
+
binding: number;
|
|
188
|
+
visibility: number;
|
|
189
|
+
buffer?: { type?: "uniform" | "storage" | "read-only-storage"; hasDynamicOffset?: boolean; minBindingSize?: number };
|
|
190
|
+
sampler?: { type?: "filtering" | "non-filtering" | "comparison" };
|
|
191
|
+
texture?: { sampleType?: "float" | "unfilterable-float" | "depth" | "sint" | "uint"; viewDimension?: string; multisampled?: boolean };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface GpuBindGroupEntry {
|
|
195
|
+
binding: number;
|
|
196
|
+
resource: GpuSampler | GpuTextureView | { buffer: GpuBuffer; offset?: number; size?: number };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface GpuVertexBufferLayout {
|
|
200
|
+
arrayStride: number;
|
|
201
|
+
stepMode?: GpuVertexStepMode;
|
|
202
|
+
attributes: { format: GpuVertexFormat; offset: number; shaderLocation: number }[];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface GpuBlendComponent {
|
|
206
|
+
operation?: GpuBlendOperation;
|
|
207
|
+
srcFactor?: GpuBlendFactor;
|
|
208
|
+
dstFactor?: GpuBlendFactor;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface GpuColorTargetState {
|
|
212
|
+
format: GpuTextureFormat;
|
|
213
|
+
blend?: { color: GpuBlendComponent; alpha: GpuBlendComponent };
|
|
214
|
+
writeMask?: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface GpuDepthStencilState {
|
|
218
|
+
format: GpuTextureFormat;
|
|
219
|
+
depthWriteEnabled?: boolean;
|
|
220
|
+
depthCompare?: GpuCompareFunction;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface GpuRenderPipelineDescriptor {
|
|
224
|
+
label?: string;
|
|
225
|
+
layout: GpuPipelineLayout | "auto";
|
|
226
|
+
vertex: { module: GpuShaderModule; entryPoint?: string; buffers?: GpuVertexBufferLayout[] };
|
|
227
|
+
fragment?: { module: GpuShaderModule; entryPoint?: string; targets: GpuColorTargetState[] };
|
|
228
|
+
primitive?: { topology?: GpuPrimitiveTopology; cullMode?: GpuCullMode; frontFace?: GpuFrontFace; stripIndexFormat?: GpuIndexFormat };
|
|
229
|
+
depthStencil?: GpuDepthStencilState;
|
|
230
|
+
multisample?: { count?: number };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface GpuRenderPassColorAttachment {
|
|
234
|
+
view: GpuTextureView;
|
|
235
|
+
resolveTarget?: GpuTextureView;
|
|
236
|
+
clearValue?: { r: number; g: number; b: number; a: number };
|
|
237
|
+
loadOp: GpuLoadOp;
|
|
238
|
+
storeOp: GpuStoreOp;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface GpuRenderPassDepthStencilAttachment {
|
|
242
|
+
view: GpuTextureView;
|
|
243
|
+
depthClearValue?: number;
|
|
244
|
+
depthLoadOp?: GpuLoadOp;
|
|
245
|
+
depthStoreOp?: GpuStoreOp;
|
|
246
|
+
stencilClearValue?: number;
|
|
247
|
+
stencilLoadOp?: GpuLoadOp;
|
|
248
|
+
stencilStoreOp?: GpuStoreOp;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface GpuRenderPassDescriptor {
|
|
252
|
+
label?: string;
|
|
253
|
+
colorAttachments: GpuRenderPassColorAttachment[];
|
|
254
|
+
depthStencilAttachment?: GpuRenderPassDepthStencilAttachment;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface GpuCommandEncoder extends GpuObjectBase {
|
|
258
|
+
beginRenderPass(descriptor: GpuRenderPassDescriptor): GpuRenderPassEncoder;
|
|
259
|
+
finish(descriptor?: { label?: string }): GpuCommandBuffer;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface GpuRenderPassEncoder extends GpuObjectBase {
|
|
263
|
+
setPipeline(pipeline: GpuRenderPipeline): void;
|
|
264
|
+
setVertexBuffer(slot: number, buffer: GpuBuffer, offset?: number, size?: number): void;
|
|
265
|
+
setIndexBuffer(buffer: GpuBuffer, format: GpuIndexFormat, offset?: number, size?: number): void;
|
|
266
|
+
setBindGroup(index: number, bindGroup: GpuBindGroup): void;
|
|
267
|
+
drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
|
|
268
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
269
|
+
pushDebugGroup(label: string): void;
|
|
270
|
+
popDebugGroup(): void;
|
|
271
|
+
end(): void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface GpuCanvasContext {
|
|
275
|
+
configure(configuration: { device: GpuDevice; format: GpuTextureFormat; usage?: number; alphaMode?: "opaque" | "premultiplied" }): void;
|
|
276
|
+
unconfigure(): void;
|
|
277
|
+
getCurrentTexture(): GpuTexture;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Returns `navigator.gpu`, or undefined when the browser has no WebGPU.
|
|
282
|
+
*/
|
|
283
|
+
export function getNavigatorGpu(): Gpu | undefined {
|
|
284
|
+
if (typeof navigator === "undefined") {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
return (navigator as unknown as { gpu?: Gpu }).gpu ?? undefined;
|
|
288
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {BlendStateDescriptor} from "../../core/rendering/blending/blend-state-descriptor.ts";
|
|
2
|
+
import type {IBlendState} from "../../api/index.ts";
|
|
3
|
+
import type {GpuBlendComponent} from "../WebGpuTypes.ts";
|
|
4
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGPU blend state. WebGPU bakes blending into the render pipeline, so this only holds the converted values.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuBlendState implements IBlendState {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The constructor.
|
|
14
|
+
* @param descriptor The blend state descriptor.
|
|
15
|
+
*/
|
|
16
|
+
public constructor(descriptor: BlendStateDescriptor) {
|
|
17
|
+
this.blendingEnabled = descriptor.blendingEnabled;
|
|
18
|
+
this.color = {
|
|
19
|
+
srcFactor: WebGpuConverter.convertBlendFactor(descriptor.color.srcFactor),
|
|
20
|
+
dstFactor: WebGpuConverter.convertBlendFactor(descriptor.color.dstFactor),
|
|
21
|
+
operation: WebGpuConverter.convertBlendOperation(descriptor.color.operation),
|
|
22
|
+
};
|
|
23
|
+
this.alpha = {
|
|
24
|
+
srcFactor: WebGpuConverter.convertBlendFactor(descriptor.alpha.srcFactor),
|
|
25
|
+
dstFactor: WebGpuConverter.convertBlendFactor(descriptor.alpha.dstFactor),
|
|
26
|
+
operation: WebGpuConverter.convertBlendOperation(descriptor.alpha.operation),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether blending is enabled. */
|
|
31
|
+
public readonly blendingEnabled: boolean;
|
|
32
|
+
|
|
33
|
+
/** The color blend component. */
|
|
34
|
+
public readonly color: GpuBlendComponent;
|
|
35
|
+
|
|
36
|
+
/** The alpha blend component. */
|
|
37
|
+
public readonly alpha: GpuBlendComponent;
|
|
38
|
+
|
|
39
|
+
/** The `GPUBlendState` for a color target, or undefined when blending is disabled. */
|
|
40
|
+
public get gpuBlendState(): { color: GpuBlendComponent; alpha: GpuBlendComponent } | undefined {
|
|
41
|
+
return this.blendingEnabled ? {color: this.color, alpha: this.alpha} : undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @inheritDoc */
|
|
45
|
+
public get nativePtr(): any {
|
|
46
|
+
return this.gpuBlendState;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @inheritDoc */
|
|
50
|
+
public dispose(): void {
|
|
51
|
+
// Nothing to release.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BufferUsage,
|
|
3
|
+
type IBufferFactory,
|
|
4
|
+
type IFramework,
|
|
5
|
+
type IIndexBuffer,
|
|
6
|
+
type IUniformBuffer,
|
|
7
|
+
type IVertexBuffer,
|
|
8
|
+
} from "../../api/index.ts";
|
|
9
|
+
import {WebGpuVertexBuffer} from "./WebGpuVertexBuffer.ts";
|
|
10
|
+
import {WebGpuIndexBuffer} from "./WebGpuIndexBuffer.ts";
|
|
11
|
+
import {WebGpuUniformBuffer} from "./WebGpuUniformBuffer.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The WebGPU buffers factory.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export class WebGpuBuffersFactory implements IBufferFactory {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The constructor.
|
|
21
|
+
* @param _framework The framework.
|
|
22
|
+
*/
|
|
23
|
+
public constructor(private readonly _framework: IFramework) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @inheritDoc */
|
|
27
|
+
public createVertexBuffer(data: ArrayLike<number>, vertexStride: number, usage: BufferUsage = BufferUsage.VERTEX | BufferUsage.COPY_DST, label?: string): IVertexBuffer {
|
|
28
|
+
const buffer = new WebGpuVertexBuffer(this._framework, data, vertexStride, usage, label);
|
|
29
|
+
buffer.initialize();
|
|
30
|
+
return buffer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @inheritDoc */
|
|
34
|
+
public createUniformBuffer(data: ArrayLike<number>, usage: BufferUsage = BufferUsage.UNIFORM | BufferUsage.COPY_DST, label?: string): IUniformBuffer {
|
|
35
|
+
const buffer = new WebGpuUniformBuffer(this._framework, data, usage, label);
|
|
36
|
+
buffer.initialize();
|
|
37
|
+
return buffer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @inheritDoc */
|
|
41
|
+
public createIndexBuffer(data: ArrayLike<number>, label?: string): IIndexBuffer {
|
|
42
|
+
const buffer = new WebGpuIndexBuffer(this._framework, label);
|
|
43
|
+
buffer.initialize(data);
|
|
44
|
+
return buffer;
|
|
45
|
+
}
|
|
46
|
+
}
|