Search code examples
glslvulkan

Why does Vulkan forbid uniforms that are not uniform blocks?


According to Vulkan Specification,

The following features are removed:

  • default uniforms (uniform variables not inside a uniform block)

For example, the following is forbidden in GLSL:

layout(set = 0, binding = 0) uniform mat4 projectionMatrix;

Instead, it seems, programmers are encouraged to create a uniform block:

layout(set = 0, binding = 0) uniform Projection {
    mat4 matrix;
} projection;

Using single-valued uniforms is sometimes useful for smaller applications. What was the rationale behind removing the functionality?


Solution

  • It's in keeping with Vulkan's philosophy of being more explicit, where the application makes the decisions the driver otherwise would. It's not efficient for GPUs to manage single uniforms in isolation; they will be inevitably aggregated into some kind of uniform block under the hood. So Vulkan exposes only uniform blocks and lets you make those decisions yourself. You can use a single uniform block per variable if you really want to, but you'll have to explicitly allocate memory for them separately.