Don't pass in RT to individual Gpu CommandBuffer calls

The Vulkan backend already stored a GrVkRT, but was inconsistent
in sometimes using the stored value and sometimes the passed in
value (though they should be the same). This just cleans up the
code so that everyone uses a stored RT.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3126

Change-Id: I571de4bfb1da612d61171321d5224a9a19d8e545
Reviewed-on: https://skia-review.googlesource.com/3126
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Greg Daniel 2016-10-12 09:47:22 -04:00 committed by Skia Commit-Bot
parent fe2965af79
commit 65a0927418
9 changed files with 50 additions and 53 deletions

View File

@ -19,22 +19,22 @@ void GrGpuCommandBuffer::submit(const SkIRect& bounds) {
this->onSubmit(bounds);
}
void GrGpuCommandBuffer::clear(const GrFixedClip& clip, GrColor color, GrRenderTarget* rt) {
void GrGpuCommandBuffer::clear(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()));
this->onClear(rt, clip, color);
#endif
this->onClear(clip, color);
}
void GrGpuCommandBuffer::clearStencilClip(const GrFixedClip& clip,
bool insideStencilMask,
GrRenderTarget* rt) {
SkASSERT(rt);
this->onClearStencilClip(rt, clip, insideStencilMask);
bool insideStencilMask) {
this->onClearStencilClip(clip, insideStencilMask);
}
bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline,
const GrPrimitiveProcessor& primProc,
const GrMesh* mesh,

View File

@ -66,18 +66,20 @@ public:
/**
* Clear the passed in render target. Ignores the draw state and clip.
*/
void clear(const GrFixedClip&, GrColor, GrRenderTarget*);
void clear(const GrFixedClip&, GrColor);
void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
void clearStencilClip(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(GrRenderTarget* = nullptr) = 0;
virtual void discard() = 0;
private:
virtual GrGpu* gpu() = 0;
virtual GrRenderTarget* renderTarget() = 0;
virtual void onSubmit(const SkIRect& bounds) = 0;
// overridden by backend-specific derived class to perform the draw call.
@ -87,10 +89,9 @@ private:
int meshCount) = 0;
// overridden by backend-specific derived class to perform the clear.
virtual void onClear(GrRenderTarget*, const GrFixedClip&, GrColor) = 0;
virtual void onClear(const GrFixedClip&, GrColor) = 0;
virtual void onClearStencilClip(GrRenderTarget*,
const GrFixedClip&,
virtual void onClearStencilClip(const GrFixedClip&,
bool insideStencilMask) = 0;
};

View File

@ -95,7 +95,7 @@ private:
void onPrepare(GrBatchFlushState*) override {}
void onDraw(GrBatchFlushState* state) override {
state->commandBuffer()->clear(fClip, fColor, fRenderTarget.get());
state->commandBuffer()->clear(fClip, fColor);
}
GrFixedClip fClip;

View File

@ -51,7 +51,7 @@ private:
void onPrepare(GrBatchFlushState*) override {}
void onDraw(GrBatchFlushState* state) override {
state->commandBuffer()->clearStencilClip(fClip, fInsideStencilMask, fRenderTarget.get());
state->commandBuffer()->clearStencilClip(fClip, fInsideStencilMask);
}
const GrFixedClip fClip;

View File

@ -44,7 +44,7 @@ private:
void onPrepare(GrBatchFlushState*) override {}
void onDraw(GrBatchFlushState* state) override {
state->commandBuffer()->discard(fRenderTarget.get());
state->commandBuffer()->discard();
}
GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;

View File

@ -2642,7 +2642,7 @@ GrGpuCommandBuffer* GrGLGpu::createCommandBuffer(
GrRenderTarget* target,
const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo,
const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) {
return new GrGLGpuCommandBuffer(this);
return new GrGLGpuCommandBuffer(this, static_cast<GrGLRenderTarget*>(target));
}
void GrGLGpu::finishDrawTarget() {

View File

@ -12,6 +12,8 @@
#include "GrGLGpu.h"
class GrGLRenderTarget;
class GrGLGpuCommandBuffer : public GrGpuCommandBuffer {
/**
* We do not actually buffer up draws or do any work in the this class for GL. Instead commands
@ -19,16 +21,17 @@ class GrGLGpuCommandBuffer : public GrGpuCommandBuffer {
* pass through functions to corresponding calls in the GrGLGpu class.
*/
public:
GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu) {}
GrGLGpuCommandBuffer(GrGLGpu* gpu, GrGLRenderTarget* rt) : fGpu(gpu), fRenderTarget(rt) {}
virtual ~GrGLGpuCommandBuffer() {}
void end() override {}
void discard(GrRenderTarget* rt) override {}
void discard() override {}
private:
GrGpu* gpu() override { return fGpu; }
GrRenderTarget* renderTarget() override { return fRenderTarget; }
void onSubmit(const SkIRect& bounds) override {}
@ -39,17 +42,17 @@ private:
fGpu->draw(pipeline, primProc, mesh, meshCount);
}
void onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) override {
fGpu->clear(clip, color, rt);
void onClear(const GrFixedClip& clip, GrColor color) override {
fGpu->clear(clip, color, fRenderTarget);
}
void onClearStencilClip(GrRenderTarget* rt,
const GrFixedClip& clip,
void onClearStencilClip(const GrFixedClip& clip,
bool insideStencilMask) override {
fGpu->clearStencilClip(clip, insideStencilMask, rt);
fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget);
}
GrGLGpu* fGpu;
GrGLRenderTarget* fRenderTarget;
typedef GrGpuCommandBuffer INHERITED;
};

View File

@ -91,6 +91,7 @@ GrVkGpuCommandBuffer::~GrVkGpuCommandBuffer() {
}
GrGpu* GrVkGpuCommandBuffer::gpu() { return fGpu; }
GrRenderTarget* GrVkGpuCommandBuffer::renderTarget() { return fRenderTarget; }
void GrVkGpuCommandBuffer::end() {
fCommandBuffer->end(fGpu);
@ -136,7 +137,7 @@ void GrVkGpuCommandBuffer::onSubmit(const SkIRect& bounds) {
fRenderTarget, bounds);
}
void GrVkGpuCommandBuffer::discard(GrRenderTarget* target) {
void GrVkGpuCommandBuffer::discard() {
if (fIsEmpty) {
// We will change the render pass to do a clear load instead
GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_DONT_CARE,
@ -146,15 +147,14 @@ void GrVkGpuCommandBuffer::discard(GrRenderTarget* target) {
const GrVkRenderPass* oldRP = fRenderPass;
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
const GrVkResourceProvider::CompatibleRPHandle& rpHandle =
vkRT->compatibleRenderPassHandle();
fRenderTarget->compatibleRenderPassHandle();
if (rpHandle.isValid()) {
fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle,
vkColorOps,
vkStencilOps);
} else {
fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT,
fRenderPass = fGpu->resourceProvider().findRenderPass(*fRenderTarget,
vkColorOps,
vkStencilOps);
}
@ -165,14 +165,11 @@ void GrVkGpuCommandBuffer::discard(GrRenderTarget* target) {
}
}
void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target,
const GrFixedClip& clip,
void GrVkGpuCommandBuffer::onClearStencilClip(const GrFixedClip& clip,
bool insideStencilMask) {
SkASSERT(target);
SkASSERT(!clip.hasWindowRectangles());
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment();
GrStencilAttachment* sb = fRenderTarget->renderTargetPriv().getStencilAttachment();
// this should only be called internally when we know we have a
// stencil buffer.
SkASSERT(sb);
@ -193,13 +190,13 @@ void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target,
// Flip rect if necessary
SkIRect vkRect;
if (!clip.scissorEnabled()) {
vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height());
} else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) {
vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height());
} else if (kBottomLeft_GrSurfaceOrigin != fRenderTarget->origin()) {
vkRect = clip.scissorRect();
} else {
const SkIRect& scissor = clip.scissorRect();
vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom,
scissor.fRight, vkRT->height() - scissor.fTop);
vkRect.setLTRB(scissor.fLeft, fRenderTarget->height() - scissor.fBottom,
scissor.fRight, fRenderTarget->height() - scissor.fTop);
}
clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop };
@ -220,16 +217,13 @@ void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target,
fIsEmpty = false;
}
void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& clip, GrColor color) {
void GrVkGpuCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
// parent class should never let us get here with no RT
SkASSERT(target);
SkASSERT(!clip.hasWindowRectangles());
VkClearColorValue vkColor;
GrColorToRGBAFloat(color, vkColor.float32);
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
if (fIsEmpty && !clip.scissorEnabled()) {
// We will change the render pass to do a clear load instead
GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR,
@ -240,13 +234,13 @@ void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& cl
const GrVkRenderPass* oldRP = fRenderPass;
const GrVkResourceProvider::CompatibleRPHandle& rpHandle =
vkRT->compatibleRenderPassHandle();
fRenderTarget->compatibleRenderPassHandle();
if (rpHandle.isValid()) {
fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle,
vkColorOps,
vkStencilOps);
} else {
fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT,
fRenderPass = fGpu->resourceProvider().findRenderPass(*fRenderTarget,
vkColorOps,
vkStencilOps);
}
@ -264,13 +258,13 @@ void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& cl
// Flip rect if necessary
SkIRect vkRect;
if (!clip.scissorEnabled()) {
vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height());
} else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) {
vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height());
} else if (kBottomLeft_GrSurfaceOrigin != fRenderTarget->origin()) {
vkRect = clip.scissorRect();
} else {
const SkIRect& scissor = clip.scissorRect();
vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom,
scissor.fRight, vkRT->height() - scissor.fTop);
vkRect.setLTRB(scissor.fLeft, fRenderTarget->height() - scissor.fBottom,
scissor.fRight, fRenderTarget->height() - scissor.fTop);
}
clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop };
clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height() };
@ -378,9 +372,7 @@ void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline,
if (!meshCount) {
return;
}
GrRenderTarget* rt = pipeline.getRenderTarget();
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt);
const GrVkRenderPass* renderPass = vkRT->simpleRenderPass();
const GrVkRenderPass* renderPass = fRenderTarget->simpleRenderPass();
SkASSERT(renderPass);
prepare_sampled_images(primProc, fGpu);

View File

@ -32,10 +32,11 @@ public:
void end() override;
void discard(GrRenderTarget* rt) override;
void discard() override;
private:
GrGpu* gpu() override;
GrRenderTarget* renderTarget() override;
void onSubmit(const SkIRect& bounds) override;
@ -52,9 +53,9 @@ private:
const GrMesh* mesh,
int meshCount) override;
void onClear(GrRenderTarget* rt, const GrFixedClip&, GrColor color) override;
void onClear(const GrFixedClip&, GrColor color) override;
void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask) override;
void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
const GrVkRenderPass* fRenderPass;
GrVkSecondaryCommandBuffer* fCommandBuffer;