aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohan Maiya <m.maiya@samsung.com>2024-04-17 17:05:07 -0500
committerAngle LUCI CQ <angle-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-18 20:18:26 +0000
commit4813295059014a39fb75d6a9dd031debb079c69e (patch)
tree050e9a3cf213fdec866872035eb053d56c515d3d
parent80c8b6f05034b346541788d9e6de17f5d22cc854 (diff)
downloadangle-4813295059014a39fb75d6a9dd031debb079c69e.tar.gz
Vulkan: Optimize DescriptorSetLayoutDesc layout
Separate out immutable samplers into its own array so we can remove padding from PackedDescriptorSetBinding which reduces the size of that struct from 16 bytes to 4 bytes. Bug: angleproject:2462 Change-Id: I79d1ab584178202c9b7f34b0c7926edced4e21a8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5464162 Commit-Queue: mohan maiya <m.maiya@samsung.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com>
-rw-r--r--src/libANGLE/renderer/vulkan/UtilsVk.cpp3
-rw-r--r--src/libANGLE/renderer/vulkan/vk_cache_utils.cpp46
-rw-r--r--src/libANGLE/renderer/vulkan/vk_cache_utils.h10
-rw-r--r--src/libANGLE/renderer/vulkan/vk_helpers.cpp4
4 files changed, 26 insertions, 37 deletions
diff --git a/src/libANGLE/renderer/vulkan/UtilsVk.cpp b/src/libANGLE/renderer/vulkan/UtilsVk.cpp
index 0c53c7bb00..306a40ec28 100644
--- a/src/libANGLE/renderer/vulkan/UtilsVk.cpp
+++ b/src/libANGLE/renderer/vulkan/UtilsVk.cpp
@@ -1453,8 +1453,7 @@ angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk,
&mDescriptorSetLayouts[function][DescriptorSetIndex::Internal]));
vk::DescriptorSetLayoutBindingVector bindingVector;
- std::vector<VkSampler> immutableSamplers;
- descriptorSetDesc.unpackBindings(&bindingVector, &immutableSamplers);
+ descriptorSetDesc.unpackBindings(&bindingVector);
std::vector<VkDescriptorPoolSize> descriptorPoolSizes;
for (const VkDescriptorSetLayoutBinding &binding : bindingVector)
diff --git a/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp b/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
index 74a3c87798..3061a76631 100644
--- a/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
+++ b/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
@@ -4275,7 +4275,9 @@ bool operator==(const AttachmentOpsArray &lhs, const AttachmentOpsArray &rhs)
// DescriptorSetLayoutDesc implementation.
DescriptorSetLayoutDesc::DescriptorSetLayoutDesc()
: mPackedDescriptorSetLayout{}, mValidDescriptorSetLayoutIndexMask()
-{}
+{
+ mImmutableSamplers.fill(VK_NULL_HANDLE);
+}
DescriptorSetLayoutDesc::~DescriptorSetLayoutDesc() = default;
@@ -4286,13 +4288,20 @@ DescriptorSetLayoutDesc &DescriptorSetLayoutDesc::operator=(const DescriptorSetL
size_t DescriptorSetLayoutDesc::hash() const
{
- return angle::ComputeGenericHash(mPackedDescriptorSetLayout);
+ size_t genericHash = angle::ComputeGenericHash(mValidDescriptorSetLayoutIndexMask);
+ for (size_t bindingIndex : mValidDescriptorSetLayoutIndexMask)
+ {
+ genericHash ^= angle::ComputeGenericHash(mPackedDescriptorSetLayout[bindingIndex]) ^
+ angle::ComputeGenericHash(mImmutableSamplers[bindingIndex]);
+ }
+ return genericHash;
}
bool DescriptorSetLayoutDesc::operator==(const DescriptorSetLayoutDesc &other) const
{
return memcmp(&mPackedDescriptorSetLayout, &other.mPackedDescriptorSetLayout,
- sizeof(mPackedDescriptorSetLayout)) == 0;
+ sizeof(mPackedDescriptorSetLayout)) == 0 &&
+ memcmp(&mImmutableSamplers, &other.mImmutableSamplers, sizeof(mImmutableSamplers)) == 0;
}
void DescriptorSetLayoutDesc::update(uint32_t bindingIndex,
@@ -4309,20 +4318,19 @@ void DescriptorSetLayoutDesc::update(uint32_t bindingIndex,
SetBitField(packedBinding.type, descriptorType);
SetBitField(packedBinding.count, count);
SetBitField(packedBinding.stages, stages);
- packedBinding.immutableSampler = VK_NULL_HANDLE;
- packedBinding.pad = 0;
if (immutableSampler)
{
ASSERT(count == 1);
- packedBinding.immutableSampler = immutableSampler->getHandle();
+ ASSERT(bindingIndex < gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
+
+ mImmutableSamplers[bindingIndex] = immutableSampler->getHandle();
}
mValidDescriptorSetLayoutIndexMask.set(bindingIndex, count > 0);
}
-void DescriptorSetLayoutDesc::unpackBindings(DescriptorSetLayoutBindingVector *bindings,
- std::vector<VkSampler> *immutableSamplers) const
+void DescriptorSetLayoutDesc::unpackBindings(DescriptorSetLayoutBindingVector *bindings) const
{
for (size_t bindingIndex : mValidDescriptorSetLayoutIndexMask)
{
@@ -4334,28 +4342,15 @@ void DescriptorSetLayoutDesc::unpackBindings(DescriptorSetLayoutBindingVector *b
binding.descriptorCount = packedBinding.count;
binding.descriptorType = static_cast<VkDescriptorType>(packedBinding.type);
binding.stageFlags = static_cast<VkShaderStageFlags>(packedBinding.stages);
- if (packedBinding.immutableSampler != VK_NULL_HANDLE)
+ if (mImmutableSamplers[bindingIndex] != VK_NULL_HANDLE)
{
ASSERT(packedBinding.count == 1);
- immutableSamplers->push_back(packedBinding.immutableSampler);
- binding.pImmutableSamplers = reinterpret_cast<const VkSampler *>(angle::DirtyPointer);
+ ASSERT(bindingIndex < gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
+ binding.pImmutableSamplers = &mImmutableSamplers[bindingIndex];
}
bindings->push_back(binding);
}
- if (!immutableSamplers->empty())
- {
- // Patch up pImmutableSampler addresses now that the vector is stable
- int immutableIndex = 0;
- for (VkDescriptorSetLayoutBinding &binding : *bindings)
- {
- if (binding.pImmutableSamplers)
- {
- binding.pImmutableSamplers = &(*immutableSamplers)[immutableIndex];
- immutableIndex++;
- }
- }
- }
}
// PipelineLayoutDesc implementation.
@@ -7476,8 +7471,7 @@ angle::Result DescriptorSetLayoutCache::getDescriptorSetLayout(
mCacheStats.missAndIncrementSize();
// We must unpack the descriptor set layout description.
vk::DescriptorSetLayoutBindingVector bindingVector;
- std::vector<VkSampler> immutableSamplers;
- desc.unpackBindings(&bindingVector, &immutableSamplers);
+ desc.unpackBindings(&bindingVector);
VkDescriptorSetLayoutCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
diff --git a/src/libANGLE/renderer/vulkan/vk_cache_utils.h b/src/libANGLE/renderer/vulkan/vk_cache_utils.h
index 8ca6de50e6..4db163d9de 100644
--- a/src/libANGLE/renderer/vulkan/vk_cache_utils.h
+++ b/src/libANGLE/renderer/vulkan/vk_cache_utils.h
@@ -1016,8 +1016,7 @@ class DescriptorSetLayoutDesc final
VkShaderStageFlags stages,
const Sampler *immutableSampler);
- void unpackBindings(DescriptorSetLayoutBindingVector *bindings,
- std::vector<VkSampler> *immutableSamplers) const;
+ void unpackBindings(DescriptorSetLayoutBindingVector *bindings) const;
bool empty() const { return !mValidDescriptorSetLayoutIndexMask.any(); }
@@ -1030,16 +1029,15 @@ class DescriptorSetLayoutDesc final
uint8_t type; // Stores a packed VkDescriptorType descriptorType.
uint8_t stages; // Stores a packed VkShaderStageFlags.
uint16_t count; // Stores a packed uint32_t descriptorCount.
- uint32_t pad;
- VkSampler immutableSampler;
};
- // 4x 32bit
- static_assert(sizeof(PackedDescriptorSetBinding) == 16, "Unexpected size");
+ // 1x 32bit
+ static_assert(sizeof(PackedDescriptorSetBinding) == 4, "Unexpected size");
// This is a compact representation of a descriptor set layout.
std::array<PackedDescriptorSetBinding, kMaxDescriptorSetLayoutBindings>
mPackedDescriptorSetLayout;
+ gl::ActiveTextureArray<VkSampler> mImmutableSamplers;
DescriptorSetLayoutIndexMask mValidDescriptorSetLayoutIndexMask;
};
diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.cpp b/src/libANGLE/renderer/vulkan/vk_helpers.cpp
index 0ccbd0b11c..cb33abe6ae 100644
--- a/src/libANGLE/renderer/vulkan/vk_helpers.cpp
+++ b/src/libANGLE/renderer/vulkan/vk_helpers.cpp
@@ -1035,9 +1035,7 @@ angle::Result InitDynamicDescriptorPool(Context *context,
{
std::vector<VkDescriptorPoolSize> descriptorPoolSizes;
DescriptorSetLayoutBindingVector bindingVector;
- std::vector<VkSampler> immutableSamplers;
-
- descriptorSetLayoutDesc.unpackBindings(&bindingVector, &immutableSamplers);
+ descriptorSetLayoutDesc.unpackBindings(&bindingVector);
for (const VkDescriptorSetLayoutBinding &binding : bindingVector)
{