-
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
depthCompare is not required for depth attachments if not used #3069
Conversation
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. |
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.
I wish there was a way to make this code more readable but I didn't find it.
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.
Often we use a pattern like
let success = true;
if (...) success = false;
if (...) success = false;
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.
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;
}
}
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.
Following your suggestion, I've uploaded another patch. Thank you @kainino0x!
Sorry, I won't be able to take a look any time soon. Could you find a different reviewer? |
@kainino0x Please review this PR. |
63ec603
to
e94df2e
Compare
Pushed rebase since #3066 landed. |
Previews, as seen when this build job started (e94df2e): |
e94df2e
to
923f09c
Compare
Previews, as seen when this build job started (923f09c): |
let success = false; | ||
if (!info.depth) { | ||
// depthCompare is optional for stencil-only formats. | ||
if (!depthWriteEnabled) success = true; |
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.
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]
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; | ||
} | ||
} |
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.
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:
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.
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.
@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
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.
@kainino0x (gentle ping)
Previews, as seen when this build job started (110265d): |
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.
LGTM!
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:
.unimplemented()
./** documented */
and new helper files are found inhelper_index.txt
.Requirements for reviewer sign-off:
When landing this PR, be sure to make any necessary issue status updates.
@Kangz Please have a look