Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions benchmark/framework/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ export const BENCHMARK_MANIFEST: BenchmarkManifest = Object.freeze({
})
]),
suites: Object.freeze([
Object.freeze({
id: 'p1-rendering-acceptance',
description:
'CPU/Null opaque MSAA graph and owner-mediated residency pressure acceptance evidence.',
domainIds: Object.freeze(['rendering', 'assets']),
pathPrefixes: Object.freeze([
'benchmark/p1-rendering-acceptance/',
'test/benchmark/p1-rendering-acceptance.test.ts',
'test/rendering/baseline-msaa-graph.test.ts',
'test/rendering/baseline-msaa-policy.test.ts',
'src/rendering/baseline/baseline-renderer.ts',
'src/rendering/baseline/baseline-options.ts',
'src/rendering/world/residency-pressure.ts',
'src/rendering/world/prepared-assets.ts'
]),
command: Object.freeze({
executable: 'node',
args: Object.freeze(['benchmark/p1-rendering-acceptance/runner.mjs', '{profile}'])
})
}),
Object.freeze({
id: 'dynamic-plugin-runtime',
description:
Expand Down
142 changes: 142 additions & 0 deletions benchmark/p1-rendering-acceptance/msaa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import assert from 'node:assert/strict';
import { NullDevice } from '../../src/rhi/null/device';
import { RenderGraphBuilder, RenderGraphExecutor } from '../../src/render-graph';
import { createOpaqueRenderSystem } from '../../src/rendering/phase/opaque-render-system';
import { resolveBaselineSampleCount } from '../../src/rendering/baseline/baseline-options';
import { RenderSystemRegistry, compileRenderSystems } from '../../src/rendering/systems';
import type { RenderEntityId } from '../../src/rendering/world';
import type { RenderView } from '../../src/rendering/visibility/types';
import type { AcceptanceObservation } from './types';

/**
* Executes empty-draw opaque passes; measures graph CPU work, not GPU raster cost.
* @throws When the positive view count or production attachment/resolve invariants are invalid.
*/
export async function observeMsaa(
viewCount: number,
sampleCount: 1 | 4
): Promise<AcceptanceObservation> {
assert.ok(Number.isSafeInteger(viewCount) && viewCount > 0);
const device = createMultisampleNullDevice();
assert.deepEqual(resolveBaselineSampleCount(device, sampleCount), { sampleCount });
const graph = new RenderGraphBuilder();
const registry = new RenderSystemRegistry();
const views: RenderView[] = [];
for (let index = 0; index < viewCount; index += 1) {
const id = `acceptance-${index}`;
views.push({
id,
camera: index as RenderEntityId,
surface: id,
viewport: { x: 0, y: 0, width: 64, height: 64 },
layerMask: 1,
featurePolicyKey: 'acceptance-v1',
historyKey: id
});
const color = graph.createTexture(texture('rgba16float', sampleCount));
const depth = graph.createTexture(texture('depth24plus', sampleCount));
const resolved = sampleCount === 4 ? graph.createTexture(texture('rgba16float', 1)) : undefined;
const opaque = createOpaqueRenderSystem({
id,
phase: { viewId: id, phase: 'opaque', packets: [] },
surfaceFrame: { kind: 'surface-frame', id },
color: texture('rgba16float', sampleCount),
depth: texture('depth24plus', sampleCount),
colorTarget: color,
depthTarget: depth,
...(resolved === undefined ? {} : { resolveTarget: resolved }),
present: false
});
const descriptor = opaque.descriptor;
assert.equal(descriptor.kind, 'raster');
if (descriptor.kind !== 'raster') throw new Error('Opaque descriptor must be raster.');
registry.add({
...descriptor,
setup(...[pass, context]: Parameters<typeof descriptor.setup>) {
const resources = descriptor.setup(pass, context);
// Empty draws still exercise attachment allocation/resolve; retain the pass explicitly.
pass.sideEffect(`acceptance-${index}`);
return resources;
}
});
}
const compiled = compileRenderSystems(registry, { views, graph });
const passes = compiled.plan.snapshot.passes;
const resources = compiled.plan.snapshot.resources;
assert.equal(passes.length, viewCount);
let resolves = 0;
for (const pass of passes) {
assert.ok(pass.rasterDetails);
resolves += pass.rasterDetails.resolveAttachments.length;
for (const resolve of pass.rasterDetails.resolveAttachments) {
const source = resources.find(
(resource) => resource.resourceId === resolve.source.resourceId
);
const destination = resources.find(
(resource) => resource.resourceId === resolve.destination.resourceId
);
assert.ok(source?.kind === 'texture' && destination?.kind === 'texture');
assert.equal(source.descriptor.sampleCount, 4);
assert.equal(destination.descriptor.sampleCount, 1);
assert.equal(source.descriptor.format, destination.descriptor.format);
assert.notEqual(source.resourceId, destination.resourceId);
}
}
assert.equal(resolves, sampleCount === 4 ? viewCount : 0);
const counts = resources
.filter((resource) => resource.kind === 'texture')
.map((resource) => {
assert.equal(resource.descriptor.width, 64);
return resource.descriptor.sampleCount;
});
assert.equal(counts.filter((count) => count === sampleCount).length, viewCount * 2);
assert.equal(resources.length, viewCount * (sampleCount === 4 ? 3 : 2));
const execution = new RenderGraphExecutor().execute(compiled.plan, { device });
assert.equal(execution.commandStats.renderPasses, viewCount);
assert.equal(device.queue.metrics().submitted, 1);
await execution.submission.done;
execution.commandBuffer.dispose();
device.destroy();
const counters = {
views: viewCount,
sampleCount,
resolves,
textures: resources.length,
renderPasses: execution.commandStats.renderPasses,
submissions: 1
};
return { checksum: JSON.stringify(counters), counters };
}

function createMultisampleNullDevice(): NullDevice {
const source = new NullDevice();
const capabilities = source.capabilities;
const formats = new Map(capabilities.formats);
for (const format of ['rgba16float', 'depth24plus'] as const) {
formats.set(format, {
sample: true,
filter: false,
render: true,
blend: false,
storage: false,
copySrc: true,
copyDst: true,
sampleCounts: [1, 4]
});
}
source.destroy();
// This is declared Null capability coverage; it does not assert real-device 4x support.
return new NullDevice({ capabilities: { ...capabilities, formats } });
}

function texture(format: 'rgba16float' | 'depth24plus', sampleCount: 1 | 4) {
return {
width: 64,
height: 64,
depthOrArrayLayers: 1,
mipLevelCount: 1,
sampleCount,
format,
usage: [format === 'rgba16float' ? 'color-attachment' : 'depth-stencil-attachment']
} as const;
}
144 changes: 144 additions & 0 deletions benchmark/p1-rendering-acceptance/residency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import assert from 'node:assert/strict';
import { createAssetHandle, defineAssetType } from '../../src/assets';
import { AssetPayloadRegistry } from '../../src/assets/runtime';
import { PreparedAssetRegistry } from '../../src/rendering/world';
import {
enforceCpuResidencyBudget,
enforceGpuResidencyBudget,
type ResidencyPressureSubject
} from '../../src/rendering/world/residency-pressure';
import { NullDevice } from '../../src/rhi/null/device';
import type { PreparedAssetLease, PreparedVariantKey } from '../../src/rendering/world';
import type { AcceptanceObservation } from './types';

/**
* Runs real owner eviction with leases and a pending Null submission; sizes are bytes.
* @throws When the positive four-aligned scale or owner protection/cleanup invariants are invalid.
*/
export async function observeResidency(
count: number,
mode: 'planner' | 'owner-scan'
): Promise<AcceptanceObservation> {
assert.ok(Number.isSafeInteger(count) && count > 0);
assert.equal(count % 4, 0);
const device = new NullDevice({ submissionMode: 'manual' });
const prepared = new PreparedAssetRegistry();
const payloads = new AssetPayloadRegistry();
const type = defineAssetType<{ value: number }>('acceptance-payload-v1');
const subjects: ResidencyPressureSubject[] = [];
const cpuLeases: Array<{ dispose(): void }> = [];
const gpuLeases: PreparedAssetLease<unknown>[] = [];
const submission = device.queue.submit([device.createCommandEncoder().finish()]);
let destroyedBuffers = 0;
for (let index = 0; index <= count; index += 1) {
const handle = createAssetHandle(type, `asset:acceptance-${index}`);
const key: PreparedVariantKey = {
assetId: handle.assetId,
payloadVersion: 1,
deviceGeneration: device.generation,
featurePolicyKey: 'acceptance-v1',
abiVersion: 'v1'
};
const buffer = device.createBuffer({ size: 64, usage: 1 << 3 });
prepared.publish({ key, value: { byteLength: 64, buffer } }, (value) => {
value.buffer.dispose();
assert.equal(value.buffer.state, 'disposed');
destroyedBuffers += 1;
});
const subject = { handle, gpuVariants: [key], priority: 0, lastUseTick: index, rebuildCost: 1 };
subjects.push(subject);
if (index === count) continue; // Extra device bytes are absent from initial candidates.
payloads.register(handle);
payloads.publish(
handle,
{
version: 1,
contentHash: `v1-${index}`,
byteLength: 32,
value: { value: index },
dependencies: []
},
(value) => ({ ...value })
);
if (index % 2 === 0) {
const lease = payloads.acquire(handle);
assert.ok(lease);
cpuLeases.push(lease);
}
if (index % 4 < 2) {
const lease = prepared.acquire(key);
assert.ok(lease);
if (index % 4 === 0) gpuLeases.push(lease);
else {
lease.retainUntil(submission);
lease.dispose();
}
}
}
const candidates = subjects.slice(0, count);
const first = enforce(candidates);
assert.deepEqual(first, {
cpuReleased: count * 16,
cpuRemaining: count * 16,
gpuReleased: count * 32,
gpuRemaining: count * 32 + 64
});
assert.equal(prepared.snapshot().activeLeases, count / 4);
assert.equal(prepared.snapshot().activeSubmissions, count / 4);
assert.equal(destroyedBuffers, count / 2);
for (const lease of cpuLeases) lease.dispose();
for (const lease of gpuLeases) lease.dispose();
device.queue.completeNextForTesting();
await submission.done;
await Promise.resolve();
const second = enforce(subjects);
assert.deepEqual(second, {
cpuReleased: count * 16,
cpuRemaining: 0,
gpuReleased: count * 32 + 64,
gpuRemaining: 0
});
assert.equal(prepared.snapshot().knownBytes, 0);
assert.equal(payloads.residentBytes, 0);
assert.equal(destroyedBuffers, count + 1);
device.destroy();
const counters = {
assets: count,
protectedCpu: count / 2,
protectedGpuLeases: count / 4,
protectedGpuSubmissions: count / 4,
unlistedGpuBytes: 64,
destroyedBuffers,
firstCpuReleased: first.cpuReleased,
firstGpuReleased: first.gpuReleased,
finalCpuBytes: 0,
finalGpuBytes: 0
};
return { checksum: JSON.stringify(counters), counters };

function enforce(inventory: readonly ResidencyPressureSubject[]) {
if (mode === 'planner') {
const cpu = enforceCpuResidencyBudget(payloads, 0, inventory);
const gpu = enforceGpuResidencyBudget(prepared, device.generation, 0, inventory);
return {
cpuReleased: cpu.releasedBytes,
cpuRemaining: cpu.remainingPressureBytes,
gpuReleased: gpu.releasedBytes,
gpuRemaining: gpu.remainingPressureBytes
};
}
// Lower-bound comparator: owners still validate leases; it omits planner priority ordering.
const cpuBefore = payloads.residentBytes;
const gpuBefore = prepared.snapshot().knownBytes;
for (const subject of inventory) {
if (payloads.inspect(subject.handle).revisions.length > 0) payloads.evict(subject.handle);
for (const key of subject.gpuVariants) prepared.evictUnreferenced(key);
}
return {
cpuReleased: cpuBefore - payloads.residentBytes,
cpuRemaining: payloads.residentBytes,
gpuReleased: gpuBefore - prepared.snapshot().knownBytes,
gpuRemaining: prepared.snapshot().knownBytes
};
}
}
Loading
Loading