Skip to content
Open
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
89 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
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 @@ -199,6 +199,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 @@ -66,6 +66,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
3 changes: 3 additions & 0 deletions filament/backend/include/backend/platforms/VulkanPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatf
virtual ImageData createVkImageFromExternal(ExternalImageHandleRef image) const {
return {};
}
virtual ExternalImageHandle createExternalImageFromRaw(void* image, bool sRGB) noexcept {
return {};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • all virtuals in this file should not be implemented in the header file
  • all need documentation, as this is the public API.


protected:
virtual ExtensionSet getSwapchainInstanceExtensions() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class VulkanPlatformAndroid : public VulkanPlatform {
public:
ExternalImageHandle UTILS_PUBLIC createExternalImage(AHardwareBuffer const* buffer,
bool sRGB) noexcept;
virtual ExternalImageHandle createExternalImageFromRaw(void* image,
bool sRGB) noexcept override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just combine these methods into one called createExternalImage(void* image, bool sRGB)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this issue is that Mathias didn't want to do that.
The whole concept of ExternalImageHandleRef exists to avoid using raw pointer. Something that the Stream API totally breaks, it relies (on the GL and VK sides) on void*.

Second issue is we did a ton of changes on the Impress side to create, and send ExternalImageHandleRef (works for all external image types) so undoing this would need many Impress side changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even understand what the void* is here? This needs to be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that's because in the stream case, we call createExternalImageFromRaw insinde the driver when we process the pending stream. And inside VulkanDriver.cpp we don't know what the platform is, so we can't assume createExternalImage(AHardwareBuffer const*)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see why you need to do this. This is because AcquiredImage has a void*. I think this is okay for now (for the sake of getting this done). But really, we should change the Acquired Stream API to only speak in terms of ExternalImageRef.

HOWEVER, I think this means that createExternalImageFromRaw() must not be public. It must be protected. And the concrete implementations must be private. This is needed only for internal machinery.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I am ok with that. Frankly, I think I agree, the stream taking void* isn't the right call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I not make this public?


struct UTILS_PUBLIC ExternalImageDescAndroid {
uint32_t width; // Texture width
Expand Down
96 changes: 93 additions & 3 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext& context,
mQueryManager(mPlatform->getDevice()),
mExternalImageManager(platform, &mSamplerCache, &mYcbcrConversionCache, &mDescriptorSetCache,
&mDescriptorSetLayoutCache),
mStreamedImageManager(&mExternalImageManager, &mDescriptorSetCache, &mSamplerCache),
mIsSRGBSwapChainSupported(mPlatform->getCustomization().isSRGBSwapChainSupported),
mStereoscopicType(driverConfig.stereoscopicType) {

Expand Down Expand Up @@ -455,13 +456,18 @@ void VulkanDriver::updateDescriptorSetTexture(
if (UTILS_UNLIKELY(mExternalImageManager.isExternallySampledTexture(texture))) {
mExternalImageManager.bindExternallySampledTexture(set, binding, texture, params);
mAppState.hasBoundExternalImages = true;
} else {
} else if (bool(texture->getStream())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can a texture be external sampled and streamed at the same time? or are they mutually exclusive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically yes. But that would mean that a texture that is external was attached to a stream. And that seems like something went wrong, because from the frontend's perspective you can create a texture one of 3 ways:

    1. From a format
    1. From an external image
    1. By setting a stream
      Although you could logically do 2) and then set a stream via 3, I question the meaning of that.

mStreamedImageManager.bindStreamedTexture(set, binding, texture, params);
mAppState.hasBoundExternalImages = true;
}
else {
VulkanSamplerCache::Params cacheParams = {
.sampler = params,
};
VkSampler const vksampler = mSamplerCache.getSampler(cacheParams);
mDescriptorSetCache.updateSampler(set, binding, texture, vksampler);
mExternalImageManager.clearTextureBinding(set, binding);
mStreamedImageManager.unbindStreamedTexture(set, binding);
}
}

Expand Down Expand Up @@ -965,6 +971,11 @@ void VulkanDriver::destroySwapChain(Handle<HwSwapChain> sch) {
}

void VulkanDriver::destroyStream(Handle<HwStream> sh) {
if (!sh) {
return;
}
auto stream = resource_ptr<VulkanStream>::cast(&mResourceManager, sh);
stream.dec();
}

void VulkanDriver::destroyTimerQuery(Handle<HwTimerQuery> tqh) {
Expand All @@ -991,25 +1002,99 @@ void VulkanDriver::destroyDescriptorSet(Handle<HwDescriptorSet> dsh) {
}

Handle<HwStream> VulkanDriver::createStreamNative(void* nativeStream) {
return {};
auto handle = mResourceManager.allocHandle<VulkanStream>();
auto stream = resource_ptr<VulkanStream>::make(&mResourceManager, handle);
stream.inc();
return handle;
}

Handle<HwStream> VulkanDriver::createStreamAcquired() {
return {};
auto handle = mResourceManager.allocHandle<VulkanStream>();
auto stream = resource_ptr<VulkanStream>::make(&mResourceManager, handle);
stream.inc();
return handle;
}

void VulkanDriver::setAcquiredImage(Handle<HwStream> sh, void* image, const math::mat3f& transform,
CallbackHandler* handler, StreamCallback cb, void* userData) {
FVK_SYSTRACE_SCOPE();
auto stream = resource_ptr<VulkanStream>::cast(&mResourceManager, sh);
stream->acquire({ image, cb, userData, handler });
mStreamsWithPendingAcquiredImage.push_back(stream);
}

void VulkanDriver::setStreamDimensions(Handle<HwStream> sh, uint32_t width, uint32_t height) {
auto stream = resource_ptr<VulkanStream>::cast(&mResourceManager, sh);
stream->width = width;
stream->height = height;
}

int64_t VulkanDriver::getStreamTimestamp(Handle<HwStream> sh) {
return 0;
}

void VulkanDriver::updateStreams(CommandStream* driver) {
if (UTILS_UNLIKELY(!mStreamsWithPendingAcquiredImage.empty())) {
for (auto& stream: mStreamsWithPendingAcquiredImage) {
if (stream->previousNeedsRelease()) {
scheduleRelease(stream->takePrevious());
}

auto texture = stream->getTexture(stream->getAcquired().image);
bool newImage = false;
if (!texture) {
auto externalImage =
mPlatform->createExternalImageFromRaw(stream->getAcquired().image, false);
auto metadata = mPlatform->extractExternalImageMetadata(externalImage);
auto imgData = mPlatform->createVkImageFromExternal(externalImage);

assert_invariant(imgData.internal.valid() || imgData.external.valid());

VkFormat vkformat = metadata.format;
VkImage vkimage = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE;
if (imgData.internal.valid()) {
metadata.externalFormat = 0;
vkimage = imgData.internal.image;
memory = imgData.internal.memory;
} else {
vkformat = VK_FORMAT_UNDEFINED;
vkimage = imgData.external.image;
memory = imgData.external.memory;
}

VkSamplerYcbcrConversion const conversion =
mExternalImageManager.getVkSamplerYcbcrConversion(metadata);

auto newTexture = resource_ptr<VulkanTexture>::construct(&mResourceManager, mContext,
mPlatform->getDevice(), mAllocator, &mResourceManager, &mCommands, vkimage,
memory, vkformat, conversion, metadata.samples, metadata.width,
metadata.height, metadata.layers, metadata.filamentUsage, mStagePool);

// We shouldn't need to do this when we allocate the texture
if (true) {
auto& commands = mCommands.get();
// Unlike uploaded textures or swapchains, we need to explicit transition this
// texture into the read layout.
newTexture->transitionLayout(&commands, newTexture->getPrimaryViewRange(),
VulkanLayout::FRAG_READ);
}

if (imgData.external.valid()) {
mExternalImageManager.addExternallySampledTexture(newTexture, externalImage);
// Cache the AHB backed image.
stream->pushImage(stream->getAcquired().image, newTexture);
newImage = true;
}

newTexture.inc();
texture = newTexture;
}

mStreamedImageManager.onStreamAcquireImage(texture, stream, newImage);
}
mStreamsWithPendingAcquiredImage.clear();
}
}

void VulkanDriver::destroyFence(Handle<HwFence> fh) {
Expand Down Expand Up @@ -1331,6 +1416,11 @@ TimerQueryResult VulkanDriver::getTimerQueryValue(Handle<HwTimerQuery> tqh, uint
}

void VulkanDriver::setExternalStream(Handle<HwTexture> th, Handle<HwStream> sh) {
auto t = resource_ptr<VulkanTexture>::cast(&mResourceManager, th);
assert_invariant(t);
auto s = resource_ptr<VulkanStream>::cast(&mResourceManager, sh);
assert_invariant(s);
t->setStream(s);
}

void VulkanDriver::generateMipmaps(Handle<HwTexture> th) {
Expand Down
6 changes: 6 additions & 0 deletions filament/backend/src/vulkan/VulkanDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "vulkan/VulkanDescriptorSetCache.h"
#include "vulkan/VulkanDescriptorSetLayoutCache.h"
#include "vulkan/VulkanExternalImageManager.h"
#include "vulkan/VulkanStreamedImageManager.h"
#include "vulkan/VulkanPipelineLayoutCache.h"
#include "vulkan/memory/ResourceManager.h"
#include "vulkan/memory/ResourcePointer.h"
Expand Down Expand Up @@ -153,6 +154,7 @@ class VulkanDriver final : public DriverBase {
VulkanDescriptorSetCache mDescriptorSetCache;
VulkanQueryManager mQueryManager;
VulkanExternalImageManager mExternalImageManager;
VulkanStreamedImageManager mStreamedImageManager;

// This is necessary for us to write to push constants after binding a pipeline.
using DescriptorSetLayoutHandleList = std::array<resource_ptr<VulkanDescriptorSetLayout>,
Expand Down Expand Up @@ -188,6 +190,10 @@ class VulkanDriver final : public DriverBase {

bool const mIsSRGBSwapChainSupported;
backend::StereoscopicType const mStereoscopicType;

// setAcquiredImage is a DECL_DRIVER_API_SYNCHRONOUS_N which means we don't necessarily have the
// data to process it at call time. So we store it and process it during updateStreams.
std::vector<resource_ptr<VulkanStream>> mStreamsWithPendingAcquiredImage;
};

} // namespace filament::backend
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/vulkan/VulkanExternalImageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VulkanSamplerCache;
class VulkanDescriptorSetLayoutCache;
class VulkanDescriptorSetCache;

// Manages the logic of external images and their quirks wrt Vulikan.
// Manages the logic of external images and their quirks wrt Vulkan.
class VulkanExternalImageManager {
public:

Expand Down
83 changes: 83 additions & 0 deletions filament/backend/src/vulkan/VulkanStreamedImageManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "VulkanStreamedImageManager.h"

#include "VulkanDescriptorSetCache.h"
#include "VulkanExternalImageManager.h"
#include "VulkanDescriptorSetLayoutCache.h"
#include "VulkanSamplerCache.h"

namespace filament::backend {
VulkanStreamedImageManager::VulkanStreamedImageManager(
VulkanExternalImageManager* manager,
VulkanDescriptorSetCache* descriptorSet,
VulkanSamplerCache* samplerCache)
: mExternalImageManager(manager),
mDescriptorSetCache(descriptorSet),
mSamplerCache(samplerCache) {

}

VulkanStreamedImageManager::~VulkanStreamedImageManager() = default;

void VulkanStreamedImageManager::terminate() {}

void VulkanStreamedImageManager::bindStreamedTexture(
fvkmemory::resource_ptr<VulkanDescriptorSet> set,
uint8_t bindingPoint, fvkmemory::resource_ptr<VulkanTexture> image,
SamplerParams samplerParams) {
mStreamedTexturesBindings.push_back({ bindingPoint, image, set, samplerParams });
}

void VulkanStreamedImageManager::unbindStreamedTexture(
fvkmemory::resource_ptr<VulkanDescriptorSet> set,
uint8_t bindingPoint) {
auto iter = std::remove_if(mStreamedTexturesBindings.begin(), mStreamedTexturesBindings.end(),
[&](streamedTextureBinding& binding) {
return ((binding.set == set) && (binding.binding == bindingPoint));
});
mStreamedTexturesBindings.erase(iter, mStreamedTexturesBindings.end());
}

void VulkanStreamedImageManager::onStreamAcquireImage(fvkmemory::resource_ptr<VulkanTexture> image,
fvkmemory::resource_ptr<VulkanStream> stream, bool newImage) {
for (streamedTextureBinding const& data: mStreamedTexturesBindings) {
if (data.image->getStream() == stream) {
if (newImage) {
mExternalImageManager->bindExternallySampledTexture(data.set, data.binding, image,
data.samplerParams);
} else {
// For some reason, some of the frames coming to us, are on streams where the
// descriptor set isn't external...
if (data.set->getExternalSamplerVkSet()) {
mDescriptorSetCache->updateSamplerForExternalSamplerSet(data.set, data.binding,
image);
} else {
//... In this case we just default to using the normal path and update the
//sampler.
VulkanSamplerCache::Params cacheParams = {
.sampler = data.samplerParams,
};
VkSampler const vksampler = mSamplerCache->getSampler(cacheParams);
mDescriptorSetCache->updateSampler(data.set, data.binding, image, vksampler);
}
}
}
}
}

} // namespace filament::backend
68 changes: 68 additions & 0 deletions filament/backend/src/vulkan/VulkanStreamedImageManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TNT_FILAMENT_BACKEND_CACHING_VULKANSTREAMEDIMAGEMANAGER_H
#define TNT_FILAMENT_BACKEND_CACHING_VULKANSTREAMEDIMAGEMANAGER_H

#include "VulkanHandles.h"

#include <backend/DriverEnums.h>

#include <array>
#include <vector>

namespace filament::backend {

class VulkanExternalImageManager;
class VulkanDescriptorSetCache;
class VulkanSamplerCache;

// Manages the logic of streamed and streamed images.
class VulkanStreamedImageManager {
public:
VulkanStreamedImageManager(
VulkanExternalImageManager* manager,
VulkanDescriptorSetCache* descriptorSet,
VulkanSamplerCache* samplerCache);
~VulkanStreamedImageManager();
void terminate();

public:
void bindStreamedTexture(fvkmemory::resource_ptr<VulkanDescriptorSet> set, uint8_t bindingPoint,
fvkmemory::resource_ptr<VulkanTexture> image, SamplerParams samplerParams);
void unbindStreamedTexture(fvkmemory::resource_ptr<VulkanDescriptorSet> set,
uint8_t bindingPoint);
void onStreamAcquireImage(fvkmemory::resource_ptr<VulkanTexture> image,
fvkmemory::resource_ptr<VulkanStream> stream, bool newImage);

private:
struct streamedTextureBinding {
uint8_t binding = 0;
fvkmemory::resource_ptr<VulkanTexture> image;
fvkmemory::resource_ptr<VulkanDescriptorSet> set;
SamplerParams samplerParams;
};
// keep track of all the stream bindings
std::vector<streamedTextureBinding> mStreamedTexturesBindings;

VulkanExternalImageManager* mExternalImageManager;
VulkanDescriptorSetCache* mDescriptorSetCache;
VulkanSamplerCache* mSamplerCache;
};

} // namespace filament::backend

#endif // TNT_FILAMENT_BACKEND_CACHING_VULKANSTREAMEDIMAGEMANAGER_H
Loading
Loading