2024-04-19 10:46:50 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vk_render_graph.hh"
|
2024-11-29 07:52:00 +01:00
|
|
|
#include "gpu_backend.hh"
|
2024-04-19 10:46:50 +02:00
|
|
|
|
2024-11-28 12:00:21 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2024-04-19 10:46:50 +02:00
|
|
|
namespace blender::gpu::render_graph {
|
|
|
|
|
|
2025-01-27 08:55:23 +01:00
|
|
|
VKRenderGraph::VKRenderGraph(VKResourceStateTracker &resources) : resources_(resources)
|
2024-04-19 10:46:50 +02:00
|
|
|
{
|
2024-06-20 11:34:19 +02:00
|
|
|
submission_id.reset();
|
2024-04-19 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-27 08:55:23 +01:00
|
|
|
void VKRenderGraph::reset()
|
2024-04-19 10:46:50 +02:00
|
|
|
{
|
2025-04-17 13:45:47 +02:00
|
|
|
#if 0
|
|
|
|
|
memstats();
|
|
|
|
|
#endif
|
2025-04-11 14:46:35 +02:00
|
|
|
submission_id.next();
|
|
|
|
|
|
2025-04-17 13:45:47 +02:00
|
|
|
links_.clear_and_shrink();
|
2024-04-22 06:22:31 +02:00
|
|
|
for (VKRenderGraphNode &node : nodes_) {
|
2025-01-21 14:49:23 +01:00
|
|
|
node.free_data(storage_);
|
2024-04-22 06:22:31 +02:00
|
|
|
}
|
2025-04-17 13:45:47 +02:00
|
|
|
nodes_.clear_and_shrink();
|
2025-01-21 14:49:23 +01:00
|
|
|
storage_.reset();
|
2024-05-21 17:34:55 +02:00
|
|
|
|
|
|
|
|
debug_.node_group_map.clear();
|
|
|
|
|
debug_.used_groups.clear();
|
2025-01-30 13:44:50 +01:00
|
|
|
debug_.group_stack.clear();
|
|
|
|
|
debug_.groups.clear();
|
2024-04-19 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 13:45:47 +02:00
|
|
|
void VKRenderGraph::memstats() const
|
|
|
|
|
{
|
|
|
|
|
std::cout << __func__ << " nodes: (" << nodes_.size() << "/" << nodes_.capacity() << "), "
|
|
|
|
|
<< "links: (" << links_.size() << "/" << links_.capacity() << ")\n";
|
|
|
|
|
#define PRINT_STORAGE(name) \
|
|
|
|
|
std::cout << " " #name " : (" << storage_.name.size() << " / " << storage_.name.capacity() \
|
|
|
|
|
<< ")\n "
|
|
|
|
|
|
|
|
|
|
PRINT_STORAGE(begin_rendering);
|
|
|
|
|
PRINT_STORAGE(clear_attachments);
|
|
|
|
|
PRINT_STORAGE(blit_image);
|
|
|
|
|
PRINT_STORAGE(copy_buffer_to_image);
|
|
|
|
|
PRINT_STORAGE(copy_image);
|
|
|
|
|
PRINT_STORAGE(copy_image_to_buffer);
|
|
|
|
|
PRINT_STORAGE(draw);
|
|
|
|
|
PRINT_STORAGE(draw_indexed);
|
|
|
|
|
PRINT_STORAGE(draw_indexed_indirect);
|
|
|
|
|
PRINT_STORAGE(draw_indirect);
|
|
|
|
|
#undef PRINT_STORAGE
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 10:46:50 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
2024-05-21 17:34:55 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Debug
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2024-11-29 07:52:00 +01:00
|
|
|
void VKRenderGraph::debug_group_begin(const char *name, const ColorTheme4f &color)
|
2024-05-21 17:34:55 +02:00
|
|
|
{
|
2024-11-29 07:52:00 +01:00
|
|
|
ColorTheme4f useColor = color;
|
|
|
|
|
if ((color == blender::gpu::debug::GPU_DEBUG_GROUP_COLOR_DEFAULT) &&
|
|
|
|
|
(debug_.group_stack.size() > 0))
|
|
|
|
|
{
|
|
|
|
|
useColor = debug_.groups[debug_.group_stack.last()].color;
|
|
|
|
|
}
|
|
|
|
|
DebugGroupNameID name_id = debug_.groups.index_of_or_add({std::string(name), useColor});
|
2024-06-13 09:37:17 +02:00
|
|
|
debug_.group_stack.append(name_id);
|
2024-05-21 17:34:55 +02:00
|
|
|
debug_.group_used = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKRenderGraph::debug_group_end()
|
|
|
|
|
{
|
|
|
|
|
debug_.group_stack.pop_last();
|
|
|
|
|
debug_.group_used = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 13:29:34 +02:00
|
|
|
void VKRenderGraph::debug_print(NodeHandle node_handle) const
|
|
|
|
|
{
|
|
|
|
|
std::ostream &os = std::cout;
|
|
|
|
|
os << "NODE:\n";
|
|
|
|
|
const VKRenderGraphNode &node = nodes_[node_handle];
|
|
|
|
|
os << " type:" << node.type << "\n";
|
|
|
|
|
|
|
|
|
|
const VKRenderGraphNodeLinks &links = links_[node_handle];
|
|
|
|
|
os << " inputs:\n";
|
|
|
|
|
for (const VKRenderGraphLink &link : links.inputs) {
|
|
|
|
|
os << " ";
|
|
|
|
|
link.debug_print(os, resources_);
|
|
|
|
|
os << "\n";
|
|
|
|
|
}
|
|
|
|
|
os << " outputs:\n";
|
|
|
|
|
for (const VKRenderGraphLink &link : links.outputs) {
|
|
|
|
|
os << " ";
|
|
|
|
|
link.debug_print(os, resources_);
|
|
|
|
|
os << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 12:00:21 +01:00
|
|
|
std::string VKRenderGraph::full_debug_group(NodeHandle node_handle) const
|
|
|
|
|
{
|
|
|
|
|
if ((G.debug & G_DEBUG_GPU) == 0) {
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugGroupID debug_group = debug_.node_group_map[node_handle];
|
|
|
|
|
if (debug_group == -1) {
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
for (const VKRenderGraph::DebugGroupNameID &name_id : debug_.used_groups[debug_group]) {
|
2024-11-29 08:16:13 +01:00
|
|
|
ss << "/" << debug_.groups[name_id].name;
|
2024-11-28 12:00:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 17:34:55 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
2024-04-19 10:46:50 +02:00
|
|
|
} // namespace blender::gpu::render_graph
|