简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM