@codexo/exojs-tilemap 0.19.0 → 0.20.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.
Files changed (157) hide show
  1. package/README.md +7 -163
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/ChunkSource.d.ts +0 -33
  6. package/dist/esm/ChunkSource.d.ts.map +0 -1
  7. package/dist/esm/ChunkStreamer.d.ts +0 -104
  8. package/dist/esm/ChunkStreamer.d.ts.map +0 -1
  9. package/dist/esm/ChunkStreamer.js +0 -229
  10. package/dist/esm/ChunkStreamer.js.map +0 -1
  11. package/dist/esm/ImageLayer.d.ts +0 -89
  12. package/dist/esm/ImageLayer.d.ts.map +0 -1
  13. package/dist/esm/ImageLayer.js +0 -74
  14. package/dist/esm/ImageLayer.js.map +0 -1
  15. package/dist/esm/ImageLayerNode.d.ts +0 -91
  16. package/dist/esm/ImageLayerNode.d.ts.map +0 -1
  17. package/dist/esm/ImageLayerNode.js +0 -210
  18. package/dist/esm/ImageLayerNode.js.map +0 -1
  19. package/dist/esm/MapObject.d.ts +0 -70
  20. package/dist/esm/MapObject.d.ts.map +0 -1
  21. package/dist/esm/MapObject.js +0 -34
  22. package/dist/esm/MapObject.js.map +0 -1
  23. package/dist/esm/MapObjectSpawner.d.ts +0 -133
  24. package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
  25. package/dist/esm/MapObjectSpawner.js +0 -147
  26. package/dist/esm/MapObjectSpawner.js.map +0 -1
  27. package/dist/esm/MapSpawnSession.d.ts +0 -46
  28. package/dist/esm/MapSpawnSession.d.ts.map +0 -1
  29. package/dist/esm/MapSpawnSession.js +0 -88
  30. package/dist/esm/MapSpawnSession.js.map +0 -1
  31. package/dist/esm/MapWorld.d.ts +0 -134
  32. package/dist/esm/MapWorld.d.ts.map +0 -1
  33. package/dist/esm/MapWorld.js +0 -150
  34. package/dist/esm/MapWorld.js.map +0 -1
  35. package/dist/esm/MapWorldRuntime.d.ts +0 -180
  36. package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
  37. package/dist/esm/MapWorldRuntime.js +0 -261
  38. package/dist/esm/MapWorldRuntime.js.map +0 -1
  39. package/dist/esm/ObjectLayer.d.ts +0 -379
  40. package/dist/esm/ObjectLayer.d.ts.map +0 -1
  41. package/dist/esm/ObjectLayer.js +0 -221
  42. package/dist/esm/ObjectLayer.js.map +0 -1
  43. package/dist/esm/SampledChunkSource.d.ts +0 -43
  44. package/dist/esm/SampledChunkSource.d.ts.map +0 -1
  45. package/dist/esm/SampledChunkSource.js +0 -48
  46. package/dist/esm/SampledChunkSource.js.map +0 -1
  47. package/dist/esm/TileAnimator.d.ts +0 -72
  48. package/dist/esm/TileAnimator.d.ts.map +0 -1
  49. package/dist/esm/TileAnimator.js +0 -158
  50. package/dist/esm/TileAnimator.js.map +0 -1
  51. package/dist/esm/TileChunk.d.ts +0 -103
  52. package/dist/esm/TileChunk.d.ts.map +0 -1
  53. package/dist/esm/TileChunk.js +0 -194
  54. package/dist/esm/TileChunk.js.map +0 -1
  55. package/dist/esm/TileChunkNode.d.ts +0 -2
  56. package/dist/esm/TileChunkNode.d.ts.map +0 -1
  57. package/dist/esm/TileChunkNode.js +0 -145
  58. package/dist/esm/TileChunkNode.js.map +0 -1
  59. package/dist/esm/TileLayer.d.ts +0 -286
  60. package/dist/esm/TileLayer.d.ts.map +0 -1
  61. package/dist/esm/TileLayer.js +0 -526
  62. package/dist/esm/TileLayer.js.map +0 -1
  63. package/dist/esm/TileLayerNode.d.ts +0 -129
  64. package/dist/esm/TileLayerNode.d.ts.map +0 -1
  65. package/dist/esm/TileLayerNode.js +0 -245
  66. package/dist/esm/TileLayerNode.js.map +0 -1
  67. package/dist/esm/TileMap.d.ts +0 -317
  68. package/dist/esm/TileMap.d.ts.map +0 -1
  69. package/dist/esm/TileMap.js +0 -406
  70. package/dist/esm/TileMap.js.map +0 -1
  71. package/dist/esm/TileMapBand.d.ts +0 -80
  72. package/dist/esm/TileMapBand.d.ts.map +0 -1
  73. package/dist/esm/TileMapBand.js +0 -155
  74. package/dist/esm/TileMapBand.js.map +0 -1
  75. package/dist/esm/TileMapNode.d.ts +0 -92
  76. package/dist/esm/TileMapNode.d.ts.map +0 -1
  77. package/dist/esm/TileMapNode.js +0 -134
  78. package/dist/esm/TileMapNode.js.map +0 -1
  79. package/dist/esm/TileMapView.d.ts +0 -248
  80. package/dist/esm/TileMapView.d.ts.map +0 -1
  81. package/dist/esm/TileMapView.js +0 -394
  82. package/dist/esm/TileMapView.js.map +0 -1
  83. package/dist/esm/TileProjection.d.ts +0 -59
  84. package/dist/esm/TileProjection.d.ts.map +0 -1
  85. package/dist/esm/TileProjection.js +0 -106
  86. package/dist/esm/TileProjection.js.map +0 -1
  87. package/dist/esm/TileSet.d.ts +0 -116
  88. package/dist/esm/TileSet.d.ts.map +0 -1
  89. package/dist/esm/TileSet.js +0 -168
  90. package/dist/esm/TileSet.js.map +0 -1
  91. package/dist/esm/WangSet.d.ts +0 -80
  92. package/dist/esm/WangSet.d.ts.map +0 -1
  93. package/dist/esm/WangSet.js +0 -73
  94. package/dist/esm/WangSet.js.map +0 -1
  95. package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
  96. package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
  97. package/dist/esm/WorkerSampledChunkSource.js +0 -113
  98. package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
  99. package/dist/esm/autoTile.d.ts +0 -88
  100. package/dist/esm/autoTile.d.ts.map +0 -1
  101. package/dist/esm/autoTile.js +0 -173
  102. package/dist/esm/autoTile.js.map +0 -1
  103. package/dist/esm/chunkGeometry.d.ts +0 -2
  104. package/dist/esm/chunkGeometry.d.ts.map +0 -1
  105. package/dist/esm/chunkGeometry.js +0 -116
  106. package/dist/esm/chunkGeometry.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -2
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js +0 -27
  110. package/dist/esm/nodeBounds.d.ts +0 -2
  111. package/dist/esm/nodeBounds.d.ts.map +0 -1
  112. package/dist/esm/nodeBounds.js +0 -40
  113. package/dist/esm/nodeBounds.js.map +0 -1
  114. package/dist/esm/pixelSnap.d.ts +0 -2
  115. package/dist/esm/pixelSnap.d.ts.map +0 -1
  116. package/dist/esm/pixelSnap.js +0 -21
  117. package/dist/esm/pixelSnap.js.map +0 -1
  118. package/dist/esm/projectObject.d.ts +0 -4
  119. package/dist/esm/projectObject.d.ts.map +0 -1
  120. package/dist/esm/projectObject.js +0 -87
  121. package/dist/esm/projectObject.js.map +0 -1
  122. package/dist/esm/public.d.ts +0 -48
  123. package/dist/esm/public.d.ts.map +0 -1
  124. package/dist/esm/tileCollision.d.ts +0 -190
  125. package/dist/esm/tileCollision.d.ts.map +0 -1
  126. package/dist/esm/tileCollision.js +0 -399
  127. package/dist/esm/tileCollision.js.map +0 -1
  128. package/dist/esm/tileWord.d.ts +0 -2
  129. package/dist/esm/tileWord.d.ts.map +0 -1
  130. package/dist/esm/tileWord.js +0 -16
  131. package/dist/esm/tileWord.js.map +0 -1
  132. package/dist/esm/tilemapExtension.d.ts +0 -20
  133. package/dist/esm/tilemapExtension.d.ts.map +0 -1
  134. package/dist/esm/tilemapExtension.js +0 -53
  135. package/dist/esm/tilemapExtension.js.map +0 -1
  136. package/dist/esm/tilemapSerializers.d.ts +0 -2
  137. package/dist/esm/tilemapSerializers.d.ts.map +0 -1
  138. package/dist/esm/tilemapSerializers.js +0 -54
  139. package/dist/esm/tilemapSerializers.js.map +0 -1
  140. package/dist/esm/types.d.ts +0 -231
  141. package/dist/esm/types.d.ts.map +0 -1
  142. package/dist/esm/types.js +0 -129
  143. package/dist/esm/types.js.map +0 -1
  144. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
  145. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
  146. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
  147. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
  148. package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
  149. package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
  150. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
  151. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
  152. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
  153. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
  154. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
  155. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
  156. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
  157. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
@@ -1,539 +0,0 @@
1
- import { TILE_DIAGONAL_BIT, TILE_ROW_MASK } from "../tileWord.js";
2
- import tile_chunk_default from "./shaders/tile-chunk.wgsl.js";
3
- import { AbstractWebGpuRenderer, DataTexture, Texture, colorShaderSourcesWgsl, fillShaderSource, getWebGpuBlendState, isSampleableTexture, packAffineMat4, packSnapViewport, packedGroupChanged, retainedGroupUniformBytes, stencilContentDepthStencilState } from "@codexo/exojs/renderer-sdk";
4
- import { Matrix } from "@codexo/exojs";
5
-
6
- //#region src/webgpu/WebGpuTileChunkRenderer.ts
7
- const instanceStrideBytes = 32;
8
- const wordsPerInstance = instanceStrideBytes / Uint32Array.BYTES_PER_ELEMENT;
9
- const projectionByteLength = 144;
10
- const initialBatchCapacity = 256;
11
- const indicesPerInstance = 6;
12
- const quadIndices = new Uint16Array([
13
- 0,
14
- 1,
15
- 2,
16
- 0,
17
- 2,
18
- 3
19
- ]);
20
- const tileShaderSource = `${colorShaderSourcesWgsl}${fillShaderSource(tile_chunk_default, {
21
- tileRowMask: TILE_ROW_MASK,
22
- tileDiagonalBit: TILE_DIAGONAL_BIT
23
- })}`;
24
- /**
25
- * Instanced WebGPU renderer for {@link TileChunkNode}, the parity counterpart of
26
- * the WebGL2 renderer. Same instance layout and orientation handling; per-chunk
27
- * transforms ride on the backend's shared transform storage buffer, and the
28
- * instance buffer grows on demand rather than flushing in fixed runs.
29
- * @internal
30
- */
31
- var WebGpuTileChunkRenderer = class extends AbstractWebGpuRenderer {
32
- /**
33
- * Retained-batch capability opt-in: a tile chunk's per-flush
34
- * instanced batches (fixed 32-byte layout, tile word at word 7) record and
35
- * replay from group-owned resources. Pixel-snapped draws are excluded by
36
- * the collect-time recordability predicate (and belt-and-braces poisoning
37
- * in {@link render}); tile chunks have no custom-material path to exclude.
38
- * @internal
39
- */
40
- supportsRetainedBatches = true;
41
- _projectionData = new Float32Array(projectionByteLength / Float32Array.BYTES_PER_ELEMENT);
42
- _writtenView = null;
43
- _writtenViewUpdateId = -1;
44
- _hasWrittenProjection = false;
45
- _stagedGroupData = /* @__PURE__ */ new Float32Array(16);
46
- _device = null;
47
- _shaderModule = null;
48
- _uniformBindGroupLayout = null;
49
- _textureBindGroupLayout = null;
50
- _pipelineLayout = null;
51
- _uniformBuffer = null;
52
- _sampleAlphaBuffers = [];
53
- _transformBindGroup = null;
54
- _transformStorageBuffer = null;
55
- _indexBuffer = null;
56
- _instanceBuffer = null;
57
- _instanceBufferCapacity = 0;
58
- _instanceStagingCapacity = 0;
59
- _instanceData = /* @__PURE__ */ new ArrayBuffer(0);
60
- _instanceFloat32 = new Float32Array(this._instanceData);
61
- _instanceUint32 = new Uint32Array(this._instanceData);
62
- _pipelines = /* @__PURE__ */ new Map();
63
- _textureBindGroups = /* @__PURE__ */ new WeakMap();
64
- _quadIndex = 0;
65
- _maxNodeIndex = 0;
66
- _batchNodeCount = 0;
67
- _nodeBooked = false;
68
- _currentBlendMode = null;
69
- _currentTexture = null;
70
- _passDraws = null;
71
- _instancePassBytes = 0;
72
- _stagedReplayGroupData = /* @__PURE__ */ new Float32Array(16);
73
- _recordTextures = [null];
74
- onConnect(backend) {
75
- if (this._device) return;
76
- this._device = backend.device;
77
- this._shaderModule = this._device.createShaderModule({ code: tileShaderSource });
78
- this._uniformBindGroupLayout = this._device.createBindGroupLayout({ entries: [{
79
- binding: 0,
80
- visibility: GPUShaderStage.VERTEX,
81
- buffer: { type: "uniform" }
82
- }, {
83
- binding: 1,
84
- visibility: GPUShaderStage.VERTEX,
85
- buffer: { type: "read-only-storage" }
86
- }] });
87
- this._textureBindGroupLayout = this._device.createBindGroupLayout({ entries: [
88
- {
89
- binding: 0,
90
- visibility: GPUShaderStage.FRAGMENT,
91
- texture: { sampleType: "float" }
92
- },
93
- {
94
- binding: 1,
95
- visibility: GPUShaderStage.FRAGMENT,
96
- sampler: { type: "filtering" }
97
- },
98
- {
99
- binding: 2,
100
- visibility: GPUShaderStage.FRAGMENT,
101
- buffer: { type: "uniform" }
102
- }
103
- ] });
104
- this._pipelineLayout = this._device.createPipelineLayout({ bindGroupLayouts: [this._uniformBindGroupLayout, this._textureBindGroupLayout] });
105
- this._uniformBuffer = this._device.createBuffer({
106
- size: projectionByteLength,
107
- usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
108
- });
109
- for (const premultiply of [0, 1]) {
110
- const buffer = this._device.createBuffer({
111
- size: 16,
112
- usage: GPUBufferUsage.UNIFORM,
113
- mappedAtCreation: true
114
- });
115
- new Float32Array(buffer.getMappedRange())[0] = premultiply;
116
- buffer.unmap();
117
- this._sampleAlphaBuffers.push(buffer);
118
- }
119
- this._indexBuffer = this._device.createBuffer({
120
- size: quadIndices.byteLength,
121
- usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
122
- });
123
- this._device.queue.writeBuffer(this._indexBuffer, 0, quadIndices.buffer, quadIndices.byteOffset, quadIndices.byteLength);
124
- }
125
- onDisconnect() {
126
- const coordinator = this._backend?.passCoordinator ?? null;
127
- if (coordinator !== null && this._passDraws !== null && this._passDraws === coordinator.activePass) coordinator.endPass();
128
- this._instanceBuffer?.destroy();
129
- this._indexBuffer?.destroy();
130
- this._uniformBuffer?.destroy();
131
- for (const buffer of this._sampleAlphaBuffers) buffer.destroy();
132
- this._sampleAlphaBuffers.length = 0;
133
- this._pipelines.clear();
134
- this._instanceBuffer = null;
135
- this._indexBuffer = null;
136
- this._transformBindGroup = null;
137
- this._transformStorageBuffer = null;
138
- this._textureBindGroups = /* @__PURE__ */ new WeakMap();
139
- this._uniformBuffer = null;
140
- this._pipelineLayout = null;
141
- this._textureBindGroupLayout = null;
142
- this._uniformBindGroupLayout = null;
143
- this._shaderModule = null;
144
- this._device = null;
145
- this._backend = null;
146
- this._instanceBufferCapacity = 0;
147
- this._instanceStagingCapacity = 0;
148
- this._instanceData = /* @__PURE__ */ new ArrayBuffer(0);
149
- this._instanceFloat32 = new Float32Array(this._instanceData);
150
- this._instanceUint32 = new Uint32Array(this._instanceData);
151
- this._passDraws = null;
152
- this._instancePassBytes = 0;
153
- this._quadIndex = 0;
154
- this._maxNodeIndex = 0;
155
- this._batchNodeCount = 0;
156
- this._nodeBooked = false;
157
- this._currentBlendMode = null;
158
- this._currentTexture = null;
159
- this._writtenView = null;
160
- this._writtenViewUpdateId = -1;
161
- this._hasWrittenProjection = false;
162
- }
163
- render(node) {
164
- const backend = this._backend;
165
- if (backend === null) return;
166
- const pages = node.pages;
167
- this._nodeBooked = false;
168
- if (pages.length === 0) return;
169
- const blendMode = node.blendMode;
170
- const tintRgba = node.tint.toRgba8();
171
- const command = backend.activeDrawCommand;
172
- const nodeIndex = command !== null ? command.nodeIndex : backend.pushTransform(node);
173
- for (const page of pages) this._renderPage(backend, page.texture, page.quads, blendMode, tintRgba, nodeIndex);
174
- }
175
- _renderPage(backend, texture, quads, blendMode, tintRgba, nodeIndex) {
176
- if (quads.length === 0) return;
177
- if (!isSampleableTexture(texture)) return;
178
- if (texture instanceof Texture && !(texture instanceof DataTexture) && texture.source === null) return;
179
- const blendModeChanged = this._currentBlendMode !== null && blendMode !== this._currentBlendMode;
180
- const textureChanged = this._currentTexture !== null && texture !== this._currentTexture;
181
- const willExceed = this._quadIndex + quads.length > this._instanceStagingCapacity && this._instanceStagingCapacity > 0;
182
- if ((blendModeChanged || textureChanged || willExceed) && this._quadIndex > 0) this.flush();
183
- this._currentBlendMode = blendMode;
184
- this._currentTexture = texture;
185
- backend.setBlendMode(blendMode);
186
- this._ensureStagingCapacity(this._quadIndex + quads.length);
187
- if (!this._nodeBooked) {
188
- this._nodeBooked = true;
189
- this._batchNodeCount++;
190
- }
191
- const f32 = this._instanceFloat32;
192
- const u32 = this._instanceUint32;
193
- const flipYTexture = texture.flipY;
194
- const baseWord = nodeIndex & TILE_ROW_MASK;
195
- for (const q of quads) {
196
- const idx = this._quadIndex * wordsPerInstance;
197
- f32[idx + 0] = q.x0;
198
- f32[idx + 1] = q.y0;
199
- f32[idx + 2] = q.x1;
200
- f32[idx + 3] = q.y1;
201
- const flipX = (q.orient & 1) !== 0;
202
- const tileFlipY = (q.orient & 2) !== 0;
203
- const diagonal = (q.orient & 4) !== 0;
204
- const uA = flipX ? q.u1 : q.u0;
205
- const uB = flipX ? q.u0 : q.u1;
206
- let vA = tileFlipY ? q.v1 : q.v0;
207
- let vB = tileFlipY ? q.v0 : q.v1;
208
- if (flipYTexture) {
209
- const swap = vA;
210
- vA = vB;
211
- vB = swap;
212
- }
213
- const uMin = uA * 65535 & 65535;
214
- const vMin = vA * 65535 & 65535;
215
- const uMax = uB * 65535 & 65535;
216
- const vMax = vB * 65535 & 65535;
217
- u32[idx + 4] = uMin | vMin << 16;
218
- u32[idx + 5] = uMax | vMax << 16;
219
- u32[idx + 6] = tintRgba;
220
- u32[idx + 7] = (diagonal ? baseWord | TILE_DIAGONAL_BIT : baseWord) >>> 0;
221
- this._quadIndex++;
222
- }
223
- if (nodeIndex > this._maxNodeIndex) this._maxNodeIndex = nodeIndex;
224
- }
225
- flush() {
226
- const backend = this._backend;
227
- const device = this._device;
228
- const uniformBuffer = this._uniformBuffer;
229
- if (!backend || !device || !uniformBuffer) return;
230
- if (this._quadIndex === 0 && !backend.clearRequested) return;
231
- const view = backend.view;
232
- const viewportChanged = packSnapViewport(backend, this._projectionData, 32);
233
- const projectionChanged = !this._hasWrittenProjection || this._writtenView !== view || this._writtenViewUpdateId !== view.updateId || viewportChanged || this._groupContentChanged(backend);
234
- const scissor = backend.getScissorRect();
235
- const maskClipsAll = scissor !== null && (scissor.width <= 0 || scissor.height <= 0);
236
- const coordinator = backend.passCoordinator;
237
- const texture = this._currentTexture;
238
- const blendMode = this._currentBlendMode;
239
- const indexBuffer = this._indexBuffer;
240
- const willDraw = this._quadIndex > 0 && !maskClipsAll && texture !== null && blendMode !== null && indexBuffer !== null;
241
- const flushBytes = this._quadIndex * instanceStrideBytes;
242
- const targetInstanceBytes = this._instancePassBytes + flushBytes;
243
- if (this._passDraws !== null && this._passDraws === coordinator.activePass && (projectionChanged || willDraw && targetInstanceBytes > this._instanceBufferCapacity) || willDraw && coordinator.passHasDraws && (backend.textureUploadWouldMutate(texture) || backend.transformStorageWouldGrow(this._maxNodeIndex + 1))) coordinator.endPass();
244
- if (this._passDraws !== coordinator.activePass) {
245
- this._passDraws = null;
246
- this._instancePassBytes = 0;
247
- }
248
- if (projectionChanged) {
249
- packAffineMat4(view.getTransform(), this._projectionData, 0);
250
- packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, this._projectionData, 16);
251
- this._writtenView = view;
252
- this._writtenViewUpdateId = view.updateId;
253
- this._hasWrittenProjection = true;
254
- device.queue.writeBuffer(uniformBuffer, 0, this._projectionData.buffer, this._projectionData.byteOffset, this._projectionData.byteLength);
255
- }
256
- if (willDraw || backend.clearRequested) {
257
- const active = coordinator.acquirePass();
258
- const pass = active.pass;
259
- if (willDraw) {
260
- const instanceBuffer = this._ensureInstanceBufferCapacity(device, targetInstanceBytes);
261
- const instanceByteOffset = this._instancePassBytes;
262
- device.queue.writeBuffer(instanceBuffer, instanceByteOffset, this._instanceData, 0, flushBytes);
263
- const storage = backend.getTransformStorageBuffer(this._maxNodeIndex + 1);
264
- const transformBindGroup = this._getOrCreateTransformBindGroup(device, uniformBuffer, storage.buffer);
265
- const textureBindGroup = this._getOrCreateTextureBindGroup(device, backend, texture);
266
- const stencil = coordinator.stencilActive;
267
- const pipeline = this._getPipeline(blendMode, backend.renderTargetFormat, stencil);
268
- pass.setPipeline(pipeline);
269
- pass.setBindGroup(0, transformBindGroup);
270
- pass.setBindGroup(1, textureBindGroup);
271
- pass.setVertexBuffer(0, instanceBuffer, instanceByteOffset);
272
- pass.setIndexBuffer(indexBuffer, "uint16");
273
- pass.drawIndexed(indicesPerInstance, this._quadIndex, 0, 0, 0);
274
- this._instancePassBytes = instanceByteOffset + flushBytes;
275
- this._passDraws = active;
276
- coordinator.markPassDraws();
277
- backend.stats.batches++;
278
- backend.stats.drawCalls++;
279
- }
280
- }
281
- if (this._quadIndex > 0 && backend._retainedCaptureActive && blendMode !== null && texture !== null) {
282
- this._recordTextures[0] = texture;
283
- backend.recordRetainedBatch(this, this._instanceData, flushBytes, this._quadIndex, blendMode, this._recordTextures, 1, null, null, this._batchNodeCount);
284
- }
285
- this._quadIndex = 0;
286
- this._maxNodeIndex = 0;
287
- this._batchNodeCount = 0;
288
- this._currentBlendMode = null;
289
- this._currentTexture = null;
290
- }
291
- /**
292
- * Whether the packed floats of the active group matrix differ from what the
293
- * shared projection UBO currently holds at [16, 32). Stages the packed matrix
294
- * into `_stagedGroupData` as a side effect (idempotent - safe to call more
295
- * than once per flush).
296
- */
297
- _groupContentChanged(backend) {
298
- packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, this._stagedGroupData, 0);
299
- if (!this._hasWrittenProjection) return true;
300
- return packedGroupChanged(this._stagedGroupData, this._projectionData, 16);
301
- }
302
- destroy() {
303
- this.disconnect();
304
- }
305
- _getOrCreateTransformBindGroup(device, uniformBuffer, storageBuffer) {
306
- if (this._transformBindGroup !== null && this._transformStorageBuffer === storageBuffer) return this._transformBindGroup;
307
- this._transformStorageBuffer = storageBuffer;
308
- this._transformBindGroup = device.createBindGroup({
309
- layout: this._uniformBindGroupLayout,
310
- entries: [{
311
- binding: 0,
312
- resource: { buffer: uniformBuffer }
313
- }, {
314
- binding: 1,
315
- resource: { buffer: storageBuffer }
316
- }]
317
- });
318
- return this._transformBindGroup;
319
- }
320
- /**
321
- * Build (or reuse) the group(1) texture bind group for `texture`. The
322
- * binding is resolved BEFORE the cache lookup on purpose: resolving is what
323
- * syncs a dirty/mutated texture's content to the GPU, so it must run every
324
- * flush/replay even when the bind group itself is served from cache.
325
- */
326
- _getOrCreateTextureBindGroup(device, backend, texture) {
327
- const { view, sampler } = backend.getTextureBinding(texture);
328
- const premultiply = backend.shouldPremultiplyTextureSample(texture);
329
- const cached = this._textureBindGroups.get(texture);
330
- if (cached?.view === view && cached.sampler === sampler && cached.premultiply === premultiply) return cached.group;
331
- const group = device.createBindGroup({
332
- layout: this._textureBindGroupLayout,
333
- entries: [
334
- {
335
- binding: 0,
336
- resource: view
337
- },
338
- {
339
- binding: 1,
340
- resource: sampler
341
- },
342
- {
343
- binding: 2,
344
- resource: { buffer: this._sampleAlphaBuffers[premultiply ? 1 : 0] }
345
- }
346
- ]
347
- });
348
- this._textureBindGroups.set(texture, {
349
- group,
350
- view,
351
- sampler,
352
- premultiply
353
- });
354
- return group;
355
- }
356
- /** @internal See {@link WebGpuRetainedBatchReplayer.scanRetainedNodeIndexRange}. */
357
- scanRetainedNodeIndexRange(bytes, range) {
358
- const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Uint32Array.BYTES_PER_ELEMENT);
359
- for (let i = 7; i < words.length; i += 8) {
360
- const row = words[i] & TILE_ROW_MASK;
361
- if (row < range.min) range.min = row;
362
- if (row > range.max) range.max = row;
363
- }
364
- }
365
- /** @internal See {@link WebGpuRetainedBatchReplayer.rebaseRetainedNodeIndices} (group-local indices). */
366
- rebaseRetainedNodeIndices(bytes, base) {
367
- const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Uint32Array.BYTES_PER_ELEMENT);
368
- for (let i = 7; i < words.length; i += 8) {
369
- const word = words[i];
370
- const diagonal = word & TILE_DIAGONAL_BIT;
371
- const row = word & TILE_ROW_MASK;
372
- words[i] = (diagonal | row - base & TILE_ROW_MASK) >>> 0;
373
- }
374
- }
375
- /**
376
- * Replay one recorded batch from its group-owned bundle into the OPEN pass.
377
- * Reuses only recorded DATA (instance bytes, transform rows, texture, blend
378
- * mode); every piece of STATE is resolved live - pipeline via the
379
- * `_getPipeline` cache, the group(1) texture bind group via the live
380
- * texture-set cache (resolving re-syncs dirty content), and the group's
381
- * 128-byte UBO (projection from the live view + the live composed group
382
- * matrix) written only when its content changed. The same-frame
383
- * double-replay hazard (one group under two views while the open pass
384
- * already holds this bundle's draws) ends the pass first.
385
- * @internal
386
- */
387
- replayRetainedBatch(payload) {
388
- const backend = this._backend;
389
- const device = this._device;
390
- const bundle = payload.bundle;
391
- if (!backend || !device || this._indexBuffer === null || !bundle.isReady) return;
392
- this.flush();
393
- const scissor = backend.getScissorRect();
394
- if (scissor !== null && (scissor.width <= 0 || scissor.height <= 0)) return;
395
- const coordinator = backend.passCoordinator;
396
- if (coordinator.passHasDraws) {
397
- for (const texture of payload.textures) if (backend.textureUploadWouldMutate(texture)) {
398
- coordinator.endPass();
399
- break;
400
- }
401
- }
402
- const textureBindGroup = this._getOrCreateTextureBindGroup(device, backend, payload.textures[0]);
403
- const view = backend.view;
404
- const scratch = this._stagedReplayGroupData;
405
- packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, scratch, 0);
406
- const viewportChanged = packSnapViewport(backend, bundle.uboData, 32);
407
- let uboDirty = !bundle.uboWritten || bundle.uboView !== view || bundle.uboViewUpdateId !== view.updateId || viewportChanged;
408
- if (!uboDirty) {
409
- for (let i = 0; i < 16; i++) if (scratch[i] !== bundle.uboData[16 + i]) {
410
- uboDirty = true;
411
- break;
412
- }
413
- }
414
- if (uboDirty) {
415
- const activePass = coordinator.activePass;
416
- if (activePass !== null && bundle.drawsInPass === activePass) coordinator.endPass();
417
- packAffineMat4(view.getTransform(), bundle.uboData, 0);
418
- bundle.uboData.set(scratch, 16);
419
- bundle.uboView = view;
420
- bundle.uboViewUpdateId = view.updateId;
421
- bundle.uboWritten = true;
422
- device.queue.writeBuffer(bundle.uniformBuffer, 0, bundle.uboData.buffer, bundle.uboData.byteOffset, retainedGroupUniformBytes);
423
- }
424
- const active = coordinator.acquirePass();
425
- const pass = active.pass;
426
- const nativePipeline = this._getPipeline(payload.blendMode, backend.renderTargetFormat, coordinator.stencilActive);
427
- const nativeFrameBindGroup = bundle.getBindGroup(device, this._uniformBindGroupLayout, false);
428
- const nativeCompatible = backend.colorAttachmentCount === 1;
429
- if (!nativeCompatible) bundle.nativeReplay.skipPass();
430
- if (!nativeCompatible || !bundle.nativeReplay.draw(device, active, payload, backend.renderTargetFormat, nativePipeline, nativeFrameBindGroup, textureBindGroup, this._indexBuffer, "uint16", indicesPerInstance, payload.instanceCount)) {
431
- pass.setPipeline(nativePipeline);
432
- pass.setBindGroup(0, nativeFrameBindGroup);
433
- pass.setBindGroup(1, textureBindGroup);
434
- pass.setVertexBuffer(0, bundle.instanceBuffer, payload.byteOffset);
435
- pass.setIndexBuffer(this._indexBuffer, "uint16");
436
- pass.drawIndexed(indicesPerInstance, payload.instanceCount, 0, 0, 0);
437
- }
438
- bundle.drawsInPass = active;
439
- coordinator.markPassDraws();
440
- backend.stats.batches++;
441
- backend.stats.drawCalls++;
442
- }
443
- _getPipeline(blendMode, format, stencil) {
444
- const key = `${blendMode}:${format}:${stencil ? "s" : "n"}`;
445
- const existing = this._pipelines.get(key);
446
- if (existing) return existing;
447
- if (!this._device || !this._shaderModule || !this._pipelineLayout) throw new Error("WebGpuTileChunkRenderer: renderer must be connected first.");
448
- const descriptor = {
449
- layout: this._pipelineLayout,
450
- vertex: {
451
- module: this._shaderModule,
452
- entryPoint: "vertexMain",
453
- buffers: [{
454
- arrayStride: instanceStrideBytes,
455
- stepMode: "instance",
456
- attributes: [
457
- {
458
- shaderLocation: 0,
459
- offset: 0,
460
- format: "float32x4"
461
- },
462
- {
463
- shaderLocation: 1,
464
- offset: 16,
465
- format: "unorm16x4"
466
- },
467
- {
468
- shaderLocation: 2,
469
- offset: 24,
470
- format: "unorm8x4"
471
- },
472
- {
473
- shaderLocation: 3,
474
- offset: 28,
475
- format: "uint32"
476
- }
477
- ]
478
- }]
479
- },
480
- fragment: {
481
- module: this._shaderModule,
482
- entryPoint: "fragmentMain",
483
- targets: [{
484
- format,
485
- blend: getWebGpuBlendState(blendMode),
486
- writeMask: GPUColorWrite.ALL
487
- }]
488
- },
489
- primitive: { topology: "triangle-list" }
490
- };
491
- if (stencil) descriptor.depthStencil = stencilContentDepthStencilState();
492
- const pipeline = this._device.createRenderPipeline(descriptor);
493
- this._pipelines.set(key, pipeline);
494
- return pipeline;
495
- }
496
- /**
497
- * Grow the CPU staging array to hold `instanceCount` instances, carrying the
498
- * quads packed so far. Flush-local: the array only ever holds the pending
499
- * batch, so it is sized independently of the pass-scoped GPU buffer.
500
- */
501
- _ensureStagingCapacity(instanceCount) {
502
- if (instanceCount <= this._instanceStagingCapacity) return;
503
- let nextCapacity = Math.max(this._instanceStagingCapacity, initialBatchCapacity);
504
- while (nextCapacity < instanceCount) nextCapacity *= 2;
505
- const oldData = this._instanceData;
506
- const carryBytes = Math.min(this._quadIndex * instanceStrideBytes, oldData.byteLength);
507
- const instanceData = /* @__PURE__ */ new ArrayBuffer(nextCapacity * instanceStrideBytes);
508
- if (carryBytes > 0) new Uint8Array(instanceData).set(new Uint8Array(oldData, 0, carryBytes));
509
- this._instanceStagingCapacity = nextCapacity;
510
- this._instanceData = instanceData;
511
- this._instanceFloat32 = new Float32Array(instanceData);
512
- this._instanceUint32 = new Uint32Array(instanceData);
513
- }
514
- /**
515
- * Resolve the GPU instance buffer for `requiredBytes` - the total this pass
516
- * would reach by appending, not this flush's own bytes. Reallocation frees the
517
- * buffer earlier draws in the open pass read, so the caller must have ended
518
- * that pass (and restarted the cursor) before a growing call. Capacity
519
- * doubles, so the split a growth costs converges away within a frame or two.
520
- */
521
- _ensureInstanceBufferCapacity(device, requiredBytes) {
522
- const existing = this._instanceBuffer;
523
- if (existing !== null && requiredBytes <= this._instanceBufferCapacity) return existing;
524
- const nextCapacity = Math.max(this._instanceBufferCapacity * 2, requiredBytes, initialBatchCapacity * instanceStrideBytes);
525
- const instanceBuffer = device.createBuffer({
526
- label: "tile-chunk:instance-buffer",
527
- size: nextCapacity,
528
- usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
529
- });
530
- existing?.destroy();
531
- this._instanceBufferCapacity = nextCapacity;
532
- this._instanceBuffer = instanceBuffer;
533
- return instanceBuffer;
534
- }
535
- };
536
-
537
- //#endregion
538
- export { WebGpuTileChunkRenderer };
539
- //# sourceMappingURL=WebGpuTileChunkRenderer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGpuTileChunkRenderer.js","names":["tileShaderTemplate"],"sources":["../../../src/webgpu/WebGpuTileChunkRenderer.ts"],"sourcesContent":["/// <reference types=\"@webgpu/types\" />\n\nimport { Matrix } from '@codexo/exojs';\nimport type {\n RenderTexture,\n WebGpuActiveRenderPass,\n WebGpuRetainedBatchPayload,\n WebGpuRetainedBatchReplayer,\n WebGpuRetainedNodeIndexRange,\n} from '@codexo/exojs/renderer-sdk';\nimport type { View, WebGpuBackend } from '@codexo/exojs/renderer-sdk';\nimport { isSampleableTexture } from '@codexo/exojs/renderer-sdk';\nimport {\n AbstractWebGpuRenderer,\n type BlendModes,\n colorShaderSourcesWgsl,\n DataTexture,\n fillShaderSource,\n getWebGpuBlendState,\n packAffineMat4,\n packedGroupChanged,\n packSnapViewport,\n retainedGroupUniformBytes,\n stencilContentDepthStencilState,\n Texture,\n} from '@codexo/exojs/renderer-sdk';\n\nimport type { TileQuad } from '../chunkGeometry';\nimport type { TileChunkNode } from '../TileChunkNode';\nimport { TILE_DIAGONAL_BIT, TILE_ROW_MASK } from '../tileWord';\nimport tileShaderTemplate from './shaders/tile-chunk.wgsl';\n\nconst instanceStrideBytes = 32;\nconst wordsPerInstance = instanceStrideBytes / Uint32Array.BYTES_PER_ELEMENT; // = 8\n// mat4x4 projection + mat4x4 group + vec4 snap viewport (aligned 16, total 144).\nconst projectionByteLength = 144;\nconst initialBatchCapacity = 256;\nconst indicesPerInstance = 6;\nconst quadIndices = new Uint16Array([0, 1, 2, 0, 2, 3]);\n\nconst tileShaderSource = `${colorShaderSourcesWgsl}${fillShaderSource(tileShaderTemplate, { tileRowMask: TILE_ROW_MASK, tileDiagonalBit: TILE_DIAGONAL_BIT })}`;\n\n/**\n * Instanced WebGPU renderer for {@link TileChunkNode}, the parity counterpart of\n * the WebGL2 renderer. Same instance layout and orientation handling; per-chunk\n * transforms ride on the backend's shared transform storage buffer, and the\n * instance buffer grows on demand rather than flushing in fixed runs.\n * @internal\n */\nexport class WebGpuTileChunkRenderer extends AbstractWebGpuRenderer<TileChunkNode> implements WebGpuRetainedBatchReplayer {\n /**\n * Retained-batch capability opt-in: a tile chunk's per-flush\n * instanced batches (fixed 32-byte layout, tile word at word 7) record and\n * replay from group-owned resources. Pixel-snapped draws are excluded by\n * the collect-time recordability predicate (and belt-and-braces poisoning\n * in {@link render}); tile chunks have no custom-material path to exclude.\n * @internal\n */\n public readonly supportsRetainedBatches = true;\n\n private readonly _projectionData = new Float32Array(projectionByteLength / Float32Array.BYTES_PER_ELEMENT);\n // Projection-uniform skip state: a matching (view identity, view.updateId)\n // pair AND unchanged group-matrix CONTENT (compared against the packed floats\n // at [16, 32), staged into `_stagedGroupData` by `_groupContentChanged`) mean\n // the shared UBO already holds this flush's projection, so the 128-byte write\n // is skipped.\n //\n // Content comparison, not the backend's group-transform id: a projection\n // rewrite is a PASS boundary below, so a group boundary that restores\n // byte-identical group bytes must not read as a change - otherwise a retained\n // group entered and left around tile chunks splits the single-submit frame.\n private _writtenView: View | null = null;\n private _writtenViewUpdateId = -1;\n private _hasWrittenProjection = false;\n private readonly _stagedGroupData = new Float32Array(16);\n\n private _device: GPUDevice | null = null;\n private _shaderModule: GPUShaderModule | null = null;\n private _uniformBindGroupLayout: GPUBindGroupLayout | null = null;\n private _textureBindGroupLayout: GPUBindGroupLayout | null = null;\n private _pipelineLayout: GPUPipelineLayout | null = null;\n private _uniformBuffer: GPUBuffer | null = null;\n private readonly _sampleAlphaBuffers: GPUBuffer[] = [];\n private _transformBindGroup: GPUBindGroup | null = null;\n private _transformStorageBuffer: GPUBuffer | null = null;\n private _indexBuffer: GPUBuffer | null = null;\n private _instanceBuffer: GPUBuffer | null = null;\n // Capacity of the GPU instance buffer, in BYTES: it carries every flush the\n // open pass has taken, not just the pending one. The CPU staging array is\n // sized separately (in instances) because it only ever holds one flush.\n private _instanceBufferCapacity = 0;\n private _instanceStagingCapacity = 0;\n private _instanceData: ArrayBuffer = new ArrayBuffer(0);\n private _instanceFloat32 = new Float32Array(this._instanceData);\n private _instanceUint32 = new Uint32Array(this._instanceData);\n private readonly _pipelines = new Map<string, GPURenderPipeline>();\n // group(1) texture bind groups cached per texture (mirrors the sprite/\n // nine-slice renderers): resolving `backend.getTextureBinding` is what\n // syncs a dirty/mutated texture's content to the GPU, so it must run every\n // flush/replay even when the bind group itself is served from cache.\n private _textureBindGroups = new WeakMap<Texture | RenderTexture, { group: GPUBindGroup; view: GPUTextureView; sampler: GPUSampler; premultiply: boolean }>();\n\n private _quadIndex = 0;\n private _maxNodeIndex = 0;\n // Chunk nodes booked against the PENDING batch, and whether the chunk being\n // rendered right now has already been booked. One chunk emits one tile\n // instance per tile, so the recorded batch's `submittedNodes` contribution is\n // this count and not `_quadIndex`. A chunk whose pages span several batches is\n // booked once, against the batch its first page lands in.\n private _batchNodeCount = 0;\n private _nodeBooked = false;\n private _currentBlendMode: BlendModes | null = null;\n private _currentTexture: Texture | null = null;\n\n // ── Pass-scoped write cursor ──────────────────────────────────────────────\n // `flush()` no longer ends the pass, so consecutive flushes record into ONE\n // open pass and ONE submit. Everything written into the shared instance\n // buffer is therefore scoped to that pass, not to a single flush: a flush\n // that rewrote the buffer from offset 0 would have the earlier flushes' draws\n // read this flush's bytes, because `queue.writeBuffer` is ordered against the\n // submit and not against the individual draws inside it. Each flush appends\n // at `_instancePassBytes` instead and adds the base at bind time.\n //\n // `_passDraws` is the open pass this renderer has actually RECORDED draws\n // into. Pass identity is the key: the coordinator builds a fresh active-pass\n // object on every acquire, so a pass ended by anyone else (a target switch, a\n // stencil clip, another renderer) is distinguished automatically.\n private _passDraws: WebGpuActiveRenderPass | null = null;\n private _instancePassBytes = 0;\n\n // ── Retained-batch replay state ───────────────────────────────────────────\n private readonly _stagedReplayGroupData = new Float32Array(16);\n // Reused single-slot texture list handed to the backend at record time; a\n // tile chunk batch always binds exactly one tileset texture (slot 0).\n private readonly _recordTextures: Array<Texture | RenderTexture | null> = [null];\n\n protected onConnect(backend: WebGpuBackend): void {\n if (this._device) {\n return;\n }\n\n this._device = backend.device;\n this._shaderModule = this._device.createShaderModule({ code: tileShaderSource });\n\n this._uniformBindGroupLayout = this._device.createBindGroupLayout({\n entries: [\n { binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } },\n { binding: 1, visibility: GPUShaderStage.VERTEX, buffer: { type: 'read-only-storage' } },\n ],\n });\n\n this._textureBindGroupLayout = this._device.createBindGroupLayout({\n entries: [\n { binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: 'float' } },\n { binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: { type: 'filtering' } },\n { binding: 2, visibility: GPUShaderStage.FRAGMENT, buffer: { type: 'uniform' } },\n ],\n });\n\n this._pipelineLayout = this._device.createPipelineLayout({\n bindGroupLayouts: [this._uniformBindGroupLayout, this._textureBindGroupLayout],\n });\n\n this._uniformBuffer = this._device.createBuffer({\n size: projectionByteLength,\n usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,\n });\n\n for (const premultiply of [0, 1]) {\n const buffer = this._device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM, mappedAtCreation: true });\n new Float32Array(buffer.getMappedRange())[0] = premultiply;\n buffer.unmap();\n this._sampleAlphaBuffers.push(buffer);\n }\n\n this._indexBuffer = this._device.createBuffer({\n size: quadIndices.byteLength,\n usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST,\n });\n this._device.queue.writeBuffer(this._indexBuffer, 0, quadIndices.buffer, quadIndices.byteOffset, quadIndices.byteLength);\n }\n\n protected onDisconnect(): void {\n // The teardown below destroys the very buffers a draw of ours left in the\n // open pass still binds, and the pass no longer ends at the tail of a\n // flush. Submit it first so those draws reach the queue against live\n // buffers. Backend destroy and device loss drop the pass before disconnecting\n // renderers, so this only fires when a renderer is disconnected on its own.\n const coordinator = this._backend?.passCoordinator ?? null;\n\n if (coordinator !== null && this._passDraws !== null && this._passDraws === coordinator.activePass) {\n coordinator.endPass();\n }\n\n this._instanceBuffer?.destroy();\n this._indexBuffer?.destroy();\n this._uniformBuffer?.destroy();\n for (const buffer of this._sampleAlphaBuffers) buffer.destroy();\n this._sampleAlphaBuffers.length = 0;\n this._pipelines.clear();\n this._instanceBuffer = null;\n this._indexBuffer = null;\n this._transformBindGroup = null;\n this._transformStorageBuffer = null;\n // Bind groups belong to the (possibly lost) device; drop the cache so\n // reconnect rebuilds them against the fresh device.\n this._textureBindGroups = new WeakMap<Texture | RenderTexture, { group: GPUBindGroup; view: GPUTextureView; sampler: GPUSampler; premultiply: boolean }>();\n this._uniformBuffer = null;\n this._pipelineLayout = null;\n this._textureBindGroupLayout = null;\n this._uniformBindGroupLayout = null;\n this._shaderModule = null;\n this._device = null;\n this._backend = null;\n this._instanceBufferCapacity = 0;\n this._instanceStagingCapacity = 0;\n this._instanceData = new ArrayBuffer(0);\n this._instanceFloat32 = new Float32Array(this._instanceData);\n this._instanceUint32 = new Uint32Array(this._instanceData);\n this._passDraws = null;\n this._instancePassBytes = 0;\n this._quadIndex = 0;\n this._maxNodeIndex = 0;\n this._batchNodeCount = 0;\n this._nodeBooked = false;\n this._currentBlendMode = null;\n this._currentTexture = null;\n this._writtenView = null;\n this._writtenViewUpdateId = -1;\n this._hasWrittenProjection = false;\n }\n\n public render(node: TileChunkNode): void {\n const backend = this._backend;\n\n if (backend === null) {\n return;\n }\n\n const pages = node.pages;\n\n this._nodeBooked = false;\n\n if (pages.length === 0) {\n return;\n }\n\n const blendMode = node.blendMode;\n const tintRgba = node.tint.toRgba8();\n\n const command = backend.activeDrawCommand;\n const nodeIndex = command !== null ? command.nodeIndex : backend.pushTransform(node);\n\n for (const page of pages) {\n this._renderPage(backend, page.texture, page.quads, blendMode, tintRgba, nodeIndex);\n }\n }\n\n private _renderPage(backend: WebGpuBackend, texture: Texture, quads: readonly TileQuad[], blendMode: BlendModes, tintRgba: number, nodeIndex: number): void {\n if (quads.length === 0) {\n return;\n }\n\n if (!isSampleableTexture(texture)) {\n return;\n }\n\n // A null `source` means a Texture still waiting on its image - but\n // DataTexture extends Texture and keeps its pixels in a CPU buffer, so it\n // has none by design. Without the exemption a procedurally-generated\n // tileset renders as nothing here while WebGL2, which has no such guard,\n // draws it.\n if (texture instanceof Texture && !(texture instanceof DataTexture) && texture.source === null) {\n return;\n }\n\n const blendModeChanged = this._currentBlendMode !== null && blendMode !== this._currentBlendMode;\n const textureChanged = this._currentTexture !== null && texture !== this._currentTexture;\n // Overflowing the CPU staging array flushes the accumulated run rather than\n // growing it. The GPU buffer is NOT what this asks about: it now carries\n // every flush in the pass, so flushing frees no room there - its capacity is\n // resolved in `flush()` against the pass total.\n const willExceed = this._quadIndex + quads.length > this._instanceStagingCapacity && this._instanceStagingCapacity > 0;\n\n if ((blendModeChanged || textureChanged || willExceed) && this._quadIndex > 0) {\n this.flush();\n }\n\n this._currentBlendMode = blendMode;\n this._currentTexture = texture;\n backend.setBlendMode(blendMode);\n\n this._ensureStagingCapacity(this._quadIndex + quads.length);\n\n // Booked after the flush decision above, so the chunk lands on the batch\n // that actually holds its first tile; the flag keeps a multi-page chunk from\n // being booked once per page.\n if (!this._nodeBooked) {\n this._nodeBooked = true;\n this._batchNodeCount++;\n }\n\n const f32 = this._instanceFloat32;\n const u32 = this._instanceUint32;\n const flipYTexture = texture.flipY;\n const baseWord = nodeIndex & TILE_ROW_MASK;\n\n for (const q of quads) {\n const idx = this._quadIndex * wordsPerInstance;\n\n f32[idx + 0] = q.x0;\n f32[idx + 1] = q.y0;\n f32[idx + 2] = q.x1;\n f32[idx + 3] = q.y1;\n\n const flipX = (q.orient & 1) !== 0;\n const tileFlipY = (q.orient & 2) !== 0;\n const diagonal = (q.orient & 4) !== 0;\n\n const uA = flipX ? q.u1 : q.u0;\n const uB = flipX ? q.u0 : q.u1;\n let vA = tileFlipY ? q.v1 : q.v0;\n let vB = tileFlipY ? q.v0 : q.v1;\n\n if (flipYTexture) {\n const swap = vA;\n vA = vB;\n vB = swap;\n }\n\n const uMin = (uA * 0xffff) & 0xffff;\n const vMin = (vA * 0xffff) & 0xffff;\n const uMax = (uB * 0xffff) & 0xffff;\n const vMax = (vB * 0xffff) & 0xffff;\n\n u32[idx + 4] = uMin | (vMin << 16);\n u32[idx + 5] = uMax | (vMax << 16);\n u32[idx + 6] = tintRgba;\n u32[idx + 7] = (diagonal ? baseWord | TILE_DIAGONAL_BIT : baseWord) >>> 0;\n\n this._quadIndex++;\n }\n\n if (nodeIndex > this._maxNodeIndex) {\n this._maxNodeIndex = nodeIndex;\n }\n }\n\n public flush(): void {\n const backend = this._backend;\n const device = this._device;\n const uniformBuffer = this._uniformBuffer;\n\n if (!backend || !device || !uniformBuffer) {\n return;\n }\n\n if (this._quadIndex === 0 && !backend.clearRequested) {\n return;\n }\n\n // ProjectionUniforms layout: mat4x4 projection + mat4x4 group + vec4 snap\n // viewport, packed via the shared canonical (non-transposed) column order\n // (same layout as the sprite/nine-slice renderers' group UBO). The write\n // is skipped when the UBO already holds this exact\n // (view, updateId, group bytes, snap-rect) state.\n const view = backend.view;\n const viewportChanged = packSnapViewport(backend, this._projectionData, 32);\n const projectionChanged =\n !this._hasWrittenProjection ||\n this._writtenView !== view ||\n this._writtenViewUpdateId !== view.updateId ||\n viewportChanged ||\n this._groupContentChanged(backend);\n\n const scissor = backend.getScissorRect();\n const maskClipsAll = scissor !== null && (scissor.width <= 0 || scissor.height <= 0);\n\n const coordinator = backend.passCoordinator;\n // Aliased as consts so the `willDraw` predicate narrows them for the draw\n // block below (the same narrowing the inlined condition used to provide).\n const texture = this._currentTexture;\n const blendMode = this._currentBlendMode;\n const indexBuffer = this._indexBuffer;\n const willDraw = this._quadIndex > 0 && !maskClipsAll && texture !== null && blendMode !== null && indexBuffer !== null;\n\n const flushBytes = this._quadIndex * instanceStrideBytes;\n // Sized for everything this pass has taken SO FAR plus this flush, captured\n // BEFORE the guard below may reset the cursor - and used to size the buffer\n // even when it does split. Sizing to the lone flush that remains after a\n // split would peg the buffer at one flush forever: the guard would split,\n // the split would shrink the requirement back, the capacity would never\n // ratchet, and every flush would open its own pass again.\n const targetInstanceBytes = this._instancePassBytes + flushBytes;\n const ownDrawsInPass = this._passDraws !== null && this._passDraws === coordinator.activePass;\n\n // Two predicates, deliberately different. The first gates the hazards\n // against resources only THIS renderer binds - the projection UBO (rewritten\n // at offset 0, which would retroactively re-project our earlier draws) and\n // the instance buffer (whose reallocation frees what those draws read) - so\n // it asks this renderer's own cursor. The second gates the two SHARED ones\n // (transform storage, managed texture content), which the pass may hold\n // another renderer's draws against, so it asks the coordinator. Both land on\n // the queue timeline ahead of the deferred submit, and both are answered by\n // ending (submitting) the pass first.\n if (\n (ownDrawsInPass && (projectionChanged || (willDraw && targetInstanceBytes > this._instanceBufferCapacity))) ||\n (willDraw && coordinator.passHasDraws && (backend.textureUploadWouldMutate(texture) || backend.transformStorageWouldGrow(this._maxNodeIndex + 1)))\n ) {\n coordinator.endPass();\n }\n\n // Any boundary above - or one another renderer hit since our last flush -\n // means the open pass no longer holds our draws, so the cursor restarts.\n if (this._passDraws !== coordinator.activePass) {\n this._passDraws = null;\n this._instancePassBytes = 0;\n }\n\n if (projectionChanged) {\n packAffineMat4(view.getTransform(), this._projectionData, 0);\n packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, this._projectionData, 16);\n\n this._writtenView = view;\n this._writtenViewUpdateId = view.updateId;\n this._hasWrittenProjection = true;\n\n device.queue.writeBuffer(uniformBuffer, 0, this._projectionData.buffer, this._projectionData.byteOffset, this._projectionData.byteLength);\n }\n\n // A flush whose quads are entirely clipped away by the mask draws nothing,\n // so it only needs a pass at all when a clear is still pending - opened\n // here so `createColorAttachment` consumes the clear-state once. With no\n // clear pending, skip `acquirePass` entirely rather than open (and count)\n // a pass no draw will land in.\n if (willDraw || backend.clearRequested) {\n const active = coordinator.acquirePass();\n const pass = active.pass;\n\n if (willDraw) {\n const instanceBuffer = this._ensureInstanceBufferCapacity(device, targetInstanceBytes);\n const instanceByteOffset = this._instancePassBytes;\n\n device.queue.writeBuffer(instanceBuffer, instanceByteOffset, this._instanceData, 0, flushBytes);\n\n const storage = backend.getTransformStorageBuffer(this._maxNodeIndex + 1);\n const transformBindGroup = this._getOrCreateTransformBindGroup(device, uniformBuffer, storage.buffer);\n const textureBindGroup = this._getOrCreateTextureBindGroup(device, backend, texture);\n\n const stencil = coordinator.stencilActive;\n const pipeline = this._getPipeline(blendMode, backend.renderTargetFormat, stencil);\n\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, transformBindGroup);\n pass.setBindGroup(1, textureBindGroup);\n pass.setVertexBuffer(0, instanceBuffer, instanceByteOffset);\n pass.setIndexBuffer(indexBuffer, 'uint16');\n pass.drawIndexed(indicesPerInstance, this._quadIndex, 0, 0, 0);\n\n // The pass stays open; the cursor carries this flush's consumption forward\n // so the next flush in the same pass appends AFTER the slice these draws\n // read instead of overwriting it.\n this._instancePassBytes = instanceByteOffset + flushBytes;\n this._passDraws = active;\n coordinator.markPassDraws();\n backend.stats.batches++;\n backend.stats.drawCalls++;\n }\n }\n\n // Retained capture: while a capture window is active, additionally stage\n // this batch's exact packed bytes into the group-owned bundle - the\n // recorded data IS the drawn data, byte-identical by construction.\n // Recorded regardless of the live visibility decision above (mask/\n // scissor), since visibility is re-evaluated live at replay. A batch\n // always binds a single tileset texture (slot 0); a pixel-snapped node\n // already poisoned the capture in render().\n if (this._quadIndex > 0 && backend._retainedCaptureActive && blendMode !== null && texture !== null) {\n this._recordTextures[0] = texture;\n backend.recordRetainedBatch(this, this._instanceData, flushBytes, this._quadIndex, blendMode, this._recordTextures, 1, null, null, this._batchNodeCount);\n }\n\n // The pass is deliberately left OPEN. It ends at genuine boundaries only\n // (the backend's frame/plan end, a target or view switch, a stencil clip)\n // and at the hazard splits above, so N tile-chunk flushes in a frame cost\n // one pass and one submit rather than N.\n this._quadIndex = 0;\n this._maxNodeIndex = 0;\n this._batchNodeCount = 0;\n this._currentBlendMode = null;\n this._currentTexture = null;\n }\n\n /**\n * Whether the packed floats of the active group matrix differ from what the\n * shared projection UBO currently holds at [16, 32). Stages the packed matrix\n * into `_stagedGroupData` as a side effect (idempotent - safe to call more\n * than once per flush).\n */\n private _groupContentChanged(backend: WebGpuBackend): boolean {\n packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, this._stagedGroupData, 0);\n\n if (!this._hasWrittenProjection) {\n return true;\n }\n\n return packedGroupChanged(this._stagedGroupData, this._projectionData, 16);\n }\n\n public destroy(): void {\n this.disconnect();\n }\n\n private _getOrCreateTransformBindGroup(device: GPUDevice, uniformBuffer: GPUBuffer, storageBuffer: GPUBuffer): GPUBindGroup {\n if (this._transformBindGroup !== null && this._transformStorageBuffer === storageBuffer) {\n return this._transformBindGroup;\n }\n\n this._transformStorageBuffer = storageBuffer;\n this._transformBindGroup = device.createBindGroup({\n layout: this._uniformBindGroupLayout!,\n entries: [\n { binding: 0, resource: { buffer: uniformBuffer } },\n { binding: 1, resource: { buffer: storageBuffer } },\n ],\n });\n\n return this._transformBindGroup;\n }\n\n /**\n * Build (or reuse) the group(1) texture bind group for `texture`. The\n * binding is resolved BEFORE the cache lookup on purpose: resolving is what\n * syncs a dirty/mutated texture's content to the GPU, so it must run every\n * flush/replay even when the bind group itself is served from cache.\n */\n private _getOrCreateTextureBindGroup(device: GPUDevice, backend: WebGpuBackend, texture: Texture | RenderTexture): GPUBindGroup {\n const { view, sampler } = backend.getTextureBinding(texture);\n const premultiply = backend.shouldPremultiplyTextureSample(texture);\n const cached = this._textureBindGroups.get(texture);\n\n if (cached?.view === view && cached.sampler === sampler && cached.premultiply === premultiply) {\n return cached.group;\n }\n\n const group = device.createBindGroup({\n layout: this._textureBindGroupLayout!,\n entries: [\n { binding: 0, resource: view },\n { binding: 1, resource: sampler },\n { binding: 2, resource: { buffer: this._sampleAlphaBuffers[premultiply ? 1 : 0]! } },\n ],\n });\n\n this._textureBindGroups.set(texture, { group, view, sampler, premultiply });\n\n return group;\n }\n\n // ── Retained-batch record/replay ──────────────────────────────────────────\n // The bundle/stage stores raw instance bytes; this renderer owns the\n // 32-byte (8-word) layout (tile word at word 7: transform row in bits\n // 0..28, diagonal flip in bit 29), so the layout-aware finalize steps\n // (node-index scan/rebase) and the replay dispatch live here - mirroring\n // WebGpuNineSliceSpriteRenderer's seam.\n\n /** @internal See {@link WebGpuRetainedBatchReplayer.scanRetainedNodeIndexRange}. */\n public scanRetainedNodeIndexRange(bytes: Uint8Array, range: WebGpuRetainedNodeIndexRange): void {\n const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Uint32Array.BYTES_PER_ELEMENT);\n\n for (let i = 7; i < words.length; i += 8) {\n // In-bounds: i < words.length via the loop guard. The tile word is the\n // last word of the 32-byte (8-word) instance layout; only the low 29\n // bits address the transform buffer row.\n const row = words[i]! & TILE_ROW_MASK;\n\n if (row < range.min) {\n range.min = row;\n }\n\n if (row > range.max) {\n range.max = row;\n }\n }\n }\n\n /** @internal See {@link WebGpuRetainedBatchReplayer.rebaseRetainedNodeIndices} (group-local indices). */\n public rebaseRetainedNodeIndices(bytes: Uint8Array, base: number): void {\n const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Uint32Array.BYTES_PER_ELEMENT);\n\n for (let i = 7; i < words.length; i += 8) {\n // In-bounds: i < words.length via the loop guard. Rebase ONLY the row\n // field; the diagonal-flip bit must survive untouched or tile\n // orientation corrupts.\n const word = words[i]!;\n const diagonal = word & TILE_DIAGONAL_BIT;\n const row = word & TILE_ROW_MASK;\n\n words[i] = (diagonal | ((row - base) & TILE_ROW_MASK)) >>> 0;\n }\n }\n\n /**\n * Replay one recorded batch from its group-owned bundle into the OPEN pass.\n * Reuses only recorded DATA (instance bytes, transform rows, texture, blend\n * mode); every piece of STATE is resolved live - pipeline via the\n * `_getPipeline` cache, the group(1) texture bind group via the live\n * texture-set cache (resolving re-syncs dirty content), and the group's\n * 128-byte UBO (projection from the live view + the live composed group\n * matrix) written only when its content changed. The same-frame\n * double-replay hazard (one group under two views while the open pass\n * already holds this bundle's draws) ends the pass first.\n * @internal\n */\n public replayRetainedBatch(payload: WebGpuRetainedBatchPayload): void {\n const backend = this._backend;\n const device = this._device;\n const bundle = payload.bundle;\n\n if (!backend || !device || this._indexBuffer === null || !bundle.isReady) {\n return;\n }\n\n // Drain any pending live batch first (defensive - the group boundary\n // already flushed; flush() is a no-op when nothing is pending).\n this.flush();\n\n // Match the live path's visibility handling: a fully-clipped scissor\n // draws nothing (the batch stays recorded; visibility is live per frame).\n const scissor = backend.getScissorRect();\n\n if (scissor !== null && (scissor.width <= 0 || scissor.height <= 0)) {\n return;\n }\n\n const coordinator = backend.passCoordinator;\n\n // Same-frame texture mutation guard: resolving the bindings below\n // re-uploads mutated content on the queue timeline BEFORE the deferred\n // submit, which would retroactively change draws already recorded into\n // the open pass. End (submit) the pass first so they keep the\n // pre-mutation content. The texture cache is shared and the pass survives\n // a renderer switch, so any recorded draw is at risk, not just one of ours.\n if (coordinator.passHasDraws) {\n for (const texture of payload.textures) {\n if (backend.textureUploadWouldMutate(texture)) {\n coordinator.endPass();\n break;\n }\n }\n }\n\n // Resolve the single tileset texture LIVE through the texture bind-group\n // cache (syncs dirty content, adopts refreshed views/samplers). The\n // recorded batch always has exactly one texture (slot 0).\n const textureBindGroup = this._getOrCreateTextureBindGroup(device, backend, payload.textures[0]!);\n\n // Group UBO: skip the write while (view, updateId, group bytes) match\n // what the buffer holds; guard the double-replay aliasing case first.\n const view = backend.view;\n const scratch = this._stagedReplayGroupData;\n\n packAffineMat4(backend.renderGroupTransform ?? Matrix.identity, scratch, 0);\n\n // Staged unconditionally: an unchanged rect makes this an identity write,\n // while a changed one forces the rewrite the skip state cannot see.\n const viewportChanged = packSnapViewport(backend, bundle.uboData, 32);\n\n let uboDirty = !bundle.uboWritten || bundle.uboView !== view || bundle.uboViewUpdateId !== view.updateId || viewportChanged;\n\n if (!uboDirty) {\n for (let i = 0; i < 16; i++) {\n if (scratch[i] !== bundle.uboData[16 + i]) {\n uboDirty = true;\n break;\n }\n }\n }\n\n if (uboDirty) {\n const activePass = coordinator.activePass;\n\n if (activePass !== null && bundle.drawsInPass === activePass) {\n // Rewriting the UBO would retroactively re-project this bundle's\n // draws already recorded into the open pass: end it first.\n coordinator.endPass();\n }\n\n packAffineMat4(view.getTransform(), bundle.uboData, 0);\n bundle.uboData.set(scratch, 16);\n bundle.uboView = view;\n bundle.uboViewUpdateId = view.updateId;\n bundle.uboWritten = true;\n device.queue.writeBuffer(bundle.uniformBuffer!, 0, bundle.uboData.buffer, bundle.uboData.byteOffset, retainedGroupUniformBytes);\n }\n\n const active = coordinator.acquirePass();\n const pass = active.pass;\n\n const nativePipeline = this._getPipeline(payload.blendMode, backend.renderTargetFormat, coordinator.stencilActive);\n const nativeFrameBindGroup = bundle.getBindGroup(device, this._uniformBindGroupLayout!, false);\n\n const nativeCompatible = backend.colorAttachmentCount === 1;\n if (!nativeCompatible) bundle.nativeReplay.skipPass();\n\n if (\n !nativeCompatible ||\n !bundle.nativeReplay.draw(\n device,\n active,\n payload,\n backend.renderTargetFormat,\n nativePipeline,\n nativeFrameBindGroup,\n textureBindGroup,\n this._indexBuffer,\n 'uint16',\n indicesPerInstance,\n payload.instanceCount,\n )\n ) {\n pass.setPipeline(nativePipeline);\n pass.setBindGroup(0, nativeFrameBindGroup);\n pass.setBindGroup(1, textureBindGroup);\n pass.setVertexBuffer(0, bundle.instanceBuffer, payload.byteOffset);\n pass.setIndexBuffer(this._indexBuffer, 'uint16');\n pass.drawIndexed(indicesPerInstance, payload.instanceCount, 0, 0, 0);\n }\n\n bundle.drawsInPass = active;\n coordinator.markPassDraws();\n backend.stats.batches++;\n backend.stats.drawCalls++;\n }\n\n private _getPipeline(blendMode: BlendModes, format: GPUTextureFormat, stencil: boolean): GPURenderPipeline {\n const key = `${blendMode}:${format}:${stencil ? 's' : 'n'}`;\n const existing = this._pipelines.get(key);\n\n if (existing) {\n return existing;\n }\n\n if (!this._device || !this._shaderModule || !this._pipelineLayout) {\n throw new Error('WebGpuTileChunkRenderer: renderer must be connected first.');\n }\n\n const descriptor: GPURenderPipelineDescriptor = {\n layout: this._pipelineLayout,\n vertex: {\n module: this._shaderModule,\n entryPoint: 'vertexMain',\n buffers: [\n {\n arrayStride: instanceStrideBytes,\n stepMode: 'instance',\n attributes: [\n { shaderLocation: 0, offset: 0, format: 'float32x4' },\n { shaderLocation: 1, offset: 16, format: 'unorm16x4' },\n { shaderLocation: 2, offset: 24, format: 'unorm8x4' },\n { shaderLocation: 3, offset: 28, format: 'uint32' },\n ],\n },\n ],\n },\n fragment: {\n module: this._shaderModule,\n entryPoint: 'fragmentMain',\n targets: [\n {\n format,\n blend: getWebGpuBlendState(blendMode),\n writeMask: GPUColorWrite.ALL,\n },\n ],\n },\n primitive: {\n topology: 'triangle-list',\n },\n };\n\n if (stencil) {\n descriptor.depthStencil = stencilContentDepthStencilState();\n }\n\n const pipeline = this._device.createRenderPipeline(descriptor);\n\n this._pipelines.set(key, pipeline);\n\n return pipeline;\n }\n\n /**\n * Grow the CPU staging array to hold `instanceCount` instances, carrying the\n * quads packed so far. Flush-local: the array only ever holds the pending\n * batch, so it is sized independently of the pass-scoped GPU buffer.\n */\n private _ensureStagingCapacity(instanceCount: number): void {\n if (instanceCount <= this._instanceStagingCapacity) {\n return;\n }\n\n let nextCapacity = Math.max(this._instanceStagingCapacity, initialBatchCapacity);\n\n while (nextCapacity < instanceCount) {\n nextCapacity *= 2;\n }\n\n const oldData = this._instanceData;\n const carryBytes = Math.min(this._quadIndex * instanceStrideBytes, oldData.byteLength);\n const instanceData = new ArrayBuffer(nextCapacity * instanceStrideBytes);\n\n if (carryBytes > 0) {\n new Uint8Array(instanceData).set(new Uint8Array(oldData, 0, carryBytes));\n }\n\n this._instanceStagingCapacity = nextCapacity;\n this._instanceData = instanceData;\n this._instanceFloat32 = new Float32Array(instanceData);\n this._instanceUint32 = new Uint32Array(instanceData);\n }\n\n /**\n * Resolve the GPU instance buffer for `requiredBytes` - the total this pass\n * would reach by appending, not this flush's own bytes. Reallocation frees the\n * buffer earlier draws in the open pass read, so the caller must have ended\n * that pass (and restarted the cursor) before a growing call. Capacity\n * doubles, so the split a growth costs converges away within a frame or two.\n */\n private _ensureInstanceBufferCapacity(device: GPUDevice, requiredBytes: number): GPUBuffer {\n const existing = this._instanceBuffer;\n\n if (existing !== null && requiredBytes <= this._instanceBufferCapacity) {\n return existing;\n }\n\n const nextCapacity = Math.max(this._instanceBufferCapacity * 2, requiredBytes, initialBatchCapacity * instanceStrideBytes);\n const instanceBuffer = device.createBuffer({\n label: 'tile-chunk:instance-buffer',\n size: nextCapacity,\n usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,\n });\n\n existing?.destroy();\n\n this._instanceBufferCapacity = nextCapacity;\n this._instanceBuffer = instanceBuffer;\n\n return instanceBuffer;\n }\n}\n"],"mappings":";;;;;;AAgCA,MAAM,sBAAsB;AAC5B,MAAM,mBAAmB,sBAAsB,YAAY;AAE3D,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB;AAC3B,MAAM,cAAc,IAAI,YAAY;CAAC;CAAG;CAAG;CAAG;CAAG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forms {\nmatrix: mat4x4<f32>,\ngroup: mat4x4<f32>,\nviewport: vec4<f32>,\n};\nstruct TransformSlot {\nm0: vec4<f32>,\nm1: vec4<f32>,\n};\n@group(0) @binding(0)\nvar<uniform> projection: ProjectionUniforms;\n@group(0) @binding(1)\nvar<storage, read> transforms: array<TransformSlot>;\n@group(1) @binding(0)\nvar tileTexture: texture_2d<f32>;\n@group(1) @binding(1)\nvar tileSampler: sampler;\n@group(1) @binding(2)\nvar<uniform> sampleAlpha: vec4<f32>;\nstruct VertexInput {\n@location(0) quadBounds: vec4<f32>,\n@location(1) uvBounds: vec4<f32>,\n@location(2) color: vec4<f32>,\n@location(3) tileWord: u32,\n};\nstruct VertexOutput {\n@builtin(position) position: vec4<f32>,\n@location(0) texcoord: vec2<f32>,\n@location(1) color: vec4<f32>,\n};\n@vertex\nfn vertexMain(input: VertexInput, @builtin(vertex_index) vid: u32) -> VertexOutput {\nvar output: VertexOutput;\nlet cornerX = ((vid + 1u) >> 1u) & 1u;\nlet cornerY = vid >> 1u;\nlet localX = select(input.quadBounds.x, input.quadBounds.z, cornerX == 1u);\nlet localY = select(input.quadBounds.y, input.quadBounds.w, cornerY == 1u);\nlet row = input.tileWord & {{tileRowMask}}u;\nlet diagonal = (input.tileWord & {{tileDiagonalBit}}u) != 0u;\nlet slot = transforms[row];\nlet worldX = slot.m0.x * localX + slot.m0.y * localY + slot.m1.x;\nlet worldY = slot.m0.z * localX + slot.m0.w * localY + slot.m1.y;\nvar position = projection.matrix * projection.group * vec4<f32>(worldX, worldY, 0.0, 1.0);\nif (slot.m1.z != 0.0) {\nlet originClip = projection.matrix * projection.group * vec4<f32>(slot.m1.x, slot.m1.y, 0.0, 1.0);\nlet originDevice = projection.viewport.xy + (originClip.xy * 0.5 + vec2<f32>(0.5)) * projection.viewport.zw;\nlet snapDelta = (floor(originDevice + vec2<f32>(0.5)) - originDevice) * 2.0 / max(projection.viewport.zw, vec2<f32>(1.0));\nposition = vec4<f32>(position.xy + snapDelta, position.z, position.w);\n}\noutput.position = position;\nvar su = cornerX;\nvar sv = cornerY;\nif (diagonal) {\nlet t = su;\nsu = sv;\nsv = t;\n}\nlet u = select(input.uvBounds.x, input.uvBounds.z, su == 1u);\nlet v = select(input.uvBounds.y, input.uvBounds.w, sv == 1u);\noutput.texcoord = vec2<f32>(u, v);\nlet linearTint = srgbToLinear(input.color.rgb);\noutput.color = vec4(linearTint * input.color.a, input.color.a);\nreturn output;\n}\n@fragment\nfn fragmentMain(input: VertexOutput) -> @location(0) vec4<f32> {\nlet sample = textureSample(tileTexture, tileSampler, input.texcoord);\nlet rgb = select(sample.rgb, sample.rgb * sample.a, sampleAlpha.x != 0.0);\nreturn vec4<f32>(rgb, sample.a) * input.color;\n}";
3
-
4
- //#endregion
5
- export { tile_chunk_default as default };
6
- //# sourceMappingURL=tile-chunk.wgsl.js.map