-
Notifications
You must be signed in to change notification settings - Fork 92
Add tests for mapping behavior around device.destroy() #4295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kainino0x
wants to merge
2
commits into
gpuweb:main
Choose a base branch
from
kainino0x:map-destroy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
kTextureUsageCopyInfo, | ||
kShaderStageKeys, | ||
} from '../../../../capability_info.js'; | ||
import { GPUConst } from '../../../../constants.js'; | ||
import { | ||
getBlockInfoForColorTextureFormat, | ||
kCompressedTextureFormats, | ||
|
@@ -52,16 +53,15 @@ class DeviceDestroyTests extends AllFeaturesMaxLimitsValidationTest { | |
* `fn` after the device is destroyed without any specific expectation. If `awaitLost` is true, we | ||
* also wait for device.lost to resolve before executing `fn` in the destroy case. | ||
*/ | ||
async executeAfterDestroy(fn: () => void, awaitLost: boolean): Promise<void> { | ||
async executeAfterDestroy(fn: () => void | Promise<void>, awaitLost: boolean): Promise<void> { | ||
this.expectDeviceLost('destroyed'); | ||
|
||
this.expectValidationError(fn, false); | ||
this.device.destroy(); | ||
if (awaitLost) { | ||
const lostInfo = await this.device.lost; | ||
this.expect(lostInfo.reason === 'destroyed'); | ||
} | ||
fn(); | ||
await fn(); | ||
} | ||
|
||
/** | ||
|
@@ -146,6 +146,93 @@ Tests creating buffers on destroyed device. Tests valid combinations of: | |
}, awaitLost); | ||
}); | ||
|
||
g.test('mapping,mappedAtCreation') | ||
.desc( | ||
` | ||
Tests behavior of mappedAtCreation buffers when destroying the device (multiple times). | ||
- Various usages | ||
- Wait for .lost or not | ||
` | ||
) | ||
.params(u => | ||
u | ||
.combine('usage', [ | ||
GPUConst.BufferUsage.MAP_READ, | ||
GPUConst.BufferUsage.MAP_WRITE, | ||
GPUConst.BufferUsage.COPY_SRC, | ||
]) | ||
.combine('awaitLost', [true, false]) | ||
) | ||
.fn(async t => { | ||
const { awaitLost, usage } = t.params; | ||
|
||
const b1 = t.createBufferTracked({ size: 16, usage, mappedAtCreation: true }); | ||
t.expect(b1.mapState === 'mapped', 'b1 before destroy 1'); | ||
|
||
await t.executeAfterDestroy(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are still pending this decision right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
// Destroy should have unmapped everything. | ||
t.expect(b1.mapState === 'unmapped', 'b1 after destroy 1'); | ||
// But unmap just in case, to reset state before continuing. | ||
b1.unmap(); | ||
|
||
// mappedAtCreation should still work. | ||
const b2 = t.createBufferTracked({ size: 16, usage, mappedAtCreation: true }); | ||
t.expect(b2.mapState === 'mapped', 'b2 at creation after destroy 1'); | ||
|
||
// Destroying again should unmap. | ||
t.device.destroy(); | ||
t.expect(b2.mapState === 'unmapped', 'b2 after destroy 2'); | ||
}, awaitLost); | ||
}); | ||
|
||
g.test('mapping,mapAsync') | ||
.desc( | ||
` | ||
Tests behavior of mapAsync'd buffers when destroying the device. | ||
- Various usages | ||
- Wait for .lost or not | ||
` | ||
) | ||
.params(u => | ||
u | ||
.combine('usage', [ | ||
GPUConst.BufferUsage.MAP_READ, | ||
GPUConst.BufferUsage.MAP_WRITE, | ||
GPUConst.BufferUsage.COPY_SRC, | ||
]) | ||
.combine('awaitLost', [true, false]) | ||
) | ||
.fn(async t => { | ||
const { awaitLost, usage } = t.params; | ||
|
||
const b = t.createBufferTracked({ size: 16, usage }); | ||
const mode = | ||
usage === GPUBufferUsage.MAP_READ | ||
? GPUMapMode.READ | ||
: usage === GPUBufferUsage.MAP_WRITE | ||
? GPUMapMode.WRITE | ||
: 0; | ||
if (mode) { | ||
await b.mapAsync(mode); | ||
t.expect(b.mapState === 'mapped', 'bAsync before destroy 1'); | ||
} else { | ||
t.expect(b.mapState === 'unmapped', 'bAsync before destroy 1'); | ||
} | ||
|
||
await t.executeAfterDestroy(async () => { | ||
// Destroy should have unmapped everything. | ||
t.expect(b.mapState === 'unmapped', 'bAsync after destroy 1'); | ||
// But unmap just in case, to reset state before continuing. | ||
b.unmap(); | ||
|
||
// Check that mapping after destroy fails with AbortError. | ||
const mapPromise = b.mapAsync(mode); | ||
t.shouldReject('AbortError', mapPromise); | ||
await mapPromise.catch(() => {}); | ||
t.expect(b.mapState === 'unmapped', 'bAsync after mapAsync after destroy 1'); | ||
}, awaitLost); | ||
}); | ||
|
||
g.test('createTexture,2d,uncompressed_format') | ||
.desc( | ||
` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn
is already called below, it should not be called twice. We don't need to capture validation errors anymore because there are never any (and test teardown will check this). (Likely when this test was written, sometimes there were validation errors here.)