@forgeax/engine-rhi-webgpu 0.1.2
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/LICENSE +202 -0
- package/README.md +124 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/__mocks__/gpu-device.d.ts +233 -0
- package/dist/__tests__/__mocks__/gpu-device.d.ts.map +1 -0
- package/dist/__tests__/dawn-real-gpu.dawn.test.d.ts +2 -0
- package/dist/__tests__/dawn-real-gpu.dawn.test.d.ts.map +1 -0
- package/dist/__tests__/queue-write-range.browser.test.d.ts +2 -0
- package/dist/__tests__/queue-write-range.browser.test.d.ts.map +1 -0
- package/dist/__tests__/rgba16float-live-probe.browser.test.d.ts +2 -0
- package/dist/__tests__/rgba16float-live-probe.browser.test.d.ts.map +1 -0
- package/dist/__tests__/rgba16float-live-probe.d.ts +12 -0
- package/dist/__tests__/rgba16float-live-probe.d.ts.map +1 -0
- package/dist/__tests__/rgba16float-live-probe.dawn.test.d.ts +2 -0
- package/dist/__tests__/rgba16float-live-probe.dawn.test.d.ts.map +1 -0
- package/dist/__tests__/rhi-webgpu.unit.test.d.ts +2 -0
- package/dist/__tests__/rhi-webgpu.unit.test.d.ts.map +1 -0
- package/dist/device.d.ts +62 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1704 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/__tests__/timestamp-query.unit.test.d.ts +2 -0
- package/dist/internal/__tests__/timestamp-query.unit.test.d.ts.map +1 -0
- package/dist/internal/error-translation.d.ts +16 -0
- package/dist/internal/error-translation.d.ts.map +1 -0
- package/dist/internal/timestamp-query.d.ts +39 -0
- package/dist/internal/timestamp-query.d.ts.map +1 -0
- package/package.json +58 -0
- package/src/__tests__/__mocks__/gpu-device.ts +564 -0
- package/src/__tests__/dawn-real-gpu.dawn.test.ts +1488 -0
- package/src/__tests__/queue-write-range.browser.test.ts +60 -0
- package/src/__tests__/rgba16float-live-probe.browser.test.ts +13 -0
- package/src/__tests__/rgba16float-live-probe.dawn.test.ts +15 -0
- package/src/__tests__/rgba16float-live-probe.ts +44 -0
- package/src/__tests__/rhi-webgpu.unit.test.ts +2409 -0
- package/src/device.ts +1974 -0
- package/src/errors.ts +145 -0
- package/src/index.ts +599 -0
- package/src/internal/__tests__/timestamp-query.unit.test.ts +88 -0
- package/src/internal/error-translation.ts +187 -0
- package/src/internal/timestamp-query.ts +167 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/** Failure-injection switches consumed by the device path tests. */
|
|
2
|
+
export interface MockFailures {
|
|
3
|
+
/** `requestAdapter` returns null (research F-5 single null channel). */
|
|
4
|
+
adapterNull?: boolean;
|
|
5
|
+
/** `requestDevice` rejects with `OperationError` (spec behaviour for an
|
|
6
|
+
* unsupported feature). */
|
|
7
|
+
requestDeviceFeatureNotEnabled?: boolean;
|
|
8
|
+
/** `requestDevice` rejects with `OperationError` (spec behaviour for an
|
|
9
|
+
* out-of-range limit). */
|
|
10
|
+
requestDeviceLimitExceeded?: boolean;
|
|
11
|
+
/** `createShaderModule` returns a module whose `getCompilationInfo()`
|
|
12
|
+
* yields error-typed messages. */
|
|
13
|
+
shaderCompileMessages?: readonly GPUCompilationMessage[];
|
|
14
|
+
/** `createShaderModule` returns a module whose `getCompilationInfo()`
|
|
15
|
+
* rejects — models the GPU instance being dropped mid-await (device
|
|
16
|
+
* destroyed / page teardown while the async query is in flight). */
|
|
17
|
+
getCompilationInfoRejects?: boolean;
|
|
18
|
+
/** `createRenderPipeline` throws synchronously with this message. */
|
|
19
|
+
renderPipelineError?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Mock-capture event union; consumed by passthrough assertions. */
|
|
22
|
+
export type MockCapture = {
|
|
23
|
+
kind: 'requestAdapter';
|
|
24
|
+
options: GPURequestAdapterOptions | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'requestDevice';
|
|
27
|
+
options: GPUDeviceDescriptor | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'writeBuffer';
|
|
30
|
+
buffer: MockBuffer;
|
|
31
|
+
bufferOffset: number;
|
|
32
|
+
data: ArrayBufferView | ArrayBuffer;
|
|
33
|
+
dataOffset: number | undefined;
|
|
34
|
+
size: number | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'createBuffer';
|
|
37
|
+
descriptor: GPUBufferDescriptor;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'createTexture';
|
|
40
|
+
descriptor: GPUTextureDescriptor;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'createSampler';
|
|
43
|
+
descriptor: GPUSamplerDescriptor | undefined;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'createBindGroupLayout';
|
|
46
|
+
descriptor: GPUBindGroupLayoutDescriptor;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'createBindGroup';
|
|
49
|
+
descriptor: GPUBindGroupDescriptor;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'createPipelineLayout';
|
|
52
|
+
descriptor: GPUPipelineLayoutDescriptor;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'createRenderPipeline';
|
|
55
|
+
descriptor: GPURenderPipelineDescriptor;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'createShaderModule';
|
|
58
|
+
descriptor: GPUShaderModuleDescriptor;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'createTextureView';
|
|
61
|
+
sourceDescriptor: GPUTextureDescriptor;
|
|
62
|
+
descriptor: GPUTextureViewDescriptor | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'createComputePipeline';
|
|
65
|
+
descriptor: GPUComputePipelineDescriptor;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'createQuerySet';
|
|
68
|
+
descriptor: GPUQuerySetDescriptor;
|
|
69
|
+
};
|
|
70
|
+
/** Unique brand symbol so captured handles cannot be confused with real GPU* objects. */
|
|
71
|
+
declare const MOCK_BRAND: unique symbol;
|
|
72
|
+
/**
|
|
73
|
+
* Mock texture handle: exposes spec readonly fields the shim consumes for
|
|
74
|
+
* createTextureView cross-resource validation (research §1.1: format must be
|
|
75
|
+
* in source.format ∪ source.viewFormats; usage must be a subset of
|
|
76
|
+
* source.usage). The shim retrieves these via its own WeakMap (filled at
|
|
77
|
+
* createTexture time), but the mock surfaces createView so the shim can
|
|
78
|
+
* forward and capture descriptors verbatim.
|
|
79
|
+
*/
|
|
80
|
+
export interface MockTexture {
|
|
81
|
+
readonly [MOCK_BRAND]: 'texture';
|
|
82
|
+
readonly format: GPUTextureFormat;
|
|
83
|
+
readonly usage: GPUTextureUsageFlags;
|
|
84
|
+
readonly viewFormats: readonly GPUTextureFormat[];
|
|
85
|
+
createView(descriptor?: GPUTextureViewDescriptor | undefined): MockTextureView;
|
|
86
|
+
}
|
|
87
|
+
/** Mock texture view handle. */
|
|
88
|
+
export interface MockTextureView {
|
|
89
|
+
readonly [MOCK_BRAND]: 'texture-view';
|
|
90
|
+
}
|
|
91
|
+
/** Mock device exposed subset (covers only the surface the shim uses). */
|
|
92
|
+
export interface MockDevice {
|
|
93
|
+
readonly features: GPUSupportedFeatures;
|
|
94
|
+
readonly limits: GPUSupportedLimits;
|
|
95
|
+
readonly lost: Promise<GPUDeviceLostInfo>;
|
|
96
|
+
readonly queue: MockQueue;
|
|
97
|
+
createBuffer(descriptor: GPUBufferDescriptor): MockBuffer;
|
|
98
|
+
createTexture(descriptor: GPUTextureDescriptor): MockTexture;
|
|
99
|
+
createSampler(descriptor?: GPUSamplerDescriptor | undefined): {
|
|
100
|
+
readonly [MOCK_BRAND]: 'sampler';
|
|
101
|
+
};
|
|
102
|
+
createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): {
|
|
103
|
+
readonly [MOCK_BRAND]: 'bgl';
|
|
104
|
+
};
|
|
105
|
+
createBindGroup(descriptor: GPUBindGroupDescriptor): {
|
|
106
|
+
readonly [MOCK_BRAND]: 'bg';
|
|
107
|
+
};
|
|
108
|
+
createPipelineLayout(descriptor: GPUPipelineLayoutDescriptor): {
|
|
109
|
+
readonly [MOCK_BRAND]: 'pl';
|
|
110
|
+
};
|
|
111
|
+
createRenderPipeline(descriptor: GPURenderPipelineDescriptor): {
|
|
112
|
+
readonly [MOCK_BRAND]: 'render-pipeline';
|
|
113
|
+
};
|
|
114
|
+
createComputePipeline(descriptor: GPUComputePipelineDescriptor): {
|
|
115
|
+
readonly [MOCK_BRAND]: 'compute-pipeline';
|
|
116
|
+
};
|
|
117
|
+
createQuerySet(descriptor: GPUQuerySetDescriptor): {
|
|
118
|
+
readonly [MOCK_BRAND]: 'query-set';
|
|
119
|
+
};
|
|
120
|
+
createShaderModule(descriptor: GPUShaderModuleDescriptor): {
|
|
121
|
+
readonly [MOCK_BRAND]: 'shader';
|
|
122
|
+
getCompilationInfo(): Promise<GPUCompilationInfo>;
|
|
123
|
+
};
|
|
124
|
+
createCommandEncoder(descriptor?: GPUCommandEncoderDescriptor | undefined): MockCommandEncoder;
|
|
125
|
+
}
|
|
126
|
+
/** Mock queue: tracks submit / writeBuffer for assertions; M5 / w37 adds
|
|
127
|
+
* writeTexture / copyExternalImageToTexture / onSubmittedWorkDone. */
|
|
128
|
+
export interface MockQueue {
|
|
129
|
+
readonly [MOCK_BRAND]: 'queue';
|
|
130
|
+
submit(commandBuffers: Iterable<MockCommandBuffer>): void;
|
|
131
|
+
writeBuffer(buffer: MockBuffer, bufferOffset: number, data: ArrayBufferView | ArrayBuffer, dataOffset?: number, size?: number): void;
|
|
132
|
+
writeTexture(destination: unknown, data: ArrayBufferView | ArrayBuffer, dataLayout: unknown, size: unknown): void;
|
|
133
|
+
copyExternalImageToTexture(source: unknown, destination: unknown, copySize: unknown): void;
|
|
134
|
+
onSubmittedWorkDone(): Promise<undefined>;
|
|
135
|
+
}
|
|
136
|
+
/** Mock buffer; carries `size` so writeBuffer bounds-checking has a value.
|
|
137
|
+
* Extended in M5 / w35 with mapping surface (mapAsync / getMappedRange /
|
|
138
|
+
* unmap / mapState) so the shim Buffer wrapper can drive the validation
|
|
139
|
+
* paths (research §4.1 / §4.2 / §4.4). */
|
|
140
|
+
export interface MockBuffer {
|
|
141
|
+
readonly [MOCK_BRAND]: 'buffer';
|
|
142
|
+
readonly size: number;
|
|
143
|
+
mapState: 'unmapped' | 'pending' | 'mapped';
|
|
144
|
+
mapAsync(mode: number, offset?: number, size?: number): Promise<void>;
|
|
145
|
+
getMappedRange(offset?: number, size?: number): ArrayBuffer;
|
|
146
|
+
unmap(): void;
|
|
147
|
+
}
|
|
148
|
+
/** Mock command encoder: returned by device.createCommandEncoder. */
|
|
149
|
+
export interface MockCommandEncoder {
|
|
150
|
+
readonly [MOCK_BRAND]: 'command-encoder';
|
|
151
|
+
beginRenderPass(descriptor: GPURenderPassDescriptor): MockRenderPassEncoder;
|
|
152
|
+
beginComputePass(descriptor?: GPUComputePassDescriptor): MockComputePassEncoder;
|
|
153
|
+
copyBufferToBuffer(...args: unknown[]): void;
|
|
154
|
+
copyBufferToTexture(source: unknown, destination: unknown, copySize: unknown): void;
|
|
155
|
+
copyTextureToBuffer(source: unknown, destination: unknown, copySize: unknown): void;
|
|
156
|
+
copyTextureToTexture(source: unknown, destination: unknown, copySize: unknown): void;
|
|
157
|
+
clearBuffer(buffer: MockBuffer, offset?: number, size?: number): void;
|
|
158
|
+
resolveQuerySet(...args: unknown[]): void;
|
|
159
|
+
pushDebugGroup(label: string): void;
|
|
160
|
+
popDebugGroup(): void;
|
|
161
|
+
insertDebugMarker(label: string): void;
|
|
162
|
+
finish(descriptor?: GPUCommandBufferDescriptor): MockCommandBuffer;
|
|
163
|
+
}
|
|
164
|
+
/** Mock render pass encoder. */
|
|
165
|
+
export interface MockRenderPassEncoder {
|
|
166
|
+
readonly [MOCK_BRAND]: 'render-pass-encoder';
|
|
167
|
+
setPipeline(pipeline: unknown): void;
|
|
168
|
+
setBindGroup(...args: unknown[]): void;
|
|
169
|
+
setIndexBuffer(...args: unknown[]): void;
|
|
170
|
+
setVertexBuffer(...args: unknown[]): void;
|
|
171
|
+
draw(...args: unknown[]): void;
|
|
172
|
+
drawIndexed(...args: unknown[]): void;
|
|
173
|
+
drawIndirect(...args: unknown[]): void;
|
|
174
|
+
drawIndexedIndirect(...args: unknown[]): void;
|
|
175
|
+
setViewport(...args: unknown[]): void;
|
|
176
|
+
setScissorRect(...args: unknown[]): void;
|
|
177
|
+
setBlendConstant(...args: unknown[]): void;
|
|
178
|
+
setStencilReference(...args: unknown[]): void;
|
|
179
|
+
pushDebugGroup(label: string): void;
|
|
180
|
+
popDebugGroup(): void;
|
|
181
|
+
insertDebugMarker(label: string): void;
|
|
182
|
+
end(): void;
|
|
183
|
+
}
|
|
184
|
+
/** Mock compute pass encoder. */
|
|
185
|
+
export interface MockComputePassEncoder {
|
|
186
|
+
readonly [MOCK_BRAND]: 'compute-pass-encoder';
|
|
187
|
+
setPipeline(pipeline: unknown): void;
|
|
188
|
+
setBindGroup(...args: unknown[]): void;
|
|
189
|
+
dispatchWorkgroups(...args: unknown[]): void;
|
|
190
|
+
dispatchWorkgroupsIndirect(...args: unknown[]): void;
|
|
191
|
+
end(): void;
|
|
192
|
+
}
|
|
193
|
+
/** Mock command buffer (returned by encoder.finish). */
|
|
194
|
+
export interface MockCommandBuffer {
|
|
195
|
+
readonly [MOCK_BRAND]: 'command-buffer';
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Minimal mock `GPU` provider injected via the shim's `gpu?: GPU` provider
|
|
199
|
+
* seam (research F-6 webgpu-utils + CTS consensus).
|
|
200
|
+
*
|
|
201
|
+
* `__captured` / `__failures` are observation points exclusive to the test
|
|
202
|
+
* side; the shim does not read them.
|
|
203
|
+
*/
|
|
204
|
+
export interface MockGpu {
|
|
205
|
+
/** Test observation: createX / requestX call-site descriptors in order. */
|
|
206
|
+
readonly __captured: MockCapture[];
|
|
207
|
+
/** Failure-injection switches for the test side. */
|
|
208
|
+
readonly __failures: MockFailures;
|
|
209
|
+
requestAdapter(options?: GPURequestAdapterOptions | undefined): Promise<MockAdapter | null>;
|
|
210
|
+
}
|
|
211
|
+
/** Mock adapter subset. */
|
|
212
|
+
export interface MockAdapter {
|
|
213
|
+
readonly features: GPUSupportedFeatures;
|
|
214
|
+
readonly limits: GPUSupportedLimits;
|
|
215
|
+
requestDevice(descriptor?: GPUDeviceDescriptor | undefined): Promise<MockDevice>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Create a MockGpu test entry point.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* const gpu = createMockGpu();
|
|
222
|
+
* gpu.__failures.adapterNull = true;
|
|
223
|
+
* const r = await rhiWebgpu.requestDevice({ gpu });
|
|
224
|
+
* expect(r.ok).toBe(false);
|
|
225
|
+
*/
|
|
226
|
+
export declare function createMockGpu(failures?: MockFailures): MockGpu;
|
|
227
|
+
/**
|
|
228
|
+
* Build a 6-field GPUCompilationMessage (OQ-P2 locked field set).
|
|
229
|
+
* Used by shader-compile-failed path tests asserting detail.compilerMessages.
|
|
230
|
+
*/
|
|
231
|
+
export declare function makeShaderError(partial?: Partial<GPUCompilationMessage>): GPUCompilationMessage;
|
|
232
|
+
export {};
|
|
233
|
+
//# sourceMappingURL=gpu-device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-device.d.ts","sourceRoot":"","sources":["../../../src/__tests__/__mocks__/gpu-device.ts"],"names":[],"mappings":"AA6BA,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;gCAC4B;IAC5B,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC;+BAC2B;IAC3B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC;uCACmC;IACnC,qBAAqB,CAAC,EAAE,SAAS,qBAAqB,E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AQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,aAAa,CAAC,UAAU,CAAC,EAAE,mBAAmB,GAAG,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAClF;AAsQD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAE,YAAiB,GAAG,OAAO,CA6BlE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,GAAE,OAAO,CAAC,qBAAqB,CAAM,GAC3C,qBAAqB,CAavB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dawn-real-gpu.dawn.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/dawn-real-gpu.dawn.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-write-range.browser.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/queue-write-range.browser.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba16float-live-probe.browser.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/rgba16float-live-probe.browser.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Rgba16floatRenderTargetProbe } from '@forgeax/engine-rhi';
|
|
2
|
+
export interface Rgba16floatLiveProbeEvidence {
|
|
3
|
+
readonly backend: string;
|
|
4
|
+
readonly initial: Rgba16floatRenderTargetProbe;
|
|
5
|
+
readonly loss: {
|
|
6
|
+
readonly reason: 'destroyed' | 'unknown';
|
|
7
|
+
readonly message: string;
|
|
8
|
+
};
|
|
9
|
+
readonly recovered: Rgba16floatRenderTargetProbe;
|
|
10
|
+
}
|
|
11
|
+
export declare function runRgba16floatLiveProbe(): Promise<Rgba16floatLiveProbeEvidence>;
|
|
12
|
+
//# sourceMappingURL=rgba16float-live-probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba16float-live-probe.d.ts","sourceRoot":"","sources":["../../src/__tests__/rgba16float-live-probe.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACtF,QAAQ,CAAC,SAAS,EAAE,4BAA4B,CAAC;CAClD;AAgBD,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAerF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgba16float-live-probe.dawn.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/rgba16float-live-probe.dawn.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rhi-webgpu.unit.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/rhi-webgpu.unit.test.ts"],"names":[],"mappings":""}
|
package/dist/device.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { RhiCanvasContext, RhiDevice } from '@forgeax/engine-rhi';
|
|
2
|
+
/**
|
|
3
|
+
* Get the underlying GPUDevice associated with a RhiDevice.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* Single-point escape hatch (D-S1 / feat-20260508-rhi-surface-completion).
|
|
8
|
+
* The `_internal_` prefix + `@internal` JSDoc tag mark this as engine-internal
|
|
9
|
+
* plumbing; the only sanctioned consumer is
|
|
10
|
+
* `apps/hello/triangle/src/main.ts:96` which threads the raw GPUDevice into
|
|
11
|
+
* `RendererOptions.rawDeviceForContextConfigure` so the canvas
|
|
12
|
+
* `GPUCanvasContext.configure({device})` slot keeps working
|
|
13
|
+
* (GPUCanvasContext is outside the RHI surface). Every other engine path
|
|
14
|
+
* goes through the RHI interface.
|
|
15
|
+
*
|
|
16
|
+
* Future: deprecated once `feat-future-rhi-adapter-surface` lands a
|
|
17
|
+
* `RhiCanvasContext` abstraction; this function will be removed at that
|
|
18
|
+
* closure. AC-08 grep gate keeps further callers out via word-boundary
|
|
19
|
+
* `\bgetRawDevice\b` allow-list (see apps/hello/triangle/scripts/ac-08-grep-gate.mjs).
|
|
20
|
+
*/
|
|
21
|
+
export declare function _internal_getRawDevice(device: RhiDevice): GPUDevice | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Construct a RhiDevice shim wrapping GPUDevice.
|
|
24
|
+
*
|
|
25
|
+
* Does not cache or reclassify device.lost (single-source subscription +
|
|
26
|
+
* dual-form fan-out is the engine layer's job; this package only exposes the
|
|
27
|
+
* spec Promise). See plan-strategy 3 R2 mitigation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function makeRhiDevice(rawDevice: GPUDevice): {
|
|
30
|
+
device: RhiDevice;
|
|
31
|
+
/** Exposed for createShaderModule and other shim entry points that need to
|
|
32
|
+
* bypass the createX Result wrapper. */
|
|
33
|
+
raw: GPUDevice;
|
|
34
|
+
};
|
|
35
|
+
/** Stripped-down GPUCanvasContext shape the shim consumes. Real
|
|
36
|
+
* GPUCanvasContext satisfies this; the unit-test mock fixture only
|
|
37
|
+
* implements what is needed (charter proposition 1: progressive disclosure). */
|
|
38
|
+
export interface GpuCanvasContextLike {
|
|
39
|
+
configure(configuration: GPUCanvasConfiguration): void;
|
|
40
|
+
unconfigure(): void;
|
|
41
|
+
getConfiguration(): GPUCanvasConfiguration | null;
|
|
42
|
+
getCurrentTexture(): GPUTexture;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build a RhiCanvasContext shim around a raw GPUCanvasContext (M3 / K-4 /
|
|
46
|
+
* w21).
|
|
47
|
+
*
|
|
48
|
+
* Pre-configure validation (research §3.3 mapping):
|
|
49
|
+
* - format gate: format must be in SUPPORTED_CONTEXT_FORMATS; otherwise
|
|
50
|
+
* fast-path returns `'webgpu-runtime-error'` with the spec-aligned
|
|
51
|
+
* `.expected` literal `'one of bgra8unorm/rgba8unorm/rgba16float'`.
|
|
52
|
+
*
|
|
53
|
+
* Post-configure semantics:
|
|
54
|
+
* - getCurrentTexture forwards each call to the raw context (NO cross-frame
|
|
55
|
+
* caching, research §3.3 [[Expire the current texture]]); spec
|
|
56
|
+
* InvalidStateError catches map to `'webgpu-runtime-error'`.
|
|
57
|
+
* - getConfiguration projects the spec record verbatim; missing fields
|
|
58
|
+
* remain missing (feature-detection idiom, research §3.2 toneMapping
|
|
59
|
+
* NOTE).
|
|
60
|
+
*/
|
|
61
|
+
export declare function makeCanvasContext(rawContext: GpuCanvasContextLike): RhiCanvasContext;
|
|
62
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAqBV,gBAAgB,EAIhB,SAAS,EAYV,MAAM,qBAAqB,CAAC;AAsM7B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAE/E;AAijCD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG;IACnD,MAAM,EAAE,SAAS,CAAC;IAClB;6CACyC;IACzC,GAAG,EAAE,SAAS,CAAC;CAChB,CAicA;AA0BD;;iFAEiF;AACjF,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,aAAa,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACvD,WAAW,IAAI,IAAI,CAAC;IACpB,gBAAgB,IAAI,sBAAsB,GAAG,IAAI,CAAC;IAClD,iBAAiB,IAAI,UAAU,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,oBAAoB,GAAG,gBAAgB,CAqGpF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Result, RhiError } from '@forgeax/engine-rhi';
|
|
2
|
+
/** adapter null path (research F-5 single null channel). */
|
|
3
|
+
export declare function adapterUnavailable(): Result<never, RhiError>;
|
|
4
|
+
/** feature not enabled path (boundary cases / requirements). */
|
|
5
|
+
export declare function featureNotEnabled(featureName?: string | undefined): Result<never, RhiError>;
|
|
6
|
+
/** limit exceeded path (boundary cases / requirements). */
|
|
7
|
+
export declare function limitExceeded(limitName?: string | undefined): Result<never, RhiError>;
|
|
8
|
+
/** shader compile failed path + detail.compilerMessages forwarding (OQ-P2 6 fields). */
|
|
9
|
+
export declare function shaderCompileFailed(compilerMessages: readonly GPUCompilationMessage[]): Result<never, RhiError>;
|
|
10
|
+
/**
|
|
11
|
+
* Command encoder reused after finish() (W3C WebGPU 22 GPUCommandEncoder lifecycle).
|
|
12
|
+
*
|
|
13
|
+
* Trigger: encoder.beginRenderPass / copyXxx / finish called after a prior finish().
|
|
14
|
+
* Distinct from 'rhi-not-available': this is a real-path validation failure,
|
|
15
|
+
* not a placeholder for unimplemented surface (plan-strategy D-S3 template 1).
|
|
16
|
+
*/
|
|
17
|
+
export declare function commandEncoderFinished(): Result<never, RhiError>;
|
|
18
|
+
/**
|
|
19
|
+
* Render pass not ended before next pass / finish (W3C WebGPU 22.7 Render pass).
|
|
20
|
+
*
|
|
21
|
+
* Trigger: encoder.beginRenderPass while previous pass active, or encoder.finish
|
|
22
|
+
* with active pass still recording (plan-strategy D-S3 template 2).
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderPassNotEnded(): Result<never, RhiError>;
|
|
25
|
+
/**
|
|
26
|
+
* Queue.submit real-path failure (W3C WebGPU 23 Queue).
|
|
27
|
+
*
|
|
28
|
+
* Trigger: submit([cb]) with destroyed buffer/pipeline references, or GPU validation
|
|
29
|
+
* error fan-out via onuncapturederror. Explicitly distinct from 'rhi-not-available'
|
|
30
|
+
* (device-lost subclass) - submit-failed signals dynamic resource life-cycle issues
|
|
31
|
+
* the AI user can self-recover from (plan-strategy D-S3 template 3).
|
|
32
|
+
*/
|
|
33
|
+
export declare function queueSubmitFailed(detailMessage?: string | undefined): Result<never, RhiError>;
|
|
34
|
+
/**
|
|
35
|
+
* Queue.writeBuffer offset/size out of bounds (W3C WebGPU 23.2 writeBuffer).
|
|
36
|
+
*
|
|
37
|
+
* Trigger: writeBuffer(buf, offset, data) where offset is not 4-byte aligned, or
|
|
38
|
+
* offset + data.byteLength exceeds buffer.size. Distinct from 'limit-exceeded'
|
|
39
|
+
* (static device.limits) - out-of-bounds is a dynamic per-buffer boundary
|
|
40
|
+
* (plan-strategy D-S3 template 4).
|
|
41
|
+
*/
|
|
42
|
+
export declare function queueWriteBufferOutOfBounds(args: {
|
|
43
|
+
offset: number;
|
|
44
|
+
byteLength: number;
|
|
45
|
+
bufferSize: number;
|
|
46
|
+
}): Result<never, RhiError>;
|
|
47
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAYA,OAAO,EAAO,KAAK,MAAM,EAAE,QAAQ,EAA+B,MAAM,qBAAqB,CAAC;AAE9F,4DAA4D;AAC5D,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAQ5D;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAS3F;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CASrF;AAED,wFAAwF;AACxF,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,SAAS,qBAAqB,EAAE,GACjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAUzB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAQhE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAS5D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAe7F;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAS1B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { RequestAdapterOptions, Result, RhiAdapter, RhiCanvasContext, RhiDevice, RhiError, RhiInstance, ShaderModule } from '@forgeax/engine-rhi';
|
|
2
|
+
/**
|
|
3
|
+
* The `GPU` subset accepted at the provider seam (research §F-6 webgpu-utils +
|
|
4
|
+
* CTS consensus).
|
|
5
|
+
*
|
|
6
|
+
* The shim only calls the two entries `gpu.requestAdapter()` →
|
|
7
|
+
* `adapter.requestDevice()`; accepting a structural subset rather than requiring
|
|
8
|
+
* a full GPU interface implementation lets the mock fixture
|
|
9
|
+
* (src/__tests__/__mocks__/gpu-device.ts) skip implementing
|
|
10
|
+
* `wgslLanguageFeatures` / `getPreferredCanvasFormat` and other fields this loop
|
|
11
|
+
* does not consume (charter proposition 1: progressive disclosure).
|
|
12
|
+
*/
|
|
13
|
+
export interface GpuLike {
|
|
14
|
+
requestAdapter(options?: GPURequestAdapterOptions | undefined): Promise<GpuAdapterLike | null>;
|
|
15
|
+
}
|
|
16
|
+
/** The `GPUAdapter` subset accepted at the provider seam — only the `requestDevice` entry is consumed. */
|
|
17
|
+
export interface GpuAdapterLike {
|
|
18
|
+
requestDevice(descriptor?: GPUDeviceDescriptor | undefined): Promise<GpuDeviceLike>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The `GPUDevice` subset accepted at the provider seam — exactly the fields the
|
|
22
|
+
* shim actually touches (the 5 descriptor `createX` calls + features / limits /
|
|
23
|
+
* lost + a `queue` placeholder).
|
|
24
|
+
*
|
|
25
|
+
* Differences from the full GPUDevice spec:
|
|
26
|
+
* - `onuncapturederror` / `pushErrorScope` / `createCommandEncoder` not required
|
|
27
|
+
* (only needed at M3).
|
|
28
|
+
* - `wgslLanguageFeatures` / `getPreferredCanvasFormat` not required (charter
|
|
29
|
+
* proposition 1: progressive disclosure).
|
|
30
|
+
*
|
|
31
|
+
* The coverage of `cast as GPUDevice` inside `makeRhiDevice` matches this
|
|
32
|
+
* interface exactly; both the mock and the real GPUDevice only need to satisfy
|
|
33
|
+
* this structural subset.
|
|
34
|
+
*/
|
|
35
|
+
export interface GpuDeviceLike {
|
|
36
|
+
readonly features: GPUSupportedFeatures;
|
|
37
|
+
readonly limits: GPUSupportedLimits;
|
|
38
|
+
readonly lost: Promise<GPUDeviceLostInfo>;
|
|
39
|
+
readonly queue: unknown;
|
|
40
|
+
createBuffer(descriptor: GPUBufferDescriptor): unknown;
|
|
41
|
+
createTexture(descriptor: GPUTextureDescriptor): unknown;
|
|
42
|
+
createSampler(descriptor?: GPUSamplerDescriptor | undefined): unknown;
|
|
43
|
+
createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): unknown;
|
|
44
|
+
createBindGroup(descriptor: GPUBindGroupDescriptor): unknown;
|
|
45
|
+
createPipelineLayout(descriptor: GPUPipelineLayoutDescriptor): unknown;
|
|
46
|
+
createRenderPipeline(descriptor: GPURenderPipelineDescriptor): unknown;
|
|
47
|
+
createShaderModule(descriptor: GPUShaderModuleDescriptor): unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for the `requestDevice` entry.
|
|
51
|
+
*
|
|
52
|
+
* `gpu?: GpuLike` is the provider seam (research §F-6 webgpu-utils + CTS
|
|
53
|
+
* consensus):
|
|
54
|
+
* - omitted → falls back to `globalThis.navigator.gpu` (real-device path).
|
|
55
|
+
* - explicitly provided → uses the caller-injected mock / real GPU object (mock
|
|
56
|
+
* unit-test path).
|
|
57
|
+
*
|
|
58
|
+
* `adapterOptions` / `deviceDescriptor` pass through to the corresponding spec
|
|
59
|
+
* entries.
|
|
60
|
+
*/
|
|
61
|
+
export interface RequestDeviceOptions {
|
|
62
|
+
gpu?: GpuLike | undefined;
|
|
63
|
+
adapterOptions?: GPURequestAdapterOptions | undefined;
|
|
64
|
+
deviceDescriptor?: GPUDeviceDescriptor | undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Internal `requestDevice` — single-step factory accepting an injected
|
|
68
|
+
* `gpu` mock provider. **Not part of the public RHI surface**: AI users go
|
|
69
|
+
* through the spec-aligned two-step path
|
|
70
|
+
* `rhi.requestAdapter() -> adapter.requestDevice()` (M3 break-point #2 + M6
|
|
71
|
+
* fix-up [w51]; AGENTS.md break-point list 2026-05-10 #2). This entry is
|
|
72
|
+
* retained as the unit-test seam (`packages/rhi-webgpu/src/__tests__/*`)
|
|
73
|
+
* for `gpu` mock injection; it is **not** re-exported through the `rhi`
|
|
74
|
+
* singleton and is **not** referenced by engine / apps / dawn paths
|
|
75
|
+
* (charter proposition 5 consistent abstraction red line + grep gate
|
|
76
|
+
* `m6-e: rhi.requestDevice( 0 hit`).
|
|
77
|
+
*
|
|
78
|
+
* Generates 3 of the 4 error paths here (research §F-5):
|
|
79
|
+
* - adapter null → `Result.err(RhiError { code: 'adapter-unavailable' })`
|
|
80
|
+
* - feature not enabled → `Result.err(RhiError { code: 'feature-not-enabled' })`
|
|
81
|
+
* - limit exceeded → `Result.err(RhiError { code: 'limit-exceeded' })`
|
|
82
|
+
*
|
|
83
|
+
* The 4th path (shader-compile-failed) is generated by the
|
|
84
|
+
* `createShaderModule` entry.
|
|
85
|
+
*/
|
|
86
|
+
export declare function requestDevice(opts?: RequestDeviceOptions): Promise<Result<RhiDevice, RhiError>>;
|
|
87
|
+
/**
|
|
88
|
+
* Entry 2 - async `createShaderModule`. The shader-compile-failed path
|
|
89
|
+
* forwards every 6 fields of `GPUCompilationMessage` to
|
|
90
|
+
* `RhiError.detail.compilerMessages` (OQ-P2 / F-3 finding).
|
|
91
|
+
*
|
|
92
|
+
* Implementation (post fix-f3):
|
|
93
|
+
* 1) Look up the underlying `GPUDevice` via the in-package
|
|
94
|
+
* `_internal_getRawDevice` (RAW_DEVICE_MAP reverse lookup; same module).
|
|
95
|
+
* 2) `rawDevice.createShaderModule(desc)` calls the spec entry to obtain
|
|
96
|
+
* a `GPUShaderModule`.
|
|
97
|
+
* 3) `await module.getCompilationInfo()` retrieves compilation info.
|
|
98
|
+
* 4) If any message has `type === 'error'`, return
|
|
99
|
+
* `Result.err(RhiError { code: 'shader-compile-failed',
|
|
100
|
+
* detail: { compilerMessages } })`.
|
|
101
|
+
* 5) Otherwise return `Result.ok(module as ShaderModule)`.
|
|
102
|
+
*
|
|
103
|
+
* Note: this entry accepts a shim-wrapped RhiDevice (not a raw GPUDevice)
|
|
104
|
+
* to keep the public API single-source; the in-package
|
|
105
|
+
* `_internal_getRawDevice` is the only sanctioned reverse lookup.
|
|
106
|
+
*
|
|
107
|
+
* fix-f3: the synchronous `RhiDevice.createShaderModule` placeholder is
|
|
108
|
+
* removed; the shader-compile-failed path closes inside this async entry
|
|
109
|
+
* (charter proposition 5 consistent abstraction + proposition 4 explicit
|
|
110
|
+
* failure).
|
|
111
|
+
*/
|
|
112
|
+
export declare function createShaderModule(device: RhiDevice, desc: {
|
|
113
|
+
label?: string | undefined;
|
|
114
|
+
code: string;
|
|
115
|
+
}): Promise<Result<ShaderModule, RhiError>>;
|
|
116
|
+
/**
|
|
117
|
+
* Entry — `requestAdapter` walks `navigator.gpu.requestAdapter(opts)` and
|
|
118
|
+
* wraps the result as a forgeax `RhiAdapter` (M3 break-point #2; K-5 + K-6).
|
|
119
|
+
*
|
|
120
|
+
* Strict two-step path mirrors wgpu / Dawn (research §6); the legacy
|
|
121
|
+
* `requestDevice(opts)` factory below is the deprecated single-step shortcut
|
|
122
|
+
* kept for backward compatibility while existing callers migrate.
|
|
123
|
+
*
|
|
124
|
+
* Optional `gpu` provider seam at the `RequestAdapterOptions`-side: this
|
|
125
|
+
* factory takes only the forgeax-spec `RequestAdapterOptions` (powerPreference
|
|
126
|
+
* / forceFallbackAdapter); when callers need the mock-injection seam they go
|
|
127
|
+
* through the legacy `requestDevice({ gpu })` form.
|
|
128
|
+
*
|
|
129
|
+
* @param opts — W3C-spec request adapter options.
|
|
130
|
+
* @param _compatibleSurface — accepted for dual-impl symmetry
|
|
131
|
+
* (plan-strategy D-5; AGENTS.md "Dual-impl ship-together" rule).
|
|
132
|
+
* The browser WebGPU backend does not use this parameter; it is
|
|
133
|
+
* ignored. rhi-wgpu routes it to `requestAdapterWithCanvas`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function requestAdapter(opts?: RequestAdapterOptions | undefined, _compatibleSurface?: HTMLCanvasElement | OffscreenCanvas | undefined): Promise<Result<RhiAdapter, RhiError>>;
|
|
136
|
+
/**
|
|
137
|
+
* Acquire a canvas rendering context from an HTMLCanvasElement (M3 / w15).
|
|
138
|
+
*
|
|
139
|
+
* Spec anchor: W3C WebGPU §3.3 GPUCanvasContext.
|
|
140
|
+
*
|
|
141
|
+
* Internally calls `canvas.getContext('webgpu')` and wraps the result as a
|
|
142
|
+
* branded RhiCanvasContext. Returns `Result<RhiCanvasContext, RhiError>` —
|
|
143
|
+
* canvas does not support WebGPU returns `RhiError { code: 'rhi-not-available' }`
|
|
144
|
+
* with a precise `.hint` so AI users can display a degradation banner (charter
|
|
145
|
+
* proposition 4 explicit failure).
|
|
146
|
+
*
|
|
147
|
+
* This replaces the legacy `createCanvasContext(rawCtx)` — AGENTS.md §Change stance
|
|
148
|
+
* authorizes the breaking rename (acquireCanvasContext, optimal > compatible).
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const ctxResult = acquireCanvasContext(canvas);
|
|
152
|
+
* if (!ctxResult.ok) {
|
|
153
|
+
* // canvas does not support WebGPU
|
|
154
|
+
* return;
|
|
155
|
+
* }
|
|
156
|
+
* const canvasContext = ctxResult.value;
|
|
157
|
+
* canvasContext.configure({ device, format: 'bgra8unorm', usage: 0x10 });
|
|
158
|
+
*/
|
|
159
|
+
export declare function acquireCanvasContext(canvas: HTMLCanvasElement | OffscreenCanvas): Result<RhiCanvasContext, RhiError>;
|
|
160
|
+
/**
|
|
161
|
+
* The `rhi` singleton entry (charter proposition 1: progressive disclosure +
|
|
162
|
+
* plan-strategy §7.4 discoverability:
|
|
163
|
+
* 'import { rhi } from @forgeax/engine-rhi-webgpu' + 'Engine.create({ rhi, canvas })'
|
|
164
|
+
* injection shape).
|
|
165
|
+
*
|
|
166
|
+
* Strict two-step path (M3 break-point #2 + M6 fix-up [w51]; K-5 + K-6):
|
|
167
|
+
* `rhi.requestAdapter(opts) -> adapter.requestDevice(opts)`
|
|
168
|
+
*
|
|
169
|
+
* The legacy single-step `rhi.requestDevice(opts)` factory was retired here
|
|
170
|
+
* (AGENTS.md break-point list 2026-05-10 #2). AI users follow the spec
|
|
171
|
+
* idiom (charter proposition 5 consistent abstraction red line):
|
|
172
|
+
* const adapter = (await rhi.requestAdapter()).unwrap();
|
|
173
|
+
* const device = (await adapter.requestDevice(opts)).unwrap();
|
|
174
|
+
*/
|
|
175
|
+
export declare const rhi: RhiInstance & {
|
|
176
|
+
createShaderModule: typeof createShaderModule;
|
|
177
|
+
acquireCanvasContext: typeof acquireCanvasContext;
|
|
178
|
+
};
|
|
179
|
+
export type { BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, Buffer, BufferDescriptor, CanvasConfiguration, CommandBuffer, CommandEncoderDescriptor, ComputePassDescriptor, ComputePassTimestampWrites, ComputePipeline, ComputePipelineDescriptor, Fence, PipelineLayout, PipelineLayoutDescriptor, QuerySet, QuerySetDescriptor, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline, RenderPipelineDescriptor, RequestAdapterOptions, RequestDeviceOptions as RhiRequestDeviceOptions, Result, ResultErr, ResultOk, RhiAdapter, RhiAssetNotRegisteredDetail, RhiCanvasContext, RhiCaps, RhiCommandEncoder, RhiComputePassEncoder, RhiDevice, RhiError, RhiErrorCode, RhiErrorDetail, RhiFeatures, RhiInstance, RhiLimits, RhiQueue, RhiRenderPassEncoder, RhiShaderCompileDetail, RhiSurface, RhiWebgpuRuntimeDetail, Sampler, SamplerDescriptor, ShaderModule, Texture, TextureDescriptor, TextureView, TextureViewDescriptor, } from '@forgeax/engine-rhi';
|
|
180
|
+
export { err, ok, RhiError as RhiErrorClass } from '@forgeax/engine-rhi';
|
|
181
|
+
export { _internal_getRawDevice } from './device';
|
|
182
|
+
export { translateErrorEventToRhiError } from './internal/error-translation';
|
|
183
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAEV,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACb,MAAM,qBAAqB,CAAC;AAU7B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,OAAO;IAEtB,cAAc,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,SAAS,GAAG,OAAO,CAA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