Blender V5.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
8
9#pragma once
10
12
13#include "BLI_math_base_c.hh"
15
16#include "vk_common.hh"
17
18namespace blender::gpu {
19
23struct Std140 {
25 static uint32_t component_mem_size(const shader::Type type);
27 static uint32_t element_alignment(const shader::Type type, bool is_array);
38 static uint32_t inner_row_padding(const shader::Type type);
39};
40
44struct Std430 {
46 static uint32_t component_mem_size(const shader::Type type);
48 static uint32_t element_alignment(const shader::Type type, bool is_array);
59 static uint32_t inner_row_padding(const shader::Type type);
60};
61
62template<typename LayoutT> static uint32_t element_stride(const shader::Type type)
63{
64 return LayoutT::element_components_len(type) * LayoutT::component_mem_size(type);
65}
66
67template<typename LayoutT> static uint32_t array_stride(const shader::Type type)
68{
69 return LayoutT::array_components_len(type) * LayoutT::component_mem_size(type);
70}
71
81template<typename LayoutT>
82static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
83{
84 uint32_t alignment = LayoutT::element_alignment(type, array_size != 0);
85 *r_offset = ceil_to_multiple_ul(*r_offset, alignment);
86}
87
100template<typename LayoutT>
101static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
102{
103 uint32_t size = array_size == 0 ? element_stride<LayoutT>(type) :
104 array_stride<LayoutT>(type) * array_size;
105 *r_offset += size;
106}
107
114template<typename LayoutT> static void align_end_of_struct(uint32_t *r_offset)
115{
117}
118
128
130 {
131 return int64_t(extent.x) * int64_t(extent.y) * int64_t(extent.z) * layers.size();
132 }
133
134 int64_t result_offset(int3 sub_offset, int layer) const
135 {
136 int64_t diff_x = sub_offset.x - offset.x;
137 int64_t diff_y = sub_offset.y - offset.y;
138 int64_t diff_z = sub_offset.z - offset.z;
139 int64_t diff_l = layer - layers.start();
140
141 return (diff_l * extent.x * extent.y * extent.z) + (diff_z * extent.x * extent.y) +
142 (diff_y * extent.x) + diff_x;
143 }
144};
145
146} // namespace blender::gpu
constexpr int64_t size() const
constexpr int64_t start() const
#define layer
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)
__int64 int64_t
Definition BKE_text.h:90
unsigned int uint32_t
Definition BKE_text.h:81
VecBase< int32_t, 3 > int3
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
signed int int32_t
Definition BKE_text.h:78
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)
int64_t result_offset(int3 sub_offset, int layer) const