Vulkan: Push constants #104880

Merged
Jeroen Bakker merged 73 commits from Jeroen-Bakker/blender:vulkan-push-constants into main 2023-03-06 12:29:06 +01:00
1 changed files with 20 additions and 4 deletions
Showing only changes of commit 9698a12bc3 - Show all commits

View File

@ -215,12 +215,28 @@ class VKPushConstants : NonCopyable {
const VKPushConstantsLayout::PushConstantLayout *push_constant_layout = layout_->find(
location);
BLI_assert(push_constant_layout);
BLI_assert_msg(push_constant_layout->offset + comp_len * array_size * sizeof(T) <=
layout_->size_in_bytes(),
"Tried to write outside the push constant allocated memory.");
uint8_t *bytes = static_cast<uint8_t *>(data_);
T *dst = static_cast<T *>(static_cast<void *>(&bytes[push_constant_layout->offset]));
memcpy(dst, input_data, comp_len * array_size * sizeof(T));
if (layout_->storage_type_get() == VKPushConstantsLayout::StorageType::PUSH_CONSTANTS ||
array_size == 0) {
BLI_assert_msg(push_constant_layout->offset + comp_len * array_size * sizeof(T) <=
layout_->size_in_bytes(),
"Tried to write outside the push constant allocated memory.");
memcpy(dst, input_data, comp_len * array_size * sizeof(T));
return;
}
/* Store elements in uniform buffer as array. In Std140 arrays have an element stride of 16
* bytes.*/
Jeroen-Bakker marked this conversation as resolved

You could test if the array is tightly packed and do only one memcpy.

You could test if the array is tightly packed and do only one `memcpy`.
BLI_assert(sizeof(T) == 4);
const T *src = input_data;
for (const int i : IndexRange(array_size)) {
UNUSED_VARS(i);
memcpy(dst, src, comp_len * sizeof(T));
src += comp_len;
dst += 4;
}
}
};