Draw Engine: remove hard coded limit on array sizes

This removes MAX_STORAGE, MAX_BUFFERS, MAX_TEXTURES, MAX_PASSES limits.

Actual memory saving isn't so important, it just means we don't need to
manually bump these based on changes to engines.
This commit is contained in:
Campbell Barton
2017-04-12 19:49:19 +10:00
parent b380f4927e
commit 0c9a2def8b
22 changed files with 163 additions and 109 deletions

View File

@@ -49,6 +49,9 @@ void DRW_engines_register(void);
void DRW_engines_free(void);
void DRW_engine_register(struct DrawEngineType *draw_engine_type);
void DRW_engine_viewport_data_size_get(
const void *engine_type,
int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len);
void DRW_draw_view(const struct bContext *C);

View File

@@ -73,14 +73,12 @@ typedef struct CLAY_Storage {
DRWShadingGroup *shgrps[MAX_CLAY_MAT];
} CLAY_Storage;
/* keep it under MAX_STORAGE */
typedef struct CLAY_StorageList {
struct CLAY_Storage *storage;
struct GPUUniformBuffer *mat_ubo;
struct g_data *g_data;
} CLAY_StorageList;
/* keep it under MAX_BUFFERS */
typedef struct CLAY_FramebufferList {
/* default */
struct GPUFrameBuffer *default_fb;
@@ -88,7 +86,6 @@ typedef struct CLAY_FramebufferList {
struct GPUFrameBuffer *dupli_depth;
} CLAY_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct CLAY_TextureList {
/* default */
struct GPUTexture *color;
@@ -97,7 +94,6 @@ typedef struct CLAY_TextureList {
struct GPUTexture *depth_dup;
} CLAY_TextureList;
/* keep it under MAX_PASSES */
typedef struct CLAY_PassList {
struct DRWPass *depth_pass;
struct DRWPass *depth_pass_cull;
@@ -650,9 +646,12 @@ static void CLAY_engine_free(void)
}
}
static const DrawEngineDataSize CLAY_data_size = DRW_VIEWPORT_DATA_SIZE(CLAY_Data);
DrawEngineType draw_engine_clay_type = {
NULL, NULL,
N_("Clay"),
&CLAY_data_size,
&CLAY_engine_init,
&CLAY_engine_free,
&CLAY_cache_init,

View File

@@ -268,9 +268,12 @@ static void EEVEE_collection_settings_create(RenderEngine *UNUSED(engine), IDPro
// BKE_collection_engine_property_add_int(props, "high_quality_sphere_lamps", false);
}
static const DrawEngineDataSize EEVEE_data_size = DRW_VIEWPORT_DATA_SIZE(EEVEE_Data);
DrawEngineType draw_engine_eevee_type = {
NULL, NULL,
N_("Eevee"),
&EEVEE_data_size,
&EEVEE_engine_init,
&EEVEE_engine_free,
&EEVEE_cache_init,

View File

@@ -32,7 +32,6 @@ struct Object;
#define MAX_SHADOW_CASCADE 8
#define MAX_CASCADE_NUM 4
/* keep it under MAX_PASSES */
typedef struct EEVEE_PassList {
struct DRWPass *shadow_pass;
struct DRWPass *depth_pass;
@@ -41,7 +40,6 @@ typedef struct EEVEE_PassList {
struct DRWPass *tonemap;
} EEVEE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EEVEE_FramebufferList {
struct GPUFrameBuffer *main; /* HDR */
struct GPUFrameBuffer *shadow_cube_fb;
@@ -49,7 +47,6 @@ typedef struct EEVEE_FramebufferList {
struct GPUFrameBuffer *shadow_cascade_fb;
} EEVEE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EEVEE_TextureList {
struct GPUTexture *color; /* R11_G11_B10 */
struct GPUTexture *shadow_depth_cube_pool;
@@ -57,7 +54,6 @@ typedef struct EEVEE_TextureList {
struct GPUTexture *shadow_depth_cascade_pool;
} EEVEE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EEVEE_StorageList {
/* Lamps */
/* XXX this should be per-scenelayer and not per_viewport */

View File

@@ -63,17 +63,38 @@ struct DefaultFramebufferList;
struct DefaultTextureList;
struct LampEngineData;
struct RenderEngineType;
struct ViewportEngineData;
struct ViewportEngineData_Info;
typedef struct DRWUniform DRWUniform;
typedef struct DRWInterface DRWInterface;
typedef struct DRWPass DRWPass;
typedef struct DRWShadingGroup DRWShadingGroup;
#define DRW_VIEWPORT_LIST_SIZE(list) (sizeof(list) == sizeof(char) ? 0 : ((sizeof(list)) / sizeof(void *)))
/* Unused members must be either pass list or 'char *' when not usd. */
#define DRW_VIEWPORT_DATA_SIZE(ty) { \
DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->fbl)), \
DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->txl)), \
DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->psl)), \
DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->stl)) \
}
typedef struct DrawEngineDataSize {
int fbl_len;
int txl_len;
int psl_len;
int stl_len;
} DrawEngineDataSize;
typedef struct DrawEngineType {
struct DrawEngineType *next, *prev;
char idname[32];
const DrawEngineDataSize *vedata_size;
void (*engine_init)(void *vedata);
void (*engine_free)(void);

View File

@@ -1308,6 +1308,7 @@ void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer
}
/* ****************************************** Viewport ******************************************/
static void *DRW_viewport_engine_data_get(void *engine_type)
{
void *data = GPU_viewport_engine_data_get(DST.viewport, engine_type);
@@ -1318,6 +1319,26 @@ static void *DRW_viewport_engine_data_get(void *engine_type)
return data;
}
void DRW_engine_viewport_data_size_get(
const void *engine_type_v,
int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len)
{
const DrawEngineType *engine_type = engine_type_v;
if (r_fbl_len) {
*r_fbl_len = engine_type->vedata_size->fbl_len;
}
if (r_txl_len) {
*r_txl_len = engine_type->vedata_size->txl_len;
}
if (r_psl_len) {
*r_psl_len = engine_type->vedata_size->psl_len;
}
if (r_stl_len) {
*r_stl_len = engine_type->vedata_size->stl_len;
}
}
const float *DRW_viewport_size_get(void)
{
return &DST.size[0];
@@ -1739,7 +1760,7 @@ static void DRW_debug_gpu_stats(void)
draw_stat(&rect, 0, v, engine->idname, sizeof(engine->idname));
v++;
for (int i = 0; i < MAX_PASSES; ++i) {
for (int i = 0; i < engine->vedata_size->psl_len; ++i) {
DRWPass *pass = data->psl->passes[i];
if (pass != NULL) {
GLuint64 time;

View File

@@ -35,24 +35,22 @@
extern GlobalsUboStorage ts;
/* *********** LISTS *********** */
/* keep it under MAX_PASSES */
typedef struct EDIT_ARMATURE_PassList {
struct DRWPass *bone_solid;
struct DRWPass *bone_wire;
struct DRWPass *relationship;
} EDIT_ARMATURE_PassList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_ARMATURE_StorageList {
struct g_data *g_data;
} EDIT_ARMATURE_StorageList;
typedef struct EDIT_ARMATURE_Data {
void *engine_type;
void *fbl;
void *txl;
char *fbl;
char *txl;
EDIT_ARMATURE_PassList *psl;
void *stl;
EDIT_ARMATURE_StorageList *stl;
} EDIT_ARMATURE_Data;
/* *********** STATIC *********** */
@@ -126,9 +124,12 @@ void EDIT_ARMATURE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_ARMATURE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_ARMATURE_Data);
DrawEngineType draw_engine_edit_armature_type = {
NULL, NULL,
N_("EditArmatureMode"),
&EDIT_ARMATURE_data_size,
NULL,
NULL,
&EDIT_ARMATURE_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and EDIT_CURVE_cache_init()
* for EDIT_CURVE_PassList */
/* keep it under MAX_PASSES */
typedef struct EDIT_CURVE_PassList {
/* Declare all passes here and init them in
* EDIT_CURVE_cache_init().
@@ -54,14 +53,12 @@ typedef struct EDIT_CURVE_PassList {
struct DRWPass *pass;
} EDIT_CURVE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_CURVE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} EDIT_CURVE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_CURVE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct EDIT_CURVE_TextureList {
struct GPUTexture *texture;
} EDIT_CURVE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_CURVE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -259,9 +255,12 @@ void EDIT_CURVE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_CURVE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_CURVE_Data);
DrawEngineType draw_engine_edit_curve_type = {
NULL, NULL,
N_("EditCurveMode"),
&EDIT_CURVE_data_size,
&EDIT_CURVE_engine_init,
&EDIT_CURVE_engine_free,
&EDIT_CURVE_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and EDIT_LATTICE_cache_init()
* for EDIT_LATTICE_PassList */
/* keep it under MAX_PASSES */
typedef struct EDIT_LATTICE_PassList {
/* Declare all passes here and init them in
* EDIT_LATTICE_cache_init().
@@ -54,14 +53,12 @@ typedef struct EDIT_LATTICE_PassList {
struct DRWPass *pass;
} EDIT_LATTICE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_LATTICE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} EDIT_LATTICE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_LATTICE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct EDIT_LATTICE_TextureList {
struct GPUTexture *texture;
} EDIT_LATTICE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_LATTICE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void EDIT_LATTICE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_LATTICE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_LATTICE_Data);
DrawEngineType draw_engine_edit_lattice_type = {
NULL, NULL,
N_("EditLatticeMode"),
&EDIT_LATTICE_data_size,
&EDIT_LATTICE_engine_init,
&EDIT_LATTICE_engine_free,
&EDIT_LATTICE_cache_init,

View File

@@ -54,7 +54,6 @@ extern char datatoc_common_globals_lib_glsl[];
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
/* *********** LISTS *********** */
/* keep it under MAX_PASSES */
typedef struct EDIT_MESH_PassList {
struct DRWPass *depth_hidden_wire;
struct DRWPass *edit_face_overlay;
@@ -64,18 +63,15 @@ typedef struct EDIT_MESH_PassList {
struct DRWPass *normals;
} EDIT_MESH_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_MESH_FramebufferList {
struct GPUFrameBuffer *occlude_wire_fb;
} EDIT_MESH_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_MESH_TextureList {
struct GPUTexture *occlude_wire_depth_tx;
struct GPUTexture *occlude_wire_color_tx;
} EDIT_MESH_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_MESH_StorageList {
struct g_data *g_data;
} EDIT_MESH_StorageList;
@@ -85,7 +81,7 @@ typedef struct EDIT_MESH_Data {
EDIT_MESH_FramebufferList *fbl;
EDIT_MESH_TextureList *txl;
EDIT_MESH_PassList *psl;
void *stl;
EDIT_MESH_StorageList *stl;
} EDIT_MESH_Data;
/* *********** STATIC *********** */
@@ -529,9 +525,12 @@ static void EDIT_MESH_engine_free(void)
DRW_shader_free(e_data.normals_sh);
}
static const DrawEngineDataSize EDIT_MESH_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_MESH_Data);
DrawEngineType draw_engine_edit_mesh_type = {
NULL, NULL,
N_("EditMeshMode"),
&EDIT_MESH_data_size,
&EDIT_MESH_engine_init,
&EDIT_MESH_engine_free,
&EDIT_MESH_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and EDIT_METABALL_cache_init()
* for EDIT_METABALL_PassList */
/* keep it under MAX_PASSES */
typedef struct EDIT_METABALL_PassList {
/* Declare all passes here and init them in
* EDIT_METABALL_cache_init().
@@ -54,14 +53,12 @@ typedef struct EDIT_METABALL_PassList {
struct DRWPass *pass;
} EDIT_METABALL_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_METABALL_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} EDIT_METABALL_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_METABALL_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct EDIT_METABALL_TextureList {
struct GPUTexture *texture;
} EDIT_METABALL_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_METABALL_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void EDIT_METABALL_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_METABALL_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_METABALL_Data);
DrawEngineType draw_engine_edit_metaball_type = {
NULL, NULL,
N_("EditMetaballMode"),
&EDIT_METABALL_data_size,
&EDIT_METABALL_engine_init,
&EDIT_METABALL_engine_free,
&EDIT_METABALL_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and EDIT_SURFACE_cache_init()
* for EDIT_SURFACE_PassList */
/* keep it under MAX_PASSES */
typedef struct EDIT_SURFACE_PassList {
/* Declare all passes here and init them in
* EDIT_SURFACE_cache_init().
@@ -54,14 +53,12 @@ typedef struct EDIT_SURFACE_PassList {
struct DRWPass *pass;
} EDIT_SURFACE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_SURFACE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} EDIT_SURFACE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_SURFACE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct EDIT_SURFACE_TextureList {
struct GPUTexture *texture;
} EDIT_SURFACE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_SURFACE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void EDIT_SURFACE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_SURFACE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_SURFACE_Data);
DrawEngineType draw_engine_edit_surface_type = {
NULL, NULL,
N_("EditSurfaceMode"),
&EDIT_SURFACE_data_size,
&EDIT_SURFACE_engine_init,
&EDIT_SURFACE_engine_free,
&EDIT_SURFACE_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and EDIT_TEXT_cache_init()
* for EDIT_TEXT_PassList */
/* keep it under MAX_PASSES */
typedef struct EDIT_TEXT_PassList {
/* Declare all passes here and init them in
* EDIT_TEXT_cache_init().
@@ -54,14 +53,12 @@ typedef struct EDIT_TEXT_PassList {
struct DRWPass *pass;
} EDIT_TEXT_PassList;
/* keep it under MAX_BUFFERS */
typedef struct EDIT_TEXT_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} EDIT_TEXT_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct EDIT_TEXT_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct EDIT_TEXT_TextureList {
struct GPUTexture *texture;
} EDIT_TEXT_TextureList;
/* keep it under MAX_STORAGE */
typedef struct EDIT_TEXT_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void EDIT_TEXT_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize EDIT_TEXT_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_TEXT_Data);
DrawEngineType draw_engine_edit_text_type = {
NULL, NULL,
N_("EditTextMode"),
&EDIT_TEXT_data_size,
&EDIT_TEXT_engine_init,
&EDIT_TEXT_engine_free,
&EDIT_TEXT_cache_init,

View File

@@ -60,7 +60,6 @@ extern char datatoc_object_grid_vert_glsl[];
extern char datatoc_common_globals_lib_glsl[];
/* *********** LISTS *********** */
/* keep it under MAX_PASSES */
typedef struct OBJECT_PassList {
struct DRWPass *non_meshes;
struct DRWPass *ob_center;
@@ -78,30 +77,27 @@ typedef struct OBJECT_PassList {
struct DRWPass *bone_wire;
} OBJECT_PassList;
/* keep it under MAX_BUFFERS */
typedef struct OBJECT_FramebufferList {
struct GPUFrameBuffer *outlines;
struct GPUFrameBuffer *blur;
} OBJECT_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct OBJECT_TextureList {
struct GPUTexture *outlines_depth_tx;
struct GPUTexture *outlines_color_tx;
struct GPUTexture *outlines_blur_tx;
} OBJECT_TextureList;
/* keep it under MAX_STORAGE */
typedef struct OBJECT_StorageList {
struct g_data *g_data;
} OBJECT_StorageList;
typedef struct OBJECT_Data {
void *engine_type;
void *fbl;
void *txl;
OBJECT_FramebufferList *fbl;
OBJECT_TextureList *txl;
OBJECT_PassList *psl;
void *stl;
OBJECT_StorageList *stl;
} OBJECT_Data;
/* *********** STATIC *********** */
@@ -1218,9 +1214,12 @@ void OBJECT_collection_settings_create(IDProperty *props)
BKE_collection_engine_property_add_int(props, "show_backface_culling", false);
}
static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data);
DrawEngineType draw_engine_object_type = {
NULL, NULL,
N_("ObjectMode"),
&OBJECT_data_size,
&OBJECT_engine_init,
&OBJECT_engine_free,
&OBJECT_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and PAINT_TEXTURE_cache_init()
* for PAINT_TEXTURE_PassList */
/* keep it under MAX_PASSES */
typedef struct PAINT_TEXTURE_PassList {
/* Declare all passes here and init them in
* PAINT_TEXTURE_cache_init().
@@ -54,14 +53,12 @@ typedef struct PAINT_TEXTURE_PassList {
struct DRWPass *pass;
} PAINT_TEXTURE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct PAINT_TEXTURE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} PAINT_TEXTURE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct PAINT_TEXTURE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct PAINT_TEXTURE_TextureList {
struct GPUTexture *texture;
} PAINT_TEXTURE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct PAINT_TEXTURE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void PAINT_TEXTURE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize PAINT_TEXTURE_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_TEXTURE_Data);
DrawEngineType draw_engine_paint_texture_type = {
NULL, NULL,
N_("PaintTextureMode"),
&PAINT_TEXTURE_data_size,
&PAINT_TEXTURE_engine_init,
&PAINT_TEXTURE_engine_free,
&PAINT_TEXTURE_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and PAINT_VERTEX_cache_init()
* for PAINT_VERTEX_PassList */
/* keep it under MAX_PASSES */
typedef struct PAINT_VERTEX_PassList {
/* Declare all passes here and init them in
* PAINT_VERTEX_cache_init().
@@ -54,14 +53,12 @@ typedef struct PAINT_VERTEX_PassList {
struct DRWPass *pass;
} PAINT_VERTEX_PassList;
/* keep it under MAX_BUFFERS */
typedef struct PAINT_VERTEX_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} PAINT_VERTEX_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct PAINT_VERTEX_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct PAINT_VERTEX_TextureList {
struct GPUTexture *texture;
} PAINT_VERTEX_TextureList;
/* keep it under MAX_STORAGE */
typedef struct PAINT_VERTEX_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -257,9 +253,12 @@ void PAINT_VERTEX_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize PAINT_VERTEX_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_VERTEX_Data);
DrawEngineType draw_engine_paint_vertex_type = {
NULL, NULL,
N_("PaintVertexMode"),
&PAINT_VERTEX_data_size,
&PAINT_VERTEX_engine_init,
&PAINT_VERTEX_engine_free,
&PAINT_VERTEX_cache_init,

View File

@@ -46,7 +46,6 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
* initialize most of them and PAINT_WEIGHT_cache_init()
* for PAINT_WEIGHT_PassList */
/* keep it under MAX_PASSES */
typedef struct PAINT_WEIGHT_PassList {
/* Declare all passes here and init them in
* PAINT_WEIGHT_cache_init().
@@ -54,14 +53,12 @@ typedef struct PAINT_WEIGHT_PassList {
struct DRWPass *pass;
} PAINT_WEIGHT_PassList;
/* keep it under MAX_BUFFERS */
typedef struct PAINT_WEIGHT_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} PAINT_WEIGHT_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct PAINT_WEIGHT_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -69,7 +66,6 @@ typedef struct PAINT_WEIGHT_TextureList {
struct GPUTexture *texture;
} PAINT_WEIGHT_TextureList;
/* keep it under MAX_STORAGE */
typedef struct PAINT_WEIGHT_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -254,9 +250,12 @@ void PAINT_WEIGHT_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize PAINT_WEIGHT_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_WEIGHT_Data);
DrawEngineType draw_engine_paint_weight_type = {
NULL, NULL,
N_("PaintWeightMode"),
&PAINT_WEIGHT_data_size,
&PAINT_WEIGHT_engine_init,
&PAINT_WEIGHT_engine_free,
&PAINT_WEIGHT_cache_init,

View File

@@ -40,7 +40,6 @@
* initialize most of them and PARTICLE_cache_init()
* for PARTICLE_PassList */
/* keep it under MAX_PASSES */
typedef struct PARTICLE_PassList {
/* Declare all passes here and init them in
* PARTICLE_cache_init().
@@ -48,14 +47,12 @@ typedef struct PARTICLE_PassList {
struct DRWPass *pass;
} PARTICLE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct PARTICLE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} PARTICLE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct PARTICLE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -63,7 +60,6 @@ typedef struct PARTICLE_TextureList {
struct GPUTexture *texture;
} PARTICLE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct PARTICLE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -252,9 +248,12 @@ void PARTICLE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize PARTICLE_data_size = DRW_VIEWPORT_DATA_SIZE(PARTICLE_Data);
DrawEngineType draw_engine_particle_type = {
NULL, NULL,
N_("ParticleMode"),
&PARTICLE_data_size,
&PARTICLE_engine_init,
&PARTICLE_engine_free,
&PARTICLE_cache_init,

View File

@@ -40,7 +40,6 @@
* initialize most of them and POSE_cache_init()
* for POSE_PassList */
/* keep it under MAX_PASSES */
typedef struct POSE_PassList {
/* Declare all passes here and init them in
* POSE_cache_init().
@@ -48,14 +47,12 @@ typedef struct POSE_PassList {
struct DRWPass *pass;
} POSE_PassList;
/* keep it under MAX_BUFFERS */
typedef struct POSE_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} POSE_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct POSE_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -63,7 +60,6 @@ typedef struct POSE_TextureList {
struct GPUTexture *texture;
} POSE_TextureList;
/* keep it under MAX_STORAGE */
typedef struct POSE_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -252,9 +248,12 @@ void POSE_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize POSE_data_size = DRW_VIEWPORT_DATA_SIZE(POSE_Data);
DrawEngineType draw_engine_pose_type = {
NULL, NULL,
N_("PoseMode"),
&POSE_data_size,
&POSE_engine_init,
&POSE_engine_free,
&POSE_cache_init,

View File

@@ -40,7 +40,6 @@
* initialize most of them and SCULPT_cache_init()
* for SCULPT_PassList */
/* keep it under MAX_PASSES */
typedef struct SCULPT_PassList {
/* Declare all passes here and init them in
* SCULPT_cache_init().
@@ -48,14 +47,12 @@ typedef struct SCULPT_PassList {
struct DRWPass *pass;
} SCULPT_PassList;
/* keep it under MAX_BUFFERS */
typedef struct SCULPT_FramebufferList {
/* Contains all framebuffer objects needed by this engine.
* Only contains (GPUFrameBuffer *) */
struct GPUFrameBuffer *fb;
} SCULPT_FramebufferList;
/* keep it under MAX_TEXTURES */
typedef struct SCULPT_TextureList {
/* Contains all framebuffer textures / utility textures
* needed by this engine. Only viewport specific textures
@@ -63,7 +60,6 @@ typedef struct SCULPT_TextureList {
struct GPUTexture *texture;
} SCULPT_TextureList;
/* keep it under MAX_STORAGE */
typedef struct SCULPT_StorageList {
/* Contains any other memory block that the engine needs.
* Only directly MEM_(m/c)allocN'ed blocks because they are
@@ -251,9 +247,12 @@ void SCULPT_collection_settings_create(CollectionEngineSettings *ces)
}
#endif
static const DrawEngineDataSize SCULPT_data_size = DRW_VIEWPORT_DATA_SIZE(SCULPT_Data);
DrawEngineType draw_engine_sculpt_type = {
NULL, NULL,
N_("SculptMode"),
&SCULPT_data_size,
&SCULPT_engine_init,
&SCULPT_engine_free,
&SCULPT_cache_init,

View File

@@ -41,26 +41,21 @@
typedef struct GPUViewport GPUViewport;
#define MAX_BUFFERS 8
#define MAX_TEXTURES 16
#define MAX_PASSES 16
#define MAX_STORAGE 9 /* extend if needed */
/* All FramebufferLists are just the same pointers with different names */
typedef struct FramebufferList {
struct GPUFrameBuffer *framebuffers[MAX_BUFFERS];
struct GPUFrameBuffer *framebuffers[0];
} FramebufferList;
typedef struct TextureList {
struct GPUTexture *textures[MAX_TEXTURES];
struct GPUTexture *textures[0];
} TextureList;
typedef struct PassList {
struct DRWPass *passes[MAX_PASSES];
struct DRWPass *passes[0];
} PassList;
typedef struct StorageList {
void *storage[MAX_STORAGE]; /* custom structs from the engine */
void *storage[0]; /* custom structs from the engine */
} StorageList;
typedef struct ViewportEngineData {
@@ -78,6 +73,13 @@ typedef struct ViewportEngineData {
double background_time;
} ViewportEngineData;
typedef struct ViewportEngineData_Info {
int fbl_len;
int txl_len;
int psl_len;
int stl_len;
} ViewportEngineData_Info;
GPUViewport *GPU_viewport_create(void);
void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect);
void GPU_viewport_unbind(GPUViewport *viewport);

View File

@@ -51,6 +51,9 @@
#include "MEM_guardedalloc.h"
static const int default_fbl_len = (sizeof(DefaultFramebufferList)) / sizeof(void *);
static const int default_txl_len = (sizeof(DefaultTextureList)) / sizeof(void *);
struct GPUViewport {
float pad[4];
@@ -61,19 +64,20 @@ struct GPUViewport {
ListBase data; /* ViewportEngineData wrapped in LinkData */
unsigned int data_hash; /* If hash mismatch we free all ViewportEngineData in this viewport */
FramebufferList *fbl;
TextureList *txl;
DefaultFramebufferList *fbl;
DefaultTextureList *txl;
};
static void GPU_viewport_buffers_free(FramebufferList *fbl, TextureList *txl);
static void GPU_viewport_storage_free(StorageList *stl);
static void GPU_viewport_passes_free(PassList *psl);
static void GPU_viewport_buffers_free(FramebufferList *fbl, int fbl_len, TextureList *txl, int txl_len);
static void GPU_viewport_storage_free(StorageList *stl, int stl_len);
static void GPU_viewport_passes_free(PassList *psl, int psl_len);
GPUViewport *GPU_viewport_create(void)
{
GPUViewport *viewport = MEM_callocN(sizeof(GPUViewport), "GPUViewport");
viewport->fbl = MEM_callocN(sizeof(FramebufferList), "FramebufferList");
viewport->txl = MEM_callocN(sizeof(TextureList), "TextureList");
viewport->fbl = MEM_callocN(sizeof(DefaultFramebufferList), "FramebufferList");
viewport->txl = MEM_callocN(sizeof(DefaultTextureList), "TextureList");
viewport->size[0] = viewport->size[1] = -1;
return viewport;
@@ -83,12 +87,16 @@ void *GPU_viewport_engine_data_create(GPUViewport *viewport, void *engine_type)
{
LinkData *ld = MEM_callocN(sizeof(LinkData), "LinkData");
ViewportEngineData *data = MEM_callocN(sizeof(ViewportEngineData), "ViewportEngineData");
int fbl_len, txl_len, psl_len, stl_len;
DRW_engine_viewport_data_size_get(engine_type, &fbl_len, &txl_len, &psl_len, &stl_len);
data->engine_type = engine_type;
data->fbl = MEM_callocN(sizeof(FramebufferList), "FramebufferList");
data->txl = MEM_callocN(sizeof(TextureList), "TextureList");
data->psl = MEM_callocN(sizeof(PassList), "PassList");
data->stl = MEM_callocN(sizeof(StorageList), "StorageList");
data->fbl = MEM_callocN((sizeof(void *) * fbl_len) + sizeof(FramebufferList), "FramebufferList");
data->txl = MEM_callocN((sizeof(void *) * txl_len) + sizeof(TextureList), "TextureList");
data->psl = MEM_callocN((sizeof(void *) * psl_len) + sizeof(PassList), "PassList");
data->stl = MEM_callocN((sizeof(void *) * stl_len) + sizeof(StorageList), "StorageList");
ld->data = data;
BLI_addtail(&viewport->data, ld);
@@ -98,14 +106,17 @@ void *GPU_viewport_engine_data_create(GPUViewport *viewport, void *engine_type)
static void GPU_viewport_engines_data_free(GPUViewport *viewport)
{
int fbl_len, txl_len, psl_len, stl_len;
LinkData *next;
for (LinkData *link = viewport->data.first; link; link = next) {
next = link->next;
ViewportEngineData *data = link->data;
DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, &psl_len, &stl_len);
GPU_viewport_buffers_free(data->fbl, data->txl);
GPU_viewport_passes_free(data->psl);
GPU_viewport_storage_free(data->stl);
GPU_viewport_buffers_free(data->fbl, fbl_len, data->txl, txl_len);
GPU_viewport_passes_free(data->psl, psl_len);
GPU_viewport_storage_free(data->stl, stl_len);
MEM_freeN(data->fbl);
MEM_freeN(data->txl);
@@ -154,7 +165,9 @@ bool GPU_viewport_cache_validate(GPUViewport *viewport, unsigned int hash)
if (G.debug_value != 666 && G.debug_value != 667) {
for (LinkData *link = viewport->data.first; link; link = link->next) {
ViewportEngineData *data = link->data;
GPU_viewport_passes_free(data->psl);
int psl_len;
DRW_engine_viewport_data_size_get(data->engine_type, NULL, NULL, &psl_len, NULL);
GPU_viewport_passes_free(data->psl, psl_len);
}
dirty = true;
}
@@ -171,8 +184,9 @@ bool GPU_viewport_cache_validate(GPUViewport *viewport, unsigned int hash)
void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
{
DefaultFramebufferList *dfbl = (DefaultFramebufferList *)viewport->fbl;
DefaultTextureList *dtxl = (DefaultTextureList *)viewport->txl;
DefaultFramebufferList *dfbl = viewport->fbl;
DefaultTextureList *dtxl = viewport->txl;
int fbl_len, txl_len;
/* add one pixel because of scissor test */
int rect_w = BLI_rcti_size_x(rect) + 1;
@@ -180,11 +194,14 @@ void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
if (dfbl->default_fb) {
if (rect_w != viewport->size[0] || rect_h != viewport->size[1]) {
GPU_viewport_buffers_free(viewport->fbl, viewport->txl);
GPU_viewport_buffers_free(
(FramebufferList *)viewport->fbl, default_fbl_len,
(TextureList *)viewport->txl, default_txl_len);
for (LinkData *link = viewport->data.first; link; link = link->next) {
ViewportEngineData *data = link->data;
GPU_viewport_buffers_free(data->fbl, data->txl);
DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, NULL, NULL);
GPU_viewport_buffers_free(data->fbl, fbl_len, data->txl, txl_len);
}
}
}
@@ -243,7 +260,7 @@ cleanup:
static void draw_ofs_to_screen(GPUViewport *viewport)
{
DefaultTextureList *dtxl = (DefaultTextureList *)viewport->txl;
DefaultTextureList *dtxl = viewport->txl;
GPUTexture *color = dtxl->color;
@@ -282,7 +299,7 @@ static void draw_ofs_to_screen(GPUViewport *viewport)
void GPU_viewport_unbind(GPUViewport *viewport)
{
DefaultFramebufferList *dfbl = (DefaultFramebufferList *)viewport->fbl;
DefaultFramebufferList *dfbl = viewport->fbl;
if (dfbl->default_fb) {
GPU_framebuffer_texture_unbind(dfbl->default_fb, NULL);
@@ -296,17 +313,18 @@ void GPU_viewport_unbind(GPUViewport *viewport)
}
}
static void GPU_viewport_buffers_free(FramebufferList *fbl, TextureList *txl)
static void GPU_viewport_buffers_free(
FramebufferList *fbl, int fbl_len,
TextureList *txl, int txl_len)
{
int i;
for (i = MAX_BUFFERS - 1; i > -1; --i) {
for (int i = 0; i < fbl_len; i++) {
GPUFrameBuffer *fb = fbl->framebuffers[i];
if (fb) {
GPU_framebuffer_free(fb);
fbl->framebuffers[i] = NULL;
}
}
for (i = MAX_TEXTURES - 1; i > -1; --i) {
for (int i = 0; i < txl_len; i++) {
GPUTexture *tex = txl->textures[i];
if (tex) {
GPU_texture_free(tex);
@@ -315,9 +333,9 @@ static void GPU_viewport_buffers_free(FramebufferList *fbl, TextureList *txl)
}
}
static void GPU_viewport_storage_free(StorageList *stl)
static void GPU_viewport_storage_free(StorageList *stl, int stl_len)
{
for (int i = MAX_STORAGE - 1; i > -1; --i) {
for (int i = 0; i < stl_len; i++) {
void *storage = stl->storage[i];
if (storage) {
MEM_freeN(storage);
@@ -326,9 +344,9 @@ static void GPU_viewport_storage_free(StorageList *stl)
}
}
static void GPU_viewport_passes_free(PassList *psl)
static void GPU_viewport_passes_free(PassList *psl, int psl_len)
{
for (int i = MAX_PASSES - 1; i > -1; --i) {
for (int i = 0; i < psl_len; i++) {
struct DRWPass *pass = psl->passes[i];
if (pass) {
DRW_pass_free(pass);
@@ -342,7 +360,10 @@ void GPU_viewport_free(GPUViewport *viewport)
{
GPU_viewport_engines_data_free(viewport);
GPU_viewport_buffers_free(viewport->fbl, viewport->txl);
GPU_viewport_buffers_free(
(FramebufferList *)viewport->fbl, default_fbl_len,
(TextureList *)viewport->txl, default_txl_len);
MEM_freeN(viewport->fbl);
MEM_freeN(viewport->txl);