Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-08-27 11:37:43 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-08-27 11:37:43 +0300
commit6868988a1e409f7fc26e9f5c0b025ec609aa474a (patch)
tree0e1428455bc772a916f1c37cd6fa151b11759054
parent75ef33c7d35f86462ae0e447d87cbba66a01d563 (diff)
Make debug draw/print working with new draw manager
-rw-r--r--source/blender/draw/intern/draw_command.cc8
-rw-r--r--source/blender/draw/intern/draw_defines.h3
-rw-r--r--source/blender/draw/intern/draw_manager.cc26
-rw-r--r--source/blender/draw/intern/draw_manager.hh2
-rw-r--r--source/blender/draw/intern/draw_shader_shared.h2
-rw-r--r--source/blender/draw/intern/shaders/draw_debug_info.hh8
-rw-r--r--source/blender/draw/intern/shaders/draw_view_info.hh2
7 files changed, 41 insertions, 10 deletions
diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc
index bca0fe63b81..004cf0d5c02 100644
--- a/source/blender/draw/intern/draw_command.cc
+++ b/source/blender/draw/intern/draw_command.cc
@@ -572,10 +572,10 @@ void DrawMultiBuf::bind(RecordingState &state,
GPUShader *shader = DRW_shader_draw_command_generate_get();
GPU_shader_bind(shader);
GPU_shader_uniform_1i(shader, "prototype_len", prototype_count_);
- GPU_storagebuf_bind(group_buf_, 0);
- GPU_storagebuf_bind(visibility_buf, 1);
- GPU_storagebuf_bind(prototype_buf_, 2);
- GPU_storagebuf_bind(command_buf_, 3);
+ GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo(shader, "group_buf"));
+ GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo(shader, "visibility_buf"));
+ GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo(shader, "prototype_buf"));
+ GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo(shader, "command_buf"));
GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT);
GPU_compute_dispatch(shader, divide_ceil_u(prototype_count_, DRW_COMMAND_GROUP_SIZE), 1, 1);
if (WORKAROUND_RESOURCE_ID) {
diff --git a/source/blender/draw/intern/draw_defines.h b/source/blender/draw/intern/draw_defines.h
index 00c614a5f46..9ae5b793b83 100644
--- a/source/blender/draw/intern/draw_defines.h
+++ b/source/blender/draw/intern/draw_defines.h
@@ -18,6 +18,9 @@
#define DRW_OBJ_INFOS_SLOT 9
#define DRW_OBJ_ATTR_SLOT 8
+#define DRW_DEBUG_PRINT_SLOT 15
+#define DRW_DEBUG_DRAW_SLOT 14
+
#define DRW_COMMAND_GROUP_SIZE 64
#define DRW_FINALIZE_GROUP_SIZE 64
/* Must be multiple of 32. Set to 32 for shader simplicity. */
diff --git a/source/blender/draw/intern/draw_manager.cc b/source/blender/draw/intern/draw_manager.cc
index accc5e19704..f48f56b80d3 100644
--- a/source/blender/draw/intern/draw_manager.cc
+++ b/source/blender/draw/intern/draw_manager.cc
@@ -8,6 +8,8 @@
#include "BKE_global.h"
#include "GPU_compute.h"
+#include "draw_debug.hh"
+#include "draw_defines.h"
#include "draw_manager.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
@@ -57,24 +59,40 @@ void Manager::end_sync()
bounds_buf.push_update();
infos_buf.push_update();
+ debug_bind();
+
/* Dispatch compute to finalize the resources on GPU. Save a bit of CPU time. */
uint thread_groups = divide_ceil_u(resource_len_, DRW_FINALIZE_GROUP_SIZE);
GPUShader *shader = DRW_shader_draw_resource_finalize_get();
GPU_shader_bind(shader);
GPU_shader_uniform_1i(shader, "resource_len", resource_len_);
- GPU_storagebuf_bind(matrix_buf, 0);
- GPU_storagebuf_bind(bounds_buf, 1);
- GPU_storagebuf_bind(infos_buf, 2);
+ GPU_storagebuf_bind(matrix_buf, GPU_shader_get_ssbo(shader, "matrix_buf"));
+ GPU_storagebuf_bind(bounds_buf, GPU_shader_get_ssbo(shader, "bounds_buf"));
+ GPU_storagebuf_bind(infos_buf, GPU_shader_get_ssbo(shader, "infos_buf"));
GPU_compute_dispatch(shader, thread_groups, 1, 1);
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
GPU_debug_group_end();
}
+void Manager::debug_bind()
+{
+#ifdef DEBUG
+ GPU_storagebuf_bind(drw_debug_gpu_draw_buf_get(), DRW_DEBUG_DRAW_SLOT);
+ GPU_storagebuf_bind(drw_debug_gpu_print_buf_get(), DRW_DEBUG_PRINT_SLOT);
+# ifndef DISABLE_DEBUG_SHADER_PRINT_BARRIER
+ /* Add a barrier to allow multiple shader writing to the same buffer. */
+ GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
+# endif
+#endif
+}
+
void Manager::submit(PassSimple &pass, View &view)
{
view.bind();
+ debug_bind();
+
command::RecordingState state;
pass.draw_commands_buf_.bind(state, pass.headers_, pass.commands_, view.visibility_buf_);
@@ -90,6 +108,8 @@ void Manager::submit(PassMain &pass, View &view)
{
view.bind();
+ debug_bind();
+
view.compute_visibility(bounds_buf, resource_len_);
command::RecordingState state;
diff --git a/source/blender/draw/intern/draw_manager.hh b/source/blender/draw/intern/draw_manager.hh
index 98de25290e0..6b68fbfdb28 100644
--- a/source/blender/draw/intern/draw_manager.hh
+++ b/source/blender/draw/intern/draw_manager.hh
@@ -132,6 +132,8 @@ class Manager {
/** TODO(fclem): The following should become private at some point. */
void begin_sync();
void end_sync();
+
+ void debug_bind();
};
inline ResourceHandle Manager::resource_handle(const ObjectRef ref)
diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h
index 0747ddfe9f0..c432638e218 100644
--- a/source/blender/draw/intern/draw_shader_shared.h
+++ b/source/blender/draw/intern/draw_shader_shared.h
@@ -152,6 +152,8 @@ struct ObjectBounds {
float4 bounding_corners[4];
/** Bounding sphere derived from the bounding corner. Computed on GPU. */
float4 bounding_sphere;
+ /** Radius of the inscribed sphere derived from the bounding corner. Computed on GPU. */
+#define _inner_sphere_radius bounding_corners[3].w
#if !defined(GPU_SHADER) && defined(__cplusplus)
void sync();
diff --git a/source/blender/draw/intern/shaders/draw_debug_info.hh b/source/blender/draw/intern/shaders/draw_debug_info.hh
index 893a5e537d9..ce450bb1210 100644
--- a/source/blender/draw/intern/shaders/draw_debug_info.hh
+++ b/source/blender/draw/intern/shaders/draw_debug_info.hh
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "draw_defines.h"
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
@@ -10,7 +11,7 @@
GPU_SHADER_CREATE_INFO(draw_debug_print)
.typedef_source("draw_shader_shared.h")
- .storage_buf(7, Qualifier::READ_WRITE, "uint", "drw_debug_print_buf[]");
+ .storage_buf(DRW_DEBUG_PRINT_SLOT, Qualifier::READ_WRITE, "uint", "drw_debug_print_buf[]");
GPU_SHADER_INTERFACE_INFO(draw_debug_print_display_iface, "").flat(Type::UINT, "char_index");
@@ -34,7 +35,10 @@ GPU_SHADER_CREATE_INFO(draw_debug_print_display)
GPU_SHADER_CREATE_INFO(draw_debug_draw)
.typedef_source("draw_shader_shared.h")
- .storage_buf(6, Qualifier::READ_WRITE, "DRWDebugVert", "drw_debug_verts_buf[]");
+ .storage_buf(DRW_DEBUG_DRAW_SLOT,
+ Qualifier::READ_WRITE,
+ "DRWDebugVert",
+ "drw_debug_verts_buf[]");
GPU_SHADER_INTERFACE_INFO(draw_debug_draw_display_iface, "interp").flat(Type::VEC4, "color");
diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh
index da7605c51c8..c016ff1a8d1 100644
--- a/source/blender/draw/intern/shaders/draw_view_info.hh
+++ b/source/blender/draw/intern/shaders/draw_view_info.hh
@@ -160,7 +160,7 @@ GPU_SHADER_CREATE_INFO(draw_visibility_compute)
.storage_buf(1, Qualifier::READ_WRITE, "uint", "visibility_buf[]")
.push_constant(Type::INT, "resource_len")
.compute_source("draw_visibility_comp.glsl")
- .additional_info("draw_view", "draw_debug_print");
+ .additional_info("draw_view");
GPU_SHADER_CREATE_INFO(draw_command_generate)
.do_static_compilation(true)