Implementation
static TraceEvent fromJson(
Map<String, Object?> j,
TraceBlobReader blob,
) => switch (j['kind']) {
'beginFrame' => const TraceBeginFrame(),
'uploadGeometry' => TraceUploadGeometry(
id: asInt(j['id']),
usage: usageFromJson(j['usage']),
bytes: blob.read(j['bytes']),
),
'overwriteGeometry' => TraceOverwriteGeometry(
target: _range(j['target']),
offset: asInt(j['offset']),
bytes: blob.read(j['bytes']),
),
'releaseGeometry' => TraceReleaseGeometry(asInt(j['buffer'])),
'createTexture' => TraceCreateTexture(
id: asInt(j['id']),
spec: specFromJson(j['spec']),
),
'createTextureFromPixels' => TraceCreateTextureFromPixels(
id: asInt(j['id']),
width: asInt(j['width']),
height: asInt(j['height']),
format: textureFormatWire.read(j['format']),
pixels: blob.read(j['pixels']),
mipLevels: (j['mipLevels'] as List<Object?>?)?.map(blob.read).toList(),
),
'createCubeTextureFromPixels' => TraceCreateCubeTextureFromPixels(
id: asInt(j['id']),
size: asInt(j['size']),
format: textureFormatWire.read(j['format']),
faces: (j['faces']! as List<Object?>).map(blob.read).toList(),
mipLevels: (j['mipLevels'] as List<Object?>?)
?.map((f) => (f! as List<Object?>).map(blob.read).toList())
.toList(),
),
'createCubeRenderTarget' => TraceCreateCubeRenderTarget(
id: asInt(j['id']),
size: asInt(j['size']),
format: textureFormatWire.read(j['format']),
mipLevels: asInt(j['mipLevels']),
),
'overwriteTexture' => TraceOverwriteTexture(
texture: asInt(j['texture']),
rgba: blob.read(j['rgba']),
region: j['region'] == null ? null : screenRectFromJson(j['region']),
mipLevel: asInt(j['mipLevel']),
),
'releaseTexture' => TraceReleaseTexture(asInt(j['texture'])),
'loadShaders' => TraceLoadShaders(blob.read(j['bytes'])),
'createPipeline' => TraceCreatePipeline(
id: asInt(j['id']),
vertex: j['vertex']! as String,
fragment: j['fragment']! as String,
layout: j['layout'] == null ? null : layoutFromJson(j['layout']),
),
'beginRenderPass' => TraceBeginRenderPass(
pass: asInt(j['pass']),
label: j['label'] as String?,
colors: <TraceColorTarget>[
for (final c in (j['colors']! as List<Object?>).map(asMap))
TraceColorTarget(
texture: asInt(c['texture']),
resolveTexture: c['resolveTexture'] == null
? null
: asInt(c['resolveTexture']),
loadAction: loadActionWire.read(c['loadAction']),
storeAction: storeActionWire.read(c['storeAction']),
clearValue: c['clearValue'] == null
? null
: vector4FromJson(c['clearValue']),
face: asInt(c['face']),
mipLevel: asInt(c['mipLevel']),
// Absent from a trace written before 1.0 recorded layers, and
// from any attachment at layer zero.
layer: c['layer'] == null ? 0 : asInt(c['layer']),
),
],
depth: switch (j['depth']) {
null => null,
final Object d => _depthTarget(asMap(d)),
},
),
'readPixels' => TraceReadPixels(asInt(j['texture'])),
'readback' => TraceReadback(
texture: asInt(j['texture']),
region: j['region'] == null ? null : screenRectFromJson(j['region']),
),
'setViewport' => TraceSetViewport(
asInt(j['pass']),
screenRectFromJson(j['rect']),
),
'setScissor' => TraceSetScissor(
asInt(j['pass']),
screenRectFromJson(j['rect']),
),
'setPrimitiveType' => TraceSetPrimitiveType(
asInt(j['pass']),
primitiveTypeWire.read(j['value']),
),
'setPolygonMode' => TraceSetPolygonMode(
asInt(j['pass']),
polygonModeWire.read(j['value']),
),
'setCullMode' => TraceSetCullMode(
asInt(j['pass']),
cullModeWire.read(j['value']),
),
'setWindingOrder' => TraceSetWindingOrder(
asInt(j['pass']),
windingOrderWire.read(j['value']),
),
'setDepthWrite' => TraceSetDepthWrite(
asInt(j['pass']),
j['value']! as bool,
),
'setAlphaToCoverage' => TraceSetAlphaToCoverage(
asInt(j['pass']),
j['value']! as bool,
),
'setDepthCompare' => TraceSetDepthCompare(
asInt(j['pass']),
compareFunctionWire.read(j['value']),
),
'setStencil' => TraceSetStencil(
asInt(j['pass']),
stencilFromJson(j['front']),
j['back'] == null ? null : stencilFromJson(j['back']),
),
'setStencilReference' => TraceSetStencilReference(
asInt(j['pass']),
asInt(j['value']),
),
'setBlend' => TraceSetBlend(
asInt(j['pass']),
j['state'] == null ? null : blendFromJson(j['state']),
asInt(j['attachment']),
),
'setBlendColor' => TraceSetBlendColor(
asInt(j['pass']),
linearColorFromJson(j['color']),
),
'pushDebugGroup' => TracePushDebugGroup(
asInt(j['pass']),
j['label']! as String,
),
'popDebugGroup' => TracePopDebugGroup(asInt(j['pass'])),
'insertDebugMarker' => TraceInsertDebugMarker(
asInt(j['pass']),
j['label']! as String,
),
'setLabel' => TraceSetLabel(
resource: TraceLabeled.fromWire(j['resource']),
id: asInt(j['id']),
label: j['label']! as String,
),
'bindPipeline' => TraceBindPipeline(asInt(j['pass']), asInt(j['pipeline'])),
'bindVertexBuffer' => TraceBindVertexBuffer(
pass: asInt(j['pass']),
buffer: _range(j['buffer']),
vertexCount: asInt(j['vertexCount']),
slot: asInt(j['slot']),
),
'bindVertexData' => TraceBindVertexData(
pass: asInt(j['pass']),
bytes: blob.read(j['bytes']),
vertexCount: asInt(j['vertexCount']),
slot: asInt(j['slot']),
),
'bindIndexBuffer' => TraceBindIndexBuffer(
pass: asInt(j['pass']),
buffer: _range(j['buffer']),
type: indexTypeWire.read(j['type']),
indexCount: asInt(j['indexCount']),
),
'bindIndexData' => TraceBindIndexData(
pass: asInt(j['pass']),
bytes: blob.read(j['bytes']),
type: indexTypeWire.read(j['type']),
indexCount: asInt(j['indexCount']),
),
'bindUniformBlock' => TraceBindUniformBlock(
pass: asInt(j['pass']),
shader: j['shader']! as String,
block: j['block']! as String,
members: _members(j['members'], blob),
),
'bindTexture' => TraceBindTexture(
pass: asInt(j['pass']),
shader: j['shader']! as String,
slot: j['slot']! as String,
texture: asInt(j['texture']),
sampler: j['sampler'] == null ? null : samplerFromJson(j['sampler']),
),
'clearBindings' => TraceClearBindings(asInt(j['pass'])),
'draw' => TraceDraw(
asInt(j['pass']),
instanceCount: asInt(j['instanceCount']),
firstIndex: j['firstIndex'] == null ? 0 : asInt(j['firstIndex']),
indexCount: j['indexCount'] == null ? null : asInt(j['indexCount']),
),
'submit' => TraceSubmit(asInt(j['pass'])),
'createStorageBuffer' => TraceCreateStorageBuffer(
id: asInt(j['id']),
bytes: blob.read(j['bytes']),
hostReadable: j['hostReadable']! as bool,
indices: j['indices'] == null ? null : asInt(j['indices']),
),
'releaseStorageBuffer' => TraceReleaseStorageBuffer(asInt(j['buffer'])),
'createComputePipeline' => TraceCreateComputePipeline(
asInt(j['id']),
j['shader']! as String,
),
'beginComputePass' => TraceBeginComputePass(
asInt(j['pass']),
j['label'] as String?,
),
'computeBindPipeline' => TraceComputeBindPipeline(
asInt(j['pass']),
asInt(j['pipeline']),
),
'computeBindStorageBuffer' => TraceComputeBindStorageBuffer(
pass: asInt(j['pass']),
shader: j['shader']! as String,
name: j['name']! as String,
buffer: asInt(j['buffer']),
),
'computeBindUniformBlock' => TraceComputeBindUniformBlock(
pass: asInt(j['pass']),
shader: j['shader']! as String,
block: j['block']! as String,
members: _members(j['members'], blob),
),
'dispatch' => TraceDispatch(
asInt(j['pass']),
asInt(j['x']),
asInt(j['y']),
asInt(j['z']),
),
'computeSubmit' => TraceComputeSubmit(asInt(j['pass'])),
'readBuffer' => TraceReadBuffer(asInt(j['buffer'])),
final other => throw TraceFormatException(
'a trace event of kind $other, which this build does not know',
),
};