Skip to content

Commit 4a80ba2

Browse files
timvpGoogleCommit Bot
authored andcommitted
Vulkan: Ignore VK_INCOMPLETE from vkGetPipelineCacheData
From vkGetPipelineCacheData(3) Manual Page: If pDataSize is less than the maximum size that can be retrieved by the pipeline cache, at most pDataSize bytes will be written to pData, and vkGetPipelineCacheData will return VK_INCOMPLETE. Any data written to pData is valid and can be provided as the pInitialData member of the VkPipelineCacheCreateInfo structure passed to vkCreatePipelineCache. Bug: angleproject:3988 Test: CQ, CtsOpenGLTestCases Change-Id: I34589ee3c9e27839a9cd0168b4a2186f4cbb255e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1854680 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: Tobin Ehlis <tobine@google.com>
1 parent 68591ef commit 4a80ba2

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/libANGLE/renderer/vulkan/RendererVk.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,14 @@ angle::Result RendererVk::getPipelineLayout(
14851485
pipelineLayoutOut);
14861486
}
14871487

1488+
angle::Result RendererVk::getPipelineCacheSize(DisplayVk *displayVk, size_t *pipelineCacheSizeOut)
1489+
{
1490+
VkResult result = mPipelineCache.getCacheData(mDevice, pipelineCacheSizeOut, nullptr);
1491+
ANGLE_VK_TRY(displayVk, result);
1492+
1493+
return angle::Result::Continue;
1494+
}
1495+
14881496
angle::Result RendererVk::syncPipelineCacheVk(DisplayVk *displayVk)
14891497
{
14901498
// TODO: Synchronize access to the pipeline/blob caches?
@@ -1502,33 +1510,41 @@ angle::Result RendererVk::syncPipelineCacheVk(DisplayVk *displayVk)
15021510

15031511
mPipelineCacheVkUpdateTimeout = kPipelineCacheVkUpdatePeriod;
15041512

1505-
// Get the size of the cache.
15061513
size_t pipelineCacheSize = 0;
1507-
VkResult result = mPipelineCache.getCacheData(mDevice, &pipelineCacheSize, nullptr);
1508-
if (result != VK_INCOMPLETE)
1509-
{
1510-
ANGLE_VK_TRY(displayVk, result);
1511-
}
1514+
ANGLE_TRY(getPipelineCacheSize(displayVk, &pipelineCacheSize));
15121515

15131516
angle::MemoryBuffer *pipelineCacheData = nullptr;
15141517
ANGLE_VK_CHECK_ALLOC(displayVk,
15151518
displayVk->getScratchBuffer(pipelineCacheSize, &pipelineCacheData));
15161519

15171520
size_t originalPipelineCacheSize = pipelineCacheSize;
1518-
result = mPipelineCache.getCacheData(mDevice, &pipelineCacheSize, pipelineCacheData->data());
1519-
// Note: currently we don't accept incomplete as we don't expect it (the full size of cache
1520-
// was determined just above), so receiving it hints at an implementation bug we would want
1521-
// to know about early.
1522-
ASSERT(result != VK_INCOMPLETE);
1521+
VkResult result =
1522+
mPipelineCache.getCacheData(mDevice, &pipelineCacheSize, pipelineCacheData->data());
1523+
// We don't need all of the cache data, so just make sure we at least got the header
1524+
// Vulkan Spec 9.6. Pipeline Cache
1525+
// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/chap9.html#pipelines-cache
1526+
// If pDataSize is less than what is necessary to store this header, nothing will be written to
1527+
// pData and zero will be written to pDataSize.
1528+
// Any data written to pData is valid and can be provided as the pInitialData member of the
1529+
// VkPipelineCacheCreateInfo structure passed to vkCreatePipelineCache.
1530+
if (ANGLE_UNLIKELY(result == VK_INCOMPLETE) || (pipelineCacheSize == 0))
1531+
{
1532+
size_t intermediatePipelineCacheSize = pipelineCacheSize;
1533+
ANGLE_TRY(getPipelineCacheSize(displayVk, &pipelineCacheSize));
1534+
ERR() << "Pipeline cache size changed: old = " << originalPipelineCacheSize
1535+
<< ", intermediate = " << intermediatePipelineCacheSize
1536+
<< ", current = " << pipelineCacheData;
1537+
}
1538+
// TODO(http://anglebug.com/3988) Ignore VK_INCOMPLETE to reduce test flakiness
15231539
ANGLE_VK_TRY(displayVk, result);
15241540

15251541
// If vkGetPipelineCacheData ends up writing fewer bytes than requested, zero out the rest of
15261542
// the buffer to avoid leaking garbage memory.
1527-
ASSERT(pipelineCacheSize <= originalPipelineCacheSize);
1528-
if (pipelineCacheSize < originalPipelineCacheSize)
1543+
ASSERT(pipelineCacheSize <= pipelineCacheData->size());
1544+
if (pipelineCacheSize < pipelineCacheData->size())
15291545
{
15301546
memset(pipelineCacheData->data() + pipelineCacheSize, 0,
1531-
originalPipelineCacheSize - pipelineCacheSize);
1547+
pipelineCacheData->size() - pipelineCacheSize);
15321548
}
15331549

15341550
displayVk->getBlobCache()->putApplication(mPipelineCacheVkBlobKey, *pipelineCacheData);

src/libANGLE/renderer/vulkan/RendererVk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class RendererVk : angle::NonCopyable
127127
const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts,
128128
vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut);
129129

130+
angle::Result getPipelineCacheSize(DisplayVk *displayVk, size_t *pipelineCacheSizeOut);
130131
angle::Result syncPipelineCacheVk(DisplayVk *displayVk);
131132

132133
// Issues a new serial for linked shader modules. Used in the pipeline cache.

0 commit comments

Comments
 (0)