MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ gpu_block_layout()

MAYAFLUX_API GpuBlockLayout MayaFlux::Kakshya::gpu_block_layout ( std::span< const GpuDataFormat >  fields)

Lay out fields in declaration order under std430 rules.

Each offset is the running end rounded up to the field's alignment, and the size is the end rounded up to the widest alignment, never less than four. This is the layout Vulkan applies to push constant blocks, which the GLSL path leaves to the compiler and the SPIR-V path must state itself.

Parameters
fieldsField formats in declaration order.
Returns
One offset per field. Unrecognised formats take no space and report the current end as their offset.

Definition at line 88 of file GpuDataFormat.cpp.

89{
90 GpuBlockLayout layout;
91 layout.offsets.reserve(fields.size());
92
93 size_t end = 0;
94 size_t widest = 4;
95 for (const GpuDataFormat field : fields) {
96 const size_t align = gpu_data_format_align(field);
97 if (align == 0) {
98 layout.offsets.push_back(static_cast<uint32_t>(end));
99 continue;
100 }
101
102 end = (end + align - 1) / align * align;
103 layout.offsets.push_back(static_cast<uint32_t>(end));
104 end += gpu_data_format_bytes(field);
105 widest = std::max(widest, align);
106 }
107
108 layout.size = static_cast<uint32_t>((end + widest - 1) / widest * widest);
109 return layout;
110}
size_t gpu_data_format_align(GpuDataFormat fmt) noexcept
Base alignment in bytes of one element, following std430 rules.
GpuDataFormat
GPU data formats with explicit precision levels.
std::vector< uint32_t > offsets
Member offsets and total size of a block of GpuDataFormat fields.

References gpu_data_format_align(), gpu_data_format_bytes(), MayaFlux::Kakshya::GpuBlockLayout::offsets, and MayaFlux::Kakshya::GpuBlockLayout::size.

Referenced by MayaFlux::Portal::Graphics::push_constant_layout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: