Skip to content

Commit

Permalink
Vulkan: Smaller PackedDescriptorSetBinding
Browse files Browse the repository at this point in the history
Bug: angleproject:8677
Change-Id: Id7bcef8de129514446384a019b6cce95da13b028
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5522755
Auto-Submit: Shahbaz Youssefi <[email protected]>
Reviewed-by: Charlie Lao <[email protected]>
Reviewed-by: mohan maiya <[email protected]>
Commit-Queue: Charlie Lao <[email protected]>
  • Loading branch information
ShabbyX authored and Angle LUCI CQ committed Jun 17, 2024
1 parent cdc541d commit d074491
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
37 changes: 26 additions & 11 deletions src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4258,7 +4258,7 @@ bool operator==(const AttachmentOpsArray &lhs, const AttachmentOpsArray &rhs)

// DescriptorSetLayoutDesc implementation.
DescriptorSetLayoutDesc::DescriptorSetLayoutDesc()
: mDescriptorSetLayoutBindings{}, mImmutableSamplers{}
: mImmutableSamplers{}, mDescriptorSetLayoutBindings{}
{}

DescriptorSetLayoutDesc::~DescriptorSetLayoutDesc() = default;
Expand Down Expand Up @@ -4308,42 +4308,57 @@ void DescriptorSetLayoutDesc::update(uint32_t bindingIndex,
ASSERT(count < std::numeric_limits<uint16_t>::max());
ASSERT(bindingIndex < std::numeric_limits<uint16_t>::max());

PackedDescriptorSetBinding packedBinding = {};
if (bindingIndex >= mDescriptorSetLayoutBindings.size())
{
PackedDescriptorSetBinding invalid = {};
invalid.type = PackedDescriptorSetBinding::kInvalidType;
mDescriptorSetLayoutBindings.resize(bindingIndex + 1, invalid);
}

PackedDescriptorSetBinding &packedBinding = mDescriptorSetLayoutBindings[bindingIndex];
SetBitField(packedBinding.type, descriptorType);
SetBitField(packedBinding.count, count);
SetBitField(packedBinding.stages, stages);
SetBitField(packedBinding.bindingIndex, bindingIndex);
SetBitField(packedBinding.hasImmutableSampler, 0);

if (immutableSampler)
{
if (bindingIndex >= mImmutableSamplers.size())
{
mImmutableSamplers.resize(bindingIndex + 1);
}

ASSERT(count == 1);
SetBitField(packedBinding.hasImmutableSampler, 1);
mImmutableSamplers.push_back(immutableSampler->getHandle());
mImmutableSamplers[bindingIndex] = immutableSampler->getHandle();
}

mDescriptorSetLayoutBindings.push_back(std::move(packedBinding));
}

void DescriptorSetLayoutDesc::unpackBindings(DescriptorSetLayoutBindingVector *bindings) const
{
size_t immutableSamplersIndex = 0;

// Unpack all valid descriptor set layout bindings
for (const PackedDescriptorSetBinding &packedBinding : mDescriptorSetLayoutBindings)
for (size_t bindingIndex = 0; bindingIndex < mDescriptorSetLayoutBindings.size();
++bindingIndex)
{
const PackedDescriptorSetBinding &packedBinding =
mDescriptorSetLayoutBindings[bindingIndex];
if (packedBinding.type == PackedDescriptorSetBinding::kInvalidType)
{
continue;
}

ASSERT(packedBinding.count != 0);

VkDescriptorSetLayoutBinding binding = {};
binding.binding = static_cast<uint32_t>(packedBinding.bindingIndex);
binding.binding = static_cast<uint32_t>(bindingIndex);
binding.descriptorCount = packedBinding.count;
binding.descriptorType = static_cast<VkDescriptorType>(packedBinding.type);
binding.stageFlags = static_cast<VkShaderStageFlags>(packedBinding.stages);

if (packedBinding.hasImmutableSampler)
{
ASSERT(packedBinding.count == 1);
binding.pImmutableSamplers = &mImmutableSamplers[immutableSamplersIndex++];
binding.pImmutableSamplers = &mImmutableSamplers[bindingIndex];
}

bindings->push_back(binding);
Expand Down
23 changes: 14 additions & 9 deletions src/libANGLE/renderer/vulkan/vk_cache_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,28 +1021,33 @@ class DescriptorSetLayoutDesc final
// TODO: https://issuetracker.google.com/issues/159156775: Have immutable sampler use serial
union PackedDescriptorSetBinding
{
static constexpr uint8_t kInvalidType = 255;

struct
{
uint8_t type; // Stores a packed VkDescriptorType descriptorType.
uint8_t stages; // Stores a packed VkShaderStageFlags.
uint16_t count; // Stores a packed uint32_t descriptorCount
uint16_t bindingIndex; // Stores the binding index
uint16_t hasImmutableSampler; // Whether this binding has an immutable sampler
uint8_t type; // Stores a packed VkDescriptorType descriptorType.
uint8_t stages; // Stores a packed VkShaderStageFlags.
uint16_t count : 15; // Stores a packed uint32_t descriptorCount
uint16_t hasImmutableSampler : 1; // Whether this binding has an immutable sampler
};
uint64_t value;
uint32_t value;

bool operator==(const PackedDescriptorSetBinding &other) const
{
return value == other.value;
}
};

// 1x 64bit
static_assert(sizeof(PackedDescriptorSetBinding) == 8, "Unexpected size");
// 1x 32bit
static_assert(sizeof(PackedDescriptorSetBinding) == 4, "Unexpected size");

angle::FastVector<VkSampler, kDefaultImmutableSamplerBindingsCount> mImmutableSamplers;
angle::FastVector<PackedDescriptorSetBinding, kDefaultDescriptorSetLayoutBindingsCount>
mDescriptorSetLayoutBindings;
angle::FastVector<VkSampler, kDefaultImmutableSamplerBindingsCount> mImmutableSamplers;

#if !defined(ANGLE_IS_64_BIT_CPU)
ANGLE_MAYBE_UNUSED_PRIVATE_FIELD uint32_t mPadding = 0;
#endif
};

// The following are for caching descriptor set layouts. Limited to max three descriptor set
Expand Down

0 comments on commit d074491

Please sign in to comment.