From 5c9ce9d066cbfa12e01e411fd5c46bd7043a74b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 5 Feb 2022 22:47:10 +0100 Subject: DRW: Make use of shader shared header --- source/blender/draw/intern/draw_manager.c | 2 +- source/blender/draw/intern/draw_manager.h | 30 +++---------------------- source/blender/draw/intern/draw_manager_data.c | 10 ++++----- source/blender/draw/intern/draw_manager_exec.c | 6 ++--- source/blender/draw/intern/draw_shader_shared.h | 9 ++++++++ 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 1249004eda0..271b1e01fad 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -630,7 +630,7 @@ static void drw_manager_init(DRWManager *dst, GPUViewport *viewport, const int s } if (G_draw.view_ubo == NULL) { - G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(DRWViewUboStorage), NULL, "G_draw.view_ubo"); + G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(ViewInfos), NULL, "G_draw.view_ubo"); } if (dst->draw_list == NULL) { diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index f7fb50188f3..7981563a9c1 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -42,6 +42,7 @@ #include "GPU_viewport.h" #include "draw_instance_data.h" +#include "draw_shader_shared.h" #ifdef __cplusplus extern "C" { @@ -426,38 +427,13 @@ struct DRWPass { char name[MAX_PASS_NAME]; }; -/* keep in sync with viewBlock */ -typedef struct DRWViewUboStorage { - /* View matrices */ - float persmat[4][4]; - float persinv[4][4]; - float viewmat[4][4]; - float viewinv[4][4]; - float winmat[4][4]; - float wininv[4][4]; - - float clipplanes[6][4]; - float viewvecs[2][4]; - /* Should not be here. Not view dependent (only main view). */ - float viewcamtexcofac[4]; - float viewport_size[2]; - float viewport_size_inv[2]; - - /** Frustum culling data. */ - /** NOTE: vec3 arrays are paded to vec4. */ - float frustum_corners[8][4]; - float frustum_planes[6][4]; -} DRWViewUboStorage; - -BLI_STATIC_ASSERT_ALIGN(DRWViewUboStorage, 16) - #define MAX_CULLED_VIEWS 32 struct DRWView { /** Parent view if this is a sub view. NULL otherwise. */ struct DRWView *parent; - DRWViewUboStorage storage; + ViewInfos storage; /** Number of active clipplanes. */ int clip_planes_len; /** Does culling result needs to be updated. */ @@ -647,7 +623,7 @@ typedef struct DRWManager { uint primary_view_ct; /** TODO(@fclem): Remove this. Only here to support * shaders without common_view_lib.glsl */ - DRWViewUboStorage view_storage_cpy; + ViewInfos view_storage_cpy; #ifdef USE_GPU_SELECT uint select_id; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index fd239499ca7..378e1dac149 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -1841,7 +1841,7 @@ static void draw_frustum_bound_sphere_calc(const BoundBox *bbox, } } -static void draw_view_matrix_state_update(DRWViewUboStorage *storage, +static void draw_view_matrix_state_update(ViewInfos *storage, const float viewmat[4][4], const float winmat[4][4]) { @@ -2061,7 +2061,7 @@ void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len) BLI_assert(plane_len <= MAX_CLIP_PLANES); view->clip_planes_len = plane_len; if (plane_len > 0) { - memcpy(view->storage.clipplanes, planes, sizeof(float[4]) * plane_len); + memcpy(view->storage.clip_planes, planes, sizeof(float[4]) * plane_len); } } @@ -2124,21 +2124,21 @@ float DRW_view_far_distance_get(const DRWView *view) void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse) { view = (view) ? view : DST.view_default; - const DRWViewUboStorage *storage = &view->storage; + const ViewInfos *storage = &view->storage; copy_m4_m4(mat, (inverse) ? storage->viewinv : storage->viewmat); } void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse) { view = (view) ? view : DST.view_default; - const DRWViewUboStorage *storage = &view->storage; + const ViewInfos *storage = &view->storage; copy_m4_m4(mat, (inverse) ? storage->wininv : storage->winmat); } void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse) { view = (view) ? view : DST.view_default; - const DRWViewUboStorage *storage = &view->storage; + const ViewInfos *storage = &view->storage; copy_m4_m4(mat, (inverse) ? storage->persinv : storage->persmat); } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index ac44eda0fce..1b80a665b29 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -1074,10 +1074,10 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) static void drw_update_view(const float viewport_size[2]) { - DRWViewUboStorage *storage = &DST.view_active->storage; + ViewInfos *storage = &DST.view_active->storage; copy_v2_v2(storage->viewport_size, viewport_size); - copy_v2_v2(storage->viewport_size_inv, viewport_size); - invert_v2(storage->viewport_size_inv); + copy_v2_v2(storage->viewport_size_inverse, viewport_size); + invert_v2(storage->viewport_size_inverse); /* TODO(fclem): update a big UBO and only bind ranges here. */ GPU_uniformbuf_update(G_draw.view_ubo, &DST.view_active->storage); diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index b19d4542b22..a73cb4ad5b6 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -1,6 +1,10 @@ #ifndef GPU_SHADER # include "GPU_shader_shared_utils.h" + +typedef struct ViewInfos ViewInfos; +typedef struct ObjectMatrices ObjectMatrices; +typedef struct ObjectInfos ObjectInfos; #endif #define DRW_SHADER_SHARED_H @@ -23,6 +27,11 @@ struct ViewInfos { float2 viewport_size; float2 viewport_size_inverse; + + /** Frustum culling data. */ + /** NOTE: vec3 arrays are paded to vec4. */ + float4 frustum_corners[8]; + float4 frustum_planes[6]; }; BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16) -- cgit v1.2.3