Skip to content

Conversation

phoenixxxx
Copy link
Contributor

This is the implemenation of the Stream API on the Vulkan Backend. We leverage most of the work that was done by the external image manager, but we created a different manager to contain the code.

Tested on Moohan (manual merge, so some things could have gotten lost in the process). Also working on validating this on Android.

VulkanStreamedImageManager mStreamedImageManager;

// Stream transforms
std::unordered_map<VkBuffer, BufferObjectStreamDescriptor> mStreamUniformDescriptors;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we keep this in VulkanStreamedImageManager ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather not. It feels more nature for the stream to hold this data. It also means that once we have the stream we can access all the stream images. Since this object is not a Thread safe resource, it seems sensible?
But if you feel strongly about it, I can move it to the VulkanStreamedImageManager, that's one more level of indirection where we need a to map<VkBuffer, BufferObjectStreamDescriptor> inside the VulkanStreamedImageManager

// For some reason, some of the frames coming to us, are on streams where the
// descriptor set isn't external...
if (data.set->getExternalSamplerVkSet()) {
if (newImage) {
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 can always just call bindExternallySampledTexture even if it's not a newImage ?

But we should probably add some logic in bindExternallSampledTexture to remove an entry if it shares the same data.set and data.binding. (Basically it's overwriting the existing binding for a descriptor set).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, we get these calls every frame, which means we will keep pushing int the binding vector and it will grow unbounded.

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to add logic in bindExternallySampledTexture to remove bindings to the same set and set binding.

// For some reason, some of the frames coming to us, are on streams where the
// descriptor set isn't external...
if (data.set->getExternalSamplerVkSet()) {
if (newImage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to add logic in bindExternallySampledTexture to remove bindings to the same set and set binding.

Copy link
Collaborator

@pixelflinger pixelflinger left a comment

Choose a reason for hiding this comment

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

LGTM, just had a small comment

Copy link
Contributor

@poweifeng poweifeng left a comment

Choose a reason for hiding this comment

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

Can you file a bug to track the stream feature for ARM (mali)? The sample-hello-camera sample does not work it seems

if (data.image->getStream() == stream) {
// For some reason, some of the frames coming to us, are on streams where the
// descriptor set isn't external...
if (data.set->getExternalSamplerVkSet()) {
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 this needs to be image->getVkFormat() == VK_FORMAT_UNDEFINED that indicates the texture has a externally sampled format. The ExternalSamplerVkSet will only be created if the bindExternallySampledTexture goes through.

Copy link
Contributor

@rafadevai rafadevai Sep 23, 2025

Choose a reason for hiding this comment

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

Nice catch!!

You are right, if the new acquiredImage needs an external sampler then bind it, otherwise just update the sampler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch yes.

commands.acquire(bo);
bo->loadFromCpu(commands, bd.buffer, byteOffset, bd.size);

if (UTILS_UNLIKELY(!mStreamUniformDescriptors.empty())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldnt the copyMat3f happen before bo->loadFromCpu?
right now its copying the current bd.buffer to the gpu memory and then its updating the transform

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 that's right, good catch.

if (data.image->getStream() == stream) {
// For some reason, some of the frames coming to us, are on streams where the
// descriptor set isn't external...
if (data.image->getVkFormat() == VK_FORMAT_UNDEFINED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so im pretty sure here, you have to create a new descriptor set and copy the contents otherwise you might update one currently in flight

like every time, you acquire a new image, we need a new descriptor set regardless if the the sampler changed or not

Copy link
Contributor

Choose a reason for hiding this comment

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

and that's actually what this PR is doing. So you might want to wait for it to land and then rebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

but even if the stream is not using an external sampler, you would still have to create a new descriptor set, which from what I understand, that PR wont help

Also in the case its also using the same colorspace but the texture is different, you would also require a new descriptor set because you want to update the entry but not change the one currently in flight.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, you're right. You'll need to make a new descriptor for the non-externally-sampled case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK so I think I might have lost track of all the temporary DS.... And I think a lot of cracks were found in the current ext sampler implementations. I am fine focusing on #9251 and then re-evaluating how to manage this for the stream path (in this PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants