DRW: Change UBOs binding logic.
Use the same logic than textures. Also reset bindings only on shader changes.
This commit is contained in:
parent
dfd8a52cd2
commit
41abbc271c
|
@ -438,6 +438,12 @@ static void drw_viewport_var_init(void)
|
|||
if (DST.RST.bound_tex_slots == NULL) {
|
||||
DST.RST.bound_tex_slots = MEM_callocN(sizeof(bool) * GPU_max_textures(), "Bound Texture Slots");
|
||||
}
|
||||
if (DST.RST.bound_ubos == NULL) {
|
||||
DST.RST.bound_ubos = MEM_callocN(sizeof(GPUUniformBuffer *) * GPU_max_ubo_binds(), "Bound GPUUniformBuffer refs");
|
||||
}
|
||||
if (DST.RST.bound_ubo_slots == NULL) {
|
||||
DST.RST.bound_ubo_slots = MEM_callocN(sizeof(bool) * GPU_max_textures(), "Bound Ubo Slots");
|
||||
}
|
||||
|
||||
if (view_ubo == NULL) {
|
||||
view_ubo = DRW_uniformbuffer_create(sizeof(ViewUboStorage), NULL);
|
||||
|
@ -1948,6 +1954,8 @@ void DRW_engines_free(void)
|
|||
|
||||
MEM_SAFE_FREE(DST.RST.bound_texs);
|
||||
MEM_SAFE_FREE(DST.RST.bound_tex_slots);
|
||||
MEM_SAFE_FREE(DST.RST.bound_ubos);
|
||||
MEM_SAFE_FREE(DST.RST.bound_ubo_slots);
|
||||
|
||||
DRW_opengl_context_disable();
|
||||
|
||||
|
|
|
@ -336,6 +336,8 @@ typedef struct DRWManager {
|
|||
GPUTexture **bound_texs;
|
||||
bool *bound_tex_slots;
|
||||
int bind_tex_inc;
|
||||
GPUUniformBuffer **bound_ubos;
|
||||
bool *bound_ubo_slots;
|
||||
int bind_ubo_inc;
|
||||
} RST;
|
||||
} DRWManager;
|
||||
|
|
|
@ -729,11 +729,20 @@ static void bind_texture(GPUTexture *tex)
|
|||
|
||||
static void bind_ubo(GPUUniformBuffer *ubo)
|
||||
{
|
||||
if (DST.RST.bind_ubo_inc < GPU_max_ubo_binds()) {
|
||||
GPU_uniformbuffer_bind(ubo, DST.RST.bind_ubo_inc);
|
||||
DST.RST.bind_ubo_inc++;
|
||||
}
|
||||
else {
|
||||
int bind_num = GPU_uniformbuffer_bindpoint(ubo);
|
||||
if (bind_num == -1) {
|
||||
for (int i = 0; i < GPU_max_ubo_binds(); ++i) {
|
||||
DST.RST.bind_ubo_inc = (DST.RST.bind_ubo_inc + 1) % GPU_max_ubo_binds();
|
||||
if (DST.RST.bound_ubo_slots[DST.RST.bind_ubo_inc] == false) {
|
||||
if (DST.RST.bound_ubos[DST.RST.bind_ubo_inc] != NULL) {
|
||||
GPU_uniformbuffer_unbind(DST.RST.bound_ubos[DST.RST.bind_ubo_inc]);
|
||||
}
|
||||
GPU_uniformbuffer_bind(ubo, DST.RST.bind_ubo_inc);
|
||||
DST.RST.bound_ubos[DST.RST.bind_ubo_inc] = ubo;
|
||||
DST.RST.bound_ubo_slots[DST.RST.bind_ubo_inc] = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* This is not depending on user input.
|
||||
* It is our responsability to make sure there enough slots. */
|
||||
BLI_assert(0 && "Not enough ubo slots! This should not happen!\n");
|
||||
|
@ -741,6 +750,7 @@ static void bind_ubo(GPUUniformBuffer *ubo)
|
|||
/* printf so user can report bad behaviour */
|
||||
printf("Not enough ubo slots! This should not happen!\n");
|
||||
}
|
||||
DST.RST.bound_ubo_slots[bind_num] = true;
|
||||
}
|
||||
|
||||
static void release_texture_slots(void)
|
||||
|
@ -750,7 +760,7 @@ static void release_texture_slots(void)
|
|||
|
||||
static void release_ubo_slots(void)
|
||||
{
|
||||
DST.RST.bind_ubo_inc = 0;
|
||||
memset(DST.RST.bound_ubo_slots, 0x0, sizeof(bool) * GPU_max_textures());
|
||||
}
|
||||
|
||||
static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
||||
|
@ -766,10 +776,10 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
|||
if (DST.shader) GPU_shader_unbind();
|
||||
GPU_shader_bind(shgroup->shader);
|
||||
DST.shader = shgroup->shader;
|
||||
}
|
||||
|
||||
release_texture_slots();
|
||||
release_ubo_slots();
|
||||
release_texture_slots();
|
||||
release_ubo_slots();
|
||||
}
|
||||
|
||||
drw_state_set((pass_state & shgroup->state_extra_disable) | shgroup->state_extra);
|
||||
drw_stencil_set(shgroup->stencil_mask);
|
||||
|
@ -1000,6 +1010,14 @@ static void drw_draw_pass_ex(DRWPass *pass, DRWShadingGroup *start_group, DRWSha
|
|||
}
|
||||
}
|
||||
|
||||
/* Clear Bound Ubos */
|
||||
for (int i = 0; i < GPU_max_ubo_binds(); i++) {
|
||||
if (DST.RST.bound_ubos[i] != NULL) {
|
||||
GPU_uniformbuffer_unbind(DST.RST.bound_ubos[i]);
|
||||
DST.RST.bound_ubos[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (DST.shader) {
|
||||
GPU_shader_unbind();
|
||||
DST.shader = NULL;
|
||||
|
|
|
@ -149,7 +149,7 @@ void gpu_extensions_init(void)
|
|||
else
|
||||
GG.max_anisotropy = 1.0f;
|
||||
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &GG.maxubobinds);
|
||||
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GG.maxubobinds);
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GG.maxubosize);
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
|
Loading…
Reference in New Issue