Skip to content
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: delay calling context getCurrentTexture after configure #3294

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/webgpu/web_platform/reftests/delay_get_texture.html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { timeout } from '../../../common/util/timeout.js';
import { takeScreenshotDelayed } from '../../../common/util/wpt_reftest_wait.js';

function assert(condition: boolean, msg?: string | (() => string)): asserts condition {
if (!condition) {
throw new Error(msg && (typeof msg === 'string' ? msg : msg()));
}
}

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 canvas = document.getElementById('cvs0') as HTMLCanvasElement;
const ctx = canvas.getContext('webgpu') as unknown as GPUCanvasContext;
ctx.configure({
device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: 'premultiplied',
});

timeout(() => {
const encoder = device.createCommandEncoder();
const pass = encoder.beginRenderPass({
colorAttachments: [
{
view: ctx.getCurrentTexture().createView(),
clearValue: { r: 0.0, g: 1.0, b: 0.0, a: 1.0 },
loadOp: 'clear',
storeOp: 'store',
},
],
});
pass.end();
device.queue.submit([encoder.finish()]);

takeScreenshotDelayed(50);
}, 100);
})();
10 changes: 10 additions & 0 deletions src/webgpu/web_platform/reftests/delay_get_texture.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html class="reftest-wait">
<title>WebGPU delay getCurrentTexture</title>
<meta charset="utf-8" />
<link rel="help" href="https://gpuweb.github.io/gpuweb/" />
<meta name="assert" content="WebGPU delay calling getCurrentTexture should be presented correctly" />
<link rel="match" href="./ref/delay_get_texture-ref.html" />
<canvas id="cvs0" width="20" height="20" style="width: 20px; height: 20px;"></canvas>
<script type="module" src="delay_get_texture.html.js"></script>
</html>
17 changes: 17 additions & 0 deletions src/webgpu/web_platform/reftests/ref/delay_get_texture-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<title>WebGPU delay getCurrentTexture (ref)</title>
<meta charset="utf-8" />
<link rel="help" href="https://gpuweb.github.io/gpuweb/" />
<canvas id="cvs0" width="20" height="20" style="width: 20px; height: 20px;"></canvas>
<script>
function draw(canvas) {
var c = document.getElementById(canvas);
var ctx = c.getContext('2d');
ctx.fillStyle = '#00FF00';
ctx.fillRect(0, 0, c.width, c.height);
}

draw('cvs0');
</script>
</html>