[Bf-blender-cvs] [5f59dddd19d] temp-gpu-compute-shaders: Migrated to `GPU_*buf_bind_as_ssbo`
Jeroen Bakker
noreply at git.blender.org
Fri May 7 14:03:03 CEST 2021
Commit: 5f59dddd19d509b24a4712c6fbf3f7e51559d78e
Author: Jeroen Bakker
Date: Fri May 7 11:00:41 2021 +0200
Branches: temp-gpu-compute-shaders
https://developer.blender.org/rB5f59dddd19d509b24a4712c6fbf3f7e51559d78e
Migrated to `GPU_*buf_bind_as_ssbo`
===================================================================
M source/blender/gpu/GPU_index_buffer.h
M source/blender/gpu/GPU_shader.h
M source/blender/gpu/GPU_vertex_buffer.h
M source/blender/gpu/intern/gpu_index_buffer.cc
M source/blender/gpu/intern/gpu_index_buffer_private.hh
M source/blender/gpu/intern/gpu_shader.cc
M source/blender/gpu/intern/gpu_vertex_buffer.cc
M source/blender/gpu/intern/gpu_vertex_buffer_private.hh
M source/blender/gpu/opengl/gl_index_buffer.cc
M source/blender/gpu/opengl/gl_index_buffer.hh
M source/blender/gpu/opengl/gl_vertex_buffer.cc
M source/blender/gpu/opengl/gl_vertex_buffer.hh
M source/blender/gpu/tests/gpu_shader_test.cc
===================================================================
diff --git a/source/blender/gpu/GPU_index_buffer.h b/source/blender/gpu/GPU_index_buffer.h
index 76aab3c196b..41861ff6fd5 100644
--- a/source/blender/gpu/GPU_index_buffer.h
+++ b/source/blender/gpu/GPU_index_buffer.h
@@ -70,6 +70,8 @@ void GPU_indexbuf_set_tri_restart(GPUIndexBufBuilder *builder, uint elem);
GPUIndexBuf *GPU_indexbuf_build(GPUIndexBufBuilder *);
void GPU_indexbuf_build_in_place(GPUIndexBufBuilder *, GPUIndexBuf *);
+void GPU_indexbuf_bind_as_ssbo(GPUIndexBuf *elem, int binding);
+
/* Create a sub-range of an existing index-buffer. */
GPUIndexBuf *GPU_indexbuf_create_subrange(GPUIndexBuf *elem_src, uint start, uint length);
void GPU_indexbuf_create_subrange_in_place(GPUIndexBuf *elem,
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 6eea690627f..8f82ee90873 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -89,9 +89,6 @@ void GPU_shader_unbind(void);
bool GPU_shader_transform_feedback_enable(GPUShader *shader, struct GPUVertBuf *vertbuf);
void GPU_shader_transform_feedback_disable(GPUShader *shader);
-void GPU_shader_attach_vertex_buffer(GPUShader *shader, struct GPUVertBuf *vertbuf, int location);
-void GPU_shader_attach_index_buffer(GPUShader *shader, struct GPUIndexBuf *indexbuf, int location);
-
int GPU_shader_get_program(GPUShader *shader);
typedef enum {
diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index 01ab252a6c1..139b11557ec 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -139,6 +139,7 @@ uint GPU_vertbuf_get_vertex_len(const GPUVertBuf *verts);
GPUVertBufStatus GPU_vertbuf_get_status(const GPUVertBuf *verts);
void GPU_vertbuf_use(GPUVertBuf *);
+void GPU_vertbuf_bind_as_ssbo(struct GPUVertBuf *verts, int binding);
/* XXX do not use. */
void GPU_vertbuf_update_sub(GPUVertBuf *verts, uint start, uint len, void *data);
diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc
index 65932d2dbf4..c41deb3b3d8 100644
--- a/source/blender/gpu/intern/gpu_index_buffer.cc
+++ b/source/blender/gpu/intern/gpu_index_buffer.cc
@@ -366,4 +366,9 @@ int GPU_indexbuf_primitive_len(GPUPrimType prim_type)
return indices_per_primitive(prim_type);
}
+void GPU_indexbuf_bind_as_ssbo(GPUIndexBuf *elem, int binding)
+{
+ unwrap(elem)->bind_as_ssbo(binding);
+}
+
/** \} */
diff --git a/source/blender/gpu/intern/gpu_index_buffer_private.hh b/source/blender/gpu/intern/gpu_index_buffer_private.hh
index 2405db8664a..1916c5a5256 100644
--- a/source/blender/gpu/intern/gpu_index_buffer_private.hh
+++ b/source/blender/gpu/intern/gpu_index_buffer_private.hh
@@ -91,6 +91,8 @@ class IndexBuf {
return is_init_;
};
+ virtual void bind_as_ssbo(uint binding) = 0;
+
private:
inline void squeeze_indices_short(uint min_idx, uint max_idx);
inline uint index_range(uint *r_min, uint *r_max);
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index c343650d833..ab7d5e52701 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -588,22 +588,6 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader)
/** \} */
-/* -------------------------------------------------------------------- */
-/** \name Buffer binding
- * \{ */
-
-void GPU_shader_attach_vertex_buffer(GPUShader *shader, struct GPUVertBuf *vertbuf, int position)
-{
- unwrap(shader)->attach_buffer(vertbuf, position);
-}
-
-void GPU_shader_attach_index_buffer(GPUShader *shader, struct GPUIndexBuf *indexbuf, int position)
-{
- unwrap(shader)->attach_buffer(indexbuf, position);
-}
-
-/** \} */
-
/* -------------------------------------------------------------------- */
/** \name Uniforms / Resource location
* \{ */
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.cc b/source/blender/gpu/intern/gpu_vertex_buffer.cc
index 09b9eba9f95..3abd7e489f7 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.cc
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.cc
@@ -324,6 +324,11 @@ void GPU_vertbuf_use(GPUVertBuf *verts)
unwrap(verts)->upload();
}
+void GPU_vertbuf_bind_as_ssbo(struct GPUVertBuf *verts, int binding)
+{
+ unwrap(verts)->bind_as_ssbo(binding);
+}
+
/* XXX this is just a wrapper for the use of the Hair refine workaround.
* To be used with GPU_vertbuf_use(). */
void GPU_vertbuf_update_sub(GPUVertBuf *verts, uint start, uint len, void *data)
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer_private.hh b/source/blender/gpu/intern/gpu_vertex_buffer_private.hh
index 67a09f6f83c..03c60745f99 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer_private.hh
+++ b/source/blender/gpu/intern/gpu_vertex_buffer_private.hh
@@ -66,6 +66,7 @@ class VertBuf {
void allocate(uint vert_len);
void resize(uint vert_len);
void upload(void);
+ virtual void bind_as_ssbo(uint binding) = 0;
VertBuf *duplicate(void);
diff --git a/source/blender/gpu/opengl/gl_index_buffer.cc b/source/blender/gpu/opengl/gl_index_buffer.cc
index e2c18c5d0b9..b607ec8d55a 100644
--- a/source/blender/gpu/opengl/gl_index_buffer.cc
+++ b/source/blender/gpu/opengl/gl_index_buffer.cc
@@ -59,4 +59,11 @@ void GLIndexBuf::bind()
}
}
+void GLIndexBuf::bind_as_ssbo(uint binding)
+{
+ bind();
+ BLI_assert(ibo_id_ != 0);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, ibo_id_);
+}
+
} // namespace blender::gpu
diff --git a/source/blender/gpu/opengl/gl_index_buffer.hh b/source/blender/gpu/opengl/gl_index_buffer.hh
index 9c89b8ae87d..2b0411d03f8 100644
--- a/source/blender/gpu/opengl/gl_index_buffer.hh
+++ b/source/blender/gpu/opengl/gl_index_buffer.hh
@@ -43,6 +43,7 @@ class GLIndexBuf : public IndexBuf {
~GLIndexBuf();
void bind(void);
+ void bind_as_ssbo(uint binding) override;
void *offset_ptr(uint additional_vertex_offset) const
{
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc
index d2c98f0a637..448c165cfee 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.cc
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc
@@ -118,6 +118,13 @@ void GLVertBuf::bind()
}
}
+void GLVertBuf::bind_as_ssbo(uint binding)
+{
+ bind();
+ BLI_assert(vbo_id_ != 0);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, vbo_id_);
+}
+
void GLVertBuf::update_sub(uint start, uint len, void *data)
{
glBufferSubData(GL_ARRAY_BUFFER, start, len, data);
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.hh b/source/blender/gpu/opengl/gl_vertex_buffer.hh
index 61bc7bc00b0..77e68908e61 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.hh
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.hh
@@ -53,6 +53,7 @@ class GLVertBuf : public VertBuf {
void release_data(void) override;
void upload_data(void) override;
void duplicate_data(VertBuf *dst) override;
+ void bind_as_ssbo(uint binding) override;
MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
};
diff --git a/source/blender/gpu/tests/gpu_shader_test.cc b/source/blender/gpu/tests/gpu_shader_test.cc
index c421acf2fe2..c6ddef20a45 100644
--- a/source/blender/gpu/tests/gpu_shader_test.cc
+++ b/source/blender/gpu/tests/gpu_shader_test.cc
@@ -180,7 +180,7 @@ void main() {
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_DEVICE_ONLY);
GPU_vertbuf_data_alloc(vbo, SIZE);
- GPU_shader_attach_vertex_buffer(shader, vbo, 0);
+ GPU_vertbuf_bind_as_ssbo(vbo, 0);
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
@@ -252,7 +252,7 @@ void main() {
}
GPUIndexBuf *ibo = GPU_indexbuf_build(&ibo_builder);
- GPU_shader_attach_index_buffer(shader, ibo, 0);
+ GPU_indexbuf_bind_as_ssbo(ibo, 0);
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE / 2, 1, 1);
@@ -317,7 +317,7 @@ void main() {
}
GPUIndexBuf *ibo = GPU_indexbuf_build(&ibo_builder);
- GPU_shader_attach_index_buffer(shader, ibo, 0);
+ GPU_indexbuf_bind_as_ssbo(ibo, 0);
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
More information about the Bf-blender-cvs
mailing list