DRW: Add support for GPUStorageBuf
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user