Skip to content

Add rgba8unorm support for swapchain format - #952

Merged
kainino0x merged 8 commits into
gpuweb:mainfrom
jchen10:swapchain_format
Feb 10, 2022
Merged

kainino0x merged 8 commits into
gpuweb:mainfrom
jchen10:swapchain_format

Conversation

@jchen10

@jchen10 jchen10 commented Jan 26, 2022 •

Copy link
Copy Markdown
Contributor

This extends the readbackFromWebGPUCanvas and canvas_clear tests to cover rgba8unorm.

Issue: #915


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

@jchen10

jchen10 commented Jan 26, 2022

Copy link
Copy Markdown
Contributor Author

@kainino0x @Kangz @austinEng PTAL

@github-actions

Copy link
Copy Markdown

Previews, as seen when this build job started (8ec807d):
Run tests | View tsdoc

@kainino0x

Copy link
Copy Markdown
Collaborator

Also please retain the PR template and fill out the checklist according to the docs (maybe you opened the PR with a tool which doesn't prefill the template?) I pasted in the checklist and reviewed the reviewer aspects.

This extends the readbackFromWebGPUCanvas and canvas_clear tests to cover rgba8unorm.
@github-actions

github-actions Bot commented Feb 8, 2022

Copy link
Copy Markdown

Previews, as seen when this build job started (96162dd):
Run tests | View tsdoc

@jchen10

jchen10 commented Feb 8, 2022

Copy link
Copy Markdown
Contributor Author

Also please retain the PR template and fill out the checklist according to the docs (maybe you opened the PR with a tool which doesn't prefill the template?) I pasted in the checklist and reviewed the reviewer aspects.

Ah, I manually removed the template as I didn't know what it's for. Thanks for correcting me!

@jchen10

jchen10 commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

@kainino0x Would you like to take a look again? Thanks!

@kainino0x kainino0x left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Still LGTM

jchen10 force-pushed the swapchain_format branch from 8ec807d to 96162dd 19 hours ago

Please avoid force pushing after a review has started so it's easier to look at incremental changes. (If you need to update with the main branch, use a merge commit, which GitHub can render more nicely than a force-push rebase.)

(In this case the force-push was still easy to read, I think because it didn't contain a rebase.)

@jchen10

jchen10 commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

Still LGTM

jchen10 force-pushed the swapchain_format branch from 8ec807d to 96162dd 19 hours ago

Please avoid force pushing after a review has started so it's easier to look at incremental changes. (If you need to update with the main branch, use a merge commit, which GitHub can render more nicely than a force-push rebase.)

(In this case the force-push was still easy to read, I think because it didn't contain a rebase.)

Good to know, thanks!

@github-actions

github-actions Bot commented Feb 9, 2022

Copy link
Copy Markdown

Previews, as seen when this build job started (1f1ebf5):
Run tests | View tsdoc

@github-actions

github-actions Bot commented Feb 9, 2022

Copy link
Copy Markdown

Previews, as seen when this build job started (1f1ebf5):
Run tests | View tsdoc

@jchen10

jchen10 commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

@kainino0x Sorry for the inconvenience. I probably did another force-update accidentally for rebase.

* Add rgba8unorm support for swapchain format

This extends the readbackFromWebGPUCanvas and canvas_clear tests to cover rgba8unorm.

* Cleanup kValidSwapchainFormats and use draw to initialize canvas
@kainino0x

Copy link
Copy Markdown
Collaborator

No worries!

passEncoder.setPipeline(pipeline);
passEncoder.draw(6, 1, 0, 0);
passEncoder.endPass();
t.device.queue.submit([commandEncoder.finish()]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm very sorry, I definitely didn't think this suggestion through. I was imagining using just the loadValue, no draw call. Of course this isn't possible because you want to draw different colors to each of the 4 pixels.

Using a draw call is obviously a lot more complex than using a copy even though the copy gets slightly complex with different formats. Simplicity would be nice here, but I suppose the draw call is still nicer since it will generalize to all formats.

An alternative would be to create a 1x1 temporary render target temp and do 4 empty render passes and 4 copyTextureToTexture commands:

  • add local closure const clearOnePixel = () => { ... } that does:
    • beginRenderPass (temp, clear to a color, store), end pass
    • copyTextureToTexture(temp into one pixel of canvas)
  • call clearOnePixel once for each of the 4 pixels

WDYT of this approach?

@github-actions

Copy link
Copy Markdown

Previews, as seen when this build job started (2231b78):
Run tests | View tsdoc

@github-actions

Copy link
Copy Markdown

Previews, as seen when this build job started (8e0e07a):
Run tests | View tsdoc

@github-actions

Copy link
Copy Markdown

Previews, as seen when this build job started (9bf7de7):
Run tests | View tsdoc

@kainino0x kainino0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for all the rounds of comments. I have one last simplification but it's minor - just using one texture and one submit instead of many.

Comment on lines 111 to 119
const pixels = [
{ color: { r: 0.0, g: 0.0, b: 1.0, a: 1.0 }, pos: { x: 0, y: 0 } },
{ color: { r: 0.0, g: 1.0, b: 0.0, a: 1.0 }, pos: { x: 1, y: 0 } },
{ color: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, pos: { x: 0, y: 1 } },
{ color: { r: 1.0, g: 1.0, b: 0.0, a: 1.0 }, pos: { x: 1, y: 1 } },
];
pixels.forEach(pixel => {
clearOnePixel(pixel.color, pixel.pos.x, pixel.pos.y);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: prefer for (const pixel of pixels) over pixels.forEach(pixel =>

In this case, however, I would just write this, as it's much simpler:

clearOnePixel([0, 0, 1, 1], 0, 0);
clearOnePixel([0, 1, 0, 1], 1, 0);
...

see suggestion below

@kainino0x
kainino0x enabled auto-merge (squash) February 10, 2022 19:25
@kainino0x
kainino0x merged commit 77fbca4 into gpuweb:main Feb 10, 2022
@github-actions

Copy link
Copy Markdown

Previews, as seen when this build job started (3698722):
Run tests | View tsdoc

@jchen10

jchen10 commented Feb 11, 2022

Copy link
Copy Markdown
Contributor Author

Sorry for all the rounds of comments. I have one last simplification but it's minor - just using one texture and one submit instead of many.

Nice, thanks for reviewing!

@jchen10
jchen10 deleted the swapchain_format branch February 11, 2022 01:49
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.

2 participants