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-10-05 22:54:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-10-07 13:43:09 +0300
commit055680a89e4b37662daf0c397539866a42c6d54a (patch)
treeb0a6f4926f4ba72bbf323c1c4eca5799cc55e045
parentf43c2d9abe0f8b6efca8fa803774a065a6749a88 (diff)
DRW: Split ViewCullingData out of ViewInfos
This is in order to reduce the size of ViewInfos and support multi view rendering.
-rw-r--r--source/blender/draw/engines/eevee_next/shaders/infos/eevee_light_culling_info.hh4
-rw-r--r--source/blender/draw/intern/draw_defines.h1
-rw-r--r--source/blender/draw/intern/draw_manager_data.cc8
-rw-r--r--source/blender/draw/intern/draw_shader_shared.h16
-rw-r--r--source/blender/draw/intern/draw_view.cc22
-rw-r--r--source/blender/draw/intern/draw_view.hh2
-rw-r--r--source/blender/draw/intern/shaders/common_intersect_lib.glsl14
-rw-r--r--source/blender/draw/intern/shaders/draw_view_info.hh6
8 files changed, 40 insertions, 33 deletions
diff --git a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_light_culling_info.hh b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_light_culling_info.hh
index 41602426a1d..45232a8c551 100644
--- a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_light_culling_info.hh
+++ b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_light_culling_info.hh
@@ -21,7 +21,7 @@ GPU_SHADER_CREATE_INFO(eevee_light_data)
GPU_SHADER_CREATE_INFO(eevee_light_culling_select)
.do_static_compilation(true)
- .additional_info("eevee_shared", "draw_view")
+ .additional_info("eevee_shared", "draw_view", "draw_view_culling")
.local_group_size(CULLING_SELECT_GROUP_SIZE)
.storage_buf(0, Qualifier::READ_WRITE, "LightCullingData", "light_cull_buf")
.storage_buf(1, Qualifier::READ, "LightData", "in_light_buf[]")
@@ -52,7 +52,7 @@ GPU_SHADER_CREATE_INFO(eevee_light_culling_zbin)
GPU_SHADER_CREATE_INFO(eevee_light_culling_tile)
.do_static_compilation(true)
- .additional_info("eevee_shared", "draw_view")
+ .additional_info("eevee_shared", "draw_view", "draw_view_culling")
.local_group_size(CULLING_TILE_GROUP_SIZE)
.storage_buf(0, Qualifier::READ, "LightCullingData", "light_cull_buf")
.storage_buf(1, Qualifier::READ, "LightData", "light_buf[]")
diff --git a/source/blender/draw/intern/draw_defines.h b/source/blender/draw/intern/draw_defines.h
index 3df7e47cffb..2a50cc6f17b 100644
--- a/source/blender/draw/intern/draw_defines.h
+++ b/source/blender/draw/intern/draw_defines.h
@@ -12,6 +12,7 @@
#pragma once
#define DRW_VIEW_UBO_SLOT 0
+#define DRW_VIEW_CULLING_UBO_SLOT 1
#define DRW_RESOURCE_ID_SLOT 11
#define DRW_OBJ_MAT_SLOT 10
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index 6741d25bcdf..fc4e444e43e 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -2321,14 +2321,6 @@ void DRW_view_update(DRWView *view,
draw_frustum_bound_sphere_calc(
&view->frustum_corners, viewinv, winmat, wininv, &view->frustum_bsphere);
- /* TODO(fclem): Deduplicate. */
- for (int i = 0; i < 8; i++) {
- copy_v3_v3(view->storage.frustum_corners[i], view->frustum_corners.vec[i]);
- }
- for (int i = 0; i < 6; i++) {
- copy_v4_v4(view->storage.frustum_planes[i], view->frustum_planes[i]);
- }
-
#ifdef DRW_DEBUG_CULLING
if (G.debug_value != 0) {
DRW_debug_sphere(
diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h
index c6cd15551b9..13f21323552 100644
--- a/source/blender/draw/intern/draw_shader_shared.h
+++ b/source/blender/draw/intern/draw_shader_shared.h
@@ -7,6 +7,7 @@
# include "GPU_shader_shared_utils.h"
# include "draw_defines.h"
+typedef struct ViewCullingData ViewCullingData;
typedef struct ViewInfos ViewInfos;
typedef struct ObjectMatrices ObjectMatrices;
typedef struct ObjectInfos ObjectInfos;
@@ -50,6 +51,15 @@ typedef enum eObjectInfoFlag eObjectInfoFlag;
* This should be kept in sync with `GPU_ATTR_MAX` */
#define DRW_ATTRIBUTE_PER_CURVES_MAX 15
+struct ViewCullingData {
+ /** \note vec3 array padded to vec4. */
+ /** Frustum corners. */
+ float4 corners[8];
+ float4 planes[6];
+ float4 bound_sphere;
+};
+BLI_STATIC_ASSERT_ALIGN(ViewCullingData, 16)
+
struct ViewInfos {
/* View matrices */
float4x4 viewmat;
@@ -65,12 +75,6 @@ struct ViewInfos {
float2 viewport_size;
float2 viewport_size_inverse;
- /** Frustum culling data. */
- /** \note vec3 array padded to vec4. */
- float4 frustum_corners[8];
- float4 frustum_planes[6];
- float4 frustum_bound_sphere;
-
/** For debugging purpose */
/* Mouse pixel. */
int2 mouse_pixel;
diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc
index 1e739cf0871..bf3505c7645 100644
--- a/source/blender/draw/intern/draw_view.cc
+++ b/source/blender/draw/intern/draw_view.cc
@@ -28,8 +28,8 @@ void View::sync(const float4x4 &view_mat, const float4x4 &win_mat)
update_view_vectors();
- BoundBox &bound_box = *reinterpret_cast<BoundBox *>(&data_.frustum_corners);
- BoundSphere &bound_sphere = *reinterpret_cast<BoundSphere *>(&data_.frustum_bound_sphere);
+ BoundBox &bound_box = *reinterpret_cast<BoundBox *>(&culling_.corners);
+ BoundSphere &bound_sphere = *reinterpret_cast<BoundSphere *>(&culling_.bound_sphere);
frustum_boundbox_calc(bound_box);
frustum_culling_planes_calc();
frustum_culling_sphere_calc(bound_box, bound_sphere);
@@ -83,16 +83,16 @@ void View::frustum_culling_planes_calc()
{
float4x4 persmat = data_.winmat * data_.viewmat;
planes_from_projmat(persmat.ptr(),
- data_.frustum_planes[0],
- data_.frustum_planes[5],
- data_.frustum_planes[1],
- data_.frustum_planes[3],
- data_.frustum_planes[4],
- data_.frustum_planes[2]);
+ culling_.planes[0],
+ culling_.planes[5],
+ culling_.planes[1],
+ culling_.planes[3],
+ culling_.planes[4],
+ culling_.planes[2]);
/* Normalize. */
for (int p = 0; p < 6; p++) {
- data_.frustum_planes[p].w /= normalize_v3(data_.frustum_planes[p]);
+ culling_.planes[p].w /= normalize_v3(culling_.planes[p]);
}
}
@@ -284,9 +284,11 @@ void View::bind()
if (dirty_) {
dirty_ = false;
data_.push_update();
+ culling_.push_update();
}
GPU_uniformbuf_bind(data_, DRW_VIEW_UBO_SLOT);
+ GPU_uniformbuf_bind(culling_, DRW_VIEW_CULLING_UBO_SLOT);
}
void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool debug_freeze)
@@ -294,6 +296,8 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d
if (debug_freeze && frozen_ == false) {
data_freeze_ = static_cast<ViewInfos>(data_);
data_freeze_.push_update();
+ culling_freeze_ = static_cast<ViewCullingData>(culling_);
+ culling_freeze_.push_update();
}
#ifdef DEBUG
if (debug_freeze) {
diff --git a/source/blender/draw/intern/draw_view.hh b/source/blender/draw/intern/draw_view.hh
index 27e7a7a0028..d3cdea46956 100644
--- a/source/blender/draw/intern/draw_view.hh
+++ b/source/blender/draw/intern/draw_view.hh
@@ -26,8 +26,10 @@ class View {
private:
UniformBuffer<ViewInfos> data_;
+ UniformBuffer<ViewCullingData> culling_;
/** Frozen version of data_ used for debugging culling. */
UniformBuffer<ViewInfos> data_freeze_;
+ UniformBuffer<ViewCullingData> culling_freeze_;
/** Result of the visibility computation. 1 bit per resource ID. */
VisibilityBuf visibility_buf_;
diff --git a/source/blender/draw/intern/shaders/common_intersect_lib.glsl b/source/blender/draw/intern/shaders/common_intersect_lib.glsl
index 83223f89277..d1416e220a4 100644
--- a/source/blender/draw/intern/shaders/common_intersect_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_intersect_lib.glsl
@@ -135,7 +135,7 @@ bool intersect_view(Pyramid pyramid)
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
- float test = dot(drw_view.frustum_planes[p], vec4(pyramid.corners[v], 1.0));
+ float test = dot(drw_view_culling.planes[p], vec4(pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -157,7 +157,7 @@ bool intersect_view(Pyramid pyramid)
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
- float test = dot(i_pyramid.planes[p], vec4(drw_view.frustum_corners[v].xyz, 1.0));
+ float test = dot(i_pyramid.planes[p], vec4(drw_view_culling.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -180,7 +180,7 @@ bool intersect_view(Box box)
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
- float test = dot(drw_view.frustum_planes[p], vec4(box.corners[v], 1.0));
+ float test = dot(drw_view_culling.planes[p], vec4(box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -202,7 +202,7 @@ bool intersect_view(Box box)
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
- float test = dot(i_box.planes[p], vec4(drw_view.frustum_corners[v].xyz, 1.0));
+ float test = dot(i_box.planes[p], vec4(drw_view_culling.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -226,7 +226,7 @@ bool intersect_view(IsectBox i_box)
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
- float test = dot(drw_view.frustum_planes[p], vec4(i_box.corners[v], 1.0));
+ float test = dot(drw_view_culling.planes[p], vec4(i_box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -246,7 +246,7 @@ bool intersect_view(IsectBox i_box)
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
- float test = dot(i_box.planes[p], vec4(drw_view.frustum_corners[v].xyz, 1.0));
+ float test = dot(i_box.planes[p], vec4(drw_view_culling.corners[v].xyz, 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
@@ -267,7 +267,7 @@ bool intersect_view(Sphere sphere)
bool intersects = true;
for (int p = 0; p < 6 && intersects; ++p) {
- float dist_to_plane = dot(drw_view.frustum_planes[p], vec4(sphere.center, 1.0));
+ float dist_to_plane = dot(drw_view_culling.planes[p], vec4(sphere.center, 1.0));
if (dist_to_plane < -sphere.radius) {
intersects = false;
}
diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh
index c522c607791..b33deebadd5 100644
--- a/source/blender/draw/intern/shaders/draw_view_info.hh
+++ b/source/blender/draw/intern/shaders/draw_view_info.hh
@@ -48,6 +48,10 @@ GPU_SHADER_CREATE_INFO(draw_view)
.uniform_buf(DRW_VIEW_UBO_SLOT, "ViewInfos", "drw_view", Frequency::PASS)
.typedef_source("draw_shader_shared.h");
+GPU_SHADER_CREATE_INFO(draw_view_culling)
+ .uniform_buf(DRW_VIEW_CULLING_UBO_SLOT, "ViewCullingData", "drw_view_culling")
+ .typedef_source("draw_shader_shared.h");
+
GPU_SHADER_CREATE_INFO(draw_modelmat)
.uniform_buf(8, "ObjectMatrices", "drw_matrices[DRW_RESOURCE_CHUNK_LEN]", Frequency::BATCH)
.define("ModelMatrix", "(drw_matrices[resource_id].model)")
@@ -160,7 +164,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");
+ .additional_info("draw_view", "draw_view_culling");
GPU_SHADER_CREATE_INFO(draw_command_generate)
.do_static_compilation(true)