Use mixed samples internally for default coverage AA
Lays the infrastructure to use mixed samples internally, and begins
using nvpr with mixed samples on the default "gl" and "gles" configs.
In this rendition, we take the simplest approach possible re: stencil
attachments. We initially create a render target without stencil
(i.e., 0 samples). Then, any time a proxy needs a stencil buffer with
more samples than its target currently has, we create and attach a new
stencil buffer. However, we never "downgrade" a render target's
stencil attachment to one with fewer samples. So if the proxy only
needs one sample and the target has many, we leave it.
Bug: skia:
Change-Id: I8558ba799ac3dee457f349f77d4517c11413c9a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/224456
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index 3642ec3..6c7a893 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -74,11 +74,27 @@
///////////////////////////////////////////////////////////////////////////////
void GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) {
+#ifdef SK_DEBUG
+ if (1 == fRenderTarget->fSampleCnt) {
+ // TODO: We don't expect a mixed sampled render target to ever change its stencil buffer
+ // right now. But if it does swap in a stencil buffer with a different number of samples,
+ // and if we have a valid fSamplePatternKey, we will need to invalidate fSamplePatternKey
+ // here and add tests to make sure we it properly.
+ SkASSERT(GrSamplePatternDictionary::kInvalidSamplePatternKey ==
+ fRenderTarget->fSamplePatternKey);
+ } else {
+ // Render targets with >1 color sample should never use mixed samples. (This would lead to
+ // different sample patterns, depending on stencil state.)
+ SkASSERT(!stencil || stencil->numSamples() == fRenderTarget->fSampleCnt);
+ }
+#endif
+
if (!stencil && !fRenderTarget->fStencilAttachment) {
// No need to do any work since we currently don't have a stencil attachment and
// we're not actually adding one.
return;
}
+
fRenderTarget->fStencilAttachment = std::move(stencil);
if (!fRenderTarget->completeStencilAttachment()) {
fRenderTarget->fStencilAttachment = nullptr;
@@ -91,7 +107,19 @@
}
int GrRenderTargetPriv::getSamplePatternKey() const {
- SkASSERT(fRenderTarget->fSampleCnt > 1);
+#ifdef SK_DEBUG
+ GrStencilAttachment* stencil = fRenderTarget->fStencilAttachment.get();
+ if (fRenderTarget->fSampleCnt <= 1) {
+ // If the color buffer is not multisampled, the sample pattern better come from the stencil
+ // buffer (mixed samples).
+ SkASSERT(stencil && stencil->numSamples() > 1);
+ } else {
+ // The color sample count and stencil count cannot both be unequal and both greater than
+ // one. If this were the case, there would be more than one sample pattern associated with
+ // the render target.
+ SkASSERT(!stencil || stencil->numSamples() == fRenderTarget->fSampleCnt);
+ }
+#endif
if (GrSamplePatternDictionary::kInvalidSamplePatternKey == fRenderTarget->fSamplePatternKey) {
fRenderTarget->fSamplePatternKey =
fRenderTarget->getGpu()->findOrAssignSamplePatternKey(fRenderTarget);