diff options
author | 2016-11-30 13:38:32 -0500 | |
---|---|---|
committer | 2016-11-30 20:17:51 +0000 | |
commit | c293a29bc2fced15ac44a66efa813d42cb3f2e0b (patch) | |
tree | f1dc394033e8baa97e05a060ca5dc9885224c85c /src/gpu | |
parent | c789b61167dd98efc3c3bfcf9673eef24c2e57f4 (diff) |
Make GrGpuCommandBuffer infer its render target from first draw
This is a temporary workaround to allow removal of GrBatch::renderTarget().
Change-Id: Ic14710a369802064cf6446e8191a98ea3595556d
Reviewed-on: https://skia-review.googlesource.com/5342
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrGpu.h | 6 | ||||
-rw-r--r-- | src/gpu/GrGpuCommandBuffer.cpp | 9 | ||||
-rw-r--r-- | src/gpu/GrGpuCommandBuffer.h | 16 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetOpList.cpp | 3 | ||||
-rw-r--r-- | src/gpu/batches/GrClearBatch.h | 2 | ||||
-rw-r--r-- | src/gpu/batches/GrClearStencilClipBatch.h | 2 | ||||
-rw-r--r-- | src/gpu/batches/GrDiscardBatch.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.h | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpuCommandBuffer.h | 29 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.h | 1 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpuCommandBuffer.cpp | 70 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpuCommandBuffer.h | 15 |
14 files changed, 116 insertions, 47 deletions
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 80beffafd7..b89248025e 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -367,9 +367,11 @@ public: } // Creates a GrGpuCommandBuffer in which the GrOpList can send draw commands to instead of - // directly to the Gpu object. + // directly to the Gpu object. This currently does not take a GrRenderTarget. The command buffer + // is expected to infer the render target from the first draw, clear, or discard. This is an + // awkward workaround that goes away after MDB is complete and the render target is known from + // the GrRenderTargetOpList. virtual GrGpuCommandBuffer* createCommandBuffer( - GrRenderTarget* target, const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) = 0; diff --git a/src/gpu/GrGpuCommandBuffer.cpp b/src/gpu/GrGpuCommandBuffer.cpp index d2a4e6e6b9..9ef459f08d 100644 --- a/src/gpu/GrGpuCommandBuffer.cpp +++ b/src/gpu/GrGpuCommandBuffer.cpp @@ -19,20 +19,19 @@ void GrGpuCommandBuffer::submit() { this->onSubmit(); } -void GrGpuCommandBuffer::clear(const GrFixedClip& clip, GrColor color) { +void GrGpuCommandBuffer::clear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) { #ifdef SK_DEBUG - GrRenderTarget* rt = this->renderTarget(); SkASSERT(rt); SkASSERT(!clip.scissorEnabled() || (SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) && SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect())); #endif - this->onClear(clip, color); + this->onClear(rt, clip, color); } -void GrGpuCommandBuffer::clearStencilClip(const GrFixedClip& clip, +void GrGpuCommandBuffer::clearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, bool insideStencilMask) { - this->onClearStencilClip(clip, insideStencilMask); + this->onClearStencilClip(rt, clip, insideStencilMask); } bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline, diff --git a/src/gpu/GrGpuCommandBuffer.h b/src/gpu/GrGpuCommandBuffer.h index ef4f428c9c..f8c938ba64 100644 --- a/src/gpu/GrGpuCommandBuffer.h +++ b/src/gpu/GrGpuCommandBuffer.h @@ -26,6 +26,12 @@ struct SkRect; * the same render target. It is possible that these commands execute immediately (GL), or get * buffered up for later execution (Vulkan). GrBatches will execute their draw commands into a * GrGpuCommandBuffer. + * + * Ideally we'd know the GrRenderTarget, or at least its properties when the GrGpuCommandBuffer, is + * created. We also then wouldn't include it in the GrPipeline or as a parameter to the clear and + * discard methods. The logical place for that will be in GrRenderTargetOpList post-MDB. For now + * the render target is redundantly passed to each operation, though it will always be the same + * render target for a given command buffer even pre-MDB. */ class GrGpuCommandBuffer { public: @@ -72,16 +78,16 @@ public: /** * Clear the passed in render target. Ignores the draw state and clip. */ - void clear(const GrFixedClip&, GrColor); + void clear(GrRenderTarget*, const GrFixedClip&, GrColor); - void clearStencilClip(const GrFixedClip&, bool insideStencilMask); + void clearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask); /** * Discards the contents render target. nullptr indicates that the current render target should * be discarded. */ // TODO: This should be removed in the future to favor using the load and store ops for discard - virtual void discard() = 0; + virtual void discard(GrRenderTarget*) = 0; private: virtual GrGpu* gpu() = 0; @@ -97,9 +103,9 @@ private: const SkRect& bounds) = 0; // overridden by backend-specific derived class to perform the clear. - virtual void onClear(const GrFixedClip&, GrColor) = 0; + virtual void onClear(GrRenderTarget*, const GrFixedClip&, GrColor) = 0; - virtual void onClearStencilClip(const GrFixedClip&, + virtual void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) = 0; }; diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index aab71f9019..b69d915f06 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -204,8 +204,7 @@ bool GrRenderTargetOpList::drawBatches(GrBatchFlushState* flushState) { static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, GrColor_ILLEGAL }; - commandBuffer.reset(fGpu->createCommandBuffer(currentRT, - kBasicLoadStoreInfo, // Color + commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color kBasicLoadStoreInfo)); // Stencil } flushState->setCommandBuffer(commandBuffer.get()); diff --git a/src/gpu/batches/GrClearBatch.h b/src/gpu/batches/GrClearBatch.h index ef38e74af8..724981e658 100644 --- a/src/gpu/batches/GrClearBatch.h +++ b/src/gpu/batches/GrClearBatch.h @@ -100,7 +100,7 @@ private: void onPrepare(GrBatchFlushState*) override {} void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { - state->commandBuffer()->clear(fClip, fColor); + state->commandBuffer()->clear(fRenderTarget.get(), fClip, fColor); } GrFixedClip fClip; diff --git a/src/gpu/batches/GrClearStencilClipBatch.h b/src/gpu/batches/GrClearStencilClipBatch.h index f1e5b50d95..7f69f64c16 100644 --- a/src/gpu/batches/GrClearStencilClipBatch.h +++ b/src/gpu/batches/GrClearStencilClipBatch.h @@ -55,7 +55,7 @@ private: void onPrepare(GrBatchFlushState*) override {} void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { - state->commandBuffer()->clearStencilClip(fClip, fInsideStencilMask); + state->commandBuffer()->clearStencilClip(fRenderTarget.get(), fClip, fInsideStencilMask); } const GrFixedClip fClip; diff --git a/src/gpu/batches/GrDiscardBatch.h b/src/gpu/batches/GrDiscardBatch.h index 54f41b9ef4..799c7462cb 100644 --- a/src/gpu/batches/GrDiscardBatch.h +++ b/src/gpu/batches/GrDiscardBatch.h @@ -47,7 +47,7 @@ private: void onPrepare(GrBatchFlushState*) override {} void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { - state->commandBuffer()->discard(); + state->commandBuffer()->discard(fRenderTarget.get()); } GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 67414a4957..d3f13d061c 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2645,10 +2645,9 @@ bool GrGLGpu::onReadPixels(GrSurface* surface, } GrGpuCommandBuffer* GrGLGpu::createCommandBuffer( - GrRenderTarget* target, const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) { - return new GrGLGpuCommandBuffer(this, static_cast<GrGLRenderTarget*>(target)); + return new GrGLGpuCommandBuffer(this); } void GrGLGpu::finishOpList() { diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index c6e7935ed0..0c3d0605c7 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -122,7 +122,6 @@ public: void clearStencil(GrRenderTarget*) override; GrGpuCommandBuffer* createCommandBuffer( - GrRenderTarget* target, const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) override; diff --git a/src/gpu/gl/GrGLGpuCommandBuffer.h b/src/gpu/gl/GrGLGpuCommandBuffer.h index 069eea5f58..d1e1fe83db 100644 --- a/src/gpu/gl/GrGLGpuCommandBuffer.h +++ b/src/gpu/gl/GrGLGpuCommandBuffer.h @@ -22,13 +22,19 @@ class GrGLGpuCommandBuffer : public GrGpuCommandBuffer { * pass through functions to corresponding calls in the GrGLGpu class. */ public: - GrGLGpuCommandBuffer(GrGLGpu* gpu, GrGLRenderTarget* rt) : fGpu(gpu), fRenderTarget(rt) {} + GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu), fRenderTarget(nullptr) {} virtual ~GrGLGpuCommandBuffer() {} void end() override {} - void discard() override {} + void discard(GrRenderTarget* rt) override { + GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); + if (!fRenderTarget) { + fRenderTarget = target; + } + SkASSERT(target == fRenderTarget); + } void inlineUpload(GrBatchFlushState* state, GrDrawBatch::DeferredUploadFn& upload) override { state->doUpload(upload); @@ -45,15 +51,30 @@ private: const GrMesh* mesh, int meshCount, const SkRect& bounds) override { + GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget()); + if (!fRenderTarget) { + fRenderTarget = target; + } + SkASSERT(target == fRenderTarget); fGpu->draw(pipeline, primProc, mesh, meshCount); } - void onClear(const GrFixedClip& clip, GrColor color) override { + void onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) override { + GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); + if (!fRenderTarget) { + fRenderTarget = target; + } + SkASSERT(target == fRenderTarget); fGpu->clear(clip, color, fRenderTarget); } - void onClearStencilClip(const GrFixedClip& clip, + void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, bool insideStencilMask) override { + GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); + if (!fRenderTarget) { + fRenderTarget = target; + } + SkASSERT(target == fRenderTarget); fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget); } diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 674e8e4180..9fab21dce9 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -210,11 +210,9 @@ GrVkGpu::~GrVkGpu() { /////////////////////////////////////////////////////////////////////////////// GrGpuCommandBuffer* GrVkGpu::createCommandBuffer( - GrRenderTarget* target, const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) { - GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); - return new GrVkGpuCommandBuffer(this, vkRT, colorInfo, stencilInfo); + return new GrVkGpuCommandBuffer(this, colorInfo, stencilInfo); } void GrVkGpu::submitCommandBuffer(SyncQueue sync) { diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index dd1eaa15a7..fce0100762 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -102,7 +102,6 @@ public: void clearStencil(GrRenderTarget* target) override; GrGpuCommandBuffer* createCommandBuffer( - GrRenderTarget* target, const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) override; diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp index 9b70c0b6e4..7725e8e11d 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp +++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp @@ -53,21 +53,28 @@ void get_vk_load_store_ops(const GrGpuCommandBuffer::LoadAndStoreInfo& info, } GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu, - GrVkRenderTarget* target, const LoadAndStoreInfo& colorInfo, const LoadAndStoreInfo& stencilInfo) : fGpu(gpu) - , fRenderTarget(target) { - VkAttachmentLoadOp vkLoadOp; - VkAttachmentStoreOp vkStoreOp; + , fRenderTarget(nullptr) + , fClearColor(GrColor4f::FromGrColor(colorInfo.fClearColor)){ - get_vk_load_store_ops(colorInfo, &vkLoadOp, &vkStoreOp); - GrVkRenderPass::LoadStoreOps vkColorOps(vkLoadOp, vkStoreOp); + get_vk_load_store_ops(colorInfo, &fVkColorLoadOp, &fVkColorStoreOp); - get_vk_load_store_ops(stencilInfo, &vkLoadOp, &vkStoreOp); - GrVkRenderPass::LoadStoreOps vkStencilOps(vkLoadOp, vkStoreOp); + get_vk_load_store_ops(stencilInfo, &fVkStencilLoadOp, &fVkStencilStoreOp); + + fCurrentCmdBuffer = -1; +} + +void GrVkGpuCommandBuffer::init(GrVkRenderTarget* target) { + SkASSERT(!fRenderTarget); + fRenderTarget = target; + + GrVkRenderPass::LoadStoreOps vkColorOps(fVkColorLoadOp, fVkColorStoreOp); + GrVkRenderPass::LoadStoreOps vkStencilOps(fVkStencilLoadOp, fVkStencilStoreOp); CommandBufferInfo& cbInfo = fCommandBufferInfos.push_back(); + SkASSERT(fCommandBufferInfos.count() == 1); fCurrentCmdBuffer = 0; const GrVkResourceProvider::CompatibleRPHandle& rpHandle = target->compatibleRenderPassHandle(); @@ -81,16 +88,20 @@ GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu, vkStencilOps); } - GrColorToRGBAFloat(colorInfo.fClearColor, cbInfo.fColorClearValue.color.float32); + cbInfo.fColorClearValue.color.float32[0] = fClearColor.fRGBA[0]; + cbInfo.fColorClearValue.color.float32[1] = fClearColor.fRGBA[1]; + cbInfo.fColorClearValue.color.float32[2] = fClearColor.fRGBA[2]; + cbInfo.fColorClearValue.color.float32[3] = fClearColor.fRGBA[3]; cbInfo.fBounds.setEmpty(); cbInfo.fIsEmpty = true; cbInfo.fStartsWithClear = false; - cbInfo.fCommandBuffer = gpu->resourceProvider().findOrCreateSecondaryCommandBuffer(); - cbInfo.fCommandBuffer->begin(gpu, target->framebuffer(), cbInfo.fRenderPass); + cbInfo.fCommandBuffer = fGpu->resourceProvider().findOrCreateSecondaryCommandBuffer(); + cbInfo.fCommandBuffer->begin(fGpu, target->framebuffer(), cbInfo.fRenderPass); } + GrVkGpuCommandBuffer::~GrVkGpuCommandBuffer() { for (int i = 0; i < fCommandBufferInfos.count(); ++i) { CommandBufferInfo& cbInfo = fCommandBufferInfos[i]; @@ -103,10 +114,15 @@ GrGpu* GrVkGpuCommandBuffer::gpu() { return fGpu; } GrRenderTarget* GrVkGpuCommandBuffer::renderTarget() { return fRenderTarget; } void GrVkGpuCommandBuffer::end() { - fCommandBufferInfos[fCurrentCmdBuffer].fCommandBuffer->end(fGpu); + if (fCurrentCmdBuffer >= 0) { + fCommandBufferInfos[fCurrentCmdBuffer].fCommandBuffer->end(fGpu); + } } void GrVkGpuCommandBuffer::onSubmit() { + if (!fRenderTarget) { + return; + } // Change layout of our render target so it can be used as the color attachment. Currently // we don't attach the resolve to the framebuffer so no need to change its layout. GrVkImage* targetImage = fRenderTarget->msaaImage() ? fRenderTarget->msaaImage() @@ -162,7 +178,13 @@ void GrVkGpuCommandBuffer::onSubmit() { } } -void GrVkGpuCommandBuffer::discard() { +void GrVkGpuCommandBuffer::discard(GrRenderTarget* rt) { + GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt); + if (!fRenderTarget) { + this->init(target); + } + SkASSERT(target == fRenderTarget); + CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdBuffer]; if (cbInfo.fIsEmpty) { // We will change the render pass to do a clear load instead @@ -192,10 +214,16 @@ void GrVkGpuCommandBuffer::discard() { } } -void GrVkGpuCommandBuffer::onClearStencilClip(const GrFixedClip& clip, +void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, bool insideStencilMask) { SkASSERT(!clip.hasWindowRectangles()); + GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt); + if (!fRenderTarget) { + this->init(target); + } + SkASSERT(target == fRenderTarget); + CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdBuffer]; GrStencilAttachment* sb = fRenderTarget->renderTargetPriv().getStencilAttachment(); @@ -253,10 +281,16 @@ void GrVkGpuCommandBuffer::onClearStencilClip(const GrFixedClip& clip, } } -void GrVkGpuCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) { +void GrVkGpuCommandBuffer::onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) { // parent class should never let us get here with no RT SkASSERT(!clip.hasWindowRectangles()); + GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(rt); + if (!fRenderTarget) { + this->init(target); + } + SkASSERT(target == fRenderTarget); + CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdBuffer]; VkClearColorValue vkColor; @@ -462,6 +496,12 @@ void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline, const GrMesh* meshes, int meshCount, const SkRect& bounds) { + GrVkRenderTarget* target = static_cast<GrVkRenderTarget*>(pipeline.getRenderTarget()); + if (!fRenderTarget) { + this->init(target); + } + SkASSERT(target == fRenderTarget); + if (!meshCount) { return; } diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.h b/src/gpu/vk/GrVkGpuCommandBuffer.h index 160e4ca63f..9c6f03d24d 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.h +++ b/src/gpu/vk/GrVkGpuCommandBuffer.h @@ -24,7 +24,6 @@ class GrVkSecondaryCommandBuffer; class GrVkGpuCommandBuffer : public GrGpuCommandBuffer { public: GrVkGpuCommandBuffer(GrVkGpu* gpu, - GrVkRenderTarget*, const LoadAndStoreInfo& colorInfo, const LoadAndStoreInfo& stencilInfo); @@ -32,11 +31,14 @@ public: void end() override; - void discard() override; + void discard(GrRenderTarget*) override; void inlineUpload(GrBatchFlushState* state, GrDrawBatch::DeferredUploadFn& upload) override; private: + // Performs lazy initialization on the first operation seen by the command buffer. + void init(GrVkRenderTarget* rt); + GrGpu* gpu() override; GrRenderTarget* renderTarget() override; @@ -55,9 +57,9 @@ private: int meshCount, const SkRect& bounds) override; - void onClear(const GrFixedClip&, GrColor color) override; + void onClear(GrRenderTarget*, const GrFixedClip&, GrColor color) override; - void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override; + void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override; void addAdditionalCommandBuffer(); @@ -85,6 +87,11 @@ private: GrVkGpu* fGpu; GrVkRenderTarget* fRenderTarget; + VkAttachmentLoadOp fVkColorLoadOp; + VkAttachmentStoreOp fVkColorStoreOp; + VkAttachmentLoadOp fVkStencilLoadOp; + VkAttachmentStoreOp fVkStencilStoreOp; + GrColor4f fClearColor; typedef GrGpuCommandBuffer INHERITED; }; |