Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
6218164
Adding the begin frame message for later xtrace post processing.
phoenixxxx Jun 4, 2024
e265850
Merge branch 'main' into main
phoenixxxx Jun 4, 2024
8671617
Merge branch 'main' into main
poweifeng Jun 5, 2024
d49554d
Merge branch 'main' into main
poweifeng Jun 5, 2024
4fccd95
Merge branch 'google:main' into main
phoenixxxx Jun 11, 2024
96cba96
Merge branch 'google:main' into main
phoenixxxx Jun 18, 2024
abe8a49
Merge branch 'google:main' into main
phoenixxxx Jun 27, 2024
c81cedd
Merge branch 'google:main' into main
phoenixxxx Sep 4, 2024
387942c
Merge branch 'google:main' into main
phoenixxxx Sep 21, 2024
0fdf1ca
Merge branch 'google:main' into main
phoenixxxx Oct 3, 2024
8bc4d3a
Merge branch 'google:main' into main
phoenixxxx Oct 9, 2024
9e92193
Merge branch 'google:main' into main
phoenixxxx Oct 18, 2024
01a2480
Merge branch 'google:main' into main
phoenixxxx Oct 26, 2024
48bb10a
Merge branch 'google:main' into main
phoenixxxx Oct 30, 2024
ff145f6
Merge branch 'google:main' into main
phoenixxxx Oct 31, 2024
c5c2d42
Merge branch 'google:main' into main
phoenixxxx Nov 5, 2024
3b0e44c
Merge branch 'google:main' into main
phoenixxxx Nov 5, 2024
80803f9
Merge branch 'google:main' into main
phoenixxxx Nov 6, 2024
ad3a5b7
Merge branch 'google:main' into main
phoenixxxx Dec 3, 2024
be6b6ae
Merge branch 'google:main' into main
phoenixxxx Dec 19, 2024
021c4f6
Merge branch 'google:main' into main
phoenixxxx Jan 13, 2025
0a661c1
Merge branch 'google:main' into main
phoenixxxx Jan 27, 2025
ea4c20e
Merge branch 'google:main' into main
phoenixxxx Jan 30, 2025
ba99844
Merge branch 'google:main' into main
phoenixxxx Mar 6, 2025
cfe6a42
Merge branch 'google:main' into main
phoenixxxx Mar 6, 2025
7f7dadd
Merge branch 'google:main' into main
phoenixxxx Mar 14, 2025
b570d48
Merge branch 'google:main' into main
phoenixxxx Mar 17, 2025
b09cbaf
Merge branch 'google:main' into main
phoenixxxx Mar 18, 2025
13e1d2a
Merge branch 'google:main' into main
phoenixxxx Mar 21, 2025
ff2827b
Merge branch 'google:main' into main
phoenixxxx Mar 28, 2025
55fc91b
Merge branch 'google:main' into main
phoenixxxx May 8, 2025
bcae04c
Merge branch 'google:main' into main
phoenixxxx May 12, 2025
2fac13e
Merge branch 'google:main' into main
phoenixxxx Aug 1, 2025
d45a265
First commit
phoenixxxx Aug 5, 2025
c00afac
This is not needed
phoenixxxx Aug 6, 2025
84fc69e
Bypass the AHB* issue.
phoenixxxx Aug 6, 2025
1b4f88b
Typo: Forgot to remove the function.
phoenixxxx Aug 6, 2025
839867e
Typo: No const specifier.
phoenixxxx Aug 6, 2025
397282a
Removing the const.
phoenixxxx Aug 6, 2025
75fdacb
no exception
phoenixxxx Aug 6, 2025
111ac62
Merge branch 'google:main' into main
phoenixxxx Aug 7, 2025
19cbb94
Merge branch 'main' into streamed_texture
phoenixxxx Aug 7, 2025
c612bfd
Feedback from discussions with Powei.
phoenixxxx Aug 11, 2025
3c93f00
Making the changes discussed with the team.
phoenixxxx Aug 12, 2025
487fb27
Merge branch 'google:main' into main
phoenixxxx Aug 12, 2025
fbf2f0d
Merge branch 'main' into streamed_texture
phoenixxxx Aug 12, 2025
8b6fa40
Removing useless comments.
phoenixxxx Aug 12, 2025
f548c58
Merge branch 'google:main' into main
phoenixxxx Aug 13, 2025
bee08b4
Merge branch 'main' into streamed_texture
phoenixxxx Aug 13, 2025
76fc21a
Adding the required methods for allocation.
phoenixxxx Aug 14, 2025
5858acf
Forgot one more switch case.
phoenixxxx Aug 14, 2025
e441cbb
Moving the resource to –fvkmemory::Resource type.
phoenixxxx Aug 15, 2025
5a0f78d
Merge branch 'google:main' into main
phoenixxxx Aug 18, 2025
865cb0a
Adding streamed set.
phoenixxxx Aug 18, 2025
a220f70
Merge branch 'main' into streamed_texture
phoenixxxx Aug 18, 2025
c6d0127
Allocating every frame for streamed textures.
phoenixxxx Aug 19, 2025
8017d5e
Changing the binding logic.
phoenixxxx Aug 20, 2025
ad57838
Proper checks for the streamed texture.
phoenixxxx Aug 25, 2025
0210611
Merge branch 'google:main' into main
phoenixxxx Aug 25, 2025
1e5d37a
Merge branch 'main' into streamed_texture
phoenixxxx Aug 25, 2025
29e3f07
Cleanup.
phoenixxxx Aug 25, 2025
406a348
Chaning the logic of the state tracking for streamed textures.
phoenixxxx Aug 28, 2025
3a1aebe
Fixed full screen bug.
phoenixxxx Aug 28, 2025
0c07c3f
Refactoring of the code.
phoenixxxx Aug 29, 2025
f503205
Merge branch 'google:main' into main
phoenixxxx Aug 29, 2025
6e8959e
Merge branch 'main' into streamed_texture
phoenixxxx Aug 29, 2025
39be20b
Typo.
phoenixxxx Aug 29, 2025
db83dc0
GitHub feedback.
phoenixxxx Sep 4, 2025
54c636d
Merge branch 'google:main' into main
phoenixxxx Sep 4, 2025
562eeed
Merge branch 'main' into streamed_texture
phoenixxxx Sep 4, 2025
74ffe4e
Github feedback
phoenixxxx Sep 5, 2025
32ca1d3
feedback.
phoenixxxx Sep 5, 2025
3457700
Typo
phoenixxxx Sep 5, 2025
85c899a
Feedback.
phoenixxxx Sep 9, 2025
0ba9c2a
Feedback.
phoenixxxx Sep 9, 2025
78d5e34
Feedback
phoenixxxx Sep 11, 2025
1216024
Feedback
phoenixxxx Sep 12, 2025
e022396
Feedback
phoenixxxx Sep 15, 2025
48cd99a
Fixing the Android path.
phoenixxxx Sep 18, 2025
83a89b5
Fixing the Android path.
phoenixxxx Sep 18, 2025
1a390f4
Feedback.
phoenixxxx Sep 19, 2025
c9b3104
Merge branch 'google:main' into main
phoenixxxx Sep 19, 2025
0a11d0c
Merge branch 'main' into streamed_texture
phoenixxxx Sep 19, 2025
86f0afe
feedback
phoenixxxx Sep 19, 2025
44b506b
Feedback.
phoenixxxx Sep 22, 2025
df284fe
Nit
phoenixxxx Sep 22, 2025
f96afef
Feedback
phoenixxxx Sep 23, 2025
e4f29b0
Feedback
phoenixxxx Sep 24, 2025
56831e2
Feedback
phoenixxxx Sep 25, 2025
77b9913
vk: fix update after bind (wrt descriptor set) validation error
poweifeng Sep 26, 2025
71175ee
Merge branch 'google:main' into main
phoenixxxx Oct 13, 2025
6696170
Merge branch 'main' into streamed_texture
phoenixxxx Oct 13, 2025
65f78c0
Merge branch 'google:main' into main
phoenixxxx Oct 21, 2025
dac6585
Merge branch 'main' into pf/vk-ext-img-fix-ref
phoenixxxx Oct 21, 2025
2791195
Merge branch 'google:main' into main
phoenixxxx Oct 22, 2025
3cd6593
Merge branch 'main' into streamed_texture
phoenixxxx Oct 22, 2025
90739b1
Merge branch 'pf/vk-ext-img-fix-ref' into streamed_texture
phoenixxxx Oct 22, 2025
ffd6e28
Removing the decision on whether to use external format or not out of…
phoenixxxx Oct 29, 2025
49f9708
Merge branch 'google:main' into main
phoenixxxx Oct 29, 2025
4e05cd7
Merge branch 'google:main' into main
phoenixxxx Nov 4, 2025
44a85a6
Merge branch 'main' into streamed_texture
phoenixxxx Nov 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions filament/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ if (FILAMENT_SUPPORTS_VULKAN)
src/vulkan/VulkanDriverFactory.h
src/vulkan/VulkanExternalImageManager.cpp
src/vulkan/VulkanExternalImageManager.h
src/vulkan/VulkanStreamedImageManager.cpp
src/vulkan/VulkanStreamedImageManager.h
src/vulkan/VulkanFboCache.cpp
src/vulkan/VulkanFboCache.h
src/vulkan/VulkanHandles.cpp
Expand Down
3 changes: 3 additions & 0 deletions filament/backend/include/backend/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class UTILS_PUBLIC Platform {
ExternalImageHandle& operator=(ExternalImageHandle const& rhs) noexcept;
ExternalImageHandle& operator=(ExternalImageHandle&& rhs) noexcept;

bool operator==(const ExternalImageHandle& rhs) const noexcept {
return mTarget == rhs.mTarget;
}
explicit operator bool() const noexcept { return mTarget != nullptr; }

ExternalImage* UTILS_NULLABLE get() noexcept { return mTarget; }
Expand Down
87 changes: 63 additions & 24 deletions filament/backend/src/vulkan/VulkanDescriptorSetCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "VulkanCommands.h"
#include "VulkanHandles.h"
#include "VulkanConstants.h"
#include "utils/compiler.h"

#include <utils/FixedCapacityVector.h>
#include <utils/Panic.h>
Expand All @@ -31,6 +32,18 @@ namespace filament::backend {

namespace {

using Bitmask = fvkutils::UniformBufferBitmask;
static_assert(sizeof(Bitmask) * 8 == fvkutils::MAX_DESCRIPTOR_SET_BITMASK_BITS);

Bitmask foldBitsInHalf(Bitmask bitset) {
Bitmask outBitset;
bitset.forEachSetBit([&](size_t index) {
constexpr size_t BITMASK_LOWER_BITS_LEN = sizeof(outBitset) * 4;
outBitset.set(index % BITMASK_LOWER_BITS_LEN);
});
return outBitset;
}

using DescriptorSetLayoutArray = VulkanDescriptorSetCache::DescriptorSetLayoutArray;
using DescriptorCount = VulkanDescriptorSetCache::DescriptorCount;

Expand Down Expand Up @@ -304,8 +317,7 @@ void VulkanDescriptorSetCache::commit(VulkanCommandBuffer* commands,
// This code actually binds the descriptor sets.
auto set = updateSets[index];
VkCommandBuffer const cmdbuffer = commands->buffer();
VkDescriptorSet vkset = useExternalSamplers[index] ? set->getExternalSamplerVkSet() :
set->getVkSet();
VkDescriptorSet const vkset = set->getVkSet();
commands->acquire(set);
vkCmdBindDescriptorSets(cmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, index,
1, &vkset, set->uniqueDynamicUboCount, set->getOffsets()->data());
Expand Down Expand Up @@ -341,17 +353,39 @@ void VulkanDescriptorSetCache::updateBuffer(fvkmemory::resource_ptr<VulkanDescri
.pBufferInfo = &info,
};
vkUpdateDescriptorSets(mDevice, 1, &descriptorWrite, 0, nullptr);

if (auto externalSamplerSet = set->getExternalSamplerVkSet();
externalSamplerSet != VK_NULL_HANDLE) {
descriptorWrite.dstSet = externalSamplerSet;
vkUpdateDescriptorSets(mDevice, 1, &descriptorWrite, 0, nullptr);
}
set->acquire(bufferObject);
}

void VulkanDescriptorSetCache::updateSamplerImpl(VkDescriptorSet vkset, uint8_t binding,
fvkmemory::resource_ptr<VulkanTexture> texture, VkSampler sampler) noexcept {
void VulkanDescriptorSetCache::updateSampler(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
uint8_t binding, fvkmemory::resource_ptr<VulkanTexture> texture,
VkSampler sampler, VkDescriptorSetLayout externalSamplerLayout) noexcept {

// We have to update a bound set for two use cases
// - streaming API (a changing feed of AHardwareBuffer)
// - external samplers - potential changing of dataspace per-frame
if (UTILS_UNLIKELY(set->isBound())) {
auto layout = set->getLayout();
// Build a new descriptor set from the new layout
auto genLayout = externalSamplerLayout != VK_NULL_HANDLE ?
externalSamplerLayout : layout->getVkLayout();
VkDescriptorSet const newSet = getVkSet(layout->count, genLayout);
Bitmask const ubo = layout->bitmask.ubo | layout->bitmask.dynamicUbo;
Bitmask samplers = layout->bitmask.sampler;
samplers.unset(binding);

// Each bitmask denotes a binding index, and separated into two stages - vertex and buffer
// We fold the two stages into just the lower half of the bits to denote a combined set of
// bindings.
Bitmask const copyBindings = foldBitsInHalf(ubo | samplers);
VkDescriptorSet const srcSet = set->getVkSet();
copySet(srcSet, newSet, copyBindings);
set->addNewSet(newSet,
[this, layoutCount = layout->count, genLayout, newSet](VulkanDescriptorSet*) {
this->manualRecycle(layoutCount, genLayout, newSet);
});
}

VkDescriptorSet const vkset = set->getVkSet();
VkImageSubresourceRange range = texture->getPrimaryViewRange();
VkImageViewType const expectedType = texture->getViewType();
if (any(texture->usage & TextureUsage::DEPTH_ATTACHMENT) &&
Expand All @@ -376,19 +410,6 @@ void VulkanDescriptorSetCache::updateSamplerImpl(VkDescriptorSet vkset, uint8_t
.pImageInfo = &info,
};
vkUpdateDescriptorSets(mDevice, 1, &descriptorWrite, 0, nullptr);
}

void VulkanDescriptorSetCache::updateSampler(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
uint8_t binding, fvkmemory::resource_ptr<VulkanTexture> texture,
VkSampler sampler) noexcept {
updateSamplerImpl(set->getVkSet(), binding, texture, sampler);
set->acquire(texture);
}

void VulkanDescriptorSetCache::updateSamplerForExternalSamplerSet(
fvkmemory::resource_ptr<VulkanDescriptorSet> set, uint8_t binding,
fvkmemory::resource_ptr<VulkanTexture> texture) noexcept {
updateSamplerImpl(set->getExternalSamplerVkSet(), binding, texture, VK_NULL_HANDLE);
set->acquire(texture);
}

Expand All @@ -405,7 +426,7 @@ fvkmemory::resource_ptr<VulkanDescriptorSet> VulkanDescriptorSetCache::createSet
auto const& count = layout->count;
auto const vklayout = layout->getVkLayout();
auto set = fvkmemory::resource_ptr<VulkanDescriptorSet>::make(
mResourceManager, handle, layout->bitmask.dynamicUbo, layout->count.dynamicUbo,
mResourceManager, handle, layout,
[vkSet, count, vklayout, this](
VulkanDescriptorSet*) { this->manualRecycle(count, vklayout, vkSet); },
vkSet);
Expand All @@ -428,4 +449,22 @@ void VulkanDescriptorSetCache::manualRecycle(VulkanDescriptorSetLayout::Count co

void VulkanDescriptorSetCache::gc() { mStashedSets = {}; }

void VulkanDescriptorSetCache::copySet(VkDescriptorSet srcSet, VkDescriptorSet dstSet,
fvkutils::SamplerBitmask bindings) const {
// TODO: fix the size for better memory management
std::vector<VkCopyDescriptorSet> copies;
bindings.forEachSetBit([&](size_t index) {
copies.push_back({
.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET,
.srcSet = srcSet,
.srcBinding = (uint32_t) index,
.dstSet = dstSet,
.dstBinding = (uint32_t) index,
.descriptorCount = 1,
});
});
vkUpdateDescriptorSets(mDevice, 0, nullptr, copies.size(), copies.data());
}


} // namespace filament::backend
7 changes: 4 additions & 3 deletions filament/backend/src/vulkan/VulkanDescriptorSetCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class VulkanDescriptorSetCache {
VkDeviceSize size) noexcept;

void updateSampler(fvkmemory::resource_ptr<VulkanDescriptorSet> set, uint8_t binding,
fvkmemory::resource_ptr<VulkanTexture> texture, VkSampler sampler) noexcept;
fvkmemory::resource_ptr<VulkanTexture> texture, VkSampler sampler,
VkDescriptorSetLayout externalSamplerLayout = VK_NULL_HANDLE) noexcept;

void updateSamplerForExternalSamplerSet(fvkmemory::resource_ptr<VulkanDescriptorSet> set, uint8_t binding,
fvkmemory::resource_ptr<VulkanTexture> texture) noexcept;
Expand Down Expand Up @@ -90,8 +91,8 @@ class VulkanDescriptorSetCache {
void resetCachedState() noexcept { mLastBoundInfo = {}; }

private:
void updateSamplerImpl(VkDescriptorSet set, uint8_t binding,
fvkmemory::resource_ptr<VulkanTexture> texture, VkSampler sampler) noexcept;
void copySet(VkDescriptorSet srcSet, VkDescriptorSet destSet,
fvkutils::SamplerBitmask copyBindings) const;

class DescriptorInfinitePool;

Expand Down
Loading
Loading