2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2020 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-09-14 17:07:37 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*
|
|
|
|
|
* Debug features of OpenGL.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2020-09-14 17:07:37 +02:00
|
|
|
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
|
|
|
|
#include "gpu_context_private.hh"
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_debug.hh"
|
2020-09-14 17:07:37 +02:00
|
|
|
|
2020-09-14 19:52:49 +02:00
|
|
|
using namespace blender;
|
2020-09-14 17:07:37 +02:00
|
|
|
using namespace blender::gpu;
|
|
|
|
|
|
|
|
|
|
void GPU_debug_group_begin(const char *name)
|
|
|
|
|
{
|
2025-02-18 15:36:50 +01:00
|
|
|
if (!(G.debug & G_DEBUG_GPU) && !G.profile_gpu) {
|
2020-09-14 17:07:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-14 19:52:49 +02:00
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
DebugStack &stack = ctx->debug_stack;
|
|
|
|
|
stack.append(StringRef(name));
|
|
|
|
|
ctx->debug_group_begin(name, stack.size());
|
2020-09-14 17:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 00:31:20 -05:00
|
|
|
void GPU_debug_group_end()
|
2020-09-14 17:07:37 +02:00
|
|
|
{
|
2025-02-18 15:36:50 +01:00
|
|
|
if (!(G.debug & G_DEBUG_GPU) && !G.profile_gpu) {
|
2020-09-14 17:07:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-14 19:52:49 +02:00
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
ctx->debug_stack.pop_last();
|
|
|
|
|
ctx->debug_group_end();
|
2020-09-14 17:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
|
|
|
|
|
{
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (ctx == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DebugStack &stack = ctx->debug_stack;
|
2023-12-11 13:54:57 -05:00
|
|
|
if (stack.is_empty()) {
|
2020-09-14 17:07:37 +02:00
|
|
|
r_name_buf[0] = '\0';
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-11 13:37:10 +10:00
|
|
|
size_t len = 0;
|
2020-09-14 19:52:49 +02:00
|
|
|
for (StringRef &name : stack) {
|
2022-05-11 13:37:10 +10:00
|
|
|
len += BLI_snprintf_rlen(r_name_buf + len, name_buf_len - len, "%s > ", name.data());
|
2020-09-14 17:07:37 +02:00
|
|
|
}
|
2022-05-11 13:37:10 +10:00
|
|
|
r_name_buf[len - 3] = '\0';
|
2020-09-16 01:36:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPU_debug_group_match(const char *ref)
|
|
|
|
|
{
|
|
|
|
|
/* Otherwise there will be no names. */
|
|
|
|
|
BLI_assert(G.debug & G_DEBUG_GPU);
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (ctx == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-30 15:24:46 +10:00
|
|
|
const DebugStack &stack = ctx->debug_stack;
|
|
|
|
|
for (const StringRef &name : stack) {
|
2020-09-16 15:24:37 +02:00
|
|
|
if (name == ref) {
|
2020-09-16 01:36:32 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-16 08:54:05 +01:00
|
|
|
|
2024-02-23 10:57:37 +01:00
|
|
|
void GPU_debug_capture_begin(const char *title)
|
2023-03-16 08:54:05 +01:00
|
|
|
{
|
|
|
|
|
/* GPU Frame capture is only enabled when --debug-gpu is specified. */
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (ctx && !ctx->debug_is_capturing) {
|
2024-02-23 10:57:37 +01:00
|
|
|
ctx->debug_is_capturing = ctx->debug_capture_begin(title);
|
2023-03-16 08:54:05 +01:00
|
|
|
/* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
|
|
|
|
|
GPU_finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_debug_capture_end()
|
|
|
|
|
{
|
|
|
|
|
/* GPU Frame capture is only enabled when --debug-gpu is specified. */
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (ctx && ctx->debug_is_capturing) {
|
|
|
|
|
/* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
|
|
|
|
|
GPU_finish();
|
|
|
|
|
ctx->debug_capture_end();
|
|
|
|
|
ctx->debug_is_capturing = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *GPU_debug_capture_scope_create(const char *name)
|
|
|
|
|
{
|
|
|
|
|
/* GPU Frame capture is only enabled when --debug-gpu is specified. */
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU)) {
|
2023-03-17 16:44:01 +11:00
|
|
|
return nullptr;
|
2023-03-16 08:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (!ctx) {
|
2023-03-17 16:44:01 +11:00
|
|
|
return nullptr;
|
2023-03-16 08:54:05 +01:00
|
|
|
}
|
|
|
|
|
return ctx->debug_capture_scope_create(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPU_debug_capture_scope_begin(void *scope)
|
|
|
|
|
{
|
|
|
|
|
/* Early exit if scope does not exist or not in debug mode. */
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU) || !scope) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (!ctx) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Declare beginning of capture scope region. */
|
|
|
|
|
bool scope_capturing = ctx->debug_capture_scope_begin(scope);
|
|
|
|
|
if (scope_capturing && !ctx->debug_is_capturing) {
|
|
|
|
|
/* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
|
|
|
|
|
GPU_finish();
|
|
|
|
|
ctx->debug_is_capturing = true;
|
|
|
|
|
}
|
|
|
|
|
return ctx->debug_is_capturing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_debug_capture_scope_end(void *scope)
|
|
|
|
|
{
|
|
|
|
|
/* Early exit if scope does not exist or not in debug mode. */
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU) || !scope) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context *ctx = Context::get();
|
|
|
|
|
if (!ctx) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If capturing, call GPU_finish to ensure all desired GPU commands occur within the capture
|
|
|
|
|
* boundary. */
|
|
|
|
|
if (ctx->debug_is_capturing) {
|
|
|
|
|
GPU_finish();
|
|
|
|
|
ctx->debug_is_capturing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Declare end of capture scope region. */
|
|
|
|
|
ctx->debug_capture_scope_end(scope);
|
|
|
|
|
}
|
2025-08-27 15:43:09 +02:00
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
|
|
|
|
|
void debug_validate_binding_image_format()
|
|
|
|
|
{
|
|
|
|
|
if (!(G.debug & G_DEBUG_GPU)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto &texture_formats_state = Context::get()->state_manager->image_formats;
|
|
|
|
|
const auto &texture_formats_shader = Context::get()->shader->interface->image_formats_;
|
|
|
|
|
for (int image_unit = 0; image_unit < GPU_MAX_IMAGE; image_unit++) {
|
|
|
|
|
TextureWriteFormat format_state = texture_formats_state[image_unit];
|
|
|
|
|
TextureWriteFormat format_shader = texture_formats_shader[image_unit];
|
|
|
|
|
if (format_state != TextureWriteFormat::Invalid &&
|
|
|
|
|
format_shader == TextureWriteFormat::Invalid)
|
|
|
|
|
{
|
|
|
|
|
/* It is allowed for an image to be bound in the state manager but to be unused in the
|
|
|
|
|
* shader. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (UNLIKELY(texture_formats_shader[image_unit] != texture_formats_state[image_unit])) {
|
|
|
|
|
fprintf(
|
|
|
|
|
stderr,
|
|
|
|
|
"Error in GPU_debug_validate_binding_image_format: Image format mismatch detected for "
|
|
|
|
|
"shader '%s' at binding %d (shader format '%s' vs. bound texture format '%s').\n",
|
|
|
|
|
Context::get()->shader->name_get().c_str(),
|
|
|
|
|
image_unit,
|
|
|
|
|
GPU_texture_format_name(to_texture_format(texture_formats_shader[image_unit])),
|
|
|
|
|
GPU_texture_format_name(to_texture_format(texture_formats_state[image_unit])));
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::gpu
|