Fix vulkan async transfer from call to not submit command buffer to early.
Change-Id: I657758070261a6365975d9c7d61489b1ccb0e437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219201
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index e783a20..873ac8b 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -335,6 +335,8 @@
void GrVkGpu::submitCommandBuffer(SyncQueue sync, GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) {
SkASSERT(fCurrentCmdBuffer);
+ SkASSERT(!fCachedRTCommandBuffer || !fCachedRTCommandBuffer->isActive());
+ SkASSERT(!fCachedTexCommandBuffer || !fCachedTexCommandBuffer->isActive());
if (!fCurrentCmdBuffer->hasWork() && kForce_SyncQueue != sync &&
!fSemaphoresToSignal.count() && !fSemaphoresToWaitOn.count()) {
@@ -569,10 +571,6 @@
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_HOST_BIT,
false);
-
- // The caller is responsible for syncing.
- this->submitCommandBuffer(kSkip_SyncQueue);
-
return true;
}
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index 726095d..10682c6 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -327,6 +327,10 @@
SkASSERT(fGpu == rt->getContext()->priv().getGpu());
SkASSERT(!fLastPipelineState);
+#ifdef SK_DEBUG
+ fIsActive = true;
+#endif
+
this->INHERITED::set(rt, origin);
if (this->wrapsSecondaryCommandBuffer()) {
@@ -360,6 +364,10 @@
fLastPipelineState = nullptr;
fRenderTarget = nullptr;
+
+#ifdef SK_DEBUG
+ fIsActive = false;
+#endif
}
bool GrVkGpuRTCommandBuffer::wrapsSecondaryCommandBuffer() const {
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.h b/src/gpu/vk/GrVkGpuCommandBuffer.h
index 395ae24..d3eb668 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.h
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.h
@@ -54,14 +54,38 @@
void reset() {
fTasks.reset();
fTexture = nullptr;
+#ifdef SK_DEBUG
+ fIsActive = false;
+#endif
}
+ void setVk(GrTexture* tex, GrSurfaceOrigin origin) {
+#ifdef SK_DEBUG
+ fIsActive = true;
+#endif
+ this->INHERITED::set(tex, origin);
+ }
+
+#ifdef SK_DEBUG
+ bool isActive() const { return fIsActive; }
+#endif
+
void submit();
private:
GrVkGpu* fGpu;
GrTRecorder<GrVkPrimaryCommandBufferTask> fTasks{1024};
+#ifdef SK_DEBUG
+ // When we are actively recording into the GrVkGpuCommandBuffer we set this flag to true. This
+ // then allows us to assert that we never submit a primary command buffer to the queue while in
+ // a recording state. This is needed since when we submit to the queue we change command pools
+ // and may trigger the old one to be reset, but a recording GrVkGpuCommandBuffer may still have
+ // a outstanding secondary command buffer allocated from that pool that we'll try to access
+ // after the pool as been reset.
+ bool fIsActive = false;
+#endif
+
typedef GrGpuTextureCommandBuffer INHERITED;
};
@@ -92,6 +116,10 @@
void submit();
+#ifdef SK_DEBUG
+ bool isActive() const { return fIsActive; }
+#endif
+
private:
void init();
@@ -193,6 +221,16 @@
VkAttachmentStoreOp fVkStencilStoreOp;
int fCurrentCmdInfo = -1;
+#ifdef SK_DEBUG
+ // When we are actively recording into the GrVkGpuCommandBuffer we set this flag to true. This
+ // then allows us to assert that we never submit a primary command buffer to the queue while in
+ // a recording state. This is needed since when we submit to the queue we change command pools
+ // and may trigger the old one to be reset, but a recording GrVkGpuCommandBuffer may still have
+ // a outstanding secondary command buffer allocated from that pool that we'll try to access
+ // after the pool as been reset.
+ bool fIsActive = false;
+#endif
+
typedef GrGpuRTCommandBuffer INHERITED;
};