Add GrContextOption to limit the number of cached secondary command buffers.

Bug: skia:10438
Change-Id: I3116fc1c7ee75f9b7a712c05199a9ed4a0d419c5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302291
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Emircan Uysaler <emircan@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Greg Daniel 2020-07-14 09:21:48 -04:00 committed by Skia Commit-Bot
parent 380fba6e4b
commit 43833b028a
5 changed files with 32 additions and 2 deletions

View File

@ -225,6 +225,17 @@ struct SK_API GrContextOptions {
*/
int fInternalMultisampleCount = 4;
/**
* In Skia's vulkan backend a single GrContext submit equates to the submission of a single
* primary command buffer to the VkQueue. This value specifies how many vulkan secondary command
* buffers we will cache for reuse on a given primary command buffer. A single submit may use
* more than this many secondary command buffers, but after the primary command buffer is
* finished on the GPU it will only hold on to this many secondary command buffers for reuse.
*
* A value of -1 means we will pick a limit value internally.
*/
int fMaxCachedVulkanSecondaryCommandBuffers = -1;
#if GR_TEST_UTILS
/**
* Private options that are only meant for testing within Skia's tools.

View File

@ -401,6 +401,11 @@ void GrVkCaps::init(const GrContextOptions& contextOptions, const GrVkInterface*
this->initFormatTable(vkInterface, physDev, properties);
this->initStencilFormat(vkInterface, physDev);
if (contextOptions.fMaxCachedVulkanSecondaryCommandBuffers >= 0) {
fMaxPerPoolCachedSecondaryCommandBuffers =
contextOptions.fMaxCachedVulkanSecondaryCommandBuffers;
}
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
this->applyDriverCorrectnessWorkarounds(properties);
}

View File

@ -162,6 +162,10 @@ public:
return fPreferPrimaryOverSecondaryCommandBuffers;
}
int maxPerPoolCachedSecondaryCommandBuffers() const {
return fMaxPerPoolCachedSecondaryCommandBuffers;
}
bool mustInvalidatePrimaryCmdBufferStateAfterClearAttachments() const {
return fMustInvalidatePrimaryCmdBufferStateAfterClearAttachments;
}
@ -334,6 +338,11 @@ private:
bool fPreferPrimaryOverSecondaryCommandBuffers = true;
bool fMustInvalidatePrimaryCmdBufferStateAfterClearAttachments = false;
// We default this to 100 since we already cap the max render tasks at 100 before doing a
// submission in the GrDrawingManager, so we shouldn't be going over 100 secondary command
// buffers per primary anyways.
int fMaxPerPoolCachedSecondaryCommandBuffers = 100;
typedef GrCaps INHERITED;
};

View File

@ -45,7 +45,9 @@ GrVkCommandPool::GrVkCommandPool(GrVkGpu* gpu, VkCommandPool commandPool,
GrVkPrimaryCommandBuffer* primaryCmdBuffer)
: GrVkManagedResource(gpu)
, fCommandPool(commandPool)
, fPrimaryCommandBuffer(primaryCmdBuffer) {
, fPrimaryCommandBuffer(primaryCmdBuffer)
, fMaxCachedSecondaryCommandBuffers(
gpu->vkCaps().maxPerPoolCachedSecondaryCommandBuffers()) {
}
std::unique_ptr<GrVkSecondaryCommandBuffer> GrVkCommandPool::findOrCreateSecondaryCommandBuffer(
@ -62,7 +64,9 @@ std::unique_ptr<GrVkSecondaryCommandBuffer> GrVkCommandPool::findOrCreateSeconda
void GrVkCommandPool::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer) {
std::unique_ptr<GrVkSecondaryCommandBuffer> scb(buffer);
fAvailableSecondaryBuffers.push_back(std::move(scb));
if (fAvailableSecondaryBuffers.count() < fMaxCachedSecondaryCommandBuffers) {
fAvailableSecondaryBuffers.push_back(std::move(scb));
}
}
void GrVkCommandPool::close() {

View File

@ -62,6 +62,7 @@ private:
// Array of available secondary command buffers that are not in flight
SkSTArray<4, std::unique_ptr<GrVkSecondaryCommandBuffer>, true> fAvailableSecondaryBuffers;
int fMaxCachedSecondaryCommandBuffers;
};
#endif