aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-08-24 15:59:33 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-24 20:18:27 +0000
commit500d58b2a6e6fd03239622da42b67b2c9843b7be (patch)
treedc77637f3bbcc07773c3bdbd292870c59f28e333 /src/gpu/vk
parentfb126fa96e0f49f5dc17a9a043acced68be99e93 (diff)
Make Copy Ops to go through GpuCommandBuffer instead of straigt to GPU.
Bug: skia: Change-Id: I4eae4507e07278997e26419e94586eef0780c423 Reviewed-on: https://skia-review.googlesource.com/38361 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r--src/gpu/vk/GrVkGpu.cpp13
-rw-r--r--src/gpu/vk/GrVkGpu.h8
-rw-r--r--src/gpu/vk/GrVkGpuCommandBuffer.cpp140
-rw-r--r--src/gpu/vk/GrVkGpuCommandBuffer.h61
4 files changed, 155 insertions, 67 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index cd3054cd05..a36bbe51fb 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -257,11 +257,16 @@ void GrVkGpu::disconnect(DisconnectType type) {
///////////////////////////////////////////////////////////////////////////////
-GrGpuCommandBuffer* GrVkGpu::createCommandBuffer(
+GrGpuRTCommandBuffer* GrVkGpu::createCommandBuffer(
GrRenderTarget* rt, GrSurfaceOrigin origin,
- const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo,
- const GrGpuCommandBuffer::StencilLoadAndStoreInfo& stencilInfo) {
- return new GrVkGpuCommandBuffer(this, rt, origin, colorInfo, stencilInfo);
+ const GrGpuRTCommandBuffer::LoadAndStoreInfo& colorInfo,
+ const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo) {
+ return new GrVkGpuRTCommandBuffer(this, rt, origin, colorInfo, stencilInfo);
+}
+
+GrGpuTextureCommandBuffer* GrVkGpu::createCommandBuffer(GrTexture* texture,
+ GrSurfaceOrigin origin) {
+ return new GrVkGpuTextureCommandBuffer(this, texture, origin);
}
void GrVkGpu::submitCommandBuffer(SyncQueue sync) {
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 00bf060f74..ad157cac9f 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -96,10 +96,12 @@ public:
void clearStencil(GrRenderTarget* target, int clearValue) override;
- GrGpuCommandBuffer* createCommandBuffer(
+ GrGpuRTCommandBuffer* createCommandBuffer(
GrRenderTarget*, GrSurfaceOrigin,
- const GrGpuCommandBuffer::LoadAndStoreInfo&,
- const GrGpuCommandBuffer::StencilLoadAndStoreInfo&) override;
+ const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
+ const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
+
+ GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
void addMemoryBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index 66e4bffe87..4987cea3b1 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -22,17 +22,37 @@
#include "GrVkTexture.h"
#include "SkRect.h"
-void get_vk_load_store_ops(GrGpuCommandBuffer::LoadOp loadOpIn,
- GrGpuCommandBuffer::StoreOp storeOpIn,
+void GrVkGpuTextureCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect,
+ const SkIPoint& dstPoint) {
+ fCopies.emplace_back(src, srcRect, dstPoint);
+}
+
+void GrVkGpuTextureCommandBuffer::insertEventMarker(const char* msg) {
+ // TODO: does Vulkan have a correlate?
+}
+
+void GrVkGpuTextureCommandBuffer::submit() {
+ for (int i = 0; i < fCopies.count(); ++i) {
+ CopyInfo& copyInfo = fCopies[i];
+ fGpu->copySurface(fTexture, copyInfo.fSrc, copyInfo.fSrcRect, copyInfo.fDstPoint);
+ }
+}
+
+GrVkGpuTextureCommandBuffer::~GrVkGpuTextureCommandBuffer() {}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void get_vk_load_store_ops(GrGpuRTCommandBuffer::LoadOp loadOpIn,
+ GrGpuRTCommandBuffer::StoreOp storeOpIn,
VkAttachmentLoadOp* loadOp, VkAttachmentStoreOp* storeOp) {
switch (loadOpIn) {
- case GrGpuCommandBuffer::LoadOp::kLoad:
+ case GrGpuRTCommandBuffer::LoadOp::kLoad:
*loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
break;
- case GrGpuCommandBuffer::LoadOp::kClear:
+ case GrGpuRTCommandBuffer::LoadOp::kClear:
*loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
break;
- case GrGpuCommandBuffer::LoadOp::kDiscard:
+ case GrGpuRTCommandBuffer::LoadOp::kDiscard:
*loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
break;
default:
@@ -41,10 +61,10 @@ void get_vk_load_store_ops(GrGpuCommandBuffer::LoadOp loadOpIn,
}
switch (storeOpIn) {
- case GrGpuCommandBuffer::StoreOp::kStore:
+ case GrGpuRTCommandBuffer::StoreOp::kStore:
*storeOp = VK_ATTACHMENT_STORE_OP_STORE;
break;
- case GrGpuCommandBuffer::StoreOp::kDiscard:
+ case GrGpuRTCommandBuffer::StoreOp::kDiscard:
*storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
break;
default:
@@ -53,10 +73,10 @@ void get_vk_load_store_ops(GrGpuCommandBuffer::LoadOp loadOpIn,
}
}
-GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu,
- GrRenderTarget* rt, GrSurfaceOrigin origin,
- const LoadAndStoreInfo& colorInfo,
- const StencilLoadAndStoreInfo& stencilInfo)
+GrVkGpuRTCommandBuffer::GrVkGpuRTCommandBuffer(GrVkGpu* gpu,
+ GrRenderTarget* rt, GrSurfaceOrigin origin,
+ const LoadAndStoreInfo& colorInfo,
+ const StencilLoadAndStoreInfo& stencilInfo)
: INHERITED(rt, origin)
, fGpu(gpu)
, fClearColor(GrColor4f::FromGrColor(colorInfo.fClearColor))
@@ -71,7 +91,7 @@ GrVkGpuCommandBuffer::GrVkGpuCommandBuffer(GrVkGpu* gpu,
this->init();
}
-void GrVkGpuCommandBuffer::init() {
+void GrVkGpuRTCommandBuffer::init() {
GrVkRenderPass::LoadStoreOps vkColorOps(fVkColorLoadOp, fVkColorStoreOp);
GrVkRenderPass::LoadStoreOps vkStencilOps(fVkStencilLoadOp, fVkStencilStoreOp);
@@ -105,7 +125,7 @@ void GrVkGpuCommandBuffer::init() {
}
-GrVkGpuCommandBuffer::~GrVkGpuCommandBuffer() {
+GrVkGpuRTCommandBuffer::~GrVkGpuRTCommandBuffer() {
for (int i = 0; i < fCommandBufferInfos.count(); ++i) {
CommandBufferInfo& cbInfo = fCommandBufferInfos[i];
for (int j = 0; j < cbInfo.fCommandBuffers.count(); ++j) {
@@ -115,15 +135,15 @@ GrVkGpuCommandBuffer::~GrVkGpuCommandBuffer() {
}
}
-GrGpu* GrVkGpuCommandBuffer::gpu() { return fGpu; }
+GrGpu* GrVkGpuRTCommandBuffer::gpu() { return fGpu; }
-void GrVkGpuCommandBuffer::end() {
+void GrVkGpuRTCommandBuffer::end() {
if (fCurrentCmdInfo >= 0) {
fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf()->end(fGpu);
}
}
-void GrVkGpuCommandBuffer::onSubmit() {
+void GrVkGpuRTCommandBuffer::submit() {
if (!fRenderTarget) {
return;
}
@@ -160,6 +180,11 @@ void GrVkGpuCommandBuffer::onSubmit() {
iuInfo.fFlushState->doUpload(iuInfo.fUpload);
}
+ for (int j = 0; j < cbInfo.fPreCopies.count(); ++j) {
+ CopyInfo& copyInfo = cbInfo.fPreCopies[j];
+ fGpu->copySurface(fRenderTarget, copyInfo.fSrc, copyInfo.fSrcRect, copyInfo.fDstPoint);
+ }
+
// TODO: We can't add this optimization yet since many things create a scratch texture which
// adds the discard immediately, but then don't draw to it right away. This causes the
// discard to be ignored and we get yelled at for loading uninitialized data. However, once
@@ -184,7 +209,7 @@ void GrVkGpuCommandBuffer::onSubmit() {
}
}
-void GrVkGpuCommandBuffer::discard() {
+void GrVkGpuRTCommandBuffer::discard() {
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget);
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
@@ -216,11 +241,11 @@ void GrVkGpuCommandBuffer::discard() {
}
}
-void GrVkGpuCommandBuffer::insertEventMarker(const char* msg) {
+void GrVkGpuRTCommandBuffer::insertEventMarker(const char* msg) {
// TODO: does Vulkan have a correlate?
}
-void GrVkGpuCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
+void GrVkGpuRTCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
SkASSERT(!clip.hasWindowRectangles());
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
@@ -280,7 +305,7 @@ void GrVkGpuCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insi
}
}
-void GrVkGpuCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
+void GrVkGpuRTCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget);
// parent class should never let us get here with no RT
@@ -361,7 +386,9 @@ void GrVkGpuCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
return;
}
-void GrVkGpuCommandBuffer::addAdditionalCommandBuffer() {
+////////////////////////////////////////////////////////////////////////////////
+
+void GrVkGpuRTCommandBuffer::addAdditionalCommandBuffer() {
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget);
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
@@ -370,7 +397,7 @@ void GrVkGpuCommandBuffer::addAdditionalCommandBuffer() {
cbInfo.currentCmdBuf()->begin(fGpu, vkRT->framebuffer(), cbInfo.fRenderPass);
}
-void GrVkGpuCommandBuffer::addAdditionalRenderPass() {
+void GrVkGpuRTCommandBuffer::addAdditionalRenderPass() {
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget);
fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf()->end(fGpu);
@@ -406,7 +433,7 @@ void GrVkGpuCommandBuffer::addAdditionalRenderPass() {
cbInfo.currentCmdBuf()->begin(fGpu, vkRT->framebuffer(), cbInfo.fRenderPass);
}
-void GrVkGpuCommandBuffer::inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload) {
+void GrVkGpuRTCommandBuffer::inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload) {
if (!fCommandBufferInfos[fCurrentCmdInfo].fIsEmpty) {
this->addAdditionalRenderPass();
@@ -414,12 +441,21 @@ void GrVkGpuCommandBuffer::inlineUpload(GrOpFlushState* state, GrDrawOp::Deferre
fCommandBufferInfos[fCurrentCmdInfo].fPreDrawUploads.emplace_back(state, upload);
}
+void GrVkGpuRTCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect,
+ const SkIPoint& dstPoint) {
+ if (!fCommandBufferInfos[fCurrentCmdInfo].fIsEmpty ||
+ fCommandBufferInfos[fCurrentCmdInfo].fStartsWithClear) {
+ this->addAdditionalRenderPass();
+ }
+ fCommandBufferInfos[fCurrentCmdInfo].fPreCopies.emplace_back(src, srcRect, dstPoint);
+}
+
////////////////////////////////////////////////////////////////////////////////
-void GrVkGpuCommandBuffer::bindGeometry(const GrPrimitiveProcessor& primProc,
- const GrBuffer* indexBuffer,
- const GrBuffer* vertexBuffer,
- const GrBuffer* instanceBuffer) {
+void GrVkGpuRTCommandBuffer::bindGeometry(const GrPrimitiveProcessor& primProc,
+ const GrBuffer* indexBuffer,
+ const GrBuffer* vertexBuffer,
+ const GrBuffer* instanceBuffer) {
GrVkSecondaryCommandBuffer* currCmdBuf = fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf();
// There is no need to put any memory barriers to make sure host writes have finished here.
// When a command buffer is submitted to a queue, there is an implicit memory barrier that
@@ -457,7 +493,7 @@ void GrVkGpuCommandBuffer::bindGeometry(const GrPrimitiveProcessor& primProc,
}
}
-sk_sp<GrVkPipelineState> GrVkGpuCommandBuffer::prepareDrawState(
+sk_sp<GrVkPipelineState> GrVkGpuRTCommandBuffer::prepareDrawState(
const GrPipeline& pipeline,
const GrPrimitiveProcessor& primProc,
GrPrimitiveType primitiveType,
@@ -535,12 +571,12 @@ static void prepare_sampled_images(const GrResourceIOProcessor& processor, GrVkG
}
}
-void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline,
- const GrPrimitiveProcessor& primProc,
- const GrMesh meshes[],
- const GrPipeline::DynamicState dynamicStates[],
- int meshCount,
- const SkRect& bounds) {
+void GrVkGpuRTCommandBuffer::onDraw(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrMesh meshes[],
+ const GrPipeline::DynamicState dynamicStates[],
+ int meshCount,
+ const SkRect& bounds) {
SkASSERT(pipeline.renderTarget() == fRenderTarget);
if (!meshCount) {
@@ -605,30 +641,30 @@ void GrVkGpuCommandBuffer::onDraw(const GrPipeline& pipeline,
pipelineState->freeTempResources(fGpu);
}
-void GrVkGpuCommandBuffer::sendInstancedMeshToGpu(const GrPrimitiveProcessor& primProc,
- GrPrimitiveType,
- const GrBuffer* vertexBuffer,
- int vertexCount,
- int baseVertex,
- const GrBuffer* instanceBuffer,
- int instanceCount,
- int baseInstance) {
+void GrVkGpuRTCommandBuffer::sendInstancedMeshToGpu(const GrPrimitiveProcessor& primProc,
+ GrPrimitiveType,
+ const GrBuffer* vertexBuffer,
+ int vertexCount,
+ int baseVertex,
+ const GrBuffer* instanceBuffer,
+ int instanceCount,
+ int baseInstance) {
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
this->bindGeometry(primProc, nullptr, vertexBuffer, instanceBuffer);
cbInfo.currentCmdBuf()->draw(fGpu, vertexCount, instanceCount, baseVertex, baseInstance);
fGpu->stats()->incNumDraws();
}
-void GrVkGpuCommandBuffer::sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor& primProc,
- GrPrimitiveType,
- const GrBuffer* indexBuffer,
- int indexCount,
- int baseIndex,
- const GrBuffer* vertexBuffer,
- int baseVertex,
- const GrBuffer* instanceBuffer,
- int instanceCount,
- int baseInstance) {
+void GrVkGpuRTCommandBuffer::sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor& primProc,
+ GrPrimitiveType,
+ const GrBuffer* indexBuffer,
+ int indexCount,
+ int baseIndex,
+ const GrBuffer* vertexBuffer,
+ int baseVertex,
+ const GrBuffer* instanceBuffer,
+ int instanceCount,
+ int baseInstance) {
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
this->bindGeometry(primProc, indexBuffer, vertexBuffer, instanceBuffer);
cbInfo.currentCmdBuf()->drawIndexed(fGpu, indexCount, instanceCount,
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.h b/src/gpu/vk/GrVkGpuCommandBuffer.h
index ab5900eb61..9209a3b2a6 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.h
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.h
@@ -21,13 +21,44 @@ class GrVkRenderPass;
class GrVkRenderTarget;
class GrVkSecondaryCommandBuffer;
-class GrVkGpuCommandBuffer : public GrGpuCommandBuffer, private GrMesh::SendToGpuImpl {
+class GrVkGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
public:
- GrVkGpuCommandBuffer(GrVkGpu*, GrRenderTarget*, GrSurfaceOrigin,
- const LoadAndStoreInfo&,
- const StencilLoadAndStoreInfo&);
+ GrVkGpuTextureCommandBuffer(GrVkGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin)
+ : INHERITED(texture, origin)
+ , fGpu(gpu) {
+ }
+
+ ~GrVkGpuTextureCommandBuffer() override;
+
+ void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
+
+ void insertEventMarker(const char*) override;
+
+private:
+ void submit() override;
+
+ struct CopyInfo {
+ CopyInfo(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint)
+ : fSrc(src), fSrcRect(srcRect), fDstPoint(dstPoint) {}
+
+ GrSurface* fSrc;
+ SkIRect fSrcRect;
+ SkIPoint fDstPoint;
+ };
+
+ GrVkGpu* fGpu;
+ SkTArray<CopyInfo> fCopies;
+
+ typedef GrGpuTextureCommandBuffer INHERITED;
+};
- ~GrVkGpuCommandBuffer() override;
+class GrVkGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl {
+public:
+ GrVkGpuRTCommandBuffer(GrVkGpu*, GrRenderTarget*, GrSurfaceOrigin,
+ const LoadAndStoreInfo&,
+ const StencilLoadAndStoreInfo&);
+
+ ~GrVkGpuRTCommandBuffer() override;
void begin() override { }
void end() override;
@@ -37,13 +68,15 @@ public:
void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload) override;
+ void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
+
+ void submit() override;
+
private:
void init();
GrGpu* gpu() override;
- void onSubmit() override;
-
// Bind vertex and index buffers
void bindGeometry(const GrPrimitiveProcessor&,
const GrBuffer* indexBuffer,
@@ -104,6 +137,15 @@ private:
GrDrawOp::DeferredUploadFn fUpload;
};
+ struct CopyInfo {
+ CopyInfo(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint)
+ : fSrc(src), fSrcRect(srcRect), fDstPoint(dstPoint) {}
+
+ GrSurface* fSrc;
+ SkIRect fSrcRect;
+ SkIPoint fDstPoint;
+ };
+
struct CommandBufferInfo {
const GrVkRenderPass* fRenderPass;
SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers;
@@ -111,7 +153,10 @@ private:
SkRect fBounds;
bool fIsEmpty;
bool fStartsWithClear;
+ // The PreDrawUploads and PreCopies are sent to the GPU before submitting the secondary
+ // command buffer.
SkTArray<InlineUploadInfo> fPreDrawUploads;
+ SkTArray<CopyInfo> fPreCopies;
GrVkSecondaryCommandBuffer* currentCmdBuf() {
return fCommandBuffers.back();
@@ -129,7 +174,7 @@ private:
GrColor4f fClearColor;
GrVkPipelineState* fLastPipelineState;
- typedef GrGpuCommandBuffer INHERITED;
+ typedef GrGpuRTCommandBuffer INHERITED;
};
#endif