After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660512 - ClutterShaderEffect recompiles the shader for every instance
ClutterShaderEffect recompiles the shader for every instance
Status: RESOLVED FIXED
Product: clutter
Classification: Platform
Component: ClutterEffect
unspecified
Other All
: Normal normal
: ---
Assigned To: clutter-maint
clutter-maint
Depends on:
Blocks:
 
 
Reported: 2011-09-29 19:21 UTC by Neil Roberts
Modified: 2011-09-30 10:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
clutter-shader-effect: Add a get_static_shader_source virtual (13.78 KB, patch)
2011-09-29 19:21 UTC, Neil Roberts
accepted-commit_now Details | Review
Add a conformance test for ClutterShaderEffect (9.19 KB, patch)
2011-09-29 19:21 UTC, Neil Roberts
accepted-commit_now Details | Review

Description Neil Roberts 2011-09-29 19:21:17 UTC
I think most ClutterShaderEffect subclasses just use a single static
shader that gets used for every instance of the effect. However the
current implementation creates a new shader for every instance. This
is enforced by the API because the only way to set the shader source
is by calling clutter_shader_effect_set_shader_source which takes a
string and is per-instance.

This is particularly bad with the current Cogl architecture because
every pipeline created with a brand new state is stored in the program
cache and never freed. This means that anything creating effects for
actors that come and go will leak compiled programs. This eventually
hits a g_warning in Cogl that the program cache is becoming large.
Comment 1 Neil Roberts 2011-09-29 19:21:19 UTC
Created attachment 197802 [details] [review]
clutter-shader-effect: Add a get_static_shader_source virtual

This is used as an alternative to calling
clutter_shader_effect_set_shader_source. A ClutterShaderEffect
subclass is now expected to implement this method to return the source
for the effect that will be used for all instances of this
subclass. It is only called once regardless of the number of instances
created. That way Clutter can avoid recompiling the shader source for
every new instance of the effect.
Comment 2 Neil Roberts 2011-09-29 19:21:22 UTC
Created attachment 197803 [details] [review]
Add a conformance test for ClutterShaderEffect

This adds a simple conformance test which sets up a few shader effects
using both the old style with clutter_shader_effect_set_source and the
new style by overriding get_static_shader_source. The effects are then
verified to confirm that they drew the right pixel colour.
Comment 3 Emmanuele Bassi (:ebassi) 2011-09-29 19:41:26 UTC
Review of attachment 197802 [details] [review]:

looks good to me, apart from minor coding style/documentation issues; if you could fix them before committing it would be great.

::: clutter/clutter-shader-effect.c
@@ +166,3 @@
 
+G_DEFINE_TYPE_WITH_CODE
+           (ClutterShaderEffect,

please, don't break the line here. if you need a bigger screen I think we can arrange that. :-p

@@ +344,3 @@
+    CLUTTER_SHADER_EFFECT_GET_CLASS (self);
+
+clutter_shader_effect_try_static_source (ClutterShaderEffect *self)

please, add "!= NULL": I prefer explicit comparisons for pointers.

::: clutter/clutter-shader-effect.h
@@ +70,1 @@
  *

why did you delete the rest of the description?

gtk-doc will actively complain.
Comment 4 Emmanuele Bassi (:ebassi) 2011-09-29 19:42:32 UTC
Review of attachment 197803 [details] [review]:

looks good to me.
Comment 5 Neil Roberts 2011-09-29 20:03:07 UTC
Review of attachment 197802 [details] [review]:

::: clutter/clutter-shader-effect.h
@@ +70,1 @@
  *

The ClutterShaderEffectClass structure no longer contains only private data so it wouldn't make any sense to leave it in. gtk-doc didn't seem to complain when I tried compiling it.
Comment 6 Emmanuele Bassi (:ebassi) 2011-09-29 21:23:58 UTC
(In reply to comment #5)
> Review of attachment 197802 [details] [review]:
> 
> ::: clutter/clutter-shader-effect.h
> @@ +70,1 @@
>   *
> 
> The ClutterShaderEffectClass structure no longer contains only private data so
> it wouldn't make any sense to leave it in. gtk-doc didn't seem to complain when
> I tried compiling it.

no, it contains only private data. all class structures are defined as such; vfuncs that are public are marked as public, and thus appear in the documentation - everything else inside it is considered private.
Comment 7 Neil Roberts 2011-09-30 10:59:28 UTC
> no, it contains only private data. all class structures are defined as such;
> vfuncs that are public are marked as public, and thus appear in the
> documentation - everything else inside it is considered private.

Well, I don't really understand your reasoning to be honest ('it only contains private data except for the things that aren't private') but I'll leave it in anyway. I've pushed the patches as 8b995a9 and 3372a02. I even did the overly long line change even though it made me feel ill ;)