-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add reftests: canvas display after device lost #3669
Merged
kainino0x
merged 4 commits into
gpuweb:main
from
perryuwang:canvas_display_after_device_lost
Apr 25, 2024
Merged
Changes from all commits
Commits
Show all changes
4 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
65 changes: 65 additions & 0 deletions
65
src/webgpu/web_platform/reftests/canvas_display_after_device_lost.html.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { timeout } from '../../../common/util/timeout.js'; | ||
import { assert } from '../../../common/util/util.js'; | ||
import { takeScreenshotDelayed } from '../../../common/util/wpt_reftest_wait.js'; | ||
|
||
void (async () => { | ||
assert( | ||
typeof navigator !== 'undefined' && navigator.gpu !== undefined, | ||
'No WebGPU implementation found' | ||
); | ||
|
||
const adapter = await navigator.gpu.requestAdapter(); | ||
assert(adapter !== null); | ||
const device = await adapter.requestDevice(); | ||
assert(device !== null); | ||
const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); | ||
let deviceLost = false; | ||
|
||
function draw(canvasId: string, alphaMode: GPUCanvasAlphaMode, abortAfterDeviceLost: boolean) { | ||
if (deviceLost && abortAfterDeviceLost) { | ||
return; | ||
} | ||
|
||
const canvas = document.getElementById(canvasId) as HTMLCanvasElement; | ||
const ctx = canvas.getContext('webgpu') as unknown as GPUCanvasContext; | ||
ctx.configure({ | ||
device, | ||
format: presentationFormat, | ||
alphaMode, | ||
}); | ||
|
||
const colorAttachment = ctx.getCurrentTexture(); | ||
const colorAttachmentView = colorAttachment.createView(); | ||
|
||
const encoder = device.createCommandEncoder(); | ||
const pass = encoder.beginRenderPass({ | ||
colorAttachments: [ | ||
{ | ||
view: colorAttachmentView, | ||
clearValue: { r: 0.4, g: 1.0, b: 0.0, a: 1.0 }, | ||
loadOp: 'clear', | ||
storeOp: 'store', | ||
}, | ||
], | ||
}); | ||
pass.end(); | ||
device.queue.submit([encoder.finish()]); | ||
} | ||
|
||
function drawAll() { | ||
draw('cvs0', 'opaque', true); | ||
draw('cvs1', 'opaque', false); | ||
draw('cvs2', 'premultiplied', true); | ||
draw('cvs3', 'premultiplied', false); | ||
|
||
if (!deviceLost) { | ||
device.destroy(); | ||
deviceLost = true; | ||
timeout(drawAll, 100); | ||
} else { | ||
takeScreenshotDelayed(50); | ||
} | ||
} | ||
|
||
drawAll(); | ||
})(); |
16 changes: 16 additions & 0 deletions
16
src/webgpu/web_platform/reftests/canvas_display_after_device_lost.https.html
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<title>WebGPU canvas_display_after_device_lost</title> | ||
<meta charset="utf-8" /> | ||
<link rel="help" href="https://gpuweb.github.io/gpuweb/" /> | ||
<meta name="assert" content="WebGPU canvas should be presented correctly after device lost" /> | ||
<link rel="match" href="./ref/canvas_display_after_device_lost-ref.html" /> | ||
<style> | ||
body { background-color: #F0E68C; } | ||
</style> | ||
<canvas id="cvs0" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs1" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs2" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs3" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<script type="module" src="canvas_display_after_device_lost.html.js"></script> | ||
</html> |
26 changes: 26 additions & 0 deletions
26
src/webgpu/web_platform/reftests/ref/canvas_display_after_device_lost-ref.html
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<title>WebGPU canvas_display_after_device_lost (ref)</title> | ||
<meta charset="utf-8" /> | ||
<link rel="help" href="https://gpuweb.github.io/gpuweb/" /> | ||
<style> | ||
body { background-color: #F0E68C; } | ||
</style> | ||
<canvas id="cvs0" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs1" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs2" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<canvas id="cvs3" width="20" height="20" style="width: 20px; height: 20px;"></canvas> | ||
<script> | ||
function draw(canvas, color) { | ||
var c = document.getElementById(canvas); | ||
var ctx = c.getContext('2d'); | ||
ctx.fillStyle = color; | ||
ctx.fillRect(0, 0, c.width, c.height); | ||
} | ||
|
||
draw('cvs0', '#66FF00'); | ||
draw('cvs1', '#000000'); | ||
draw('cvs2', '#66FF00'); | ||
draw('cvs3', '#00000000'); | ||
</script> | ||
</html> |
Oops, something went wrong.
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.
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.
This will reconfigure the canvas between device.destroy() and ctx.getCurrentTexture(). This could interact with the test. I pushed a commit which adds 4 more cases that draw without reconfiguring - please review to make sure the expected results look right.