[Bf-blender-cvs] [b60e61396b7] temp-gpu-uniform-builtin-structs: Rename to ShaderBlocks

Jeroen Bakker noreply at git.blender.org
Fri Jul 9 12:23:19 CEST 2021


Commit: b60e61396b7b4bc54f4e628118586ab168775671
Author: Jeroen Bakker
Date:   Fri Jul 9 09:51:22 2021 +0200
Branches: temp-gpu-uniform-builtin-structs
https://developer.blender.org/rBb60e61396b7b4bc54f4e628118586ab168775671

Rename to ShaderBlocks

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_shader.h
R100	source/blender/gpu/GPU_uniform_buffer_types.h	source/blender/gpu/GPU_shader_block_types.h
R078	source/blender/gpu/intern/gpu_uniform_buffer_structs.cc	source/blender/gpu/intern/gpu_shader_block.cc
A	source/blender/gpu/intern/gpu_shader_block.hh
M	source/blender/gpu/intern/gpu_shader_private.hh
M	source/blender/gpu/intern/gpu_uniform_buffer_private.hh
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/opengl/gl_shader_interface.cc
M	source/blender/gpu/opengl/gl_shader_interface.hh
M	source/blender/gpu/tests/gpu_uniform_buffer_struct_test.cc

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index ab85a80b57c..267cda4f38a 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -81,13 +81,13 @@ set(SRC
   intern/gpu_select_pick.c
   intern/gpu_select_sample_query.cc
   intern/gpu_shader.cc
+  intern/gpu_shader_block.cc
   intern/gpu_shader_builtin.c
   intern/gpu_shader_log.cc
   intern/gpu_shader_interface.cc
   intern/gpu_state.cc
   intern/gpu_texture.cc
   intern/gpu_uniform_buffer.cc
-  intern/gpu_uniform_buffer_structs.cc
   intern/gpu_vertex_buffer.cc
   intern/gpu_vertex_format.cc
   intern/gpu_viewport.c
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index b1fefcdeb36..600ab5c1808 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -23,7 +23,7 @@
 
 #pragma once
 
-#include "GPU_uniform_buffer_types.h"
+#include "GPU_shader_block_types.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/source/blender/gpu/GPU_uniform_buffer_types.h b/source/blender/gpu/GPU_shader_block_types.h
similarity index 100%
rename from source/blender/gpu/GPU_uniform_buffer_types.h
rename to source/blender/gpu/GPU_shader_block_types.h
diff --git a/source/blender/gpu/intern/gpu_uniform_buffer_structs.cc b/source/blender/gpu/intern/gpu_shader_block.cc
similarity index 78%
rename from source/blender/gpu/intern/gpu_uniform_buffer_structs.cc
rename to source/blender/gpu/intern/gpu_shader_block.cc
index 0f14a4ae8b0..a10bf4a332c 100644
--- a/source/blender/gpu/intern/gpu_uniform_buffer_structs.cc
+++ b/source/blender/gpu/intern/gpu_shader_block.cc
@@ -26,7 +26,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "GPU_shader.h"
-#include "GPU_uniform_buffer_types.h"
+#include "gpu_shader_block.hh"
 #include "gpu_shader_interface.hh"
 
 namespace blender::gpu {
@@ -55,10 +55,10 @@ static bool is_valid_location(int location)
   return true;
 }
 
-static constexpr UniformBuiltinStructType::AttributeBinding determine_binding_struct_1(
+static constexpr ShaderBlockType::AttributeBinding determine_binding_struct_1(
     const GPUUniformBuiltin builtin_uniform)
 {
-  UniformBuiltinStructType::AttributeBinding result = {-1, 0};
+  ShaderBlockType::AttributeBinding result = {-1, 0};
 
   switch (builtin_uniform) {
     case GPU_UNIFORM_MODEL:
@@ -89,7 +89,7 @@ static constexpr UniformBuiltinStructType::AttributeBinding determine_binding_st
   return result;
 }
 
-static constexpr UniformBuiltinStructType::AttributeBinding determine_binding(
+static constexpr ShaderBlockType::AttributeBinding determine_binding(
     const GPUShaderBlockType struct_type, const GPUUniformBuiltin builtin_uniform)
 {
 
@@ -104,7 +104,7 @@ static constexpr UniformBuiltinStructType::AttributeBinding determine_binding(
   return {};
 }
 
-static constexpr std::array<const UniformBuiltinStructType::AttributeBinding, GPU_NUM_UNIFORMS>
+static constexpr std::array<const ShaderBlockType::AttributeBinding, GPU_NUM_UNIFORMS>
 builtin_uniforms_for_struct_type(const GPUShaderBlockType struct_type)
 {
   return {
@@ -131,7 +131,7 @@ builtin_uniforms_for_struct_type(const GPUShaderBlockType struct_type)
 }
 
 static constexpr std::array<
-    const std::array<const UniformBuiltinStructType::AttributeBinding, GPU_NUM_UNIFORMS>,
+    const std::array<const ShaderBlockType::AttributeBinding, GPU_NUM_UNIFORMS>,
     GPU_NUM_SHADER_BLOCK_TYPES>
     ATTRIBUTE_BINDINGS = {
         builtin_uniforms_for_struct_type(GPU_SHADER_BLOCK_CUSTOM),
@@ -158,17 +158,17 @@ static constexpr size_t data_size_for(const GPUShaderBlockType struct_type)
 /** \name Struct type
  * \{ */
 
-constexpr UniformBuiltinStructType::UniformBuiltinStructType(const GPUShaderBlockType type)
+constexpr ShaderBlockType::ShaderBlockType(const GPUShaderBlockType type)
     : type(type), m_attribute_bindings(ATTRIBUTE_BINDINGS[type]), m_data_size(data_size_for(type))
 {
 }
 
-bool UniformBuiltinStructType::AttributeBinding::has_binding() const
+bool ShaderBlockType::AttributeBinding::has_binding() const
 {
   return binding != -1;
 }
 
-bool UniformBuiltinStructType::has_all_builtin_uniforms(const ShaderInterface &interface) const
+bool ShaderBlockType::has_all_builtin_uniforms(const ShaderInterface &interface) const
 {
   for (int i = 0; i < GPU_NUM_UNIFORMS; i++) {
     const GPUUniformBuiltin builtin_uniform = static_cast<const GPUUniformBuiltin>(i);
@@ -182,13 +182,12 @@ bool UniformBuiltinStructType::has_all_builtin_uniforms(const ShaderInterface &i
   return true;
 }
 
-static constexpr std::array<UniformBuiltinStructType, GPU_NUM_SHADER_BLOCK_TYPES>
-    STRUCT_TYPE_INFOS = {
-        UniformBuiltinStructType(GPU_SHADER_BLOCK_CUSTOM),
-        UniformBuiltinStructType(GPU_SHADER_BLOCK_3D_COLOR),
+static constexpr std::array<ShaderBlockType, GPU_NUM_SHADER_BLOCK_TYPES> STRUCT_TYPE_INFOS = {
+    ShaderBlockType(GPU_SHADER_BLOCK_CUSTOM),
+    ShaderBlockType(GPU_SHADER_BLOCK_3D_COLOR),
 };
 
-const UniformBuiltinStructType &UniformBuiltinStructType::get(const GPUShaderBlockType type)
+const ShaderBlockType &ShaderBlockType::get(const GPUShaderBlockType type)
 {
   return STRUCT_TYPE_INFOS[type];
 }
@@ -200,8 +199,7 @@ std::optional<const GPUShaderBlockType> find_smallest_uniform_builtin_struct(
     return std::nullopt;
   }
 
-  if (UniformBuiltinStructType::get(GPU_SHADER_BLOCK_3D_COLOR)
-          .has_all_builtin_uniforms(interface)) {
+  if (ShaderBlockType::get(GPU_SHADER_BLOCK_3D_COLOR).has_all_builtin_uniforms(interface)) {
     return std::make_optional(GPU_SHADER_BLOCK_3D_COLOR);
   }
 
@@ -214,25 +212,25 @@ std::optional<const GPUShaderBlockType> find_smallest_uniform_builtin_struct(
 /** \name Struct type
  * \{ */
 
-UniformBuiltinStruct::UniformBuiltinStruct(const GPUShaderBlockType type)
-    : m_type_info(UniformBuiltinStructType::get(type))
+ShaderBlockBuffer::ShaderBlockBuffer(const GPUShaderBlockType type)
+    : m_type_info(ShaderBlockType::get(type))
 {
   m_data = MEM_mallocN(m_type_info.data_size(), __func__);
 }
 
-UniformBuiltinStruct::~UniformBuiltinStruct()
+ShaderBlockBuffer::~ShaderBlockBuffer()
 {
   MEM_freeN(m_data);
   m_data = nullptr;
 }
 
-bool UniformBuiltinStruct::uniform_int(int location, int comp_len, int array_size, const int *data)
+bool ShaderBlockBuffer::uniform_int(int location, int comp_len, int array_size, const int *data)
 {
   if (!is_valid_location(location)) {
     return false;
   }
   const GPUUniformBuiltin builtin_uniform = to_builtin_uniform(location);
-  const UniformBuiltinStructType::AttributeBinding &attribute = m_type_info.attribute_binding(
+  const ShaderBlockType::AttributeBinding &attribute = m_type_info.attribute_binding(
       builtin_uniform);
 
   if (!attribute.has_binding()) {
@@ -245,16 +243,16 @@ bool UniformBuiltinStruct::uniform_int(int location, int comp_len, int array_siz
   return true;
 }
 
-bool UniformBuiltinStruct::uniform_float(int location,
-                                         int comp_len,
-                                         int array_size,
-                                         const float *data)
+bool ShaderBlockBuffer::uniform_float(int location,
+                                      int comp_len,
+                                      int array_size,
+                                      const float *data)
 {
   if (!is_valid_location(location)) {
     return false;
   }
   const GPUUniformBuiltin builtin_uniform = to_builtin_uniform(location);
-  const UniformBuiltinStructType::AttributeBinding &attribute = m_type_info.attribute_binding(
+  const ShaderBlockType::AttributeBinding &attribute = m_type_info.attribute_binding(
       builtin_uniform);
 
   if (!attribute.has_binding()) {
diff --git a/source/blender/gpu/intern/gpu_shader_block.hh b/source/blender/gpu/intern/gpu_shader_block.hh
new file mode 100644
index 00000000000..95e8524a334
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_shader_block.hh
@@ -0,0 +1,100 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2020, Blender Foundation.
+ */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "BLI_sys_types.h"
+
+#include <optional>
+
+#include "GPU_shader_block_types.h"
+#include "gpu_shader_interface.hh"
+
+#include <array>
+
+namespace blender::gpu {
+
+class ShaderBlockType {
+ public:
+  constexpr ShaderBlockType(const GPUShaderBlockType type);
+  static const ShaderBlockType &get(const GPUShaderBlockType type);
+
+  bool has_all_builtin_uniforms(const ShaderInterface &interface) const;
+
+  GPUShaderBlockType type;
+  struct AttributeBinding {
+    int binding = -1;
+    size_t offset = 0;
+
+    bool has_binding() const;
+  };
+
+  const AttributeBinding &attribute_binding(const GPUUniformBuiltin builtin_uniform) const
+  {
+    return m_attribute_bindings[builtin_uniform];
+  }
+
+  size_t data_size() const
+  {
+    return m_data_size;
+  }
+
+ private:
+  const std::array<const AttributeBinding, GPU_NUM_UNIFORMS> &m_attribute_bindings;
+  const size_t m_data_size;
+};
+
+class ShaderBlockBuffer {
+ public:
+  struct Flags {
+    bool is_dirty : 1;
+  };
+
+  ShaderBlockBuffer(const GPUShaderBlockType type);
+  ShaderBlockBuffer(const ShaderBlockBuffer &other) = default;
+  ShaderBlockBuffer(ShaderBlockBuffer &&other) = default;
+
+  ~ShaderBlockBuffer();
+
+  void *data() const
+  {
+    return m_data;
+  };
+
+  const ShaderBlockType &type_info() const
+  {
+    return m_type_info;
+  }
+
+  bool uniform_int(int location, int comp_len, int array_size, const int *data);
+  bool uniform_f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list