@derschmale/tiny-helix 0.1.0
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 +21 -0
- package/README.md +95 -0
- package/dist/BindGroup.d.ts +121 -0
- package/dist/BlendMode.d.ts +21 -0
- package/dist/Buffer.d.ts +66 -0
- package/dist/BufferDataWriter.d.ts +67 -0
- package/dist/CommandEncoder.d.ts +50 -0
- package/dist/ComputePass.d.ts +37 -0
- package/dist/ComputePipeline.d.ts +18 -0
- package/dist/Mesh.d.ts +177 -0
- package/dist/Pipeline.d.ts +47 -0
- package/dist/RenderPass.d.ts +101 -0
- package/dist/RenderPipeline.d.ts +77 -0
- package/dist/RenderTarget.d.ts +44 -0
- package/dist/Renderer.d.ts +44 -0
- package/dist/Sampler.d.ts +31 -0
- package/dist/Shader.d.ts +77 -0
- package/dist/Texture.d.ts +55 -0
- package/dist/TinyHelix.d.ts +163 -0
- package/dist/UniformBuffer.d.ts +84 -0
- package/dist/WebGPUContext.d.ts +70 -0
- package/dist/buffers/Buffer.d.ts +79 -0
- package/dist/buffers/BufferDataWriter.d.ts +68 -0
- package/dist/buffers/IBuffer.d.ts +4 -0
- package/dist/buffers/UniformBuffer.d.ts +111 -0
- package/dist/enums.d.ts +158 -0
- package/dist/index.d.ts +24 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/tiny-helix.debug.js +3351 -0
- package/dist/tiny-helix.debug.js.map +1 -0
- package/dist/tiny-helix.esm.debug.js +3386 -0
- package/dist/tiny-helix.esm.debug.js.map +1 -0
- package/dist/tiny-helix.esm.js +2 -0
- package/dist/tiny-helix.esm.js.map +1 -0
- package/dist/tiny-helix.js +2 -0
- package/dist/tiny-helix.js.map +1 -0
- package/dist/utils/IndexedCollection.d.ts +4 -0
- package/dist/utils/float32ToFloat16.d.ts +5 -0
- package/dist/utils/mapUndefined.d.ts +6 -0
- package/dist/utils/padArrayBuffer.d.ts +10 -0
- package/package.json +54 -0
|
@@ -0,0 +1,3351 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["TinyHelix"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["TinyHelix"] = factory();
|
|
10
|
+
})(this, () => {
|
|
11
|
+
return /******/ (() => { // webpackBootstrap
|
|
12
|
+
/******/ "use strict";
|
|
13
|
+
/******/ var __webpack_modules__ = ({
|
|
14
|
+
|
|
15
|
+
/***/ "./src/BindGroup.ts":
|
|
16
|
+
/*!**************************!*\
|
|
17
|
+
!*** ./src/BindGroup.ts ***!
|
|
18
|
+
\**************************/
|
|
19
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
20
|
+
|
|
21
|
+
__webpack_require__.r(__webpack_exports__);
|
|
22
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
23
|
+
/* harmony export */ BindGroup: () => (/* binding */ BindGroup),
|
|
24
|
+
/* harmony export */ BindGroupBuilder: () => (/* binding */ BindGroupBuilder),
|
|
25
|
+
/* harmony export */ BindGroupLayout: () => (/* binding */ BindGroupLayout),
|
|
26
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
27
|
+
/* harmony export */ });
|
|
28
|
+
/* harmony import */ var _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./buffers/UniformBuffer */ "./src/buffers/UniformBuffer.ts");
|
|
29
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
30
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Lightweight wrapper around a GPUBindGroup.
|
|
36
|
+
* Use {@link TinyHelix.createBindGroup} to create instances.
|
|
37
|
+
*/
|
|
38
|
+
class BindGroup {
|
|
39
|
+
/**
|
|
40
|
+
* Construct a wrapper around an existing GPUBindGroup.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
constructor(inner) {
|
|
44
|
+
this._inner = inner;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Builder for creating GPUBindGroup instances. Supports adding uniform buffer
|
|
49
|
+
* entries and a human-readable label.
|
|
50
|
+
*/
|
|
51
|
+
class BindGroupBuilder {
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
constructor(ctx, layout) {
|
|
56
|
+
this._entries = [];
|
|
57
|
+
this._ctx = ctx;
|
|
58
|
+
this._layout = layout;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Assign a human-readable label for the bind group (useful in GPU debuggers).
|
|
62
|
+
*/
|
|
63
|
+
withLabel(label) {
|
|
64
|
+
this._label = label;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Attach a buffer to the bind group
|
|
69
|
+
* @param fieldName
|
|
70
|
+
* @param buffer
|
|
71
|
+
*/
|
|
72
|
+
withBuffer(fieldName, buffer) {
|
|
73
|
+
const index = this._layout._getBindingIndex(fieldName);
|
|
74
|
+
this._entries[index] = {
|
|
75
|
+
binding: index, resource: buffer._getBufferResource()
|
|
76
|
+
};
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
/** Attach a texture to the bind group. */
|
|
80
|
+
withTexture(fieldName, texture) {
|
|
81
|
+
const index = this._layout._getBindingIndex(fieldName);
|
|
82
|
+
this._entries[index] = {
|
|
83
|
+
binding: index, resource: texture._inner
|
|
84
|
+
};
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/** Attach a sampler to the bind group at the given binding index. */
|
|
88
|
+
withSampler(fieldName, sampler) {
|
|
89
|
+
const index = this._layout._getBindingIndex(fieldName);
|
|
90
|
+
this._entries[index] = {
|
|
91
|
+
binding: index, resource: sampler._inner
|
|
92
|
+
};
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create the GPUBindGroup and return a wrapped `BindGroup` instance.
|
|
97
|
+
*/
|
|
98
|
+
build() {
|
|
99
|
+
const inner = this._ctx.device.createBindGroup({
|
|
100
|
+
label: this._label,
|
|
101
|
+
entries: this._entries,
|
|
102
|
+
layout: this._layout._inner
|
|
103
|
+
});
|
|
104
|
+
return new BindGroup(inner);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Wrapper around a GPUBindGroupLayout that also keeps track of any
|
|
109
|
+
* UniformBufferLayout objects associated with the layout. Useful for
|
|
110
|
+
* constructing `BindGroupBuilder` instances for specific layouts.
|
|
111
|
+
*/
|
|
112
|
+
class BindGroupLayout {
|
|
113
|
+
constructor(inner, ctx, indices, uboLayouts) {
|
|
114
|
+
this._inner = inner;
|
|
115
|
+
this._indices = indices;
|
|
116
|
+
this._uboLayouts = uboLayouts;
|
|
117
|
+
this._ctx = ctx;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the UniformBufferLayout associated with a named field (if any).
|
|
121
|
+
*/
|
|
122
|
+
getUniformBufferLayout(name) {
|
|
123
|
+
return this._uboLayouts.get(name);
|
|
124
|
+
}
|
|
125
|
+
createUniformBuffer(name) {
|
|
126
|
+
const layout = this._uboLayouts.get(name);
|
|
127
|
+
return (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_1__.mapUndefined)(layout, layout => new _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_0__.UniformBuffer(layout, this._ctx));
|
|
128
|
+
}
|
|
129
|
+
_getBindingIndex(fieldName) {
|
|
130
|
+
const index = this._indices.get(fieldName);
|
|
131
|
+
if (index === undefined) {
|
|
132
|
+
throw (`No field name found for ${fieldName} in bind group layout.`);
|
|
133
|
+
}
|
|
134
|
+
return index;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Builder for GPUBindGroupLayout. Currently supports adding uniform buffers
|
|
139
|
+
* and their associated layout information.
|
|
140
|
+
*/
|
|
141
|
+
class BindGroupLayoutBuilder {
|
|
142
|
+
constructor(ctx) {
|
|
143
|
+
this._entries = [];
|
|
144
|
+
this._indices = new Map();
|
|
145
|
+
// TODO: add other buffer/texture types
|
|
146
|
+
this._uboLayouts = new Map();
|
|
147
|
+
this._ctx = ctx;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Assign a label for the bind group layout.
|
|
151
|
+
*/
|
|
152
|
+
withLabel(label) {
|
|
153
|
+
this._label = label;
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Add a uniform buffer binding at the given index and record its layout.
|
|
158
|
+
* @param index - binding index
|
|
159
|
+
* @param field_name - a name used to reference the layout later
|
|
160
|
+
* @param layout - the UniformBufferLayout describing the UBO
|
|
161
|
+
* @param visibility - shader stage visibility flags (defaults to VERTEX|FRAGMENT|COMPUTE)
|
|
162
|
+
*/
|
|
163
|
+
withUniformBuffer(index, field_name, layout, visibility) {
|
|
164
|
+
this._entries[index] = {
|
|
165
|
+
binding: index,
|
|
166
|
+
visibility: visibility ?? GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE,
|
|
167
|
+
buffer: { type: 'uniform' }
|
|
168
|
+
};
|
|
169
|
+
this._indices.set(field_name, index);
|
|
170
|
+
this._uboLayouts.set(field_name, layout);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Add a storage buffer binding at the given index and record its layout.
|
|
175
|
+
* @param index - binding index
|
|
176
|
+
* @param field_name - a name used to reference the layout later
|
|
177
|
+
* @param access_mode - Defines whether the storage buffer is read-only or not.
|
|
178
|
+
* @param visibility - shader stage visibility flags (defaults to FRAGMENT|COMPUTE)
|
|
179
|
+
*/
|
|
180
|
+
withStorageBuffer(index, field_name, access_mode, visibility) {
|
|
181
|
+
let type = "storage";
|
|
182
|
+
if (access_mode === _enums__WEBPACK_IMPORTED_MODULE_2__.StorageAccess.Read) {
|
|
183
|
+
type = "read-only-storage";
|
|
184
|
+
}
|
|
185
|
+
this._entries[index] = {
|
|
186
|
+
binding: index,
|
|
187
|
+
visibility: visibility ?? GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE,
|
|
188
|
+
buffer: { type, hasDynamicOffset: false, minBindingSize: 4 }
|
|
189
|
+
};
|
|
190
|
+
this._indices.set(field_name, index);
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Add a storage texture binding at the given index. The texture will be
|
|
195
|
+
* write-only and use RGBA8Unorm format.
|
|
196
|
+
* @param index
|
|
197
|
+
* @param field_name
|
|
198
|
+
* @param format
|
|
199
|
+
* @param access_mode
|
|
200
|
+
* @param visibility
|
|
201
|
+
*/
|
|
202
|
+
withStorageTexture(index, field_name, format, access_mode, visibility) {
|
|
203
|
+
this._entries[index] = {
|
|
204
|
+
binding: index,
|
|
205
|
+
visibility: visibility ?? GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE,
|
|
206
|
+
storageTexture: { access: access_mode, format }
|
|
207
|
+
};
|
|
208
|
+
this._indices.set(field_name, index);
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
withTexture(index, field_name, visibility) {
|
|
212
|
+
this._entries[index] = {
|
|
213
|
+
binding: index,
|
|
214
|
+
visibility: visibility ?? GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE,
|
|
215
|
+
texture: { sampleType: 'float' }
|
|
216
|
+
};
|
|
217
|
+
this._indices.set(field_name, index);
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
withSampler(index, field_name, visibility) {
|
|
221
|
+
this._entries[index] = {
|
|
222
|
+
binding: index,
|
|
223
|
+
visibility: visibility ?? GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE,
|
|
224
|
+
sampler: { type: 'filtering' }
|
|
225
|
+
};
|
|
226
|
+
this._indices.set(field_name, index);
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Create the underlying GPUBindGroupLayout and return a wrapped `BindGroupLayout`.
|
|
231
|
+
*/
|
|
232
|
+
build() {
|
|
233
|
+
const inner = this._ctx.device.createBindGroupLayout({
|
|
234
|
+
label: this._label,
|
|
235
|
+
entries: this._entries
|
|
236
|
+
});
|
|
237
|
+
return new BindGroupLayout(inner, this._ctx, this._indices, this._uboLayouts);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BindGroupLayoutBuilder);
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
/***/ }),
|
|
244
|
+
|
|
245
|
+
/***/ "./src/BlendMode.ts":
|
|
246
|
+
/*!**************************!*\
|
|
247
|
+
!*** ./src/BlendMode.ts ***!
|
|
248
|
+
\**************************/
|
|
249
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
250
|
+
|
|
251
|
+
__webpack_require__.r(__webpack_exports__);
|
|
252
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
253
|
+
/* harmony export */ BlendMode: () => (/* binding */ BlendMode)
|
|
254
|
+
/* harmony export */ });
|
|
255
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
256
|
+
|
|
257
|
+
class BlendMode {
|
|
258
|
+
get srcFactor() { return this._inner.color.srcFactor; }
|
|
259
|
+
set srcFactor(value) { this._inner.color.srcFactor = value; }
|
|
260
|
+
get dstFactor() { return this._inner.color.dstFactor; }
|
|
261
|
+
set dstFactor(value) { this._inner.color.dstFactor = value; }
|
|
262
|
+
get alphaSrcFactor() { return this._inner.alpha.srcFactor; }
|
|
263
|
+
set alphaSrcFactor(value) { this._inner.alpha.srcFactor = value; }
|
|
264
|
+
get alphaDstFactor() { return this._inner.alpha.dstFactor; }
|
|
265
|
+
set alphaDstFactor(value) { this._inner.alpha.dstFactor = value; }
|
|
266
|
+
constructor(srcFactor, dstFactor, alphaSrcFactor, alphaDstFactor) {
|
|
267
|
+
this._inner = {
|
|
268
|
+
color: { srcFactor: _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.SrcAlpha, dstFactor: _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha },
|
|
269
|
+
alpha: { srcFactor: _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, dstFactor: _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha }
|
|
270
|
+
};
|
|
271
|
+
this.srcFactor = srcFactor;
|
|
272
|
+
this.dstFactor = dstFactor;
|
|
273
|
+
this.alphaSrcFactor = alphaSrcFactor;
|
|
274
|
+
this.alphaDstFactor = alphaDstFactor;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
BlendMode.ALPHA = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.SrcAlpha, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha);
|
|
278
|
+
BlendMode.ADDITIVE = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.SrcAlpha, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One);
|
|
279
|
+
BlendMode.MULTIPLY = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.DstColor, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.Zero, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.Zero, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One);
|
|
280
|
+
BlendMode.SCREEN = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcColor, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha);
|
|
281
|
+
BlendMode.OVERLAY = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.SrcAlpha, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha);
|
|
282
|
+
BlendMode.DARKEN = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcColor, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha);
|
|
283
|
+
BlendMode.LIGHTEN = new BlendMode(_enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcColor, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.One, _enums__WEBPACK_IMPORTED_MODULE_0__.BlendFactor.OneMinusSrcAlpha);
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
/***/ }),
|
|
287
|
+
|
|
288
|
+
/***/ "./src/CommandEncoder.ts":
|
|
289
|
+
/*!*******************************!*\
|
|
290
|
+
!*** ./src/CommandEncoder.ts ***!
|
|
291
|
+
\*******************************/
|
|
292
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
293
|
+
|
|
294
|
+
__webpack_require__.r(__webpack_exports__);
|
|
295
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
296
|
+
/* harmony export */ CommandEncoder: () => (/* binding */ CommandEncoder)
|
|
297
|
+
/* harmony export */ });
|
|
298
|
+
/* harmony import */ var _RenderPass__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RenderPass */ "./src/RenderPass.ts");
|
|
299
|
+
/* harmony import */ var _ComputePass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComputePass */ "./src/ComputePass.ts");
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Encapsulates a GPUCommandEncoder and provides helper methods to build and
|
|
304
|
+
* submit GPU commands for a single frame. CommandEncoder should only be created
|
|
305
|
+
* through the TinyHelix instance (See {@link TinyHelix.createCommandEncoder})
|
|
306
|
+
*/
|
|
307
|
+
class CommandEncoder {
|
|
308
|
+
/**
|
|
309
|
+
* Create a new CommandEncoder bound to a backbuffer/render target and
|
|
310
|
+
* the WebGPU context.
|
|
311
|
+
*
|
|
312
|
+
* @internal
|
|
313
|
+
*/
|
|
314
|
+
constructor(backbufferTarget, globalBindGroups, ctx, depthStencilTarget, label) {
|
|
315
|
+
this._commandBuffer = null;
|
|
316
|
+
const device = ctx.device;
|
|
317
|
+
this._queue = device.queue;
|
|
318
|
+
this._backbufferTarget = backbufferTarget;
|
|
319
|
+
this._depthStencilTarget = depthStencilTarget;
|
|
320
|
+
this._globalBindGroups = globalBindGroups;
|
|
321
|
+
this._encoder = device.createCommandEncoder({ label });
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Clears a buffer's contents
|
|
325
|
+
*/
|
|
326
|
+
clearBuffer(buffer, offset, size) {
|
|
327
|
+
this._encoder.clearBuffer(buffer._inner, offset, size);
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Begin building a render pass attached to this encoder.
|
|
332
|
+
* Returns a fluent RenderPassBuilder used to configure attachments and clear ops.
|
|
333
|
+
*/
|
|
334
|
+
createRenderPass() {
|
|
335
|
+
return new _RenderPass__WEBPACK_IMPORTED_MODULE_0__.RenderPassBuilder(this._encoder, this._globalBindGroups, this._backbufferTarget, this._depthStencilTarget);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Begin building a compute pass attached to this encoder.
|
|
339
|
+
* Returns a fluent ComputePassBuilder used to configure bindings and dispatch ops.
|
|
340
|
+
*/
|
|
341
|
+
createComputePass() {
|
|
342
|
+
return new _ComputePass__WEBPACK_IMPORTED_MODULE_1__.ComputePassBuilder(this._encoder, this._globalBindGroups);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Mark the encoder as finished and finalize any pending commands.
|
|
346
|
+
* Calling finish() multiple times is safe but a no-op after the first call.
|
|
347
|
+
*/
|
|
348
|
+
finish() {
|
|
349
|
+
if (!this._commandBuffer) {
|
|
350
|
+
this._commandBuffer = this._encoder.finish();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Submit the recorded commands to the GPU queue. If the encoder has not
|
|
355
|
+
* been finished yet, finish() will be called automatically.
|
|
356
|
+
*/
|
|
357
|
+
submit() {
|
|
358
|
+
this.finish();
|
|
359
|
+
this._queue.submit([this._commandBuffer]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
/***/ }),
|
|
365
|
+
|
|
366
|
+
/***/ "./src/ComputePass.ts":
|
|
367
|
+
/*!****************************!*\
|
|
368
|
+
!*** ./src/ComputePass.ts ***!
|
|
369
|
+
\****************************/
|
|
370
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
371
|
+
|
|
372
|
+
__webpack_require__.r(__webpack_exports__);
|
|
373
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
374
|
+
/* harmony export */ ComputePass: () => (/* binding */ ComputePass),
|
|
375
|
+
/* harmony export */ ComputePassBuilder: () => (/* binding */ ComputePassBuilder)
|
|
376
|
+
/* harmony export */ });
|
|
377
|
+
class ComputePass {
|
|
378
|
+
constructor(inner) {
|
|
379
|
+
this._inner = inner;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Set the compute pipeline to use for the next dispatch calls.
|
|
383
|
+
* @param pipeline
|
|
384
|
+
*/
|
|
385
|
+
setPipeline(pipeline) {
|
|
386
|
+
this._inner.setPipeline(pipeline._inner);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
dispatch(x, y, z) {
|
|
390
|
+
this._inner.dispatchWorkgroups(x, y, z);
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
dispatchIndirect(buffer, offset) {
|
|
394
|
+
this._inner.dispatchWorkgroupsIndirect(buffer._inner, offset);
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Set a bind group at the given index.
|
|
399
|
+
* @param index - bind group index in the render pipeline layout
|
|
400
|
+
* @param bindGroup - a `BindGroup` instance
|
|
401
|
+
*/
|
|
402
|
+
setBindGroup(index, bindGroup) {
|
|
403
|
+
this._inner.setBindGroup(index, bindGroup._inner);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* End the compute pass. After calling end(), the underlying encoder may
|
|
408
|
+
* continue recording other passes or be finished/submitted.
|
|
409
|
+
*/
|
|
410
|
+
end() {
|
|
411
|
+
this._inner.end();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
class ComputePassBuilder {
|
|
415
|
+
constructor(encoder, globalBindGroups) {
|
|
416
|
+
this._encoder = encoder;
|
|
417
|
+
this._globalBindGroups = globalBindGroups;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Assign a human-readable label for the render pass (useful for GPU debuggers).
|
|
421
|
+
*/
|
|
422
|
+
withLabel(label) {
|
|
423
|
+
this._label = label;
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
build() {
|
|
427
|
+
const desc = {
|
|
428
|
+
label: this._label
|
|
429
|
+
};
|
|
430
|
+
const pass = new ComputePass(this._encoder.beginComputePass(desc));
|
|
431
|
+
for (let i = 0; i < this._globalBindGroups.length; ++i) {
|
|
432
|
+
pass.setBindGroup(i, this._globalBindGroups[i]);
|
|
433
|
+
}
|
|
434
|
+
return pass;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
/***/ }),
|
|
440
|
+
|
|
441
|
+
/***/ "./src/ComputePipeline.ts":
|
|
442
|
+
/*!********************************!*\
|
|
443
|
+
!*** ./src/ComputePipeline.ts ***!
|
|
444
|
+
\********************************/
|
|
445
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
446
|
+
|
|
447
|
+
__webpack_require__.r(__webpack_exports__);
|
|
448
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
449
|
+
/* harmony export */ ComputePipeline: () => (/* binding */ ComputePipeline),
|
|
450
|
+
/* harmony export */ ComputePipelineBuilder: () => (/* binding */ ComputePipelineBuilder)
|
|
451
|
+
/* harmony export */ });
|
|
452
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
453
|
+
|
|
454
|
+
class ComputePipeline {
|
|
455
|
+
constructor(inner) {
|
|
456
|
+
this._inner = inner;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
class ComputePipelineBuilder {
|
|
460
|
+
constructor(ctx) {
|
|
461
|
+
this._ctx = ctx;
|
|
462
|
+
}
|
|
463
|
+
withLabel(label) {
|
|
464
|
+
this._label = label;
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
/** Select the shader entry point for the fragment stage. */
|
|
468
|
+
withShader(shader, entry) {
|
|
469
|
+
this._shader = shader;
|
|
470
|
+
this._entry = entry;
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
build() {
|
|
474
|
+
const shader = this._shader;
|
|
475
|
+
const layout = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(shader._bindGroupLayouts, bindGroupLayouts => this._ctx.device.createPipelineLayout({
|
|
476
|
+
bindGroupLayouts: bindGroupLayouts.map(value => value._inner),
|
|
477
|
+
label: this._label
|
|
478
|
+
})) ?? "auto";
|
|
479
|
+
const desc = {
|
|
480
|
+
label: this._label,
|
|
481
|
+
compute: {
|
|
482
|
+
module: shader._inner,
|
|
483
|
+
entryPoint: this._entry
|
|
484
|
+
},
|
|
485
|
+
layout
|
|
486
|
+
};
|
|
487
|
+
return new ComputePipeline(this._ctx.device.createComputePipeline(desc));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
/***/ }),
|
|
493
|
+
|
|
494
|
+
/***/ "./src/Mesh.ts":
|
|
495
|
+
/*!*********************!*\
|
|
496
|
+
!*** ./src/Mesh.ts ***!
|
|
497
|
+
\*********************/
|
|
498
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
499
|
+
|
|
500
|
+
__webpack_require__.r(__webpack_exports__);
|
|
501
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
502
|
+
/* harmony export */ FrontFace: () => (/* binding */ FrontFace),
|
|
503
|
+
/* harmony export */ IndexFormat: () => (/* binding */ IndexFormat),
|
|
504
|
+
/* harmony export */ Mesh: () => (/* binding */ Mesh),
|
|
505
|
+
/* harmony export */ MeshBuilder: () => (/* binding */ MeshBuilder),
|
|
506
|
+
/* harmony export */ MeshTopology: () => (/* binding */ MeshTopology),
|
|
507
|
+
/* harmony export */ StreamBuilder: () => (/* binding */ StreamBuilder),
|
|
508
|
+
/* harmony export */ VertexFormat: () => (/* binding */ VertexFormat)
|
|
509
|
+
/* harmony export */ });
|
|
510
|
+
/* harmony import */ var _buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./buffers/Buffer */ "./src/buffers/Buffer.ts");
|
|
511
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Index buffer formats supported by the library.
|
|
516
|
+
*/
|
|
517
|
+
var IndexFormat;
|
|
518
|
+
(function (IndexFormat) {
|
|
519
|
+
IndexFormat["Uint16"] = "uint16";
|
|
520
|
+
IndexFormat["Uint32"] = "uint32";
|
|
521
|
+
})(IndexFormat || (IndexFormat = {}));
|
|
522
|
+
class IndexBuffer {
|
|
523
|
+
constructor(data, ctx, keepData = false) {
|
|
524
|
+
// Use BYTES_PER_ELEMENT on the union-typed array in a typed manner to avoid 'any' casts
|
|
525
|
+
const bytesPerElement = data.BYTES_PER_ELEMENT;
|
|
526
|
+
this.format = bytesPerElement === 2 ? IndexFormat.Uint16 : IndexFormat.Uint32;
|
|
527
|
+
this.count = data.length;
|
|
528
|
+
this.buffer = new _buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferBuilder(ctx)
|
|
529
|
+
.withData(data.buffer, keepData)
|
|
530
|
+
.withUsage(_buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferUsage.CopyDst | _buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferUsage.Index)
|
|
531
|
+
.build();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Mesh topology enum (maps to GPU primitive topologies).
|
|
536
|
+
*/
|
|
537
|
+
var MeshTopology;
|
|
538
|
+
(function (MeshTopology) {
|
|
539
|
+
MeshTopology["TriangleList"] = "triangle-list";
|
|
540
|
+
MeshTopology["TriangleStrip"] = "triangle-strip";
|
|
541
|
+
MeshTopology["LineList"] = "line-list";
|
|
542
|
+
MeshTopology["LineStrip"] = "line-strip";
|
|
543
|
+
MeshTopology["PointList"] = "point-list";
|
|
544
|
+
})(MeshTopology || (MeshTopology = {}));
|
|
545
|
+
/**
|
|
546
|
+
* Winding mode for front-facing triangles.
|
|
547
|
+
*/
|
|
548
|
+
var FrontFace;
|
|
549
|
+
(function (FrontFace) {
|
|
550
|
+
FrontFace["Clockwise"] = "cw";
|
|
551
|
+
FrontFace["CounterClockwise"] = "ccw";
|
|
552
|
+
})(FrontFace || (FrontFace = {}));
|
|
553
|
+
/**
|
|
554
|
+
* Vertex attribute formats supported by the helper. These are translated into
|
|
555
|
+
* GPU vertex attribute formats when building pipelines.
|
|
556
|
+
*/
|
|
557
|
+
var VertexFormat;
|
|
558
|
+
(function (VertexFormat) {
|
|
559
|
+
VertexFormat["Uint8"] = "uint8";
|
|
560
|
+
VertexFormat["Uint8x2"] = "uint8x2";
|
|
561
|
+
VertexFormat["Uint8x4"] = "uint8x4";
|
|
562
|
+
VertexFormat["Sint8"] = "sint8";
|
|
563
|
+
VertexFormat["Sint8x2"] = "sint8x2";
|
|
564
|
+
VertexFormat["Sint8x4"] = "sint8x4";
|
|
565
|
+
VertexFormat["Unorm8"] = "unorm8";
|
|
566
|
+
VertexFormat["Unorm8x2"] = "unorm8x2";
|
|
567
|
+
VertexFormat["Unorm8x4"] = "unorm8x4";
|
|
568
|
+
VertexFormat["Snorm8"] = "snorm8";
|
|
569
|
+
VertexFormat["Snorm8x2"] = "snorm8x2";
|
|
570
|
+
VertexFormat["Snorm8x4"] = "snorm8x4";
|
|
571
|
+
VertexFormat["Uint16"] = "uint16";
|
|
572
|
+
VertexFormat["Uint16x2"] = "uint16x2";
|
|
573
|
+
VertexFormat["Uint16x4"] = "uint16x4";
|
|
574
|
+
VertexFormat["Sint16"] = "sint16";
|
|
575
|
+
VertexFormat["Sint16x2"] = "sint16x2";
|
|
576
|
+
VertexFormat["Sint16x4"] = "sint16x4";
|
|
577
|
+
VertexFormat["Unorm16"] = "unorm16";
|
|
578
|
+
VertexFormat["Unorm16x2"] = "unorm16x2";
|
|
579
|
+
VertexFormat["Unorm16x4"] = "unorm16x4";
|
|
580
|
+
VertexFormat["Snorm16"] = "snorm16";
|
|
581
|
+
VertexFormat["Snorm16x2"] = "snorm16x2";
|
|
582
|
+
VertexFormat["Snorm16x4"] = "snorm16x4";
|
|
583
|
+
VertexFormat["Float16"] = "float16";
|
|
584
|
+
VertexFormat["Float16x2"] = "float16x2";
|
|
585
|
+
VertexFormat["Float16x4"] = "float16x4";
|
|
586
|
+
VertexFormat["Float32"] = "float32";
|
|
587
|
+
VertexFormat["Float32x2"] = "float32x2";
|
|
588
|
+
VertexFormat["Float32x3"] = "float32x3";
|
|
589
|
+
VertexFormat["Float32x4"] = "float32x4";
|
|
590
|
+
VertexFormat["Uint32"] = "uint32";
|
|
591
|
+
VertexFormat["Uint32x2"] = "uint32x2";
|
|
592
|
+
VertexFormat["Uint32x3"] = "uint32x3";
|
|
593
|
+
VertexFormat["Uint32x4"] = "uint32x4";
|
|
594
|
+
VertexFormat["Sint32"] = "sint32";
|
|
595
|
+
VertexFormat["Sint32x2"] = "sint32x2";
|
|
596
|
+
VertexFormat["Sint32x3"] = "sint32x3";
|
|
597
|
+
VertexFormat["Sint32x4"] = "sint32x4";
|
|
598
|
+
VertexFormat["Unorm10_10_10_2"] = "unorm10-10-10-2";
|
|
599
|
+
VertexFormat["Unorm8x4_bgra"] = "unorm8x4-bgra";
|
|
600
|
+
})(VertexFormat || (VertexFormat = {}));
|
|
601
|
+
/**
|
|
602
|
+
* Lightweight Mesh representation containing vertex streams and an optional index buffer.
|
|
603
|
+
* Use `MeshBuilder` to construct instances.
|
|
604
|
+
*/
|
|
605
|
+
class Mesh {
|
|
606
|
+
/**
|
|
607
|
+
* @internal
|
|
608
|
+
*/
|
|
609
|
+
constructor(topology, frontFace, streams, indexBuffer) {
|
|
610
|
+
this._streams = [];
|
|
611
|
+
this._topology = topology;
|
|
612
|
+
this._frontFace = frontFace;
|
|
613
|
+
this._streams = streams;
|
|
614
|
+
this._indexBuffer = indexBuffer;
|
|
615
|
+
this._numVertices = this._streams[0].numVertices;
|
|
616
|
+
this._streams.forEach(stream => console.assert(stream.numVertices === this._numVertices, "All vertex streams must have the same number of vertices."));
|
|
617
|
+
}
|
|
618
|
+
/** The primitive topology for this mesh. */
|
|
619
|
+
get topology() {
|
|
620
|
+
return this._topology;
|
|
621
|
+
}
|
|
622
|
+
/** The winding used to determine front-facing triangles. */
|
|
623
|
+
get frontFace() {
|
|
624
|
+
return this._frontFace;
|
|
625
|
+
}
|
|
626
|
+
/** The number of vertex streams in this mesh. */
|
|
627
|
+
get numStreams() {
|
|
628
|
+
return this._streams.length;
|
|
629
|
+
}
|
|
630
|
+
/** Get the number of vertices in the first vertex stream. */
|
|
631
|
+
get numVertices() {
|
|
632
|
+
return this._numVertices;
|
|
633
|
+
}
|
|
634
|
+
/** Get the GPU-backed vertex buffer for a given stream index. */
|
|
635
|
+
getVertexBuffer(streamIndex) {
|
|
636
|
+
return this._streams[streamIndex].buffer;
|
|
637
|
+
}
|
|
638
|
+
/** Get the stride (byte size) of a vertex in the requested stream. */
|
|
639
|
+
getStreamStride(streamIndex) {
|
|
640
|
+
return this._streams[streamIndex].stride;
|
|
641
|
+
}
|
|
642
|
+
/** Get the declared attributes for a vertex stream. */
|
|
643
|
+
getStreamAttributes(streamIndex) {
|
|
644
|
+
return this._streams[streamIndex].attributes;
|
|
645
|
+
}
|
|
646
|
+
/** Get the optional index buffer backing this mesh. */
|
|
647
|
+
get indexBuffer() {
|
|
648
|
+
return this._indexBuffer?.buffer;
|
|
649
|
+
}
|
|
650
|
+
/** Get the index format of the index buffer backing this mesh. */
|
|
651
|
+
get indexFormat() {
|
|
652
|
+
return this._indexBuffer?.format ?? IndexFormat.Uint16;
|
|
653
|
+
}
|
|
654
|
+
/** Get the number of indices in the index buffer backing this mesh. */
|
|
655
|
+
get numIndices() {
|
|
656
|
+
return this._indexBuffer?.count ?? 0;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function vertexFormatByteSize(format) {
|
|
660
|
+
switch (format) {
|
|
661
|
+
case VertexFormat.Uint8:
|
|
662
|
+
case VertexFormat.Sint8:
|
|
663
|
+
case VertexFormat.Unorm8:
|
|
664
|
+
case VertexFormat.Snorm8:
|
|
665
|
+
return 1;
|
|
666
|
+
case VertexFormat.Uint8x2:
|
|
667
|
+
case VertexFormat.Sint8x2:
|
|
668
|
+
case VertexFormat.Unorm8x2:
|
|
669
|
+
case VertexFormat.Snorm8x2:
|
|
670
|
+
case VertexFormat.Uint16:
|
|
671
|
+
case VertexFormat.Sint16:
|
|
672
|
+
case VertexFormat.Unorm16:
|
|
673
|
+
case VertexFormat.Snorm16:
|
|
674
|
+
case VertexFormat.Float16:
|
|
675
|
+
return 2;
|
|
676
|
+
case VertexFormat.Uint8x4:
|
|
677
|
+
case VertexFormat.Sint8x4:
|
|
678
|
+
case VertexFormat.Unorm8x4:
|
|
679
|
+
case VertexFormat.Snorm8x4:
|
|
680
|
+
case VertexFormat.Uint16x2:
|
|
681
|
+
case VertexFormat.Sint16x2:
|
|
682
|
+
case VertexFormat.Unorm16x2:
|
|
683
|
+
case VertexFormat.Snorm16x2:
|
|
684
|
+
case VertexFormat.Float16x2:
|
|
685
|
+
case VertexFormat.Float32:
|
|
686
|
+
case VertexFormat.Uint32:
|
|
687
|
+
case VertexFormat.Sint32:
|
|
688
|
+
case VertexFormat.Unorm10_10_10_2:
|
|
689
|
+
case VertexFormat.Unorm8x4_bgra:
|
|
690
|
+
return 4;
|
|
691
|
+
case VertexFormat.Uint16x4:
|
|
692
|
+
case VertexFormat.Sint16x4:
|
|
693
|
+
case VertexFormat.Unorm16x4:
|
|
694
|
+
case VertexFormat.Snorm16x4:
|
|
695
|
+
case VertexFormat.Float16x4:
|
|
696
|
+
case VertexFormat.Float32x2:
|
|
697
|
+
case VertexFormat.Uint32x2:
|
|
698
|
+
case VertexFormat.Sint32x2:
|
|
699
|
+
return 8;
|
|
700
|
+
case VertexFormat.Float32x3:
|
|
701
|
+
case VertexFormat.Uint32x3:
|
|
702
|
+
case VertexFormat.Sint32x3:
|
|
703
|
+
return 12;
|
|
704
|
+
case VertexFormat.Float32x4:
|
|
705
|
+
case VertexFormat.Uint32x4:
|
|
706
|
+
case VertexFormat.Sint32x4:
|
|
707
|
+
return 16;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
class VertexStream {
|
|
711
|
+
constructor() {
|
|
712
|
+
this.stride = 0;
|
|
713
|
+
this.attributes = [];
|
|
714
|
+
}
|
|
715
|
+
pushAttribute(name, format) {
|
|
716
|
+
this.attributes.push({ name, format, offset: this.stride });
|
|
717
|
+
this.stride += vertexFormatByteSize(format);
|
|
718
|
+
}
|
|
719
|
+
get numVertices() {
|
|
720
|
+
return this.buffer.size / this.stride;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Builder helper used when creating a vertex stream for a Mesh.
|
|
725
|
+
*/
|
|
726
|
+
class StreamBuilder {
|
|
727
|
+
/**
|
|
728
|
+
* @internal
|
|
729
|
+
*/
|
|
730
|
+
constructor(stream, ctx) {
|
|
731
|
+
this._stream = stream;
|
|
732
|
+
this._ctx = ctx;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Add a vertex attribute to the stream.
|
|
736
|
+
* @param name - attribute name used by the shader bindings
|
|
737
|
+
* @param format - attribute format (see VertexFormat)
|
|
738
|
+
*/
|
|
739
|
+
pushAttribute(name, format) {
|
|
740
|
+
this._stream.pushAttribute(name, format);
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Upload vertex data for this stream. `keepOnCPU` controls whether the
|
|
745
|
+
* source ArrayBuffer is retained in memory for readback.
|
|
746
|
+
*/
|
|
747
|
+
withData(data, keepOnCPU = false) {
|
|
748
|
+
this._stream.buffer = new _buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferBuilder(this._ctx)
|
|
749
|
+
.withData(data, keepOnCPU)
|
|
750
|
+
.withUsage(_buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferUsage.Vertex | _buffers_Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferUsage.CopyDst)
|
|
751
|
+
.build();
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Fluent builder for creating a Mesh. Use `pushStream()` to describe vertex
|
|
756
|
+
* streams and `withIndexData()` to add optional indices.
|
|
757
|
+
*/
|
|
758
|
+
class MeshBuilder {
|
|
759
|
+
/**
|
|
760
|
+
* @internal
|
|
761
|
+
*/
|
|
762
|
+
constructor(ctx) {
|
|
763
|
+
this._topology = MeshTopology.TriangleList;
|
|
764
|
+
this._frontFace = FrontFace.CounterClockwise;
|
|
765
|
+
this._streams = [];
|
|
766
|
+
this._ctx = ctx;
|
|
767
|
+
}
|
|
768
|
+
/** Add a vertex stream using a builder callback. */
|
|
769
|
+
pushStream(buildFunc) {
|
|
770
|
+
const stream = new VertexStream();
|
|
771
|
+
buildFunc(new StreamBuilder(stream, this._ctx));
|
|
772
|
+
console.assert(stream.buffer !== undefined, "Vertex stream must have a buffer. Did you forget to call withData()?");
|
|
773
|
+
this._streams.push(stream);
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
776
|
+
/** Set the winding used to determine front-facing triangles. Defaults to counter-clockwise. */
|
|
777
|
+
withFrontFace(value) {
|
|
778
|
+
this._frontFace = value;
|
|
779
|
+
return this;
|
|
780
|
+
}
|
|
781
|
+
/** Set the primitive topology for the mesh. Defaults to triangle list. */
|
|
782
|
+
withTopology(value) {
|
|
783
|
+
this._topology = value;
|
|
784
|
+
return this;
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Provide index data (Uint16Array or Uint32Array). If `keepOnCPU` is true the
|
|
788
|
+
* original array buffer will be preserved on the resulting mesh's index buffer.
|
|
789
|
+
*/
|
|
790
|
+
withIndexData(data, keepOnCPU = false) {
|
|
791
|
+
this._indexBuffer = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_1__.mapUndefined)(data, data => new IndexBuffer(data, this._ctx, keepOnCPU));
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
/** Build the mesh. */
|
|
795
|
+
build() {
|
|
796
|
+
console.assert(this._streams.length > 0, "Mesh must have at least one vertex stream.");
|
|
797
|
+
return new Mesh(this._topology, this._frontFace, this._streams, this._indexBuffer);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
/***/ }),
|
|
803
|
+
|
|
804
|
+
/***/ "./src/RenderPass.ts":
|
|
805
|
+
/*!***************************!*\
|
|
806
|
+
!*** ./src/RenderPass.ts ***!
|
|
807
|
+
\***************************/
|
|
808
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
809
|
+
|
|
810
|
+
__webpack_require__.r(__webpack_exports__);
|
|
811
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
812
|
+
/* harmony export */ RenderPass: () => (/* binding */ RenderPass),
|
|
813
|
+
/* harmony export */ RenderPassBuilder: () => (/* binding */ RenderPassBuilder)
|
|
814
|
+
/* harmony export */ });
|
|
815
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
816
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Lightweight wrapper around GPURenderPassEncoder. Provides a minimal API
|
|
821
|
+
* for ending the pass; higher-level helpers may be added later.
|
|
822
|
+
*/
|
|
823
|
+
class RenderPass {
|
|
824
|
+
/**
|
|
825
|
+
* Internal accessor for the underlying GPURenderPassEncoder. Not intended for public use.
|
|
826
|
+
* @internal
|
|
827
|
+
*/
|
|
828
|
+
constructor(inner) {
|
|
829
|
+
this._numVertices = 0;
|
|
830
|
+
this._numIndices = 0;
|
|
831
|
+
this._inner = inner;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Set the render pipeline to use for the next draw calls.
|
|
835
|
+
* @param pipeline
|
|
836
|
+
*/
|
|
837
|
+
setPipeline(pipeline) {
|
|
838
|
+
if (this._renderPipeline != pipeline) {
|
|
839
|
+
this._inner.setPipeline(pipeline._inner);
|
|
840
|
+
this._renderPipeline = pipeline;
|
|
841
|
+
}
|
|
842
|
+
return this;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Sets the mesh to use for the next draw calls.
|
|
846
|
+
* @param mesh
|
|
847
|
+
*/
|
|
848
|
+
setMesh(mesh) {
|
|
849
|
+
for (let i = 0; i < mesh.numStreams; ++i) {
|
|
850
|
+
const vertex_buffer = mesh.getVertexBuffer(i);
|
|
851
|
+
this._inner.setVertexBuffer(i, vertex_buffer._inner);
|
|
852
|
+
}
|
|
853
|
+
this._numVertices = mesh.numVertices;
|
|
854
|
+
const indexBuffer = mesh.indexBuffer;
|
|
855
|
+
if (indexBuffer) {
|
|
856
|
+
this._inner.setIndexBuffer(indexBuffer._inner, mesh.indexFormat);
|
|
857
|
+
this._numIndices = mesh.numIndices;
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
this._numIndices = 0;
|
|
861
|
+
}
|
|
862
|
+
return this;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Set a bind group at the given index.
|
|
866
|
+
* @param index - bind group index in the render pipeline layout
|
|
867
|
+
* @param bindGroup - a `BindGroup` instance
|
|
868
|
+
*/
|
|
869
|
+
setBindGroup(index, bindGroup) {
|
|
870
|
+
this._inner.setBindGroup(index, bindGroup._inner);
|
|
871
|
+
return this;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Issue a draw call using the currently set pipeline and mesh.
|
|
875
|
+
*/
|
|
876
|
+
draw() {
|
|
877
|
+
if (this._numIndices) {
|
|
878
|
+
this._inner.drawIndexed(this._numIndices, 1, 0, 0, 0);
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
this._inner.draw(this._numVertices, 1, 0, 0);
|
|
882
|
+
}
|
|
883
|
+
return this;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* End the render pass. After calling end(), the underlying encoder may
|
|
887
|
+
* continue recording other passes or be finished/submitted.
|
|
888
|
+
*/
|
|
889
|
+
end() {
|
|
890
|
+
this._inner.end();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Fluent builder for configuring and creating a render pass.
|
|
895
|
+
*
|
|
896
|
+
* Use the builder to specify color targets, clear values and labels before
|
|
897
|
+
* calling `build()` to obtain a `RenderPass` instance.
|
|
898
|
+
*/
|
|
899
|
+
class RenderPassBuilder {
|
|
900
|
+
/**
|
|
901
|
+
* Create a new builder instance. This should only be called from the CommandEncoder
|
|
902
|
+
* instance (see {@link CommandEncoder.createRenderPass}).
|
|
903
|
+
* @internal
|
|
904
|
+
*/
|
|
905
|
+
constructor(commandEncoder, globalBindGroups, defaultTarget, defaultDepthTarget) {
|
|
906
|
+
this._colorTargets = [];
|
|
907
|
+
this._clearColors = [];
|
|
908
|
+
this._encoder = commandEncoder;
|
|
909
|
+
this._defaultTarget = defaultTarget;
|
|
910
|
+
this._defaultDepthTarget = defaultDepthTarget;
|
|
911
|
+
this._globalBindGroups = globalBindGroups;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Assign a human-readable label for the render pass (useful for GPU debuggers).
|
|
915
|
+
*/
|
|
916
|
+
withLabel(label) {
|
|
917
|
+
this._label = label;
|
|
918
|
+
return this;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Add a color target to render into. If no targets are added the default
|
|
922
|
+
* backbuffer target will be used.
|
|
923
|
+
*/
|
|
924
|
+
withColorTarget(target) {
|
|
925
|
+
this._colorTargets.push(target);
|
|
926
|
+
return this;
|
|
927
|
+
}
|
|
928
|
+
withDepthStencilTarget(target) {
|
|
929
|
+
this._depthTarget = target;
|
|
930
|
+
return this;
|
|
931
|
+
}
|
|
932
|
+
withClearColor(r, g, b, a) {
|
|
933
|
+
let color;
|
|
934
|
+
if (r === undefined) {
|
|
935
|
+
color = [0.0, 0.0, 0.0, 1.0];
|
|
936
|
+
}
|
|
937
|
+
else if (typeof r === 'number') {
|
|
938
|
+
color = [r, g ?? 0.0, b ?? 0.0, a ?? 1.0];
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
color = [r[0], r[1], r[2], r[3] ?? 1.0];
|
|
942
|
+
}
|
|
943
|
+
// rendering to the default target is special cased, so we need to set the clear color for the last target
|
|
944
|
+
if (this._colorTargets.length === 0) {
|
|
945
|
+
this._clearColors[0] = color;
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
this._clearColors[this._colorTargets.length - 1] = color;
|
|
949
|
+
}
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Set the clear stencil value
|
|
954
|
+
*/
|
|
955
|
+
withClearStencil(stencil) {
|
|
956
|
+
this._clearStencil = stencil;
|
|
957
|
+
return this;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Set the clear depth value
|
|
961
|
+
*/
|
|
962
|
+
withClearDepth(depth) {
|
|
963
|
+
this._clearDepth = depth;
|
|
964
|
+
return this;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Build and begin the render pass. Returns a `RenderPass` wrapper around
|
|
968
|
+
* the low-level GPURenderPassEncoder.
|
|
969
|
+
*/
|
|
970
|
+
build() {
|
|
971
|
+
let targets;
|
|
972
|
+
let depthTarget;
|
|
973
|
+
// if anything was specified specifically, use those, otherwise use the defaults
|
|
974
|
+
if (this._colorTargets.length || !!this._depthTarget) {
|
|
975
|
+
targets = this._colorTargets;
|
|
976
|
+
depthTarget = this._depthTarget;
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
targets = [this._defaultTarget];
|
|
980
|
+
depthTarget = this._defaultDepthTarget;
|
|
981
|
+
}
|
|
982
|
+
let stencilLoadOp;
|
|
983
|
+
let stencilStoreOp;
|
|
984
|
+
let stencilClearValue;
|
|
985
|
+
if (depthTarget?.format === _enums__WEBPACK_IMPORTED_MODULE_1__.TextureFormat.Depth32FloatStencil8 || depthTarget?.format === _enums__WEBPACK_IMPORTED_MODULE_1__.TextureFormat.Depth24PlusStencil8) {
|
|
986
|
+
stencilLoadOp = this._clearStencil != undefined ? 'clear' : 'load';
|
|
987
|
+
stencilStoreOp = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._clearStencil, () => 'store');
|
|
988
|
+
stencilClearValue = this._clearStencil;
|
|
989
|
+
}
|
|
990
|
+
const colorAttachments = targets.map((target, i) => ({
|
|
991
|
+
view: target._inner,
|
|
992
|
+
loadOp: this._clearColors[i] ? 'clear' : 'load',
|
|
993
|
+
storeOp: 'store',
|
|
994
|
+
clearValue: this._clearColors[i]
|
|
995
|
+
}));
|
|
996
|
+
const desc = {
|
|
997
|
+
colorAttachments,
|
|
998
|
+
depthStencilAttachment: (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(depthTarget, target => ({
|
|
999
|
+
view: target._inner,
|
|
1000
|
+
depthClearValue: this._clearDepth,
|
|
1001
|
+
depthLoadOp: this._clearDepth != undefined ? 'clear' : 'load',
|
|
1002
|
+
depthStoreOp: (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._clearDepth, () => 'store'),
|
|
1003
|
+
stencilClearValue,
|
|
1004
|
+
stencilLoadOp,
|
|
1005
|
+
stencilStoreOp
|
|
1006
|
+
})),
|
|
1007
|
+
label: this._label
|
|
1008
|
+
};
|
|
1009
|
+
const pass = new RenderPass(this._encoder.beginRenderPass(desc));
|
|
1010
|
+
this._globalBindGroups.forEach((group, i) => pass.setBindGroup(i, group));
|
|
1011
|
+
return pass;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
/***/ }),
|
|
1017
|
+
|
|
1018
|
+
/***/ "./src/RenderPipeline.ts":
|
|
1019
|
+
/*!*******************************!*\
|
|
1020
|
+
!*** ./src/RenderPipeline.ts ***!
|
|
1021
|
+
\*******************************/
|
|
1022
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1023
|
+
|
|
1024
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1025
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1026
|
+
/* harmony export */ RenderPipeline: () => (/* binding */ RenderPipeline),
|
|
1027
|
+
/* harmony export */ RenderPipelineBuilder: () => (/* binding */ RenderPipelineBuilder)
|
|
1028
|
+
/* harmony export */ });
|
|
1029
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
1030
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Thin wrapper around GPURenderPipeline exposing a small helper for attribute
|
|
1035
|
+
* location lookup. The underlying pipeline and shader are available for advanced use.
|
|
1036
|
+
*/
|
|
1037
|
+
class RenderPipeline {
|
|
1038
|
+
constructor(inner, shader) {
|
|
1039
|
+
this._inner = inner;
|
|
1040
|
+
this._shader = shader;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Helper to get the shader-declared attribute location for a named attribute.
|
|
1044
|
+
*/
|
|
1045
|
+
getVertexAttributeLocation(name) {
|
|
1046
|
+
return this._shader.getVertexAttributeLocation(name);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Fluent builder for creating a GPURenderPipeline. Attach a `Shader` and
|
|
1051
|
+
* optionally a `Mesh` (to derive vertex buffer layouts) before calling `build()`.
|
|
1052
|
+
*/
|
|
1053
|
+
class RenderPipelineBuilder {
|
|
1054
|
+
constructor(ctx, defaultDepthFormat) {
|
|
1055
|
+
this._colorTargets = [];
|
|
1056
|
+
this._vertexEntry = undefined;
|
|
1057
|
+
this._fragmentEntry = undefined;
|
|
1058
|
+
this._label = undefined;
|
|
1059
|
+
this._overrideConstants = {};
|
|
1060
|
+
this._cullMode = _enums__WEBPACK_IMPORTED_MODULE_1__.CullMode.Back;
|
|
1061
|
+
this._mesh = undefined;
|
|
1062
|
+
this._ctx = ctx;
|
|
1063
|
+
this._defaultColorState = [{
|
|
1064
|
+
format: ctx.format,
|
|
1065
|
+
blend: undefined,
|
|
1066
|
+
writeMask: GPUColorWrite.ALL
|
|
1067
|
+
}];
|
|
1068
|
+
this._defaultDepthState = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(defaultDepthFormat, format => ({
|
|
1069
|
+
format,
|
|
1070
|
+
depthWriteEnabled: true,
|
|
1071
|
+
depthCompare: 'less',
|
|
1072
|
+
}));
|
|
1073
|
+
}
|
|
1074
|
+
/** Assign a human-readable label for the pipeline (useful in graphics debuggers). */
|
|
1075
|
+
withLabel(label) {
|
|
1076
|
+
this._label = label;
|
|
1077
|
+
return this;
|
|
1078
|
+
}
|
|
1079
|
+
/** Set face-culling mode. Default is `Back`. */
|
|
1080
|
+
withCullMode(value) {
|
|
1081
|
+
this._cullMode = value;
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1084
|
+
/** Provide a Mesh to automatically derive vertex buffer layouts. */
|
|
1085
|
+
withMesh(mesh) {
|
|
1086
|
+
this._mesh = mesh;
|
|
1087
|
+
return this;
|
|
1088
|
+
}
|
|
1089
|
+
/** Attach a compiled Shader to the pipeline. */
|
|
1090
|
+
withShader(shader) {
|
|
1091
|
+
this._shader = shader;
|
|
1092
|
+
return this;
|
|
1093
|
+
}
|
|
1094
|
+
/** Select the shader entry point for the vertex stage. */
|
|
1095
|
+
withVertexShader(entry) {
|
|
1096
|
+
this._vertexEntry = entry;
|
|
1097
|
+
return this;
|
|
1098
|
+
}
|
|
1099
|
+
/** Select the shader entry point for the fragment stage. */
|
|
1100
|
+
withFragmentShader(entry) {
|
|
1101
|
+
this._fragmentEntry = entry;
|
|
1102
|
+
return this;
|
|
1103
|
+
}
|
|
1104
|
+
/** Add a color target with the given texture format. */
|
|
1105
|
+
withColorTarget(format) {
|
|
1106
|
+
this._colorTargets.push({
|
|
1107
|
+
format,
|
|
1108
|
+
blend: undefined,
|
|
1109
|
+
writeMask: GPUColorWrite.ALL
|
|
1110
|
+
});
|
|
1111
|
+
return this;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Add a depth target with the given texture format.
|
|
1115
|
+
*/
|
|
1116
|
+
withDepthTarget(format) {
|
|
1117
|
+
this._depthState = {
|
|
1118
|
+
format,
|
|
1119
|
+
...this._defaultDepthState
|
|
1120
|
+
};
|
|
1121
|
+
return this;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Set the depth compare function. Default is `less`.
|
|
1125
|
+
* @param compare
|
|
1126
|
+
*/
|
|
1127
|
+
withDepthCompare(compare) {
|
|
1128
|
+
const target = this._depthState ?? this._defaultDepthState;
|
|
1129
|
+
if (!target) {
|
|
1130
|
+
console.warn("No depth target set. Setting depth compare function has no effect.");
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
target.depthCompare = compare;
|
|
1134
|
+
}
|
|
1135
|
+
return this;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Enable or disable depth writes. Default is `true`.
|
|
1139
|
+
* @param enabled
|
|
1140
|
+
*/
|
|
1141
|
+
withDepthWrite(enabled) {
|
|
1142
|
+
const target = this._depthState ?? this._defaultDepthState;
|
|
1143
|
+
if (!target) {
|
|
1144
|
+
console.warn("No depth target set. Setting depth write enabled has no effect.");
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
target.depthWriteEnabled = enabled;
|
|
1148
|
+
}
|
|
1149
|
+
return this;
|
|
1150
|
+
}
|
|
1151
|
+
/** Override a shader constant for specialization. */
|
|
1152
|
+
withOverrideConstant(id, value) {
|
|
1153
|
+
this._overrideConstants[id] = value;
|
|
1154
|
+
return this;
|
|
1155
|
+
}
|
|
1156
|
+
/** Set the blend mode for the last assigned (or default) color target. */
|
|
1157
|
+
withBlendMode(blendMode) {
|
|
1158
|
+
this.lastColorTarget.blend = blendMode._inner;
|
|
1159
|
+
return this;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Build and create the `RenderPipeline`. Throws if required pieces (shader/vertices)
|
|
1163
|
+
* are missing.
|
|
1164
|
+
*/
|
|
1165
|
+
build() {
|
|
1166
|
+
if (!this._shader) {
|
|
1167
|
+
throw new Error("Shader not specified. Use withShader() to set the shader to use.");
|
|
1168
|
+
}
|
|
1169
|
+
const shader = this._shader;
|
|
1170
|
+
if (this._vertexEntry === undefined) {
|
|
1171
|
+
throw new Error("Shader does not contain a vertex entry point. Use ShaderBuilder.withVertexShader() to set one.");
|
|
1172
|
+
}
|
|
1173
|
+
let colorTargets;
|
|
1174
|
+
let depthState;
|
|
1175
|
+
if (this._colorTargets.length || !!this._depthState) {
|
|
1176
|
+
colorTargets = this._colorTargets;
|
|
1177
|
+
depthState = this._depthState;
|
|
1178
|
+
}
|
|
1179
|
+
else {
|
|
1180
|
+
// only use defaults if no targets were set explicitly
|
|
1181
|
+
colorTargets = this._defaultColorState;
|
|
1182
|
+
depthState = this._defaultDepthState;
|
|
1183
|
+
}
|
|
1184
|
+
const primitive = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._mesh, mesh => ({
|
|
1185
|
+
topology: mesh.topology,
|
|
1186
|
+
frontFace: mesh.frontFace,
|
|
1187
|
+
cullMode: this._cullMode,
|
|
1188
|
+
}));
|
|
1189
|
+
const buffers = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._mesh, mesh => {
|
|
1190
|
+
const buffers = [];
|
|
1191
|
+
for (let i = 0; i < mesh.numStreams; ++i) {
|
|
1192
|
+
const attributes = mesh.getStreamAttributes(i)
|
|
1193
|
+
.filter(attr => shader.hasVertexAttribute(attr.name))
|
|
1194
|
+
.map(attr => ({
|
|
1195
|
+
shaderLocation: shader.getVertexAttributeLocation(attr.name),
|
|
1196
|
+
offset: attr.offset,
|
|
1197
|
+
format: attr.format,
|
|
1198
|
+
}));
|
|
1199
|
+
buffers.push({
|
|
1200
|
+
arrayStride: mesh.getStreamStride(i),
|
|
1201
|
+
stepMode: 'vertex',
|
|
1202
|
+
attributes
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
return buffers;
|
|
1206
|
+
});
|
|
1207
|
+
const layout = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(shader._bindGroupLayouts, bindGroupLayouts => this._ctx.device.createPipelineLayout({
|
|
1208
|
+
bindGroupLayouts: bindGroupLayouts.map(value => value._inner),
|
|
1209
|
+
label: this._label
|
|
1210
|
+
})) ?? "auto";
|
|
1211
|
+
const desc = {
|
|
1212
|
+
label: this._label,
|
|
1213
|
+
layout,
|
|
1214
|
+
primitive,
|
|
1215
|
+
depthStencil: depthState,
|
|
1216
|
+
vertex: {
|
|
1217
|
+
buffers,
|
|
1218
|
+
module: shader._inner,
|
|
1219
|
+
entryPoint: this._vertexEntry,
|
|
1220
|
+
constants: this._overrideConstants
|
|
1221
|
+
},
|
|
1222
|
+
fragment: (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._fragmentEntry, entry => ({
|
|
1223
|
+
module: shader._inner,
|
|
1224
|
+
entryPoint: entry,
|
|
1225
|
+
targets: colorTargets,
|
|
1226
|
+
constants: this._overrideConstants
|
|
1227
|
+
}))
|
|
1228
|
+
};
|
|
1229
|
+
const inner = this._ctx.device.createRenderPipeline(desc);
|
|
1230
|
+
return new RenderPipeline(inner, shader);
|
|
1231
|
+
}
|
|
1232
|
+
get lastColorTarget() {
|
|
1233
|
+
return this._colorTargets.length ? this._colorTargets[this._colorTargets.length - 1] : this._defaultColorState[0];
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
/***/ }),
|
|
1239
|
+
|
|
1240
|
+
/***/ "./src/RenderTarget.ts":
|
|
1241
|
+
/*!*****************************!*\
|
|
1242
|
+
!*** ./src/RenderTarget.ts ***!
|
|
1243
|
+
\*****************************/
|
|
1244
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1245
|
+
|
|
1246
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1247
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1248
|
+
/* harmony export */ RenderTarget: () => (/* binding */ RenderTarget),
|
|
1249
|
+
/* harmony export */ RenderTargetBuilder: () => (/* binding */ RenderTargetBuilder)
|
|
1250
|
+
/* harmony export */ });
|
|
1251
|
+
/**
|
|
1252
|
+
* Lightweight wrapper around a GPUTextureView representing a render target.
|
|
1253
|
+
* Use `view()` to get the underlying GPUTextureView when building render passes.
|
|
1254
|
+
*/
|
|
1255
|
+
class RenderTarget {
|
|
1256
|
+
constructor(view, format) {
|
|
1257
|
+
this._inner = view;
|
|
1258
|
+
this._format = format;
|
|
1259
|
+
}
|
|
1260
|
+
get format() {
|
|
1261
|
+
return this._format;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Builder for creating a `RenderTarget` from a `Texture`.
|
|
1266
|
+
*
|
|
1267
|
+
* The builder produces a GPUTextureView configured with a sensible default
|
|
1268
|
+
* descriptor and wraps it in a `RenderTarget` helper.
|
|
1269
|
+
*/
|
|
1270
|
+
class RenderTargetBuilder {
|
|
1271
|
+
/**
|
|
1272
|
+
* Create a new RenderTargetBuilder for the given texture. This should only be called
|
|
1273
|
+
* from the TinyHelix instance (see {@link TinyHelix.createRenderTarget}).
|
|
1274
|
+
* @param texture
|
|
1275
|
+
*
|
|
1276
|
+
* @internal
|
|
1277
|
+
*/
|
|
1278
|
+
constructor(texture) {
|
|
1279
|
+
this._baseMipLevel = 0;
|
|
1280
|
+
this._baseArrayLayer = 0;
|
|
1281
|
+
this._texture = texture;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Set the base mip level to use for the render target. Defaults to 0.
|
|
1285
|
+
*/
|
|
1286
|
+
withMipLevel(level) {
|
|
1287
|
+
this._baseMipLevel = level;
|
|
1288
|
+
return this;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Set the base array layer to use for the render target. Defaults to 0.
|
|
1292
|
+
*/
|
|
1293
|
+
withArrayLayer(layer) {
|
|
1294
|
+
this._baseArrayLayer = layer;
|
|
1295
|
+
return this;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Create and return a new `RenderTarget` instance.
|
|
1299
|
+
*/
|
|
1300
|
+
build() {
|
|
1301
|
+
const tex = this._texture._inner;
|
|
1302
|
+
const desc = {
|
|
1303
|
+
format: tex.format,
|
|
1304
|
+
dimension: tex.dimension,
|
|
1305
|
+
aspect: 'all',
|
|
1306
|
+
baseMipLevel: this._baseMipLevel,
|
|
1307
|
+
mipLevelCount: 1,
|
|
1308
|
+
baseArrayLayer: this._baseArrayLayer,
|
|
1309
|
+
arrayLayerCount: 1
|
|
1310
|
+
};
|
|
1311
|
+
return new RenderTarget(this._texture._inner.createView(desc), this._texture.format);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
/***/ }),
|
|
1317
|
+
|
|
1318
|
+
/***/ "./src/Sampler.ts":
|
|
1319
|
+
/*!************************!*\
|
|
1320
|
+
!*** ./src/Sampler.ts ***!
|
|
1321
|
+
\************************/
|
|
1322
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1323
|
+
|
|
1324
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1325
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1326
|
+
/* harmony export */ Sampler: () => (/* binding */ Sampler),
|
|
1327
|
+
/* harmony export */ SamplerBuilder: () => (/* binding */ SamplerBuilder)
|
|
1328
|
+
/* harmony export */ });
|
|
1329
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
1330
|
+
|
|
1331
|
+
class Sampler {
|
|
1332
|
+
constructor(inner) {
|
|
1333
|
+
this._inner = inner;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
class SamplerBuilder {
|
|
1337
|
+
constructor(ctx) {
|
|
1338
|
+
this._ctx = ctx;
|
|
1339
|
+
}
|
|
1340
|
+
withAddressMode(u, v, w) {
|
|
1341
|
+
this._addressModeU = u;
|
|
1342
|
+
this._addressModeV = v ?? u;
|
|
1343
|
+
this._addressModeW = w ?? u;
|
|
1344
|
+
return this;
|
|
1345
|
+
}
|
|
1346
|
+
withFiltering(minFilter, magFilter, mipmapFilter) {
|
|
1347
|
+
this._minFilter = minFilter;
|
|
1348
|
+
this._magFilter = magFilter ?? minFilter;
|
|
1349
|
+
this._mipmapFilter = mipmapFilter ?? minFilter;
|
|
1350
|
+
return this;
|
|
1351
|
+
}
|
|
1352
|
+
withTrilinearFiltering() {
|
|
1353
|
+
this.withFiltering(_enums__WEBPACK_IMPORTED_MODULE_0__.FilterMode.Linear);
|
|
1354
|
+
return this;
|
|
1355
|
+
}
|
|
1356
|
+
withNearestFiltering() {
|
|
1357
|
+
this.withFiltering(_enums__WEBPACK_IMPORTED_MODULE_0__.FilterMode.Nearest);
|
|
1358
|
+
return this;
|
|
1359
|
+
}
|
|
1360
|
+
withAnisotropicFiltering(maxAnisotropy) {
|
|
1361
|
+
this.withFiltering(_enums__WEBPACK_IMPORTED_MODULE_0__.FilterMode.Linear);
|
|
1362
|
+
this._maxAnisotropy = maxAnisotropy;
|
|
1363
|
+
return this;
|
|
1364
|
+
}
|
|
1365
|
+
withMinMipLevel(level) {
|
|
1366
|
+
this._minMipLevel = level;
|
|
1367
|
+
return this;
|
|
1368
|
+
}
|
|
1369
|
+
withMaxMipLevel(level) {
|
|
1370
|
+
this._maxMipLevel = level;
|
|
1371
|
+
return this;
|
|
1372
|
+
}
|
|
1373
|
+
withCompareFunction(compare) {
|
|
1374
|
+
this._compare = compare;
|
|
1375
|
+
return this;
|
|
1376
|
+
}
|
|
1377
|
+
build() {
|
|
1378
|
+
return new Sampler(this._ctx.device.createSampler({
|
|
1379
|
+
addressModeU: this._addressModeU,
|
|
1380
|
+
addressModeV: this._addressModeV,
|
|
1381
|
+
addressModeW: this._addressModeW,
|
|
1382
|
+
magFilter: this._magFilter,
|
|
1383
|
+
minFilter: this._minFilter,
|
|
1384
|
+
mipmapFilter: this._mipmapFilter,
|
|
1385
|
+
lodMinClamp: this._minMipLevel,
|
|
1386
|
+
lodMaxClamp: this._maxMipLevel,
|
|
1387
|
+
compare: this._compare,
|
|
1388
|
+
maxAnisotropy: this._maxAnisotropy
|
|
1389
|
+
}));
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
/***/ }),
|
|
1395
|
+
|
|
1396
|
+
/***/ "./src/Shader.ts":
|
|
1397
|
+
/*!***********************!*\
|
|
1398
|
+
!*** ./src/Shader.ts ***!
|
|
1399
|
+
\***********************/
|
|
1400
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1401
|
+
|
|
1402
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1403
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1404
|
+
/* harmony export */ Shader: () => (/* binding */ Shader),
|
|
1405
|
+
/* harmony export */ ShaderBuilder: () => (/* binding */ ShaderBuilder)
|
|
1406
|
+
/* harmony export */ });
|
|
1407
|
+
/* harmony import */ var _BindGroup__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BindGroup */ "./src/BindGroup.ts");
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Wrapper around GPUShaderModule. Keeps a map of vertex attribute names to
|
|
1411
|
+
* shader locations to aid pipeline construction.
|
|
1412
|
+
*/
|
|
1413
|
+
class Shader {
|
|
1414
|
+
/**
|
|
1415
|
+
* @internal
|
|
1416
|
+
*/
|
|
1417
|
+
constructor(inner, ctx, vertexAttributes, bindGroupLayouts) {
|
|
1418
|
+
this._inner = inner;
|
|
1419
|
+
this._ctx = ctx;
|
|
1420
|
+
this._vertexAttributes = vertexAttributes;
|
|
1421
|
+
this._bindGroupLayouts = bindGroupLayouts;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Get the shader location for a named vertex attribute. Returns undefined if the attribute
|
|
1425
|
+
* is not declared by the shader.
|
|
1426
|
+
*/
|
|
1427
|
+
getVertexAttributeLocation(name) {
|
|
1428
|
+
return this._vertexAttributes.get(name) ?? undefined;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Returns true if the shader declares a vertex attribute with the given name.
|
|
1432
|
+
* @param name
|
|
1433
|
+
*/
|
|
1434
|
+
hasVertexAttribute(name) {
|
|
1435
|
+
return this._vertexAttributes.has(name);
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Create a BindGroupBuilder for the shader's bind group at the given index.
|
|
1439
|
+
* @param group - index of the bind group declared by the shader
|
|
1440
|
+
*/
|
|
1441
|
+
createBindGroup(group) {
|
|
1442
|
+
return new _BindGroup__WEBPACK_IMPORTED_MODULE_0__.BindGroupBuilder(this._ctx, this._bindGroupLayouts[group]);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Builder for creating shader modules and declaring attribute locations used by the helper
|
|
1447
|
+
* pipeline builder.
|
|
1448
|
+
*/
|
|
1449
|
+
class ShaderBuilder {
|
|
1450
|
+
/**
|
|
1451
|
+
* @internal
|
|
1452
|
+
*/
|
|
1453
|
+
constructor(ctx) {
|
|
1454
|
+
this._vertexAttributes = new Map(); // name -> location
|
|
1455
|
+
this._includes = new Map();
|
|
1456
|
+
this._ctx = ctx;
|
|
1457
|
+
}
|
|
1458
|
+
/** Optional label for the underlying GPUShaderModule. */
|
|
1459
|
+
withLabel(label) {
|
|
1460
|
+
this._label = label;
|
|
1461
|
+
return this;
|
|
1462
|
+
}
|
|
1463
|
+
/** Set WGSL or other shader code to compile into a GPUShaderModule. */
|
|
1464
|
+
withCode(code) {
|
|
1465
|
+
this._code = code;
|
|
1466
|
+
return this;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Add a named include to the shader code. The include will be expanded
|
|
1470
|
+
* in the shader code before compilation. The include name must be unique
|
|
1471
|
+
* within the shader code. This allows using `#include<name>` in the shader
|
|
1472
|
+
* code to include other files. While this is not standard WGSL, it's too
|
|
1473
|
+
* useful not to support.
|
|
1474
|
+
*
|
|
1475
|
+
* @param name - The name as used in the `#include<name>` directive.
|
|
1476
|
+
* @param code - The code the include should expand to.
|
|
1477
|
+
*/
|
|
1478
|
+
withInclude(name, code) {
|
|
1479
|
+
this._includes.set(name, code);
|
|
1480
|
+
return this;
|
|
1481
|
+
}
|
|
1482
|
+
/** Declare a named vertex attribute and the location it maps to in the shader. */
|
|
1483
|
+
withVertexAttribute(name, location) {
|
|
1484
|
+
this._vertexAttributes.set(name, location);
|
|
1485
|
+
return this;
|
|
1486
|
+
}
|
|
1487
|
+
withBindGroup(index, layout) {
|
|
1488
|
+
this._bindGroupLayouts = this._bindGroupLayouts ?? [];
|
|
1489
|
+
if (layout instanceof _BindGroup__WEBPACK_IMPORTED_MODULE_0__.BindGroupLayout) {
|
|
1490
|
+
this._bindGroupLayouts[index] = layout;
|
|
1491
|
+
}
|
|
1492
|
+
else {
|
|
1493
|
+
const builder = new _BindGroup__WEBPACK_IMPORTED_MODULE_0__["default"](this._ctx);
|
|
1494
|
+
layout(builder);
|
|
1495
|
+
this._bindGroupLayouts[index] = builder.build();
|
|
1496
|
+
}
|
|
1497
|
+
return this;
|
|
1498
|
+
}
|
|
1499
|
+
// TODO: Provide layout methods
|
|
1500
|
+
/** Compile the shader module and return a `Shader` instance. */
|
|
1501
|
+
build() {
|
|
1502
|
+
if (!this._code) {
|
|
1503
|
+
throw new Error("Shader code not specified. Use withCode() to set the shader source.");
|
|
1504
|
+
}
|
|
1505
|
+
let code = this._code;
|
|
1506
|
+
for (const [name, inc] of this._includes) {
|
|
1507
|
+
// Create a regex to match the include directive while allowing
|
|
1508
|
+
// optional whitespace between tokens, e.g.:
|
|
1509
|
+
// #include<name>
|
|
1510
|
+
// # include < name >
|
|
1511
|
+
// and so on. Escape the include name so it is safe in a RegExp.
|
|
1512
|
+
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1513
|
+
const includeRegex = new RegExp(`#\\s*include\\s*<\\s*${escapedName}\\s*>`, 'g');
|
|
1514
|
+
code = code.replace(includeRegex, inc);
|
|
1515
|
+
}
|
|
1516
|
+
const inner = this._ctx.device.createShaderModule({
|
|
1517
|
+
label: this._label,
|
|
1518
|
+
code,
|
|
1519
|
+
});
|
|
1520
|
+
return new Shader(inner, this._ctx, this._vertexAttributes, this._bindGroupLayouts);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
/***/ }),
|
|
1526
|
+
|
|
1527
|
+
/***/ "./src/Texture.ts":
|
|
1528
|
+
/*!************************!*\
|
|
1529
|
+
!*** ./src/Texture.ts ***!
|
|
1530
|
+
\************************/
|
|
1531
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1532
|
+
|
|
1533
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1534
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1535
|
+
/* harmony export */ Texture: () => (/* binding */ Texture),
|
|
1536
|
+
/* harmony export */ TextureBuilder: () => (/* binding */ TextureBuilder),
|
|
1537
|
+
/* harmony export */ TextureView: () => (/* binding */ TextureView),
|
|
1538
|
+
/* harmony export */ TextureViewBuilder: () => (/* binding */ TextureViewBuilder)
|
|
1539
|
+
/* harmony export */ });
|
|
1540
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
1541
|
+
|
|
1542
|
+
/**
|
|
1543
|
+
* Small wrapper around GPUTexture providing convenience constructors and
|
|
1544
|
+
* an internal accessor for low-level interop.
|
|
1545
|
+
*/
|
|
1546
|
+
class Texture {
|
|
1547
|
+
/**
|
|
1548
|
+
* Create a Texture wrapper from an existing GPUTexture.
|
|
1549
|
+
* @param texture - The underlying GPUTexture
|
|
1550
|
+
*/
|
|
1551
|
+
static from_webgpu(texture, format) {
|
|
1552
|
+
return new Texture(texture, format);
|
|
1553
|
+
}
|
|
1554
|
+
constructor(inner, format) {
|
|
1555
|
+
this._inner = inner;
|
|
1556
|
+
this._format = format;
|
|
1557
|
+
}
|
|
1558
|
+
createView() {
|
|
1559
|
+
return new TextureViewBuilder(this);
|
|
1560
|
+
}
|
|
1561
|
+
get format() {
|
|
1562
|
+
return this._format;
|
|
1563
|
+
}
|
|
1564
|
+
_getBufferResource() {
|
|
1565
|
+
return this._inner.createView();
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
class TextureBuilder {
|
|
1569
|
+
constructor(ctx) {
|
|
1570
|
+
this._size = [1, 1, 1];
|
|
1571
|
+
this._data = undefined;
|
|
1572
|
+
this._format = _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8UnormSrgb;
|
|
1573
|
+
this._usage = GPUTextureUsage.TEXTURE_BINDING;
|
|
1574
|
+
this._ctx = ctx;
|
|
1575
|
+
}
|
|
1576
|
+
withSize(width, height, depthOrArrayLayers = 1) {
|
|
1577
|
+
this._size = [width, height, depthOrArrayLayers];
|
|
1578
|
+
return this;
|
|
1579
|
+
}
|
|
1580
|
+
withData(data) {
|
|
1581
|
+
this._data = data;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
withFormat(format) {
|
|
1585
|
+
this._format = format;
|
|
1586
|
+
return this;
|
|
1587
|
+
}
|
|
1588
|
+
withImage(data) {
|
|
1589
|
+
this._data = data;
|
|
1590
|
+
this._size = [data.width, data.height, 1];
|
|
1591
|
+
return this;
|
|
1592
|
+
}
|
|
1593
|
+
withUsage(usage) {
|
|
1594
|
+
this._usage |= usage;
|
|
1595
|
+
return this;
|
|
1596
|
+
}
|
|
1597
|
+
build() {
|
|
1598
|
+
if (this._data) {
|
|
1599
|
+
this._usage |= GPUTextureUsage.COPY_DST;
|
|
1600
|
+
}
|
|
1601
|
+
const inner = this._ctx.device.createTexture({
|
|
1602
|
+
format: this._format, size: this._size, usage: this._usage
|
|
1603
|
+
});
|
|
1604
|
+
if (this._data instanceof ImageBitmap) {
|
|
1605
|
+
this._ctx.device.queue.copyExternalImageToTexture({ source: this._data }, { texture: inner }, [this._size[0], this._size[1], 1]);
|
|
1606
|
+
}
|
|
1607
|
+
else if (this._data) {
|
|
1608
|
+
const [width, height, depthOrArrayLayers] = this._size;
|
|
1609
|
+
const blockWidth = getBlockWidth(this._format);
|
|
1610
|
+
const blocksPerRow = Math.ceil(width / blockWidth);
|
|
1611
|
+
const bytesPerRow = blocksPerRow * bytesPerBlock(this._format);
|
|
1612
|
+
this._ctx.device.queue.writeTexture({ texture: inner }, this._data, { bytesPerRow }, { width, height, depthOrArrayLayers });
|
|
1613
|
+
}
|
|
1614
|
+
return new Texture(inner, this._format);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
class TextureView {
|
|
1618
|
+
constructor(inner) {
|
|
1619
|
+
this._inner = inner;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
class TextureViewBuilder {
|
|
1623
|
+
/**
|
|
1624
|
+
* @internal
|
|
1625
|
+
*/
|
|
1626
|
+
constructor(texture) {
|
|
1627
|
+
this._desc = {};
|
|
1628
|
+
this._texture = texture;
|
|
1629
|
+
}
|
|
1630
|
+
withSingleMip(level) {
|
|
1631
|
+
this._desc.baseMipLevel = level;
|
|
1632
|
+
this._desc.mipLevelCount = 1;
|
|
1633
|
+
return this;
|
|
1634
|
+
}
|
|
1635
|
+
withMipRange(start, end) {
|
|
1636
|
+
this._desc.baseMipLevel = start;
|
|
1637
|
+
this._desc.mipLevelCount = end - start;
|
|
1638
|
+
return this;
|
|
1639
|
+
}
|
|
1640
|
+
withSingleLayer(layer) {
|
|
1641
|
+
this._desc.baseArrayLayer = layer;
|
|
1642
|
+
this._desc.arrayLayerCount = 1;
|
|
1643
|
+
return this;
|
|
1644
|
+
}
|
|
1645
|
+
withLayerRange(start, end) {
|
|
1646
|
+
this._desc.baseArrayLayer = start;
|
|
1647
|
+
this._desc.arrayLayerCount = end;
|
|
1648
|
+
return this;
|
|
1649
|
+
}
|
|
1650
|
+
build() {
|
|
1651
|
+
return new TextureView(this._texture._inner.createView(this._desc));
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
function isBc(format) {
|
|
1655
|
+
switch (format) {
|
|
1656
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc1RgbaUnorm:
|
|
1657
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc1RgbaUnormSrgb:
|
|
1658
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc2RgbaUnorm:
|
|
1659
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc2RgbaUnormSrgb:
|
|
1660
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc3RgbaUnorm:
|
|
1661
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc3RgbaUnormSrgb:
|
|
1662
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc4RUnorm:
|
|
1663
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc4RSnorm:
|
|
1664
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc5RgUnorm:
|
|
1665
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc5RgSnorm:
|
|
1666
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc6hRgbUfloat:
|
|
1667
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc6hRgbFloat:
|
|
1668
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc7RgbaUnorm:
|
|
1669
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc7RgbaUnormSrgb:
|
|
1670
|
+
return true;
|
|
1671
|
+
default: return false;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
function isEtc(format) {
|
|
1675
|
+
switch (format) {
|
|
1676
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8Unorm:
|
|
1677
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8UnormSrgb:
|
|
1678
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8A1Unorm:
|
|
1679
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8A1UnormSrgb:
|
|
1680
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgba8Unorm:
|
|
1681
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgba8UnormSrgb:
|
|
1682
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacR11Unorm:
|
|
1683
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacR11Snorm:
|
|
1684
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacRg11Unorm:
|
|
1685
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacRg11Snorm:
|
|
1686
|
+
return true;
|
|
1687
|
+
default:
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
function getBlockWidth(format) {
|
|
1692
|
+
if (isBc(format) || isEtc(format))
|
|
1693
|
+
return 4;
|
|
1694
|
+
switch (format) {
|
|
1695
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc4x4Unorm:
|
|
1696
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc4x4UnormSrgb:
|
|
1697
|
+
return 4;
|
|
1698
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x4Unorm:
|
|
1699
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x4UnormSrgb:
|
|
1700
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x5Unorm:
|
|
1701
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x5UnormSrgb:
|
|
1702
|
+
return 5;
|
|
1703
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x5Unorm:
|
|
1704
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x5UnormSrgb:
|
|
1705
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x6Unorm:
|
|
1706
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x6UnormSrgb:
|
|
1707
|
+
return 6;
|
|
1708
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x5Unorm:
|
|
1709
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x5UnormSrgb:
|
|
1710
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x6Unorm:
|
|
1711
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x6UnormSrgb:
|
|
1712
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x8Unorm:
|
|
1713
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x8UnormSrgb:
|
|
1714
|
+
return 8;
|
|
1715
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x5Unorm:
|
|
1716
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x5UnormSrgb:
|
|
1717
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x6Unorm:
|
|
1718
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x6UnormSrgb:
|
|
1719
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x8Unorm:
|
|
1720
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x8UnormSrgb:
|
|
1721
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x10Unorm:
|
|
1722
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x10UnormSrgb:
|
|
1723
|
+
return 10;
|
|
1724
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x10Unorm:
|
|
1725
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x10UnormSrgb:
|
|
1726
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x12Unorm:
|
|
1727
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x12UnormSrgb:
|
|
1728
|
+
return 12;
|
|
1729
|
+
default:
|
|
1730
|
+
return 1;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Returns the number of bytes in a compressed or uncompressed block for the
|
|
1735
|
+
* given texture format. Matches the mapping from the Rust implementation and
|
|
1736
|
+
* throws for unsupported formats.
|
|
1737
|
+
*/
|
|
1738
|
+
function bytesPerBlock(format) {
|
|
1739
|
+
switch (format) {
|
|
1740
|
+
// 1-byte formats
|
|
1741
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R8Unorm:
|
|
1742
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R8Snorm:
|
|
1743
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R8Uint:
|
|
1744
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R8Sint:
|
|
1745
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Stencil8:
|
|
1746
|
+
return 1;
|
|
1747
|
+
// 2-byte formats
|
|
1748
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R16Uint:
|
|
1749
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R16Sint:
|
|
1750
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R16Unorm:
|
|
1751
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R16Snorm:
|
|
1752
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R16Float:
|
|
1753
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG8Unorm:
|
|
1754
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG8Snorm:
|
|
1755
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG8Uint:
|
|
1756
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG8Sint:
|
|
1757
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Depth16Unorm:
|
|
1758
|
+
return 2;
|
|
1759
|
+
// 4-byte formats
|
|
1760
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R32Uint:
|
|
1761
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R32Sint:
|
|
1762
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.R32Float:
|
|
1763
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG16Uint:
|
|
1764
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG16Sint:
|
|
1765
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG16Unorm:
|
|
1766
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG16Snorm:
|
|
1767
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG16Float:
|
|
1768
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8Unorm:
|
|
1769
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8UnormSrgb:
|
|
1770
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8Snorm:
|
|
1771
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8Uint:
|
|
1772
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8Sint:
|
|
1773
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bgra8Unorm:
|
|
1774
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bgra8UnormSrgb:
|
|
1775
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgb9e5Ufloat:
|
|
1776
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgb10a2Uint:
|
|
1777
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgb10a2Unorm:
|
|
1778
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Depth24Plus:
|
|
1779
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Depth24PlusStencil8:
|
|
1780
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Depth32Float:
|
|
1781
|
+
return 4;
|
|
1782
|
+
// 8-byte formats
|
|
1783
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rg11b10Ufloat:
|
|
1784
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG32Uint:
|
|
1785
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG32Sint:
|
|
1786
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.RG32Float:
|
|
1787
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba16Uint:
|
|
1788
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba16Sint:
|
|
1789
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba16Unorm:
|
|
1790
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba16Snorm:
|
|
1791
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba16Float:
|
|
1792
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Depth32FloatStencil8:
|
|
1793
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc1RgbaUnorm:
|
|
1794
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc1RgbaUnormSrgb:
|
|
1795
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc4RUnorm:
|
|
1796
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc4RSnorm:
|
|
1797
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8Unorm:
|
|
1798
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8UnormSrgb:
|
|
1799
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8A1Unorm:
|
|
1800
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgb8A1UnormSrgb:
|
|
1801
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacR11Unorm:
|
|
1802
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacR11Snorm:
|
|
1803
|
+
return 8;
|
|
1804
|
+
// 16-byte formats
|
|
1805
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba32Uint:
|
|
1806
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba32Sint:
|
|
1807
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba32Float:
|
|
1808
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc2RgbaUnorm:
|
|
1809
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc2RgbaUnormSrgb:
|
|
1810
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc3RgbaUnorm:
|
|
1811
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc3RgbaUnormSrgb:
|
|
1812
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc5RgUnorm:
|
|
1813
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc5RgSnorm:
|
|
1814
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc6hRgbUfloat:
|
|
1815
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc6hRgbFloat:
|
|
1816
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc7RgbaUnorm:
|
|
1817
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc7RgbaUnormSrgb:
|
|
1818
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgba8Unorm:
|
|
1819
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Etc2Rgba8UnormSrgb:
|
|
1820
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacRg11Unorm:
|
|
1821
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.EacRg11Snorm:
|
|
1822
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc4x4Unorm:
|
|
1823
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc4x4UnormSrgb:
|
|
1824
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x4Unorm:
|
|
1825
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x4UnormSrgb:
|
|
1826
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x5Unorm:
|
|
1827
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc5x5UnormSrgb:
|
|
1828
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x5Unorm:
|
|
1829
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x5UnormSrgb:
|
|
1830
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x6Unorm:
|
|
1831
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc6x6UnormSrgb:
|
|
1832
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x5Unorm:
|
|
1833
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x5UnormSrgb:
|
|
1834
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x6Unorm:
|
|
1835
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x6UnormSrgb:
|
|
1836
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x8Unorm:
|
|
1837
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc8x8UnormSrgb:
|
|
1838
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x5Unorm:
|
|
1839
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x5UnormSrgb:
|
|
1840
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x6Unorm:
|
|
1841
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x6UnormSrgb:
|
|
1842
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x8Unorm:
|
|
1843
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x8UnormSrgb:
|
|
1844
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x10Unorm:
|
|
1845
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc10x10UnormSrgb:
|
|
1846
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x10Unorm:
|
|
1847
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x10UnormSrgb:
|
|
1848
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x12Unorm:
|
|
1849
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Astc12x12UnormSrgb:
|
|
1850
|
+
case _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Bc2RgbaUnorm:
|
|
1851
|
+
// NOTE: Bc2RgbaUnorm is already listed above; duplicate entries are
|
|
1852
|
+
// harmless but kept out of caution when mapping from Rust.
|
|
1853
|
+
return 16;
|
|
1854
|
+
default:
|
|
1855
|
+
throw new Error(`Unsupported texture format: ${format}`);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
/***/ }),
|
|
1861
|
+
|
|
1862
|
+
/***/ "./src/TinyHelix.ts":
|
|
1863
|
+
/*!**************************!*\
|
|
1864
|
+
!*** ./src/TinyHelix.ts ***!
|
|
1865
|
+
\**************************/
|
|
1866
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1867
|
+
|
|
1868
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1869
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1870
|
+
/* harmony export */ TinyHelix: () => (/* binding */ TinyHelix)
|
|
1871
|
+
/* harmony export */ });
|
|
1872
|
+
/* harmony import */ var _WebGPUContext__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./WebGPUContext */ "./src/WebGPUContext.ts");
|
|
1873
|
+
/* harmony import */ var _CommandEncoder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CommandEncoder */ "./src/CommandEncoder.ts");
|
|
1874
|
+
/* harmony import */ var _Texture__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Texture */ "./src/Texture.ts");
|
|
1875
|
+
/* harmony import */ var _RenderTarget__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./RenderTarget */ "./src/RenderTarget.ts");
|
|
1876
|
+
/* harmony import */ var _Shader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Shader */ "./src/Shader.ts");
|
|
1877
|
+
/* harmony import */ var _RenderPipeline__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./RenderPipeline */ "./src/RenderPipeline.ts");
|
|
1878
|
+
/* harmony import */ var _Mesh__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Mesh */ "./src/Mesh.ts");
|
|
1879
|
+
/* harmony import */ var _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./buffers/UniformBuffer */ "./src/buffers/UniformBuffer.ts");
|
|
1880
|
+
/* harmony import */ var _BindGroup__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./BindGroup */ "./src/BindGroup.ts");
|
|
1881
|
+
/* harmony import */ var _Sampler__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Sampler */ "./src/Sampler.ts");
|
|
1882
|
+
/* harmony import */ var _ComputePipeline__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./ComputePipeline */ "./src/ComputePipeline.ts");
|
|
1883
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
1884
|
+
/* harmony import */ var _buffers_Buffer__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./buffers/Buffer */ "./src/buffers/Buffer.ts");
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
|
|
1893
|
+
|
|
1894
|
+
|
|
1895
|
+
|
|
1896
|
+
|
|
1897
|
+
|
|
1898
|
+
/**
|
|
1899
|
+
* Main entry point for the tiny-helix API. Manages the WebGPU context,
|
|
1900
|
+
* backbuffer and provides helpers to create render targets and command encoders.
|
|
1901
|
+
*/
|
|
1902
|
+
class TinyHelix {
|
|
1903
|
+
/**
|
|
1904
|
+
* Create a new TinyHelix instance. Call `initialize()` before rendering.
|
|
1905
|
+
*/
|
|
1906
|
+
constructor(canvas) {
|
|
1907
|
+
this._options = {};
|
|
1908
|
+
this._shaderIncludes = new Map();
|
|
1909
|
+
this._globalBindBufferLayouts = [];
|
|
1910
|
+
this._globalBindBuffers = [];
|
|
1911
|
+
this._context = new _WebGPUContext__WEBPACK_IMPORTED_MODULE_0__.WebGPUContext();
|
|
1912
|
+
this._canvas = canvas;
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1915
|
+
* Initializes the underlying WebGPU context and prepares resources.
|
|
1916
|
+
* @param options - Configuration options forwarded to the WebGPU context
|
|
1917
|
+
* @example await tiny.initialize({ canvas: myCanvas });
|
|
1918
|
+
*/
|
|
1919
|
+
async initialize(options = {}) {
|
|
1920
|
+
options.canvas = this._canvas;
|
|
1921
|
+
this._options = options;
|
|
1922
|
+
await this._context.initialize(options);
|
|
1923
|
+
this._createDepthStencil();
|
|
1924
|
+
}
|
|
1925
|
+
resize(width, height) {
|
|
1926
|
+
this._canvas.width = width;
|
|
1927
|
+
this._canvas.height = height;
|
|
1928
|
+
this._createDepthStencil();
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Add a named include for all shader code. The include will be expanded
|
|
1932
|
+
* in any shader code created through {@link TinyHelix.createShader}.
|
|
1933
|
+
* The include name must be unique within the shader code. This allows
|
|
1934
|
+
* using `#include<name>` in the shader code to include other files.
|
|
1935
|
+
* While this is not standard WGSL, it's too useful not to support.
|
|
1936
|
+
'
|
|
1937
|
+
* @param name - The name as used in the `#include<name>` directive.
|
|
1938
|
+
* @param source - The code the include should expand to.
|
|
1939
|
+
*/
|
|
1940
|
+
addShaderInclude(name, source) {
|
|
1941
|
+
this._shaderIncludes.set(name, source);
|
|
1942
|
+
return this;
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Return the chosen depth/stencil format if configured.
|
|
1946
|
+
*/
|
|
1947
|
+
get depthStencilFormat() {
|
|
1948
|
+
return this._options.depthStencilFormat;
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* The current frame's backbuffer texture. Valid after `startFrame()` has been
|
|
1952
|
+
* called.
|
|
1953
|
+
* @throws Error if accessed before startFrame()
|
|
1954
|
+
*/
|
|
1955
|
+
get backbuffer() {
|
|
1956
|
+
if (!this._backbuffer) {
|
|
1957
|
+
throw new Error('Backbuffer not initialized. Did you forget to call startFrame()?');
|
|
1958
|
+
}
|
|
1959
|
+
return this._backbuffer;
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* The RenderTarget wrapper for the current backbuffer. Valid after `startFrame()`.
|
|
1963
|
+
* @throws Error if accessed before startFrame()
|
|
1964
|
+
*/
|
|
1965
|
+
get backbufferTarget() {
|
|
1966
|
+
if (!this._backbufferTarget) {
|
|
1967
|
+
throw new Error('Backbuffer not initialized. Did you forget to call startFrame()?');
|
|
1968
|
+
}
|
|
1969
|
+
return this._backbufferTarget;
|
|
1970
|
+
}
|
|
1971
|
+
get colorSpace() {
|
|
1972
|
+
return this._context.colorSpace;
|
|
1973
|
+
}
|
|
1974
|
+
get backbufferFormat() {
|
|
1975
|
+
return this._context.format;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* The width of the current backbuffer. Valid after `startFrame()`.
|
|
1979
|
+
*/
|
|
1980
|
+
get backbufferWidth() {
|
|
1981
|
+
return this._canvas.width;
|
|
1982
|
+
}
|
|
1983
|
+
/**
|
|
1984
|
+
* The height of the current backbuffer. Valid after `startFrame()`.
|
|
1985
|
+
*/
|
|
1986
|
+
get backbufferHeight() {
|
|
1987
|
+
return this._canvas.height;
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Needs to be called before rendering each frame. Updates internal backbuffer
|
|
1991
|
+
* references to the current swapchain texture.
|
|
1992
|
+
* @example tiny.startFrame();
|
|
1993
|
+
*/
|
|
1994
|
+
startFrame() {
|
|
1995
|
+
this._backbuffer = _Texture__WEBPACK_IMPORTED_MODULE_2__.Texture.from_webgpu(this._context.getCurrentTexture(), this._context.format);
|
|
1996
|
+
this._backbufferTarget = this.createRenderTarget(this._backbuffer)
|
|
1997
|
+
.build();
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Create a RenderTargetBuilder for a given texture.
|
|
2001
|
+
*/
|
|
2002
|
+
createRenderTarget(target) {
|
|
2003
|
+
return new _RenderTarget__WEBPACK_IMPORTED_MODULE_3__.RenderTargetBuilder(target);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Create a ShaderBuilder for creating a Shader.
|
|
2007
|
+
*/
|
|
2008
|
+
createShader() {
|
|
2009
|
+
let builder = new _Shader__WEBPACK_IMPORTED_MODULE_4__.ShaderBuilder(this._context);
|
|
2010
|
+
this._shaderIncludes.forEach((v, k) => builder = builder.withInclude(k, v));
|
|
2011
|
+
this._globalBindBufferLayouts.forEach((layout, i) => builder.withBindGroup(i, layout));
|
|
2012
|
+
return builder;
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Create a BindGroupLayoutBuilder for creating a BindGroupLayout.
|
|
2016
|
+
*/
|
|
2017
|
+
createBindGroupLayout() {
|
|
2018
|
+
return new _BindGroup__WEBPACK_IMPORTED_MODULE_8__["default"](this._context);
|
|
2019
|
+
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Create a BindGroupBuilder for creating a BindGroup.
|
|
2022
|
+
*/
|
|
2023
|
+
createBindGroup(layout) {
|
|
2024
|
+
return new _BindGroup__WEBPACK_IMPORTED_MODULE_8__.BindGroupBuilder(this._context, layout);
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Create a MeshBuilder for creating a Mesh.
|
|
2028
|
+
*/
|
|
2029
|
+
createMesh() {
|
|
2030
|
+
return new _Mesh__WEBPACK_IMPORTED_MODULE_6__.MeshBuilder(this._context);
|
|
2031
|
+
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Create a RenderPipelineBuilder for creating a RenderPipeline.
|
|
2034
|
+
*/
|
|
2035
|
+
createRenderPipeline() {
|
|
2036
|
+
return new _RenderPipeline__WEBPACK_IMPORTED_MODULE_5__.RenderPipelineBuilder(this._context, this._options.depthStencilFormat);
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Create a ComputePipelineBuilder for creating a ComputePipeline.
|
|
2040
|
+
*/
|
|
2041
|
+
createComputePipeline() {
|
|
2042
|
+
return new _ComputePipeline__WEBPACK_IMPORTED_MODULE_10__.ComputePipelineBuilder(this._context);
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* Create a SamplerBuilder for creating a Sampler.
|
|
2046
|
+
*/
|
|
2047
|
+
createSampler() {
|
|
2048
|
+
return new _Sampler__WEBPACK_IMPORTED_MODULE_9__.SamplerBuilder(this._context);
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Create a TextureBuilder for creating a Texture.
|
|
2052
|
+
*/
|
|
2053
|
+
createTexture() {
|
|
2054
|
+
return new _Texture__WEBPACK_IMPORTED_MODULE_2__.TextureBuilder(this._context);
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Creates a command encoder for recording GPU commands for the current frame.
|
|
2058
|
+
* @param label - Optional debug label to assign to the encoder
|
|
2059
|
+
*/
|
|
2060
|
+
createCommandEncoder(label) {
|
|
2061
|
+
return new _CommandEncoder__WEBPACK_IMPORTED_MODULE_1__.CommandEncoder(this.backbufferTarget, this._globalBindBuffers, this._context, this._depthStencilTarget, label);
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Create a UniformBufferLayoutBuilder for creating a UniformBufferLayout.
|
|
2065
|
+
*/
|
|
2066
|
+
createUniformBufferLayout() {
|
|
2067
|
+
return new _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_7__.UniformBufferLayoutBuilder();
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* Create a UniformBuffer for the given layout.
|
|
2071
|
+
*/
|
|
2072
|
+
createUniformBuffer(layout) {
|
|
2073
|
+
return new _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_7__.UniformBuffer(layout, this._context);
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Create a BufferBuilder to construct raw buffers.
|
|
2077
|
+
*/
|
|
2078
|
+
createBuffer() {
|
|
2079
|
+
return new _buffers_Buffer__WEBPACK_IMPORTED_MODULE_12__.BufferBuilder(this._context);
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Allows setting a global bind group for all render passes. This is useful
|
|
2083
|
+
* for setting bind groups that are used by all passes. These buffers will
|
|
2084
|
+
* automatically be set for all render and compute passes.
|
|
2085
|
+
* @param index - The index of the bind group in the render pipeline layout.
|
|
2086
|
+
* @param buffer - The bind group to set.
|
|
2087
|
+
*/
|
|
2088
|
+
setGlobalBindGroup(index, layout, buffer) {
|
|
2089
|
+
this._globalBindBufferLayouts[index] = layout;
|
|
2090
|
+
this._globalBindBuffers[index] = buffer;
|
|
2091
|
+
return this;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Destroy the TinyHelix instance and release all GPU resources.
|
|
2095
|
+
*/
|
|
2096
|
+
destroy() {
|
|
2097
|
+
this._context.destroy();
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* Returns the current depth/stencil texture if configured.
|
|
2101
|
+
*/
|
|
2102
|
+
depthStencilTexture() {
|
|
2103
|
+
return this._depthStencil;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Returns the current depth/stencil RenderTarget if configured.
|
|
2107
|
+
*/
|
|
2108
|
+
depthStencilTarget() {
|
|
2109
|
+
return this._depthStencilTarget;
|
|
2110
|
+
}
|
|
2111
|
+
_createDepthStencil() {
|
|
2112
|
+
this._depthStencil = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_11__.mapUndefined)(this._options.depthStencilFormat, (f) => this.createTexture()
|
|
2113
|
+
.withFormat(f)
|
|
2114
|
+
.withSize(this._canvas.width, this._canvas.height)
|
|
2115
|
+
.withUsage(GPUTextureUsage.RENDER_ATTACHMENT)
|
|
2116
|
+
.build());
|
|
2117
|
+
this._depthStencilTarget = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_11__.mapUndefined)(this._depthStencil, (t) => this.createRenderTarget(t)
|
|
2118
|
+
.build());
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
|
|
2123
|
+
/***/ }),
|
|
2124
|
+
|
|
2125
|
+
/***/ "./src/WebGPUContext.ts":
|
|
2126
|
+
/*!******************************!*\
|
|
2127
|
+
!*** ./src/WebGPUContext.ts ***!
|
|
2128
|
+
\******************************/
|
|
2129
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2130
|
+
|
|
2131
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2132
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2133
|
+
/* harmony export */ WebGPUContext: () => (/* binding */ WebGPUContext)
|
|
2134
|
+
/* harmony export */ });
|
|
2135
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
2136
|
+
|
|
2137
|
+
/**
|
|
2138
|
+
* Manages WebGPU adapter, device, and context initialization
|
|
2139
|
+
*/
|
|
2140
|
+
class WebGPUContext {
|
|
2141
|
+
constructor() {
|
|
2142
|
+
this._adapter = null;
|
|
2143
|
+
this._device = null;
|
|
2144
|
+
this._context = null;
|
|
2145
|
+
this._format = _enums__WEBPACK_IMPORTED_MODULE_0__.TextureFormat.Rgba8UnormSrgb;
|
|
2146
|
+
this._canvas = null;
|
|
2147
|
+
this._colorSpace = _enums__WEBPACK_IMPORTED_MODULE_0__.ColorSpace.sRGB;
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Gets the WebGPU adapter. Throws if not initialized.
|
|
2151
|
+
*/
|
|
2152
|
+
get adapter() {
|
|
2153
|
+
return this._adapter;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Gets the WebGPU device. Throws if not initialized.
|
|
2157
|
+
*/
|
|
2158
|
+
get device() {
|
|
2159
|
+
return this._device;
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Gets the GPU canvas context. Throws if no canvas was configured.
|
|
2163
|
+
*/
|
|
2164
|
+
get context() {
|
|
2165
|
+
return this._context;
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Gets the preferred texture format used by the configured canvas/context.
|
|
2169
|
+
*/
|
|
2170
|
+
get format() {
|
|
2171
|
+
return this._format;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Gets the color space used by the configured canvas/context.
|
|
2175
|
+
*/
|
|
2176
|
+
get colorSpace() {
|
|
2177
|
+
return this._colorSpace;
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Gets the configured canvas element. Throws if none was provided during initialization.
|
|
2181
|
+
*/
|
|
2182
|
+
get canvas() {
|
|
2183
|
+
return this._canvas;
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Checks if WebGPU is supported in the current environment.
|
|
2187
|
+
*/
|
|
2188
|
+
static isSupported() {
|
|
2189
|
+
return typeof navigator !== 'undefined' && 'gpu' in navigator;
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Initializes the WebGPU context and device.
|
|
2193
|
+
* @param options - Configuration options such as canvas and adapter preferences
|
|
2194
|
+
* @throws Error if WebGPU is not supported or initialization fails
|
|
2195
|
+
*/
|
|
2196
|
+
async initialize(options = {}) {
|
|
2197
|
+
if (!WebGPUContext.isSupported()) {
|
|
2198
|
+
throw new Error('WebGPU is not supported in this browser');
|
|
2199
|
+
}
|
|
2200
|
+
// Request adapter
|
|
2201
|
+
this._adapter = await navigator.gpu.requestAdapter({
|
|
2202
|
+
powerPreference: options.powerPreference ?? 'high-performance',
|
|
2203
|
+
});
|
|
2204
|
+
if (!this._adapter) {
|
|
2205
|
+
throw new Error('Failed to get WebGPU adapter');
|
|
2206
|
+
}
|
|
2207
|
+
// Request device
|
|
2208
|
+
this._device = await this._adapter.requestDevice({
|
|
2209
|
+
requiredFeatures: options.requiredFeatures,
|
|
2210
|
+
requiredLimits: options.requiredLimits,
|
|
2211
|
+
});
|
|
2212
|
+
if (!this._device) {
|
|
2213
|
+
throw new Error('Failed to get WebGPU device');
|
|
2214
|
+
}
|
|
2215
|
+
// Setup error handling
|
|
2216
|
+
this._device.lost.then((info) => {
|
|
2217
|
+
console.error('WebGPU device lost:', info.message);
|
|
2218
|
+
if (info.reason !== 'destroyed') {
|
|
2219
|
+
// Attempt to reinitialize
|
|
2220
|
+
this.initialize(options).catch((error) => {
|
|
2221
|
+
console.error('Failed to reinitialize WebGPU context:', error);
|
|
2222
|
+
});
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
// Configure canvas context if provided
|
|
2226
|
+
if (options.canvas) {
|
|
2227
|
+
this._canvas = options.canvas;
|
|
2228
|
+
this._context = this._canvas.getContext("webgpu");
|
|
2229
|
+
if (!this._context) {
|
|
2230
|
+
throw new Error("Failed to get WebGPU context from canvas");
|
|
2231
|
+
}
|
|
2232
|
+
const canUseP3 = window.matchMedia("(color-gamut: p3)").matches;
|
|
2233
|
+
this._colorSpace = options.colorSpace ?? _enums__WEBPACK_IMPORTED_MODULE_0__.ColorSpace.sRGB;
|
|
2234
|
+
if (this._colorSpace === _enums__WEBPACK_IMPORTED_MODULE_0__.ColorSpace.DisplayP3 && !canUseP3) {
|
|
2235
|
+
this._colorSpace = _enums__WEBPACK_IMPORTED_MODULE_0__.ColorSpace.sRGB;
|
|
2236
|
+
console.warn("DisplayP3 not supported, falling back to sRGB");
|
|
2237
|
+
}
|
|
2238
|
+
this._format = navigator.gpu.getPreferredCanvasFormat();
|
|
2239
|
+
this._context.configure({
|
|
2240
|
+
device: this._device,
|
|
2241
|
+
format: this._format,
|
|
2242
|
+
colorSpace: this._colorSpace,
|
|
2243
|
+
alphaMode: "premultiplied",
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
else {
|
|
2247
|
+
console.warn("No canvas provided!");
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Internal helper to fetch the current swapchain texture.
|
|
2252
|
+
* @internal
|
|
2253
|
+
*/
|
|
2254
|
+
getCurrentTexture() {
|
|
2255
|
+
return this._context.getCurrentTexture();
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Destroys the WebGPU context and releases resources
|
|
2259
|
+
*/
|
|
2260
|
+
destroy() {
|
|
2261
|
+
if (this._device) {
|
|
2262
|
+
this._device.destroy();
|
|
2263
|
+
this._device = null;
|
|
2264
|
+
}
|
|
2265
|
+
this._adapter = null;
|
|
2266
|
+
this._context = null;
|
|
2267
|
+
this._canvas = null;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
|
|
2272
|
+
/***/ }),
|
|
2273
|
+
|
|
2274
|
+
/***/ "./src/buffers/Buffer.ts":
|
|
2275
|
+
/*!*******************************!*\
|
|
2276
|
+
!*** ./src/buffers/Buffer.ts ***!
|
|
2277
|
+
\*******************************/
|
|
2278
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2279
|
+
|
|
2280
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2281
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2282
|
+
/* harmony export */ Buffer: () => (/* binding */ Buffer),
|
|
2283
|
+
/* harmony export */ BufferBuilder: () => (/* binding */ BufferBuilder),
|
|
2284
|
+
/* harmony export */ BufferUsage: () => (/* binding */ BufferUsage),
|
|
2285
|
+
/* harmony export */ TextureUsage: () => (/* binding */ TextureUsage)
|
|
2286
|
+
/* harmony export */ });
|
|
2287
|
+
/* harmony import */ var _utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/mapUndefined */ "./src/utils/mapUndefined.ts");
|
|
2288
|
+
/* harmony import */ var _utils_padArrayBuffer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/padArrayBuffer */ "./src/utils/padArrayBuffer.ts");
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
/**
|
|
2292
|
+
* Buffer usage flags re-exported from the WebGPU API for convenience.
|
|
2293
|
+
* Use these when constructing buffers with `BufferBuilder.withUsage()`.
|
|
2294
|
+
*/
|
|
2295
|
+
var BufferUsage;
|
|
2296
|
+
(function (BufferUsage) {
|
|
2297
|
+
BufferUsage[BufferUsage["MapRead"] = GPUBufferUsage.MAP_READ] = "MapRead";
|
|
2298
|
+
BufferUsage[BufferUsage["MapWrite"] = GPUBufferUsage.MAP_WRITE] = "MapWrite";
|
|
2299
|
+
BufferUsage[BufferUsage["CopySrc"] = GPUBufferUsage.COPY_SRC] = "CopySrc";
|
|
2300
|
+
BufferUsage[BufferUsage["CopyDst"] = GPUBufferUsage.COPY_DST] = "CopyDst";
|
|
2301
|
+
BufferUsage[BufferUsage["Index"] = GPUBufferUsage.INDEX] = "Index";
|
|
2302
|
+
BufferUsage[BufferUsage["Vertex"] = GPUBufferUsage.VERTEX] = "Vertex";
|
|
2303
|
+
BufferUsage[BufferUsage["Uniform"] = GPUBufferUsage.UNIFORM] = "Uniform";
|
|
2304
|
+
BufferUsage[BufferUsage["Storage"] = GPUBufferUsage.STORAGE] = "Storage";
|
|
2305
|
+
BufferUsage[BufferUsage["Indirect"] = GPUBufferUsage.INDIRECT] = "Indirect";
|
|
2306
|
+
BufferUsage[BufferUsage["QueryResolve"] = GPUBufferUsage.QUERY_RESOLVE] = "QueryResolve";
|
|
2307
|
+
})(BufferUsage || (BufferUsage = {}));
|
|
2308
|
+
var TextureUsage;
|
|
2309
|
+
(function (TextureUsage) {
|
|
2310
|
+
TextureUsage[TextureUsage["CopySrc"] = GPUTextureUsage.COPY_SRC] = "CopySrc";
|
|
2311
|
+
TextureUsage[TextureUsage["CopyDst"] = GPUTextureUsage.COPY_DST] = "CopyDst";
|
|
2312
|
+
TextureUsage[TextureUsage["TextureBinding"] = GPUTextureUsage.TEXTURE_BINDING] = "TextureBinding";
|
|
2313
|
+
TextureUsage[TextureUsage["StorageBinding"] = GPUTextureUsage.STORAGE_BINDING] = "StorageBinding";
|
|
2314
|
+
TextureUsage[TextureUsage["RenderAttachment"] = GPUTextureUsage.RENDER_ATTACHMENT] = "RenderAttachment";
|
|
2315
|
+
})(TextureUsage || (TextureUsage = {}));
|
|
2316
|
+
/**
|
|
2317
|
+
* Builder for creating GPU-backed buffers.
|
|
2318
|
+
*
|
|
2319
|
+
* Example:
|
|
2320
|
+
* const buf = new BufferBuilder(ctx)
|
|
2321
|
+
* .withUsage(BufferUsage.Vertex | BufferUsage.CopyDst)
|
|
2322
|
+
* .withData(new Float32Array([...]).buffer)
|
|
2323
|
+
* .build();
|
|
2324
|
+
*/
|
|
2325
|
+
class BufferBuilder {
|
|
2326
|
+
constructor(ctx) {
|
|
2327
|
+
this._size = 0;
|
|
2328
|
+
this._keepData = false;
|
|
2329
|
+
this._usage = 0;
|
|
2330
|
+
this._ctx = ctx;
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Add usage flags for the GPU buffer.
|
|
2334
|
+
*/
|
|
2335
|
+
withUsage(usage) {
|
|
2336
|
+
this._usage |= usage;
|
|
2337
|
+
return this;
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* Provide initial data for the buffer. If `keepOnCPU` is true the original
|
|
2341
|
+
* ArrayBuffer is stored in the resulting `Buffer.data` field for readback or
|
|
2342
|
+
* reuse.
|
|
2343
|
+
*/
|
|
2344
|
+
withData(data, keepOnCPU = false) {
|
|
2345
|
+
this._data = data;
|
|
2346
|
+
// round to the nearest multiple of 4 bytes, as required by GPUBuffer.writeBuffer()
|
|
2347
|
+
this._size = data.byteLength;
|
|
2348
|
+
this._keepData = keepOnCPU;
|
|
2349
|
+
this._usage |= BufferUsage.CopyDst;
|
|
2350
|
+
return this;
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Specify a size for the buffer, used when not providing data.
|
|
2354
|
+
*/
|
|
2355
|
+
withSize(size) {
|
|
2356
|
+
this._size = size;
|
|
2357
|
+
return this;
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Create the GPU buffer and upload any provided data.
|
|
2361
|
+
*/
|
|
2362
|
+
build() {
|
|
2363
|
+
const data = (0,_utils_mapUndefined__WEBPACK_IMPORTED_MODULE_0__.mapUndefined)(this._data, data => (0,_utils_padArrayBuffer__WEBPACK_IMPORTED_MODULE_1__.padArrayBuffer)(data, 4));
|
|
2364
|
+
const buffer = this._ctx.device.createBuffer({
|
|
2365
|
+
size: data ? data.byteLength : this._size, // in case we don't have data, we need to specify the size explicitly'
|
|
2366
|
+
usage: this._usage
|
|
2367
|
+
});
|
|
2368
|
+
if (data) {
|
|
2369
|
+
this._ctx.device.queue.writeBuffer(buffer, 0, data);
|
|
2370
|
+
}
|
|
2371
|
+
return new Buffer(buffer, this._keepData ? this._data : undefined);
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Lightweight wrapper around a GPUBuffer. Exposes the original CPU-side data
|
|
2376
|
+
* (when kept) and the underlying GPU buffer for low-level interop.
|
|
2377
|
+
*/
|
|
2378
|
+
class Buffer {
|
|
2379
|
+
/**
|
|
2380
|
+
* Create a Buffer from an existing GPUBuffer.
|
|
2381
|
+
* @param inner The underlying GPUBuffer.
|
|
2382
|
+
* @param data Optional CPU-side copy of the buffer contents.
|
|
2383
|
+
*/
|
|
2384
|
+
constructor(inner, data) {
|
|
2385
|
+
this._inner = inner;
|
|
2386
|
+
this.data = data;
|
|
2387
|
+
}
|
|
2388
|
+
/** Size of the GPU buffer in bytes. */
|
|
2389
|
+
get size() { return this._inner.size; }
|
|
2390
|
+
_uploadData(ctx) {
|
|
2391
|
+
if (!this.data) {
|
|
2392
|
+
console.warn("Buffer has no data to upload.");
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
ctx.device.queue.writeBuffer(this._inner, 0, this.data);
|
|
2396
|
+
}
|
|
2397
|
+
_getBufferResource() {
|
|
2398
|
+
return { buffer: this._inner };
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
|
|
2403
|
+
/***/ }),
|
|
2404
|
+
|
|
2405
|
+
/***/ "./src/buffers/BufferDataWriter.ts":
|
|
2406
|
+
/*!*****************************************!*\
|
|
2407
|
+
!*** ./src/buffers/BufferDataWriter.ts ***!
|
|
2408
|
+
\*****************************************/
|
|
2409
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2410
|
+
|
|
2411
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2412
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2413
|
+
/* harmony export */ BufferDataWriter: () => (/* binding */ BufferDataWriter)
|
|
2414
|
+
/* harmony export */ });
|
|
2415
|
+
/* harmony import */ var _utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/float32ToFloat16 */ "./src/utils/float32ToFloat16.ts");
|
|
2416
|
+
|
|
2417
|
+
/**
|
|
2418
|
+
* Utility for incrementally building binary data into an ArrayBuffer.
|
|
2419
|
+
* Provides typed push helpers for common numeric types used in vertex/index buffers.
|
|
2420
|
+
*/
|
|
2421
|
+
class BufferDataWriter {
|
|
2422
|
+
/** Create a new writer with the given total byte size. */
|
|
2423
|
+
constructor(byteSize) {
|
|
2424
|
+
this._offset = 0;
|
|
2425
|
+
this._buffer = new ArrayBuffer(byteSize);
|
|
2426
|
+
this._view = new DataView(this._buffer);
|
|
2427
|
+
}
|
|
2428
|
+
/** Push an unsigned 8-bit integer. */
|
|
2429
|
+
pushUint8(value) {
|
|
2430
|
+
this._view.setUint8(this._offset, value);
|
|
2431
|
+
this._offset += 1;
|
|
2432
|
+
return this;
|
|
2433
|
+
}
|
|
2434
|
+
/** Push two unsigned 8-bit integers. */
|
|
2435
|
+
pushUint8x2(x, y) {
|
|
2436
|
+
this.pushUint8(x);
|
|
2437
|
+
this.pushUint8(y);
|
|
2438
|
+
return this;
|
|
2439
|
+
}
|
|
2440
|
+
/** Push four unsigned 8-bit integers. */
|
|
2441
|
+
pushUint8x4(x, y, z, w) {
|
|
2442
|
+
this.pushUint8(x);
|
|
2443
|
+
this.pushUint8(y);
|
|
2444
|
+
this.pushUint8(z);
|
|
2445
|
+
this.pushUint8(w);
|
|
2446
|
+
return this;
|
|
2447
|
+
}
|
|
2448
|
+
/** Push a signed 8-bit integer. */
|
|
2449
|
+
pushSint8(value) {
|
|
2450
|
+
this._view.setInt8(this._offset, value);
|
|
2451
|
+
this._offset += 1;
|
|
2452
|
+
return this;
|
|
2453
|
+
}
|
|
2454
|
+
/** Push two signed 8-bit integers. */
|
|
2455
|
+
pushSint8x2(x, y) {
|
|
2456
|
+
this.pushSint8(x);
|
|
2457
|
+
this.pushSint8(y);
|
|
2458
|
+
return this;
|
|
2459
|
+
}
|
|
2460
|
+
/** Push four signed 8-bit integers. */
|
|
2461
|
+
pushSint8x4(x, y, z, w) {
|
|
2462
|
+
this.pushSint8(x);
|
|
2463
|
+
this.pushSint8(y);
|
|
2464
|
+
this.pushSint8(z);
|
|
2465
|
+
this.pushSint8(w);
|
|
2466
|
+
return this;
|
|
2467
|
+
}
|
|
2468
|
+
/** Push an unsigned 16-bit integer (little-endian). */
|
|
2469
|
+
pushUint16(value) {
|
|
2470
|
+
this._view.setUint16(this._offset, value, true);
|
|
2471
|
+
this._offset += 2;
|
|
2472
|
+
return this;
|
|
2473
|
+
}
|
|
2474
|
+
/** Push two unsigned 16-bit integers (little-endian). */
|
|
2475
|
+
pushUint16x2(x, y) {
|
|
2476
|
+
this.pushUint16(x);
|
|
2477
|
+
this.pushUint16(y);
|
|
2478
|
+
return this;
|
|
2479
|
+
}
|
|
2480
|
+
/** Push four unsigned 16-bit integers (little-endian). */
|
|
2481
|
+
pushUint16x4(x, y, z, w) {
|
|
2482
|
+
this.pushUint16(x);
|
|
2483
|
+
this.pushUint16(y);
|
|
2484
|
+
this.pushUint16(z);
|
|
2485
|
+
this.pushUint16(w);
|
|
2486
|
+
return this;
|
|
2487
|
+
}
|
|
2488
|
+
/** Push a signed 16-bit integer (little-endian). */
|
|
2489
|
+
pushSint16(value) {
|
|
2490
|
+
this._view.setInt16(this._offset, value, true);
|
|
2491
|
+
this._offset += 2;
|
|
2492
|
+
return this;
|
|
2493
|
+
}
|
|
2494
|
+
/** Push two signed 16-bit integers (little-endian). */
|
|
2495
|
+
pushSint16x2(x, y) {
|
|
2496
|
+
this.pushSint16(x);
|
|
2497
|
+
this.pushSint16(y);
|
|
2498
|
+
return this;
|
|
2499
|
+
}
|
|
2500
|
+
/** Push four signed 16-bit integers (little-endian). */
|
|
2501
|
+
pushSint16x4(x, y, z, w) {
|
|
2502
|
+
this.pushSint16(x);
|
|
2503
|
+
this.pushSint16(y);
|
|
2504
|
+
this.pushSint16(z);
|
|
2505
|
+
this.pushSint16(w);
|
|
2506
|
+
return this;
|
|
2507
|
+
}
|
|
2508
|
+
/** Push a 16-bit float (little-endian). */
|
|
2509
|
+
pushFloat16(value) {
|
|
2510
|
+
const bits = (0,_utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_0__.float32ToFloat16)(value);
|
|
2511
|
+
this._view.setUint16(this._offset, bits, true);
|
|
2512
|
+
this._offset += 2;
|
|
2513
|
+
return this;
|
|
2514
|
+
}
|
|
2515
|
+
/** Push two 16-bit floats (little-endian). */
|
|
2516
|
+
pushFloat16x2(x, y) {
|
|
2517
|
+
this.pushFloat16(x);
|
|
2518
|
+
this.pushFloat16(y);
|
|
2519
|
+
return this;
|
|
2520
|
+
}
|
|
2521
|
+
/** Push four 16-bit floats (little-endian). */
|
|
2522
|
+
pushFloat16x4(x, y, z, w) {
|
|
2523
|
+
this.pushFloat16(x);
|
|
2524
|
+
this.pushFloat16(y);
|
|
2525
|
+
this.pushFloat16(z);
|
|
2526
|
+
this.pushFloat16(w);
|
|
2527
|
+
return this;
|
|
2528
|
+
}
|
|
2529
|
+
/** Push a 32-bit float (little-endian). */
|
|
2530
|
+
pushFloat32(value) {
|
|
2531
|
+
this._view.setFloat32(this._offset, value, true);
|
|
2532
|
+
this._offset += 4;
|
|
2533
|
+
return this;
|
|
2534
|
+
}
|
|
2535
|
+
/** Push two 32-bit floats (little-endian). */
|
|
2536
|
+
pushFloat32x2(arr) {
|
|
2537
|
+
this.pushFloat32(arr[0]);
|
|
2538
|
+
this.pushFloat32(arr[1]);
|
|
2539
|
+
return this;
|
|
2540
|
+
}
|
|
2541
|
+
/** Push four 32-bit floats (little-endian). */
|
|
2542
|
+
pushFloat32x3(arr) {
|
|
2543
|
+
this.pushFloat32(arr[0]);
|
|
2544
|
+
this.pushFloat32(arr[1]);
|
|
2545
|
+
this.pushFloat32(arr[2]);
|
|
2546
|
+
return this;
|
|
2547
|
+
}
|
|
2548
|
+
/** Push an 8-bit float (little-endian). */
|
|
2549
|
+
pushFloat32x4(arr) {
|
|
2550
|
+
this.pushFloat32(arr[0]);
|
|
2551
|
+
this.pushFloat32(arr[1]);
|
|
2552
|
+
this.pushFloat32(arr[2]);
|
|
2553
|
+
this.pushFloat32(arr[3]);
|
|
2554
|
+
return this;
|
|
2555
|
+
}
|
|
2556
|
+
/** Push an unsigned 32-bit integer (little-endian). */
|
|
2557
|
+
pushUint32(value) {
|
|
2558
|
+
this._view.setUint32(this._offset, value, true);
|
|
2559
|
+
this._offset += 4;
|
|
2560
|
+
return this;
|
|
2561
|
+
}
|
|
2562
|
+
/** Push two unsigned 32-bit integers (little-endian). */
|
|
2563
|
+
pushUint32x2(arr) {
|
|
2564
|
+
this.pushUint32(arr[0]);
|
|
2565
|
+
this.pushUint32(arr[1]);
|
|
2566
|
+
return this;
|
|
2567
|
+
}
|
|
2568
|
+
/** Push three unsigned 32-bit integers (little-endian). */
|
|
2569
|
+
pushUint32x3(arr) {
|
|
2570
|
+
this.pushUint32(arr[0]);
|
|
2571
|
+
this.pushUint32(arr[1]);
|
|
2572
|
+
this.pushUint32(arr[2]);
|
|
2573
|
+
return this;
|
|
2574
|
+
}
|
|
2575
|
+
/** Push four unsigned 32-bit integers (little-endian). */
|
|
2576
|
+
pushUint32x4(arr) {
|
|
2577
|
+
this.pushUint32(arr[0]);
|
|
2578
|
+
this.pushUint32(arr[1]);
|
|
2579
|
+
this.pushUint32(arr[2]);
|
|
2580
|
+
this.pushUint32(arr[3]);
|
|
2581
|
+
return this;
|
|
2582
|
+
}
|
|
2583
|
+
/** Push a signed 32-bit integer (little-endian). */
|
|
2584
|
+
pushSint32(value) {
|
|
2585
|
+
this._view.setInt32(this._offset, value, true);
|
|
2586
|
+
this._offset += 4;
|
|
2587
|
+
return this;
|
|
2588
|
+
}
|
|
2589
|
+
/** Push two signed 32-bit integers (little-endian). */
|
|
2590
|
+
pushSint32x2(arr) {
|
|
2591
|
+
this.pushSint32(arr[0]);
|
|
2592
|
+
this.pushSint32(arr[1]);
|
|
2593
|
+
return this;
|
|
2594
|
+
}
|
|
2595
|
+
/** Push three signed 32-bit integers (little-endian). */
|
|
2596
|
+
pushSint32x3(arr) {
|
|
2597
|
+
this.pushSint32(arr[0]);
|
|
2598
|
+
this.pushSint32(arr[1]);
|
|
2599
|
+
this.pushSint32(arr[2]);
|
|
2600
|
+
return this;
|
|
2601
|
+
}
|
|
2602
|
+
/** Push four signed 32-bit integers (little-endian). */
|
|
2603
|
+
pushSint32x4(arr) {
|
|
2604
|
+
this.pushSint32(arr[0]);
|
|
2605
|
+
this.pushSint32(arr[1]);
|
|
2606
|
+
this.pushSint32(arr[2]);
|
|
2607
|
+
this.pushSint32(arr[3]);
|
|
2608
|
+
return this;
|
|
2609
|
+
}
|
|
2610
|
+
/** Returns the underlying ArrayBuffer containing all written data. */
|
|
2611
|
+
get arrayBuffer() {
|
|
2612
|
+
return this._buffer;
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
/***/ }),
|
|
2618
|
+
|
|
2619
|
+
/***/ "./src/buffers/UniformBuffer.ts":
|
|
2620
|
+
/*!**************************************!*\
|
|
2621
|
+
!*** ./src/buffers/UniformBuffer.ts ***!
|
|
2622
|
+
\**************************************/
|
|
2623
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2624
|
+
|
|
2625
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2626
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2627
|
+
/* harmony export */ BaseType: () => (/* binding */ BaseType),
|
|
2628
|
+
/* harmony export */ UniformBuffer: () => (/* binding */ UniformBuffer),
|
|
2629
|
+
/* harmony export */ UniformBufferLayout: () => (/* binding */ UniformBufferLayout),
|
|
2630
|
+
/* harmony export */ UniformBufferLayoutBuilder: () => (/* binding */ UniformBufferLayoutBuilder)
|
|
2631
|
+
/* harmony export */ });
|
|
2632
|
+
/* harmony import */ var _Buffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Buffer */ "./src/buffers/Buffer.ts");
|
|
2633
|
+
/* harmony import */ var _utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/float32ToFloat16 */ "./src/utils/float32ToFloat16.ts");
|
|
2634
|
+
|
|
2635
|
+
|
|
2636
|
+
/**
|
|
2637
|
+
* Primitive base types supported by the uniform buffer helpers.
|
|
2638
|
+
* These correspond to WGSL scalar types used inside UBOs.
|
|
2639
|
+
*/
|
|
2640
|
+
var BaseType;
|
|
2641
|
+
(function (BaseType) {
|
|
2642
|
+
BaseType[BaseType["Float16"] = 0] = "Float16";
|
|
2643
|
+
BaseType[BaseType["Float32"] = 1] = "Float32";
|
|
2644
|
+
BaseType[BaseType["Uint"] = 2] = "Uint";
|
|
2645
|
+
BaseType[BaseType["Sint"] = 3] = "Sint";
|
|
2646
|
+
BaseType[BaseType["Boolean"] = 4] = "Boolean";
|
|
2647
|
+
})(BaseType || (BaseType = {}));
|
|
2648
|
+
function sizeForBaseType(type) {
|
|
2649
|
+
switch (type) {
|
|
2650
|
+
case BaseType.Float16:
|
|
2651
|
+
return 2;
|
|
2652
|
+
case BaseType.Float32:
|
|
2653
|
+
return 4;
|
|
2654
|
+
case BaseType.Boolean:
|
|
2655
|
+
return 1;
|
|
2656
|
+
default:
|
|
2657
|
+
throw new Error("Unknown BaseType.");
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
var ContainerType;
|
|
2661
|
+
(function (ContainerType) {
|
|
2662
|
+
ContainerType[ContainerType["Scalar"] = 0] = "Scalar";
|
|
2663
|
+
ContainerType[ContainerType["Vec"] = 1] = "Vec";
|
|
2664
|
+
ContainerType[ContainerType["Matrix"] = 2] = "Matrix";
|
|
2665
|
+
ContainerType[ContainerType["Array"] = 3] = "Array";
|
|
2666
|
+
})(ContainerType || (ContainerType = {}));
|
|
2667
|
+
class MemberType {
|
|
2668
|
+
constructor(baseType, containerType, numRows, numCols) {
|
|
2669
|
+
this.numRows = 1;
|
|
2670
|
+
this.numCols = 1;
|
|
2671
|
+
if (containerType === ContainerType.Scalar && numRows !== 1 && numCols !== 1) {
|
|
2672
|
+
throw new Error("Scalar member must have numRows = 1.");
|
|
2673
|
+
}
|
|
2674
|
+
this.baseType = baseType;
|
|
2675
|
+
this.containerType = containerType;
|
|
2676
|
+
this.numRows = numRows;
|
|
2677
|
+
this.numCols = numCols;
|
|
2678
|
+
}
|
|
2679
|
+
get size() {
|
|
2680
|
+
// when we're dealing with matrices, storing vec3f internally stores as vec4f
|
|
2681
|
+
const numRows = this.numCols > 1 && this.numRows === 3 ? 4 : this.numRows;
|
|
2682
|
+
return sizeForBaseType(this.baseType) * numRows * this.numCols;
|
|
2683
|
+
}
|
|
2684
|
+
get alignment() {
|
|
2685
|
+
const numElements = this.numRows === 3 ? 4 : this.numRows;
|
|
2686
|
+
// matrices are also just aligned to their underlying vec alignment
|
|
2687
|
+
return sizeForBaseType(this.baseType) * numElements;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
class UniformBufferLayoutBuilder {
|
|
2691
|
+
constructor() {
|
|
2692
|
+
this._size = 0;
|
|
2693
|
+
this._members = new Map();
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Reserve an explicit size for the resulting UBO layout. If not set the
|
|
2697
|
+
* builder will compute a size that fits all declared members.
|
|
2698
|
+
*/
|
|
2699
|
+
withSize(size) {
|
|
2700
|
+
if (this._size !== 0)
|
|
2701
|
+
throw new Error("Size already set.");
|
|
2702
|
+
this._size = size;
|
|
2703
|
+
return this;
|
|
2704
|
+
}
|
|
2705
|
+
pushScalar(baseType, name) {
|
|
2706
|
+
return this._pushField(baseType, name, ContainerType.Scalar);
|
|
2707
|
+
}
|
|
2708
|
+
pushVec2(baseType, name) {
|
|
2709
|
+
return this._pushField(baseType, name, ContainerType.Vec, 2);
|
|
2710
|
+
}
|
|
2711
|
+
pushVec3(baseType, name) {
|
|
2712
|
+
return this._pushField(baseType, name, ContainerType.Vec, 3);
|
|
2713
|
+
}
|
|
2714
|
+
pushVec4(baseType, name) {
|
|
2715
|
+
return this._pushField(baseType, name, ContainerType.Vec, 4);
|
|
2716
|
+
}
|
|
2717
|
+
pushMatrix(baseType, numRows, numCols, name) {
|
|
2718
|
+
if (!Number.isInteger(numRows) || !Number.isInteger(numCols)) {
|
|
2719
|
+
throw new Error('Matrix dimensions must be integers');
|
|
2720
|
+
}
|
|
2721
|
+
if (numRows < 2 || numRows > 4 || numCols < 2 || numCols > 4) {
|
|
2722
|
+
throw new Error('Matrix dimensions must be between 2 and 4 (inclusive)');
|
|
2723
|
+
}
|
|
2724
|
+
return this._pushField(baseType, name, ContainerType.Matrix, numRows, numCols);
|
|
2725
|
+
}
|
|
2726
|
+
/**
|
|
2727
|
+
* Finalize and return a `UniformBufferLayout` describing member offsets and total size.
|
|
2728
|
+
*/
|
|
2729
|
+
build() {
|
|
2730
|
+
// round up to 16 byte alignment with a 16 byte minimum
|
|
2731
|
+
this._size = Math.ceil(this._size / 16) * 16;
|
|
2732
|
+
return new UniformBufferLayout(this._size, this._members);
|
|
2733
|
+
}
|
|
2734
|
+
_pushField(baseType, name, containerType, numRows = 1, numCols = 1) {
|
|
2735
|
+
const type = new MemberType(baseType, containerType, numRows, numCols);
|
|
2736
|
+
const alignment = type.alignment;
|
|
2737
|
+
const offset = Math.ceil(this._size / alignment) * alignment;
|
|
2738
|
+
this._members.set(name, { offset, type });
|
|
2739
|
+
this._size = offset + type.size;
|
|
2740
|
+
return this;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* Describes the layout of a uniform buffer including member offsets and total size.
|
|
2745
|
+
* Use `UniformBufferLayoutBuilder` to construct instances.
|
|
2746
|
+
*/
|
|
2747
|
+
class UniformBufferLayout {
|
|
2748
|
+
constructor(size, members) {
|
|
2749
|
+
this.size = size;
|
|
2750
|
+
this._members = members;
|
|
2751
|
+
}
|
|
2752
|
+
/**
|
|
2753
|
+
* Create typed DataViews for each member of the layout.
|
|
2754
|
+
* @internal
|
|
2755
|
+
*/
|
|
2756
|
+
_createDataViews(target) {
|
|
2757
|
+
const map = new Map();
|
|
2758
|
+
for (const [name, member] of this._members) {
|
|
2759
|
+
let ArrayConst;
|
|
2760
|
+
const size = member.type.size;
|
|
2761
|
+
let byteSize = 4;
|
|
2762
|
+
switch (member.type.baseType) {
|
|
2763
|
+
case BaseType.Float16:
|
|
2764
|
+
byteSize = 2;
|
|
2765
|
+
ArrayConst = Uint16Array;
|
|
2766
|
+
break;
|
|
2767
|
+
case BaseType.Float32:
|
|
2768
|
+
ArrayConst = Float32Array;
|
|
2769
|
+
break;
|
|
2770
|
+
case BaseType.Uint:
|
|
2771
|
+
case BaseType.Boolean:
|
|
2772
|
+
ArrayConst = Uint32Array;
|
|
2773
|
+
break;
|
|
2774
|
+
case BaseType.Sint:
|
|
2775
|
+
ArrayConst = Int32Array;
|
|
2776
|
+
break;
|
|
2777
|
+
}
|
|
2778
|
+
map.set(name, [member, new ArrayConst(target, member.offset, size / byteSize)]);
|
|
2779
|
+
}
|
|
2780
|
+
return map;
|
|
2781
|
+
}
|
|
2782
|
+
_getMemberOrThrow(name) {
|
|
2783
|
+
const member = this._members.get(name);
|
|
2784
|
+
if (!member) {
|
|
2785
|
+
throw new Error(`Member ${name} not found in layout.`);
|
|
2786
|
+
}
|
|
2787
|
+
return member;
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
/**
|
|
2791
|
+
* GPU-backed uniform buffer wrapper providing typed setters and an upload method.
|
|
2792
|
+
* Use {@link TinyHelix.createUniformBuffer} to create instances.
|
|
2793
|
+
*/
|
|
2794
|
+
class UniformBuffer {
|
|
2795
|
+
/**
|
|
2796
|
+
* Create a new UniformBuffer with the given layout and WebGPU context.
|
|
2797
|
+
* @internal
|
|
2798
|
+
*/
|
|
2799
|
+
constructor(layout, ctx) {
|
|
2800
|
+
this._dataViews = new Map();
|
|
2801
|
+
const data = new ArrayBuffer(layout.size);
|
|
2802
|
+
this._buffer = new _Buffer__WEBPACK_IMPORTED_MODULE_0__.BufferBuilder(ctx)
|
|
2803
|
+
.withUsage(GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST)
|
|
2804
|
+
.withData(data, true)
|
|
2805
|
+
.build();
|
|
2806
|
+
this._data = this._buffer.data;
|
|
2807
|
+
this._dataViews = layout._createDataViews(this._data);
|
|
2808
|
+
// hmmm let's think a bit here.
|
|
2809
|
+
// We could go through all the members of the layout and create typed views for them, so we don't need all the
|
|
2810
|
+
// _write functions upstairs
|
|
2811
|
+
this._ctx = ctx;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Sets the value of a scalar field.
|
|
2815
|
+
* @param name Name of the scalar field.
|
|
2816
|
+
* @param value Value to set.
|
|
2817
|
+
*/
|
|
2818
|
+
setScalar(name, value) {
|
|
2819
|
+
const [member, target] = this._dataViews.get(name);
|
|
2820
|
+
if (member.type.baseType === BaseType.Float16) {
|
|
2821
|
+
target[0] = (0,_utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_1__.float32ToFloat16)(value);
|
|
2822
|
+
}
|
|
2823
|
+
else {
|
|
2824
|
+
target[0] = value;
|
|
2825
|
+
}
|
|
2826
|
+
return this;
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Sets the values for a vector field.
|
|
2830
|
+
* @param name Name of the vector field.
|
|
2831
|
+
* @param values Array of values to set.
|
|
2832
|
+
*/
|
|
2833
|
+
setVec(name, values) {
|
|
2834
|
+
const [member, target] = this._dataViews.get(name);
|
|
2835
|
+
if (member.type.baseType == BaseType.Float16) {
|
|
2836
|
+
for (let i = 0; i < values.length; ++i) {
|
|
2837
|
+
target[i] = (0,_utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_1__.float32ToFloat16)(values[i]);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
else {
|
|
2841
|
+
for (let i = 0; i < values.length; ++i) {
|
|
2842
|
+
target[i] = values[i];
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
return this;
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* Sets the values for a matrix field.
|
|
2849
|
+
* @param name Name of the matrix field.
|
|
2850
|
+
* @param values Array of values to set. The values are expected to be in column-major order.
|
|
2851
|
+
*/
|
|
2852
|
+
setMatrix(name, values) {
|
|
2853
|
+
const [member, target] = this._dataViews.get(name);
|
|
2854
|
+
const numCols = member.type.numCols;
|
|
2855
|
+
const numRows = member.type.numRows;
|
|
2856
|
+
const skipW = numRows === 3;
|
|
2857
|
+
// I know looping inside the cases looks ugly and the loops are tiny, but I just can't bring myself to put
|
|
2858
|
+
// a switch in a loop
|
|
2859
|
+
let i = 0;
|
|
2860
|
+
if (member.type.baseType === BaseType.Float16) {
|
|
2861
|
+
for (let col = 0; col < numCols; ++col) {
|
|
2862
|
+
for (let row = 0; row < numRows; ++row) {
|
|
2863
|
+
target[i] = (0,_utils_float32ToFloat16__WEBPACK_IMPORTED_MODULE_1__.float32ToFloat16)(values[i]);
|
|
2864
|
+
++i;
|
|
2865
|
+
}
|
|
2866
|
+
if (skipW)
|
|
2867
|
+
++i;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
else {
|
|
2871
|
+
for (let col = 0; col < numCols; ++col) {
|
|
2872
|
+
for (let row = 0; row < numRows; ++row) {
|
|
2873
|
+
target[i] = values[i];
|
|
2874
|
+
++i;
|
|
2875
|
+
}
|
|
2876
|
+
if (skipW)
|
|
2877
|
+
++i;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
return this;
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* Upload the current buffer contents to the GPU.
|
|
2884
|
+
*/
|
|
2885
|
+
upload() {
|
|
2886
|
+
this._buffer._uploadData(this._ctx);
|
|
2887
|
+
return this;
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Internal accessor returning the underlying Buffer wrapper.
|
|
2891
|
+
* @internal
|
|
2892
|
+
*/
|
|
2893
|
+
_getBufferResource() {
|
|
2894
|
+
return { buffer: this._buffer._inner };
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
|
|
2899
|
+
/***/ }),
|
|
2900
|
+
|
|
2901
|
+
/***/ "./src/enums.ts":
|
|
2902
|
+
/*!**********************!*\
|
|
2903
|
+
!*** ./src/enums.ts ***!
|
|
2904
|
+
\**********************/
|
|
2905
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2906
|
+
|
|
2907
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2908
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2909
|
+
/* harmony export */ AddressMode: () => (/* binding */ AddressMode),
|
|
2910
|
+
/* harmony export */ BlendFactor: () => (/* binding */ BlendFactor),
|
|
2911
|
+
/* harmony export */ ColorSpace: () => (/* binding */ ColorSpace),
|
|
2912
|
+
/* harmony export */ CompareFunction: () => (/* binding */ CompareFunction),
|
|
2913
|
+
/* harmony export */ CullMode: () => (/* binding */ CullMode),
|
|
2914
|
+
/* harmony export */ FilterMode: () => (/* binding */ FilterMode),
|
|
2915
|
+
/* harmony export */ StorageAccess: () => (/* binding */ StorageAccess),
|
|
2916
|
+
/* harmony export */ TextureFormat: () => (/* binding */ TextureFormat)
|
|
2917
|
+
/* harmony export */ });
|
|
2918
|
+
var ColorSpace;
|
|
2919
|
+
(function (ColorSpace) {
|
|
2920
|
+
ColorSpace["sRGB"] = "srgb";
|
|
2921
|
+
ColorSpace["DisplayP3"] = "display-p3";
|
|
2922
|
+
})(ColorSpace || (ColorSpace = {}));
|
|
2923
|
+
var FilterMode;
|
|
2924
|
+
(function (FilterMode) {
|
|
2925
|
+
FilterMode["Nearest"] = "nearest";
|
|
2926
|
+
FilterMode["Linear"] = "linear";
|
|
2927
|
+
})(FilterMode || (FilterMode = {}));
|
|
2928
|
+
var AddressMode;
|
|
2929
|
+
(function (AddressMode) {
|
|
2930
|
+
AddressMode["ClampToEdge"] = "clamp-to-edge";
|
|
2931
|
+
AddressMode["Repeat"] = "repeat";
|
|
2932
|
+
AddressMode["MirrorRepeat"] = "mirror-repeat";
|
|
2933
|
+
})(AddressMode || (AddressMode = {}));
|
|
2934
|
+
/**
|
|
2935
|
+
* Face culling modes used by the render pipeline primitive state.
|
|
2936
|
+
*/
|
|
2937
|
+
var CullMode;
|
|
2938
|
+
(function (CullMode) {
|
|
2939
|
+
CullMode["None"] = "none";
|
|
2940
|
+
CullMode["Front"] = "front";
|
|
2941
|
+
CullMode["Back"] = "back";
|
|
2942
|
+
})(CullMode || (CullMode = {}));
|
|
2943
|
+
var TextureFormat;
|
|
2944
|
+
(function (TextureFormat) {
|
|
2945
|
+
TextureFormat["R8Unorm"] = "r8unorm";
|
|
2946
|
+
TextureFormat["R8Snorm"] = "r8snorm";
|
|
2947
|
+
TextureFormat["R8Uint"] = "r8uint";
|
|
2948
|
+
TextureFormat["R8Sint"] = "r8sint";
|
|
2949
|
+
TextureFormat["R16Unorm"] = "r16unorm";
|
|
2950
|
+
TextureFormat["R16Snorm"] = "r16snorm";
|
|
2951
|
+
TextureFormat["R16Uint"] = "r16uint";
|
|
2952
|
+
TextureFormat["R16Sint"] = "r16sint";
|
|
2953
|
+
TextureFormat["R16Float"] = "r16float";
|
|
2954
|
+
TextureFormat["RG8Unorm"] = "rg8unorm";
|
|
2955
|
+
TextureFormat["RG8Snorm"] = "rg8snorm";
|
|
2956
|
+
TextureFormat["RG8Uint"] = "rg8uint";
|
|
2957
|
+
TextureFormat["RG8Sint"] = "rg8sint";
|
|
2958
|
+
TextureFormat["R32Uint"] = "r32uint";
|
|
2959
|
+
TextureFormat["R32Sint"] = "r32sint";
|
|
2960
|
+
TextureFormat["R32Float"] = "r32float";
|
|
2961
|
+
TextureFormat["RG16Unorm"] = "rg16unorm";
|
|
2962
|
+
TextureFormat["RG16Snorm"] = "rg16snorm";
|
|
2963
|
+
TextureFormat["RG16Uint"] = "rg16uint";
|
|
2964
|
+
TextureFormat["RG16Sint"] = "rg16sint";
|
|
2965
|
+
TextureFormat["RG16Float"] = "rg16float";
|
|
2966
|
+
TextureFormat["Rgba8Unorm"] = "rgba8unorm";
|
|
2967
|
+
TextureFormat["Rgba8UnormSrgb"] = "rgba8unorm-srgb";
|
|
2968
|
+
TextureFormat["Rgba8Snorm"] = "rgba8snorm";
|
|
2969
|
+
TextureFormat["Rgba8Uint"] = "rgba8uint";
|
|
2970
|
+
TextureFormat["Rgba8Sint"] = "rgba8sint";
|
|
2971
|
+
TextureFormat["Bgra8Unorm"] = "bgra8unorm";
|
|
2972
|
+
TextureFormat["Bgra8UnormSrgb"] = "bgra8unorm-srgb";
|
|
2973
|
+
TextureFormat["Rgb9e5Ufloat"] = "rgb9e5ufloat";
|
|
2974
|
+
TextureFormat["Rgb10a2Uint"] = "rgb10a2uint";
|
|
2975
|
+
TextureFormat["Rgb10a2Unorm"] = "rgb10a2unorm";
|
|
2976
|
+
TextureFormat["Rg11b10Ufloat"] = "rg11b10ufloat";
|
|
2977
|
+
TextureFormat["RG32Uint"] = "rg32uint";
|
|
2978
|
+
TextureFormat["RG32Sint"] = "rg32sint";
|
|
2979
|
+
TextureFormat["RG32Float"] = "rg32float";
|
|
2980
|
+
TextureFormat["Rgba16Unorm"] = "rgba16unorm";
|
|
2981
|
+
TextureFormat["Rgba16Snorm"] = "rgba16snorm";
|
|
2982
|
+
TextureFormat["Rgba16Uint"] = "rgba16uint";
|
|
2983
|
+
TextureFormat["Rgba16Sint"] = "rgba16sint";
|
|
2984
|
+
TextureFormat["Rgba16Float"] = "rgba16float";
|
|
2985
|
+
TextureFormat["Rgba32Uint"] = "rgba32uint";
|
|
2986
|
+
TextureFormat["Rgba32Sint"] = "rgba32sint";
|
|
2987
|
+
TextureFormat["Rgba32Float"] = "rgba32float";
|
|
2988
|
+
TextureFormat["Stencil8"] = "stencil8";
|
|
2989
|
+
TextureFormat["Depth16Unorm"] = "depth16unorm";
|
|
2990
|
+
TextureFormat["Depth24Plus"] = "depth24plus";
|
|
2991
|
+
TextureFormat["Depth24PlusStencil8"] = "depth24plus-stencil8";
|
|
2992
|
+
TextureFormat["Depth32Float"] = "depth32float";
|
|
2993
|
+
TextureFormat["Depth32FloatStencil8"] = "depth32float-stencil8";
|
|
2994
|
+
TextureFormat["Bc1RgbaUnorm"] = "bc1-rgba-unorm";
|
|
2995
|
+
TextureFormat["Bc1RgbaUnormSrgb"] = "bc1-rgba-unorm-srgb";
|
|
2996
|
+
TextureFormat["Bc2RgbaUnorm"] = "bc2-rgba-unorm";
|
|
2997
|
+
TextureFormat["Bc2RgbaUnormSrgb"] = "bc2-rgba-unorm-srgb";
|
|
2998
|
+
TextureFormat["Bc3RgbaUnorm"] = "bc3-rgba-unorm";
|
|
2999
|
+
TextureFormat["Bc3RgbaUnormSrgb"] = "bc3-rgba-unorm-srgb";
|
|
3000
|
+
TextureFormat["Bc4RUnorm"] = "bc4-r-unorm";
|
|
3001
|
+
TextureFormat["Bc4RSnorm"] = "bc4-r-snorm";
|
|
3002
|
+
TextureFormat["Bc5RgUnorm"] = "bc5-rg-unorm";
|
|
3003
|
+
TextureFormat["Bc5RgSnorm"] = "bc5-rg-snorm";
|
|
3004
|
+
TextureFormat["Bc6hRgbUfloat"] = "bc6h-rgb-ufloat";
|
|
3005
|
+
TextureFormat["Bc6hRgbFloat"] = "bc6h-rgb-float";
|
|
3006
|
+
TextureFormat["Bc7RgbaUnorm"] = "bc7-rgba-unorm";
|
|
3007
|
+
TextureFormat["Bc7RgbaUnormSrgb"] = "bc7-rgba-unorm-srgb";
|
|
3008
|
+
TextureFormat["Etc2Rgb8Unorm"] = "etc2-rgb8unorm";
|
|
3009
|
+
TextureFormat["Etc2Rgb8UnormSrgb"] = "etc2-rgb8unorm-srgb";
|
|
3010
|
+
TextureFormat["Etc2Rgb8A1Unorm"] = "etc2-rgb8a1unorm";
|
|
3011
|
+
TextureFormat["Etc2Rgb8A1UnormSrgb"] = "etc2-rgb8a1unorm-srgb";
|
|
3012
|
+
TextureFormat["Etc2Rgba8Unorm"] = "etc2-rgba8unorm";
|
|
3013
|
+
TextureFormat["Etc2Rgba8UnormSrgb"] = "etc2-rgba8unorm-srgb";
|
|
3014
|
+
TextureFormat["EacR11Unorm"] = "eac-r11unorm";
|
|
3015
|
+
TextureFormat["EacR11Snorm"] = "eac-r11snorm";
|
|
3016
|
+
TextureFormat["EacRg11Unorm"] = "eac-rg11unorm";
|
|
3017
|
+
TextureFormat["EacRg11Snorm"] = "eac-rg11snorm";
|
|
3018
|
+
TextureFormat["Astc4x4Unorm"] = "astc-4x4-unorm";
|
|
3019
|
+
TextureFormat["Astc4x4UnormSrgb"] = "astc-4x4-unorm-srgb";
|
|
3020
|
+
TextureFormat["Astc5x4Unorm"] = "astc-5x4-unorm";
|
|
3021
|
+
TextureFormat["Astc5x4UnormSrgb"] = "astc-5x4-unorm-srgb";
|
|
3022
|
+
TextureFormat["Astc5x5Unorm"] = "astc-5x5-unorm";
|
|
3023
|
+
TextureFormat["Astc5x5UnormSrgb"] = "astc-5x5-unorm-srgb";
|
|
3024
|
+
TextureFormat["Astc6x5Unorm"] = "astc-6x5-unorm";
|
|
3025
|
+
TextureFormat["Astc6x5UnormSrgb"] = "astc-6x5-unorm-srgb";
|
|
3026
|
+
TextureFormat["Astc6x6Unorm"] = "astc-6x6-unorm";
|
|
3027
|
+
TextureFormat["Astc6x6UnormSrgb"] = "astc-6x6-unorm-srgb";
|
|
3028
|
+
TextureFormat["Astc8x5Unorm"] = "astc-8x5-unorm";
|
|
3029
|
+
TextureFormat["Astc8x5UnormSrgb"] = "astc-8x5-unorm-srgb";
|
|
3030
|
+
TextureFormat["Astc8x6Unorm"] = "astc-8x6-unorm";
|
|
3031
|
+
TextureFormat["Astc8x6UnormSrgb"] = "astc-8x6-unorm-srgb";
|
|
3032
|
+
TextureFormat["Astc8x8Unorm"] = "astc-8x8-unorm";
|
|
3033
|
+
TextureFormat["Astc8x8UnormSrgb"] = "astc-8x8-unorm-srgb";
|
|
3034
|
+
TextureFormat["Astc10x5Unorm"] = "astc-10x5-unorm";
|
|
3035
|
+
TextureFormat["Astc10x5UnormSrgb"] = "astc-10x5-unorm-srgb";
|
|
3036
|
+
TextureFormat["Astc10x6Unorm"] = "astc-10x6-unorm";
|
|
3037
|
+
TextureFormat["Astc10x6UnormSrgb"] = "astc-10x6-unorm-srgb";
|
|
3038
|
+
TextureFormat["Astc10x8Unorm"] = "astc-10x8-unorm";
|
|
3039
|
+
TextureFormat["Astc10x8UnormSrgb"] = "astc-10x8-unorm-srgb";
|
|
3040
|
+
TextureFormat["Astc10x10Unorm"] = "astc-10x10-unorm";
|
|
3041
|
+
TextureFormat["Astc10x10UnormSrgb"] = "astc-10x10-unorm-srgb";
|
|
3042
|
+
TextureFormat["Astc12x10Unorm"] = "astc-12x10-unorm";
|
|
3043
|
+
TextureFormat["Astc12x10UnormSrgb"] = "astc-12x10-unorm-srgb";
|
|
3044
|
+
TextureFormat["Astc12x12Unorm"] = "astc-12x12-unorm";
|
|
3045
|
+
TextureFormat["Astc12x12UnormSrgb"] = "astc-12x12-unorm-srgb";
|
|
3046
|
+
})(TextureFormat || (TextureFormat = {}));
|
|
3047
|
+
var BlendFactor;
|
|
3048
|
+
(function (BlendFactor) {
|
|
3049
|
+
BlendFactor["Zero"] = "zero";
|
|
3050
|
+
BlendFactor["One"] = "one";
|
|
3051
|
+
BlendFactor["SrcColor"] = "src";
|
|
3052
|
+
BlendFactor["OneMinusSrcColor"] = "one-minus-src";
|
|
3053
|
+
BlendFactor["SrcAlpha"] = "src-alpha";
|
|
3054
|
+
BlendFactor["OneMinusSrcAlpha"] = "one-minus-src-alpha";
|
|
3055
|
+
BlendFactor["DstColor"] = "dst";
|
|
3056
|
+
BlendFactor["OneMinusDstColor"] = "one-minus-dst";
|
|
3057
|
+
BlendFactor["DstAlpha"] = "dst-alpha";
|
|
3058
|
+
BlendFactor["OneMinusDstAlpha"] = "one-minus-dst-alpha";
|
|
3059
|
+
BlendFactor["SrcAlphaSaturated"] = "src-alpha-saturated";
|
|
3060
|
+
BlendFactor["Constant"] = "constant";
|
|
3061
|
+
BlendFactor["OneMinusConstant"] = "one-minus-constant";
|
|
3062
|
+
BlendFactor["Src1Color"] = "src1";
|
|
3063
|
+
BlendFactor["OneMinusSrc1Color"] = "one-minus-src1";
|
|
3064
|
+
BlendFactor["Src1Alpha"] = "src1-alpha";
|
|
3065
|
+
BlendFactor["OneMinusSrc1Alpha"] = "one-minus-src1-alpha";
|
|
3066
|
+
})(BlendFactor || (BlendFactor = {}));
|
|
3067
|
+
var CompareFunction;
|
|
3068
|
+
(function (CompareFunction) {
|
|
3069
|
+
CompareFunction["Never"] = "never";
|
|
3070
|
+
CompareFunction["Less"] = "less";
|
|
3071
|
+
CompareFunction["Equal"] = "equal";
|
|
3072
|
+
CompareFunction["LessEqual"] = "less-equal";
|
|
3073
|
+
CompareFunction["Greater"] = "greater";
|
|
3074
|
+
CompareFunction["NotEqual"] = "not-equal";
|
|
3075
|
+
CompareFunction["GreaterEqual"] = "greater-equal";
|
|
3076
|
+
CompareFunction["Always"] = "always";
|
|
3077
|
+
})(CompareFunction || (CompareFunction = {}));
|
|
3078
|
+
var StorageAccess;
|
|
3079
|
+
(function (StorageAccess) {
|
|
3080
|
+
StorageAccess["ReadWrite"] = "read-write";
|
|
3081
|
+
StorageAccess["Read"] = "read-only";
|
|
3082
|
+
StorageAccess["Write"] = "write-only";
|
|
3083
|
+
})(StorageAccess || (StorageAccess = {}));
|
|
3084
|
+
|
|
3085
|
+
|
|
3086
|
+
/***/ }),
|
|
3087
|
+
|
|
3088
|
+
/***/ "./src/utils/float32ToFloat16.ts":
|
|
3089
|
+
/*!***************************************!*\
|
|
3090
|
+
!*** ./src/utils/float32ToFloat16.ts ***!
|
|
3091
|
+
\***************************************/
|
|
3092
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3093
|
+
|
|
3094
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3095
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3096
|
+
/* harmony export */ float32ToFloat16: () => (/* binding */ float32ToFloat16)
|
|
3097
|
+
/* harmony export */ });
|
|
3098
|
+
/**
|
|
3099
|
+
* Convert a JavaScript number (float32) to IEEE 754 binary16 (float16) representation.
|
|
3100
|
+
* Returns the 16-bit unsigned integer bit pattern for the half-float.
|
|
3101
|
+
*/
|
|
3102
|
+
function float32ToFloat16(value) {
|
|
3103
|
+
// This is a compact implementation adapted for correctness.
|
|
3104
|
+
const f32 = new Float32Array(1);
|
|
3105
|
+
f32[0] = value;
|
|
3106
|
+
const f32u = new Uint32Array(f32.buffer)[0];
|
|
3107
|
+
const sign = (f32u >> 16) & 0x8000;
|
|
3108
|
+
const exponent = ((f32u >> 23) & 0xff) - 127;
|
|
3109
|
+
const mantissa = f32u & 0x007fffff;
|
|
3110
|
+
if (exponent <= -15) {
|
|
3111
|
+
// Too small to be represented as a normalized half-float -> zero or subnormal
|
|
3112
|
+
// Round-to-zero behavior
|
|
3113
|
+
return sign;
|
|
3114
|
+
}
|
|
3115
|
+
if (exponent > 16) {
|
|
3116
|
+
// Overflow -> return Infinity
|
|
3117
|
+
return sign | 0x7c00;
|
|
3118
|
+
}
|
|
3119
|
+
const halfExp = exponent + 15;
|
|
3120
|
+
const halfMant = mantissa >> 13;
|
|
3121
|
+
return sign | (halfExp << 10) | halfMant;
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
|
|
3125
|
+
/***/ }),
|
|
3126
|
+
|
|
3127
|
+
/***/ "./src/utils/mapUndefined.ts":
|
|
3128
|
+
/*!***********************************!*\
|
|
3129
|
+
!*** ./src/utils/mapUndefined.ts ***!
|
|
3130
|
+
\***********************************/
|
|
3131
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3132
|
+
|
|
3133
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3134
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3135
|
+
/* harmony export */ mapUndefined: () => (/* binding */ mapUndefined)
|
|
3136
|
+
/* harmony export */ });
|
|
3137
|
+
/**
|
|
3138
|
+
* Maps undefined values to undefined and non-undefined values to the result of fn. Similar to Rust's `Option<T>::map`.
|
|
3139
|
+
* @param value The value to map.
|
|
3140
|
+
* @param fn The mapping function.
|
|
3141
|
+
*/
|
|
3142
|
+
function mapUndefined(value, fn) {
|
|
3143
|
+
if (value === undefined) {
|
|
3144
|
+
return undefined;
|
|
3145
|
+
}
|
|
3146
|
+
return fn(value);
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
|
|
3150
|
+
/***/ }),
|
|
3151
|
+
|
|
3152
|
+
/***/ "./src/utils/padArrayBuffer.ts":
|
|
3153
|
+
/*!*************************************!*\
|
|
3154
|
+
!*** ./src/utils/padArrayBuffer.ts ***!
|
|
3155
|
+
\*************************************/
|
|
3156
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3157
|
+
|
|
3158
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3159
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3160
|
+
/* harmony export */ padArrayBuffer: () => (/* binding */ padArrayBuffer)
|
|
3161
|
+
/* harmony export */ });
|
|
3162
|
+
/**
|
|
3163
|
+
* Pad an ArrayBuffer (or SharedArrayBuffer) to the given alignment in bytes.
|
|
3164
|
+
* If the input is already aligned, the original buffer is returned. Otherwise a
|
|
3165
|
+
* new buffer is allocated, the contents copied, and the new buffer returned.
|
|
3166
|
+
*
|
|
3167
|
+
* @param input - The input ArrayBuffer or SharedArrayBuffer to pad
|
|
3168
|
+
* @param alignment - Desired byte alignment (e.g. 4 for 32-bit alignment)
|
|
3169
|
+
* @returns A buffer with byteLength rounded up to the nearest multiple of alignment
|
|
3170
|
+
*/
|
|
3171
|
+
function padArrayBuffer(input, alignment) {
|
|
3172
|
+
const targetSize = Math.ceil(input.byteLength / alignment) * alignment;
|
|
3173
|
+
if (targetSize === input.byteLength)
|
|
3174
|
+
return input;
|
|
3175
|
+
const data = input instanceof ArrayBuffer ? new ArrayBuffer(targetSize) : new SharedArrayBuffer(targetSize);
|
|
3176
|
+
const src = new Uint8Array(input);
|
|
3177
|
+
const dst = new Uint8Array(data);
|
|
3178
|
+
dst.set(src);
|
|
3179
|
+
return data;
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
|
|
3183
|
+
/***/ })
|
|
3184
|
+
|
|
3185
|
+
/******/ });
|
|
3186
|
+
/************************************************************************/
|
|
3187
|
+
/******/ // The module cache
|
|
3188
|
+
/******/ var __webpack_module_cache__ = {};
|
|
3189
|
+
/******/
|
|
3190
|
+
/******/ // The require function
|
|
3191
|
+
/******/ function __webpack_require__(moduleId) {
|
|
3192
|
+
/******/ // Check if module is in cache
|
|
3193
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
3194
|
+
/******/ if (cachedModule !== undefined) {
|
|
3195
|
+
/******/ return cachedModule.exports;
|
|
3196
|
+
/******/ }
|
|
3197
|
+
/******/ // Create a new module (and put it into the cache)
|
|
3198
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
3199
|
+
/******/ // no module.id needed
|
|
3200
|
+
/******/ // no module.loaded needed
|
|
3201
|
+
/******/ exports: {}
|
|
3202
|
+
/******/ };
|
|
3203
|
+
/******/
|
|
3204
|
+
/******/ // Execute the module function
|
|
3205
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
3206
|
+
/******/
|
|
3207
|
+
/******/ // Return the exports of the module
|
|
3208
|
+
/******/ return module.exports;
|
|
3209
|
+
/******/ }
|
|
3210
|
+
/******/
|
|
3211
|
+
/************************************************************************/
|
|
3212
|
+
/******/ /* webpack/runtime/define property getters */
|
|
3213
|
+
/******/ (() => {
|
|
3214
|
+
/******/ // define getter functions for harmony exports
|
|
3215
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
3216
|
+
/******/ for(var key in definition) {
|
|
3217
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
3218
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
3219
|
+
/******/ }
|
|
3220
|
+
/******/ }
|
|
3221
|
+
/******/ };
|
|
3222
|
+
/******/ })();
|
|
3223
|
+
/******/
|
|
3224
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
3225
|
+
/******/ (() => {
|
|
3226
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
3227
|
+
/******/ })();
|
|
3228
|
+
/******/
|
|
3229
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
3230
|
+
/******/ (() => {
|
|
3231
|
+
/******/ // define __esModule on exports
|
|
3232
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
3233
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
3234
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
3235
|
+
/******/ }
|
|
3236
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
3237
|
+
/******/ };
|
|
3238
|
+
/******/ })();
|
|
3239
|
+
/******/
|
|
3240
|
+
/************************************************************************/
|
|
3241
|
+
var __webpack_exports__ = {};
|
|
3242
|
+
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
3243
|
+
(() => {
|
|
3244
|
+
/*!**********************!*\
|
|
3245
|
+
!*** ./src/index.ts ***!
|
|
3246
|
+
\**********************/
|
|
3247
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3248
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3249
|
+
/* harmony export */ AddressMode: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.AddressMode),
|
|
3250
|
+
/* harmony export */ BaseType: () => (/* reexport safe */ _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_16__.BaseType),
|
|
3251
|
+
/* harmony export */ BindGroup: () => (/* reexport safe */ _BindGroup__WEBPACK_IMPORTED_MODULE_2__.BindGroup),
|
|
3252
|
+
/* harmony export */ BindGroupBuilder: () => (/* reexport safe */ _BindGroup__WEBPACK_IMPORTED_MODULE_2__.BindGroupBuilder),
|
|
3253
|
+
/* harmony export */ BindGroupLayout: () => (/* reexport safe */ _BindGroup__WEBPACK_IMPORTED_MODULE_2__.BindGroupLayout),
|
|
3254
|
+
/* harmony export */ BlendFactor: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.BlendFactor),
|
|
3255
|
+
/* harmony export */ BlendMode: () => (/* reexport safe */ _BlendMode__WEBPACK_IMPORTED_MODULE_3__.BlendMode),
|
|
3256
|
+
/* harmony export */ Buffer: () => (/* reexport safe */ _buffers_Buffer__WEBPACK_IMPORTED_MODULE_15__.Buffer),
|
|
3257
|
+
/* harmony export */ BufferBuilder: () => (/* reexport safe */ _buffers_Buffer__WEBPACK_IMPORTED_MODULE_15__.BufferBuilder),
|
|
3258
|
+
/* harmony export */ BufferDataWriter: () => (/* reexport safe */ _buffers_BufferDataWriter__WEBPACK_IMPORTED_MODULE_17__.BufferDataWriter),
|
|
3259
|
+
/* harmony export */ BufferUsage: () => (/* reexport safe */ _buffers_Buffer__WEBPACK_IMPORTED_MODULE_15__.BufferUsage),
|
|
3260
|
+
/* harmony export */ ColorSpace: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.ColorSpace),
|
|
3261
|
+
/* harmony export */ CommandEncoder: () => (/* reexport safe */ _CommandEncoder__WEBPACK_IMPORTED_MODULE_4__.CommandEncoder),
|
|
3262
|
+
/* harmony export */ CompareFunction: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.CompareFunction),
|
|
3263
|
+
/* harmony export */ ComputePass: () => (/* reexport safe */ _ComputePass__WEBPACK_IMPORTED_MODULE_5__.ComputePass),
|
|
3264
|
+
/* harmony export */ ComputePassBuilder: () => (/* reexport safe */ _ComputePass__WEBPACK_IMPORTED_MODULE_5__.ComputePassBuilder),
|
|
3265
|
+
/* harmony export */ ComputePipeline: () => (/* reexport safe */ _ComputePipeline__WEBPACK_IMPORTED_MODULE_6__.ComputePipeline),
|
|
3266
|
+
/* harmony export */ ComputePipelineBuilder: () => (/* reexport safe */ _ComputePipeline__WEBPACK_IMPORTED_MODULE_6__.ComputePipelineBuilder),
|
|
3267
|
+
/* harmony export */ CullMode: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.CullMode),
|
|
3268
|
+
/* harmony export */ FilterMode: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.FilterMode),
|
|
3269
|
+
/* harmony export */ FrontFace: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.FrontFace),
|
|
3270
|
+
/* harmony export */ IndexFormat: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.IndexFormat),
|
|
3271
|
+
/* harmony export */ Mesh: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.Mesh),
|
|
3272
|
+
/* harmony export */ MeshBuilder: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.MeshBuilder),
|
|
3273
|
+
/* harmony export */ MeshTopology: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.MeshTopology),
|
|
3274
|
+
/* harmony export */ RenderPass: () => (/* reexport safe */ _RenderPass__WEBPACK_IMPORTED_MODULE_9__.RenderPass),
|
|
3275
|
+
/* harmony export */ RenderPassBuilder: () => (/* reexport safe */ _RenderPass__WEBPACK_IMPORTED_MODULE_9__.RenderPassBuilder),
|
|
3276
|
+
/* harmony export */ RenderPipeline: () => (/* reexport safe */ _RenderPipeline__WEBPACK_IMPORTED_MODULE_10__.RenderPipeline),
|
|
3277
|
+
/* harmony export */ RenderPipelineBuilder: () => (/* reexport safe */ _RenderPipeline__WEBPACK_IMPORTED_MODULE_10__.RenderPipelineBuilder),
|
|
3278
|
+
/* harmony export */ RenderTarget: () => (/* reexport safe */ _RenderTarget__WEBPACK_IMPORTED_MODULE_11__.RenderTarget),
|
|
3279
|
+
/* harmony export */ RenderTargetBuilder: () => (/* reexport safe */ _RenderTarget__WEBPACK_IMPORTED_MODULE_11__.RenderTargetBuilder),
|
|
3280
|
+
/* harmony export */ Sampler: () => (/* reexport safe */ _Sampler__WEBPACK_IMPORTED_MODULE_12__.Sampler),
|
|
3281
|
+
/* harmony export */ SamplerBuilder: () => (/* reexport safe */ _Sampler__WEBPACK_IMPORTED_MODULE_12__.SamplerBuilder),
|
|
3282
|
+
/* harmony export */ Shader: () => (/* reexport safe */ _Shader__WEBPACK_IMPORTED_MODULE_13__.Shader),
|
|
3283
|
+
/* harmony export */ ShaderBuilder: () => (/* reexport safe */ _Shader__WEBPACK_IMPORTED_MODULE_13__.ShaderBuilder),
|
|
3284
|
+
/* harmony export */ StorageAccess: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.StorageAccess),
|
|
3285
|
+
/* harmony export */ StreamBuilder: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.StreamBuilder),
|
|
3286
|
+
/* harmony export */ Texture: () => (/* reexport safe */ _Texture__WEBPACK_IMPORTED_MODULE_14__.Texture),
|
|
3287
|
+
/* harmony export */ TextureBuilder: () => (/* reexport safe */ _Texture__WEBPACK_IMPORTED_MODULE_14__.TextureBuilder),
|
|
3288
|
+
/* harmony export */ TextureFormat: () => (/* reexport safe */ _enums__WEBPACK_IMPORTED_MODULE_7__.TextureFormat),
|
|
3289
|
+
/* harmony export */ TextureUsage: () => (/* reexport safe */ _buffers_Buffer__WEBPACK_IMPORTED_MODULE_15__.TextureUsage),
|
|
3290
|
+
/* harmony export */ TextureView: () => (/* reexport safe */ _Texture__WEBPACK_IMPORTED_MODULE_14__.TextureView),
|
|
3291
|
+
/* harmony export */ TextureViewBuilder: () => (/* reexport safe */ _Texture__WEBPACK_IMPORTED_MODULE_14__.TextureViewBuilder),
|
|
3292
|
+
/* harmony export */ TinyHelix: () => (/* reexport safe */ _TinyHelix__WEBPACK_IMPORTED_MODULE_0__.TinyHelix),
|
|
3293
|
+
/* harmony export */ UniformBuffer: () => (/* reexport safe */ _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_16__.UniformBuffer),
|
|
3294
|
+
/* harmony export */ UniformBufferLayout: () => (/* reexport safe */ _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_16__.UniformBufferLayout),
|
|
3295
|
+
/* harmony export */ UniformBufferLayoutBuilder: () => (/* reexport safe */ _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_16__.UniformBufferLayoutBuilder),
|
|
3296
|
+
/* harmony export */ VertexFormat: () => (/* reexport safe */ _Mesh__WEBPACK_IMPORTED_MODULE_8__.VertexFormat),
|
|
3297
|
+
/* harmony export */ WebGPUContext: () => (/* reexport safe */ _WebGPUContext__WEBPACK_IMPORTED_MODULE_1__.WebGPUContext),
|
|
3298
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
3299
|
+
/* harmony export */ });
|
|
3300
|
+
/* harmony import */ var _TinyHelix__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./TinyHelix */ "./src/TinyHelix.ts");
|
|
3301
|
+
/* harmony import */ var _WebGPUContext__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./WebGPUContext */ "./src/WebGPUContext.ts");
|
|
3302
|
+
/* harmony import */ var _BindGroup__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BindGroup */ "./src/BindGroup.ts");
|
|
3303
|
+
/* harmony import */ var _BlendMode__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./BlendMode */ "./src/BlendMode.ts");
|
|
3304
|
+
/* harmony import */ var _CommandEncoder__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CommandEncoder */ "./src/CommandEncoder.ts");
|
|
3305
|
+
/* harmony import */ var _ComputePass__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./ComputePass */ "./src/ComputePass.ts");
|
|
3306
|
+
/* harmony import */ var _ComputePipeline__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./ComputePipeline */ "./src/ComputePipeline.ts");
|
|
3307
|
+
/* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./enums */ "./src/enums.ts");
|
|
3308
|
+
/* harmony import */ var _Mesh__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Mesh */ "./src/Mesh.ts");
|
|
3309
|
+
/* harmony import */ var _RenderPass__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./RenderPass */ "./src/RenderPass.ts");
|
|
3310
|
+
/* harmony import */ var _RenderPipeline__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./RenderPipeline */ "./src/RenderPipeline.ts");
|
|
3311
|
+
/* harmony import */ var _RenderTarget__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./RenderTarget */ "./src/RenderTarget.ts");
|
|
3312
|
+
/* harmony import */ var _Sampler__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./Sampler */ "./src/Sampler.ts");
|
|
3313
|
+
/* harmony import */ var _Shader__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./Shader */ "./src/Shader.ts");
|
|
3314
|
+
/* harmony import */ var _Texture__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./Texture */ "./src/Texture.ts");
|
|
3315
|
+
/* harmony import */ var _buffers_Buffer__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./buffers/Buffer */ "./src/buffers/Buffer.ts");
|
|
3316
|
+
/* harmony import */ var _buffers_UniformBuffer__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./buffers/UniformBuffer */ "./src/buffers/UniformBuffer.ts");
|
|
3317
|
+
/* harmony import */ var _buffers_BufferDataWriter__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./buffers/BufferDataWriter */ "./src/buffers/BufferDataWriter.ts");
|
|
3318
|
+
/**
|
|
3319
|
+
* tiny-helix: A TypeScript library for WebGPU
|
|
3320
|
+
* @packageDocumentation
|
|
3321
|
+
*/
|
|
3322
|
+
|
|
3323
|
+
|
|
3324
|
+
// Default export for convenience
|
|
3325
|
+
|
|
3326
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_TinyHelix__WEBPACK_IMPORTED_MODULE_0__.TinyHelix);
|
|
3327
|
+
|
|
3328
|
+
|
|
3329
|
+
|
|
3330
|
+
|
|
3331
|
+
|
|
3332
|
+
|
|
3333
|
+
|
|
3334
|
+
|
|
3335
|
+
|
|
3336
|
+
|
|
3337
|
+
|
|
3338
|
+
|
|
3339
|
+
|
|
3340
|
+
|
|
3341
|
+
|
|
3342
|
+
|
|
3343
|
+
|
|
3344
|
+
})();
|
|
3345
|
+
|
|
3346
|
+
__webpack_exports__ = __webpack_exports__["default"];
|
|
3347
|
+
/******/ return __webpack_exports__;
|
|
3348
|
+
/******/ })()
|
|
3349
|
+
;
|
|
3350
|
+
});
|
|
3351
|
+
//# sourceMappingURL=tiny-helix.debug.js.map
|