From 1c1a3198af9dad58ff0a09e0828f64df5d9a4646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 28 Sep 2019 00:35:12 +0200 Subject: EEVEE: Speedup: Don't request orco layer if not needed Should speed up eevee mesh update a tiny bit in certain particular cases (deform modifier + (shader using texcoord (but not generated output) OR principled bsdf OR geometry node (except tangent output))). --- source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c | 2 ++ source/blender/nodes/shader/nodes/node_shader_geometry.c | 6 ++++-- source/blender/nodes/shader/nodes/node_shader_tex_coord.c | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c index 595ddf27d0a..3340054396d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c @@ -120,6 +120,7 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, GPU_link(mat, "world_normals_get", &in[20].link); } +#if 0 /* Not used at the moment. */ /* Tangents */ if (!in[21].link) { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); @@ -131,6 +132,7 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, GPU_builtin(GPU_OBJECT_MATRIX), &in[21].link); } +#endif bool use_diffuse = socket_not_one(4) && socket_not_one(15); bool use_subsurf = socket_not_zero(1) && use_diffuse && node->sss_id > 0; diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.c b/source/blender/nodes/shader/nodes/node_shader_geometry.c index df9a8ac8318..d94141c3699 100644 --- a/source/blender/nodes/shader/nodes/node_shader_geometry.c +++ b/source/blender/nodes/shader/nodes/node_shader_geometry.c @@ -41,9 +41,11 @@ static int node_shader_gpu_geometry(GPUMaterial *mat, { /* HACK: Don't request GPU_BARYCENTRIC_TEXCO if not used because it will * trigger the use of geometry shader (and the performance penalty it implies). */ - float val[2] = {0.0f, 0.0f}; + float val[4] = {0.0f, 0.0f, 0.0f, 0.0f}; GPUNodeLink *bary_link = (!out[5].hasoutput) ? GPU_constant(val) : GPU_builtin(GPU_BARYCENTRIC_TEXCO); + /* Opti: don't request orco if not needed. */ + GPUNodeLink *orco_link = (!out[2].hasoutput) ? GPU_constant(val) : GPU_attribute(CD_ORCO, ""); return GPU_stack_link(mat, node, @@ -52,7 +54,7 @@ static int node_shader_gpu_geometry(GPUMaterial *mat, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_WORLD_NORMAL), - GPU_attribute(CD_ORCO, ""), + orco_link, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), bary_link); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c index 637aeb3c182..068458b7e1f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -45,14 +45,17 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat, GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) : GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); - /* TODO only request orco if needed. */ - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + /* Opti: don't request orco if not needed. */ + GPUNodeLink *orco = (!out[0].hasoutput) ? GPU_constant((float[4]){0.0f, 0.0f, 0.0f, 0.0f}) : + GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); GPUNodeLink *viewpos = GPU_builtin(GPU_VIEW_POSITION); GPUNodeLink *worldnor = GPU_builtin(GPU_WORLD_NORMAL); GPUNodeLink *texcofacs = GPU_builtin(GPU_CAMERA_TEXCO_FACTORS); - GPU_link(mat, "generated_from_orco", orco, &orco); + if (out[0].hasoutput) { + GPU_link(mat, "generated_from_orco", orco, &orco); + } GPU_stack_link( mat, node, "node_tex_coord", in, out, viewpos, worldnor, inv_obmat, texcofacs, orco, mtface); -- cgit v1.2.3