diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-02-09 01:19:31 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-03-18 22:49:45 +0300 |
commit | 8c93f8c6cc9c7300a150118d8a29f98b1ba7bbdd (patch) | |
tree | ec7aa41774b2df29d5a46bc3fb1b52aaed83f63f /source/blender | |
parent | bacfd55a0e4ca5a59ee46824c500992a3dddc6b6 (diff) |
DRW: Add support for GPUStorageBuf
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 15 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 46 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_backend.hh | 4 |
5 files changed, 80 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 37c1365a5f2..528e8664fbb 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -30,6 +30,7 @@ #include "GPU_framebuffer.h" #include "GPU_primitive.h" #include "GPU_shader.h" +#include "GPU_storage_buffer.h" #include "GPU_texture.h" #include "GPU_uniform_buffer.h" @@ -568,6 +569,12 @@ void DRW_shgroup_uniform_block_ex(DRWShadingGroup *shgroup, void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup, const char *name, struct GPUUniformBuf **ubo DRW_DEBUG_FILE_LINE_ARGS); +void DRW_shgroup_storage_block_ex(DRWShadingGroup *shgroup, + const char *name, + const struct GPUStorageBuf *ssbo DRW_DEBUG_FILE_LINE_ARGS); +void DRW_shgroup_storage_block_ref_ex(DRWShadingGroup *shgroup, + const char *name, + struct GPUStorageBuf **ssbo DRW_DEBUG_FILE_LINE_ARGS); void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, @@ -643,6 +650,10 @@ void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup, DRW_shgroup_uniform_block_ex(shgroup, name, ubo, __FILE__, __LINE__) # define DRW_shgroup_uniform_block_ref(shgroup, name, ubo) \ DRW_shgroup_uniform_block_ref_ex(shgroup, name, ubo, __FILE__, __LINE__) +# define DRW_shgroup_storage_block(shgroup, name, ubo) \ + DRW_shgroup_storage_block_ex(shgroup, name, ubo, __FILE__, __LINE__) +# define DRW_shgroup_storage_block_ref(shgroup, name, ubo) \ + DRW_shgroup_storage_block_ref_ex(shgroup, name, ubo, __FILE__, __LINE__) #else # define DRW_shgroup_vertex_buffer(shgroup, name, vert) \ DRW_shgroup_vertex_buffer_ex(shgroup, name, vert) @@ -652,6 +663,10 @@ void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup, DRW_shgroup_uniform_block_ex(shgroup, name, ubo) # define DRW_shgroup_uniform_block_ref(shgroup, name, ubo) \ DRW_shgroup_uniform_block_ref_ex(shgroup, name, ubo) +# define DRW_shgroup_storage_block(shgroup, name, ubo) \ + DRW_shgroup_storage_block_ex(shgroup, name, ubo) +# define DRW_shgroup_storage_block_ref(shgroup, name, ubo) \ + DRW_shgroup_storage_block_ref_ex(shgroup, name, ubo) #endif bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup); diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 06643439bbc..b5aaaf36368 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -309,6 +309,8 @@ typedef enum { DRW_UNIFORM_IMAGE_REF, DRW_UNIFORM_BLOCK, DRW_UNIFORM_BLOCK_REF, + DRW_UNIFORM_STORAGE_BLOCK, + DRW_UNIFORM_STORAGE_BLOCK_REF, DRW_UNIFORM_TFEEDBACK_TARGET, DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE, DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE_REF, @@ -343,6 +345,11 @@ struct DRWUniform { GPUUniformBuf *block; GPUUniformBuf **block_ref; }; + /* DRW_UNIFORM_STORAGE_BLOCK */ + union { + GPUStorageBuf *ssbo; + GPUStorageBuf **ssbo_ref; + }; /* DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE */ union { GPUVertBuf *vertbuf; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 95691a0df68..be45cee8759 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -216,6 +216,8 @@ static void drw_shgroup_uniform(DRWShadingGroup *shgroup, BLI_assert(arraysize > 0 && arraysize <= 16); BLI_assert(length >= 0 && length <= 16); BLI_assert(!ELEM(type, + DRW_UNIFORM_STORAGE_BLOCK, + DRW_UNIFORM_STORAGE_BLOCK_REF, DRW_UNIFORM_BLOCK, DRW_UNIFORM_BLOCK_REF, DRW_UNIFORM_TEXTURE, @@ -310,6 +312,50 @@ void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup, drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_BLOCK_REF, ubo, 0, 0, 1); } +void DRW_shgroup_storage_block_ex(DRWShadingGroup *shgroup, + const char *name, + const GPUStorageBuf *ssbo DRW_DEBUG_FILE_LINE_ARGS) +{ + BLI_assert(ssbo != NULL); + /* TODO(@fclem): Fix naming inconsistency. */ + int loc = GPU_shader_get_ssbo(shgroup->shader, name); + if (loc == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", + file, + line, + name); +#else + /* TODO(@fclem): Would be good to have, but eevee has too much of this for the moment. */ + // BLI_assert_msg(0, "Unable to locate binding of shader storage buffer objects."); +#endif + return; + } + drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_STORAGE_BLOCK, ssbo, 0, 0, 1); +} + +void DRW_shgroup_storage_block_ref_ex(DRWShadingGroup *shgroup, + const char *name, + GPUStorageBuf **ssbo DRW_DEBUG_FILE_LINE_ARGS) +{ + BLI_assert(ssbo != NULL); + /* TODO(@fclem): Fix naming inconsistency. */ + int loc = GPU_shader_get_ssbo(shgroup->shader, name); + if (loc == -1) { +#ifdef DRW_UNUSED_RESOURCE_TRACKING + printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", + file, + line, + name); +#else + /* TODO(@fclem): Would be good to have, but eevee has too much of this for the moment. */ + // BLI_assert_msg(0, "Unable to locate binding of shader storage buffer objects."); +#endif + return; + } + drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_STORAGE_BLOCK_REF, ssbo, 0, 0, 1); +} + void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const int *value, diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 07e47a0c691..319f63eebad 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -319,6 +319,7 @@ void DRW_state_reset(void) GPU_texture_unbind_all(); GPU_uniformbuf_unbind_all(); + GPU_storagebuf_unbind_all(); /* Should stay constant during the whole rendering. */ GPU_point_size(5); @@ -621,6 +622,12 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, case DRW_UNIFORM_BLOCK_REF: GPU_uniformbuf_bind(*uni->block_ref, uni->location); break; + case DRW_UNIFORM_STORAGE_BLOCK: + GPU_storagebuf_bind(uni->ssbo, uni->location); + break; + case DRW_UNIFORM_STORAGE_BLOCK_REF: + GPU_storagebuf_bind(*uni->ssbo_ref, uni->location); + break; case DRW_UNIFORM_BLOCK_OBMATS: state->obmats_loc = uni->location; GPU_uniformbuf_bind(DST.vmempool->matrices_ubo[0], uni->location); @@ -915,6 +922,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) if (G.debug & G_DEBUG_GPU) { GPU_texture_unbind_all(); GPU_uniformbuf_unbind_all(); + GPU_storagebuf_unbind_all(); } } GPU_shader_bind(shgroup->shader); diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh index 2b6e485f152..56d7c3b4e46 100644 --- a/source/blender/gpu/intern/gpu_backend.hh +++ b/source/blender/gpu/intern/gpu_backend.hh @@ -9,6 +9,8 @@ #pragma once +#include "GPU_vertex_buffer.h" + namespace blender { namespace gpu { @@ -22,6 +24,7 @@ class QueryPool; class Shader; class Texture; class UniformBuf; +class StorageBuf; class VertBuf; class GPUBackend { @@ -43,6 +46,7 @@ class GPUBackend { virtual Shader *shader_alloc(const char *name) = 0; virtual Texture *texture_alloc(const char *name) = 0; virtual UniformBuf *uniformbuf_alloc(int size, const char *name) = 0; + virtual StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) = 0; virtual VertBuf *vertbuf_alloc() = 0; }; |