space-data-module-sdk 0.12.0 → 0.13.1
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/package.json +2 -2
- package/src/runtime-host/gpuComputeContext.js +394 -0
- package/src/runtime-host/index.js +32 -0
- package/templates/gpu-module/include/space_data_gpu_abi.h +71 -5
- package/templates/gpu-module/manifest.json +2 -2
package/docs/gpu-module-abi.html
CHANGED
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
<p>GPU-capable modules declare the coarse capability id:</p>
|
|
110
110
|
<div class="codeblock"><div class="codeblock-head">json</div><pre><code>{
|
|
111
111
|
"capability": "gpu_compute",
|
|
112
|
-
"scope": "webgpu.
|
|
112
|
+
"scope": "webgpu.v2",
|
|
113
113
|
"required": false,
|
|
114
|
-
"description": "Optional WebGPU/Dawn compute acceleration."
|
|
114
|
+
"description": "Optional WebGPU/Dawn compute acceleration with shared host-owned device and buffer handles."
|
|
115
115
|
}</code></pre></div>
|
|
116
|
-
<p>Use <code>required: false</code> unless the module has no correct CPU path. A missing GPU adapter must degrade to the module's CPU implementation, not to an incomplete result.</p>
|
|
116
|
+
<p>Use <code>scope: "webgpu.v1"</code> for single-module byte-returning dispatch or <code>scope: "webgpu.v2"</code> when exchanging opaque shared <code>GPUBuffer</code> handles on a host-owned <code>GPUDevice</code>. Use <code>required: false</code> unless the module has no correct CPU path. A missing GPU adapter must degrade to the module's CPU implementation, not to an incomplete result.</p>
|
|
117
117
|
<p>The <code>gpu_compute</code> id is part of the SDK recommended capability vocabulary. The typed PLG <code>HOST_CAPABILITIES</code> enum cannot carry a dedicated GPU enum value until the canonical standards schema adds one. Until that SDS change lands, module manifests should use the string/object capability form above and avoid claiming a typed PLG host capability enum for GPU.</p>
|
|
118
118
|
<h2 id="artifact-layout"><a class="anchor" href="#artifact-layout" aria-hidden="true">#</a>Artifact Layout</h2>
|
|
119
119
|
<p>The canonical portable artifact remains:</p>
|
|
@@ -137,10 +137,17 @@ dist/wasmedge/gpu-host.{so,dylib,dll}</code></pre></div>
|
|
|
137
137
|
<li>packed dispatch/result descriptors</li>
|
|
138
138
|
</ul>
|
|
139
139
|
<p>All multi-byte fields are little-endian in serialized buffers. Structs in the header are fixed-width and intentionally avoid owning pointers. Pointers are runtime-local implementation details and must not appear in durable manifests, publication metadata, or cross-process descriptors.</p>
|
|
140
|
-
<h3 id="2-host-dispatch-abi"><a class="anchor" href="#2-host-dispatch-abi" aria-hidden="true">#</a>2. Host Dispatch ABI</h3>
|
|
141
|
-
<p>The canonical
|
|
142
|
-
<div class="codeblock"><div class="codeblock-head">text</div><pre><code>gpu_compute.
|
|
143
|
-
|
|
140
|
+
<h3 id="2-host-dispatch-shared-buffer-abi-v2"><a class="anchor" href="#2-host-dispatch-shared-buffer-abi-v2" aria-hidden="true">#</a>2. Host Dispatch & Shared Buffer ABI (v2)</h3>
|
|
141
|
+
<p>The canonical operations are:</p>
|
|
142
|
+
<div class="codeblock"><div class="codeblock-head">text</div><pre><code>gpu_compute.device.info.v1
|
|
143
|
+
gpu_compute.buffer.create.v1
|
|
144
|
+
gpu_compute.buffer.describe.v1
|
|
145
|
+
gpu_compute.buffer.read.v1
|
|
146
|
+
gpu_compute.buffer.release.v1
|
|
147
|
+
gpu_compute.dispatch.v1</code></pre></div>
|
|
148
|
+
<p>In ABI v2 (<code>SDN_GPU_ABI_VERSION = 2</code>, scope <code>webgpu.v2</code>), the host owns ONE shared <code>GPUDevice</code> (<code>createSharedGpuContext</code> in <code>space-data-module-sdk/runtime-host</code>) and assigns opaque integer buffer handles (<code>SdnGpuBufferHandle { handle_id, device_id, byte_length, role, scalar_format, record_stride, flags }</code>). Independent modules (for example a propagator such as <code>propagator/sdn-ap</code> and a screener such as <code>analysis/conjunction-assessment</code>) pass handles on the same <code>device_id</code> directly into compute bind groups without copying buffers back through CPU memory.</p>
|
|
149
|
+
<p><code>detectWebGpu()</code> probes host GPU availability without throwing and returns <code>backendKind: "cpu-fallback"</code> when no WebGPU/Dawn adapter is present.</p>
|
|
150
|
+
<p>The host dispatch adapter receives:</p>
|
|
144
151
|
<ul>
|
|
145
152
|
<li>an ABI version</li>
|
|
146
153
|
<li>a stable kernel id</li>
|
|
@@ -174,7 +181,10 @@ dist/wasmedge/gpu-host.{so,dylib,dll}</code></pre></div>
|
|
|
174
181
|
<p>WasmEdge deployments that need GPU acceleration should use a native host extension linked against Dawn. The native host implements the same <code>gpu_compute.dispatch.v1</code> operation and uses the same C/C++ layout header.</p>
|
|
175
182
|
<p>The shared module artifact should still be loadable without that extension. A pure <code>["wasmedge"]</code> artifact may choose a higher-capability native host profile, but a <code>["browser", "wasmedge"]</code> artifact must retain the portable fallback contract documented in <code>docs/browser-wasmedge-isomorphic.md</code>.</p>
|
|
176
183
|
<h2 id="numerical-rules"><a class="anchor" href="#numerical-rules" aria-hidden="true">#</a>Numerical Rules</h2>
|
|
177
|
-
<p>GPU kernels that need
|
|
184
|
+
<p>GPU kernels that need full 64-bit IEEE-754 precision (bit-for-bit identical to WASM <code>f64</code>, 0 ULP) MUST use <code>SDN_GPU_SCALAR_FORMAT_IEEE754_F64_U32X2</code> (<code>vec2<u32></code> little-endian <code>(lo, hi)</code> pairs) with exact IEEE-754 round-to-nearest-even software arithmetic in WGSL:</p>
|
|
185
|
+
<div class="codeblock"><div class="codeblock-head">c</div><pre><code>SdnGpuF64Bits x = sdn_gpu_pack_f64(value);
|
|
186
|
+
double back = sdn_gpu_unpack_f64(x);</code></pre></div>
|
|
187
|
+
<p>GPU broadphase kernels that only need ~48-bit position precision may continue to use split high/low <code>f32</code> values (<code>SDN_GPU_SCALAR_FORMAT_SPLIT_F64</code>):</p>
|
|
178
188
|
<div class="codeblock"><div class="codeblock-head">c</div><pre><code>SdnGpuSplitF64 x = sdn_gpu_split_f64(x_km);</code></pre></div>
|
|
179
189
|
<p>For orbital screening, store position components in kilometers unless a module contract states otherwise. The high component is the nearest <code>f32</code>; the low component is the residual:</p>
|
|
180
190
|
<div class="codeblock"><div class="codeblock-head">text</div><pre><code>hi = f32(value)
|
|
@@ -202,7 +212,7 @@ lo = f32(value - f64(hi))</code></pre></div>
|
|
|
202
212
|
<li><a class="depth-2" href="#artifact-layout">Artifact Layout</a></li>
|
|
203
213
|
<li><a class="depth-2" href="#abi-layers">ABI Layers</a></li>
|
|
204
214
|
<li><a class="depth-3" href="#1-data-layout-abi">1. Data Layout ABI</a></li>
|
|
205
|
-
<li><a class="depth-3" href="#2-host-dispatch-abi">2. Host Dispatch ABI</a></li>
|
|
215
|
+
<li><a class="depth-3" href="#2-host-dispatch-shared-buffer-abi-v2">2. Host Dispatch & Shared Buffer ABI (v2)</a></li>
|
|
206
216
|
<li><a class="depth-3" href="#3-module-level-api">3. Module-Level API</a></li>
|
|
207
217
|
<li><a class="depth-2" href="#browser-backend">Browser Backend</a></li>
|
|
208
218
|
<li><a class="depth-2" href="#wasmedge-backend">WasmEdge Backend</a></li>
|
package/docs/gpu-module-abi.md
CHANGED
|
@@ -25,15 +25,13 @@ GPU-capable modules declare the coarse capability id:
|
|
|
25
25
|
```json
|
|
26
26
|
{
|
|
27
27
|
"capability": "gpu_compute",
|
|
28
|
-
"scope": "webgpu.
|
|
28
|
+
"scope": "webgpu.v2",
|
|
29
29
|
"required": false,
|
|
30
|
-
"description": "Optional WebGPU/Dawn compute acceleration."
|
|
30
|
+
"description": "Optional WebGPU/Dawn compute acceleration with shared host-owned device and buffer handles."
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Use `required: false` unless the module has no correct CPU path. A missing GPU
|
|
35
|
-
adapter must degrade to the module's CPU implementation, not to an incomplete
|
|
36
|
-
result.
|
|
34
|
+
Use `scope: "webgpu.v1"` for single-module byte-returning dispatch or `scope: "webgpu.v2"` when exchanging opaque shared `GPUBuffer` handles on a host-owned `GPUDevice`. Use `required: false` unless the module has no correct CPU path. A missing GPU adapter must degrade to the module's CPU implementation, not to an incomplete result.
|
|
37
35
|
|
|
38
36
|
The `gpu_compute` id is part of the SDK recommended capability vocabulary. The
|
|
39
37
|
typed PLG `HOST_CAPABILITIES` enum cannot carry a dedicated GPU enum value
|
|
@@ -86,15 +84,31 @@ header are fixed-width and intentionally avoid owning pointers. Pointers are
|
|
|
86
84
|
runtime-local implementation details and must not appear in durable manifests,
|
|
87
85
|
publication metadata, or cross-process descriptors.
|
|
88
86
|
|
|
89
|
-
### 2. Host Dispatch ABI
|
|
87
|
+
### 2. Host Dispatch & Shared Buffer ABI (v2)
|
|
90
88
|
|
|
91
|
-
The canonical
|
|
89
|
+
The canonical operations are:
|
|
92
90
|
|
|
93
91
|
```text
|
|
92
|
+
gpu_compute.device.info.v1
|
|
93
|
+
gpu_compute.buffer.create.v1
|
|
94
|
+
gpu_compute.buffer.describe.v1
|
|
95
|
+
gpu_compute.buffer.read.v1
|
|
96
|
+
gpu_compute.buffer.release.v1
|
|
94
97
|
gpu_compute.dispatch.v1
|
|
95
98
|
```
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
In ABI v2 (`SDN_GPU_ABI_VERSION = 2`, scope `webgpu.v2`), the host owns ONE shared
|
|
101
|
+
`GPUDevice` (`createSharedGpuContext` in `space-data-module-sdk/runtime-host`) and
|
|
102
|
+
assigns opaque integer buffer handles (`SdnGpuBufferHandle { handle_id, device_id,
|
|
103
|
+
byte_length, role, scalar_format, record_stride, flags }`). Independent modules
|
|
104
|
+
(for example a propagator such as `propagator/sdn-ap` and a screener such as
|
|
105
|
+
`analysis/conjunction-assessment`) pass handles on the same `device_id` directly
|
|
106
|
+
into compute bind groups without copying buffers back through CPU memory.
|
|
107
|
+
|
|
108
|
+
`detectWebGpu()` probes host GPU availability without throwing and returns
|
|
109
|
+
`backendKind: "cpu-fallback"` when no WebGPU/Dawn adapter is present.
|
|
110
|
+
|
|
111
|
+
The host dispatch adapter receives:
|
|
98
112
|
|
|
99
113
|
- an ABI version
|
|
100
114
|
- a stable kernel id
|
|
@@ -153,8 +167,18 @@ contract documented in `docs/browser-wasmedge-isomorphic.md`.
|
|
|
153
167
|
|
|
154
168
|
## Numerical Rules
|
|
155
169
|
|
|
156
|
-
GPU kernels that need
|
|
157
|
-
`
|
|
170
|
+
GPU kernels that need full 64-bit IEEE-754 precision (bit-for-bit identical to
|
|
171
|
+
WASM `f64`, 0 ULP) MUST use `SDN_GPU_SCALAR_FORMAT_IEEE754_F64_U32X2` (`vec2<u32>`
|
|
172
|
+
little-endian `(lo, hi)` pairs) with exact IEEE-754 round-to-nearest-even software
|
|
173
|
+
arithmetic in WGSL:
|
|
174
|
+
|
|
175
|
+
```c
|
|
176
|
+
SdnGpuF64Bits x = sdn_gpu_pack_f64(value);
|
|
177
|
+
double back = sdn_gpu_unpack_f64(x);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
GPU broadphase kernels that only need ~48-bit position precision may continue to
|
|
181
|
+
use split high/low `f32` values (`SDN_GPU_SCALAR_FORMAT_SPLIT_F64`):
|
|
158
182
|
|
|
159
183
|
```c
|
|
160
184
|
SdnGpuSplitF64 x = sdn_gpu_split_f64(x_km);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "space-data-module-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Module SDK for building, validating, signing, and deploying WebAssembly modules on the Space Data Network.",
|
|
6
6
|
"type": "module",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"flatsql": "3.12.1",
|
|
135
135
|
"hd-wallet-wasm": "2.2.2",
|
|
136
136
|
"sdn-emception": "1.0.0",
|
|
137
|
-
"spacedatastandards.org": "1.
|
|
137
|
+
"spacedatastandards.org": "1.314.0"
|
|
138
138
|
},
|
|
139
139
|
"devDependencies": {
|
|
140
140
|
"esbuild": "^0.28.0",
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// Host-owned shared GPU compute context and opaque buffer-handle registry (SDK GPU Module ABI v2).
|
|
2
|
+
//
|
|
3
|
+
// Enables independent modules (for example propagator/sdn-ap and analysis/conjunction-assessment)
|
|
4
|
+
// to share one host-owned GPUDevice and exchange GPU buffers via opaque numeric handle ids with
|
|
5
|
+
// zero CPU round-trip, while cleanly detecting GPU availability and falling back to CPU when
|
|
6
|
+
// WebGPU/Dawn is absent.
|
|
7
|
+
|
|
8
|
+
export const SDN_GPU_ABI_VERSION = 2;
|
|
9
|
+
export const SDN_GPU_CAPABILITY_ID = "gpu_compute";
|
|
10
|
+
export const SDN_GPU_CAPABILITY_SCOPE_V1 = "webgpu.v1";
|
|
11
|
+
export const SDN_GPU_CAPABILITY_SCOPE_V2 = "webgpu.v2";
|
|
12
|
+
|
|
13
|
+
export const SDN_GPU_STATUS = Object.freeze({
|
|
14
|
+
OK: 0,
|
|
15
|
+
UNAVAILABLE: 1,
|
|
16
|
+
UNSUPPORTED_ABI: 2,
|
|
17
|
+
INVALID_DESCRIPTOR: 3,
|
|
18
|
+
LIMIT_EXCEEDED: 4,
|
|
19
|
+
DISPATCH_FAILED: 5,
|
|
20
|
+
OUTPUT_OVERFLOW: 6,
|
|
21
|
+
UNKNOWN_HANDLE: 7,
|
|
22
|
+
DEVICE_MISMATCH: 8,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const SDN_GPU_BACKEND = Object.freeze({
|
|
26
|
+
UNKNOWN: 0,
|
|
27
|
+
BROWSER_WEBGPU: 1,
|
|
28
|
+
DAWN_NATIVE: 2,
|
|
29
|
+
CPU_FALLBACK: 3,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const SDN_GPU_BUFFER_ROLE = Object.freeze({
|
|
33
|
+
STORAGE_READ: 1 << 0,
|
|
34
|
+
STORAGE_WRITE: 1 << 1,
|
|
35
|
+
UNIFORM: 1 << 2,
|
|
36
|
+
INDIRECT: 1 << 3,
|
|
37
|
+
SHARED_EXCHANGE: 1 << 4,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const SDN_GPU_SCALAR_FORMAT = Object.freeze({
|
|
41
|
+
U8: 1,
|
|
42
|
+
U32: 2,
|
|
43
|
+
I32: 3,
|
|
44
|
+
F32: 4,
|
|
45
|
+
SPLIT_F64: 5,
|
|
46
|
+
IEEE754_F64_U32X2: 6,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const _f64Scratch = new ArrayBuffer(8);
|
|
50
|
+
const _f64View = new Float64Array(_f64Scratch);
|
|
51
|
+
const _u32View = new Uint32Array(_f64Scratch);
|
|
52
|
+
|
|
53
|
+
/** Pack an IEEE-754 binary64 number into little-endian { lo, hi } u32 pair (0 ULP loss). */
|
|
54
|
+
export function packF64Bits(value) {
|
|
55
|
+
_f64View[0] = value;
|
|
56
|
+
return { lo: _u32View[0], hi: _u32View[1] };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Unpack little-endian (lo, hi) u32 pair into an exact IEEE-754 binary64 number. */
|
|
60
|
+
export function unpackF64Bits(lo, hi) {
|
|
61
|
+
_u32View[0] = lo >>> 0;
|
|
62
|
+
_u32View[1] = hi >>> 0;
|
|
63
|
+
return _f64View[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Reinterpret a Float64Array as little-endian Uint32Array (pairs of [lo, hi]) without copying. */
|
|
67
|
+
export function f64ArrayToU32Pairs(f64) {
|
|
68
|
+
return new Uint32Array(f64.buffer, f64.byteOffset, f64.length * 2);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Reinterpret little-endian Uint32Array pairs [lo, hi] as Float64Array without copying. */
|
|
72
|
+
export function u32PairsToF64Array(u32) {
|
|
73
|
+
if ((u32.byteLength & 7) !== 0) {
|
|
74
|
+
throw new RangeError("u32 byteLength must be a multiple of 8 for IEEE-754 f64 pairs.");
|
|
75
|
+
}
|
|
76
|
+
return new Float64Array(u32.buffer, u32.byteOffset, u32.byteLength / 8);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let nextDeviceId = 1;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Probes whether WebGPU is available in the current host without throwing.
|
|
83
|
+
* Returns { available: false, backendKind: 'cpu-fallback', reason, context: null }
|
|
84
|
+
* when unavailable, or { available: true, backendKind: 'browser-webgpu', adapter, device, context }.
|
|
85
|
+
*/
|
|
86
|
+
export async function detectWebGpu(options = {}) {
|
|
87
|
+
const gpu = options.gpu ?? globalThis?.navigator?.gpu ?? null;
|
|
88
|
+
if (!gpu || typeof gpu.requestAdapter !== "function") {
|
|
89
|
+
return {
|
|
90
|
+
available: false,
|
|
91
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
92
|
+
backendKind: "cpu-fallback",
|
|
93
|
+
backendCode: SDN_GPU_BACKEND.CPU_FALLBACK,
|
|
94
|
+
reason: "navigator.gpu is unavailable in this runtime.",
|
|
95
|
+
adapter: null,
|
|
96
|
+
device: null,
|
|
97
|
+
context: null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const adapter = await gpu.requestAdapter({
|
|
102
|
+
powerPreference: options.powerPreference ?? "high-performance",
|
|
103
|
+
forceFallbackAdapter: Boolean(options.forceFallbackAdapter),
|
|
104
|
+
});
|
|
105
|
+
if (!adapter) {
|
|
106
|
+
return {
|
|
107
|
+
available: false,
|
|
108
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
109
|
+
backendKind: "cpu-fallback",
|
|
110
|
+
backendCode: SDN_GPU_BACKEND.CPU_FALLBACK,
|
|
111
|
+
reason: "No WebGPU adapter returned by navigator.gpu.requestAdapter().",
|
|
112
|
+
adapter: null,
|
|
113
|
+
device: null,
|
|
114
|
+
context: null,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const requiredLimits = options.requiredLimits ?? {};
|
|
118
|
+
const device = await adapter.requestDevice(
|
|
119
|
+
Object.keys(requiredLimits).length > 0 ? { requiredLimits } : undefined,
|
|
120
|
+
);
|
|
121
|
+
const info = adapter.info ?? (typeof adapter.requestAdapterInfo === "function" ? await adapter.requestAdapterInfo() : null);
|
|
122
|
+
const adapterLabel = info
|
|
123
|
+
? [info.vendor, info.architecture, info.device, info.description].filter(Boolean).join(" ") || "WebGPU"
|
|
124
|
+
: "WebGPU";
|
|
125
|
+
const context = createSharedGpuContext({
|
|
126
|
+
device,
|
|
127
|
+
adapter,
|
|
128
|
+
adapterLabel,
|
|
129
|
+
backendKind: "browser-webgpu",
|
|
130
|
+
backendCode: SDN_GPU_BACKEND.BROWSER_WEBGPU,
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
available: true,
|
|
134
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
135
|
+
backendKind: "browser-webgpu",
|
|
136
|
+
backendCode: SDN_GPU_BACKEND.BROWSER_WEBGPU,
|
|
137
|
+
adapterLabel,
|
|
138
|
+
adapter,
|
|
139
|
+
device,
|
|
140
|
+
context,
|
|
141
|
+
};
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return {
|
|
144
|
+
available: false,
|
|
145
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
146
|
+
backendKind: "cpu-fallback",
|
|
147
|
+
backendCode: SDN_GPU_BACKEND.CPU_FALLBACK,
|
|
148
|
+
reason: error?.message ?? String(error),
|
|
149
|
+
adapter: null,
|
|
150
|
+
device: null,
|
|
151
|
+
context: null,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Host-owned shared GPU context: holds one GPUDevice and an opaque handle table so
|
|
158
|
+
* independent modules (e.g. AP and CA) exchange GPU buffers without CPU round-trips.
|
|
159
|
+
*/
|
|
160
|
+
export function createSharedGpuContext(options = {}) {
|
|
161
|
+
const device = options.device ?? null;
|
|
162
|
+
if (!device || typeof device.createBuffer !== "function") {
|
|
163
|
+
throw new TypeError("createSharedGpuContext requires a valid GPUDevice (device.createBuffer).");
|
|
164
|
+
}
|
|
165
|
+
const deviceId = options.deviceId ?? nextDeviceId++;
|
|
166
|
+
const backendKind = options.backendKind ?? "browser-webgpu";
|
|
167
|
+
const backendCode = options.backendCode ?? SDN_GPU_BACKEND.BROWSER_WEBGPU;
|
|
168
|
+
const adapterLabel = options.adapterLabel ?? "WebGPU";
|
|
169
|
+
const handles = new Map();
|
|
170
|
+
let nextHandleId = 1;
|
|
171
|
+
let destroyed = false;
|
|
172
|
+
|
|
173
|
+
const assertAlive = () => {
|
|
174
|
+
if (destroyed) throw new Error("SharedGpuContext has been destroyed.");
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
function buildDescriptor(entry) {
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
180
|
+
handleId: entry.handleId,
|
|
181
|
+
deviceId,
|
|
182
|
+
byteLength: entry.byteLength,
|
|
183
|
+
role: entry.role,
|
|
184
|
+
scalarFormat: entry.scalarFormat,
|
|
185
|
+
recordStride: entry.recordStride,
|
|
186
|
+
layout: entry.layout,
|
|
187
|
+
owner: entry.owner,
|
|
188
|
+
metadata: entry.metadata ? { ...entry.metadata } : {},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Register an existing GPUBuffer owned by this context's device and return its opaque handle descriptor. */
|
|
193
|
+
function registerBuffer(buffer, spec = {}) {
|
|
194
|
+
assertAlive();
|
|
195
|
+
if (!buffer || typeof buffer.destroy !== "function") {
|
|
196
|
+
throw new TypeError("registerBuffer requires a GPUBuffer.");
|
|
197
|
+
}
|
|
198
|
+
const handleId = nextHandleId++;
|
|
199
|
+
const entry = {
|
|
200
|
+
handleId,
|
|
201
|
+
buffer,
|
|
202
|
+
byteLength: Number(spec.byteLength ?? buffer.size ?? 0),
|
|
203
|
+
role: Number(spec.role ?? (SDN_GPU_BUFFER_ROLE.STORAGE_READ | SDN_GPU_BUFFER_ROLE.STORAGE_WRITE | SDN_GPU_BUFFER_ROLE.SHARED_EXCHANGE)),
|
|
204
|
+
scalarFormat: Number(spec.scalarFormat ?? SDN_GPU_SCALAR_FORMAT.U8),
|
|
205
|
+
recordStride: Number(spec.recordStride ?? 0),
|
|
206
|
+
layout: spec.layout ?? null,
|
|
207
|
+
owner: spec.owner ?? null,
|
|
208
|
+
ownedByContext: spec.ownedByContext !== false,
|
|
209
|
+
metadata: spec.metadata ? { ...spec.metadata } : {},
|
|
210
|
+
};
|
|
211
|
+
handles.set(handleId, entry);
|
|
212
|
+
return buildDescriptor(entry);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Allocate a GPUBuffer on the shared device and register an opaque handle for cross-module handoff. */
|
|
216
|
+
function createBuffer(spec = {}) {
|
|
217
|
+
assertAlive();
|
|
218
|
+
const byteLength = Number(spec.byteLength ?? spec.size ?? 0);
|
|
219
|
+
if (!(byteLength > 0)) {
|
|
220
|
+
throw new RangeError("createBuffer requires byteLength > 0.");
|
|
221
|
+
}
|
|
222
|
+
const alignedSize = Math.ceil(byteLength / 4) * 4;
|
|
223
|
+
const usage = spec.usage ?? (
|
|
224
|
+
globalThis.GPUBufferUsage
|
|
225
|
+
? (globalThis.GPUBufferUsage.STORAGE | globalThis.GPUBufferUsage.COPY_SRC | globalThis.GPUBufferUsage.COPY_DST)
|
|
226
|
+
: 0x8c
|
|
227
|
+
);
|
|
228
|
+
const buffer = device.createBuffer({
|
|
229
|
+
size: alignedSize,
|
|
230
|
+
usage,
|
|
231
|
+
...(spec.label ? { label: spec.label } : {}),
|
|
232
|
+
});
|
|
233
|
+
if (spec.initialData) {
|
|
234
|
+
const view = ArrayBuffer.isView(spec.initialData)
|
|
235
|
+
? new Uint8Array(spec.initialData.buffer, spec.initialData.byteOffset, spec.initialData.byteLength)
|
|
236
|
+
: new Uint8Array(spec.initialData);
|
|
237
|
+
device.queue.writeBuffer(buffer, 0, view);
|
|
238
|
+
}
|
|
239
|
+
return registerBuffer(buffer, { ...spec, byteLength: alignedSize, ownedByContext: true });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function resolveEntry(handleOrId) {
|
|
243
|
+
assertAlive();
|
|
244
|
+
const id = typeof handleOrId === "object" && handleOrId !== null ? handleOrId.handleId : Number(handleOrId);
|
|
245
|
+
if (typeof handleOrId === "object" && handleOrId !== null && handleOrId.deviceId != null && handleOrId.deviceId !== deviceId) {
|
|
246
|
+
const err = new Error(`GPU buffer handle ${id} belongs to device ${handleOrId.deviceId}, not ${deviceId}.`);
|
|
247
|
+
err.gpuStatus = SDN_GPU_STATUS.DEVICE_MISMATCH;
|
|
248
|
+
throw err;
|
|
249
|
+
}
|
|
250
|
+
const entry = handles.get(id);
|
|
251
|
+
if (!entry) {
|
|
252
|
+
const err = new Error(`Unknown GPU buffer handle ${id}.`);
|
|
253
|
+
err.gpuStatus = SDN_GPU_STATUS.UNKNOWN_HANDLE;
|
|
254
|
+
throw err;
|
|
255
|
+
}
|
|
256
|
+
return entry;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function getBuffer(handleOrId) {
|
|
260
|
+
return resolveEntry(handleOrId).buffer;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function describeBuffer(handleOrId) {
|
|
264
|
+
return buildDescriptor(resolveEntry(handleOrId));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Read bytes from a registered shared buffer back to CPU (used only for CPU-consumer fallback or verification). */
|
|
268
|
+
async function readBuffer(handleOrId, byteOffset = 0, byteLength = null) {
|
|
269
|
+
const entry = resolveEntry(handleOrId);
|
|
270
|
+
const length = byteLength == null ? entry.byteLength - byteOffset : Number(byteLength);
|
|
271
|
+
if (length <= 0) return new Uint8Array(0);
|
|
272
|
+
const aligned = Math.ceil(length / 4) * 4;
|
|
273
|
+
const U = globalThis.GPUBufferUsage ?? { MAP_READ: 0x0001, COPY_DST: 0x0008 };
|
|
274
|
+
const M = globalThis.GPUMapMode ?? { READ: 0x0001 };
|
|
275
|
+
const staging = device.createBuffer({ size: aligned, usage: U.MAP_READ | U.COPY_DST });
|
|
276
|
+
try {
|
|
277
|
+
const enc = device.createCommandEncoder();
|
|
278
|
+
enc.copyBufferToBuffer(entry.buffer, byteOffset, staging, 0, aligned);
|
|
279
|
+
device.queue.submit([enc.finish()]);
|
|
280
|
+
await staging.mapAsync(M.READ, 0, aligned);
|
|
281
|
+
const copy = new Uint8Array(staging.getMappedRange(0, aligned).slice(0, length));
|
|
282
|
+
staging.unmap();
|
|
283
|
+
return copy;
|
|
284
|
+
} finally {
|
|
285
|
+
staging.destroy();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function releaseBuffer(handleOrId) {
|
|
290
|
+
const id = typeof handleOrId === "object" && handleOrId !== null ? handleOrId.handleId : Number(handleOrId);
|
|
291
|
+
const entry = handles.get(id);
|
|
292
|
+
if (!entry) return false;
|
|
293
|
+
handles.delete(id);
|
|
294
|
+
if (entry.ownedByContext) {
|
|
295
|
+
entry.buffer.destroy();
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function listBuffers() {
|
|
301
|
+
return Array.from(handles.values(), buildDescriptor);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function getDeviceInfo() {
|
|
305
|
+
const lim = device.limits ?? {};
|
|
306
|
+
return Object.freeze({
|
|
307
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
308
|
+
available: !destroyed,
|
|
309
|
+
backendKind,
|
|
310
|
+
backendCode,
|
|
311
|
+
deviceId,
|
|
312
|
+
adapterLabel,
|
|
313
|
+
maxStorageBufferBindingSize: Number(lim.maxStorageBufferBindingSize ?? 0),
|
|
314
|
+
maxBufferSize: Number(lim.maxBufferSize ?? 0),
|
|
315
|
+
maxComputeWorkgroupSizeX: Number(lim.maxComputeWorkgroupSizeX ?? 256),
|
|
316
|
+
maxComputeInvocationsPerWorkgroup: Number(lim.maxComputeInvocationsPerWorkgroup ?? 256),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function destroy() {
|
|
321
|
+
if (destroyed) return;
|
|
322
|
+
destroyed = true;
|
|
323
|
+
for (const entry of handles.values()) {
|
|
324
|
+
if (entry.ownedByContext) entry.buffer.destroy();
|
|
325
|
+
}
|
|
326
|
+
handles.clear();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const context = {
|
|
330
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
331
|
+
deviceId,
|
|
332
|
+
device,
|
|
333
|
+
adapter: options.adapter ?? null,
|
|
334
|
+
adapterLabel,
|
|
335
|
+
backendKind,
|
|
336
|
+
backendCode,
|
|
337
|
+
getDeviceInfo,
|
|
338
|
+
createBuffer,
|
|
339
|
+
registerBuffer,
|
|
340
|
+
getBuffer,
|
|
341
|
+
describeBuffer,
|
|
342
|
+
readBuffer,
|
|
343
|
+
releaseBuffer,
|
|
344
|
+
listBuffers,
|
|
345
|
+
destroy,
|
|
346
|
+
};
|
|
347
|
+
return context;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Creates a runtime-host capability adapter for `gpu_compute` implementing v2 device/buffer operations. */
|
|
351
|
+
export function createGpuCapabilityAdapter(contextOrNull = null) {
|
|
352
|
+
return {
|
|
353
|
+
"device.info.v1"() {
|
|
354
|
+
if (!contextOrNull) {
|
|
355
|
+
return {
|
|
356
|
+
abiVersion: SDN_GPU_ABI_VERSION,
|
|
357
|
+
available: false,
|
|
358
|
+
backendKind: "cpu-fallback",
|
|
359
|
+
backendCode: SDN_GPU_BACKEND.CPU_FALLBACK,
|
|
360
|
+
deviceId: 0,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return contextOrNull.getDeviceInfo();
|
|
364
|
+
},
|
|
365
|
+
"buffer.create.v1"(params = {}) {
|
|
366
|
+
if (!contextOrNull) {
|
|
367
|
+
const err = new Error("GPU compute context unavailable.");
|
|
368
|
+
err.gpuStatus = SDN_GPU_STATUS.UNAVAILABLE;
|
|
369
|
+
throw err;
|
|
370
|
+
}
|
|
371
|
+
return contextOrNull.createBuffer(params);
|
|
372
|
+
},
|
|
373
|
+
"buffer.describe.v1"(params = {}) {
|
|
374
|
+
if (!contextOrNull) {
|
|
375
|
+
const err = new Error("GPU compute context unavailable.");
|
|
376
|
+
err.gpuStatus = SDN_GPU_STATUS.UNAVAILABLE;
|
|
377
|
+
throw err;
|
|
378
|
+
}
|
|
379
|
+
return contextOrNull.describeBuffer(params.handle ?? params.handleId);
|
|
380
|
+
},
|
|
381
|
+
"buffer.read.v1"(params = {}) {
|
|
382
|
+
if (!contextOrNull) {
|
|
383
|
+
const err = new Error("GPU compute context unavailable.");
|
|
384
|
+
err.gpuStatus = SDN_GPU_STATUS.UNAVAILABLE;
|
|
385
|
+
throw err;
|
|
386
|
+
}
|
|
387
|
+
return contextOrNull.readBuffer(params.handle ?? params.handleId, params.byteOffset ?? 0, params.byteLength ?? null);
|
|
388
|
+
},
|
|
389
|
+
"buffer.release.v1"(params = {}) {
|
|
390
|
+
if (!contextOrNull) return { released: false };
|
|
391
|
+
return { released: contextOrNull.releaseBuffer(params.handle ?? params.handleId) };
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
@@ -6,6 +6,23 @@ import {
|
|
|
6
6
|
isSharedBuffer,
|
|
7
7
|
} from "./runtimeRegionStore.js";
|
|
8
8
|
import { createModuleRegistry } from "./moduleRegistry.js";
|
|
9
|
+
import {
|
|
10
|
+
SDN_GPU_ABI_VERSION,
|
|
11
|
+
SDN_GPU_CAPABILITY_ID,
|
|
12
|
+
SDN_GPU_CAPABILITY_SCOPE_V1,
|
|
13
|
+
SDN_GPU_CAPABILITY_SCOPE_V2,
|
|
14
|
+
SDN_GPU_STATUS,
|
|
15
|
+
SDN_GPU_BACKEND,
|
|
16
|
+
SDN_GPU_BUFFER_ROLE,
|
|
17
|
+
SDN_GPU_SCALAR_FORMAT,
|
|
18
|
+
packF64Bits,
|
|
19
|
+
unpackF64Bits,
|
|
20
|
+
f64ArrayToU32Pairs,
|
|
21
|
+
u32PairsToF64Array,
|
|
22
|
+
detectWebGpu,
|
|
23
|
+
createSharedGpuContext,
|
|
24
|
+
createGpuCapabilityAdapter,
|
|
25
|
+
} from "./gpuComputeContext.js";
|
|
9
26
|
import {
|
|
10
27
|
SCR_GRID_STATE_FLOATS,
|
|
11
28
|
SCR_GRID_STATE_BYTES,
|
|
@@ -192,6 +209,21 @@ export {
|
|
|
192
209
|
encodeScrGridFlatBuffer,
|
|
193
210
|
decodeScrGridFlatBuffer,
|
|
194
211
|
createSharedEphemerisGridManager,
|
|
212
|
+
SDN_GPU_ABI_VERSION,
|
|
213
|
+
SDN_GPU_CAPABILITY_ID,
|
|
214
|
+
SDN_GPU_CAPABILITY_SCOPE_V1,
|
|
215
|
+
SDN_GPU_CAPABILITY_SCOPE_V2,
|
|
216
|
+
SDN_GPU_STATUS,
|
|
217
|
+
SDN_GPU_BACKEND,
|
|
218
|
+
SDN_GPU_BUFFER_ROLE,
|
|
219
|
+
SDN_GPU_SCALAR_FORMAT,
|
|
220
|
+
packF64Bits,
|
|
221
|
+
unpackF64Bits,
|
|
222
|
+
f64ArrayToU32Pairs,
|
|
223
|
+
u32PairsToF64Array,
|
|
224
|
+
detectWebGpu,
|
|
225
|
+
createSharedGpuContext,
|
|
226
|
+
createGpuCapabilityAdapter,
|
|
195
227
|
};
|
|
196
228
|
// Flow-tier validating method registry (vendored sdn-flow semantics; distinct
|
|
197
229
|
// from createModuleRegistry's module-lifecycle registry).
|
|
@@ -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": [
|