Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to allocate image on GTX 1080 #7

Open
Mon-Ouie opened this issue Jan 17, 2024 · 5 comments
Open

Failure to allocate image on GTX 1080 #7

Mon-Ouie opened this issue Jan 17, 2024 · 5 comments

Comments

@Mon-Ouie
Copy link

For some reason the allocation of yuv_texture in pipeline.rs fails:

Error: a non-validation error occurred

Caused by:
    0: allocating memory for the image failed
    1: finding a suitable memory type failed

The Vulkan wrapper isn't finding the right memory type to create the image. I might be overlooking a flag but it seems like a suitable memory type is present though:

$ vulkaninfo
...
memoryHeaps: count = 3
        memoryHeaps[0]:
                size   = 8589934592 (0x200000000) (8.00 GiB)
                budget = 4746379264 (0x11ae80000) (4.42 GiB)
                usage  = 0 (0x00000000) (0.00 B)
                flags: count = 1
                        MEMORY_HEAP_DEVICE_LOCAL_BIT
        memoryHeaps[1]:
                size   = 25176649728 (0x5dca53000) (23.45 GiB)
                budget = 25176649728 (0x5dca53000) (23.45 GiB)
                usage  = 0 (0x00000000) (0.00 B)
                flags:
                        None
        memoryHeaps[2]:
                size   = 257949696 (0x0f600000) (246.00 MiB)
                budget = 198508544 (0x0bd50000) (189.31 MiB)
                usage  = 59441152 (0x038b0000) (56.69 MiB)
                flags: count = 1
                        MEMORY_HEAP_DEVICE_LOCAL_BIT
memoryTypes: count = 11
        # ... more memory types ...
        memoryTypes[8]:
                heapIndex     = 1
                propertyFlags = 0x0006: count = 2
                        MEMORY_PROPERTY_HOST_VISIBLE_BIT
                        MEMORY_PROPERTY_HOST_COHERENT_BIT
                usable for:
                        IMAGE_TILING_OPTIMAL:
                                None
                        IMAGE_TILING_LINEAR:
                                color images
                                (non-sparse, non-transient)
        memoryTypes[9]:
                heapIndex     = 1
                propertyFlags = 0x000e: count = 3
                        MEMORY_PROPERTY_HOST_VISIBLE_BIT
                        MEMORY_PROPERTY_HOST_COHERENT_BIT
                        MEMORY_PROPERTY_HOST_CACHED_BIT
                usable for:
                        IMAGE_TILING_OPTIMAL:
                                None
                        IMAGE_TILING_LINEAR:
                                color images
                                (non-sparse, non-transient)
        memoryTypes[10]:
                heapIndex     = 2
                propertyFlags = 0x0007: count = 3
                        MEMORY_PROPERTY_DEVICE_LOCAL_BIT
                        MEMORY_PROPERTY_HOST_VISIBLE_BIT
                        MEMORY_PROPERTY_HOST_COHERENT_BIT
                usable for:
                        IMAGE_TILING_OPTIMAL:
                                None
                        IMAGE_TILING_LINEAR:
                                color images
                                (non-sparse, non-transient)

The overlay does work if I just change the memory type filter for this one allocation to force the allocation to run:

diff --git a/src/pipeline.rs b/src/pipeline.rs
index c632b4b..b6b17bd 100644
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@ -226,8 +226,7 @@ impl Pipeline {
                 ..Default::default()
             },
             AllocationCreateInfo {
-                memory_type_filter: MemoryTypeFilter::HOST_SEQUENTIAL_WRITE
-                    | MemoryTypeFilter::PREFER_DEVICE,
+                memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
                 ..Default::default()
             },
         )?;

System information for reference:

  • GPU driver: nvidia 545.29.06
  • kernel: Linux 6.7.0-arch3-1
@yshui
Copy link
Owner

yshui commented Jan 17, 2024

You might need to look into vulkano's code.

https://github.com/vulkano-rs/vulkano/blob/94f50f18bd25971ea123adb8b5782ad65a8f085c/vulkano/src/memory/allocator/mod.rs#L1110-L1135

Add some logging statement here might be helpful.

@Mon-Ouie
Copy link
Author

Okay, the part I was missing is that vkGetImageMemoryRequirements indicates the image must be allocated on either memory type 1 (propertyFlags = 0x0000) or memory type 7 (propertyFlags = 0x0001: MEMORY_PROPERTY_DEVICE_LOCAL_BIT).

@yshui
Copy link
Owner

yshui commented Jan 20, 2024

hmm, so maybe we need to allocate buffer on host and device, and do buffer to buffer copy?

@6661620a
Copy link

6661620a commented Feb 3, 2024

I am getting the same error as @Mon-Ouie on Ubuntu 22.04. I tried to make the changes to the code that he suggested, ran cargo clean, cargo build --release but I still receive the error :/
Any ideas how to make it work?

@Mon-Ouie
Copy link
Author

hmm, so maybe we need to allocate buffer on host and device, and do buffer to buffer copy?

Probably, or if you want to be fancy and avoid the copy when appropriate memory types are available you can see how AMD recommends people to handle these cases in their VulkanMemoryAllocator library: https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/usage_patterns.html (see "Advanced data uploading") — presumably vulkano allows similar flags to be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants