Use main command buffer for updateBackendTexture in vulkan.

Deletes support for the "side" temp command buffer

Bug: chromium:1087124
Change-Id: I97cda4e98faddd2d65f257613e19a825f52402c1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294518
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2020-06-05 10:22:26 -04:00 committed by Skia Commit-Bot
parent de00dc9004
commit 288ecf60bd
5 changed files with 41 additions and 85 deletions

View File

@ -482,8 +482,8 @@ public:
* If possible, create a backend texture initialized to a particular color. The client should
* ensure that the returned backend texture is valid. The client can pass in a finishedProc
* to be notified when the data has been uploaded by the gpu and the texture can be deleted. The
* client can assume the upload work has been submitted to the gpu. The finishedProc will always
* get called even if we failed to create the GrBackendTexture.
* client is required to call GrContext::submit to send the upload work to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture.
* For the Vulkan backend the layout of the created VkImage will be:
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
*/
@ -500,8 +500,8 @@ public:
* If possible, create a backend texture initialized to a particular color. The client should
* ensure that the returned backend texture is valid. The client can pass in a finishedProc
* to be notified when the data has been uploaded by the gpu and the texture can be deleted. The
* client can assume the upload work has been submitted to the gpu. The finishedProc will always
* get called even if we failed to create the GrBackendTexture.
* client is required to call GrContext::submit to send the upload work to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture.
* If successful, the created backend texture will be compatible with the provided
* SkColorType.
* For the Vulkan backend the layout of the created VkImage will be:
@ -520,9 +520,9 @@ public:
* If possible, create a backend texture initialized to a particular color that is
* compatible with the provided characterization. The client should ensure that the
* returned backend texture is valid. The client can pass in a finishedProc to be notified when
* the data has been uploaded by the gpu and the texture can be deleted. The client can assume
* the upload work has been submitted to the gpu. The finishedProc will always get called even
* if we failed to create the GrBackendTexture.
* the data has been uploaded by the gpu and the texture can be deleted. The client is required
* to call GrContext::submit to send the upload work to the gpu. The finishedProc will always
* get called even if we failed to create the GrBackendTexture.
* For the Vulkan backend the layout of the created VkImage will be:
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if texturaeble
* VK_IMAGE_LAYOUT_UNDEFINED if not textureable
@ -536,11 +536,12 @@ public:
* If possible, create a backend texture initialized with the provided pixmap data. The client
* should ensure that the returned backend texture is valid. The client can pass in a
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
* deleted. The client can assume the upload work has been submitted to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture.
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
* If successful, the created backend texture will be compatible with the provided
* pixmap(s). Compatible, in this case, means that the backend format will be the result
* of calling defaultBackendFormat on the base pixmap's colortype.
* of calling defaultBackendFormat on the base pixmap's colortype. The src data can be deleted
* when this call returns.
* If numLevels is 1 a non-mipMapped texture will result. If a mipMapped texture is desired
* the data for all the mipmap levels must be provided. In the mipmapped case all the
* colortypes of the provided pixmaps must be the same. Additionally, all the miplevels
@ -568,8 +569,8 @@ public:
* If possible, updates a backend texture to be filled to a particular color. The client should
* check the return value to see if the update was successful. The client can pass in a
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
* deleted. The client can assume the upload work has been submitted to the gpu. The
* finishedProc will always get called even if we failed to update the GrBackendTexture.
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
* The finishedProc will always get called even if we failed to update the GrBackendTexture.
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
*/
@ -582,10 +583,11 @@ public:
* If possible, updates a backend texture filled with the provided pixmap data. The client
* should check the return value to see if the update was successful. The client can pass in a
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
* deleted. The client can assume the upload work has been submitted to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture.
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
* The backend texture must be compatible with the provided pixmap(s). Compatible, in this case,
* means that the backend format is compatible with the base pixmap's colortype.
* means that the backend format is compatible with the base pixmap's colortype. The src data
* can be deleted when this call returns.
* If the backend texture is mip mapped, the data for all the mipmap levels must be provided.
* In the mipmapped case all the colortypes of the provided pixmaps must be the same.
* Additionally, all the miplevels must be sized correctly (please see
@ -614,8 +616,8 @@ public:
*If possible, create a compressed backend texture initialized to a particular color. The
* client should ensure that the returned backend texture is valid. The client can pass in a
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
* deleted. The client can assume the upload work has been submitted to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture.
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
* For the Vulkan backend the layout of the created VkImage will be:
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
*/
@ -639,8 +641,8 @@ public:
* If possible, create a backend texture initialized with the provided raw data. The client
* should ensure that the returned backend texture is valid. The client can pass in a
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
* deleted. The client can assume the upload work has been submitted to the gpu. The
* finishedProc will always get called even if we failed to create the GrBackendTexture
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
* The finishedProc will always get called even if we failed to create the GrBackendTexture
* If numLevels is 1 a non-mipMapped texture will result. If a mipMapped texture is desired
* the data for all the mipmap levels must be provided. Additionally, all the miplevels
* must be sized correctly (please see SkMipMap::ComputeLevelSize and ComputeLevelCount).

View File

@ -241,7 +241,6 @@ void GrVkGpu::destroyResources() {
fMainCmdPool->getPrimaryCommandBuffer()->end(this);
fMainCmdPool->close();
}
SkASSERT(!fTempCmdPool);
// wait for all commands to finish
VkResult res = VK_CALL(QueueWaitIdle(fQueue));
@ -301,7 +300,6 @@ void GrVkGpu::disconnect(DisconnectType type) {
fSemaphoresToWaitOn.reset();
fSemaphoresToSignal.reset();
fMainCmdBuffer = nullptr;
SkASSERT(!fTempCmdBuffer);
fDisconnected = true;
}
}
@ -325,40 +323,6 @@ GrOpsRenderPass* GrVkGpu::getOpsRenderPass(
return fCachedOpsRenderPass.get();
}
GrVkPrimaryCommandBuffer* GrVkGpu::getTempCommandBuffer() {
SkASSERT(!fTempCmdPool && !fTempCmdBuffer);
fTempCmdPool = fResourceProvider.findOrCreateCommandPool();
if (!fTempCmdPool) {
return nullptr;
}
fTempCmdBuffer = fTempCmdPool->getPrimaryCommandBuffer();
SkASSERT(fTempCmdBuffer);
fTempCmdBuffer->begin(this);
return fTempCmdBuffer;
}
bool GrVkGpu::submitTempCommandBuffer(SyncQueue sync, sk_sp<GrRefCntedCallback> finishedCallback) {
SkASSERT(fTempCmdBuffer);
fTempCmdBuffer->end(this);
fTempCmdPool->close();
SkASSERT(fMainCmdBuffer->validateNoSharedImageResources(fTempCmdBuffer));
fTempCmdBuffer->addFinishedProc(std::move(finishedCallback));
SkTArray<GrVkSemaphore::Resource*, false> fEmptySemaphores;
bool didSubmit = fTempCmdBuffer->submitToQueue(this, fQueue, fEmptySemaphores,
fEmptySemaphores);
if (didSubmit && sync == kForce_SyncQueue) {
fTempCmdBuffer->forceSync(this);
}
fTempCmdPool->unref();
fTempCmdPool = nullptr;
fTempCmdBuffer = nullptr;
return didSubmit;
}
bool GrVkGpu::submitCommandBuffer(SyncQueue sync) {
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
SkASSERT(this->currentCommandBuffer());
@ -1658,7 +1622,7 @@ bool GrVkGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture,
return false;
}
GrVkPrimaryCommandBuffer* cmdBuffer = this->getTempCommandBuffer();
GrVkPrimaryCommandBuffer* cmdBuffer = this->currentCommandBuffer();
if (!cmdBuffer) {
return false;
}
@ -1727,7 +1691,10 @@ bool GrVkGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture,
VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
false);
return this->submitTempCommandBuffer(kSkip_SyncQueue, std::move(finishedCallback));
if (finishedCallback) {
this->addFinishedCallback(std::move(finishedCallback));
}
return this->submitCommandBuffer(kSkip_SyncQueue);
}
GrBackendTexture GrVkGpu::onCreateBackendTexture(SkISize dimensions,
@ -2052,7 +2019,14 @@ void GrVkGpu::prepareSurfacesForBackendAccessAndExternalIO(
void GrVkGpu::addFinishedProc(GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) {
SkASSERT(finishedProc);
fResourceProvider.addFinishedProcToActiveCommandBuffers(finishedProc, finishedContext);
sk_sp<GrRefCntedCallback> finishedCallback(
new GrRefCntedCallback(finishedProc, finishedContext));
this->addFinishedCallback(std::move(finishedCallback));
}
void GrVkGpu::addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback) {
SkASSERT(finishedCallback);
fResourceProvider.addFinishedProcToActiveCommandBuffers(std::move(finishedCallback));
}
bool GrVkGpu::onSubmitToGpu(bool syncCpu) {

View File

@ -56,9 +56,7 @@ public:
VkDevice device() const { return fDevice; }
VkQueue queue() const { return fQueue; }
uint32_t queueIndex() const { return fQueueIndex; }
GrVkCommandPool* cmdPool() const {
return fTempCmdPool ? fTempCmdPool : fMainCmdPool;
}
GrVkCommandPool* cmdPool() const { return fMainCmdPool; }
const VkPhysicalDeviceProperties& physicalDeviceProperties() const {
return fPhysDevProps;
}
@ -69,9 +67,7 @@ public:
GrVkResourceProvider& resourceProvider() { return fResourceProvider; }
GrVkPrimaryCommandBuffer* currentCommandBuffer() const {
return fTempCmdBuffer ? fTempCmdBuffer : fMainCmdBuffer;
}
GrVkPrimaryCommandBuffer* currentCommandBuffer() const { return fMainCmdBuffer; }
void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override;
@ -256,6 +252,8 @@ private:
void addFinishedProc(GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) override;
void addFinishedCallback(sk_sp<GrRefCntedCallback> finishedCallback);
void prepareSurfacesForBackendAccessAndExternalIO(
GrSurfaceProxy* proxies[], int numProxies, SkSurface::BackendSurfaceAccess access,
const GrPrepareForExternalIORequests& externalRequests) override;
@ -298,18 +296,6 @@ private:
GrVkImageInfo*,
GrProtected);
// Creates a new temporary primary command buffer that will be target of all subsequent commands
// until it is submitted via submitTempCommandBuffer. When the temp command buffer gets
// submitted the main command buffer will begin being the target of commands again. When using a
// a temp command buffer, the caller should not use any resources that may have been used by the
// unsubmitted main command buffer. The reason for this is we've already updated state, like
// image layout, for the resources on the main command buffer even though we haven't submitted
// it yet. Thus if the same resource gets used on the temp our tracking will get thosse state
// updates out of order. It is legal to use a resource on either the temp or main command buffer
// that was used on a previously submitted command buffer;
GrVkPrimaryCommandBuffer* getTempCommandBuffer();
bool submitTempCommandBuffer(SyncQueue sync, sk_sp<GrRefCntedCallback> finishedCallback);
sk_sp<const GrVkInterface> fInterface;
sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
sk_sp<GrVkCaps> fVkCaps;
@ -327,10 +313,6 @@ private:
// just a raw pointer; object's lifespan is managed by fCmdPool
GrVkPrimaryCommandBuffer* fMainCmdBuffer;
GrVkCommandPool* fTempCmdPool = nullptr;
// just a raw pointer; object's lifespan is managed by fCmdPool
GrVkPrimaryCommandBuffer* fTempCmdBuffer = nullptr;
SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToWaitOn;
SkSTArray<1, GrVkSemaphore::Resource*> fSemaphoresToSignal;

View File

@ -365,12 +365,11 @@ void GrVkResourceProvider::checkCommandBuffers() {
}
void GrVkResourceProvider::addFinishedProcToActiveCommandBuffers(
GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext) {
sk_sp<GrRefCntedCallback> procRef(new GrRefCntedCallback(finishedProc, finishedContext));
sk_sp<GrRefCntedCallback> finishedCallback) {
for (int i = 0; i < fActiveCommandPools.count(); ++i) {
GrVkCommandPool* pool = fActiveCommandPools[i];
GrVkPrimaryCommandBuffer* buffer = pool->getPrimaryCommandBuffer();
buffer->addFinishedProc(procRef);
buffer->addFinishedProc(finishedCallback);
}
}

View File

@ -91,8 +91,7 @@ public:
// that the client cares about before they explicitly called flush and the GPU may reorder
// command execution. So we make sure all previously submitted work finishes before we call the
// finishedProc.
void addFinishedProcToActiveCommandBuffers(GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext);
void addFinishedProcToActiveCommandBuffers(sk_sp<GrRefCntedCallback> finishedCallback);
// Finds or creates a compatible GrVkDescriptorPool for the requested type and count.
// The refcount is incremented and a pointer returned.