[Bf-blender-cvs] [007f1b74a67] master: Cleanup: split off code from gpu_codegen.c into smaller files
Brecht Van Lommel
noreply at git.blender.org
Sat Feb 15 21:13:31 CET 2020
Commit: 007f1b74a67302fb4c164eb26969419434a98aee
Author: Brecht Van Lommel
Date: Wed Feb 12 12:48:44 2020 +0100
Branches: master
https://developer.blender.org/rB007f1b74a67302fb4c164eb26969419434a98aee
Cleanup: split off code from gpu_codegen.c into smaller files
===================================================================
M source/blender/blenlib/BLI_string.h
M source/blender/blenlib/intern/string.c
M source/blender/draw/intern/draw_manager_data.c
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/intern/gpu_codegen.c
M source/blender/gpu/intern/gpu_codegen.h
M source/blender/gpu/intern/gpu_init_exit.c
M source/blender/gpu/intern/gpu_material.c
A source/blender/gpu/intern/gpu_material_library.c
M source/blender/gpu/intern/gpu_material_library.h
A source/blender/gpu/intern/gpu_node_graph.c
A source/blender/gpu/intern/gpu_node_graph.h
M source/blender/gpu/intern/gpu_uniformbuffer.c
===================================================================
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index cab2e68ca2b..cc91c26a2ab 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -118,6 +118,7 @@ int BLI_str_index_in_array_n(const char *__restrict str,
int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array)
ATTR_NONNULL();
+bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_NONNULL();
bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL();
bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t length)
ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 1eed59e568e..acc256226d2 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -900,6 +900,24 @@ int BLI_str_index_in_array(const char *__restrict str, const char **__restrict s
return -1;
}
+/**
+ * Find if a string starts with another string.
+ *
+ * \param str: The string to search within.
+ * \param start: The string we look for at the start.
+ * \return If str starts with start.
+ */
+bool BLI_str_startswith(const char *__restrict str, const char *__restrict start)
+{
+ for (; *str && *start; str++, start++) {
+ if (*str != *start) {
+ return false;
+ }
+ }
+
+ return (*start == '\0');
+}
+
bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t slength)
{
size_t elength = strlen(end);
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index f9a6b663900..1b2195b8e41 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -46,8 +46,10 @@
#endif
#include "GPU_buffers.h"
+#include "GPU_material.h"
#include "intern/gpu_codegen.h"
+#include "intern/gpu_node_graph.h"
/* -------------------------------------------------------------------- */
/** \name Uniform Buffer Object (DRW_uniformbuffer)
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index ea8bcfda92c..0ab3e775566 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -69,7 +69,9 @@ set(SRC
intern/gpu_immediate_util.c
intern/gpu_init_exit.c
intern/gpu_material.c
+ intern/gpu_material_library.c
intern/gpu_matrix.c
+ intern/gpu_node_graph.c
intern/gpu_platform.c
intern/gpu_primitive.c
intern/gpu_select.c
@@ -121,6 +123,7 @@ set(SRC
intern/gpu_context_private.h
intern/gpu_material_library.h
intern/gpu_matrix_private.h
+ intern/gpu_node_graph.h
intern/gpu_primitive_private.h
intern/gpu_private.h
intern/gpu_select_private.h
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 4787015e3d6..2f9af536b8c 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -27,8 +27,6 @@
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
-#include "DNA_material_types.h"
-#include "DNA_node_types.h"
#include "BLI_blenlib.h"
#include "BLI_hash_mm2a.h"
@@ -38,10 +36,10 @@
#include "BLI_ghash.h"
#include "BLI_threads.h"
-#include "BKE_material.h"
-
#include "PIL_time.h"
+#include "BKE_material.h"
+
#include "GPU_extensions.h"
#include "GPU_glew.h"
#include "GPU_material.h"
@@ -53,13 +51,11 @@
#include "gpu_codegen.h"
#include "gpu_material_library.h"
+#include "gpu_node_graph.h"
#include <string.h>
#include <stdarg.h>
-extern char datatoc_gpu_shader_material_glsl[];
-extern char datatoc_gpu_shader_geometry_glsl[];
-
extern char datatoc_gpu_shader_common_obinfos_lib_glsl[];
extern char datatoc_common_view_lib_glsl[];
@@ -132,281 +128,6 @@ static GPUPass *gpu_pass_cache_resolve_collision(GPUPass *pass,
return NULL;
}
-/* -------------------- GPU Codegen ------------------ */
-
-/* type definitions and constants */
-
-#define MAX_FUNCTION_NAME 64
-#define MAX_PARAMETER 32
-
-typedef enum {
- FUNCTION_QUAL_IN,
- FUNCTION_QUAL_OUT,
- FUNCTION_QUAL_INOUT,
-} GPUFunctionQual;
-
-typedef struct GPUFunction {
- char name[MAX_FUNCTION_NAME];
- eGPUType paramtype[MAX_PARAMETER];
- GPUFunctionQual paramqual[MAX_PARAMETER];
- int totparam;
- GPUMaterialLibrary *library;
-} GPUFunction;
-
-/* Indices match the eGPUType enum */
-static const char *GPU_DATATYPE_STR[17] = {
- "",
- "float",
- "vec2",
- "vec3",
- "vec4",
- NULL,
- NULL,
- NULL,
- NULL,
- "mat3",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- "mat4",
-};
-
-/* GLSL code parsing for finding function definitions.
- * These are stored in a hash for lookup when creating a material. */
-
-static GHash *FUNCTION_HASH = NULL;
-#if 0
-static char *FUNCTION_PROTOTYPES = NULL;
-static GPUShader *FUNCTION_LIB = NULL;
-#endif
-
-static int gpu_str_prefix(const char *str, const char *prefix)
-{
- while (*str && *prefix) {
- if (*str != *prefix) {
- return 0;
- }
-
- str++;
- prefix++;
- }
-
- return (*prefix == '\0');
-}
-
-static char *gpu_str_skip_token(char *str, char *token, int max)
-{
- int len = 0;
-
- /* skip a variable/function name */
- while (*str) {
- if (ELEM(*str, ' ', '(', ')', ',', ';', '\t', '\n', '\r')) {
- break;
- }
- else {
- if (token && len < max - 1) {
- *token = *str;
- token++;
- len++;
- }
- str++;
- }
- }
-
- if (token) {
- *token = '\0';
- }
-
- /* skip the next special characters:
- * note the missing ')' */
- while (*str) {
- if (ELEM(*str, ' ', '(', ',', ';', '\t', '\n', '\r')) {
- str++;
- }
- else {
- break;
- }
- }
-
- return str;
-}
-
-static void gpu_parse_material_library(GHash *hash, GPUMaterialLibrary *library)
-{
- GPUFunction *function;
- eGPUType type;
- GPUFunctionQual qual;
- int i;
- char *code = library->code;
-
- while ((code = strstr(code, "void "))) {
- function = MEM_callocN(sizeof(GPUFunction), "GPUFunction");
- function->library = library;
-
- code = gpu_str_skip_token(code, NULL, 0);
- code = gpu_str_skip_token(code, function->name, MAX_FUNCTION_NAME);
-
- /* get parameters */
- while (*code && *code != ')') {
- /* test if it's an input or output */
- qual = FUNCTION_QUAL_IN;
- if (gpu_str_prefix(code, "out ")) {
- qual = FUNCTION_QUAL_OUT;
- }
- if (gpu_str_prefix(code, "inout ")) {
- qual = FUNCTION_QUAL_INOUT;
- }
- if ((qual != FUNCTION_QUAL_IN) || gpu_str_prefix(code, "in ")) {
- code = gpu_str_skip_token(code, NULL, 0);
- }
-
- /* test for type */
- type = GPU_NONE;
- for (i = 1; i < ARRAY_SIZE(GPU_DATATYPE_STR); i++) {
- if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
- type = i;
- break;
- }
- }
-
- if (!type && gpu_str_prefix(code, "samplerCube")) {
- type = GPU_TEXCUBE;
- }
- if (!type && gpu_str_prefix(code, "sampler2DShadow")) {
- type = GPU_SHADOW2D;
- }
- if (!type && gpu_str_prefix(code, "sampler1DArray")) {
- type = GPU_TEX1D_ARRAY;
- }
- if (!type && gpu_str_prefix(code, "sampler2DArray")) {
- type = GPU_TEX2D_ARRAY;
- }
- if (!type && gpu_str_prefix(code, "sampler2D")) {
- type = GPU_TEX2D;
- }
- if (!type && gpu_str_prefix(code, "sampler3D")) {
- type = GPU_TEX3D;
- }
-
- if (!type && gpu_str_prefix(code, "Closure")) {
- type = GPU_CLOSURE;
- }
-
- if (type) {
- /* add parameter */
- code = gpu_str_skip_token(code, NULL, 0);
- code = gpu_str_skip_token(code, NULL, 0);
- function->paramqual[function->totparam] = qual;
- function->paramtype[function->totparam] = type;
- function->totparam++;
- }
- else {
- fprintf(stderr, "GPU invalid function parameter in %s.\n", function->name);
- break;
- }
- }
-
- if (function->name[0] == '\0' || function->totparam == 0) {
- fprintf(stderr, "GPU functions parse error.\n");
- MEM_freeN(function);
- break;
- }
-
- BLI_ghash_insert(hash, function->name, function);
- }
-}
-
-#if 0
-static char *gpu_generate_function_prototyps(GHash *hash)
-{
- DynStr *ds = BLI_dynstr_new();
- GHashIterator *ghi;
- GPUFunction *function;
- char *name, *prototypes;
- int a;
-
- /* automatically generate function prototypes to add to the top of the
- * generated code, to avoid have to add the actual code & recompile all */
- ghi = BLI_ghashIterator_new(hash);
-
- for (; !BLI_ghashIterator_done(ghi); BLI_ghashIterator_step(ghi)) {
- name = BLI_ghashIterator_getValue(ghi);
- function = BLI_ghashIterator_getValue(ghi);
-
- BLI_dynstr_appendf(ds, "void %s(", name);
- for (a = 0; a < function->totparam; a++) {
- if (function->paramqual[a] == FUNCTION_QUAL_OUT) {
- BLI_dynstr_append(ds, "out ");
- }
- else if (function->paramqual[a] == FUNCTION_QUAL_INOUT) {
- BLI_dynstr_append(ds, "inout ");
- }
-
- if (function->paramtype[a] == GPU_TEX2D) {
- BLI_dynstr_append(ds, "sampler2D");
- }
- else if (function->paramtype[a] == GPU_SHADOW2D) {
- BLI_dynstr_append(ds, "sampler2DShadow");
- }
- else {
- BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
- }
-# if 0
- BLI_dynstr_appendf(ds, " param%d", a);
-# endif
-
- if (a != function->totparam - 1) {
- BLI_dynstr_append(ds, ", ");
- }
- }
- BLI_dynstr_append(ds, ");\n");
- }
-
- BLI_dynstr_append(ds, "\n");
-
- prototypes = BLI_dynstr_get_cstring(ds);
- BLI_dynstr_free(ds);
-
- return prototypes;
-}
-#endif
-
-static GPUFunction *gpu_lookup_function(const char *name)
-{
- return BLI_ghash_lookup(FUNCTION_HASH, (const void *)name);
-}
-
-void gpu_codegen_init(void)
-{
- GPU_code_generate_glsl_lib();
-}
-
-void gpu_codegen_exit(void)
-{
- BKE_material_defaults_free_gpu();
-
- if (FUNCTION_HAS
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list