|
2 | 2 |
|
3 | 3 | In this section, we'll explore push constants, a powerful feature in Vulkan that allows us to efficiently pass small amounts of data to shaders without the overhead of descriptor sets. |
4 | 4 |
|
5 | | -Throughout our engine implementation, we're using vk::raii dynamic rendering and C++20 modules. The vk::raii namespace provides Resource Acquisition Is Initialization (RAII) wrappers for Vulkan objects, which helps with resource management and makes the code cleaner. Dynamic rendering simplifies the rendering process by eliminating the need for explicit render passes and framebuffers. C++20 modules improve code organization, compilation times, and encapsulation compared to traditional header files. |
6 | | - |
7 | 5 | == What Are Push Constants? |
8 | 6 |
|
9 | 7 | Push constants are a way to send a small amount of data directly to shaders. Unlike uniform buffers, which require descriptor sets and memory allocation, push constants are part of the command buffer itself. This makes them ideal for small, frequently changing data. |
10 | 8 |
|
11 | | -Some key characteristics of push constants: |
12 | | - |
13 | | -1. *Size Limitations*: Push constants have a limited size (typically 128 bytes, but this can vary depending on the device). |
14 | | -2. *Efficiency*: They're more efficient than uniform buffers for small, frequently changing data. |
15 | | -3. *Simplicity*: They don't require descriptor sets or memory allocation. |
16 | | -4. *Scope*: They're available to all shader stages in a pipeline. |
| 9 | +Some key characteristics of push constants: they are tiny (typically up to 128 bytes, device dependent), fast to update per draw, and require no descriptor sets or allocations because they live on the command buffer. They can be read by any shader stage you enable in the pipeline. |
17 | 10 |
|
18 | 11 | == When to Use Push Constants |
19 | 12 |
|
20 | | -Push constants are particularly useful for: |
21 | | - |
22 | | -1. *Per-Draw Data*: Data that changes for each draw call, such as material properties. |
23 | | -2. *Small Data Sets*: Data that fits within the size limitations of push constants. |
24 | | -3. *Frequently Changing Data*: Data that changes often, where the overhead of updating a uniform buffer would be significant. |
25 | | - |
26 | | -For our PBR implementation, push constants are perfect for storing material properties like base color, metallic factor, and roughness factor. |
| 13 | +Use push constants for tiny, per‑draw parameters that change frequently—exactly the kind of material knobs (base color, metallic, roughness) we tweak per object. If the data is larger than the device’s push‑constant limit or doesn’t change often, prefer a uniform buffer instead. |
27 | 14 |
|
28 | 15 | == Defining Push Constants in Shaders |
29 | 16 |
|
|
0 commit comments