Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
93 lines
1.8 KiB
C++
93 lines
1.8 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_array.hh"
|
|
|
|
#include "gpu_shader_create_info.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
/**
|
|
* Super class for resources that can be bound to a shader.
|
|
*/
|
|
class VKBindableResource {
|
|
protected:
|
|
virtual ~VKBindableResource();
|
|
|
|
public:
|
|
/**
|
|
* Bind the resource to the shader.
|
|
*/
|
|
virtual void bind(int binding, shader::ShaderCreateInfo::Resource::BindType bind_type) = 0;
|
|
|
|
protected:
|
|
void unbind_from_active_context();
|
|
|
|
private:
|
|
void unbind_from_all_contexts();
|
|
};
|
|
|
|
/**
|
|
* Blender binds resources at context level (VKStateManager). The bindings are organized in
|
|
* namespaces.
|
|
*/
|
|
template<shader::ShaderCreateInfo::Resource::BindType BindType, int MaxBindings = 16>
|
|
class VKBindSpace {
|
|
Array<VKBindableResource *> bindings_ = Array<VKBindableResource *>(MaxBindings);
|
|
|
|
public:
|
|
VKBindSpace()
|
|
{
|
|
bindings_.fill(nullptr);
|
|
}
|
|
|
|
/**
|
|
* Register a binding to this namespace.
|
|
*/
|
|
void bind(int binding, VKBindableResource &resource)
|
|
{
|
|
bindings_[binding] = &resource;
|
|
}
|
|
|
|
/**
|
|
* Apply registered bindings to the active shader.
|
|
*/
|
|
void apply_bindings()
|
|
{
|
|
for (int binding : IndexRange(MaxBindings)) {
|
|
if (bindings_[binding] != nullptr) {
|
|
bindings_[binding]->bind(binding, BindType);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Unregister the given resource from this namespace.
|
|
*/
|
|
void unbind(VKBindableResource &resource)
|
|
{
|
|
for (int binding : IndexRange(MaxBindings)) {
|
|
if (bindings_[binding] == &resource) {
|
|
bindings_[binding] = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove all bindings from this namespace.
|
|
*/
|
|
void unbind_all()
|
|
{
|
|
bindings_.fill(nullptr);
|
|
}
|
|
};
|
|
|
|
} // namespace blender::gpu
|