@holtjs/stage 0.12.0 → 0.14.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/CHANGELOG.md +20 -0
- package/dist/{anims-BYBzSNXO.d.ts → anims-BOvaKn6w.d.ts} +33 -6
- package/dist/anims.d.ts +1 -1
- package/dist/{display-CuyQc8oE.js → display-CVjvA8ZO.js} +12 -1
- package/dist/ecs.d.ts +3 -3
- package/dist/ecs.js +2 -2
- package/dist/{game-DZoRjZNH.js → game-BF1ZbJRC.js} +131 -53
- package/dist/{game-CT_WCPjJ.d.ts → game-rKghsNlA.d.ts} +33 -15
- package/dist/headless.d.ts +33 -3
- package/dist/headless.js +201 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +28 -20
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-B8vktrUk.js → renderer-webgpu-CnIevdNP.js} +468 -174
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -2
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/world.d.ts +1 -1
- package/package.json +1 -1
|
@@ -3128,11 +3128,11 @@ async function requestWebGpuDevice(canvas, options = {}) {
|
|
|
3128
3128
|
return null;
|
|
3129
3129
|
}
|
|
3130
3130
|
}
|
|
3131
|
-
const
|
|
3132
|
-
const
|
|
3131
|
+
const INITIAL_VERTS = 65536;
|
|
3132
|
+
const INITIAL_INDICES = 98304;
|
|
3133
3133
|
const VERT_FLOATS = 6;
|
|
3134
3134
|
const VERT_STRIDE = 24;
|
|
3135
|
-
const
|
|
3135
|
+
const INITIAL_SDF_PANELS = 16384;
|
|
3136
3136
|
const SDF_FLOATS = 16;
|
|
3137
3137
|
const SDF_STRIDE = 64;
|
|
3138
3138
|
const WGSL_BATCH_SRC = `
|
|
@@ -3405,18 +3405,27 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3405
3405
|
sdfQuadIbo;
|
|
3406
3406
|
samplerLinear;
|
|
3407
3407
|
samplerNearest;
|
|
3408
|
+
samplerLinearRepeat;
|
|
3409
|
+
samplerNearestRepeat;
|
|
3408
3410
|
batchBgl;
|
|
3409
3411
|
sdfBgl;
|
|
3410
3412
|
sdfBindGroup;
|
|
3413
|
+
batchMod;
|
|
3414
|
+
batchLayout;
|
|
3415
|
+
sdfMod;
|
|
3416
|
+
sdfLayout;
|
|
3411
3417
|
batchPipelines = /* @__PURE__ */ new Map();
|
|
3412
3418
|
sdfPipelines = /* @__PURE__ */ new Map();
|
|
3413
3419
|
texCache = /* @__PURE__ */ new WeakMap();
|
|
3414
3420
|
dummyEntry;
|
|
3415
|
-
|
|
3421
|
+
vertCap = INITIAL_VERTS;
|
|
3422
|
+
indexCap = INITIAL_INDICES;
|
|
3423
|
+
vertRaw = new ArrayBuffer(INITIAL_VERTS * VERT_STRIDE);
|
|
3416
3424
|
f32 = new Float32Array(this.vertRaw);
|
|
3417
3425
|
u32 = new Uint32Array(this.vertRaw);
|
|
3418
|
-
indices = new
|
|
3419
|
-
|
|
3426
|
+
indices = new Uint32Array(INITIAL_INDICES);
|
|
3427
|
+
sdfCap = INITIAL_SDF_PANELS;
|
|
3428
|
+
sdfRaw = new ArrayBuffer(INITIAL_SDF_PANELS * SDF_STRIDE);
|
|
3420
3429
|
sdfF32 = new Float32Array(this.sdfRaw);
|
|
3421
3430
|
sdfU32 = new Uint32Array(this.sdfRaw);
|
|
3422
3431
|
vertCount = 0;
|
|
@@ -3424,6 +3433,8 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3424
3433
|
cmdStartIndex = 0;
|
|
3425
3434
|
sdfCount = 0;
|
|
3426
3435
|
sdfCmdStart = 0;
|
|
3436
|
+
curTargetW = 1;
|
|
3437
|
+
curTargetH = 1;
|
|
3427
3438
|
curBlend = BlendModes.NORMAL;
|
|
3428
3439
|
curBindGroup = null;
|
|
3429
3440
|
cmds = [];
|
|
@@ -3515,6 +3526,18 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3515
3526
|
magFilter: "nearest",
|
|
3516
3527
|
minFilter: "nearest"
|
|
3517
3528
|
});
|
|
3529
|
+
this.samplerLinearRepeat = dev.createSampler({
|
|
3530
|
+
magFilter: "linear",
|
|
3531
|
+
minFilter: "linear",
|
|
3532
|
+
addressModeU: "repeat",
|
|
3533
|
+
addressModeV: "repeat"
|
|
3534
|
+
});
|
|
3535
|
+
this.samplerNearestRepeat = dev.createSampler({
|
|
3536
|
+
magFilter: "nearest",
|
|
3537
|
+
minFilter: "nearest",
|
|
3538
|
+
addressModeU: "repeat",
|
|
3539
|
+
addressModeV: "repeat"
|
|
3540
|
+
});
|
|
3518
3541
|
this.batchBgl = dev.createBindGroupLayout({ entries: [
|
|
3519
3542
|
{
|
|
3520
3543
|
binding: 0,
|
|
@@ -3544,101 +3567,18 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3544
3567
|
resource: { buffer: this.globalsBuf }
|
|
3545
3568
|
}]
|
|
3546
3569
|
});
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3570
|
+
this.batchMod = dev.createShaderModule({ code: WGSL_BATCH_SRC });
|
|
3571
|
+
this.batchLayout = dev.createPipelineLayout({ bindGroupLayouts: [this.batchBgl] });
|
|
3572
|
+
this.sdfMod = dev.createShaderModule({ code: WGSL_SDF_SRC });
|
|
3573
|
+
this.sdfLayout = dev.createPipelineLayout({ bindGroupLayouts: [this.sdfBgl] });
|
|
3551
3574
|
for (const mode of [
|
|
3552
3575
|
BlendModes.NORMAL,
|
|
3553
3576
|
BlendModes.ADD,
|
|
3554
3577
|
BlendModes.MULTIPLY,
|
|
3555
3578
|
BlendModes.SCREEN
|
|
3556
3579
|
]) {
|
|
3557
|
-
this.
|
|
3558
|
-
|
|
3559
|
-
vertex: {
|
|
3560
|
-
module: batchMod,
|
|
3561
|
-
entryPoint: "vsMain",
|
|
3562
|
-
buffers: [{
|
|
3563
|
-
arrayStride: VERT_STRIDE,
|
|
3564
|
-
attributes: [
|
|
3565
|
-
{
|
|
3566
|
-
shaderLocation: 0,
|
|
3567
|
-
offset: 0,
|
|
3568
|
-
format: "float32x2"
|
|
3569
|
-
},
|
|
3570
|
-
{
|
|
3571
|
-
shaderLocation: 1,
|
|
3572
|
-
offset: 8,
|
|
3573
|
-
format: "float32x2"
|
|
3574
|
-
},
|
|
3575
|
-
{
|
|
3576
|
-
shaderLocation: 2,
|
|
3577
|
-
offset: 16,
|
|
3578
|
-
format: "uint32"
|
|
3579
|
-
},
|
|
3580
|
-
{
|
|
3581
|
-
shaderLocation: 3,
|
|
3582
|
-
offset: 20,
|
|
3583
|
-
format: "float32"
|
|
3584
|
-
}
|
|
3585
|
-
]
|
|
3586
|
-
}]
|
|
3587
|
-
},
|
|
3588
|
-
fragment: {
|
|
3589
|
-
module: batchMod,
|
|
3590
|
-
entryPoint: "fsMain",
|
|
3591
|
-
targets: [blendTargetState(format, mode)]
|
|
3592
|
-
},
|
|
3593
|
-
primitive: { topology: "triangle-list" }
|
|
3594
|
-
}));
|
|
3595
|
-
this.sdfPipelines.set(mode, dev.createRenderPipeline({
|
|
3596
|
-
layout: sdfLayout,
|
|
3597
|
-
vertex: {
|
|
3598
|
-
module: sdfMod,
|
|
3599
|
-
entryPoint: "vsSdf",
|
|
3600
|
-
buffers: [{
|
|
3601
|
-
arrayStride: 8,
|
|
3602
|
-
stepMode: "vertex",
|
|
3603
|
-
attributes: [{
|
|
3604
|
-
shaderLocation: 0,
|
|
3605
|
-
offset: 0,
|
|
3606
|
-
format: "float32x2"
|
|
3607
|
-
}]
|
|
3608
|
-
}, {
|
|
3609
|
-
arrayStride: SDF_STRIDE,
|
|
3610
|
-
stepMode: "instance",
|
|
3611
|
-
attributes: [
|
|
3612
|
-
{
|
|
3613
|
-
shaderLocation: 1,
|
|
3614
|
-
offset: 0,
|
|
3615
|
-
format: "float32x4"
|
|
3616
|
-
},
|
|
3617
|
-
{
|
|
3618
|
-
shaderLocation: 2,
|
|
3619
|
-
offset: 16,
|
|
3620
|
-
format: "float32x4"
|
|
3621
|
-
},
|
|
3622
|
-
{
|
|
3623
|
-
shaderLocation: 3,
|
|
3624
|
-
offset: 32,
|
|
3625
|
-
format: "float32x4"
|
|
3626
|
-
},
|
|
3627
|
-
{
|
|
3628
|
-
shaderLocation: 4,
|
|
3629
|
-
offset: 48,
|
|
3630
|
-
format: "float32x4"
|
|
3631
|
-
}
|
|
3632
|
-
]
|
|
3633
|
-
}]
|
|
3634
|
-
},
|
|
3635
|
-
fragment: {
|
|
3636
|
-
module: sdfMod,
|
|
3637
|
-
entryPoint: "fsSdf",
|
|
3638
|
-
targets: [blendTargetState(format, mode)]
|
|
3639
|
-
},
|
|
3640
|
-
primitive: { topology: "triangle-list" }
|
|
3641
|
-
}));
|
|
3580
|
+
this.getBatchPipeline(format, mode);
|
|
3581
|
+
this.getSdfPipeline(format, mode);
|
|
3642
3582
|
}
|
|
3643
3583
|
const dummyTex = dev.createTexture({
|
|
3644
3584
|
size: [
|
|
@@ -3673,6 +3613,159 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3673
3613
|
bindGroupNearest: this.makeBatchBindGroup(dummyView, this.samplerNearest)
|
|
3674
3614
|
};
|
|
3675
3615
|
}
|
|
3616
|
+
getBatchPipeline(targetFormat, mode) {
|
|
3617
|
+
const key = `${targetFormat}:${mode}`;
|
|
3618
|
+
let p = this.batchPipelines.get(key);
|
|
3619
|
+
if (p) return p;
|
|
3620
|
+
p = this.device.createRenderPipeline({
|
|
3621
|
+
layout: this.batchLayout,
|
|
3622
|
+
vertex: {
|
|
3623
|
+
module: this.batchMod,
|
|
3624
|
+
entryPoint: "vsMain",
|
|
3625
|
+
buffers: [{
|
|
3626
|
+
arrayStride: VERT_STRIDE,
|
|
3627
|
+
attributes: [
|
|
3628
|
+
{
|
|
3629
|
+
shaderLocation: 0,
|
|
3630
|
+
offset: 0,
|
|
3631
|
+
format: "float32x2"
|
|
3632
|
+
},
|
|
3633
|
+
{
|
|
3634
|
+
shaderLocation: 1,
|
|
3635
|
+
offset: 8,
|
|
3636
|
+
format: "float32x2"
|
|
3637
|
+
},
|
|
3638
|
+
{
|
|
3639
|
+
shaderLocation: 2,
|
|
3640
|
+
offset: 16,
|
|
3641
|
+
format: "uint32"
|
|
3642
|
+
},
|
|
3643
|
+
{
|
|
3644
|
+
shaderLocation: 3,
|
|
3645
|
+
offset: 20,
|
|
3646
|
+
format: "float32"
|
|
3647
|
+
}
|
|
3648
|
+
]
|
|
3649
|
+
}]
|
|
3650
|
+
},
|
|
3651
|
+
fragment: {
|
|
3652
|
+
module: this.batchMod,
|
|
3653
|
+
entryPoint: "fsMain",
|
|
3654
|
+
targets: [blendTargetState(targetFormat, mode)]
|
|
3655
|
+
},
|
|
3656
|
+
primitive: { topology: "triangle-list" }
|
|
3657
|
+
});
|
|
3658
|
+
this.batchPipelines.set(key, p);
|
|
3659
|
+
return p;
|
|
3660
|
+
}
|
|
3661
|
+
getSdfPipeline(targetFormat, mode) {
|
|
3662
|
+
const key = `${targetFormat}:${mode}`;
|
|
3663
|
+
let p = this.sdfPipelines.get(key);
|
|
3664
|
+
if (p) return p;
|
|
3665
|
+
p = this.device.createRenderPipeline({
|
|
3666
|
+
layout: this.sdfLayout,
|
|
3667
|
+
vertex: {
|
|
3668
|
+
module: this.sdfMod,
|
|
3669
|
+
entryPoint: "vsSdf",
|
|
3670
|
+
buffers: [{
|
|
3671
|
+
arrayStride: 8,
|
|
3672
|
+
stepMode: "vertex",
|
|
3673
|
+
attributes: [{
|
|
3674
|
+
shaderLocation: 0,
|
|
3675
|
+
offset: 0,
|
|
3676
|
+
format: "float32x2"
|
|
3677
|
+
}]
|
|
3678
|
+
}, {
|
|
3679
|
+
arrayStride: SDF_STRIDE,
|
|
3680
|
+
stepMode: "instance",
|
|
3681
|
+
attributes: [
|
|
3682
|
+
{
|
|
3683
|
+
shaderLocation: 1,
|
|
3684
|
+
offset: 0,
|
|
3685
|
+
format: "float32x4"
|
|
3686
|
+
},
|
|
3687
|
+
{
|
|
3688
|
+
shaderLocation: 2,
|
|
3689
|
+
offset: 16,
|
|
3690
|
+
format: "float32x4"
|
|
3691
|
+
},
|
|
3692
|
+
{
|
|
3693
|
+
shaderLocation: 3,
|
|
3694
|
+
offset: 32,
|
|
3695
|
+
format: "float32x4"
|
|
3696
|
+
},
|
|
3697
|
+
{
|
|
3698
|
+
shaderLocation: 4,
|
|
3699
|
+
offset: 48,
|
|
3700
|
+
format: "float32x4"
|
|
3701
|
+
}
|
|
3702
|
+
]
|
|
3703
|
+
}]
|
|
3704
|
+
},
|
|
3705
|
+
fragment: {
|
|
3706
|
+
module: this.sdfMod,
|
|
3707
|
+
entryPoint: "fsSdf",
|
|
3708
|
+
targets: [blendTargetState(targetFormat, mode)]
|
|
3709
|
+
},
|
|
3710
|
+
primitive: { topology: "triangle-list" }
|
|
3711
|
+
});
|
|
3712
|
+
this.sdfPipelines.set(key, p);
|
|
3713
|
+
return p;
|
|
3714
|
+
}
|
|
3715
|
+
ensureBatchCapacity(extraVerts, extraIndices) {
|
|
3716
|
+
if (this.vertCount + extraVerts > this.vertCap) {
|
|
3717
|
+
let nextCap = this.vertCap;
|
|
3718
|
+
while (nextCap < this.vertCount + extraVerts) nextCap *= 2;
|
|
3719
|
+
const nextRaw = new ArrayBuffer(nextCap * VERT_STRIDE);
|
|
3720
|
+
const nextF32 = new Float32Array(nextRaw);
|
|
3721
|
+
nextF32.set(this.f32.subarray(0, this.vertCount * VERT_FLOATS));
|
|
3722
|
+
this.vertCap = nextCap;
|
|
3723
|
+
this.vertRaw = nextRaw;
|
|
3724
|
+
this.f32 = nextF32;
|
|
3725
|
+
this.u32 = new Uint32Array(nextRaw);
|
|
3726
|
+
try {
|
|
3727
|
+
this.vbo?.destroy?.();
|
|
3728
|
+
} catch {}
|
|
3729
|
+
this.vbo = this.device.createBuffer({
|
|
3730
|
+
size: nextRaw.byteLength,
|
|
3731
|
+
usage: 40
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
if (this.indexCount + extraIndices > this.indexCap) {
|
|
3735
|
+
let nextCap = this.indexCap;
|
|
3736
|
+
while (nextCap < this.indexCount + extraIndices) nextCap *= 2;
|
|
3737
|
+
const nextInd = new Uint32Array(nextCap);
|
|
3738
|
+
nextInd.set(this.indices.subarray(0, this.indexCount));
|
|
3739
|
+
this.indexCap = nextCap;
|
|
3740
|
+
this.indices = nextInd;
|
|
3741
|
+
try {
|
|
3742
|
+
this.ibo?.destroy?.();
|
|
3743
|
+
} catch {}
|
|
3744
|
+
this.ibo = this.device.createBuffer({
|
|
3745
|
+
size: nextInd.byteLength,
|
|
3746
|
+
usage: 24
|
|
3747
|
+
});
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
ensureSdfCapacity(extraInstances) {
|
|
3751
|
+
if (this.sdfCount + extraInstances <= this.sdfCap) return;
|
|
3752
|
+
let nextCap = this.sdfCap;
|
|
3753
|
+
while (nextCap < this.sdfCount + extraInstances) nextCap *= 2;
|
|
3754
|
+
const nextRaw = new ArrayBuffer(nextCap * SDF_STRIDE);
|
|
3755
|
+
const nextF32 = new Float32Array(nextRaw);
|
|
3756
|
+
nextF32.set(this.sdfF32.subarray(0, this.sdfCount * SDF_FLOATS));
|
|
3757
|
+
this.sdfCap = nextCap;
|
|
3758
|
+
this.sdfRaw = nextRaw;
|
|
3759
|
+
this.sdfF32 = nextF32;
|
|
3760
|
+
this.sdfU32 = new Uint32Array(nextRaw);
|
|
3761
|
+
try {
|
|
3762
|
+
this.sdfInstVbo?.destroy?.();
|
|
3763
|
+
} catch {}
|
|
3764
|
+
this.sdfInstVbo = this.device.createBuffer({
|
|
3765
|
+
size: nextRaw.byteLength,
|
|
3766
|
+
usage: 40
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3676
3769
|
makeBatchBindGroup(view, sampler) {
|
|
3677
3770
|
return this.device.createBindGroup({
|
|
3678
3771
|
layout: this.batchBgl,
|
|
@@ -3836,10 +3929,19 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3836
3929
|
if (dirty && entry && !isRenderTarget) this.extractAndUploadTexture(entry.tex, image, w, h, premultiply);
|
|
3837
3930
|
return nearest ? entry.bindGroupNearest : entry.bindGroupLinear;
|
|
3838
3931
|
}
|
|
3839
|
-
ensureSourceBindGroup(src) {
|
|
3840
|
-
const
|
|
3932
|
+
ensureSourceBindGroup(src, repeat = false) {
|
|
3933
|
+
const nearest = src.filterMode === FilterMode.NEAREST;
|
|
3934
|
+
const bg = this.ensureGpuTexture(src, src.image, src.width, src.height, nearest, src.dirty, src.premultiplyAlpha, src.isRenderTarget);
|
|
3841
3935
|
src.dirty = false;
|
|
3842
|
-
return bg;
|
|
3936
|
+
if (!repeat || !bg) return bg;
|
|
3937
|
+
const entry = this.texCache.get(src);
|
|
3938
|
+
if (!entry) return bg;
|
|
3939
|
+
if (nearest) {
|
|
3940
|
+
if (!entry.bindGroupNearestRepeat) entry.bindGroupNearestRepeat = this.makeBatchBindGroup(entry.view, this.samplerNearestRepeat);
|
|
3941
|
+
return entry.bindGroupNearestRepeat;
|
|
3942
|
+
}
|
|
3943
|
+
if (!entry.bindGroupLinearRepeat) entry.bindGroupLinearRepeat = this.makeBatchBindGroup(entry.view, this.samplerLinearRepeat);
|
|
3944
|
+
return entry.bindGroupLinearRepeat;
|
|
3843
3945
|
}
|
|
3844
3946
|
currentScissor() {
|
|
3845
3947
|
return this.scissorStack.length > 0 ? { ...this.scissorStack[this.scissorStack.length - 1] } : null;
|
|
@@ -3880,36 +3982,45 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3880
3982
|
this.curBindGroup = bindGroup;
|
|
3881
3983
|
}
|
|
3882
3984
|
pushQuad(m, x0, y0, x1, y1, u0, v0, u1, v1, abgr, mode, blend, bindGroup) {
|
|
3883
|
-
|
|
3985
|
+
const a = m.a, b = m.b, c = m.c, d = m.d, tx = m.tx, ty = m.ty;
|
|
3986
|
+
const sx0 = a * x0 + c * y0 + tx, sy0 = b * x0 + d * y0 + ty;
|
|
3987
|
+
const sx1 = a * x1 + c * y0 + tx, sy1 = b * x1 + d * y0 + ty;
|
|
3988
|
+
const sx2 = a * x1 + c * y1 + tx, sy2 = b * x1 + d * y1 + ty;
|
|
3989
|
+
const sx3 = a * x0 + c * y1 + tx, sy3 = b * x0 + d * y1 + ty;
|
|
3990
|
+
const tw = this.curTargetW, th = this.curTargetH;
|
|
3991
|
+
if (sx0 < 0 && sx1 < 0 && sx2 < 0 && sx3 < 0 || sx0 > tw && sx1 > tw && sx2 > tw && sx3 > tw || sy0 < 0 && sy1 < 0 && sy2 < 0 && sy3 < 0 || sy0 > th && sy1 > th && sy2 > th && sy3 > th) {
|
|
3992
|
+
this.lastStats.culled++;
|
|
3993
|
+
return;
|
|
3994
|
+
}
|
|
3995
|
+
this.ensureBatchCapacity(4, 6);
|
|
3884
3996
|
this.bindBatch(blend, bindGroup);
|
|
3885
3997
|
const bv = this.vertCount;
|
|
3886
3998
|
let fi = bv * VERT_FLOATS;
|
|
3887
3999
|
const f32 = this.f32;
|
|
3888
4000
|
const u32 = this.u32;
|
|
3889
|
-
|
|
3890
|
-
f32[fi
|
|
3891
|
-
f32[fi + 1] = b * x0 + d * y0 + ty;
|
|
4001
|
+
f32[fi] = sx0;
|
|
4002
|
+
f32[fi + 1] = sy0;
|
|
3892
4003
|
f32[fi + 2] = u0;
|
|
3893
4004
|
f32[fi + 3] = v0;
|
|
3894
4005
|
u32[fi + 4] = abgr;
|
|
3895
4006
|
f32[fi + 5] = mode;
|
|
3896
4007
|
fi += VERT_FLOATS;
|
|
3897
|
-
f32[fi] =
|
|
3898
|
-
f32[fi + 1] =
|
|
4008
|
+
f32[fi] = sx1;
|
|
4009
|
+
f32[fi + 1] = sy1;
|
|
3899
4010
|
f32[fi + 2] = u1;
|
|
3900
4011
|
f32[fi + 3] = v0;
|
|
3901
4012
|
u32[fi + 4] = abgr;
|
|
3902
4013
|
f32[fi + 5] = mode;
|
|
3903
4014
|
fi += VERT_FLOATS;
|
|
3904
|
-
f32[fi] =
|
|
3905
|
-
f32[fi + 1] =
|
|
4015
|
+
f32[fi] = sx2;
|
|
4016
|
+
f32[fi + 1] = sy2;
|
|
3906
4017
|
f32[fi + 2] = u1;
|
|
3907
4018
|
f32[fi + 3] = v1;
|
|
3908
4019
|
u32[fi + 4] = abgr;
|
|
3909
4020
|
f32[fi + 5] = mode;
|
|
3910
4021
|
fi += VERT_FLOATS;
|
|
3911
|
-
f32[fi] =
|
|
3912
|
-
f32[fi + 1] =
|
|
4022
|
+
f32[fi] = sx3;
|
|
4023
|
+
f32[fi + 1] = sy3;
|
|
3913
4024
|
f32[fi + 2] = u0;
|
|
3914
4025
|
f32[fi + 3] = v1;
|
|
3915
4026
|
u32[fi + 4] = abgr;
|
|
@@ -3926,29 +4037,37 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3926
4037
|
this.indexCount = ii + 6;
|
|
3927
4038
|
}
|
|
3928
4039
|
pushTri(m, x0, y0, x1, y1, x2, y2, abgr, blend) {
|
|
3929
|
-
|
|
4040
|
+
const a = m.a, b = m.b, c = m.c, d = m.d, tx = m.tx, ty = m.ty;
|
|
4041
|
+
const sx0 = a * x0 + c * y0 + tx, sy0 = b * x0 + d * y0 + ty;
|
|
4042
|
+
const sx1 = a * x1 + c * y1 + tx, sy1 = b * x1 + d * y1 + ty;
|
|
4043
|
+
const sx2 = a * x2 + c * y2 + tx, sy2 = b * x2 + d * y2 + ty;
|
|
4044
|
+
const tw = this.curTargetW, th = this.curTargetH;
|
|
4045
|
+
if (sx0 < 0 && sx1 < 0 && sx2 < 0 || sx0 > tw && sx1 > tw && sx2 > tw || sy0 < 0 && sy1 < 0 && sy2 < 0 || sy0 > th && sy1 > th && sy2 > th) {
|
|
4046
|
+
this.lastStats.culled++;
|
|
4047
|
+
return;
|
|
4048
|
+
}
|
|
4049
|
+
this.ensureBatchCapacity(3, 3);
|
|
3930
4050
|
this.bindBatch(blend, this.dummyEntry.bindGroupLinear);
|
|
3931
4051
|
const bv = this.vertCount;
|
|
3932
4052
|
let fi = bv * VERT_FLOATS;
|
|
3933
4053
|
const f32 = this.f32;
|
|
3934
4054
|
const u32 = this.u32;
|
|
3935
|
-
|
|
3936
|
-
f32[fi
|
|
3937
|
-
f32[fi + 1] = b * x0 + d * y0 + ty;
|
|
4055
|
+
f32[fi] = sx0;
|
|
4056
|
+
f32[fi + 1] = sy0;
|
|
3938
4057
|
f32[fi + 2] = 0;
|
|
3939
4058
|
f32[fi + 3] = 0;
|
|
3940
4059
|
u32[fi + 4] = abgr;
|
|
3941
4060
|
f32[fi + 5] = 2;
|
|
3942
4061
|
fi += VERT_FLOATS;
|
|
3943
|
-
f32[fi] =
|
|
3944
|
-
f32[fi + 1] =
|
|
4062
|
+
f32[fi] = sx1;
|
|
4063
|
+
f32[fi + 1] = sy1;
|
|
3945
4064
|
f32[fi + 2] = 0;
|
|
3946
4065
|
f32[fi + 3] = 0;
|
|
3947
4066
|
u32[fi + 4] = abgr;
|
|
3948
4067
|
f32[fi + 5] = 2;
|
|
3949
4068
|
fi += VERT_FLOATS;
|
|
3950
|
-
f32[fi] =
|
|
3951
|
-
f32[fi + 1] =
|
|
4069
|
+
f32[fi] = sx2;
|
|
4070
|
+
f32[fi + 1] = sy2;
|
|
3952
4071
|
f32[fi + 2] = 0;
|
|
3953
4072
|
f32[fi + 3] = 0;
|
|
3954
4073
|
u32[fi + 4] = abgr;
|
|
@@ -3961,12 +4080,21 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3961
4080
|
this.indexCount = ii + 3;
|
|
3962
4081
|
}
|
|
3963
4082
|
pushSdfInstance(m, rx, ry, w, h, rTL, rTR, rBR, rBL, borderW, pixelStep, fillAbgr, borderAbgr, blend) {
|
|
3964
|
-
if (
|
|
4083
|
+
if (w <= 0 || h <= 0) return;
|
|
4084
|
+
const tx = m.a * rx + m.c * ry + m.tx;
|
|
4085
|
+
const ty = m.b * rx + m.d * ry + m.ty;
|
|
4086
|
+
const sx1 = tx + m.a * w, sy1 = ty + m.b * w;
|
|
4087
|
+
const sx2 = sx1 + m.c * h, sy2 = sy1 + m.d * h;
|
|
4088
|
+
const sx3 = tx + m.c * h, sy3 = ty + m.d * h;
|
|
4089
|
+
const tw = this.curTargetW, th = this.curTargetH;
|
|
4090
|
+
if (tx < 0 && sx1 < 0 && sx2 < 0 && sx3 < 0 || tx > tw && sx1 > tw && sx2 > tw && sx3 > tw || ty < 0 && sy1 < 0 && sy2 < 0 && sy3 < 0 || ty > th && sy1 > th && sy2 > th && sy3 > th) {
|
|
4091
|
+
this.lastStats.culled++;
|
|
4092
|
+
return;
|
|
4093
|
+
}
|
|
4094
|
+
this.ensureSdfCapacity(1);
|
|
3965
4095
|
if (this.indexCount > this.cmdStartIndex) this.flushPendingBatch();
|
|
3966
4096
|
if (this.curBlend !== blend && this.sdfCount > this.sdfCmdStart) this.flushPendingSdf();
|
|
3967
4097
|
this.curBlend = blend;
|
|
3968
|
-
const tx = m.a * rx + m.c * ry + m.tx;
|
|
3969
|
-
const ty = m.b * rx + m.d * ry + m.ty;
|
|
3970
4098
|
const maxR = Math.min(w, h) * .5;
|
|
3971
4099
|
const base = this.sdfCount * SDF_FLOATS;
|
|
3972
4100
|
const f = this.sdfF32;
|
|
@@ -4230,27 +4358,86 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4230
4358
|
const txt = obj;
|
|
4231
4359
|
const cv = txt.ensureCanvas();
|
|
4232
4360
|
if (!cv || cv.width <= 0 || cv.height <= 0) break;
|
|
4233
|
-
const
|
|
4234
|
-
const curRev = txt.canvasDirty ? -2 : txt._wgpuSeq ?? 0;
|
|
4235
|
-
const dirty = prevRev !== curRev || txt.glDirty;
|
|
4361
|
+
const dirty = Boolean(txt.glDirty);
|
|
4236
4362
|
const bg = this.ensureGpuTexture(txt, cv, cv.width, cv.height, false, dirty);
|
|
4237
4363
|
txt.glDirty = false;
|
|
4238
|
-
txt._wgpuRev = curRev;
|
|
4239
4364
|
if (!bg) break;
|
|
4240
4365
|
const ox = txt.displayOriginX, oy = txt.displayOriginY;
|
|
4241
4366
|
const rgb = txt.isTinted ? txt.tint : WHITE_RGB;
|
|
4242
|
-
|
|
4367
|
+
if (txt.isCropped && txt.width > 0 && txt.height > 0) {
|
|
4368
|
+
const cx0 = Math.max(0, Math.min(txt.width, txt.cropX));
|
|
4369
|
+
const cy0 = Math.max(0, Math.min(txt.height, txt.cropY));
|
|
4370
|
+
const cx1 = Math.max(cx0, Math.min(txt.width, txt.cropX + txt.cropW));
|
|
4371
|
+
const cy1 = Math.max(cy0, Math.min(txt.height, txt.cropY + txt.cropH));
|
|
4372
|
+
if (cx1 > cx0 && cy1 > cy0) this.pushQuad(m, cx0 - ox, cy0 - oy, cx1 - ox, cy1 - oy, cx0 / txt.width, cy0 / txt.height, cx1 / txt.width, cy1 / txt.height, packColorAbgr(rgb, effAlpha), 0, txt.blendMode, bg);
|
|
4373
|
+
} else this.pushQuad(m, -ox, -oy, txt.width - ox, txt.height - oy, 0, 0, 1, 1, packColorAbgr(rgb, effAlpha), 0, txt.blendMode, bg);
|
|
4243
4374
|
break;
|
|
4244
4375
|
}
|
|
4245
|
-
case "NineSlice":
|
|
4246
|
-
case "TileSprite": {
|
|
4376
|
+
case "NineSlice": {
|
|
4247
4377
|
const ns = obj;
|
|
4248
4378
|
const fr = ns.frame;
|
|
4249
|
-
if (!fr) break;
|
|
4379
|
+
if (!fr || ns.width <= 0 || ns.height <= 0) break;
|
|
4250
4380
|
const bg = this.ensureSourceBindGroup(fr.source);
|
|
4251
4381
|
if (!bg) break;
|
|
4252
4382
|
const ox = ns.displayOriginX, oy = ns.displayOriginY;
|
|
4253
|
-
|
|
4383
|
+
const abgr = packColorAbgr(ns.isTinted ? ns.tint : WHITE_RGB, effAlpha);
|
|
4384
|
+
const sw = fr.cutWidth, sh = fr.cutHeight;
|
|
4385
|
+
const lw = Math.min(ns.leftWidth, ns.width * .5, sw);
|
|
4386
|
+
const rw = Math.min(ns.rightWidth, ns.width * .5, sw - lw);
|
|
4387
|
+
const th = Math.min(ns.topHeight, ns.height * .5, sh);
|
|
4388
|
+
const bh = Math.min(ns.bottomHeight, ns.height * .5, sh - th);
|
|
4389
|
+
const xs = [
|
|
4390
|
+
-ox,
|
|
4391
|
+
lw - ox,
|
|
4392
|
+
ns.width - rw - ox,
|
|
4393
|
+
ns.width - ox
|
|
4394
|
+
];
|
|
4395
|
+
const ys = [
|
|
4396
|
+
-oy,
|
|
4397
|
+
th - oy,
|
|
4398
|
+
ns.height - bh - oy,
|
|
4399
|
+
ns.height - oy
|
|
4400
|
+
];
|
|
4401
|
+
const du = fr.u1 - fr.u0, dv = fr.v1 - fr.v0;
|
|
4402
|
+
const us = [
|
|
4403
|
+
fr.u0,
|
|
4404
|
+
fr.u0 + lw / sw * du,
|
|
4405
|
+
fr.u1 - rw / sw * du,
|
|
4406
|
+
fr.u1
|
|
4407
|
+
];
|
|
4408
|
+
const vs = [
|
|
4409
|
+
fr.v0,
|
|
4410
|
+
fr.v0 + th / sh * dv,
|
|
4411
|
+
fr.v1 - bh / sh * dv,
|
|
4412
|
+
fr.v1
|
|
4413
|
+
];
|
|
4414
|
+
for (let ry = 0; ry < 3; ry++) {
|
|
4415
|
+
if (ys[ry + 1] <= ys[ry]) continue;
|
|
4416
|
+
for (let rx = 0; rx < 3; rx++) {
|
|
4417
|
+
if (xs[rx + 1] <= xs[rx]) continue;
|
|
4418
|
+
this.pushQuad(m, xs[rx], ys[ry], xs[rx + 1], ys[ry + 1], us[rx], vs[ry], us[rx + 1], vs[ry + 1], abgr, 0, ns.blendMode, bg);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
break;
|
|
4422
|
+
}
|
|
4423
|
+
case "TileSprite": {
|
|
4424
|
+
const ts = obj;
|
|
4425
|
+
const fr = ts.frame;
|
|
4426
|
+
if (!fr || ts.width <= 0 || ts.height <= 0) break;
|
|
4427
|
+
const isFullTex = fr.cutX === 0 && fr.cutY === 0 && fr.cutWidth === fr.source.width && fr.cutHeight === fr.source.height;
|
|
4428
|
+
const bg = this.ensureSourceBindGroup(fr.source, isFullTex);
|
|
4429
|
+
if (!bg) break;
|
|
4430
|
+
const ox = ts.displayOriginX, oy = ts.displayOriginY;
|
|
4431
|
+
const abgr = packColorAbgr(ts.isTinted ? ts.tint : WHITE_RGB, effAlpha);
|
|
4432
|
+
if (isFullTex) {
|
|
4433
|
+
const sx = Math.max(1e-4, ts.tileScaleX);
|
|
4434
|
+
const sy = Math.max(1e-4, ts.tileScaleY);
|
|
4435
|
+
const u0 = ts.tilePositionX / fr.width;
|
|
4436
|
+
const v0 = ts.tilePositionY / fr.height;
|
|
4437
|
+
const u1 = u0 + ts.width / (fr.width * sx);
|
|
4438
|
+
const v1 = v0 + ts.height / (fr.height * sy);
|
|
4439
|
+
this.pushQuad(m, -ox, -oy, ts.width - ox, ts.height - oy, u0, v0, u1, v1, abgr, 0, ts.blendMode, bg);
|
|
4440
|
+
} else this.pushQuad(m, -ox, -oy, ts.width - ox, ts.height - oy, fr.u0, fr.v0, fr.u1, fr.v1, abgr, 0, ts.blendMode, bg);
|
|
4254
4441
|
break;
|
|
4255
4442
|
}
|
|
4256
4443
|
case "Graphics":
|
|
@@ -4272,18 +4459,21 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4272
4459
|
case "InstancedBatch": {
|
|
4273
4460
|
const batch = obj;
|
|
4274
4461
|
const cols = batch.columns;
|
|
4275
|
-
if (!cols || cols.count <= 0) break;
|
|
4276
|
-
const src = batch.texture?.source?.[0];
|
|
4277
|
-
if (!src) break;
|
|
4278
|
-
const bg = this.ensureSourceBindGroup(src);
|
|
4279
|
-
if (!bg) break;
|
|
4462
|
+
if (!cols || cols.count <= 0 || !batch.texture) break;
|
|
4280
4463
|
const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
|
|
4464
|
+
let lastSrc = null;
|
|
4465
|
+
let lastBg = null;
|
|
4281
4466
|
for (let i = 0; i < n; i++) {
|
|
4282
4467
|
const s = cols.order ? cols.order[i] : i;
|
|
4283
4468
|
const a = effAlpha * (cols.alpha ? cols.alpha[s] : 1);
|
|
4284
4469
|
if (a <= 0) continue;
|
|
4285
4470
|
const fr = cols.frameIndex ? batch.texture.get(cols.frameIndex[s]) : batch.defaultFrame;
|
|
4286
4471
|
if (!fr || fr.empty || fr.width <= 0 || fr.height <= 0) continue;
|
|
4472
|
+
if (fr.source !== lastSrc) {
|
|
4473
|
+
lastSrc = fr.source;
|
|
4474
|
+
lastBg = this.ensureSourceBindGroup(lastSrc);
|
|
4475
|
+
}
|
|
4476
|
+
if (!lastBg) continue;
|
|
4287
4477
|
const sx = cols.scaleX ? cols.scaleX[s] : 1;
|
|
4288
4478
|
const sy = cols.scaleY ? cols.scaleY[s] : sx;
|
|
4289
4479
|
const rot = cols.rotation ? cols.rotation[s] : 0;
|
|
@@ -4291,7 +4481,7 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4291
4481
|
multiplyMat(m, cols.x[s], cols.y[s], sx, sy, rot, im);
|
|
4292
4482
|
const ox = fr.width * batch.originX, oy = fr.height * batch.originY;
|
|
4293
4483
|
const rgb = cols.tint ? cols.tint[s] : WHITE_RGB;
|
|
4294
|
-
this.pushQuad(im, -ox, -oy, fr.width - ox, fr.height - oy, fr.u0, fr.v0, fr.u1, fr.v1, packColorAbgr(rgb, a), 0, batch.blendMode,
|
|
4484
|
+
this.pushQuad(im, -ox, -oy, fr.width - ox, fr.height - oy, fr.u0, fr.v0, fr.u1, fr.v1, packColorAbgr(rgb, a), 0, batch.blendMode, lastBg);
|
|
4295
4485
|
}
|
|
4296
4486
|
break;
|
|
4297
4487
|
}
|
|
@@ -4356,8 +4546,8 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4356
4546
|
const sy1 = cm.b * wx1 + cm.d * wy1 + cm.ty;
|
|
4357
4547
|
const l = Math.max(0, Math.floor(Math.min(sx0, sx1)));
|
|
4358
4548
|
const t = Math.max(0, Math.floor(Math.min(sy0, sy1)));
|
|
4359
|
-
const r = Math.min(this.
|
|
4360
|
-
const b = Math.min(this.
|
|
4549
|
+
const r = Math.min(this.curTargetW, Math.ceil(Math.max(sx0, sx1)));
|
|
4550
|
+
const b = Math.min(this.curTargetH, Math.ceil(Math.max(sy0, sy1)));
|
|
4361
4551
|
this.scissorStack.push({
|
|
4362
4552
|
x: l,
|
|
4363
4553
|
y: t,
|
|
@@ -4382,31 +4572,53 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4382
4572
|
}
|
|
4383
4573
|
}
|
|
4384
4574
|
}
|
|
4385
|
-
|
|
4575
|
+
executePass(targetView, targetFormat, targetW, targetH, displayList, camera, recordMainStats) {
|
|
4576
|
+
const savedState = this.cmds.length > 0 || this.vertCount > 0 || this.sdfCount > 0 ? {
|
|
4577
|
+
vertCount: this.vertCount,
|
|
4578
|
+
indexCount: this.indexCount,
|
|
4579
|
+
cmdStartIndex: this.cmdStartIndex,
|
|
4580
|
+
sdfCount: this.sdfCount,
|
|
4581
|
+
sdfCmdStart: this.sdfCmdStart,
|
|
4582
|
+
curTargetW: this.curTargetW,
|
|
4583
|
+
curTargetH: this.curTargetH,
|
|
4584
|
+
curBlend: this.curBlend,
|
|
4585
|
+
curBindGroup: this.curBindGroup,
|
|
4586
|
+
cmds: this.cmds,
|
|
4587
|
+
scissorStack: this.scissorStack,
|
|
4588
|
+
vertSnap: this.vertCount > 0 ? this.f32.slice(0, this.vertCount * VERT_FLOATS) : null,
|
|
4589
|
+
idxSnap: this.indexCount > 0 ? this.indices.slice(0, this.indexCount) : null,
|
|
4590
|
+
sdfSnap: this.sdfCount > 0 ? this.sdfF32.slice(0, this.sdfCount * SDF_FLOATS) : null
|
|
4591
|
+
} : null;
|
|
4592
|
+
if (savedState) {
|
|
4593
|
+
this.cmds = [];
|
|
4594
|
+
this.scissorStack = [];
|
|
4595
|
+
}
|
|
4386
4596
|
camera.syncMetrics();
|
|
4387
4597
|
this.vertCount = 0;
|
|
4388
4598
|
this.indexCount = 0;
|
|
4389
4599
|
this.cmdStartIndex = 0;
|
|
4390
4600
|
this.sdfCount = 0;
|
|
4391
4601
|
this.sdfCmdStart = 0;
|
|
4602
|
+
this.curTargetW = targetW;
|
|
4603
|
+
this.curTargetH = targetH;
|
|
4392
4604
|
this.cmds.length = 0;
|
|
4393
4605
|
this.scissorStack.length = 0;
|
|
4394
4606
|
this.curBlend = BlendModes.NORMAL;
|
|
4395
4607
|
this.curBindGroup = null;
|
|
4608
|
+
if (recordMainStats) this.lastStats.culled = 0;
|
|
4396
4609
|
const list = displayList.sorted();
|
|
4397
4610
|
const camAlpha = camera.alpha;
|
|
4398
4611
|
for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, null, camAlpha, 0);
|
|
4399
4612
|
this.flushAllPending();
|
|
4400
4613
|
this.device.queue.writeBuffer(this.globalsBuf, 0, new Float32Array([
|
|
4401
|
-
|
|
4402
|
-
|
|
4614
|
+
targetW,
|
|
4615
|
+
targetH,
|
|
4403
4616
|
0,
|
|
4404
4617
|
0
|
|
4405
4618
|
]));
|
|
4406
4619
|
if (this.vertCount > 0) {
|
|
4407
4620
|
this.device.queue.writeBuffer(this.vbo, 0, this.f32.subarray(0, this.vertCount * VERT_FLOATS));
|
|
4408
|
-
|
|
4409
|
-
this.device.queue.writeBuffer(this.ibo, 0, this.indices.subarray(0, idxWriteCount));
|
|
4621
|
+
this.device.queue.writeBuffer(this.ibo, 0, this.indices.subarray(0, this.indexCount));
|
|
4410
4622
|
}
|
|
4411
4623
|
if (this.sdfCount > 0) this.device.queue.writeBuffer(this.sdfInstVbo, 0, this.sdfF32.subarray(0, this.sdfCount * SDF_FLOATS));
|
|
4412
4624
|
const bg = camera.backgroundColor;
|
|
@@ -4421,10 +4633,9 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4421
4633
|
b: bg.b * bg.a,
|
|
4422
4634
|
a: bg.a
|
|
4423
4635
|
};
|
|
4424
|
-
const view = this.gpuContext ? this.gpuContext.getCurrentTexture().createView() : this.ensureOffscreenTarget();
|
|
4425
4636
|
const encoder = this.device.createCommandEncoder();
|
|
4426
4637
|
const pass = encoder.beginRenderPass({ colorAttachments: [{
|
|
4427
|
-
view,
|
|
4638
|
+
view: targetView,
|
|
4428
4639
|
clearValue: clearColor,
|
|
4429
4640
|
loadOp: "clear",
|
|
4430
4641
|
storeOp: "store"
|
|
@@ -4435,16 +4646,16 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4435
4646
|
if (cmd.scissor) {
|
|
4436
4647
|
if (cmd.scissor.w <= 0 || cmd.scissor.h <= 0) continue;
|
|
4437
4648
|
pass.setScissorRect(cmd.scissor.x, cmd.scissor.y, cmd.scissor.w, cmd.scissor.h);
|
|
4438
|
-
} else pass.setScissorRect(0, 0,
|
|
4649
|
+
} else pass.setScissorRect(0, 0, targetW, targetH);
|
|
4439
4650
|
if (cmd.kind === "batch") {
|
|
4440
|
-
pass.setPipeline(this.
|
|
4651
|
+
pass.setPipeline(this.getBatchPipeline(targetFormat, cmd.blend));
|
|
4441
4652
|
pass.setBindGroup(0, cmd.bindGroup);
|
|
4442
4653
|
pass.setVertexBuffer(0, this.vbo);
|
|
4443
|
-
pass.setIndexBuffer(this.ibo, "
|
|
4654
|
+
pass.setIndexBuffer(this.ibo, "uint32");
|
|
4444
4655
|
pass.drawIndexed(cmd.indexCount, 1, cmd.firstIndex, 0, 0);
|
|
4445
4656
|
} else {
|
|
4446
4657
|
sdfDraws++;
|
|
4447
|
-
pass.setPipeline(this.
|
|
4658
|
+
pass.setPipeline(this.getSdfPipeline(targetFormat, cmd.blend));
|
|
4448
4659
|
pass.setBindGroup(0, this.sdfBindGroup);
|
|
4449
4660
|
pass.setVertexBuffer(0, this.sdfCornerVbo);
|
|
4450
4661
|
pass.setVertexBuffer(1, this.sdfInstVbo);
|
|
@@ -4454,12 +4665,36 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4454
4665
|
}
|
|
4455
4666
|
pass.end();
|
|
4456
4667
|
this.device.queue.submit([encoder.finish()]);
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4668
|
+
if (recordMainStats) {
|
|
4669
|
+
this.lastStats.drawCalls = this.cmds.length;
|
|
4670
|
+
this.lastStats.flushes = this.cmds.length;
|
|
4671
|
+
this.lastStats.tris = (this.indexCount / 3 | 0) + this.sdfCount * 2;
|
|
4672
|
+
this.lastStats.quads = (this.vertCount >> 2) + this.sdfCount;
|
|
4673
|
+
this.lastStats.sdfPanels = this.sdfCount;
|
|
4674
|
+
this.lastStats.sdfDraws = sdfDraws;
|
|
4675
|
+
}
|
|
4676
|
+
if (savedState) {
|
|
4677
|
+
this.ensureBatchCapacity(savedState.vertCount, savedState.indexCount);
|
|
4678
|
+
this.ensureSdfCapacity(savedState.sdfCount);
|
|
4679
|
+
if (savedState.vertSnap) this.f32.set(savedState.vertSnap, 0);
|
|
4680
|
+
if (savedState.idxSnap) this.indices.set(savedState.idxSnap, 0);
|
|
4681
|
+
if (savedState.sdfSnap) this.sdfF32.set(savedState.sdfSnap, 0);
|
|
4682
|
+
this.vertCount = savedState.vertCount;
|
|
4683
|
+
this.indexCount = savedState.indexCount;
|
|
4684
|
+
this.cmdStartIndex = savedState.cmdStartIndex;
|
|
4685
|
+
this.sdfCount = savedState.sdfCount;
|
|
4686
|
+
this.sdfCmdStart = savedState.sdfCmdStart;
|
|
4687
|
+
this.curTargetW = savedState.curTargetW;
|
|
4688
|
+
this.curTargetH = savedState.curTargetH;
|
|
4689
|
+
this.curBlend = savedState.curBlend;
|
|
4690
|
+
this.curBindGroup = savedState.curBindGroup;
|
|
4691
|
+
this.cmds = savedState.cmds;
|
|
4692
|
+
this.scissorStack = savedState.scissorStack;
|
|
4693
|
+
}
|
|
4694
|
+
}
|
|
4695
|
+
render(displayList, camera) {
|
|
4696
|
+
const view = this.gpuContext ? this.gpuContext.getCurrentTexture().createView() : this.ensureOffscreenTarget();
|
|
4697
|
+
this.executePass(view, this.format, this.width, this.height, displayList, camera, true);
|
|
4463
4698
|
}
|
|
4464
4699
|
encodeCopyToStaging() {
|
|
4465
4700
|
if (!this.offscreenTex) this.ensureOffscreenTarget();
|
|
@@ -4552,50 +4787,109 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4552
4787
|
buf.unmap();
|
|
4553
4788
|
}
|
|
4554
4789
|
}
|
|
4555
|
-
/** Create an offscreen render target backed by a registered Stage `Texture` (`key`) for WebGPU passes (e.g. `Lighting2DSystem`). */
|
|
4790
|
+
/** Create an offscreen GPU render target backed by a registered Stage `Texture` (`key`) for WebGPU passes (e.g. `Lighting2DSystem`). */
|
|
4556
4791
|
createRenderTarget(key, width, height, textures, filterMode = FilterMode.LINEAR) {
|
|
4557
4792
|
const w = Math.max(1, Math.round(width));
|
|
4558
4793
|
const h = Math.max(1, Math.round(height));
|
|
4559
|
-
const
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4794
|
+
const tex = textures.addImage(key, {
|
|
4795
|
+
width: w,
|
|
4796
|
+
height: h
|
|
4797
|
+
}, {
|
|
4798
|
+
filterMode,
|
|
4799
|
+
isRenderTarget: true
|
|
4800
|
+
});
|
|
4565
4801
|
if (!tex) throw new Error("Stage: failed to register WebGPU RenderTarget texture");
|
|
4566
|
-
tex.source[0]
|
|
4802
|
+
const src = tex.source[0];
|
|
4803
|
+
this.ensureSourceBindGroup(src);
|
|
4804
|
+
const gpuEntry = this.texCache.get(src);
|
|
4567
4805
|
const rtCamera = new Camera(w, h, true);
|
|
4568
|
-
|
|
4806
|
+
let lazy2D = null;
|
|
4807
|
+
let lazyCanvas = null;
|
|
4808
|
+
let lastUsed2D = false;
|
|
4569
4809
|
return {
|
|
4570
4810
|
key,
|
|
4571
4811
|
width: w,
|
|
4572
4812
|
height: h,
|
|
4573
4813
|
texture: tex,
|
|
4574
4814
|
camera: rtCamera,
|
|
4575
|
-
|
|
4815
|
+
_gpuEntry: gpuEntry,
|
|
4816
|
+
_markGpuRendered: () => {
|
|
4817
|
+
lastUsed2D = false;
|
|
4818
|
+
},
|
|
4819
|
+
_render2DCallback: (cb, cam) => {
|
|
4820
|
+
if (!lazy2D || !lazyCanvas) {
|
|
4821
|
+
const doc = this.canvas?.ownerDocument ?? (typeof document !== "undefined" ? document : void 0);
|
|
4822
|
+
if (!doc) throw new Error("Stage: ownerDocument unavailable for 2D callback RenderTarget");
|
|
4823
|
+
lazyCanvas = doc.createElement("canvas");
|
|
4824
|
+
lazyCanvas.width = w;
|
|
4825
|
+
lazyCanvas.height = h;
|
|
4826
|
+
lazy2D = new Renderer2D(lazyCanvas, w, h);
|
|
4827
|
+
}
|
|
4828
|
+
cam.syncMetrics();
|
|
4829
|
+
cb(lazy2D, cam);
|
|
4830
|
+
this.extractAndUploadTexture(gpuEntry.tex, lazyCanvas, w, h, true);
|
|
4831
|
+
lastUsed2D = true;
|
|
4832
|
+
},
|
|
4576
4833
|
readPixels: (out) => {
|
|
4577
4834
|
const byteLen = w * h * 4;
|
|
4578
4835
|
const dst = out && out.length >= byteLen ? out : new Uint8Array(byteLen);
|
|
4579
|
-
|
|
4580
|
-
|
|
4836
|
+
if (lastUsed2D && lazy2D) {
|
|
4837
|
+
const img = lazy2D.ctx.getImageData(0, 0, w, h);
|
|
4838
|
+
dst.set(img.data.subarray(0, byteLen));
|
|
4839
|
+
return dst;
|
|
4840
|
+
}
|
|
4841
|
+
if (typeof this.device._readBufferSync === "function") {
|
|
4842
|
+
const bytesPerRow = w * 4 + 255 & -256;
|
|
4843
|
+
const totalBuf = bytesPerRow * h;
|
|
4844
|
+
const tmpBuf = this.device.createBuffer({
|
|
4845
|
+
size: totalBuf,
|
|
4846
|
+
usage: 9
|
|
4847
|
+
});
|
|
4848
|
+
const enc = this.device.createCommandEncoder();
|
|
4849
|
+
enc.copyTextureToBuffer({ texture: gpuEntry.tex }, {
|
|
4850
|
+
buffer: tmpBuf,
|
|
4851
|
+
offset: 0,
|
|
4852
|
+
bytesPerRow,
|
|
4853
|
+
rowsPerImage: h
|
|
4854
|
+
}, [
|
|
4855
|
+
w,
|
|
4856
|
+
h,
|
|
4857
|
+
1
|
|
4858
|
+
]);
|
|
4859
|
+
this.device.queue.submit([enc.finish()]);
|
|
4860
|
+
if (bytesPerRow === w * 4) this.device._readBufferSync(tmpBuf, dst, byteLen);
|
|
4861
|
+
else {
|
|
4862
|
+
const raw = new Uint8Array(totalBuf);
|
|
4863
|
+
this.device._readBufferSync(tmpBuf, raw, totalBuf);
|
|
4864
|
+
for (let y = 0; y < h; y++) dst.set(raw.subarray(y * bytesPerRow, y * bytesPerRow + w * 4), y * w * 4);
|
|
4865
|
+
}
|
|
4866
|
+
try {
|
|
4867
|
+
tmpBuf.destroy?.();
|
|
4868
|
+
} catch {}
|
|
4869
|
+
return dst;
|
|
4870
|
+
}
|
|
4581
4871
|
return dst;
|
|
4582
4872
|
},
|
|
4583
4873
|
destroy: () => {
|
|
4584
|
-
|
|
4874
|
+
lazy2D?.destroy();
|
|
4875
|
+
try {
|
|
4876
|
+
gpuEntry.tex?.destroy?.();
|
|
4877
|
+
} catch {}
|
|
4585
4878
|
textures.remove(key);
|
|
4586
4879
|
}
|
|
4587
4880
|
};
|
|
4588
4881
|
}
|
|
4589
|
-
/** Render a `DisplayList`
|
|
4882
|
+
/** Render a `DisplayList` natively on the GPU into an offscreen `StageRenderTarget` (zero CPU Canvas2D copy!). */
|
|
4590
4883
|
renderToTarget(target, content, camera = target.camera) {
|
|
4591
|
-
const
|
|
4592
|
-
if (!sub) return;
|
|
4884
|
+
const ext = target;
|
|
4593
4885
|
if (typeof content === "function") {
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
}
|
|
4597
|
-
const
|
|
4598
|
-
if (
|
|
4886
|
+
ext._render2DCallback?.(content, camera);
|
|
4887
|
+
return;
|
|
4888
|
+
}
|
|
4889
|
+
const entry = ext._gpuEntry ?? this.texCache.get(target.texture.source[0]);
|
|
4890
|
+
if (!entry) return;
|
|
4891
|
+
ext._markGpuRendered?.();
|
|
4892
|
+
this.executePass(entry.view, "rgba8unorm", target.width, target.height, content, camera, false);
|
|
4599
4893
|
}
|
|
4600
4894
|
destroy() {
|
|
4601
4895
|
this.removeAllListeners();
|