// This test has 3 phases:
// 1) Repeatedly call a function that creates some WebGPU objects with
// some variations. One of the objects is always an encoder. Act on
// those objects in ways that might confuse the cycle detector. All
// of the objects *should* be garbage collectable, including the
// encoders. Store a weak link to each of the encoders.
// 2) Invoke garbage collection.
// 3) Confirm all the encoders were garbage collected.
// Define some stuff we'll use in the various phases.
const gc_promise = () =>
new Promise(resolve => SpecialPowers.exactGC(resolve));
// Define an array of structs containing a label and a weak reference
// to an encoder, then fill it by executing a bunch of WebGPU commands.
let results = [];
// Here's our WebGPU test function, which we'll call with permuted
// parameters:
// label: string label to use in error messages
// encoderType: string in ["render", "compute", "bundle"].
// resourceExtraParam: boolean should one of the resources get an
// added property with a scalar value. This can change the order that
// things are processed by the cycle collector.
// resourceCycle: boolean should one of the resources get an added
// property that is set to the encoder.
// endOrFinish: boolean should the encoder be ended. If not, it's just
// dropped.
let test_func = async ( label,
encoderType,
resourceExtraParam,
resourceCycle,
endOrFinish
) => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
if (resourceExtraParam) {
resource.extra = true;
}
if (resourceCycle) {
resource.encoder = encoder;
}
if (endOrFinish) {
if (encoderType == "render" || encoderType == "compute") {
pass.end();
} else if (encoderType == "bundle") {
encoder.finish();
}
}
// Get a weak ref to the encoder, which we'll check after GC to ensure
// that it got collected.
encoderWeakRef = SpecialPowers.Cu.getWeakReference(encoder);
ok(encoderWeakRef.get(), `${label} got encoder weak ref.`);
results.push({ label,
encoderWeakRef,
});
};
// The rest of the test will run in a promise chain. Define an async
// function to fill our results.
let call_test_func = async () => {
for (const encoderType of ["render", "compute", "bundle"]) {
for (const resourceExtraParam of [true, false]) {
for (const resourceCycle of [true, false]) {
for (const endOrFinish of [true, false]) {
const label = `[${encoderType}, ${resourceExtraParam}, ${resourceCycle}, ${endOrFinish}]`;
await test_func( label,
encoderType,
resourceExtraParam,
resourceCycle,
endOrFinish
);
}
}
}
}
};
// Phase 1: Start the promise chain and call test_func repeated to fill
// our results struct.
call_test_func()
// Phase 2: Do our garbage collection.
.then(gc_promise)
.then(gc_promise)
.then(gc_promise)
// Phase 3: Iterate over results and check that all of the encoders
// were garbage collected.
.then(() => {
for (result of results) {
ok(
!result.encoderWeakRef.get(),
`${result.label} cycle collected encoder.`
);
}
})
.catch(e => {
ok(false, `unhandled exception ${e}`);
})
.finally(() => {
SimpleTest.finish();
});
</script>
</body>
</html>
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.