2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-02-22 14:42:01 +01:00
|
|
|
#include "BLI_array.hh"
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
#include "gpu_shader_create_info.hh"
|
|
|
|
|
#include "gpu_shader_interface.hh"
|
|
|
|
|
|
2023-03-06 12:28:55 +01:00
|
|
|
#include "BLI_array.hh"
|
|
|
|
|
|
2024-04-16 14:00:49 +02:00
|
|
|
#include "vk_descriptor_set_layouts.hh"
|
2023-03-06 12:28:55 +01:00
|
|
|
#include "vk_push_constants.hh"
|
2023-02-22 14:42:01 +01:00
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
namespace blender::gpu {
|
2024-09-26 10:59:45 +02:00
|
|
|
|
|
|
|
|
struct VKResourceBinding {
|
|
|
|
|
shader::ShaderCreateInfo::Resource::BindType bind_type =
|
|
|
|
|
shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER;
|
|
|
|
|
int binding = -1;
|
|
|
|
|
|
|
|
|
|
VKDescriptorSet::Location location;
|
|
|
|
|
VKImageViewArrayed arrayed = VKImageViewArrayed::DONT_CARE;
|
|
|
|
|
VkAccessFlags access_mask = VK_ACCESS_NONE;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
class VKShaderInterface : public ShaderInterface {
|
|
|
|
|
private:
|
2024-09-26 10:59:45 +02:00
|
|
|
/** Binding information for each shader input. */
|
|
|
|
|
Array<VKResourceBinding> resource_bindings_;
|
2024-04-16 14:00:49 +02:00
|
|
|
VKDescriptorSetLayoutInfo descriptor_set_layout_info_;
|
2023-02-21 15:03:12 +01:00
|
|
|
|
2023-03-06 12:28:55 +01:00
|
|
|
VKPushConstants::Layout push_constants_layout_;
|
|
|
|
|
|
2023-09-26 16:04:08 +02:00
|
|
|
shader::BuiltinBits shader_builtins_;
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
public:
|
|
|
|
|
VKShaderInterface() = default;
|
|
|
|
|
|
|
|
|
|
void init(const shader::ShaderCreateInfo &info);
|
2023-02-22 14:42:01 +01:00
|
|
|
|
|
|
|
|
const VKDescriptorSet::Location descriptor_set_location(
|
|
|
|
|
const shader::ShaderCreateInfo::Resource &resource) const;
|
2023-05-11 08:44:57 +02:00
|
|
|
const std::optional<VKDescriptorSet::Location> descriptor_set_location(
|
2023-02-22 14:42:01 +01:00
|
|
|
const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const;
|
|
|
|
|
|
2024-04-22 20:47:30 +02:00
|
|
|
/**
|
|
|
|
|
* Get the access mask for a binding.
|
|
|
|
|
*
|
|
|
|
|
* Is used to build the correct resource accesses in the render graph (dispatch/draw nodes).
|
|
|
|
|
*
|
|
|
|
|
* Will return VK_ACCESS_NONE when binding isn't found or not compatible with the given bind
|
|
|
|
|
* type.
|
|
|
|
|
*/
|
|
|
|
|
const VkAccessFlags access_mask(const shader::ShaderCreateInfo::Resource::BindType &bind_type,
|
|
|
|
|
int binding) const;
|
2024-06-25 15:15:18 +02:00
|
|
|
const VKImageViewArrayed arrayed(const shader::ShaderCreateInfo::Resource::BindType &bind_type,
|
|
|
|
|
int binding) const;
|
2024-04-22 20:47:30 +02:00
|
|
|
|
2023-03-09 10:39:49 +11:00
|
|
|
/** Get the Layout of the shader. */
|
2023-03-06 12:28:55 +01:00
|
|
|
const VKPushConstants::Layout &push_constants_layout_get() const
|
|
|
|
|
{
|
|
|
|
|
return push_constants_layout_;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 14:00:49 +02:00
|
|
|
const VKDescriptorSetLayoutInfo &descriptor_set_layout_info_get() const
|
|
|
|
|
{
|
|
|
|
|
return descriptor_set_layout_info_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 13:35:01 +02:00
|
|
|
shader::Type get_attribute_type(int location) const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<shader::Type>(attr_types_[location]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 16:04:08 +02:00
|
|
|
bool is_point_shader() const
|
|
|
|
|
{
|
|
|
|
|
return (shader_builtins_ & shader::BuiltinBits::POINT_SIZE) == shader::BuiltinBits::POINT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 10:59:45 +02:00
|
|
|
const Span<VKResourceBinding> resource_bindings_get() const
|
|
|
|
|
{
|
|
|
|
|
return resource_bindings_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 14:42:01 +01:00
|
|
|
private:
|
2024-04-16 14:00:49 +02:00
|
|
|
void init_descriptor_set_layout_info(const shader::ShaderCreateInfo &info,
|
|
|
|
|
int64_t resources_len,
|
|
|
|
|
Span<shader::ShaderCreateInfo::Resource> resources,
|
|
|
|
|
VKPushConstants::StorageType push_constants_storage);
|
2023-02-21 15:03:12 +01:00
|
|
|
/**
|
|
|
|
|
* Retrieve the shader input for the given resource.
|
|
|
|
|
*
|
|
|
|
|
* nullptr is returned when resource could not be found.
|
|
|
|
|
* Should only happen when still developing the Vulkan shader.
|
|
|
|
|
*/
|
|
|
|
|
const ShaderInput *shader_input_get(const shader::ShaderCreateInfo::Resource &resource) const;
|
|
|
|
|
const ShaderInput *shader_input_get(
|
|
|
|
|
const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const;
|
2024-09-26 10:59:45 +02:00
|
|
|
const VKResourceBinding &resource_binding_info(const ShaderInput *shader_input) const;
|
|
|
|
|
|
2023-12-22 19:02:53 +01:00
|
|
|
void descriptor_set_location_update(
|
|
|
|
|
const ShaderInput *shader_input,
|
|
|
|
|
const VKDescriptorSet::Location location,
|
2024-04-22 20:47:30 +02:00
|
|
|
const shader::ShaderCreateInfo::Resource::BindType bind_type,
|
2024-06-25 15:15:18 +02:00
|
|
|
std::optional<const shader::ShaderCreateInfo::Resource> resource,
|
|
|
|
|
VKImageViewArrayed arrayed);
|
2023-02-21 15:03:12 +01:00
|
|
|
};
|
2023-02-22 14:42:01 +01:00
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
} // namespace blender::gpu
|