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

depthCompare is not required for depth attachments if not used #3069

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

beaufortfrancois
Copy link
Collaborator

@beaufortfrancois beaufortfrancois commented Oct 16, 2023

Following #3066, this PR adds tests that check that depthCompare is not required for formats with depth if it's not used. See gpuweb/gpuweb#4336


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.) They pass in my Chromium build patched with https://dawn-review.googlesource.com/c/dawn/+/155703

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.

@Kangz Please have a look

const success =
// depthCompare is optional for stencil-only formats.
(!info.depth && depthWriteEnabled !== true) ||
// depthCompare is optional for formats with a depth if it is not used for anything.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wish there was a way to make this code more readable but I didn't find it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Often we use a pattern like

let success = true;
if (...) success = false;
if (...) success = false;

Copy link
Collaborator

@kainino0x kainino0x Oct 17, 2023

Choose a reason for hiding this comment

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

Most of the PR looks good, but I hope you don't mind if I'll finish the review after you've done a refactor like that. It's quite hard to read right now.

I think it can looks something approximately like:

let success = false;
if (info.depth) {
} else {
  if (depthWriteEnabled === false && areDepthFailOpKeep) success = true;
  if (depthCompare) {
    if (...) success = false;
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following your suggestion, I've uploaded another patch. Thank you @kainino0x!

@Kangz
Copy link
Collaborator

Kangz commented Oct 16, 2023

Sorry, I won't be able to take a look any time soon. Could you find a different reviewer?

@beaufortfrancois
Copy link
Collaborator Author

@kainino0x Please review this PR.

Base automatically changed from depth to main October 17, 2023 01:48
@kainino0x
Copy link
Collaborator

Pushed rebase since #3066 landed.

@github-actions
Copy link

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

@github-actions
Copy link

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

let success = false;
if (!info.depth) {
// depthCompare is optional for stencil-only formats.
if (!depthWriteEnabled) success = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: This confused me a little because depthWriteEnabled=true is not even allowed with stencil-only formats. Then I realized this check is here because of that. Digging further it's quite hard to see how all of the validation rules from the spec appear here. [continued in other comment]

Comment on lines 76 to 92
const areDepthFailOpKeep =
stencilFrontDepthFailOp === 'keep' && stencilBackDepthFailOp === 'keep';

let success = false;
if (!info.depth) {
// depthCompare is optional for stencil-only formats.
if (!depthWriteEnabled) success = true;
} else {
// depthCompare is optional for formats with a depth if it's not used for anything.
if (depthWriteEnabled === false && areDepthFailOpKeep) success = true;
if (depthCompare) {
// validation will succeed normally for formats with depth aspect.
if (depthWriteEnabled && areDepthFailOpKeep) success = true;
// validation will succeed as well for formats with stencil and depth aspect.
if (info.stencil && depthWriteEnabled !== undefined) success = true;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Apologies for another big change. It is much easier to think about written this way, but I still find it quite hard to pick apart where the different rules from the spec appear here. (I probably shouldn't have suggested inverting the usual pattern, as I realize there's a good reason we usually have let success = true; if (...) success = false.)

I think the most readable form would stick close to the spec:

Suggested change
const areDepthFailOpKeep =
stencilFrontDepthFailOp === 'keep' && stencilBackDepthFailOp === 'keep';
let success = false;
if (!info.depth) {
// depthCompare is optional for stencil-only formats.
if (!depthWriteEnabled) success = true;
} else {
// depthCompare is optional for formats with a depth if it's not used for anything.
if (depthWriteEnabled === false && areDepthFailOpKeep) success = true;
if (depthCompare) {
// validation will succeed normally for formats with depth aspect.
if (depthWriteEnabled && areDepthFailOpKeep) success = true;
// validation will succeed as well for formats with stencil and depth aspect.
if (info.stencil && depthWriteEnabled !== undefined) success = true;
}
}
const depthFailOpsAreKeep =
stencilFrontDepthFailOp === 'keep' && stencilBackDepthFailOp === 'keep';
const stencilStateIsDefault = depthFailOpsAreKeep;
let success = true;
if (depthWriteEnabled || depthCompare !== 'always') {
if (!info.depth) success = false;
}
if (!stencilStateIsDefault) {
if (!info.stencil) success = false;
}
if (info.depth) {
if (depthWriteEnabled === undefined) success = false;
if (depthWriteEnabled || !depthFailOpsAreKeep) {
if (depthCompare === undefined) success = false;
}
}

I would need you to test this to make sure it's right, but it follows the spec very closely so I hope it is.

Copy link
Collaborator Author

@beaufortfrancois beaufortfrancois Oct 19, 2023

Choose a reason for hiding this comment

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

@kainino0x Thanks for the detailed answer. I followed your last suggestion with one nit:

-    if (depthWriteEnabled || depthCompare !== 'always') {
+    if (depthWriteEnabled || (depthCompare && depthCompare !== 'always')) {

I'm updating spec to make it clear as well. See gpuweb/gpuweb#4345

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kainino0x (gentle ping)

@github-actions
Copy link

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

Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

LGTM!

@kainino0x kainino0x merged commit 73bcf42 into main Oct 24, 2023
2 checks passed
@kainino0x kainino0x deleted the depthCompare branch October 24, 2023 17:25
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.

3 participants