Skip to content

Revamp object status APIs with testing in mind - #215

Closed
kainino0x wants to merge 1 commit into
gpuweb:masterfrom
kainino0x:errors3-objectstatus
Closed

kainino0x wants to merge 1 commit into
gpuweb:masterfrom
kainino0x:errors3-objectstatus

Conversation

@kainino0x

@kainino0x kainino0x commented Feb 22, 2019 •

Copy link
Copy Markdown
Contributor

This replaces #197 (tryCreate) and should also solve our conformance testing needs.

@kainino0x

Copy link
Copy Markdown
Contributor Author

Apologies for getting this out late, but here's the next revision of this part of error handling. We might be able to talk about this at the next meeting if people do have a chance to look.

Comment thread design/ErrorHandling.md Resolved
Comment thread design/ErrorHandling.md Resolved
Comment thread design/ErrorHandling.md
`device.getLastOperationStatus()` always resolves to the status of the most recent void-returning operation.
If called multiple times in a row, it returns the same result (but not the same object).

`getLastOperationStatus` returns a Promise that resolves to a `GPUOperationStatus` object describing the status of the last operation on this object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing we would also like to make sure no errors happened in previous operations and not just the current operation.

Comment thread design/ErrorHandling.md
Regardless of any recovery efforts the application makes, if creation fails,
the resulting object is invalid (and subject to error propagation).
- `getOperationStatuses`: returns a sequence of statuses for past operations.
Con: sequence will grow unboundedly unless there is some arbitrary limit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's ok, in general we only care about whether at least one error happened or none happened.

@Kangz

Kangz commented Feb 25, 2019

Copy link
Copy Markdown
Contributor

It is nice that this approach unifies OOM and validation errors but I have some concerns, and maybe an alternative.

One concern is that in the proposal the interactions of getStatus and getLastOperation and onvalidationerror are unclear. Are the two mechanisms orthogonal which means an error could be surfaced in multiple ways, or do they interact and somehow errors that have been seen with getStatus don't appear as validation error events?

Another concern is that it makes it easy to call getStatus on every object when it actually is bad practice and would cause extra GC pressure / IPC messages / promise tasks.

Finally it adds a lot of different mechanisms to handle different types of errors when it feels like they could all be unified (except device lost).

The alternative below tries to make OOM, telemetry, createReady and testing all use the same mechanism.

// GPUErrorStatus is the same as this proposal's GPUObjectStatus
partial interface GPUDevice : EventTarget {
    void pushErrorScope();
    Promise<GPUStatus> popErrorScope();

    attribute EventHandler unscopederror; // The event is essentially a GPUErrorStatus
};

The idea being that scopes capture the first error that is triggered while they are active as the innermost scope (or no error) and resolve the promise with that status. The promise reject on device loss and if an error is generated with no error scope present then the event is fired (with errors being skipped after a while).

Checking for OOM is the following:

device.pushErrorScope();
const texture = device.createTexture({
    // descriptor
});
const textureStatus = await device.popErrorScope();
if (!textureStatus.succeeded) {
    // stuff depending on OOM, testing
}

createReady would look like the following:

device.pushErrorScope();
const pipeline = device.createPipeline({
    // descriptor
});
const pipelineStatus = await device.popErrorScope();
if (!pipelineStatus.succeeded) {
    // Forward to telemetry
}
// Object is created.

Testing error happens exactly in a function call looks like the following:

device.pushErrorScope();
// Do stuff that shouldn't produce errors.
{
    device.pushErrorScope();
    device.doOperationThatErrors();
    device.popErrorScope().then(status => assert(!status.succeeded));
}
// More stuff that doesn't produce errors
device.popErrorScope().then(status => assert(status.succeeded));

For applications that handle error scoping only for particular object (OOM or waiting for the object to be created), then telemetry would use the event handler for unscoped errors:

device.addEventListener('unscopederror', (event) => {
    appendToTelemetryReport(event.message);
});

Questions:

  • Should pushing an error scope allow to push scopes that don't capture errors (would avoid the need for pushing to telemetry manually in the createReady case)
  • Do we need error codes with this?

@kainino0x

Copy link
Copy Markdown
Contributor Author

I strongly agree that the interactions of the various error mechanisms is unclear. It's one of the reasons that it took me a long time to even get to this proposal. I'll read and consider the rest of your comment as soon as I have a chance.

Comment thread design/ErrorHandling.md
a `"recoverable-out-of-memory"` error for the object creation, and `"validation-error"`s for any subsequent uses of the invalid object.
The application may need to understand whether such error log entries were part of a recovered allocation (e.g. to avoid sending telemetry for those errors).
To facilitate this filtering, the handle to the invalid object (including "expando" JavaScript properties) is attached to the error log entry (see above).
- Instead of `device.getStatus(obj)`, have `obj.getStatus()`. Con: Pollutes objects with rarely-used methods. Pro: Maybe slightly more clear to users.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is the first time in the document where you mention device.getStatus(obj) vs. obj.getStatus(). All this time, I thought the proposal was the latter. I suggest having this discussion earlier in the document.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is because I changed it and didn't do a good job of fixing up the references. Thanks for catching this.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Con: Pollutes objects with rarely-used methods.

Have we thought about having GPUStatusableObject as a base class object (that has getStatus() method) for the GPU* objects in the typedef?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it, but I'm more concerned with polluting actual objects, not polluting the IDL. This would still put one on every object.

I think I will be moving away from getStatus in the next iteration though.

Comment thread design/ErrorHandling.md Resolved
Comment thread design/ErrorHandling.md
Through this mechanism, allocation failure ("out-of-memory") can also be expressed.

Object status can be queried with `getStatus`.
`getStatus` returns a Promise which resolves to a `GPUObjectStatus` object that reports the status of the object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think a promise returning getStatus is the right thing to do.

Having getStatus return a promise means code which used to run completely inside one requestAnimationFrame callback now runs across multiple task boundaries, thus delaying frames and changing the behavior of the application. This is particularly troubling for WebXR applications where pose information sent to its requestAnimationFrame callback becomes invalid outside of the callback.

I suggest we either make getStatus be synchronous or add a debug mode of the API where errors throw exceptions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explainer should make lifetimes of each promise instance clear. For instance, if I call device.getStatus(object) multiple times in a row with the same object, do I get back the same promise instance or is a brand new promise returned for each call? If the latter, I presume the only time the promise from getStatus will ever reject is for contextLost?

The same issue also applies to getLastOperationStatus().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like with the rest of the API, I'm trying to avoid adding any synchronous stuff. What use case do you have in mind that would make it necessary to getObjectStatus synchronously?

E.g. for pose data, the app can use (1) an existing buffer with setSubData, (2) an existing, already mapped buffer, or (3) createBufferMapped

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll probably have a Dev Tools option to (synchronously) "break on WebGPU error" as the dev mode.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: Use case:
The purpose of the PR is to add mechanisms whereby developers can easily debug their code when things go wrong. To that end, using the testing APIs should not change the behavior of the application with regard to the sequencing of RAFs in relation to one another or other events/callbacks running in the application.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not trying to design these mechanisms for debugging, since Dev Tools would hopefully provide good tools.

But it's a good point that sometimes you do want more programmatic debugging tools (printf style). I'll keep it in mind.

Comment thread design/ErrorHandling.md
- `GPU*Encoder.*`

These commands do not report errors.
Instead, any error is reported by `GPUCommandEncoder.finish`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say "any error is reported by GPUCommendEncoder.finish", does this mean GPUCommandEncoder.finish will be changed to return an error? I would expect to see an IDL change if that's the case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPUCommandEncoder.finish returns a GPUCommandBuffer, and that GPUCommandBuffer is invalid.

@kainino0x

Copy link
Copy Markdown
Contributor Author

Thanks Rafael and Corentin for all the feedback. I'll look at all of it together while trying to revise.

@kainino0x kainino0x closed this Mar 1, 2019
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants