[Bf-blender-cvs] [d126ffbea4f] blender2.8: DRW: Use static list (array) of texture/ubo to track bound textures/ubos.
Clément Foucault
noreply at git.blender.org
Mon Sep 11 23:18:03 CEST 2017
Commit: d126ffbea4fc549072100022c8be15bd4e3f62ca
Author: Clément Foucault
Date: Mon Sep 11 23:15:29 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBd126ffbea4fc549072100022c8be15bd4e3f62ca
DRW: Use static list (array) of texture/ubo to track bound textures/ubos.
This is in order to use the same texture on multiple sampler.
Also texture counter is reset after each shading group. This mimics the previous behaviour.
===================================================================
M source/blender/draw/engines/clay/clay_engine.c
M source/blender/draw/intern/draw_manager.c
M source/blender/draw/modes/object_mode.c
M source/blender/gpu/GPU_uniformbuffer.h
M source/blender/gpu/intern/gpu_uniformbuffer.c
===================================================================
diff --git a/source/blender/draw/engines/clay/clay_engine.c b/source/blender/draw/engines/clay/clay_engine.c
index 44178f66563..6e98b9e5ae4 100644
--- a/source/blender/draw/engines/clay/clay_engine.c
+++ b/source/blender/draw/engines/clay/clay_engine.c
@@ -503,8 +503,9 @@ static void CLAY_engine_init(void *vedata)
}
}
-static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *UNUSED(vedata), DRWPass *pass, int *material_id, bool use_flat)
+static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *vedata, DRWPass *pass, int *material_id, bool use_flat)
{
+ CLAY_StorageList *stl = vedata->stl;
CLAY_SceneLayerData *sldata = CLAY_scene_layer_data_get();
DRWShadingGroup *grp = DRW_shgroup_create(use_flat ? e_data.clay_flat_sh : e_data.clay_sh, pass);
@@ -520,16 +521,19 @@ static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *UNUSED(vedata), DRWPass *
DRW_shgroup_uniform_texture(grp, "ssao_jitter", sldata->jitter_tx);
DRW_shgroup_uniform_block(grp, "samples_block", sldata->sampling_ubo);
+ DRW_shgroup_uniform_block(grp, "material_block", stl->mat_ubo);
return grp;
}
-static DRWShadingGroup *CLAY_hair_shgroup_create(DRWPass *pass, int *material_id)
+static DRWShadingGroup *CLAY_hair_shgroup_create(CLAY_Data *vedata, DRWPass *pass, int *material_id)
{
+ CLAY_StorageList *stl = vedata->stl;
DRWShadingGroup *grp = DRW_shgroup_create(e_data.hair_sh, pass);
DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array);
DRW_shgroup_uniform_int(grp, "mat_id", material_id, 1);
+ DRW_shgroup_uniform_block(grp, "material_block", stl->mat_ubo);
return grp;
}
@@ -679,16 +683,12 @@ static DRWShadingGroup *CLAY_object_shgrp_get(
if (shgrps[id] == NULL) {
shgrps[id] = CLAY_shgroup_create(
vedata, use_flat ? psl->clay_pass_flat : psl->clay_pass, &e_data.ubo_mat_idxs[id], use_flat);
- /* if it's the first shgrp, pass bind the material UBO */
- if (stl->storage->ubo_current_id == 1) {
- DRW_shgroup_uniform_block(shgrps[0], "material_block", stl->mat_ubo);
- }
}
return shgrps[id];
}
-static DRWShadingGroup *CLAY_hair_shgrp_get(Object *ob, CLAY_StorageList *stl, CLAY_PassList *psl)
+static DRWShadingGroup *CLAY_hair_shgrp_get(CLAY_Data *vedata, Object *ob, CLAY_StorageList *stl, CLAY_PassList *psl)
{
DRWShadingGroup **hair_shgrps = stl->storage->hair_shgrps;
@@ -698,11 +698,7 @@ static DRWShadingGroup *CLAY_hair_shgrp_get(Object *ob, CLAY_StorageList *stl, C
int hair_id = hair_mat_in_ubo(stl->storage, &hair_mat_ubo_test);
if (hair_shgrps[hair_id] == NULL) {
- hair_shgrps[hair_id] = CLAY_hair_shgroup_create(psl->hair_pass, &e_data.ubo_mat_idxs[hair_id]);
- /* if it's the first shgrp, pass bind the material UBO */
- if (stl->storage->hair_ubo_current_id == 1) {
- DRW_shgroup_uniform_block(hair_shgrps[0], "material_block", stl->hair_mat_ubo);
- }
+ hair_shgrps[hair_id] = CLAY_hair_shgroup_create(vedata, psl->hair_pass, &e_data.ubo_mat_idxs[hair_id]);
}
return hair_shgrps[hair_id];
@@ -830,7 +826,7 @@ static void CLAY_cache_populate(void *vedata, Object *ob)
if (draw_as == PART_DRAW_PATH) {
geom = DRW_cache_particles_get_hair(psys, NULL);
- hair_shgrp = CLAY_hair_shgrp_get(ob, stl, psl);
+ hair_shgrp = CLAY_hair_shgrp_get(vedata, ob, stl, psl);
DRW_shgroup_call_add(hair_shgrp, geom, mat);
}
}
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index bc9cb46168e..aad1f6d9e45 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -181,7 +181,6 @@ struct DRWUniform {
int location;
int length;
int arraysize;
- int bindloc;
const void *value;
};
@@ -219,10 +218,6 @@ struct DRWInterface {
int orcotexfac;
int eye;
int clipplanes;
- /* Textures */
- int tex_bind; /* next texture binding point */
- /* UBO */
- int ubo_bind; /* next ubo binding point */
/* Dynamic batch */
Gwn_Batch *instance_batch; /* contains instances attributes */
GLuint instance_vbo; /* same as instance_batch but generated from DRWCalls */
@@ -327,8 +322,10 @@ enum {
static struct DRWGlobalState {
/* Rendering state */
GPUShader *shader;
- ListBase bound_texs;
- int tex_bind_id;
+ GPUTexture **bound_texs;
+ GPUUniformBuffer **bound_ubos;
+ int bind_tex_inc;
+ int bind_ubo_inc;
/* Managed by `DRW_state_set`, `DRW_state_reset` */
DRWState state;
@@ -659,8 +656,6 @@ static DRWInterface *DRW_interface_create(GPUShader *shader)
interface->attribs_stride = 0;
interface->instance_vbo = 0;
interface->instance_batch = NULL;
- interface->tex_bind = GPU_max_textures() - 1;
- interface->ubo_bind = GPU_max_ubo_binds() - 1;
memset(&interface->vbo_format, 0, sizeof(Gwn_VertFormat));
@@ -681,7 +676,7 @@ static DRWInterface *DRW_interface_duplicate(DRWInterface *interface_src)
#endif
static void DRW_interface_uniform(DRWShadingGroup *shgroup, const char *name,
- DRWUniformType type, const void *value, int length, int arraysize, int bindloc)
+ DRWUniformType type, const void *value, int length, int arraysize)
{
DRWUniform *uni = MEM_mallocN(sizeof(DRWUniform), "DRWUniform");
@@ -698,7 +693,6 @@ static void DRW_interface_uniform(DRWShadingGroup *shgroup, const char *name,
uni->value = value;
uni->length = length;
uni->arraysize = arraysize;
- uni->bindloc = bindloc; /* for textures */
if (uni->location == -1) {
if (G.debug & G_DEBUG)
@@ -1114,102 +1108,77 @@ void DRW_shgroup_attrib_float(DRWShadingGroup *shgroup, const char *name, int si
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
{
- DRWInterface *interface = shgroup->interface;
-
- if (interface->tex_bind < 0) {
- /* TODO alert user */
- printf("Not enough texture slot for %s\n", name);
- return;
- }
-
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_TEXTURE, tex, 0, 1, interface->tex_bind--);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_TEXTURE, tex, 0, 1);
}
void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuffer *ubo)
{
- DRWInterface *interface = shgroup->interface;
-
- /* Be carefull: there is also a limit per shader stage. Usually 1/3 of normal limit. */
- if (interface->ubo_bind < 0) {
- /* TODO alert user */
- printf("Not enough ubo slots for %s\n", name);
- return;
- }
-
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BLOCK, ubo, 0, 1, interface->ubo_bind--);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BLOCK, ubo, 0, 1);
}
void DRW_shgroup_uniform_buffer(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
{
- DRWInterface *interface = shgroup->interface;
-
- if (interface->tex_bind < 0) {
- /* TODO alert user */
- printf("Not enough texture slot for %s\n", name);
- return;
- }
-
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BUFFER, tex, 0, 1, interface->tex_bind--);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BUFFER, tex, 0, 1);
}
void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const bool *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BOOL, value, 1, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BOOL, value, 1, arraysize);
}
void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 1, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 1, arraysize);
}
void DRW_shgroup_uniform_vec2(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 2, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 2, arraysize);
}
void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 3, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 3, arraysize);
}
void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 4, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 4, arraysize);
}
void DRW_shgroup_uniform_short_to_int(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_INT, value, 1, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_INT, value, 1, arraysize);
}
void DRW_shgroup_uniform_short_to_float(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_FLOAT, value, 1, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_FLOAT, value, 1, arraysize);
}
void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 1, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 1, arraysize);
}
void DRW_shgroup_uniform_ivec2(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 2, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 2, arraysize);
}
void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 3, arraysize, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_INT, value, 3, arraysize);
}
void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float *value)
{
- DRW_interface_uniform(shgroup, name, DRW_UNIFORM_MAT3, value, 9, 1, 0);
+ DRW_interface_uniform(shgroup, name, DRW_UNIFORM_MAT3, value, 9, 1);
}
void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float *value
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list