diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-09-14 02:02:10 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-09-14 02:03:19 +0300 |
commit | 3b080c3f66c05751f02af9a3f509c1a46b34ba20 (patch) | |
tree | 088047279fa0fde5815cbea609e45b2e2239d91b /source | |
parent | a01fbc66897b440589a86ce1e1008a91bc28b14d (diff) |
GPUCodegen: Add New GPU_SOURCE_STRUCT to be used for Closure Sockets
This way we dont rely on the static array of chars that was causing T52385.
That fixes T52385.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/gpu/GPU_material.h | 9 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 49 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.h | 3 |
3 files changed, 38 insertions, 23 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 47035c8c64e..7bc256a70fa 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -70,6 +70,7 @@ typedef struct GPUParticleInfo GPUParticleInfo; /* Functions to create GPU Materials nodes */ typedef enum GPUType { + /* Keep in sync with GPU_DATATYPE_STR */ /* The value indicates the number of elements in each type */ GPU_NONE = 0, GPU_FLOAT = 1, @@ -79,11 +80,15 @@ typedef enum GPUType { GPU_MAT3 = 9, GPU_MAT4 = 16, - GPU_CLOSURE = 17, - + /* Values not in GPU_DATATYPE_STR */ GPU_TEX2D = 1002, GPU_SHADOW2D = 1003, GPU_TEXCUBE = 1004, + + /* GLSL Struct types */ + GPU_CLOSURE = 1005, + + /* Opengl Attributes */ GPU_ATTRIB = 3001 } GPUType; diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 9fa78bfe5b9..871a754c23a 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -88,10 +88,9 @@ typedef struct GPUFunction { } GPUFunction; /* Indices match the GPUType enum */ -static const char *GPU_DATATYPE_STR[18] = { +static const char *GPU_DATATYPE_STR[17] = { "", "float", "vec2", "vec3", "vec4", - NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4", - "Closure" + NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4" }; /* GLSL code parsing for finding function definitions. @@ -192,6 +191,10 @@ static void gpu_parse_functions_string(GHash *hash, char *code) type = GPU_TEX2D; } + if (!type && gpu_str_prefix(code, "Closure")) { + type = GPU_CLOSURE; + } + if (type) { /* add parameter */ code = gpu_str_skip_token(code, NULL, 0); @@ -362,11 +365,6 @@ static void codegen_print_datatype(DynStr *ds, const GPUType type, float *data) { int i; - if (type == GPU_CLOSURE) { - BLI_dynstr_append(ds, "CLOSURE_DEFAULT"); - return; - } - BLI_dynstr_appendf(ds, "%s(", GPU_DATATYPE_STR[type]); for (i = 0; i < type; i++) { @@ -550,6 +548,10 @@ static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds, } } } + else if (input->source == GPU_SOURCE_STRUCT) { + /* Add other struct here if needed. */ + BLI_dynstr_appendf(ds, "Closure strct%d = CLOSURE_DEFAULT;\n", input->id); + } else if (input->source == GPU_SOURCE_VEC_UNIFORM) { if (input->dynamictype == GPU_DYNAMIC_UBO) { if (!input->link) { @@ -563,16 +565,8 @@ static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds, GPU_DATATYPE_STR[input->type], input->id); } else { - if (input->type != GPU_CLOSURE) { - /* for others use const so the compiler can do folding */ - BLI_dynstr_appendf(ds, "const %s cons%d = ", - GPU_DATATYPE_STR[input->type], input->id); - } - else { - /* const keyword does not work with struct */ - BLI_dynstr_appendf(ds, "%s cons%d = ", - GPU_DATATYPE_STR[input->type], input->id); - } + BLI_dynstr_appendf(ds, "const %s cons%d = ", + GPU_DATATYPE_STR[input->type], input->id); codegen_print_datatype(ds, input->type, input->vec); BLI_dynstr_append(ds, ";\n"); } @@ -637,8 +631,13 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes) /* declare temporary variables for node output storage */ for (output = node->outputs.first; output; output = output->next) { - BLI_dynstr_appendf(ds, "\t%s tmp%d;\n", - GPU_DATATYPE_STR[output->type], output->id); + if (output->type == GPU_CLOSURE) { + BLI_dynstr_appendf(ds, "\tClosure tmp%d;\n", output->id); + } + else { + BLI_dynstr_appendf(ds, "\t%s tmp%d;\n", + GPU_DATATYPE_STR[output->type], output->id); + } } } @@ -682,6 +681,9 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final else BLI_dynstr_append(ds, GPU_builtin_name(input->builtin)); } + else if (input->source == GPU_SOURCE_STRUCT) { + BLI_dynstr_appendf(ds, "strct%d", input->id); + } else if (input->source == GPU_SOURCE_VEC_UNIFORM) { if (input->dynamicvec) BLI_dynstr_appendf(ds, "unf%d", input->id); @@ -1525,6 +1527,12 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType BLI_strncpy(input->attribname, link->attribname, sizeof(input->attribname)); MEM_freeN(link); } + else if (type == GPU_CLOSURE) { + input->type = type; + input->source = GPU_SOURCE_STRUCT; + + MEM_freeN(link); + } else { /* uniform vector */ input->type = type; @@ -1536,6 +1544,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType input->dynamictype = link->dynamictype; input->dynamicdata = link->ptr2; } + MEM_freeN(link); } diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index 28eb55968bb..14e07a6e012 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -57,7 +57,8 @@ typedef enum GPUDataSource { GPU_SOURCE_OPENGL_BUILTIN, GPU_SOURCE_TEX_PIXEL, GPU_SOURCE_TEX, - GPU_SOURCE_ATTRIB + GPU_SOURCE_ATTRIB, + GPU_SOURCE_STRUCT } GPUDataSource; typedef enum { |