Commit cf49403e by Charlie Lao Committed by Commit Bot

Vulkan: Increase default uniform buffer size to 64K

Since these are per context, we can increase it (and subject to the driver maxUniformBufferRange limit) to reduce the amount of descriptor set allocated. Bug: b/161391337 Change-Id: I89e5cf16ee377735c412e9a9a22c651e1c677ded Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2310910 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent 308078b0
...@@ -360,6 +360,15 @@ struct FeaturesVk : FeatureSetBase ...@@ -360,6 +360,15 @@ struct FeaturesVk : FeatureSetBase
"Use the compute path to generate mipmaps on devices that meet the minimum requirements, " "Use the compute path to generate mipmaps on devices that meet the minimum requirements, "
"and the performance is better.", "and the performance is better.",
&members, "http://anglebug.com/4551"}; &members, "http://anglebug.com/4551"};
// Force maxUniformBufferSize to 16K on Qualcomm's Adreno 540. Pixel2's Adreno540 reports
// maxUniformBufferSize 64k but various tests failed with that size. For that specific
// device, we set to 16k for now which is known to pass all tests.
// https://issuetracker.google.com/161903006
Feature forceMaxUniformBufferSize16KB = {
"force_max_uniform_buffer_size_16K", FeatureCategory::VulkanWorkarounds,
"Force max uniform buffer size to 16K on some device due to bug", &members,
"https://issuetracker.google.com/161903006"};
}; };
inline FeaturesVk::FeaturesVk() = default; inline FeaturesVk::FeaturesVk() = default;
......
...@@ -101,6 +101,7 @@ constexpr VendorID kVendorID_Kazan = 0x10003; ...@@ -101,6 +101,7 @@ constexpr VendorID kVendorID_Kazan = 0x10003;
// Known device IDs // Known device IDs
constexpr DeviceID kDeviceID_Swiftshader = 0xC0DE; constexpr DeviceID kDeviceID_Swiftshader = 0xC0DE;
constexpr DeviceID kDeviceID_Adreno540 = 0x5040001;
// Predicates on vendor IDs // Predicates on vendor IDs
bool IsAMD(VendorID vendorId); bool IsAMD(VendorID vendorId);
......
...@@ -885,11 +885,8 @@ angle::Result ContextVk::initialize() ...@@ -885,11 +885,8 @@ angle::Result ContextVk::initialize()
size_t minAlignment = static_cast<size_t>( size_t minAlignment = static_cast<size_t>(
mRenderer->getPhysicalDeviceProperties().limits.minUniformBufferOffsetAlignment); mRenderer->getPhysicalDeviceProperties().limits.minUniformBufferOffsetAlignment);
// This size is picked based on experience, may needs more tuning.
size_t uniformBufferSize =
std::min(16 * 1024u, mRenderer->getPhysicalDeviceProperties().limits.maxUniformBufferRange);
mDefaultUniformStorage.init(mRenderer, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, minAlignment, mDefaultUniformStorage.init(mRenderer, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, minAlignment,
uniformBufferSize, true); mRenderer->getDefaultUniformBufferSize(), true);
// Initialize an "empty" buffer for use with default uniform blocks where there are no uniforms, // Initialize an "empty" buffer for use with default uniform blocks where there are no uniforms,
// or atomic counter buffer array indices that are unused. // or atomic counter buffer array indices that are unused.
......
...@@ -47,6 +47,14 @@ namespace rx ...@@ -47,6 +47,14 @@ namespace rx
namespace namespace
{ {
constexpr uint32_t kMinDefaultUniformBufferSize = 16 * 1024u;
// This size is picked based on experience. Majority of devices support 64K
// maxUniformBufferSize. Since this is per context buffer, a bigger buffer size reduces the
// number of descriptor set allocations, so we picked the maxUniformBufferSize that most
// devices supports. It may needs further tuning based on specific device needs and balance
// between performance and memory usage.
constexpr uint32_t kPreferredDefaultUniformBufferSize = 64 * 1024u;
// Update the pipeline cache every this many swaps. // Update the pipeline cache every this many swaps.
constexpr uint32_t kPipelineCacheVkUpdatePeriod = 60; constexpr uint32_t kPipelineCacheVkUpdatePeriod = 60;
// Per the Vulkan specification, as long as Vulkan 1.1+ is returned by vkEnumerateInstanceVersion, // Per the Vulkan specification, as long as Vulkan 1.1+ is returned by vkEnumerateInstanceVersion,
...@@ -442,6 +450,7 @@ RendererVk::RendererVk() ...@@ -442,6 +450,7 @@ RendererVk::RendererVk()
mMaxVertexAttribDivisor(1), mMaxVertexAttribDivisor(1),
mMaxVertexAttribStride(0), mMaxVertexAttribStride(0),
mMinImportedHostPointerAlignment(1), mMinImportedHostPointerAlignment(1),
mDefaultUniformBufferSize(kPreferredDefaultUniformBufferSize),
mDevice(VK_NULL_HANDLE), mDevice(VK_NULL_HANDLE),
mLastCompletedQueueSerial(mQueueSerialFactory.generate()), mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
mCurrentQueueSerial(mQueueSerialFactory.generate()), mCurrentQueueSerial(mQueueSerialFactory.generate()),
...@@ -1387,6 +1396,14 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF ...@@ -1387,6 +1396,14 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
} }
#endif // !defined(ANGLE_SHARED_LIBVULKAN) #endif // !defined(ANGLE_SHARED_LIBVULKAN)
if (getFeatures().forceMaxUniformBufferSize16KB.enabled)
{
mDefaultUniformBufferSize = kMinDefaultUniformBufferSize;
}
// Cap it with the driver limit
mDefaultUniformBufferSize = std::min(
mDefaultUniformBufferSize, getPhysicalDeviceProperties().limits.maxUniformBufferRange);
// Initialize the vulkan pipeline cache. // Initialize the vulkan pipeline cache.
bool success = false; bool success = false;
ANGLE_TRY(initPipelineCache(displayVk, &mPipelineCache, &success)); ANGLE_TRY(initPipelineCache(displayVk, &mPipelineCache, &success));
...@@ -1813,6 +1830,9 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev ...@@ -1813,6 +1830,9 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev
&mFeatures, allowGenerateMipmapWithCompute, &mFeatures, allowGenerateMipmapWithCompute,
maxComputeWorkGroupInvocations >= 256 && (isNvidia || (isAMD && !IsWindows()))); maxComputeWorkGroupInvocations >= 256 && (isNvidia || (isAMD && !IsWindows())));
bool isAdreno540 = mPhysicalDeviceProperties.deviceID == angle::kDeviceID_Adreno540;
ANGLE_FEATURE_CONDITION(&mFeatures, forceMaxUniformBufferSize16KB, isQualcomm && isAdreno540);
angle::PlatformMethods *platform = ANGLEPlatformCurrent(); angle::PlatformMethods *platform = ANGLEPlatformCurrent();
platform->overrideFeaturesVk(platform, &mFeatures); platform->overrideFeaturesVk(platform, &mFeatures);
......
...@@ -158,6 +158,7 @@ class RendererVk : angle::NonCopyable ...@@ -158,6 +158,7 @@ class RendererVk : angle::NonCopyable
{ {
return mMinImportedHostPointerAlignment; return mMinImportedHostPointerAlignment;
} }
uint32_t getDefaultUniformBufferSize() const { return mDefaultUniformBufferSize; }
bool isMockICDEnabled() const { return mEnabledICD == angle::vk::ICD::Mock; } bool isMockICDEnabled() const { return mEnabledICD == angle::vk::ICD::Mock; }
...@@ -318,6 +319,7 @@ class RendererVk : angle::NonCopyable ...@@ -318,6 +319,7 @@ class RendererVk : angle::NonCopyable
uint32_t mMaxVertexAttribDivisor; uint32_t mMaxVertexAttribDivisor;
VkDeviceSize mMaxVertexAttribStride; VkDeviceSize mMaxVertexAttribStride;
VkDeviceSize mMinImportedHostPointerAlignment; VkDeviceSize mMinImportedHostPointerAlignment;
uint32_t mDefaultUniformBufferSize;
VkDevice mDevice; VkDevice mDevice;
AtomicSerialFactory mQueueSerialFactory; AtomicSerialFactory mQueueSerialFactory;
AtomicSerialFactory mShaderSerialFactory; AtomicSerialFactory mShaderSerialFactory;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment