facebook / igl

Intermediate Graphics Library (IGL) is a cross-platform library that commands the GPU. It provides a single low-level cross-platform interface on top of various graphics APIs (e.g. OpenGL, Metal and Vulkan).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to align buffer?

tksuoran opened this issue · comments

I want to write to a buffer, which previously has already been written to. In this case, the write offset should be properly aligned, in order to respect buffer offset alignment requirements. I have some questions related to this:

  1. BufferDesc::BufferType type; is documented as GLES only. This does not seem to be accurate: vulkan::Buffer::create() inspects type, and derives VkBufferUsageFlags from it.
  2. IBuffer does not seem to expose buffer type. So how do I know which alignment should I apply to a buffer? At least in GL there is separate alignment values for different buffer target bindings.
  3. How do I figure out different buffer type alignments? Which buffer types DeviceFeatureLimits::BufferAlignment applies to? Does ShaderStorageBufferOffsetAlignment apply to only shader storage buffers? What alignment should I use for uniform buffer offset?
    I wonder if IBuffer should expose buffer type? Or maybe IBuffer could have method to apply necessary offset alignment (size_t in, aligned size_t out)?

Thanks!

I will make a fix for (1) and (2) by adding IBuffer::getBufferType().

As for (3), DeviceFeatureLimits::ShaderStorageBufferOffsetAlignment applies to storage buffers and DeviceFeatureLimits::BufferAlignment applies to uniform buffers. There's currently no API in IGL to get alignment information for other buffer types.

Added IBuffer::getBufferType(): 626eb93
Buffer alignment queries: f52ebe7