[Bf-blender-cvs] [efd44f8480b] blender2.8: Cleanup: GPU codegen: remove most of legacy code

Clément Foucault noreply at git.blender.org
Mon Aug 13 23:02:39 CEST 2018


Commit: efd44f8480b692e169155f5f35077a76969f6844
Author: Clément Foucault
Date:   Mon Aug 13 18:44:27 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBefd44f8480b692e169155f5f35077a76969f6844

Cleanup: GPU codegen: remove most of legacy code

A lot of code in codegen was used by previous GLSL system.
Now most of it is not used due to all the things being written from scratch
in 2.8 and we can clean most of it.

As a side not this make the system a bit less flexible (no support for
cubemaps, preview image, etc...) but can be extended again.

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

M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_codegen.h
M	source/blender/gpu/intern/gpu_uniformbuffer.c

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

diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index b97101c0e6d..08045687795 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -757,46 +757,25 @@ static DRWShadingGroup *drw_shgroup_material_create_ex(GPUPass *gpupass, DRWPass
 
 static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp, struct GPUMaterial *material)
 {
-	/* TODO : Ideally we should not convert. But since the whole codegen
-	 * is relying on GPUPass we keep it as is for now. */
-
 	ListBase *inputs = GPU_material_get_inputs(material);
 
 	/* Converting dynamic GPUInput to DRWUniform */
 	for (GPUInput *input = inputs->first; input; input = input->next) {
 		/* Textures */
-		if (input->ima) {
-			double time = 0.0; /* TODO make time variable */
-			GPUTexture *tex = GPU_texture_from_blender(
-			        input->ima, input->iuser, input->textarget, input->image_isdata, time);
+		if (input->source == GPU_SOURCE_TEX) {
+			GPUTexture *tex = NULL;
 
-			if (input->bindtex) {
-				DRW_shgroup_uniform_texture(grp, input->shadername, tex);
+			if (input->ima) {
+				double time = 0.0; /* TODO make time variable */
+				tex = GPU_texture_from_blender(input->ima, input->iuser, GL_TEXTURE_2D, input->image_isdata, time);
 			}
-		}
-		/* Color Ramps */
-		else if (input->tex) {
-			/* HACK : input->tex is a (GPUTexture **) in this case. */
-			GPUTexture *tex = *((GPUTexture **)input->tex);
-			DRW_shgroup_uniform_texture(grp, input->shadername, tex);
-		}
-		/* Floats */
-		else {
-			switch (input->type) {
-				case GPU_FLOAT:
-				case GPU_VEC2:
-				case GPU_VEC3:
-				case GPU_VEC4:
-					/* Should already be in the material ubo. */
-					break;
-				case GPU_MAT3:
-					DRW_shgroup_uniform_mat3(grp, input->shadername, (float (*)[3])input->dynamicvec);
-					break;
-				case GPU_MAT4:
-					DRW_shgroup_uniform_mat4(grp, input->shadername, (float (*)[4])input->dynamicvec);
-					break;
-				default:
-					break;
+			else {
+				/* Color Ramps */
+				tex = *input->coba;
+			}
+
+			if (input->bindtex) {
+				drw_shgroup_uniform_create_ex(grp, input->shaderloc, DRW_UNIFORM_TEXTURE, tex, 0, 1);
 			}
 		}
 	}
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 5bbe9d6d904..ab55b9c61e7 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -115,11 +115,6 @@ typedef enum GPUBuiltin {
 	GPU_VOLUME_TEMPERATURE =    (1 << 18)
 } GPUBuiltin;
 
-typedef enum GPUOpenGLBuiltin {
-	GPU_MATCAP_NORMAL = 1,
-	GPU_COLOR = 2,
-} GPUOpenGLBuiltin;
-
 typedef enum GPUMatType {
 	GPU_MATERIAL_TYPE_MESH  = 1,
 	GPU_MATERIAL_TYPE_WORLD = 2,
@@ -157,72 +152,6 @@ typedef enum GPUMaterialStatus {
 	GPU_MAT_SUCCESS,
 } GPUMaterialStatus;
 
-#define GPU_DYNAMIC_GROUP_FROM_TYPE(f) ((f) & 0xFFFF0000)
-
-#define GPU_DYNAMIC_GROUP_MISC     0x00010000
-#define GPU_DYNAMIC_GROUP_LAMP     0x00020000
-#define GPU_DYNAMIC_GROUP_OBJECT   0x00030000
-#define GPU_DYNAMIC_GROUP_SAMPLER  0x00040000
-#define GPU_DYNAMIC_GROUP_MIST     0x00050000
-#define GPU_DYNAMIC_GROUP_WORLD    0x00060000
-#define GPU_DYNAMIC_GROUP_MAT      0x00070000
-#define GPU_DYNAMIC_UBO            0x00080000
-
-typedef enum GPUDynamicType {
-
-	GPU_DYNAMIC_NONE                 = 0,
-
-	GPU_DYNAMIC_OBJECT_VIEWMAT       = 1  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_MAT           = 2  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_VIEWIMAT      = 3  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_IMAT          = 4  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_COLOR         = 5  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 6  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT  = 7  | GPU_DYNAMIC_GROUP_OBJECT,
-	GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT = 8  | GPU_DYNAMIC_GROUP_OBJECT,
-
-	GPU_DYNAMIC_LAMP_DYNVEC          = 1  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DYNCO           = 2  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DYNIMAT         = 3  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DYNPERSMAT      = 4  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DYNENERGY       = 5  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DYNCOL          = 6  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_DISTANCE        = 7  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_ATT1            = 8  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_ATT2            = 9  | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_SPOTSIZE        = 10 | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_SPOTBLEND       = 11 | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_SPOTSCALE       = 12 | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_COEFFCONST      = 13 | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_COEFFLIN        = 14 | GPU_DYNAMIC_GROUP_LAMP,
-	GPU_DYNAMIC_LAMP_COEFFQUAD       = 15 | GPU_DYNAMIC_GROUP_LAMP,
-
-	GPU_DYNAMIC_SAMPLER_2DBUFFER     = 1  | GPU_DYNAMIC_GROUP_SAMPLER,
-	GPU_DYNAMIC_SAMPLER_2DIMAGE      = 2  | GPU_DYNAMIC_GROUP_SAMPLER,
-	GPU_DYNAMIC_SAMPLER_2DSHADOW     = 3  | GPU_DYNAMIC_GROUP_SAMPLER,
-
-	GPU_DYNAMIC_MIST_ENABLE          = 1  | GPU_DYNAMIC_GROUP_MIST,
-	GPU_DYNAMIC_MIST_START           = 2  | GPU_DYNAMIC_GROUP_MIST,
-	GPU_DYNAMIC_MIST_DISTANCE        = 3  | GPU_DYNAMIC_GROUP_MIST,
-	GPU_DYNAMIC_MIST_INTENSITY       = 4  | GPU_DYNAMIC_GROUP_MIST,
-	GPU_DYNAMIC_MIST_TYPE            = 5  | GPU_DYNAMIC_GROUP_MIST,
-	GPU_DYNAMIC_MIST_COLOR           = 6  | GPU_DYNAMIC_GROUP_MIST,
-
-	GPU_DYNAMIC_HORIZON_COLOR        = 1  | GPU_DYNAMIC_GROUP_WORLD,
-	GPU_DYNAMIC_AMBIENT_COLOR        = 2  | GPU_DYNAMIC_GROUP_WORLD,
-	GPU_DYNAMIC_ZENITH_COLOR         = 3  | GPU_DYNAMIC_GROUP_WORLD,
-
-	GPU_DYNAMIC_MAT_DIFFRGB          = 1  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_REF              = 2  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_SPECRGB          = 3  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_SPEC             = 4  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_HARD             = 5  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_EMIT             = 6  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_AMB              = 7  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_ALPHA            = 8  | GPU_DYNAMIC_GROUP_MAT,
-	GPU_DYNAMIC_MAT_MIR              = 9  | GPU_DYNAMIC_GROUP_MAT
-} GPUDynamicType;
-
 GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
 GPUNodeLink *GPU_constant(float *num);
 GPUNodeLink *GPU_uniform(float *num);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 0eee9bf6ead..0cda67b8968 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -137,12 +137,8 @@ static GPUPass *gpu_pass_cache_resolve_collision(
 
 /* type definitions and constants */
 
-enum {
-	MAX_FUNCTION_NAME = 64
-};
-enum {
-	MAX_PARAMETER = 32
-};
+#define MAX_FUNCTION_NAME    64
+#define MAX_PARAMETER        32
 
 typedef enum {
 	FUNCTION_QUAL_IN,
@@ -467,10 +463,8 @@ static int codegen_input_has_texture(GPUInput *input)
 {
 	if (input->link)
 		return 0;
-	else if (input->ima || input->prv)
-		return 1;
 	else
-		return input->tex != NULL;
+		return (input->source == GPU_SOURCE_TEX);
 }
 
 const char *GPU_builtin_name(GPUBuiltin builtin)
@@ -535,70 +529,44 @@ static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, void
 
 static void codegen_set_unique_ids(ListBase *nodes)
 {
-	GHash *bindhash, *definehash;
+	GHash *bindhash;
 	GPUNode *node;
 	GPUInput *input;
 	GPUOutput *output;
 	int id = 1, texid = 0;
 
 	bindhash = BLI_ghash_ptr_new("codegen_set_unique_ids1 gh");
-	definehash = BLI_ghash_ptr_new("codegen_set_unique_ids2 gh");
 
 	for (node = nodes->first; node; node = node->next) {
 		for (input = node->inputs.first; input; input = input->next) {
 			/* set id for unique names of uniform variables */
 			input->id = id++;
-			input->bindtex = false;
-			input->definetex = false;
 
-			/* set texid used for settings texture slot with multitexture */
-			if (codegen_input_has_texture(input) &&
-			    ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)))
-			{
-				/* assign only one texid per buffer to avoid sampling
-				 * the same texture twice */
-				if (input->link) {
-					/* input is texture from buffer */
-					codegen_set_texid(bindhash, input, &texid, input->link);
-				}
-				else if (input->ima) {
+			/* set texid used for settings texture slot */
+			if (codegen_input_has_texture(input)) {
+				input->bindtex = false;
+				if (input->ima) {
 					/* input is texture from image */
 					codegen_set_texid(bindhash, input, &texid, input->ima);
 				}
-				else if (input->prv) {
-					/* input is texture from preview render */
-					codegen_set_texid(bindhash, input, &texid, input->prv);
-				}
-				else if (input->tex) {
-					/* input is user created texture, check tex pointer */
-					codegen_set_texid(bindhash, input, &texid, input->tex);
+				else if (input->coba) {
+					/* input is color band texture, check coba pointer */
+					codegen_set_texid(bindhash, input, &texid, input->coba);
 				}
-
-				/* make sure this pixel is defined exactly once */
-				if (input->source == GPU_SOURCE_TEX_PIXEL) {
-					if (input->ima) {
-						if (!BLI_ghash_haskey(definehash, input->ima)) {
-							input->definetex = true;
-							BLI_ghash_insert(definehash, input->ima, SET_INT_IN_POINTER(input->texid));
-						}
-					}
-					else {
-						if (!BLI_ghash_haskey(definehash, input->link)) {
-							input->definetex = true;
-							BLI_ghash_insert(definehash, input->link, SET_INT_IN_POINTER(input->texid));
-						}
-					}
+				else {
+					/* Either input->ima or input->coba should be non-NULL. */
+					BLI_assert(0);
 				}
 			}
 		}
 
-		for (output = node->outputs.first; output; output = output->next)
+		for (output = node->outputs.first; output; output = output->next) {
 			/* set id for unique names of tmp variables storing output */
 			output->id = id++;
+		}
 	}
 
 	BLI_ghash_free(bindhash, NULL, NULL);
-	BLI_ghash_free(definehash, NULL, NULL);
 }
 
 /**
@@ -615,14 +583,12 @@ static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds,
 	/* print uniforms */
 	for (node = nodes->

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list