Vulkan: Push constants #104880
|
@ -80,7 +80,6 @@ GPU_SHADER_CREATE_INFO(gpu_push_constants_256bytes_test)
|
|||
.push_constant(Type::FLOAT, "filler2", 32)
|
||||
.do_static_compilation(true);
|
||||
|
||||
/* It is expected that this shader will use uniform buffers and not push constants.*/
|
||||
GPU_SHADER_CREATE_INFO(gpu_push_constants_512bytes_test)
|
||||
Jeroen-Bakker marked this conversation as resolved
|
||||
.additional_info("gpu_push_constants_256bytes_test")
|
||||
.push_constant(Type::FLOAT, "filler3", 64)
|
||||
|
|
|
@ -57,6 +57,19 @@ VKPushConstantsLayout::StorageType VKPushConstantsLayout::determine_storage_type
|
|||
STORAGE_TYPE_FALLBACK;
|
||||
}
|
||||
|
||||
template<typename Layout>
|
||||
void init_struct(const shader::ShaderCreateInfo &info,
|
||||
const VKShaderInterface &interface,
|
||||
Vector<VKPushConstantsLayout::PushConstantLayout> &r_struct,
|
||||
uint32_t *r_offset)
|
||||
{
|
||||
for (const shader::ShaderCreateInfo::PushConst &push_constant : info.push_constants_) {
|
||||
const ShaderInput *shader_input = interface.uniform_get(push_constant.name.c_str());
|
||||
r_struct.append(init_constant<Layout>(push_constant, *shader_input, r_offset));
|
||||
}
|
||||
align_end_of_struct<Std140>(r_offset);
|
||||
}
|
||||
|
||||
void VKPushConstantsLayout::init(const shader::ShaderCreateInfo &info,
|
||||
const VKShaderInterface &interface,
|
||||
const StorageType storage_type,
|
||||
|
@ -64,30 +77,15 @@ void VKPushConstantsLayout::init(const shader::ShaderCreateInfo &info,
|
|||
{
|
||||
BLI_assert(push_constants.is_empty());
|
||||
storage_type_ = storage_type;
|
||||
|
||||
size_in_bytes_ = 0;
|
||||
if (storage_type == StorageType::UNIFORM_BUFFER) {
|
||||
storage_buffer_binding_ = location;
|
||||
}
|
||||
uint32_t offset = 0;
|
||||
/* TODO: add template for readability.*/
|
||||
for (const shader::ShaderCreateInfo::PushConst &push_constant : info.push_constants_) {
|
||||
const ShaderInput *shader_input = interface.uniform_get(push_constant.name.c_str());
|
||||
BLI_assert(shader_input);
|
||||
if (storage_type == StorageType::UNIFORM_BUFFER) {
|
||||
push_constants.append(init_constant<Std140>(push_constant, *shader_input, &offset));
|
||||
}
|
||||
else {
|
||||
push_constants.append(init_constant<Std430>(push_constant, *shader_input, &offset));
|
||||
}
|
||||
}
|
||||
|
||||
/* Align end of struct. */
|
||||
if (storage_type == StorageType::UNIFORM_BUFFER) {
|
||||
align_end_of_struct<Std140>(&offset);
|
||||
init_struct<Std140>(info, interface, push_constants, &size_in_bytes_);
|
||||
}
|
||||
else {
|
||||
align_end_of_struct<Std430>(&offset);
|
||||
init_struct<Std430>(info, interface, push_constants, &size_in_bytes_);
|
||||
}
|
||||
size_in_bytes_ = offset;
|
||||
}
|
||||
|
||||
const VKPushConstantsLayout::PushConstantLayout *VKPushConstantsLayout::find(
|
||||
|
|
|
@ -51,8 +51,7 @@ struct VKPushConstantsLayout {
|
|||
static constexpr StorageType STORAGE_TYPE_FALLBACK = StorageType::UNIFORM_BUFFER;
|
||||
|
||||
struct PushConstantLayout {
|
||||
/* TODO: location requires sequential lookups, we should make the location index based for
|
||||
* quicker access. */
|
||||
/* Used as lookup based on ShaderInput.*/
|
||||
int32_t location;
|
||||
|
||||
/** Offset in the push constant data (in bytes). */
|
||||
|
|
|
@ -127,17 +127,10 @@ void VKShaderInterface::init(const shader::ShaderCreateInfo &info)
|
|||
/* Post initializing push constants.*/
|
||||
/* Determine the binding location of push constants fallback buffer.*/
|
||||
int32_t push_constant_descriptor_set_location = -1;
|
||||
switch (push_constants_storage_type) {
|
||||
case VKPushConstantsLayout::StorageType::NONE:
|
||||
case VKPushConstantsLayout::StorageType::PUSH_CONSTANTS:
|
||||
break;
|
||||
|
||||
case VKPushConstantsLayout::StorageType::UNIFORM_BUFFER: {
|
||||
push_constant_descriptor_set_location = descriptor_set_location++;
|
||||
const ShaderInput *push_constant_input = ubo_get(PUSH_CONSTANTS_FALLBACK_NAME.c_str());
|
||||
descriptor_set_location_update(push_constant_input, push_constants_fallback_location);
|
||||
break;
|
||||
}
|
||||
if (push_constants_storage_type == VKPushConstantsLayout::StorageType::UNIFORM_BUFFER) {
|
||||
push_constant_descriptor_set_location = descriptor_set_location++;
|
||||
const ShaderInput *push_constant_input = ubo_get(PUSH_CONSTANTS_FALLBACK_NAME.c_str());
|
||||
descriptor_set_location_update(push_constant_input, push_constants_fallback_location);
|
||||
}
|
||||
push_constants_layout_.init(
|
||||
info, *this, push_constants_storage_type, push_constant_descriptor_set_location);
|
||||
|
|
Loading…
Reference in New Issue
Remove line as this is vulkan specific.