Skip to content

Commit

Permalink
Never reject an MSAA FBO0
Browse files Browse the repository at this point in the history
GLES2 doesn't support MSAA FBOs, so GrCaps thought it was supposed to
reject an MSAA wrapper on FBO0. This actually isn't correct. In GLES2,
FBO0 can still be multisampled.
  • Loading branch information
csmartdalton committed Apr 1, 2022
1 parent 67f70c5 commit f606bd7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/gpu/GrCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,17 @@ class GrCaps : public SkRefCnt {
virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
int sampleCount = 1) const = 0;

virtual bool isRenderTargetAsColorTypeRenderable(GrColorType ct,
const GrBackendRenderTarget& rt) const {
return this->isFormatAsColorTypeRenderable(ct, rt.getBackendFormat(), rt.sampleCnt());
}

virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0;

virtual bool isRenderTargetRenderable(const GrBackendRenderTarget& rt) const {
return this->isFormatRenderable(rt.getBackendFormat(), rt.sampleCnt());
}

// Find a sample count greater than or equal to the requested count which is supported for a
// render target of the given format or 0 if no such sample count is supported. If the requested
// sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0.
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/GrGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget

const GrCaps* caps = this->caps();

if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) {
if (!caps->isRenderTargetRenderable(backendRT)) {
return nullptr;
}

Expand Down
27 changes: 27 additions & 0 deletions src/gpu/gl/GrGLCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4481,6 +4481,20 @@ bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendForm
return this->isFormatRenderable(f, sampleCount);
}

bool GrGLCaps::isRenderTargetAsColorTypeRenderable(GrColorType ct,
const GrBackendRenderTarget& rt) const {
int sampleCntToCheck;
GrGLFramebufferInfo fbi;
if (rt.getGLFramebufferInfo(&fbi) && fbi.fFBOID == 0) {
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
// FBO0 and told us it's multisampled, just trust that the msaa is valid.
sampleCntToCheck = 1;
} else {
sampleCntToCheck = rt.sampleCnt();
}
return this->isFormatAsColorTypeRenderable(ct, rt.getBackendFormat(), sampleCntToCheck);
}

bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
return false;
Expand All @@ -4491,6 +4505,19 @@ bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount
return this->isFormatRenderable(format.asGLFormat(), sampleCount);
}

bool GrGLCaps::isRenderTargetRenderable(const GrBackendRenderTarget& rt) const {
int sampleCntToCheck;
GrGLFramebufferInfo fbi;
if (rt.getGLFramebufferInfo(&fbi) && fbi.fFBOID == 0) {
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
// FBO0 and told us it's multisampled, just trust that the msaa is valid.
sampleCntToCheck = 1;
} else {
sampleCntToCheck = rt.sampleCnt();
}
return this->isFormatRenderable(rt.getBackendFormat(), sampleCntToCheck);
}

int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
const FormatInfo& info = this->getFormatInfo(format);

Expand Down
3 changes: 3 additions & 0 deletions src/gpu/gl/GrGLCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ class GrGLCaps : public GrCaps {

bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
int sampleCount = 1) const override;
bool isRenderTargetAsColorTypeRenderable(GrColorType,
const GrBackendRenderTarget&) const override;
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
bool isRenderTargetRenderable(const GrBackendRenderTarget&) const override;
bool isFormatRenderable(GrGLFormat format, int sampleCount) const {
return sampleCount <= this->maxRenderTargetSampleCount(format);
}
Expand Down
13 changes: 10 additions & 3 deletions src/gpu/gl/GrGLGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,19 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
return nullptr;
}

const auto format = backendRT.getBackendFormat().asGLFormat();
if (!this->glCaps().isFormatRenderable(format, backendRT.sampleCnt())) {
if (!this->glCaps().isRenderTargetRenderable(backendRT)) {
return nullptr;
}

int sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
const auto format = backendRT.getBackendFormat().asGLFormat();
int sampleCount;
if (info.fFBOID == 0) {
// FBO0 has different multisampling rules than offscreen render targets. If the user wrapped
// FBO0 and told us it's multisampled, just trust the provided sample count.
sampleCount = backendRT.sampleCnt();
} else {
sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
}

GrGLRenderTarget::IDs rtIDs;
if (sampleCount <= 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/image/SkSurface_Gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ bool validate_backend_render_target(const GrCaps* caps, const GrBackendRenderTar
return false;
}

if (!caps->isFormatAsColorTypeRenderable(grCT, rt.getBackendFormat(), rt.sampleCnt())) {
if (!caps->isRenderTargetAsColorTypeRenderable(grCT, rt)) {
return false;
}

Expand Down

0 comments on commit f606bd7

Please sign in to comment.