diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-08-21 00:09:37 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-08-21 15:16:42 +0300 |
commit | 7edd8a7738481b3d4f0720a173dca2a1853996d6 (patch) | |
tree | 4b507b4535c0fbe84fc25a21ddf2db55476b1b9b /source/blender/draw/intern | |
parent | 4f0a749489af9de9b2ec0b5768d6e10898885a17 (diff) |
GPUUniformBuf: Rename struct and change API a bit
This follows the GPU module naming of other buffers.
We pass name to distinguish each GPUUniformBuf in debug mode.
Also remove DRW_uniform_buffer interface.
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 13 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 6 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 48 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 26 |
7 files changed, 43 insertions, 63 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 63625fae185..697f4f77601 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -48,6 +48,7 @@ #include "GPU_primitive.h" #include "GPU_shader.h" #include "GPU_texture.h" +#include "GPU_uniform_buffer.h" #include "draw_cache.h" #include "draw_common.h" @@ -67,7 +68,7 @@ struct GPUFrameBuffer; struct GPUMaterial; struct GPUShader; struct GPUTexture; -struct GPUUniformBuffer; +struct GPUUniformBuf; struct Object; struct ParticleSystem; struct RenderEngineType; @@ -184,14 +185,10 @@ void DRW_texture_free(struct GPUTexture *tex); } \ } while (0) -/* UBOs */ -struct GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data); -void DRW_uniformbuffer_update(struct GPUUniformBuffer *ubo, const void *data); -void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo); #define DRW_UBO_FREE_SAFE(ubo) \ do { \ if (ubo != NULL) { \ - DRW_uniformbuffer_free(ubo); \ + GPU_uniformbuf_free(ubo); \ ubo = NULL; \ } \ } while (0) @@ -516,10 +513,10 @@ void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, struct GPUTexture **tex); void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, - const struct GPUUniformBuffer *ubo); + const struct GPUUniformBuf *ubo); void DRW_shgroup_uniform_block_ref(DRWShadingGroup *shgroup, const char *name, - struct GPUUniformBuffer **ubo); + struct GPUUniformBuf **ubo); void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index aac9af088de..f80b5bd71fd 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -214,10 +214,11 @@ void DRW_globals_update(void) } if (G_draw.block_ubo == NULL) { - G_draw.block_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), gb); + G_draw.block_ubo = GPU_uniformbuf_create_ex( + sizeof(GlobalsUboStorage), gb, "GlobalsUboStorage"); } - DRW_uniformbuffer_update(G_draw.block_ubo, gb); + GPU_uniformbuf_update(G_draw.block_ubo, gb); if (!G_draw.ramp) { ColorBand ramp = {0}; diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index d6402127e5e..645848e7fe0 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -205,11 +205,11 @@ struct DRW_Global { * Not needed for constant color. */ GlobalsUboStorage block; /** Define "globalsBlock" uniform for 'block'. */ - struct GPUUniformBuffer *block_ubo; + struct GPUUniformBuf *block_ubo; struct GPUTexture *ramp; struct GPUTexture *weight_ramp; - struct GPUUniformBuffer *view_ubo; + struct GPUUniformBuf *view_ubo; }; extern struct DRW_Global G_draw; diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index b515a83959e..5f3e981c92b 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -69,7 +69,7 @@ #include "GPU_immediate.h" #include "GPU_matrix.h" #include "GPU_state.h" -#include "GPU_uniformbuffer.h" +#include "GPU_uniform_buffer.h" #include "GPU_viewport.h" #include "IMB_colormanagement.h" @@ -600,7 +600,7 @@ static void drw_viewport_var_init(void) } if (G_draw.view_ubo == NULL) { - G_draw.view_ubo = DRW_uniformbuffer_create(sizeof(DRWViewUboStorage), NULL); + G_draw.view_ubo = GPU_uniformbuf_create_ex(sizeof(DRWViewUboStorage), 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 d15a55e7bef..c0bcb0e679f 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -38,7 +38,7 @@ #include "GPU_drawlist.h" #include "GPU_framebuffer.h" #include "GPU_shader.h" -#include "GPU_uniformbuffer.h" +#include "GPU_uniform_buffer.h" #include "GPU_viewport.h" #include "draw_instance_data.h" @@ -308,8 +308,8 @@ struct DRWUniform { }; /* DRW_UNIFORM_BLOCK */ union { - GPUUniformBuffer *block; - GPUUniformBuffer **block_ref; + GPUUniformBuf *block; + GPUUniformBuf **block_ref; }; /* DRW_UNIFORM_FLOAT_COPY */ float fvalue[4]; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index c12b4a96488..afea820b057 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -48,6 +48,7 @@ #include "GPU_buffers.h" #include "GPU_material.h" +#include "GPU_uniform_buffer.h" #include "intern/gpu_codegen.h" @@ -85,27 +86,12 @@ static void draw_call_sort(DRWCommand *array, DRWCommand *array_tmp, int array_l memcpy(array, array_tmp, sizeof(*array) * array_len); } -GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data) -{ - return GPU_uniformbuffer_create(size, data, NULL); -} - -void DRW_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data) -{ - GPU_uniformbuffer_update(ubo, data); -} - -void DRW_uniformbuffer_free(GPUUniformBuffer *ubo) -{ - GPU_uniformbuffer_free(ubo); -} - void drw_resource_buffer_finish(ViewportMemoryPool *vmempool) { int chunk_id = DRW_handle_chunk_get(&DST.resource_handle); int elem_id = DRW_handle_id_get(&DST.resource_handle); int ubo_len = 1 + chunk_id - ((elem_id == 0) ? 1 : 0); - size_t list_size = sizeof(GPUUniformBuffer *) * ubo_len; + size_t list_size = sizeof(GPUUniformBuf *) * ubo_len; /* TODO find a better system. currently a lot of obinfos UBO are going to be unused * if not rendering with Eevee. */ @@ -118,8 +104,8 @@ void drw_resource_buffer_finish(ViewportMemoryPool *vmempool) /* Remove unnecessary buffers */ for (int i = ubo_len; i < vmempool->ubo_len; i++) { - GPU_uniformbuffer_free(vmempool->matrices_ubo[i]); - GPU_uniformbuffer_free(vmempool->obinfos_ubo[i]); + GPU_uniformbuf_free(vmempool->matrices_ubo[i]); + GPU_uniformbuf_free(vmempool->obinfos_ubo[i]); } if (ubo_len != vmempool->ubo_len) { @@ -133,15 +119,13 @@ void drw_resource_buffer_finish(ViewportMemoryPool *vmempool) void *data_obmat = BLI_memblock_elem_get(vmempool->obmats, i, 0); void *data_infos = BLI_memblock_elem_get(vmempool->obinfos, i, 0); if (vmempool->matrices_ubo[i] == NULL) { - vmempool->matrices_ubo[i] = GPU_uniformbuffer_create( - sizeof(DRWObjectMatrix) * DRW_RESOURCE_CHUNK_LEN, data_obmat, NULL); - vmempool->obinfos_ubo[i] = GPU_uniformbuffer_create( - sizeof(DRWObjectInfos) * DRW_RESOURCE_CHUNK_LEN, data_infos, NULL); - } - else { - GPU_uniformbuffer_update(vmempool->matrices_ubo[i], data_obmat); - GPU_uniformbuffer_update(vmempool->obinfos_ubo[i], data_infos); + vmempool->matrices_ubo[i] = GPU_uniformbuf_create(sizeof(DRWObjectMatrix) * + DRW_RESOURCE_CHUNK_LEN); + vmempool->obinfos_ubo[i] = GPU_uniformbuf_create(sizeof(DRWObjectInfos) * + DRW_RESOURCE_CHUNK_LEN); } + GPU_uniformbuf_update(vmempool->matrices_ubo[i], data_obmat); + GPU_uniformbuf_update(vmempool->obinfos_ubo[i], data_infos); } /* Aligned alloc to avoid unaligned memcpy. */ @@ -210,10 +194,10 @@ static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup, memcpy(uni->fvalue, value, sizeof(float) * length); break; case DRW_UNIFORM_BLOCK: - uni->block = (GPUUniformBuffer *)value; + uni->block = (GPUUniformBuf *)value; break; case DRW_UNIFORM_BLOCK_REF: - uni->block_ref = (GPUUniformBuffer **)value; + uni->block_ref = (GPUUniformBuf **)value; break; case DRW_UNIFORM_TEXTURE: uni->texture = (GPUTexture *)value; @@ -279,16 +263,14 @@ void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, - const GPUUniformBuffer *ubo) + const GPUUniformBuf *ubo) { BLI_assert(ubo != NULL); int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_BLOCK, ubo, 0, 0, 1); } -void DRW_shgroup_uniform_block_ref(DRWShadingGroup *shgroup, - const char *name, - GPUUniformBuffer **ubo) +void DRW_shgroup_uniform_block_ref(DRWShadingGroup *shgroup, const char *name, GPUUniformBuf **ubo) { BLI_assert(ubo != NULL); int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); @@ -1327,7 +1309,7 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, struct GPUMaterial } } - GPUUniformBuffer *ubo = GPU_material_uniform_buffer_get(material); + GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material); if (ubo != NULL) { DRW_shgroup_uniform_block(grp, GPU_UBO_BLOCK_NAME, ubo); } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 9902d3b0aeb..31d7cbaad40 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -296,7 +296,7 @@ void DRW_state_reset(void) DRW_state_reset_ex(DRW_STATE_DEFAULT); GPU_texture_unbind_all(); - GPU_uniformbuffer_unbind_all(); + GPU_uniformbuf_unbind_all(); /* Should stay constant during the whole rendering. */ GPU_point_size(5); @@ -648,18 +648,18 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, GPU_texture_bind_ex(*uni->texture_ref, uni->sampler_state, uni->location, false); break; case DRW_UNIFORM_BLOCK: - GPU_uniformbuffer_bind(uni->block, uni->location); + GPU_uniformbuf_bind(uni->block, uni->location); break; case DRW_UNIFORM_BLOCK_REF: - GPU_uniformbuffer_bind(*uni->block_ref, uni->location); + GPU_uniformbuf_bind(*uni->block_ref, uni->location); break; case DRW_UNIFORM_BLOCK_OBMATS: state->obmats_loc = uni->location; - GPU_uniformbuffer_bind(DST.vmempool->matrices_ubo[0], uni->location); + GPU_uniformbuf_bind(DST.vmempool->matrices_ubo[0], uni->location); break; case DRW_UNIFORM_BLOCK_OBINFOS: state->obinfos_loc = uni->location; - GPU_uniformbuffer_bind(DST.vmempool->obinfos_ubo[0], uni->location); + GPU_uniformbuf_bind(DST.vmempool->obinfos_ubo[0], uni->location); break; case DRW_UNIFORM_RESOURCE_CHUNK: state->chunkid_loc = uni->location; @@ -769,12 +769,12 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa GPU_shader_uniform_int(DST.shader, state->chunkid_loc, chunk); } if (state->obmats_loc != -1) { - GPU_uniformbuffer_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); - GPU_uniformbuffer_bind(DST.vmempool->matrices_ubo[chunk], state->obmats_loc); + GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); + GPU_uniformbuf_bind(DST.vmempool->matrices_ubo[chunk], state->obmats_loc); } if (state->obinfos_loc != -1) { - GPU_uniformbuffer_unbind(DST.vmempool->obinfos_ubo[state->resource_chunk]); - GPU_uniformbuffer_bind(DST.vmempool->obinfos_ubo[chunk], state->obinfos_loc); + GPU_uniformbuf_unbind(DST.vmempool->obinfos_ubo[state->resource_chunk]); + GPU_uniformbuf_bind(DST.vmempool->obinfos_ubo[chunk], state->obinfos_loc); } state->resource_chunk = chunk; } @@ -893,10 +893,10 @@ static void draw_call_batching_finish(DRWShadingGroup *shgroup, DRWCommandsState GPU_front_facing(DST.view_active->is_inverted); } if (state->obmats_loc != -1) { - GPU_uniformbuffer_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); + GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); } if (state->obinfos_loc != -1) { - GPU_uniformbuffer_unbind(DST.vmempool->obinfos_ubo[state->resource_chunk]); + GPU_uniformbuf_unbind(DST.vmempool->obinfos_ubo[state->resource_chunk]); } } @@ -926,7 +926,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) /* Unbinding can be costly. Skip in normal condition. */ if (G.debug & G_DEBUG_GPU) { GPU_texture_unbind_all(); - GPU_uniformbuffer_unbind_all(); + GPU_uniformbuf_unbind_all(); } } GPU_shader_bind(shgroup->shader); @@ -1062,7 +1062,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) static void drw_update_view(void) { /* TODO(fclem) update a big UBO and only bind ranges here. */ - DRW_uniformbuffer_update(G_draw.view_ubo, &DST.view_active->storage); + GPU_uniformbuf_update(G_draw.view_ubo, &DST.view_active->storage); /* TODO get rid of this. */ DST.view_storage_cpy = DST.view_active->storage; |