Blender V5.0
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.h"
15
16namespace blender::gpu {
17
21struct Std140 {
23 static uint32_t component_mem_size(const shader::Type type);
25 static uint32_t element_alignment(const shader::Type type, bool is_array);
27 static uint32_t element_components_len(const shader::Type type);
29 static uint32_t array_components_len(const shader::Type type);
36 static uint32_t inner_row_padding(const shader::Type type);
37};
38
42struct Std430 {
44 static uint32_t component_mem_size(const shader::Type type);
46 static uint32_t element_alignment(const shader::Type type, bool is_array);
48 static uint32_t element_components_len(const shader::Type type);
50 static uint32_t array_components_len(const shader::Type type);
57 static uint32_t inner_row_padding(const shader::Type type);
58};
59
60template<typename LayoutT> static uint32_t element_stride(const shader::Type type)
61{
62 return LayoutT::element_components_len(type) * LayoutT::component_mem_size(type);
63}
64
65template<typename LayoutT> static uint32_t array_stride(const shader::Type type)
66{
67 return LayoutT::array_components_len(type) * LayoutT::component_mem_size(type);
68}
69
79template<typename LayoutT>
80static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
81{
82 uint32_t alignment = LayoutT::element_alignment(type, array_size != 0);
83 uint32_t alignment_mask = alignment - 1;
84 uint32_t offset = *r_offset;
85 if ((offset & alignment_mask) != 0) {
86 offset &= ~alignment_mask;
87 offset += alignment;
88 *r_offset = offset;
89 }
90}
91
104template<typename LayoutT>
105static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
106{
107 uint32_t size = array_size == 0 ? element_stride<LayoutT>(type) :
108 array_stride<LayoutT>(type) * array_size;
109 *r_offset += size;
110}
111
118template<typename LayoutT> static void align_end_of_struct(uint32_t *r_offset)
119{
121}
122
132
134 {
135 return int64_t(extent.x) * int64_t(extent.y) * int64_t(extent.z) * layers.size();
136 }
137
138 int64_t result_offset(int3 sub_offset, int layer) const
139 {
140 int64_t diff_x = sub_offset.x - offset.x;
141 int64_t diff_y = sub_offset.y - offset.y;
142 int64_t diff_z = sub_offset.z - offset.z;
143 int64_t diff_l = layer - layers.start();
144
145 return (diff_l * extent.x * extent.y * extent.z) + (diff_z * extent.x * extent.y) +
146 (diff_y * extent.x) + diff_x;
147 }
148};
149
150} // namespace blender::gpu
long long int int64_t
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)
VecBase< int32_t, 3 > int3
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