@aethervtt/shard-gpu-webgl2 0.0.0-stage → 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 +2 -2
- package/dist/binding.d.ts +32 -0
- package/dist/binding.js +81 -0
- package/dist/cache.d.ts +73 -0
- package/dist/cache.js +184 -0
- package/dist/commands.d.ts +94 -0
- package/dist/commands.js +366 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.js +38 -0
- package/dist/copies.d.ts +61 -0
- package/dist/copies.js +621 -0
- package/dist/device.d.ts +160 -0
- package/dist/device.js +384 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +18 -0
- package/dist/fake-gl.d.ts +316 -0
- package/dist/fake-gl.js +949 -0
- package/dist/fbo.d.ts +30 -0
- package/dist/fbo.js +142 -0
- package/dist/formats.d.ts +25 -0
- package/dist/formats.js +106 -0
- package/dist/gl.d.ts +216 -0
- package/dist/gl.js +232 -0
- package/dist/gpu.d.ts +58 -0
- package/dist/gpu.js +213 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +42 -0
- package/dist/naga.d.ts +37 -0
- package/dist/naga.js +99 -0
- package/dist/pipeline.d.ts +113 -0
- package/dist/pipeline.js +294 -0
- package/dist/present.d.ts +18 -0
- package/dist/present.js +108 -0
- package/dist/queue.d.ts +13 -0
- package/dist/queue.js +50 -0
- package/dist/readback.d.ts +17 -0
- package/dist/readback.js +104 -0
- package/dist/replay.d.ts +76 -0
- package/dist/replay.js +657 -0
- package/dist/resources.d.ts +93 -0
- package/dist/resources.js +353 -0
- package/dist/state.d.ts +43 -0
- package/dist/state.js +169 -0
- package/package.json +36 -4
- package/wasm/shard_naga.wasm +0 -0
package/dist/readback.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { GL } from "./gl.js";
|
|
2
|
+
const READ_BYTES = { format: GL.RGBA, type: GL.UNSIGNED_BYTE, bytes: 4, direct: false };
|
|
3
|
+
const READ_BYTES_DIRECT = { ...READ_BYTES, direct: true };
|
|
4
|
+
const READ_FLOAT = { format: GL.RGBA, type: GL.FLOAT, bytes: 16, direct: false };
|
|
5
|
+
const READ_FLOAT_DIRECT = { ...READ_FLOAT, direct: true };
|
|
6
|
+
const READ_UINT = {
|
|
7
|
+
format: GL.RGBA_INTEGER,
|
|
8
|
+
type: GL.UNSIGNED_INT,
|
|
9
|
+
bytes: 16,
|
|
10
|
+
direct: false
|
|
11
|
+
};
|
|
12
|
+
const READ_UINT_DIRECT = { ...READ_UINT, direct: true };
|
|
13
|
+
const READ_SINT = { format: GL.RGBA_INTEGER, type: GL.INT, bytes: 16, direct: false };
|
|
14
|
+
function readFormatOf(info) {
|
|
15
|
+
if (info.kind === "uint") return info.internal === GL.RGBA32UI ? READ_UINT_DIRECT : READ_UINT;
|
|
16
|
+
if (info.kind === "sint") return READ_SINT;
|
|
17
|
+
if (info.kind === "depth") return READ_FLOAT;
|
|
18
|
+
if (info.type === GL.UNSIGNED_BYTE || info.type === GL.UNSIGNED_INT_2_10_10_10_REV) {
|
|
19
|
+
return info.internal === GL.RGBA8 || info.internal === GL.SRGB8_ALPHA8 ? READ_BYTES_DIRECT : READ_BYTES;
|
|
20
|
+
}
|
|
21
|
+
return info.internal === GL.RGBA32F ? READ_FLOAT_DIRECT : READ_FLOAT;
|
|
22
|
+
}
|
|
23
|
+
const scratch = new DataView(new ArrayBuffer(4));
|
|
24
|
+
function floatToHalf(value) {
|
|
25
|
+
scratch.setFloat32(0, value, true);
|
|
26
|
+
const x = scratch.getUint32(0, true);
|
|
27
|
+
const sign = x >>> 16 & 32768;
|
|
28
|
+
const exp = x >>> 23 & 255;
|
|
29
|
+
let mant = x & 8388607;
|
|
30
|
+
if (exp === 255) return sign | 31744 | (mant !== 0 ? 512 : 0);
|
|
31
|
+
let e = exp - 112;
|
|
32
|
+
if (e >= 31) return sign | 31744;
|
|
33
|
+
if (e <= 0) {
|
|
34
|
+
if (e < -10) return sign;
|
|
35
|
+
mant = (mant | 8388608) >>> 1 - e;
|
|
36
|
+
return sign | mant + 4096 >>> 13;
|
|
37
|
+
}
|
|
38
|
+
mant += 4096;
|
|
39
|
+
if (mant & 8388608) {
|
|
40
|
+
mant = 0;
|
|
41
|
+
e++;
|
|
42
|
+
if (e >= 31) return sign | 31744;
|
|
43
|
+
}
|
|
44
|
+
return sign | e << 10 | mant >>> 13;
|
|
45
|
+
}
|
|
46
|
+
function toUfloat(value, bits) {
|
|
47
|
+
if (!(value > 0)) return 0;
|
|
48
|
+
scratch.setFloat32(0, value, true);
|
|
49
|
+
const x = scratch.getUint32(0, true);
|
|
50
|
+
const e = (x >>> 23 & 255) - 112;
|
|
51
|
+
const mant = x & 8388607;
|
|
52
|
+
if (e >= 31) return 31 << bits;
|
|
53
|
+
if (e <= 0) return (mant | 8388608) >>> 1 - e >>> 23 - bits;
|
|
54
|
+
return e << bits | mant >>> 23 - bits;
|
|
55
|
+
}
|
|
56
|
+
function repack(src, read, info, width, rows, out, outOffset, bytesPerRow) {
|
|
57
|
+
const input = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
58
|
+
const output = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
59
|
+
const components = info.components;
|
|
60
|
+
const size = info.bytes / components;
|
|
61
|
+
for (let y = 0; y < rows; y++) {
|
|
62
|
+
for (let x = 0; x < width; x++) {
|
|
63
|
+
const i = (y * width + x) * read.bytes;
|
|
64
|
+
const o = outOffset + y * bytesPerRow + x * info.bytes;
|
|
65
|
+
if (info.internal === GL.RGB10_A2) {
|
|
66
|
+
const r = Math.round(src[i] * 1023 / 255);
|
|
67
|
+
const g = Math.round(src[i + 1] * 1023 / 255);
|
|
68
|
+
const b = Math.round(src[i + 2] * 1023 / 255);
|
|
69
|
+
const a = Math.round(src[i + 3] * 3 / 255);
|
|
70
|
+
output.setUint32(o, (r | g << 10 | b << 20 | a << 30) >>> 0, true);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (info.internal === GL.R11F_G11F_B10F) {
|
|
74
|
+
const r = toUfloat(input.getFloat32(i, true), 6);
|
|
75
|
+
const g = toUfloat(input.getFloat32(i + 4, true), 6);
|
|
76
|
+
const b = toUfloat(input.getFloat32(i + 8, true), 5);
|
|
77
|
+
output.setUint32(o, (r | g << 11 | b << 22) >>> 0, true);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
for (let c = 0; c < components; c++) {
|
|
81
|
+
const p = o + c * size;
|
|
82
|
+
if (read.type === GL.UNSIGNED_BYTE) {
|
|
83
|
+
out[p] = src[i + c];
|
|
84
|
+
} else if (read.type === GL.FLOAT) {
|
|
85
|
+
const v = input.getFloat32(i + c * 4, true);
|
|
86
|
+
if (size === 4) output.setFloat32(p, v, true);
|
|
87
|
+
else if (info.depth)
|
|
88
|
+
output.setUint16(p, Math.round(Math.min(1, Math.max(0, v)) * 65535), true);
|
|
89
|
+
else output.setUint16(p, floatToHalf(v), true);
|
|
90
|
+
} else {
|
|
91
|
+
const v = input.getUint32(i + c * 4, true);
|
|
92
|
+
if (size === 4) output.setUint32(p, v, true);
|
|
93
|
+
else if (size === 2) output.setUint16(p, v & 65535, true);
|
|
94
|
+
else out[p] = v & 255;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
floatToHalf,
|
|
102
|
+
readFormatOf,
|
|
103
|
+
repack
|
|
104
|
+
};
|
package/dist/replay.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type CommandStream } from './commands.js';
|
|
2
|
+
import type { Webgl2Device } from './device.js';
|
|
3
|
+
import { Webgl2Texture } from './resources.js';
|
|
4
|
+
export declare class Replayer {
|
|
5
|
+
private readonly device;
|
|
6
|
+
private readonly gl;
|
|
7
|
+
private readonly vao;
|
|
8
|
+
private readonly attachments;
|
|
9
|
+
private readonly single;
|
|
10
|
+
private stream;
|
|
11
|
+
private i;
|
|
12
|
+
private r;
|
|
13
|
+
private passFbo;
|
|
14
|
+
private passWidth;
|
|
15
|
+
private passHeight;
|
|
16
|
+
private colorCount;
|
|
17
|
+
private readonly colors;
|
|
18
|
+
private readonly resolves;
|
|
19
|
+
private readonly colorLayers;
|
|
20
|
+
private readonly colorDiscard;
|
|
21
|
+
private depthView;
|
|
22
|
+
private depthDiscard;
|
|
23
|
+
private stencilDiscard;
|
|
24
|
+
private depthReadOnly;
|
|
25
|
+
private depthCopied;
|
|
26
|
+
private readonly scratchDepth;
|
|
27
|
+
private readonly discards;
|
|
28
|
+
private readonly clearFloat;
|
|
29
|
+
private readonly clearUint;
|
|
30
|
+
private readonly clearInt;
|
|
31
|
+
private pipeline;
|
|
32
|
+
private readonly groups;
|
|
33
|
+
private readonly offsets;
|
|
34
|
+
private bindingsDirty;
|
|
35
|
+
private readonly vertexBuffers;
|
|
36
|
+
private readonly vertexOffsets;
|
|
37
|
+
private attributesDirty;
|
|
38
|
+
private attributePipeline;
|
|
39
|
+
private baseVertex;
|
|
40
|
+
private firstInstance;
|
|
41
|
+
private indexBuffer;
|
|
42
|
+
private indexBytes;
|
|
43
|
+
private indexOffset;
|
|
44
|
+
private stencilReference;
|
|
45
|
+
private readonly attribBuffer;
|
|
46
|
+
private readonly attribOffset;
|
|
47
|
+
private readonly attribStride;
|
|
48
|
+
private readonly attribFormat;
|
|
49
|
+
private readonly attribDivisor;
|
|
50
|
+
private readonly attribEnabled;
|
|
51
|
+
private readonly attribStamp;
|
|
52
|
+
private stamp;
|
|
53
|
+
private element;
|
|
54
|
+
constructor(device: Webgl2Device);
|
|
55
|
+
/** Forgets cached bindings: after a context loss, or when GL state was changed elsewhere. */
|
|
56
|
+
reset(): void;
|
|
57
|
+
/** Drops the depth copies made for `texture`. */
|
|
58
|
+
forget(texture: Webgl2Texture): void;
|
|
59
|
+
run(stream: CommandStream): void;
|
|
60
|
+
private num;
|
|
61
|
+
private ref;
|
|
62
|
+
private clearBindings;
|
|
63
|
+
private beginPass;
|
|
64
|
+
private readonly pending;
|
|
65
|
+
private endPass;
|
|
66
|
+
private draw;
|
|
67
|
+
private drawIndexed;
|
|
68
|
+
/** Binds what the draw needs. Undefined when there's nothing valid to draw with. */
|
|
69
|
+
private prepare;
|
|
70
|
+
/** Uniform blocks and textures from the bound groups. False if a group the pipeline reads is missing. */
|
|
71
|
+
private bind;
|
|
72
|
+
/** A copy of the read-only depth attachment for sampling, refreshed once per pass. */
|
|
73
|
+
private depthCopy;
|
|
74
|
+
/** Points each attribute of `p` at its buffer, moved by the base vertex or first instance. */
|
|
75
|
+
private attributes;
|
|
76
|
+
}
|