space-data-module-sdk 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/gpu-module-abi.html +19 -9
- package/docs/gpu-module-abi.md +34 -10
- package/docs/isomorphic-pthreads.html +10 -0
- package/package.json +3 -2
- package/src/index.d.ts +406 -0
- package/src/runtime-host/ephemerisGridStore.js +1688 -0
- package/src/runtime-host/gpuComputeContext.js +394 -0
- package/src/runtime-host/index.js +115 -1
- package/src/runtime-host/runtimeRegionStore.js +382 -3
- package/templates/gpu-module/include/space_data_gpu_abi.h +71 -5
- package/templates/gpu-module/manifest.json +2 -2
|
@@ -48,7 +48,7 @@ function toRecordBytes(value, recordByteLength) {
|
|
|
48
48
|
bytes.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
49
49
|
return bytes;
|
|
50
50
|
}
|
|
51
|
-
if (value instanceof ArrayBuffer) {
|
|
51
|
+
if (value instanceof ArrayBuffer || isSharedBuffer(value)) {
|
|
52
52
|
if (value.byteLength > recordByteLength) {
|
|
53
53
|
throw new RangeError("record bytes exceed recordByteLength");
|
|
54
54
|
}
|
|
@@ -58,6 +58,34 @@ function toRecordBytes(value, recordByteLength) {
|
|
|
58
58
|
throw new TypeError("runtime region records must be byte-oriented");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
function toExactUint8Array(value, label) {
|
|
62
|
+
if (value instanceof Uint8Array) {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (ArrayBuffer.isView(value)) {
|
|
66
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
67
|
+
}
|
|
68
|
+
if (value instanceof ArrayBuffer || isSharedBuffer(value)) {
|
|
69
|
+
return new Uint8Array(value);
|
|
70
|
+
}
|
|
71
|
+
throw new TypeError(`${label} must be byte-oriented`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isSharedBuffer(buffer) {
|
|
75
|
+
return (
|
|
76
|
+
typeof SharedArrayBuffer === "function" &&
|
|
77
|
+
buffer instanceof SharedArrayBuffer
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createArenaBuffer(byteLength, { shared = true } = {}) {
|
|
82
|
+
const normalizedLength = normalizePositiveInteger(byteLength, "byteLength");
|
|
83
|
+
if (shared && typeof SharedArrayBuffer === "function") {
|
|
84
|
+
return new SharedArrayBuffer(normalizedLength);
|
|
85
|
+
}
|
|
86
|
+
return new ArrayBuffer(normalizedLength);
|
|
87
|
+
}
|
|
88
|
+
|
|
61
89
|
export function createRuntimeRegionStore() {
|
|
62
90
|
let nextRegionId = 1;
|
|
63
91
|
const regions = new Map();
|
|
@@ -69,6 +97,9 @@ export function createRuntimeRegionStore() {
|
|
|
69
97
|
"recordCount",
|
|
70
98
|
);
|
|
71
99
|
}
|
|
100
|
+
if (region.kind === "contiguous") {
|
|
101
|
+
return region.recordCount;
|
|
102
|
+
}
|
|
72
103
|
return region.records.length;
|
|
73
104
|
}
|
|
74
105
|
|
|
@@ -78,6 +109,22 @@ export function createRuntimeRegionStore() {
|
|
|
78
109
|
if (!region) {
|
|
79
110
|
return null;
|
|
80
111
|
}
|
|
112
|
+
if (region.kind === "contiguous") {
|
|
113
|
+
return {
|
|
114
|
+
regionId: region.regionId,
|
|
115
|
+
layoutId: region.layoutId,
|
|
116
|
+
recordByteLength: region.recordByteLength,
|
|
117
|
+
alignment: region.alignment,
|
|
118
|
+
recordCount: region.recordCount,
|
|
119
|
+
kind: "contiguous",
|
|
120
|
+
shared: region.shared,
|
|
121
|
+
generation: region.generation,
|
|
122
|
+
byteLength: region.bytes.byteLength,
|
|
123
|
+
activeConsumers: region.consumers.size,
|
|
124
|
+
invalidated: region.invalidated,
|
|
125
|
+
metadata: region.metadata,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
81
128
|
return {
|
|
82
129
|
regionId: region.regionId,
|
|
83
130
|
layoutId: region.layoutId,
|
|
@@ -103,6 +150,10 @@ export function createRuntimeRegionStore() {
|
|
|
103
150
|
),
|
|
104
151
|
alignment: normalizeStrictlyPositiveInteger(alignment, "alignment"),
|
|
105
152
|
records: [],
|
|
153
|
+
generation: 1,
|
|
154
|
+
consumers: new Map(),
|
|
155
|
+
nextLeaseId: 1,
|
|
156
|
+
invalidated: false,
|
|
106
157
|
};
|
|
107
158
|
region.records = Array.from(initialRecords, (record) =>
|
|
108
159
|
toRecordBytes(record, region.recordByteLength),
|
|
@@ -111,6 +162,61 @@ export function createRuntimeRegionStore() {
|
|
|
111
162
|
return describeRegion(region.regionId);
|
|
112
163
|
}
|
|
113
164
|
|
|
165
|
+
function allocateContiguousRegion({
|
|
166
|
+
layoutId,
|
|
167
|
+
recordByteLength,
|
|
168
|
+
alignment = 8,
|
|
169
|
+
recordCount = 0,
|
|
170
|
+
shared = true,
|
|
171
|
+
initialBytes = null,
|
|
172
|
+
metadata = null,
|
|
173
|
+
}) {
|
|
174
|
+
const normalizedLayoutId = normalizeRequiredString(layoutId, "layoutId");
|
|
175
|
+
const normalizedRecordByteLength = normalizeStrictlyPositiveInteger(
|
|
176
|
+
recordByteLength,
|
|
177
|
+
"recordByteLength",
|
|
178
|
+
);
|
|
179
|
+
const normalizedAlignment = normalizeStrictlyPositiveInteger(
|
|
180
|
+
alignment,
|
|
181
|
+
"alignment",
|
|
182
|
+
);
|
|
183
|
+
const normalizedRecordCount = normalizePositiveInteger(
|
|
184
|
+
recordCount,
|
|
185
|
+
"recordCount",
|
|
186
|
+
);
|
|
187
|
+
const byteLength = normalizedRecordCount * normalizedRecordByteLength;
|
|
188
|
+
const buffer = createArenaBuffer(byteLength, { shared: Boolean(shared) });
|
|
189
|
+
const bytes = new Uint8Array(buffer, 0, byteLength);
|
|
190
|
+
if (initialBytes !== null && initialBytes !== undefined) {
|
|
191
|
+
const source = toExactUint8Array(initialBytes, "initialBytes");
|
|
192
|
+
if (source.byteLength > byteLength) {
|
|
193
|
+
throw new RangeError(
|
|
194
|
+
`initialBytes length (${source.byteLength}) exceeds allocated region byteLength (${byteLength}).`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
bytes.set(source, 0);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const region = {
|
|
201
|
+
regionId: nextRegionId++,
|
|
202
|
+
kind: "contiguous",
|
|
203
|
+
layoutId: normalizedLayoutId,
|
|
204
|
+
recordByteLength: normalizedRecordByteLength,
|
|
205
|
+
alignment: normalizedAlignment,
|
|
206
|
+
recordCount: normalizedRecordCount,
|
|
207
|
+
buffer,
|
|
208
|
+
bytes,
|
|
209
|
+
shared: isSharedBuffer(buffer),
|
|
210
|
+
generation: 1,
|
|
211
|
+
consumers: new Map(),
|
|
212
|
+
nextLeaseId: 1,
|
|
213
|
+
invalidated: false,
|
|
214
|
+
metadata: metadata ?? null,
|
|
215
|
+
};
|
|
216
|
+
regions.set(region.regionId, region);
|
|
217
|
+
return describeRegion(region.regionId);
|
|
218
|
+
}
|
|
219
|
+
|
|
114
220
|
function registerExternalRegion({
|
|
115
221
|
layoutId,
|
|
116
222
|
recordByteLength,
|
|
@@ -134,6 +240,10 @@ export function createRuntimeRegionStore() {
|
|
|
134
240
|
resolveRecordView,
|
|
135
241
|
"resolveRecordView",
|
|
136
242
|
),
|
|
243
|
+
generation: 1,
|
|
244
|
+
consumers: new Map(),
|
|
245
|
+
nextLeaseId: 1,
|
|
246
|
+
invalidated: false,
|
|
137
247
|
};
|
|
138
248
|
if (region.getRecordCount === undefined) {
|
|
139
249
|
region.records.length = normalizePositiveInteger(recordCount, "recordCount");
|
|
@@ -151,6 +261,9 @@ export function createRuntimeRegionStore() {
|
|
|
151
261
|
if (typeof region.getRecordCount === "function") {
|
|
152
262
|
throw new Error("Cannot set recordCount for externally counted regions");
|
|
153
263
|
}
|
|
264
|
+
if (region.kind === "contiguous") {
|
|
265
|
+
return resizeContiguousRegion(normalizedRegionId, recordCount);
|
|
266
|
+
}
|
|
154
267
|
const normalizedRecordCount = normalizePositiveInteger(
|
|
155
268
|
recordCount,
|
|
156
269
|
"recordCount",
|
|
@@ -165,7 +278,37 @@ export function createRuntimeRegionStore() {
|
|
|
165
278
|
return describeRegion(normalizedRegionId);
|
|
166
279
|
}
|
|
167
280
|
|
|
168
|
-
function
|
|
281
|
+
function getRegionArena(regionId) {
|
|
282
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
283
|
+
const region = regions.get(normalizedRegionId);
|
|
284
|
+
if (!region || region.invalidated) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
if (region.kind !== "contiguous") {
|
|
288
|
+
throw new TypeError(
|
|
289
|
+
`Region ${normalizedRegionId} (${region.kind}) does not have a contiguous arena.`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
regionId: region.regionId,
|
|
294
|
+
buffer: region.buffer,
|
|
295
|
+
byteOffset: region.bytes.byteOffset,
|
|
296
|
+
byteLength: region.bytes.byteLength,
|
|
297
|
+
bytes: region.bytes,
|
|
298
|
+
shared: region.shared,
|
|
299
|
+
alignment: region.alignment,
|
|
300
|
+
generation: region.generation,
|
|
301
|
+
recordCount: region.recordCount,
|
|
302
|
+
recordByteLength: region.recordByteLength,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function updateContiguousRecord({
|
|
307
|
+
regionId,
|
|
308
|
+
recordIndex,
|
|
309
|
+
bytes,
|
|
310
|
+
bumpGeneration = false,
|
|
311
|
+
}) {
|
|
169
312
|
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
170
313
|
const normalizedRecordIndex = normalizePositiveInteger(
|
|
171
314
|
recordIndex,
|
|
@@ -173,6 +316,203 @@ export function createRuntimeRegionStore() {
|
|
|
173
316
|
);
|
|
174
317
|
const region = regions.get(normalizedRegionId);
|
|
175
318
|
if (!region) {
|
|
319
|
+
throw new Error(`Unknown region ${normalizedRegionId}.`);
|
|
320
|
+
}
|
|
321
|
+
if (region.invalidated) {
|
|
322
|
+
throw new Error(`Region ${normalizedRegionId} has been invalidated.`);
|
|
323
|
+
}
|
|
324
|
+
if (region.kind !== "contiguous") {
|
|
325
|
+
throw new TypeError(
|
|
326
|
+
`Region ${normalizedRegionId} is not a contiguous arena region.`,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
if (normalizedRecordIndex >= region.recordCount) {
|
|
330
|
+
throw new RangeError(
|
|
331
|
+
`recordIndex ${normalizedRecordIndex} out of bounds for region ${normalizedRegionId} (recordCount=${region.recordCount}).`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const source = toRecordBytes(bytes, region.recordByteLength);
|
|
335
|
+
region.bytes.set(
|
|
336
|
+
source,
|
|
337
|
+
normalizedRecordIndex * region.recordByteLength,
|
|
338
|
+
);
|
|
339
|
+
if (bumpGeneration) {
|
|
340
|
+
region.generation += 1;
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
regionId: region.regionId,
|
|
344
|
+
recordIndex: normalizedRecordIndex,
|
|
345
|
+
generation: region.generation,
|
|
346
|
+
byteLength: region.recordByteLength,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function resizeContiguousRegion(regionId, newRecordCount, { shared } = {}) {
|
|
351
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
352
|
+
const normalizedRecordCount = normalizePositiveInteger(
|
|
353
|
+
newRecordCount,
|
|
354
|
+
"recordCount",
|
|
355
|
+
);
|
|
356
|
+
const region = regions.get(normalizedRegionId);
|
|
357
|
+
if (!region) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
if (region.invalidated) {
|
|
361
|
+
throw new Error(`Region ${normalizedRegionId} has been invalidated.`);
|
|
362
|
+
}
|
|
363
|
+
if (region.kind !== "contiguous") {
|
|
364
|
+
throw new TypeError(
|
|
365
|
+
`Region ${normalizedRegionId} is not a contiguous arena region.`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const useShared = shared === undefined ? region.shared : Boolean(shared);
|
|
369
|
+
const nextByteLength = normalizedRecordCount * region.recordByteLength;
|
|
370
|
+
const nextBuffer = createArenaBuffer(nextByteLength, { shared: useShared });
|
|
371
|
+
const nextBytes = new Uint8Array(nextBuffer, 0, nextByteLength);
|
|
372
|
+
const copyBytes = Math.min(region.bytes.byteLength, nextByteLength);
|
|
373
|
+
if (copyBytes > 0) {
|
|
374
|
+
nextBytes.set(region.bytes.subarray(0, copyBytes), 0);
|
|
375
|
+
}
|
|
376
|
+
region.buffer = nextBuffer;
|
|
377
|
+
region.bytes = nextBytes;
|
|
378
|
+
region.shared = isSharedBuffer(nextBuffer);
|
|
379
|
+
region.recordCount = normalizedRecordCount;
|
|
380
|
+
region.generation += 1;
|
|
381
|
+
return describeRegion(normalizedRegionId);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function bumpRegionGeneration(regionId) {
|
|
385
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
386
|
+
const region = regions.get(normalizedRegionId);
|
|
387
|
+
if (!region) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
region.generation += 1;
|
|
391
|
+
return region.generation;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function invalidateRegion(regionId) {
|
|
395
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
396
|
+
const region = regions.get(normalizedRegionId);
|
|
397
|
+
if (!region) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
region.invalidated = true;
|
|
401
|
+
region.generation += 1;
|
|
402
|
+
region.consumers.clear();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function attachRegionConsumer(
|
|
407
|
+
regionId,
|
|
408
|
+
{ consumerId, mode = "read-only", roleMask = null } = {},
|
|
409
|
+
) {
|
|
410
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
411
|
+
const normalizedConsumerId = normalizeRequiredString(
|
|
412
|
+
consumerId,
|
|
413
|
+
"consumerId",
|
|
414
|
+
);
|
|
415
|
+
if (mode !== "read-only") {
|
|
416
|
+
throw new Error(
|
|
417
|
+
`Shared region consumer "${normalizedConsumerId}" must attach with mode "read-only" (got "${String(mode)}").`,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const region = regions.get(normalizedRegionId);
|
|
421
|
+
if (!region) {
|
|
422
|
+
throw new Error(`Cannot attach consumer to unknown region ${normalizedRegionId}.`);
|
|
423
|
+
}
|
|
424
|
+
if (region.invalidated) {
|
|
425
|
+
throw new Error(`Cannot attach consumer to invalidated region ${normalizedRegionId}.`);
|
|
426
|
+
}
|
|
427
|
+
const leaseId = region.nextLeaseId++;
|
|
428
|
+
const attachedGeneration = region.generation;
|
|
429
|
+
const entry = {
|
|
430
|
+
leaseId,
|
|
431
|
+
regionId: normalizedRegionId,
|
|
432
|
+
consumerId: normalizedConsumerId,
|
|
433
|
+
mode: "read-only",
|
|
434
|
+
roleMask,
|
|
435
|
+
generation: attachedGeneration,
|
|
436
|
+
attachedAt: Date.now(),
|
|
437
|
+
};
|
|
438
|
+
region.consumers.set(leaseId, entry);
|
|
439
|
+
|
|
440
|
+
function isCurrent() {
|
|
441
|
+
return (
|
|
442
|
+
!region.invalidated &&
|
|
443
|
+
region.generation === attachedGeneration &&
|
|
444
|
+
region.consumers.has(leaseId)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function assertCurrent() {
|
|
449
|
+
if (!region.consumers.has(leaseId)) {
|
|
450
|
+
throw new Error(
|
|
451
|
+
`Region consumer lease ${leaseId} (${normalizedConsumerId}) on region ${normalizedRegionId} is detached or invalidated.`,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
if (region.invalidated) {
|
|
455
|
+
throw new Error(
|
|
456
|
+
`Region ${normalizedRegionId} has been invalidated; lease ${leaseId} (${normalizedConsumerId}) is stale.`,
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (region.generation !== attachedGeneration) {
|
|
460
|
+
throw new Error(
|
|
461
|
+
`Region ${normalizedRegionId} generation mismatch for lease ${leaseId} (${normalizedConsumerId}): attached at generation ${attachedGeneration}, current generation is ${region.generation}.`,
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function detach() {
|
|
468
|
+
return region.consumers.delete(leaseId);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return Object.freeze({
|
|
472
|
+
leaseId,
|
|
473
|
+
regionId: normalizedRegionId,
|
|
474
|
+
consumerId: normalizedConsumerId,
|
|
475
|
+
mode: "read-only",
|
|
476
|
+
roleMask,
|
|
477
|
+
generation: attachedGeneration,
|
|
478
|
+
isCurrent,
|
|
479
|
+
assertCurrent,
|
|
480
|
+
detach,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function detachRegionConsumer(regionId, leaseId) {
|
|
485
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
486
|
+
const normalizedLeaseId = normalizeStrictlyPositiveInteger(
|
|
487
|
+
leaseId,
|
|
488
|
+
"leaseId",
|
|
489
|
+
);
|
|
490
|
+
const region = regions.get(normalizedRegionId);
|
|
491
|
+
if (!region) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
return region.consumers.delete(normalizedLeaseId);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function listRegionConsumers(regionId) {
|
|
498
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
499
|
+
const region = regions.get(normalizedRegionId);
|
|
500
|
+
if (!region || region.invalidated) {
|
|
501
|
+
return [];
|
|
502
|
+
}
|
|
503
|
+
return Array.from(region.consumers.values(), (entry) =>
|
|
504
|
+
Object.freeze({ ...entry }),
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function resolveRecord({ regionId, recordIndex }) {
|
|
509
|
+
const normalizedRegionId = normalizePositiveInteger(regionId, "regionId");
|
|
510
|
+
const normalizedRecordIndex = normalizePositiveInteger(
|
|
511
|
+
recordIndex,
|
|
512
|
+
"recordIndex",
|
|
513
|
+
);
|
|
514
|
+
const region = regions.get(normalizedRegionId);
|
|
515
|
+
if (!region || region.invalidated) {
|
|
176
516
|
return null;
|
|
177
517
|
}
|
|
178
518
|
if (normalizedRecordIndex >= getRegionRecordCount(region)) {
|
|
@@ -181,6 +521,20 @@ export function createRuntimeRegionStore() {
|
|
|
181
521
|
if (region.kind === "external") {
|
|
182
522
|
return null;
|
|
183
523
|
}
|
|
524
|
+
if (region.kind === "contiguous") {
|
|
525
|
+
const offset = normalizedRecordIndex * region.recordByteLength;
|
|
526
|
+
return {
|
|
527
|
+
regionId: region.regionId,
|
|
528
|
+
recordIndex: normalizedRecordIndex,
|
|
529
|
+
layoutId: region.layoutId,
|
|
530
|
+
recordByteLength: region.recordByteLength,
|
|
531
|
+
alignment: region.alignment,
|
|
532
|
+
byteLength: region.recordByteLength,
|
|
533
|
+
bytes: cloneBytes(
|
|
534
|
+
region.bytes.subarray(offset, offset + region.recordByteLength),
|
|
535
|
+
),
|
|
536
|
+
};
|
|
537
|
+
}
|
|
184
538
|
return {
|
|
185
539
|
regionId: region.regionId,
|
|
186
540
|
recordIndex: normalizedRecordIndex,
|
|
@@ -199,12 +553,28 @@ export function createRuntimeRegionStore() {
|
|
|
199
553
|
"recordIndex",
|
|
200
554
|
);
|
|
201
555
|
const region = regions.get(normalizedRegionId);
|
|
202
|
-
if (!region) {
|
|
556
|
+
if (!region || region.invalidated) {
|
|
203
557
|
return null;
|
|
204
558
|
}
|
|
205
559
|
if (normalizedRecordIndex >= getRegionRecordCount(region)) {
|
|
206
560
|
return null;
|
|
207
561
|
}
|
|
562
|
+
if (region.kind === "contiguous") {
|
|
563
|
+
const offset = normalizedRecordIndex * region.recordByteLength;
|
|
564
|
+
return {
|
|
565
|
+
regionId: region.regionId,
|
|
566
|
+
recordIndex: normalizedRecordIndex,
|
|
567
|
+
layoutId: region.layoutId,
|
|
568
|
+
recordByteLength: region.recordByteLength,
|
|
569
|
+
alignment: region.alignment,
|
|
570
|
+
byteLength: region.recordByteLength,
|
|
571
|
+
byteOffset: region.bytes.byteOffset + offset,
|
|
572
|
+
buffer: region.buffer,
|
|
573
|
+
shared: region.shared,
|
|
574
|
+
generation: region.generation,
|
|
575
|
+
bytes: region.bytes.subarray(offset, offset + region.recordByteLength),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
208
578
|
if (region.kind !== "external") {
|
|
209
579
|
return resolveRecord({
|
|
210
580
|
regionId: normalizedRegionId,
|
|
@@ -236,10 +606,19 @@ export function createRuntimeRegionStore() {
|
|
|
236
606
|
|
|
237
607
|
return {
|
|
238
608
|
allocateRegion,
|
|
609
|
+
allocateContiguousRegion,
|
|
239
610
|
describeRegion,
|
|
240
611
|
registerExternalRegion,
|
|
241
612
|
resolveRecord,
|
|
242
613
|
resolveRecordView,
|
|
243
614
|
setRegionRecordCount,
|
|
615
|
+
getRegionArena,
|
|
616
|
+
updateContiguousRecord,
|
|
617
|
+
resizeContiguousRegion,
|
|
618
|
+
bumpRegionGeneration,
|
|
619
|
+
invalidateRegion,
|
|
620
|
+
attachRegionConsumer,
|
|
621
|
+
detachRegionConsumer,
|
|
622
|
+
listRegionConsumers,
|
|
244
623
|
};
|
|
245
624
|
}
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
#define SPACE_DATA_GPU_ABI_H
|
|
3
3
|
|
|
4
4
|
#include <stdint.h>
|
|
5
|
+
#include <string.h>
|
|
5
6
|
|
|
6
7
|
#ifdef __cplusplus
|
|
7
8
|
extern "C" {
|
|
8
9
|
#endif
|
|
9
10
|
|
|
10
|
-
#define SDN_GPU_ABI_VERSION
|
|
11
|
+
#define SDN_GPU_ABI_VERSION 2u
|
|
12
|
+
#define SDN_GPU_ABI_VERSION_V1 1u
|
|
11
13
|
#define SDN_GPU_CAPABILITY_ID "gpu_compute"
|
|
12
14
|
#define SDN_GPU_CAPABILITY_SCOPE_WEBGPU_V1 "webgpu.v1"
|
|
15
|
+
#define SDN_GPU_CAPABILITY_SCOPE_WEBGPU_V2 "webgpu.v2"
|
|
13
16
|
|
|
14
17
|
typedef enum SdnGpuStatus {
|
|
15
18
|
SDN_GPU_STATUS_OK = 0,
|
|
@@ -18,7 +21,9 @@ typedef enum SdnGpuStatus {
|
|
|
18
21
|
SDN_GPU_STATUS_INVALID_DESCRIPTOR = 3,
|
|
19
22
|
SDN_GPU_STATUS_LIMIT_EXCEEDED = 4,
|
|
20
23
|
SDN_GPU_STATUS_DISPATCH_FAILED = 5,
|
|
21
|
-
SDN_GPU_STATUS_OUTPUT_OVERFLOW = 6
|
|
24
|
+
SDN_GPU_STATUS_OUTPUT_OVERFLOW = 6,
|
|
25
|
+
SDN_GPU_STATUS_UNKNOWN_HANDLE = 7,
|
|
26
|
+
SDN_GPU_STATUS_DEVICE_MISMATCH = 8
|
|
22
27
|
} SdnGpuStatus;
|
|
23
28
|
|
|
24
29
|
typedef enum SdnGpuBackendKind {
|
|
@@ -32,7 +37,8 @@ typedef enum SdnGpuBufferRole {
|
|
|
32
37
|
SDN_GPU_BUFFER_ROLE_STORAGE_READ = 1u << 0,
|
|
33
38
|
SDN_GPU_BUFFER_ROLE_STORAGE_WRITE = 1u << 1,
|
|
34
39
|
SDN_GPU_BUFFER_ROLE_UNIFORM = 1u << 2,
|
|
35
|
-
SDN_GPU_BUFFER_ROLE_INDIRECT = 1u << 3
|
|
40
|
+
SDN_GPU_BUFFER_ROLE_INDIRECT = 1u << 3,
|
|
41
|
+
SDN_GPU_BUFFER_ROLE_SHARED_EXCHANGE = 1u << 4
|
|
36
42
|
} SdnGpuBufferRole;
|
|
37
43
|
|
|
38
44
|
typedef enum SdnGpuScalarFormat {
|
|
@@ -40,7 +46,8 @@ typedef enum SdnGpuScalarFormat {
|
|
|
40
46
|
SDN_GPU_SCALAR_FORMAT_U32 = 2,
|
|
41
47
|
SDN_GPU_SCALAR_FORMAT_I32 = 3,
|
|
42
48
|
SDN_GPU_SCALAR_FORMAT_F32 = 4,
|
|
43
|
-
SDN_GPU_SCALAR_FORMAT_SPLIT_F64 = 5
|
|
49
|
+
SDN_GPU_SCALAR_FORMAT_SPLIT_F64 = 5,
|
|
50
|
+
SDN_GPU_SCALAR_FORMAT_IEEE754_F64_U32X2 = 6
|
|
44
51
|
} SdnGpuScalarFormat;
|
|
45
52
|
|
|
46
53
|
typedef struct SdnGpuSplitF64 {
|
|
@@ -54,6 +61,18 @@ typedef struct SdnGpuVec3SplitF64 {
|
|
|
54
61
|
SdnGpuSplitF64 z;
|
|
55
62
|
} SdnGpuVec3SplitF64;
|
|
56
63
|
|
|
64
|
+
/* Exact IEEE-754 binary64 stored as little-endian (lo, hi) u32 pair (full 64 bits, 0 ULP). */
|
|
65
|
+
typedef struct SdnGpuF64Bits {
|
|
66
|
+
uint32_t lo;
|
|
67
|
+
uint32_t hi;
|
|
68
|
+
} SdnGpuF64Bits;
|
|
69
|
+
|
|
70
|
+
typedef struct SdnGpuVec3F64Bits {
|
|
71
|
+
SdnGpuF64Bits x;
|
|
72
|
+
SdnGpuF64Bits y;
|
|
73
|
+
SdnGpuF64Bits z;
|
|
74
|
+
} SdnGpuVec3F64Bits;
|
|
75
|
+
|
|
57
76
|
typedef struct SdnGpuBufferDesc {
|
|
58
77
|
uint32_t role;
|
|
59
78
|
uint32_t scalar_format;
|
|
@@ -63,6 +82,37 @@ typedef struct SdnGpuBufferDesc {
|
|
|
63
82
|
uint64_t byte_length;
|
|
64
83
|
} SdnGpuBufferDesc;
|
|
65
84
|
|
|
85
|
+
/* Opaque host-owned GPU buffer handle on a shared GPUDevice (no raw pointers). */
|
|
86
|
+
typedef struct SdnGpuBufferHandle {
|
|
87
|
+
uint64_t handle_id;
|
|
88
|
+
uint64_t device_id;
|
|
89
|
+
uint64_t byte_length;
|
|
90
|
+
uint32_t role;
|
|
91
|
+
uint32_t scalar_format;
|
|
92
|
+
uint32_t record_stride;
|
|
93
|
+
uint32_t flags;
|
|
94
|
+
} SdnGpuBufferHandle;
|
|
95
|
+
|
|
96
|
+
typedef struct SdnGpuSharedBufferBinding {
|
|
97
|
+
uint32_t binding_index;
|
|
98
|
+
uint32_t role;
|
|
99
|
+
uint64_t handle_id;
|
|
100
|
+
uint64_t byte_offset;
|
|
101
|
+
uint64_t byte_length;
|
|
102
|
+
} SdnGpuSharedBufferBinding;
|
|
103
|
+
|
|
104
|
+
typedef struct SdnGpuDeviceInfo {
|
|
105
|
+
uint32_t abi_version;
|
|
106
|
+
uint32_t available;
|
|
107
|
+
uint32_t backend_kind;
|
|
108
|
+
uint32_t flags;
|
|
109
|
+
uint64_t device_id;
|
|
110
|
+
uint64_t max_storage_buffer_binding_size;
|
|
111
|
+
uint64_t max_buffer_size;
|
|
112
|
+
uint32_t max_compute_workgroup_size_x;
|
|
113
|
+
uint32_t max_compute_invocations_per_workgroup;
|
|
114
|
+
} SdnGpuDeviceInfo;
|
|
115
|
+
|
|
66
116
|
typedef struct SdnGpuDispatchDesc {
|
|
67
117
|
uint32_t abi_version;
|
|
68
118
|
uint32_t descriptor_byte_length;
|
|
@@ -71,7 +121,7 @@ typedef struct SdnGpuDispatchDesc {
|
|
|
71
121
|
uint32_t input_count;
|
|
72
122
|
uint32_t output_count;
|
|
73
123
|
uint32_t uniform_byte_length;
|
|
74
|
-
uint32_t
|
|
124
|
+
uint32_t shared_binding_count;
|
|
75
125
|
uint32_t workgroup_count_x;
|
|
76
126
|
uint32_t workgroup_count_y;
|
|
77
127
|
uint32_t workgroup_count_z;
|
|
@@ -115,6 +165,22 @@ static inline SdnGpuVec3SplitF64 sdn_gpu_split_vec3_f64(
|
|
|
115
165
|
return result;
|
|
116
166
|
}
|
|
117
167
|
|
|
168
|
+
static inline SdnGpuF64Bits sdn_gpu_pack_f64(double value) {
|
|
169
|
+
uint64_t bits = 0u;
|
|
170
|
+
SdnGpuF64Bits out;
|
|
171
|
+
memcpy(&bits, &value, sizeof(bits));
|
|
172
|
+
out.lo = (uint32_t)(bits & 0xffffffffull);
|
|
173
|
+
out.hi = (uint32_t)(bits >> 32u);
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static inline double sdn_gpu_unpack_f64(SdnGpuF64Bits value) {
|
|
178
|
+
uint64_t bits = ((uint64_t)value.hi << 32u) | (uint64_t)value.lo;
|
|
179
|
+
double out = 0.0;
|
|
180
|
+
memcpy(&out, &bits, sizeof(out));
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
118
184
|
#ifdef __cplusplus
|
|
119
185
|
}
|
|
120
186
|
#endif
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"clock",
|
|
11
11
|
{
|
|
12
12
|
"capability": "gpu_compute",
|
|
13
|
-
"scope": "webgpu.
|
|
13
|
+
"scope": "webgpu.v2",
|
|
14
14
|
"required": false,
|
|
15
|
-
"description": "Optional WebGPU/Dawn compute acceleration."
|
|
15
|
+
"description": "Optional WebGPU/Dawn compute acceleration with shared host-owned device and buffer handles."
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"methods": [
|