5.9 KiB
5.9 KiB
DRP2 Error Model
This document defines the shape of validation and execution errors for DRP2.
Goals
- Errors must be backend-agnostic at the contract level.
- Producers must get actionable diagnostics without needing Vulkan or WebGPU knowledge.
- Native and browser runtimes must report the same logical error categories for the same invalid command stream.
Error Classes
Use stable symbolic codes, not backend strings, as the primary contract.
DRP2_ERR_UNKNOWN_COMMANDDRP2_ERR_UNSUPPORTED_VERSIONDRP2_ERR_UNSUPPORTED_CAPABILITYDRP2_ERR_INVALID_IDDRP2_ERR_DUPLICATE_IDDRP2_ERR_WRONG_OBJECT_TYPEDRP2_ERR_DESTROYED_OBJECTDRP2_ERR_INVALID_STATEDRP2_ERR_INVALID_ARGUMENTDRP2_ERR_OUT_OF_RANGEDRP2_ERR_ALIGNMENTDRP2_ERR_LAYOUTDRP2_ERR_USAGEDRP2_ERR_PASS_MISMATCHDRP2_ERR_PIPELINE_MISMATCHDRP2_ERR_BINDING_MISMATCHDRP2_ERR_FORMAT_MISMATCHDRP2_ERR_FEATURE_REQUIREDDRP2_ERR_OOMDRP2_ERR_INTERNAL
Reporting Shape
Every runtime should be able to map a failure to a structured record with at least:
- code
- severity
- command index
- object id, if relevant
- short message
- optional backend detail string
Backend detail may be richer, but the stable contract is the symbolic code and its semantics.
Validation Phases
Errors should be attributable to one of these phases:
- decode
- schema validation
- semantic validation
- capability validation
- execution
The same logical stream should fail as early as possible. If a problem is detectable during decode or semantic validation, runtimes should not defer it until backend execution.
Contract Rules
- Invalid streams are rejected deterministically.
- Validation failures are not recoverable within the same command.
- An invalid command does not permit partially-committed object state.
- Backend-native validation messages are supplementary and non-normative.
- Unsupported capabilities must fail with a capability-oriented error, not a generic internal error.
Code Selection Rules
Use the most specific error code that matches the contract-visible failure.
Identity And Type
- use
DRP2_ERR_INVALID_IDwhen the referenced id was never created, - use
DRP2_ERR_DESTROYED_OBJECTwhen the referenced id existed earlier in the same stream but has already been destroyed, - use
DRP2_ERR_DUPLICATE_IDwhen a creation command reuses an already-used id, - use
DRP2_ERR_WRONG_OBJECT_TYPEwhen the id exists and is live but belongs to the wrong object kind, - for typed bind-group entries, a structural
binding_typeversusresource_kindmismatch should fail during schema validation before semantic code selection is considered.
State Versus Usage
- use
DRP2_ERR_INVALID_STATEwhen the failure is about recorder scope or sequencing, - use
DRP2_ERR_USAGEwhen the failure is about whether a live resource may legally be used or destroyed in the current contract state, - use
DRP2_ERR_INVALID_ARGUMENTwhen a create-time command shape is structurally incompatible with an already-resolved live object, - prefer
DRP2_ERR_INVALID_STATEfor examples such as:- draw outside a render pass
- draw or dispatch without a pipeline bound in the current pass
- setting a bind group before a pipeline is bound in the current pass
- setting a bind group whose layout does not match the current pipeline slot
- draw without all vertex-buffer slots required by the bound pipeline
- indexed draw without a bound index buffer
- dispatch outside a compute pass
- finishing an encoder with an open pass
- resubmitting a command buffer that was already submitted earlier in the stream
- issuing a copy command inside a pass
- prefer
DRP2_ERR_USAGEfor examples such as:- destroying a resource still referenced by recorded or submitted work
- destroying a bind group still referenced by recorded or submitted work
- creating a bind-group entry whose referenced resource lacks the usage bits implied by
binding_type - using a resource in a way forbidden by its declared creation usage
- prefer
DRP2_ERR_INVALID_ARGUMENTfor examples such as:- creating a bind group whose entries do not match the declared layout
- creating a dynamic buffer binding without the explicit range required by the layout
Range, Layout, And Alignment
- use
DRP2_ERR_OUT_OF_RANGEwhen numeric bounds are exceeded after the command shape is otherwise valid, - use
DRP2_ERR_LAYOUTwhen the memory-layout description itself is invalid or inconsistent, DRP2_ERR_ALIGNMENTremains reserved but is not currently exercised by the active2.0executable contract,- prefer
DRP2_ERR_OUT_OF_RANGEfor examples such as:offset + sizeexceeding buffer bounds- a texture write region exceeding the destination subresource extent
- prefer
DRP2_ERR_LAYOUTfor examples such as:- impossible or self-contradictory row-stride / image-stride declarations
- layout metadata incompatible with the transfer shape even when the destination range exists
Phase Preference
- schema-shape failures should report a schema-validation phase before semantic codes are considered,
- semantic code selection applies only after the command object has passed schema validation,
- capability-dependent failures should prefer
DRP2_ERR_UNSUPPORTED_CAPABILITYorDRP2_ERR_FEATURE_REQUIREDover generic usage or internal errors.
First Conformance Set
The first fixture set should include negatives for:
- duplicate object creation
- using unknown ids
- wrong object type in a command
- draw outside a render pass
- incompatible pipeline in a pass
- invalid binding layout
- unsupported format or feature
- invalid copy ranges or layout metadata
- shader-stage mismatch or shader-feature mismatch in pipeline creation
- schema-shape failures such as missing discriminators or missing required fields