18 static char PUSH_CONSTANTS_FALLBACK_NAME[] =
"push_constants_fallback";
19 static size_t PUSH_CONSTANTS_FALLBACK_NAME_LEN = strlen(PUSH_CONSTANTS_FALLBACK_NAME);
20 static char SUBPASS_FALLBACK_NAME[] =
"gpu_subpass_img_0";
21 static size_t SUBPASS_FALLBACK_NAME_LEN = strlen(SUBPASS_FALLBACK_NAME);
37 switch (res.bind_type) {
38 case ShaderCreateInfo::Resource::BindType::IMAGE:
39 case ShaderCreateInfo::Resource::BindType::SAMPLER:
42 case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
45 case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
62 names_size += PUSH_CONSTANTS_FALLBACK_NAME_LEN + 1;
77 input->location = input->binding = attr.index;
78 if (input->location != -1) {
90 if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) {
92 input->location = input->binding = res.slot;
97 int32_t push_constants_fallback_location = -1;
100 input->location = input->binding = -1;
107 input->location = input->binding = subpass_in.index;
111 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
113 input->location = input->binding = res.slot;
116 else if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
124 int32_t push_constant_location = 1024;
127 input->location = push_constant_location++;
134 if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
136 input->location = input->binding = res.slot;
142 if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
146 BLI_assert_msg(0,
"Resource type is not supported for Geometry frequency");
154 input->location = constant_id++;
176 const uint32_t resources_len = input_tot_len;
179 init_descriptor_set_layout_info(info, resources_len, all_resources, push_constants_storage_type);
183 resource_bindings_.fill({});
191 descriptor_set_location_update(input,
201 if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
217 else if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
242 int32_t push_constant_descriptor_set_location = -1;
246 descriptor_set_location_update(push_constant_input,
247 push_constants_fallback_location,
252 push_constants_layout_.
init(
253 info, *
this, push_constants_storage_type, push_constant_descriptor_set_location);
259 int32_t index = (shader_input - shader_inputs);
263void VKShaderInterface::descriptor_set_location_update(
267 std::optional<const shader::ShaderCreateInfo::Resource> resource,
274 "Incorrect parameters, when no resource is given, it must be the uniform buffer "
275 "for storing push constants or sampler for subpasses.");
276 BLI_assert_msg(!resource.has_value() || resource->bind_type == bind_type,
277 "Incorrect parameter, bind types do not match.");
280 BLI_assert(resource_bindings_[index].binding == -1);
282 VkAccessFlags vk_access_flags = VK_ACCESS_NONE;
283 if (resource.has_value()) {
284 switch (resource->bind_type) {
286 vk_access_flags |= VK_ACCESS_UNIFORM_READ_BIT;
291 vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
294 vk_access_flags |= VK_ACCESS_SHADER_WRITE_BIT;
300 vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
303 vk_access_flags |= VK_ACCESS_SHADER_WRITE_BIT;
308 vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
313 vk_access_flags |= VK_ACCESS_UNIFORM_READ_BIT;
316 vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
321 resource_binding.
binding = shader_input->binding;
322 resource_binding.
location = location;
331 return resource_bindings_[index];
337 const ShaderInput *shader_input = shader_input_get(resource);
339 return resource_binding_info(shader_input).
location;
345 const ShaderInput *shader_input = shader_input_get(bind_type, binding);
346 if (shader_input ==
nullptr) {
350 if (resource_binding.
bind_type != bind_type) {
359 const ShaderInput *shader_input = shader_input_get(bind_type, binding);
360 if (shader_input ==
nullptr) {
361 return VK_ACCESS_NONE;
364 if (resource_binding.
bind_type != bind_type) {
365 return VK_ACCESS_NONE;
373 const ShaderInput *shader_input = shader_input_get(bind_type, binding);
374 if (shader_input ==
nullptr) {
377 return resource_binding_info(shader_input).
arrayed;
380const ShaderInput *VKShaderInterface::shader_input_get(
386const ShaderInput *VKShaderInterface::shader_input_get(
406void VKShaderInterface::init_descriptor_set_layout_info(
416 VK_SHADER_STAGE_ALL_GRAPHICS :
417 VK_SHADER_STAGE_COMPUTE_BIT;
418 for (
int index :
IndexRange(info.subpass_inputs_.size())) {
420 descriptor_set_layout_info_.
bindings.
append(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
426 descriptor_set_layout_info_.
bindings.
append(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
#define BLI_assert_msg(a, msg)
constexpr bool is_empty() const
void append(const T &value)
void reserve(const int64_t min_capacity)
void extend(Span< T > array)
void copy_input_name(ShaderInput *input, const StringRefNull &name, char *name_buffer, uint32_t &name_buffer_offset) const
const ShaderInput * ubo_get(const char *name) const
const ShaderInput * texture_get(const int binding) const
const char * input_name_get(const ShaderInput *input) const
static const char * builtin_uniform_block_name(GPUUniformBlockBuiltin u)
const ShaderInput * ssbo_get(const char *name) const
int32_t builtin_blocks_[GPU_NUM_UNIFORM_BLOCKS]
int32_t builtins_[GPU_NUM_UNIFORMS]
const ShaderInput * uniform_get(const char *name) const
uint16_t enabled_attr_mask_
uint8_t attr_types_[GPU_VERT_ATTR_MAX_LEN]
static const char * builtin_uniform_name(GPUUniformBuiltin u)
const VKImageViewArrayed arrayed(const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const
const VKDescriptorSet::Location descriptor_set_location(const shader::ShaderCreateInfo::Resource &resource) const
void init(const shader::ShaderCreateInfo &info)
const VkAccessFlags access_mask(const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const
output_img push_constant(Type::FLOAT, "subtrahend") .define("TYPE"
void *(* MEM_mallocN)(size_t len, const char *str)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
VkDescriptorType to_vk_descriptor_type(const shader::ShaderCreateInfo::Resource &resource)
static constexpr int BIND_SPACE_IMAGE_OFFSET
static int32_t shader_input_index(const ShaderInput *shader_inputs, const ShaderInput *shader_input)
VkShaderStageFlags vk_shader_stage_flags
static StorageType determine_storage_type(const shader::ShaderCreateInfo &info, const VKDevice &device)
void init(const shader::ShaderCreateInfo &info, const VKShaderInterface &interface, StorageType storage_type, VKDescriptorSet::Location location)
VKImageViewArrayed arrayed
VkAccessFlags access_mask
VKDescriptorSet::Location location
shader::ShaderCreateInfo::Resource::BindType bind_type
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
StringRefNull compute_source_
Vector< SubpassIn > subpass_inputs_
Vector< Resource > geometry_resources_
Vector< VertIn > vertex_inputs_
Vector< Resource > batch_resources_
size_t interface_names_size_
Vector< Resource > pass_resources_
std::string compute_source_generated
Vector< SpecializationConstant > specialization_constants_
Vector< PushConst > push_constants_