[Bf-blender-cvs] [23f541503d6] temp-gpu-compute-shaders: Updated gpu index buffer interface.

Jeroen Bakker noreply at git.blender.org
Tue May 11 10:55:47 CEST 2021


Commit: 23f541503d62ce52b29571251c31f58260bc676b
Author: Jeroen Bakker
Date:   Tue May 11 08:59:22 2021 +0200
Branches: temp-gpu-compute-shaders
https://developer.blender.org/rB23f541503d62ce52b29571251c31f58260bc676b

Updated gpu index buffer interface.

===================================================================

M	source/blender/gpu/GPU_index_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/tests/gpu_shader_test.cc

===================================================================

diff --git a/source/blender/gpu/GPU_index_buffer.h b/source/blender/gpu/GPU_index_buffer.h
index 7746db1092e..4fabf1eb0de 100644
--- a/source/blender/gpu/GPU_index_buffer.h
+++ b/source/blender/gpu/GPU_index_buffer.h
@@ -44,20 +44,12 @@ typedef struct GPUIndexBufBuilder {
   uint32_t *data;
 } GPUIndexBufBuilder;
 
-typedef enum {
-  GPU_INDEX_U16,
-  GPU_INDEX_U32,
-} GPUIndexBufType;
-
 /* supports all primitive types. */
 void GPU_indexbuf_init_ex(GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len);
-void GPU_indexbuf_init_device_only(GPUIndexBuf *elem,
-                                   GPUIndexBufType type,
-                                   GPUPrimType,
-                                   uint prim_len);
 
 /* supports only GPU_PRIM_POINTS, GPU_PRIM_LINES and GPU_PRIM_TRIS. */
 void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len);
+GPUIndexBuf *GPU_indexbuf_build_on_device(GPUPrimType, uint prim_len);
 
 void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v);
 void GPU_indexbuf_add_primitive_restart(GPUIndexBufBuilder *);
diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc
index b13aa1a9741..4d3894ce7d4 100644
--- a/source/blender/gpu/intern/gpu_index_buffer.cc
+++ b/source/blender/gpu/intern/gpu_index_buffer.cc
@@ -66,13 +66,12 @@ void GPU_indexbuf_init(GPUIndexBufBuilder *builder,
   GPU_indexbuf_init_ex(builder, prim_type, prim_len * (uint)verts_per_prim, vertex_len);
 }
 
-void GPU_indexbuf_init_device_only(GPUIndexBuf *elem_,
-                                   GPUIndexBufType index_type,
-                                   GPUPrimType prim_type,
-                                   uint prim_len)
+GPUIndexBuf *GPU_indexbuf_build_on_device(GPUPrimType prim_type, uint prim_len)
 {
+  GPUIndexBuf *elem_ = GPU_indexbuf_calloc();
   IndexBuf *elem = unwrap(elem_);
-  elem->init_device_only(index_type, prim_type, prim_len);
+  elem->init_build_on_device(prim_type, prim_len);
+  return elem_;
 }
 
 void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *builder, uint v)
@@ -250,12 +249,12 @@ void IndexBuf::init(uint indices_len, uint32_t *indices)
 #endif
 }
 
-void IndexBuf::init_device_only(GPUIndexBufType index_type, GPUPrimType prim_type, uint prim_len)
+void IndexBuf::init_build_on_device(GPUPrimType prim_type, uint prim_len)
 {
   is_init_ = true;
   index_start_ = 0;
   index_len_ = prim_len * indices_per_primitive(prim_type);
-  index_type_ = index_type;
+  index_type_ = GPU_INDEX_U32;
   data_ = nullptr;
 }
 
diff --git a/source/blender/gpu/intern/gpu_index_buffer_private.hh b/source/blender/gpu/intern/gpu_index_buffer_private.hh
index b65d3e8122d..7acbf6f1194 100644
--- a/source/blender/gpu/intern/gpu_index_buffer_private.hh
+++ b/source/blender/gpu/intern/gpu_index_buffer_private.hh
@@ -31,6 +31,11 @@
 
 namespace blender::gpu {
 
+typedef enum {
+  GPU_INDEX_U16,
+  GPU_INDEX_U32,
+} GPUIndexBufType;
+
 static inline size_t to_bytesize(GPUIndexBufType type)
 {
   return (type == GPU_INDEX_U32) ? sizeof(uint32_t) : sizeof(uint16_t);
@@ -70,7 +75,7 @@ class IndexBuf {
 
   void init(uint indices_len, uint32_t *indices);
   void init_subrange(IndexBuf *elem_src, uint start, uint length);
-  void init_device_only(GPUIndexBufType index_type, GPUPrimType prim_type, uint prim_len);
+  void init_build_on_device(GPUPrimType prim_type, uint prim_len);
 
   uint32_t index_len_get(void) const
   {
diff --git a/source/blender/gpu/tests/gpu_shader_test.cc b/source/blender/gpu/tests/gpu_shader_test.cc
index 7f6b2a13c9c..a03a5db54a8 100644
--- a/source/blender/gpu/tests/gpu_shader_test.cc
+++ b/source/blender/gpu/tests/gpu_shader_test.cc
@@ -204,69 +204,7 @@ void main() {
   GPU_shader_free(shader);
 }
 
-TEST_F(GPUTest, gpu_shader_compute_ibo_short)
-{
-
-  if (!GPU_compute_shader_support()) {
-    /* We can't test as a the platform does not support compute shaders. */
-    std::cout << "Skipping compute shader test: platform not supported";
-    return;
-  }
-
-  static constexpr uint SIZE = 128;
-
-  /* Build compute shader. */
-  const char *compute_glsl = R"(
-
-layout(local_size_x = 1) in;
-
-layout(std430, binding = 0) buffer outputIboData
-{
-  int Indexes[];
-};
-
-void main() {
-  int store_index = int(gl_GlobalInvocationID.x);
-  int index1 = store_index * 2;
-  int index2 = store_index * 2 + 1;
-  int store = ((index2 & 0xFFFF) << 16) | (index1 & 0xFFFF);
-  Indexes[store_index] = store;
-}
-
-)";
-
-  GPUShader *shader = GPU_shader_create_compute(
-      compute_glsl, nullptr, nullptr, "gpu_shader_compute_vbo");
-  EXPECT_NE(shader, nullptr);
-  GPU_shader_bind(shader);
-
-  /* Construct IBO. */
-  GPUIndexBuf *ibo = GPU_indexbuf_calloc();
-  GPU_indexbuf_init_device_only(ibo, GPU_INDEX_U16, GPU_PRIM_POINTS, SIZE);
-  GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo(shader, "outputIboData"));
-
-  /* Dispatch compute task. */
-  GPU_compute_dispatch(shader, SIZE / 2, 1, 1);
-
-  /* Check if compute has been done. */
-  GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
-
-  /* Use opengl function to download the vertex buffer. */
-  /* TODO(jbakker): Add function to copy it back to the IndexBuffer data. */
-  uint16_t *data = static_cast<uint16_t *>(glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY));
-  ASSERT_NE(data, nullptr);
-  /* Create texture to load back result. */
-  for (int index = 0; index < SIZE; index++) {
-    EXPECT_EQ(data[index], index);
-  }
-
-  /* Cleanup. */
-  GPU_shader_unbind();
-  GPU_indexbuf_discard(ibo);
-  GPU_shader_free(shader);
-}
-
-TEST_F(GPUTest, gpu_shader_compute_ibo_int)
+TEST_F(GPUTest, gpu_shader_compute_ibo)
 {
 
   if (!GPU_compute_shader_support()) {
@@ -300,8 +238,7 @@ void main() {
   GPU_shader_bind(shader);
 
   /* Construct IBO. */
-  GPUIndexBuf *ibo = GPU_indexbuf_calloc();
-  GPU_indexbuf_init_device_only(ibo, GPU_INDEX_U32, GPU_PRIM_POINTS, SIZE);
+  GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(GPU_PRIM_POINTS, SIZE);
   GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo(shader, "outputIboData"));
 
   /* Dispatch compute task. */



More information about the Bf-blender-cvs mailing list