@forgeax/engine-rhi-debug 0.0.0-dev.8d955ade1c79

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 (237) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +178 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/bootstrap-integration.test.d.ts +2 -0
  5. package/dist/__tests__/bootstrap-integration.test.d.ts.map +1 -0
  6. package/dist/__tests__/consumer-inventory.unit.test.d.ts +2 -0
  7. package/dist/__tests__/consumer-inventory.unit.test.d.ts.map +1 -0
  8. package/dist/__tests__/copy-src-usage-validity.dawn.test.d.ts +15 -0
  9. package/dist/__tests__/copy-src-usage-validity.dawn.test.d.ts.map +1 -0
  10. package/dist/__tests__/coverage-invariant.test-d.d.ts +2 -0
  11. package/dist/__tests__/coverage-invariant.test-d.d.ts.map +1 -0
  12. package/dist/__tests__/coverage-invariant.unit.test.d.ts +2 -0
  13. package/dist/__tests__/coverage-invariant.unit.test.d.ts.map +1 -0
  14. package/dist/__tests__/e2e.browser.test.d.ts +2 -0
  15. package/dist/__tests__/e2e.browser.test.d.ts.map +1 -0
  16. package/dist/__tests__/error-code-narrowing.test-d.d.ts +2 -0
  17. package/dist/__tests__/error-code-narrowing.test-d.d.ts.map +1 -0
  18. package/dist/__tests__/errors-v7.test-d.d.ts +2 -0
  19. package/dist/__tests__/errors-v7.test-d.d.ts.map +1 -0
  20. package/dist/__tests__/errors-v7.unit.test.d.ts +2 -0
  21. package/dist/__tests__/errors-v7.unit.test.d.ts.map +1 -0
  22. package/dist/__tests__/errors.unit.test.d.ts +2 -0
  23. package/dist/__tests__/errors.unit.test.d.ts.map +1 -0
  24. package/dist/__tests__/event-semantics-coverage.unit.test.d.ts +2 -0
  25. package/dist/__tests__/event-semantics-coverage.unit.test.d.ts.map +1 -0
  26. package/dist/__tests__/format-info.unit.test.d.ts +2 -0
  27. package/dist/__tests__/format-info.unit.test.d.ts.map +1 -0
  28. package/dist/__tests__/frame-model-parity.test-d.d.ts +2 -0
  29. package/dist/__tests__/frame-model-parity.test-d.d.ts.map +1 -0
  30. package/dist/__tests__/frame-model-parity.unit.test.d.ts +2 -0
  31. package/dist/__tests__/frame-model-parity.unit.test.d.ts.map +1 -0
  32. package/dist/__tests__/guard-gates.test.d.ts +2 -0
  33. package/dist/__tests__/guard-gates.test.d.ts.map +1 -0
  34. package/dist/__tests__/public-surface.integration.test.d.ts +2 -0
  35. package/dist/__tests__/public-surface.integration.test.d.ts.map +1 -0
  36. package/dist/__tests__/readback-fault-cleanup.unit.test.d.ts +2 -0
  37. package/dist/__tests__/readback-fault-cleanup.unit.test.d.ts.map +1 -0
  38. package/dist/__tests__/readback-format-matrix.dawn.test.d.ts +2 -0
  39. package/dist/__tests__/readback-format-matrix.dawn.test.d.ts.map +1 -0
  40. package/dist/__tests__/readback-format-matrix.unit.test.d.ts +2 -0
  41. package/dist/__tests__/readback-format-matrix.unit.test.d.ts.map +1 -0
  42. package/dist/__tests__/readback-matrix-fixture.d.ts +32 -0
  43. package/dist/__tests__/readback-matrix-fixture.d.ts.map +1 -0
  44. package/dist/__tests__/recorder-bootstrap.unit.test.d.ts +2 -0
  45. package/dist/__tests__/recorder-bootstrap.unit.test.d.ts.map +1 -0
  46. package/dist/__tests__/recorder-budget.unit.test.d.ts +2 -0
  47. package/dist/__tests__/recorder-budget.unit.test.d.ts.map +1 -0
  48. package/dist/__tests__/recorder-fail-fast.unit.test.d.ts +2 -0
  49. package/dist/__tests__/recorder-fail-fast.unit.test.d.ts.map +1 -0
  50. package/dist/__tests__/recorder-lifecycle.unit.test.d.ts +2 -0
  51. package/dist/__tests__/recorder-lifecycle.unit.test.d.ts.map +1 -0
  52. package/dist/__tests__/recorder-push-event.unit.test.d.ts +2 -0
  53. package/dist/__tests__/recorder-push-event.unit.test.d.ts.map +1 -0
  54. package/dist/__tests__/recorder-session.integration.test.d.ts +2 -0
  55. package/dist/__tests__/recorder-session.integration.test.d.ts.map +1 -0
  56. package/dist/__tests__/recorder-session.unit.test.d.ts +2 -0
  57. package/dist/__tests__/recorder-session.unit.test.d.ts.map +1 -0
  58. package/dist/__tests__/recorder-steady-frame.dawn.test.d.ts +2 -0
  59. package/dist/__tests__/recorder-steady-frame.dawn.test.d.ts.map +1 -0
  60. package/dist/__tests__/replay-fail-fast.unit.test.d.ts +2 -0
  61. package/dist/__tests__/replay-fail-fast.unit.test.d.ts.map +1 -0
  62. package/dist/__tests__/replay-session.dawn.test.d.ts +2 -0
  63. package/dist/__tests__/replay-session.dawn.test.d.ts.map +1 -0
  64. package/dist/__tests__/replay-session.test-d.d.ts +2 -0
  65. package/dist/__tests__/replay-session.test-d.d.ts.map +1 -0
  66. package/dist/__tests__/replay-session.unit.test.d.ts +2 -0
  67. package/dist/__tests__/replay-session.unit.test.d.ts.map +1 -0
  68. package/dist/__tests__/resolve-texture-descriptor.unit.test.d.ts +2 -0
  69. package/dist/__tests__/resolve-texture-descriptor.unit.test.d.ts.map +1 -0
  70. package/dist/__tests__/resource-lifecycle.unit.test.d.ts +2 -0
  71. package/dist/__tests__/resource-lifecycle.unit.test.d.ts.map +1 -0
  72. package/dist/__tests__/rhi-debug-fresh-replay.dawn.test.d.ts +2 -0
  73. package/dist/__tests__/rhi-debug-fresh-replay.dawn.test.d.ts.map +1 -0
  74. package/dist/__tests__/tape-index.unit.test.d.ts +2 -0
  75. package/dist/__tests__/tape-index.unit.test.d.ts.map +1 -0
  76. package/dist/__tests__/tape-v7-invalid.unit.test.d.ts +2 -0
  77. package/dist/__tests__/tape-v7-invalid.unit.test.d.ts.map +1 -0
  78. package/dist/__tests__/tape-v7-roundtrip.unit.test.d.ts +2 -0
  79. package/dist/__tests__/tape-v7-roundtrip.unit.test.d.ts.map +1 -0
  80. package/dist/__tests__/tape-v7-version.unit.test.d.ts +2 -0
  81. package/dist/__tests__/tape-v7-version.unit.test.d.ts.map +1 -0
  82. package/dist/__tests__/tree-shake.unit.test.d.ts +2 -0
  83. package/dist/__tests__/tree-shake.unit.test.d.ts.map +1 -0
  84. package/dist/__tests__/types.test.d.ts +2 -0
  85. package/dist/__tests__/types.test.d.ts.map +1 -0
  86. package/dist/browser.d.ts +45 -0
  87. package/dist/browser.d.ts.map +1 -0
  88. package/dist/browser.mjs +83 -0
  89. package/dist/browser.mjs.map +1 -0
  90. package/dist/errors.d.ts +85 -0
  91. package/dist/errors.d.ts.map +1 -0
  92. package/dist/frame-model.d.ts +158 -0
  93. package/dist/frame-model.d.ts.map +1 -0
  94. package/dist/index.d.ts +17 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.mjs +10415 -0
  97. package/dist/index.mjs.map +1 -0
  98. package/dist/protocol/codec.d.ts +6 -0
  99. package/dist/protocol/codec.d.ts.map +1 -0
  100. package/dist/protocol/event-semantics.d.ts +15 -0
  101. package/dist/protocol/event-semantics.d.ts.map +1 -0
  102. package/dist/protocol/tape-index.d.ts +30 -0
  103. package/dist/protocol/tape-index.d.ts.map +1 -0
  104. package/dist/protocol/types.d.ts +44 -0
  105. package/dist/protocol/types.d.ts.map +1 -0
  106. package/dist/protocol/validation.d.ts +7 -0
  107. package/dist/protocol/validation.d.ts.map +1 -0
  108. package/dist/readback.d.ts +156 -0
  109. package/dist/readback.d.ts.map +1 -0
  110. package/dist/recorder/assemble.d.ts +11 -0
  111. package/dist/recorder/assemble.d.ts.map +1 -0
  112. package/dist/recorder/closure.d.ts +39 -0
  113. package/dist/recorder/closure.d.ts.map +1 -0
  114. package/dist/recorder/core.d.ts +296 -0
  115. package/dist/recorder/core.d.ts.map +1 -0
  116. package/dist/recorder/device.d.ts +4 -0
  117. package/dist/recorder/device.d.ts.map +1 -0
  118. package/dist/recorder/encoder.d.ts +5 -0
  119. package/dist/recorder/encoder.d.ts.map +1 -0
  120. package/dist/recorder/lifecycle.d.ts +20 -0
  121. package/dist/recorder/lifecycle.d.ts.map +1 -0
  122. package/dist/recorder/pass.d.ts +6 -0
  123. package/dist/recorder/pass.d.ts.map +1 -0
  124. package/dist/recorder/proxy.d.ts +19 -0
  125. package/dist/recorder/proxy.d.ts.map +1 -0
  126. package/dist/recorder/queue.d.ts +4 -0
  127. package/dist/recorder/queue.d.ts.map +1 -0
  128. package/dist/recorder/resource-registry.d.ts +15 -0
  129. package/dist/recorder/resource-registry.d.ts.map +1 -0
  130. package/dist/recorder/session.d.ts +25 -0
  131. package/dist/recorder/session.d.ts.map +1 -0
  132. package/dist/recorder/shader.d.ts +3 -0
  133. package/dist/recorder/shader.d.ts.map +1 -0
  134. package/dist/recorder/snapshot.d.ts +10 -0
  135. package/dist/recorder/snapshot.d.ts.map +1 -0
  136. package/dist/recorder/wrap.d.ts +4 -0
  137. package/dist/recorder/wrap.d.ts.map +1 -0
  138. package/dist/recorder.d.ts +7 -0
  139. package/dist/recorder.d.ts.map +1 -0
  140. package/dist/replay/device-request.d.ts +8 -0
  141. package/dist/replay/device-request.d.ts.map +1 -0
  142. package/dist/replay/execute-support.d.ts +33 -0
  143. package/dist/replay/execute-support.d.ts.map +1 -0
  144. package/dist/replay/execute.d.ts +18 -0
  145. package/dist/replay/execute.d.ts.map +1 -0
  146. package/dist/replay/readback.d.ts +32 -0
  147. package/dist/replay/readback.d.ts.map +1 -0
  148. package/dist/replay/resources.d.ts +57 -0
  149. package/dist/replay/resources.d.ts.map +1 -0
  150. package/dist/replay/session.d.ts +49 -0
  151. package/dist/replay/session.d.ts.map +1 -0
  152. package/dist/replay/texture-format.d.ts +21 -0
  153. package/dist/replay/texture-format.d.ts.map +1 -0
  154. package/dist/texel-decode.d.ts +35 -0
  155. package/dist/texel-decode.d.ts.map +1 -0
  156. package/dist/texel-layout.d.ts +76 -0
  157. package/dist/texel-layout.d.ts.map +1 -0
  158. package/dist/types.d.ts +722 -0
  159. package/dist/types.d.ts.map +1 -0
  160. package/package.json +72 -0
  161. package/src/__tests__/bootstrap-integration.test.ts +268 -0
  162. package/src/__tests__/consumer-inventory.unit.test.ts +154 -0
  163. package/src/__tests__/copy-src-usage-validity.dawn.test.ts +117 -0
  164. package/src/__tests__/coverage-invariant.test-d.ts +115 -0
  165. package/src/__tests__/coverage-invariant.unit.test.ts +45 -0
  166. package/src/__tests__/e2e.browser.test.ts +239 -0
  167. package/src/__tests__/error-code-narrowing.test-d.ts +32 -0
  168. package/src/__tests__/errors-v7.test-d.ts +19 -0
  169. package/src/__tests__/errors-v7.unit.test.ts +15 -0
  170. package/src/__tests__/errors.unit.test.ts +83 -0
  171. package/src/__tests__/event-semantics-coverage.unit.test.ts +22 -0
  172. package/src/__tests__/format-info.unit.test.ts +85 -0
  173. package/src/__tests__/frame-model-parity.test-d.ts +20 -0
  174. package/src/__tests__/frame-model-parity.unit.test.ts +285 -0
  175. package/src/__tests__/guard-gates.test.ts +317 -0
  176. package/src/__tests__/public-surface.integration.test.ts +38 -0
  177. package/src/__tests__/readback-fault-cleanup.unit.test.ts +66 -0
  178. package/src/__tests__/readback-format-matrix.dawn.test.ts +378 -0
  179. package/src/__tests__/readback-format-matrix.unit.test.ts +120 -0
  180. package/src/__tests__/readback-matrix-fixture.ts +20 -0
  181. package/src/__tests__/recorder-bootstrap.unit.test.ts +302 -0
  182. package/src/__tests__/recorder-budget.unit.test.ts +42 -0
  183. package/src/__tests__/recorder-fail-fast.unit.test.ts +434 -0
  184. package/src/__tests__/recorder-lifecycle.unit.test.ts +42 -0
  185. package/src/__tests__/recorder-push-event.unit.test.ts +573 -0
  186. package/src/__tests__/recorder-session.integration.test.ts +32 -0
  187. package/src/__tests__/recorder-session.unit.test.ts +63 -0
  188. package/src/__tests__/recorder-steady-frame.dawn.test.ts +52 -0
  189. package/src/__tests__/replay-fail-fast.unit.test.ts +155 -0
  190. package/src/__tests__/replay-session.dawn.test.ts +220 -0
  191. package/src/__tests__/replay-session.test-d.ts +27 -0
  192. package/src/__tests__/replay-session.unit.test.ts +171 -0
  193. package/src/__tests__/resolve-texture-descriptor.unit.test.ts +144 -0
  194. package/src/__tests__/resource-lifecycle.unit.test.ts +114 -0
  195. package/src/__tests__/rhi-debug-fresh-replay.dawn.test.ts +178 -0
  196. package/src/__tests__/tape-index.unit.test.ts +56 -0
  197. package/src/__tests__/tape-v7-invalid.unit.test.ts +45 -0
  198. package/src/__tests__/tape-v7-roundtrip.unit.test.ts +66 -0
  199. package/src/__tests__/tape-v7-version.unit.test.ts +13 -0
  200. package/src/__tests__/tree-shake.unit.test.ts +151 -0
  201. package/src/__tests__/types.test.ts +257 -0
  202. package/src/browser.ts +146 -0
  203. package/src/errors.ts +173 -0
  204. package/src/frame-model.ts +753 -0
  205. package/src/index.ts +92 -0
  206. package/src/pako.d.ts +8 -0
  207. package/src/protocol/codec.ts +220 -0
  208. package/src/protocol/event-semantics.ts +180 -0
  209. package/src/protocol/tape-index.ts +120 -0
  210. package/src/protocol/types.ts +60 -0
  211. package/src/protocol/validation.ts +173 -0
  212. package/src/readback.ts +804 -0
  213. package/src/recorder/assemble.ts +192 -0
  214. package/src/recorder/closure.ts +408 -0
  215. package/src/recorder/core.ts +587 -0
  216. package/src/recorder/device.ts +474 -0
  217. package/src/recorder/encoder.ts +251 -0
  218. package/src/recorder/lifecycle.ts +847 -0
  219. package/src/recorder/pass.ts +241 -0
  220. package/src/recorder/proxy.ts +59 -0
  221. package/src/recorder/queue.ts +109 -0
  222. package/src/recorder/resource-registry.ts +53 -0
  223. package/src/recorder/session.ts +152 -0
  224. package/src/recorder/shader.ts +47 -0
  225. package/src/recorder/snapshot.ts +38 -0
  226. package/src/recorder/wrap.ts +157 -0
  227. package/src/recorder.ts +15 -0
  228. package/src/replay/device-request.ts +38 -0
  229. package/src/replay/execute-support.ts +243 -0
  230. package/src/replay/execute.ts +870 -0
  231. package/src/replay/readback.ts +671 -0
  232. package/src/replay/resources.ts +154 -0
  233. package/src/replay/session.ts +509 -0
  234. package/src/replay/texture-format.ts +99 -0
  235. package/src/texel-decode.ts +289 -0
  236. package/src/texel-layout.ts +324 -0
  237. package/src/types.ts +888 -0
@@ -0,0 +1,251 @@
1
+ // @forgeax/engine-rhi-debug/src/recorder/encoder -- command encoder proxy owner.
2
+
3
+ import type {
4
+ Buffer,
5
+ ComputePassDescriptor,
6
+ RenderPassDescriptor,
7
+ RhiCommandEncoder,
8
+ } from '@forgeax/engine-rhi';
9
+ import type { HandleId } from '../types';
10
+ import type { RecorderInternal } from './core';
11
+ import { allocHandleId, getHandleId, pushEvent } from './core';
12
+ import { createComputePassProxy, createRenderPassProxy } from './pass';
13
+
14
+ export function createCommandEncoderProxy(
15
+ s: RecorderInternal,
16
+ realEnc: RhiCommandEncoder,
17
+ cmdHId: HandleId,
18
+ ): RhiCommandEncoder {
19
+ return {
20
+ beginRenderPass(desc: RenderPassDescriptor) {
21
+ const passHId = allocHandleId('renderPass');
22
+ // I-2 fix-up (round 1, dawn smoke): walk colorAttachments +
23
+ // depthStencilAttachment to extract the textureView handleIds
24
+ // recorded under createTextureView. Without this the replayer
25
+ // would dereference the original GPUTextureView brand directly,
26
+ // which fails on a fresh device (cross-device GPU object reuse).
27
+ const colorAttachmentViewHandleIds: (HandleId | undefined)[] = [];
28
+ const colorAttachmentResolveTargetHandleIds: (HandleId | undefined)[] = [];
29
+ for (const att of desc.colorAttachments) {
30
+ if (att === null || att === undefined) {
31
+ colorAttachmentViewHandleIds.push(undefined);
32
+ colorAttachmentResolveTargetHandleIds.push(undefined);
33
+ } else {
34
+ const view = att.view;
35
+ const id =
36
+ view !== undefined && view !== null ? s.handleMap.get(view as object) : undefined;
37
+ colorAttachmentViewHandleIds.push(id);
38
+ const resolveTarget = att.resolveTarget;
39
+ const resolveTargetId =
40
+ resolveTarget !== undefined && resolveTarget !== null
41
+ ? s.handleMap.get(resolveTarget as object)
42
+ : undefined;
43
+ colorAttachmentResolveTargetHandleIds.push(resolveTargetId);
44
+ }
45
+ }
46
+ let depthStencilViewHandleId: HandleId | undefined;
47
+ if (desc.depthStencilAttachment !== undefined) {
48
+ const dsView = desc.depthStencilAttachment.view;
49
+ if (dsView !== undefined && dsView !== null) {
50
+ depthStencilViewHandleId = s.handleMap.get(dsView as object);
51
+ }
52
+ }
53
+ pushEvent(s, {
54
+ kind: 'beginRenderPass',
55
+ cmdHandleId: cmdHId,
56
+ passHandleId: passHId,
57
+ desc: {
58
+ colorAttachments: Array.from(desc.colorAttachments).map((attachment) =>
59
+ attachment === null || attachment === undefined ? attachment : { ...attachment },
60
+ ),
61
+ ...(desc.depthStencilAttachment === undefined
62
+ ? {}
63
+ : { depthStencilAttachment: { ...desc.depthStencilAttachment } }),
64
+ ...(desc.occlusionQuerySet === undefined
65
+ ? {}
66
+ : { occlusionQuerySet: desc.occlusionQuerySet }),
67
+ ...(desc.timestampWrites === undefined ? {} : { timestampWrites: desc.timestampWrites }),
68
+ ...(desc.maxDrawCount === undefined ? {} : { maxDrawCount: desc.maxDrawCount }),
69
+ },
70
+ colorAttachmentViewHandleIds,
71
+ colorAttachmentResolveTargetHandleIds,
72
+ depthStencilViewHandleId,
73
+ });
74
+ const realPass = realEnc.beginRenderPass(desc);
75
+ return createRenderPassProxy(s, realPass, passHId);
76
+ },
77
+ beginComputePass(desc?: ComputePassDescriptor | undefined) {
78
+ const passHId = allocHandleId('computePass');
79
+ pushEvent(s, {
80
+ kind: 'beginComputePass',
81
+ cmdHandleId: cmdHId,
82
+ passHandleId: passHId,
83
+ desc: desc as Partial<GPUComputePassDescriptor> | undefined,
84
+ });
85
+ const realPass = realEnc.beginComputePass(desc);
86
+ return createComputePassProxy(s, realPass, passHId);
87
+ },
88
+ // Passthrough copy/clear methods (event recording added where types permit)
89
+ copyBufferToBuffer(...args: unknown[]) {
90
+ // Overloaded: 3-arg or 5-arg
91
+ if (typeof args[1] === 'number') {
92
+ // 5-arg form: (source, sourceOffset, destination, destinationOffset, size)
93
+ const sourceId = getHandleId(s, args[0] as object, 'buffer');
94
+ const destinationId = getHandleId(s, args[2] as object, 'buffer');
95
+ pushEvent(s, {
96
+ kind: 'copyBufferToBuffer',
97
+ cmdHandleId: cmdHId,
98
+ sourceHandleId: sourceId,
99
+ sourceOffset: args[1] as number,
100
+ destinationHandleId: destinationId,
101
+ destinationOffset: args[3] as number,
102
+ size: args[4] as number,
103
+ });
104
+ (realEnc.copyBufferToBuffer as (...args: unknown[]) => void)(...args);
105
+ } else {
106
+ // 3-arg form: (source, destination, size?)
107
+ const sourceId = getHandleId(s, args[0] as object, 'buffer');
108
+ const destinationId = getHandleId(s, args[1] as object, 'buffer');
109
+ const size = args[2] as number | undefined;
110
+ pushEvent(s, {
111
+ kind: 'copyBufferToBuffer',
112
+ cmdHandleId: cmdHId,
113
+ sourceHandleId: sourceId,
114
+ sourceOffset: 0,
115
+ destinationHandleId: destinationId,
116
+ destinationOffset: 0,
117
+ size: (size ?? 0) as number,
118
+ });
119
+ realEnc.copyBufferToBuffer(args[0] as Buffer, args[1] as Buffer, size);
120
+ }
121
+ },
122
+ copyBufferToTexture(source, destination, copySize) {
123
+ const bufId = getHandleId(s, (source as { buffer: object }).buffer as object, 'buffer');
124
+ const texId = getHandleId(
125
+ s,
126
+ (destination as { texture: object }).texture as object,
127
+ 'texture',
128
+ );
129
+ const dstPayload: Record<string, unknown> = { textureHandleId: texId };
130
+ if (destination.mipLevel !== undefined) dstPayload.mipLevel = destination.mipLevel;
131
+ if (destination.origin !== undefined) dstPayload.origin = destination.origin;
132
+ if (destination.aspect !== undefined) dstPayload.aspect = destination.aspect;
133
+ pushEvent(s, {
134
+ kind: 'copyBufferToTexture',
135
+ cmdHandleId: cmdHId,
136
+ source: {
137
+ bufferHandleId: bufId,
138
+ offset: source.offset ?? 0,
139
+ bytesPerRow: source.bytesPerRow ?? 0,
140
+ rowsPerImage: source.rowsPerImage ?? 0,
141
+ },
142
+ destination: dstPayload as Omit<GPUTexelCopyTextureInfo, 'texture'> & {
143
+ readonly textureHandleId: HandleId;
144
+ },
145
+ copySize,
146
+ });
147
+ realEnc.copyBufferToTexture(source, destination, copySize);
148
+ },
149
+ copyTextureToBuffer(source, destination, copySize) {
150
+ const texId = getHandleId(s, (source as { texture: object }).texture as object, 'texture');
151
+ const bufId = getHandleId(s, (destination as { buffer: object }).buffer as object, 'buffer');
152
+ const srcPayload: Record<string, unknown> = { textureHandleId: texId };
153
+ if (source.mipLevel !== undefined) srcPayload.mipLevel = source.mipLevel;
154
+ if (source.origin !== undefined) srcPayload.origin = source.origin;
155
+ if (source.aspect !== undefined) srcPayload.aspect = source.aspect;
156
+ pushEvent(s, {
157
+ kind: 'copyTextureToBuffer',
158
+ cmdHandleId: cmdHId,
159
+ source: srcPayload as Omit<GPUTexelCopyTextureInfo, 'texture'> & {
160
+ readonly textureHandleId: HandleId;
161
+ },
162
+ destination: {
163
+ bufferHandleId: bufId,
164
+ offset: destination.offset ?? 0,
165
+ bytesPerRow: destination.bytesPerRow ?? 0,
166
+ rowsPerImage: destination.rowsPerImage ?? 0,
167
+ },
168
+ copySize,
169
+ });
170
+ realEnc.copyTextureToBuffer(source, destination, copySize);
171
+ },
172
+ copyTextureToTexture(source, destination, copySize) {
173
+ const srcTexId = getHandleId(s, (source as { texture: object }).texture as object, 'texture');
174
+ const dstTexId = getHandleId(
175
+ s,
176
+ (destination as { texture: object }).texture as object,
177
+ 'texture',
178
+ );
179
+ const srcPayload: Record<string, unknown> = { textureHandleId: srcTexId };
180
+ if (source.mipLevel !== undefined) srcPayload.mipLevel = source.mipLevel;
181
+ if (source.origin !== undefined) srcPayload.origin = source.origin;
182
+ if (source.aspect !== undefined) srcPayload.aspect = source.aspect;
183
+ const dstPayload: Record<string, unknown> = { textureHandleId: dstTexId };
184
+ if (destination.mipLevel !== undefined) dstPayload.mipLevel = destination.mipLevel;
185
+ if (destination.origin !== undefined) dstPayload.origin = destination.origin;
186
+ if (destination.aspect !== undefined) dstPayload.aspect = destination.aspect;
187
+ pushEvent(s, {
188
+ kind: 'copyTextureToTexture',
189
+ cmdHandleId: cmdHId,
190
+ source: srcPayload as Omit<GPUTexelCopyTextureInfo, 'texture'> & {
191
+ readonly textureHandleId: HandleId;
192
+ },
193
+ destination: dstPayload as Omit<GPUTexelCopyTextureInfo, 'texture'> & {
194
+ readonly textureHandleId: HandleId;
195
+ },
196
+ copySize,
197
+ });
198
+ realEnc.copyTextureToTexture(source, destination, copySize);
199
+ },
200
+ clearBuffer(buffer, offset, size) {
201
+ const bufId = getHandleId(s, buffer as object, 'buffer');
202
+ pushEvent(s, {
203
+ kind: 'clearBuffer',
204
+ cmdHandleId: cmdHId,
205
+ handleId: bufId,
206
+ offset,
207
+ size,
208
+ });
209
+ realEnc.clearBuffer(buffer, offset, size);
210
+ },
211
+ resolveQuerySet(querySet, firstQuery, queryCount, destination, destinationOffset) {
212
+ return realEnc.resolveQuerySet(
213
+ querySet,
214
+ firstQuery,
215
+ queryCount,
216
+ destination,
217
+ destinationOffset,
218
+ );
219
+ },
220
+ writeTimestamp(querySet, queryIndex) {
221
+ realEnc.writeTimestamp(querySet, queryIndex);
222
+ },
223
+ pushDebugGroup(groupLabel) {
224
+ pushEvent(s, { kind: 'pushDebugGroup', cmdHandleId: cmdHId, groupLabel });
225
+ realEnc.pushDebugGroup(groupLabel);
226
+ },
227
+ popDebugGroup() {
228
+ pushEvent(s, { kind: 'popDebugGroup', cmdHandleId: cmdHId });
229
+ realEnc.popDebugGroup();
230
+ },
231
+ insertDebugMarker(markerLabel) {
232
+ pushEvent(s, { kind: 'insertDebugMarker', cmdHandleId: cmdHId, markerLabel });
233
+ realEnc.insertDebugMarker(markerLabel);
234
+ },
235
+ finish() {
236
+ pushEvent(s, { kind: 'finish', cmdHandleId: cmdHId });
237
+ const res = realEnc.finish();
238
+ // I-2 fix-up (round 1, dawn smoke handle-graph integrity):
239
+ // alias the resulting CommandBuffer object to the encoder's
240
+ // cmdHandleId so subsequent queue.submit() handle lookups resolve
241
+ // to the SAME id that the createCommandEncoder/finish event pair
242
+ // declared. Without this, submit would register a fresh handleId
243
+ // for the CommandBuffer object and the tape's handle graph
244
+ // integrity check would reject the tape on deserialize.
245
+ if (res.ok) {
246
+ s.handleMap.set(res.value as object, cmdHId);
247
+ }
248
+ return res;
249
+ },
250
+ };
251
+ }