KhronosGroup / Vulkan-Tools

Vulkan Development Tools
Apache License 2.0
361 stars 153 forks source link

`vulkaninfo` size of maxUniformBufferRange is 4294967295 #1006

Closed davids91 closed 2 months ago

davids91 commented 2 months ago

I have an AMD GPU and I am investigating which address space to put my data into.

Multiple sources state that uniform buffers are limited to ~64k, but I've ran vulkaninfo on Manjaro with my card and it displayed the above range... ( 4294967295 )

Surely there must be something wrong with that.. For one, the number is u32::MAX, and I have multiple other values set to this value..

image

How can I make sure what is the maximum data I can safely upload to the uniform address space?

charles-lunarg commented 2 months ago

maxUniformBufferRange is the maximum value that can be specified in the range member of a VkDescriptorBufferInfo structure passed to vkUpdateDescriptorSets for descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC. https://docs.vulkan.org/spec/latest/chapters/limits.html

maxUniformBufferRange - 16384 - min (vulkan implementations must support at least 16384) https://docs.vulkan.org/spec/latest/chapters/limits.html#limits-minmax

You just uncovered AMD's secret trick - Uniform buffers aren't any different than Storage buffers! For AMD they do not have an upper limit on the size of a uniform buffer.

This has been the case since launch AFAIK. The vulkan.gpuinfo.org database also has plenty of uploads with the same u32 max limit. http://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxUniformBufferRange&platform=all

Multiple sources state that uniform buffers are limited to ~64k

Yes, on not-AMD hardware. Its a good idea to use that limit for portability. The roadmap 2022 profile does list ~65k as the min required range, which means if you require the 2022 profile, then you can safely use 65k uniform buffers.

Also, I could be wrong about this, but the actually memory size of a buffer can be much LARGER than 65k even on hardware with the maxUniformBufferRange of 65k, the limit is how much of the buffer can be bound at a time. As in, you could allocate a 10mb buffer but can only bind 65k of it at a time into a uniform buffer descriptor.

davids91 commented 2 months ago

That means I can allocate up to 4GB of data?! ( well give or take, but mostly take because the memeory is required for other operations as well ) for AMD hardware? that's from performance POV is amazing, as Uniform buffers are faster than storage buffers, right?

charles-lunarg commented 2 months ago

that's from performance POV is amazing, as Uniform buffers are faster than storage buffers, right?

And thats where "they are the same" comment kicks in - afaik no there isn't any performance advantage on AMD for using uniform buffers over storage buffers. That cannot be said for other hardware where they are more performant.

I suggest looking up the vendors best practices/performance guides for more concrete advice.

davids91 commented 2 months ago

Great advice and informative replies! Thank you very much!