Blender V4.3
vk_memory_layout.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12
13namespace blender::gpu {
14
18struct Std140 {
20 static uint32_t component_mem_size(const shader::Type type);
22 static uint32_t element_alignment(const shader::Type type, bool is_array);
33 static uint32_t inner_row_padding(const shader::Type type);
34};
35
39struct Std430 {
41 static uint32_t component_mem_size(const shader::Type type);
43 static uint32_t element_alignment(const shader::Type type, bool is_array);
54 static uint32_t inner_row_padding(const shader::Type type);
55};
56
57template<typename LayoutT> static uint32_t element_stride(const shader::Type type)
58{
59 return LayoutT::element_components_len(type) * LayoutT::component_mem_size(type);
60}
61
62template<typename LayoutT> static uint32_t array_stride(const shader::Type type)
63{
64 return LayoutT::array_components_len(type) * LayoutT::component_mem_size(type);
65}
66
76template<typename LayoutT>
77static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
78{
79 uint32_t alignment = LayoutT::element_alignment(type, array_size != 0);
80 uint32_t alignment_mask = alignment - 1;
81 uint32_t offset = *r_offset;
82 if ((offset & alignment_mask) != 0) {
83 offset &= ~alignment_mask;
84 offset += alignment;
85 *r_offset = offset;
86 }
87}
88
101template<typename LayoutT>
102static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
103{
104 uint32_t size = array_size == 0 ? element_stride<LayoutT>(type) :
105 array_stride<LayoutT>(type) * array_size;
106 *r_offset += size;
107}
108
115template<typename LayoutT> static void align_end_of_struct(uint32_t *r_offset)
116{
118}
119
120} // namespace blender::gpu
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
static void align_end_of_struct(uint32_t *r_offset)
static uint32_t array_stride(const shader::Type type)
static uint32_t element_stride(const shader::Type type)
static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
static uint32_t array_components_len(const shader::Type type)
static uint32_t inner_row_padding(const shader::Type type)
static uint32_t element_components_len(const shader::Type type)
static uint32_t component_mem_size(const shader::Type type)
static uint32_t element_alignment(const shader::Type type, bool is_array)
static uint32_t element_alignment(const shader::Type type, bool is_array)
static uint32_t array_components_len(const shader::Type type)
static uint32_t element_components_len(const shader::Type type)
static uint32_t component_mem_size(const shader::Type type)
static uint32_t inner_row_padding(const shader::Type type)