Blender V5.3
mtl_push_constant.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_global.hh"
10
11#include "mtl_push_constant.hh"
12
13namespace blender::gpu {
14
16 size_t &alignment)
17{
18 int comp = to_component_count(push_constant.type);
19 size_t size;
20 if (comp == 3) {
21 /* Padded size for float3. */
22 size = 4 * sizeof(float);
23 alignment = 16;
24 }
25 else if (comp == 9) {
26 /* Padded size for float3x3. */
27 size = 3 * 4 * sizeof(float);
28 alignment = 16;
29 }
30 else if (comp == 16) {
31 /* Special alignment case for float4x4. */
32 size = 4 * 4 * sizeof(float);
33 alignment = 16;
34 }
35 else {
36 size = comp * sizeof(float);
37 alignment = size;
38 }
39 return size * push_constant.array_size_safe();
40}
41
43{
44 BLI_assert(info.push_constants_.is_empty() == false);
45 size_t max_alignment = 0;
46 /* Compute size of backing buffer. */
47 size_ = 0;
49 size_t alignment;
50 size_t pc_size = padded_size(push_constant, alignment);
51 max_alignment = max_uu(max_alignment, alignment);
52 /* Padding for alignment. */
53 size_ = ceil_to_multiple_u(size_, alignment);
54 size_ += pc_size;
55 }
56 /* Pad to max alignment. */
57 size_ = ceil_to_multiple_u(size_, max_alignment);
58 data_ = reinterpret_cast<uint8_t *>(
59 MEM_new_array_zeroed_aligned(1, size_, 128, "MTLPushConstantData"));
60
61 if (G.debug & G_DEBUG_GPU) {
62 /* Poison values to detect unset values. */
63 memset(data_, 0xFD, size_);
64 }
65}
66
68{
69 MEM_delete(data_);
70}
71
73{
74 size_t alignment;
75 size_t pc_size = padded_size(push_constant, alignment);
76 /* Padding for alignment. */
77 offset_ = ceil_to_multiple_u(offset_, alignment);
78 int loc = offset_;
79 offset_ += pc_size;
80 BLI_assert(offset_ <= size_);
81 return loc;
82}
83
84} // namespace blender::gpu
MTLPushConstantBuf(const shader::ShaderCreateInfo &info)
int append(shader::ShaderCreateInfo::PushConst push_constant)
#define push_constant
BLI_INLINE int to_component_count(const Type &type)
static size_t padded_size(const shader::ShaderCreateInfo::PushConst &push_constant, size_t &alignment)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE uint max_uu(uint a, uint b)
Global G
Definition blender.cc:57
unsigned char uint8_t
Definition BKE_text.h:79
MINLINE uint ceil_to_multiple_u(uint a, uint b)
void *(*) MEM_new_array_zeroed_aligned(size_t len, size_t size, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...