Move the decision for useMultisampleFBO to GrGLOpsRenderPass

Bug: skia:11396
Change-Id: I5548784d735a11a8ca7afc7eb5a731966ec1a0b7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/393776
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2021-04-07 21:12:22 -06:00 committed by Skia Commit-Bot
parent 56892dc933
commit b0fed1dc21
6 changed files with 41 additions and 25 deletions

View File

@ -1837,7 +1837,8 @@ void GrGLGpu::disableWindowRectangles() {
#endif #endif
} }
bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& programInfo) { bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, bool useMultisampleFBO,
const GrProgramInfo& programInfo) {
this->handleDirtyContext(); this->handleDirtyContext();
sk_sp<GrGLProgram> program = fProgramCache->findOrCreateProgram(this->getContext(), sk_sp<GrGLProgram> program = fProgramCache->findOrCreateProgram(this->getContext(),
@ -1877,7 +1878,7 @@ bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& pr
// This must come after textures are flushed because a texture may need // This must come after textures are flushed because a texture may need
// to be msaa-resolved (which will modify bound FBO state). // to be msaa-resolved (which will modify bound FBO state).
this->flushRenderTarget(glRT, glRT->numSamples() > 1); this->flushRenderTarget(glRT, useMultisampleFBO);
return true; return true;
} }
@ -1939,6 +1940,7 @@ GrGLenum GrGLGpu::bindBuffer(GrGpuBufferType type, const GrBuffer* buffer) {
void GrGLGpu::clear(const GrScissorState& scissor, void GrGLGpu::clear(const GrScissorState& scissor,
std::array<float, 4> color, std::array<float, 4> color,
GrRenderTarget* target, GrRenderTarget* target,
bool useMultisampleFBO,
GrSurfaceOrigin origin) { GrSurfaceOrigin origin) {
// parent class should never let us get here with no RT // parent class should never let us get here with no RT
SkASSERT(target); SkASSERT(target);
@ -1950,9 +1952,9 @@ void GrGLGpu::clear(const GrScissorState& scissor,
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
if (scissor.enabled()) { if (scissor.enabled()) {
this->flushRenderTarget(glRT, glRT->numSamples() > 1, origin, scissor.rect()); this->flushRenderTarget(glRT, useMultisampleFBO, origin, scissor.rect());
} else { } else {
this->flushRenderTarget(glRT, glRT->numSamples() > 1); this->flushRenderTarget(glRT, useMultisampleFBO);
} }
this->flushScissor(scissor, glRT->height(), origin); this->flushScissor(scissor, glRT->height(), origin);
this->disableWindowRectangles(); this->disableWindowRectangles();
@ -1969,7 +1971,8 @@ static bool use_tiled_rendering(const GrGLCaps& glCaps,
GrStoreOp::kDiscard == stencilLoadStore.fStoreOp; GrStoreOp::kDiscard == stencilLoadStore.fStoreOp;
} }
void GrGLGpu::beginCommandBuffer(GrRenderTarget* rt, const SkIRect& bounds, GrSurfaceOrigin origin, void GrGLGpu::beginCommandBuffer(GrRenderTarget* rt, bool useMultisampleFBO, const SkIRect& bounds,
GrSurfaceOrigin origin,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) { const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) {
SkASSERT(!fIsExecutingCommandBuffer_DebugOnly); SkASSERT(!fIsExecutingCommandBuffer_DebugOnly);
@ -1977,7 +1980,7 @@ void GrGLGpu::beginCommandBuffer(GrRenderTarget* rt, const SkIRect& bounds, GrSu
this->handleDirtyContext(); this->handleDirtyContext();
auto glRT = static_cast<GrGLRenderTarget*>(rt); auto glRT = static_cast<GrGLRenderTarget*>(rt);
this->flushRenderTarget(glRT, glRT->numSamples() > 1); this->flushRenderTarget(glRT, useMultisampleFBO);
SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly = true); SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly = true);
if (use_tiled_rendering(this->glCaps(), stencilLoadStore)) { if (use_tiled_rendering(this->glCaps(), stencilLoadStore)) {
@ -2009,7 +2012,7 @@ void GrGLGpu::beginCommandBuffer(GrRenderTarget* rt, const SkIRect& bounds, GrSu
} }
} }
void GrGLGpu::endCommandBuffer(GrRenderTarget* rt, void GrGLGpu::endCommandBuffer(GrRenderTarget* rt, bool useMultisampleFBO,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) { const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) {
SkASSERT(fIsExecutingCommandBuffer_DebugOnly); SkASSERT(fIsExecutingCommandBuffer_DebugOnly);
@ -2027,13 +2030,13 @@ void GrGLGpu::endCommandBuffer(GrRenderTarget* rt,
SkSTArray<2, GrGLenum> discardAttachments; SkSTArray<2, GrGLenum> discardAttachments;
if (GrStoreOp::kDiscard == colorLoadStore.fStoreOp) { if (GrStoreOp::kDiscard == colorLoadStore.fStoreOp) {
GrGLuint renderFBOID = (glRT->numSamples() > 1) ? glRT->multisampleFBOID() GrGLuint renderFBOID = (useMultisampleFBO) ? glRT->multisampleFBOID()
: glRT->singleSampleFBOID(); : glRT->singleSampleFBOID();
discardAttachments.push_back((!renderFBOID) ? GR_GL_COLOR : GR_GL_COLOR_ATTACHMENT0); discardAttachments.push_back((!renderFBOID) ? GR_GL_COLOR : GR_GL_COLOR_ATTACHMENT0);
} }
if (GrStoreOp::kDiscard == stencilLoadStore.fStoreOp) { if (GrStoreOp::kDiscard == stencilLoadStore.fStoreOp) {
GrGLuint renderFBOID = (glRT->numSamples() > 1) ? glRT->multisampleFBOID() GrGLuint renderFBOID = (useMultisampleFBO) ? glRT->multisampleFBOID()
: glRT->singleSampleFBOID(); : glRT->singleSampleFBOID();
discardAttachments.push_back((!renderFBOID) ? GR_GL_STENCIL : GR_GL_STENCIL_ATTACHMENT); discardAttachments.push_back((!renderFBOID) ? GR_GL_STENCIL : GR_GL_STENCIL_ATTACHMENT);
} }
@ -2094,7 +2097,7 @@ void GrGLGpu::clearStencilClip(const GrScissorState& scissor, bool insideStencil
value = 0; value = 0;
} }
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
this->flushRenderTargetNoColorWrites(glRT, glRT->numSamples() > 1); this->flushRenderTargetNoColorWrites(glRT, glRT->stencilIsOnMultisampleFBO());
this->flushScissor(scissor, glRT->height(), origin); this->flushScissor(scissor, glRT->height(), origin);
this->disableWindowRectangles(); this->disableWindowRectangles();

View File

@ -71,7 +71,7 @@ public:
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer*); GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer*);
// Flushes state from GrProgramInfo to GL. Returns false if the state couldn't be set. // Flushes state from GrProgramInfo to GL. Returns false if the state couldn't be set.
bool flushGLState(GrRenderTarget*, const GrProgramInfo&); bool flushGLState(GrRenderTarget*, bool useMultisampleFBO, const GrProgramInfo&);
void flushScissorRect(const SkIRect& scissor, int rtHeight, GrSurfaceOrigin); void flushScissorRect(const SkIRect& scissor, int rtHeight, GrSurfaceOrigin);
// The flushRenderTarget methods will all set the initial viewport to the full extent of the // The flushRenderTarget methods will all set the initial viewport to the full extent of the
@ -106,7 +106,8 @@ public:
// The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu. // The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clear call for the corresponding passthrough function // Thus this is the implementation of the clear call for the corresponding passthrough function
// on GrGLOpsRenderPass. // on GrGLOpsRenderPass.
void clear(const GrScissorState&, std::array<float, 4> color, GrRenderTarget*, GrSurfaceOrigin); void clear(const GrScissorState&, std::array<float, 4> color, GrRenderTarget*,
bool useMultisampleFBO, GrSurfaceOrigin);
// The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu. // The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clearStencil call for the corresponding passthrough // Thus this is the implementation of the clearStencil call for the corresponding passthrough
@ -114,11 +115,13 @@ public:
void clearStencilClip(const GrScissorState&, bool insideStencilMask, void clearStencilClip(const GrScissorState&, bool insideStencilMask,
GrRenderTarget*, GrSurfaceOrigin); GrRenderTarget*, GrSurfaceOrigin);
void beginCommandBuffer(GrRenderTarget*, const SkIRect& bounds, GrSurfaceOrigin, void beginCommandBuffer(GrRenderTarget*, bool useMultisampleFBO,
const SkIRect& bounds, GrSurfaceOrigin,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore); const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore);
void endCommandBuffer(GrRenderTarget*, const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, void endCommandBuffer(GrRenderTarget*, bool useMultisampleFBO,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore); const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore);
void invalidateBoundRenderTarget() { void invalidateBoundRenderTarget() {

View File

@ -25,24 +25,26 @@ void GrGLOpsRenderPass::set(GrRenderTarget* rt, const SkIRect& contentBounds,
SkASSERT(fGpu == rt->getContext()->priv().getGpu()); SkASSERT(fGpu == rt->getContext()->priv().getGpu());
this->INHERITED::set(rt, origin); this->INHERITED::set(rt, origin);
fUseMultisampleFBO = rt->numSamples() > 1;
fContentBounds = contentBounds; fContentBounds = contentBounds;
fColorLoadAndStoreInfo = colorInfo; fColorLoadAndStoreInfo = colorInfo;
fStencilLoadAndStoreInfo = stencilInfo; fStencilLoadAndStoreInfo = stencilInfo;
} }
void GrGLOpsRenderPass::onBegin() { void GrGLOpsRenderPass::onBegin() {
fGpu->beginCommandBuffer(fRenderTarget, fContentBounds, fOrigin, fColorLoadAndStoreInfo, fGpu->beginCommandBuffer(fRenderTarget, fUseMultisampleFBO, fContentBounds, fOrigin,
fStencilLoadAndStoreInfo); fColorLoadAndStoreInfo, fStencilLoadAndStoreInfo);
} }
void GrGLOpsRenderPass::onEnd() { void GrGLOpsRenderPass::onEnd() {
fGpu->endCommandBuffer(fRenderTarget, fColorLoadAndStoreInfo, fStencilLoadAndStoreInfo); fGpu->endCommandBuffer(fRenderTarget, fUseMultisampleFBO, fColorLoadAndStoreInfo,
fStencilLoadAndStoreInfo);
} }
bool GrGLOpsRenderPass::onBindPipeline(const GrProgramInfo& programInfo, bool GrGLOpsRenderPass::onBindPipeline(const GrProgramInfo& programInfo,
const SkRect& drawBounds) { const SkRect& drawBounds) {
fPrimitiveType = programInfo.primitiveType(); fPrimitiveType = programInfo.primitiveType();
return fGpu->flushGLState(fRenderTarget, programInfo); return fGpu->flushGLState(fRenderTarget, fUseMultisampleFBO, programInfo);
} }
void GrGLOpsRenderPass::onSetScissorRect(const SkIRect& scissor) { void GrGLOpsRenderPass::onSetScissorRect(const SkIRect& scissor) {
@ -384,7 +386,7 @@ void GrGLOpsRenderPass::multiDrawElementsANGLEOrWebGL(const GrBuffer* drawIndire
} }
void GrGLOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) { void GrGLOpsRenderPass::onClear(const GrScissorState& scissor, std::array<float, 4> color) {
fGpu->clear(scissor, color, fRenderTarget, fOrigin); fGpu->clear(scissor, color, fRenderTarget, fUseMultisampleFBO, fOrigin);
} }
void GrGLOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) { void GrGLOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) {

View File

@ -77,7 +77,9 @@ private:
void onClear(const GrScissorState& scissor, std::array<float, 4> color) override; void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override; void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
GrGLGpu* fGpu; GrGLGpu* const fGpu;
bool fUseMultisampleFBO;
SkIRect fContentBounds; SkIRect fContentBounds;
LoadAndStoreInfo fColorLoadAndStoreInfo; LoadAndStoreInfo fColorLoadAndStoreInfo;
StencilLoadAndStoreInfo fStencilLoadAndStoreInfo; StencilLoadAndStoreInfo fStencilLoadAndStoreInfo;

View File

@ -45,8 +45,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
} }
inline void GrGLRenderTarget::setFlags(const GrGLCaps& glCaps, const IDs& idDesc) { inline void GrGLRenderTarget::setFlags(const GrGLCaps& glCaps, const IDs& idDesc) {
GrGLuint renderFBOID = (this->numSamples() > 1) ? fMultisampleFBOID : fSingleSampleFBOID; if ((fMultisampleFBOID | fSingleSampleFBOID) == 0) {
if (renderFBOID == 0) {
this->setGLRTFBOIDIs0(); this->setGLRTFBOIDIs0();
} }
} }
@ -129,7 +128,8 @@ bool GrGLRenderTarget::completeStencilAttachment() {
const GrGLInterface* interface = gpu->glInterface(); const GrGLInterface* interface = gpu->glInterface();
GrAttachment* stencil = this->getStencilAttachment(); GrAttachment* stencil = this->getStencilAttachment();
GrGLuint stencilFBOID = (this->numSamples() > 1) ? fMultisampleFBOID : fSingleSampleFBOID; GrGLuint stencilFBOID = (this->stencilIsOnMultisampleFBO()) ? fMultisampleFBOID
: fSingleSampleFBOID;
gpu->invalidateBoundRenderTarget(); gpu->invalidateBoundRenderTarget();
gpu->bindFramebuffer(GR_GL_FRAMEBUFFER, stencilFBOID); gpu->bindFramebuffer(GR_GL_FRAMEBUFFER, stencilFBOID);

View File

@ -44,6 +44,12 @@ public:
GrGLuint singleSampleFBOID() const { return fSingleSampleFBOID; } GrGLuint singleSampleFBOID() const { return fSingleSampleFBOID; }
GrGLuint multisampleFBOID() const { return fMultisampleFBOID; } GrGLuint multisampleFBOID() const { return fMultisampleFBOID; }
// If we have a multisample FBO, that is always where the stencil goes. With dynamic MSAA there
// will be a multisample FBO even if numSamples is 1.
bool stencilIsOnMultisampleFBO() const {
return this->numSamples() > 1 || fMultisampleFBOID != 0;
}
GrBackendRenderTarget getBackendRenderTarget() const override; GrBackendRenderTarget getBackendRenderTarget() const override;
GrBackendFormat backendFormat() const override; GrBackendFormat backendFormat() const override;