This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/gpu/vulkan/vk_shader_interface.hh
Jeroen Bakker 8c03410ebd Vulkan: Refactor shader interface.
Descriptor set locations are now determined in the
VKShaderInterface. Issues with the previous solution:

- Due to legacy code in GPU module the locations/bindings
  must be the same. Using one for something else might
  result in undesired lookups, incorrect resource
  bindings.
- Images/Textures reuses the same namespace, that didn't
  work as expected when looking up the resources via
  its binding.

This refactoring is required for adding support for
push constants.

Pull Request #105073
2023-02-22 14:42:01 +01:00

56 lines
1.8 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*/
#pragma once
#include "BLI_array.hh"
#include "gpu_shader_create_info.hh"
#include "gpu_shader_interface.hh"
#include "vk_descriptor_set.hh"
namespace blender::gpu {
class VKShaderInterface : public ShaderInterface {
private:
/**
* Offset when searching for a shader input based on a binding number.
*
* When shaders combine images and samplers, the images have to be offset to find the correct
* shader input. Both textures and images are stored in the uniform list and their ID can be
* overlapping.
*/
uint32_t image_offset_ = 0;
Array<VKDescriptorSet::Location> descriptor_set_locations_;
public:
VKShaderInterface() = default;
void init(const shader::ShaderCreateInfo &info);
const VKDescriptorSet::Location descriptor_set_location(
const shader::ShaderCreateInfo::Resource &resource) const;
const VKDescriptorSet::Location descriptor_set_location(
const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const;
private:
/**
* 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;
const VKDescriptorSet::Location descriptor_set_location(const ShaderInput *shader_input) const;
void descriptor_set_location_update(const ShaderInput *shader_input,
const VKDescriptorSet::Location location);
};
} // namespace blender::gpu