This allows much easier debugging of shader programs.
Usage is as simple as adding `printf` calls inside shaders.
example: `printf("Formating %d\n", my_var);`
Contrary to the `drw_print`, this is not limited
to draw manager shader dispatch/draws. It is compatible
with any shader inside blender.
Most notably, this doesn't need a viewport to display.
So this can be used to debug render pipeline.
Data formating is currently limited to only `%x`, `%d`,
`%u` and `%f`. This could be easily extended if this is
really needed.
There is no type checking, so values are directly reinterpreted
as specified by the printf format.
The current approach for making this work is to bind a
storage buffer inside `GPU_shader_bind`, making it
available to any shader that needs it. The storage buffer
is downloaded back to CPU after a frame or a render
step and the content printed to the console.
This scheduling means that you cannot rely on these printfs
to detect crashes. We could add a mode to force flushing
at shader binding to avoid this limitation.
The values are written from the shaders in binary form and
only formated on the CPU. This avoid issues with manual
printing like with `drw_print`.
Pull Request: https://projects.blender.org/blender/blender/pulls/125071
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
/* SPDX-FileCopyrightText: 2021 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*
|
|
* Shader source dependency builder that make possible to support #include directive inside the
|
|
* shader files.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_string_ref.hh"
|
|
#include "BLI_vector.hh"
|
|
|
|
#include "gpu_shader_create_info.hh"
|
|
|
|
void gpu_shader_dependency_init();
|
|
|
|
void gpu_shader_dependency_exit();
|
|
|
|
namespace blender::gpu::shader {
|
|
|
|
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull source_name);
|
|
|
|
/* Returns true is any shader code has a printf statement. */
|
|
bool gpu_shader_dependency_has_printf();
|
|
|
|
bool gpu_shader_dependency_force_gpu_print_injection();
|
|
|
|
struct PrintfFormat {
|
|
struct Block {
|
|
enum ArgumentType {
|
|
NONE = 0,
|
|
UINT,
|
|
INT,
|
|
FLOAT,
|
|
} type = NONE;
|
|
std::string fmt;
|
|
};
|
|
|
|
Vector<Block> format_blocks;
|
|
std::string format_str;
|
|
};
|
|
|
|
const PrintfFormat &gpu_shader_dependency_get_printf_format(uint32_t format_hash);
|
|
|
|
Vector<const char *> gpu_shader_dependency_get_resolved_source(const StringRefNull source_name);
|
|
StringRefNull gpu_shader_dependency_get_source(const StringRefNull source_name);
|
|
|
|
/**
|
|
* \brief Find the name of the file from which the given string was generated.
|
|
* \return filename or empty string.
|
|
* \note source_string needs to be identical to the one given by gpu_shader_dependency_get_source()
|
|
*/
|
|
StringRefNull gpu_shader_dependency_get_filename_from_source_string(
|
|
const StringRefNull source_string);
|
|
|
|
} // namespace blender::gpu::shader
|