Sunset Lake Software - Comments for "Concurrent filter initialization and usage" http://www.sunsetlakesoftware.com/forum/concurrent-filter-initialization-and-usage Comments for "Concurrent filter initialization and usage" en The slow shader compilation http://www.sunsetlakesoftware.com/forum/concurrent-filter-initialization-and-usage#comment-1608 <p>The slow shader compilation was why I tried to cache the shader programs for reuse, but as you can see that had some side-effects. There's a balance to be struck in there somewhere, but I still need to think about it.</p> <p>Shader compilation is done on the CPU, via the OpenGL ES driver, but it needs GPU resources. If I recall correctly, I tried to parallelize this and ended up causing crashes due to shared resources, but I may need to explore that again.</p> pubDate Wed, 10 Oct 2012 18:29:51 +0000 dc:creator Brad Larson guid false comment 1608 at http://www.sunsetlakesoftware.com Hi Brad, thank you for your http://www.sunsetlakesoftware.com/forum/concurrent-filter-initialization-and-usage#comment-1607 <p>Hi Brad,</p> <p>thank you for your answer and for the great framework.</p> <p>Maybe you're right about the crashes I see when using concurrently CoreImage and GPUImage: that may be a memory-related issue.</p> <p>About the parameter issue: OK, I'll wait for the fix.</p> <p>I understand that I'm not gaining much by parallelizing the creation/parametrization/usage of the filters; I'm now using them serially, and that's fine. However, it seems to me that the most time-consuming part is the shader compilation, which happens during the filter allocation/initialization phase if I'm right; where does this compilation happen? GPU or CPU? Is it parallelizable in principle if you need to set up a set of filters?</p> pubDate Wed, 10 Oct 2012 15:33:28 +0000 dc:creator mabene guid false comment 1607 at http://www.sunsetlakesoftware.com The whole framework used to http://www.sunsetlakesoftware.com/forum/concurrent-filter-initialization-and-usage#comment-1606 <p>The whole framework used to be completely unsafe to use around any kind of threading. I changed that about a month ago, when I implemented a core serial dispatch queue that runs on a background thread for doing the image processing. I have to use a single queue, because that needs to lock around the shared OpenGL ES context used by the framework.</p> <p>This context should be distinct from Core Image's OpenGL ES context (unless you somehow are sharing the two), so there should be no conflicts there. Are you sure this isn't a memory-related crash, because others have run into that while having the two operate in parallel.</p> <p>As far as the odd artifacts with multiple filters of the same type, that's a known bug in an optimization I implemented a couple of weeks ago. I tried to avoid having to recompile shader programs of the same type by caching them, but that has lead to problems where setting parameters on one shader program sets them for all instances of that program. I'm working on a fix for that. This is unrelated to any threading issues.</p> <p>In reality, you gain little by trying to parallelize any processing using this framework, because only one thing can use the GPU at a time. The threading benefits have already been realized by moving the framework's processing off of the main thread and by allowing for certain CPU and GPU actions to run in parallel (leading to a ~10-20% speedup with many filters, and preventing the main thread from being blocked or blocking the processing in the framework). Still, it should be safe to attempt to initialize and use several filters at once, because I've tried to protect against undesirable changes in the OpenGL ES state machine. Perhaps I haven't caught all of the cases here.</p> pubDate Wed, 10 Oct 2012 14:43:41 +0000 dc:creator Brad Larson guid false comment 1606 at http://www.sunsetlakesoftware.com I was able to answer this http://www.sunsetlakesoftware.com/forum/concurrent-filter-initialization-and-usage#comment-1605 <p>I was able to answer this myself; I just wanted to share.</p> <p>So, it seems like the underpinnings of GPUImage are not thread safe, as they rely on a shared openGLES context.<br /> The framework itself is taking actions against possible thread-safety issues by serializing all the key operation on a serial CGD queue (called "com.sunsetlakesoftware.GPUImage.openGLESContextQueue").<br /> This means that by dispatching asynchronously and concurrently my 16 filters I was under the *impression* of having them work in parallel; in fact, everything was being serialized by the framework queue.</p> <p>This is sufficient to explain issue (3): CIFilter is not (of course) using the same serialization queue and is possibly causing race conditions on the use of openGLES resources.</p> <p>Issue (1) and (2) are more complex; the typical three-step workflow (allocate-parametrize-use filter) is dispatched by the GPUImage framework as three (or more) separate blocks on the serial queue. If you ask concurrently to allocate-parametrize-use several filters, these three steps from different filters may be interspersed with unpredictable results.</p> <p>The bottom line seems to be that it's only safe to use one filter (or chain of filters) at a time.<br /> Or am I missing something?</p> pubDate Wed, 10 Oct 2012 12:58:38 +0000 dc:creator mabene guid false comment 1605 at http://www.sunsetlakesoftware.com