StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Allowing more control over the life-time of material shader programs #45

Closed jarrodmoldrich closed 11 years ago

jarrodmoldrich commented 11 years ago

\ SORRY FOR THE DOUBLE UP! - First request I've made, didn't think to branch first...

First of all: Thanks so much for this extensions. Saved me a huge amount of time for rendering basic primitives - something that's pretty well needed in most games, if only for debugging. Came across a few hurdles in my particular use case that I think might be of benefit for other people. I originally forked from the wrong person - hopefully that doesn't cause any problems (I've adjusted my upstream accordingly).

Problem:

In situations where SEG is used for only dynamically drawn content, it's possible that all primitives will be destroyed and remade for a particular vertex/fragment shader combo. In such a situation the graphics are cleared each frame - where reference counts will drop to zero for the shader program which will automatically destroy it. At render phase, the missing shader will be re-instantiated. This means the shader program will be remade every frame causing poor performance.

Solution:

Provide a flag that defaults for the usual auto-extinction of shader programs but allows this automatic feature to be disabled. An explicit function is provided which can be executed during the most appropriate time in the game loop according to individual project needs. It iterates through all programs and selects any zero-referenced programs for destruction in one batch.

jonathanrpace commented 11 years ago

This is cool - though I'm going to hold off on merging it. The reason being - I'm currently working on a mini overhaul of the material/texture/shader policy used internally.

Part of this will involves keeping shaders on the GPU longer than is strictly necessary - and only booting them out of memory when they're a) not being used, and b) havn't been used in a while.

This will solve the problem you describe without requiring users to have any extra knowledge about the inner workings of the API.

jarrodmoldrich commented 11 years ago

Cool! That's a nice way of automating it. Though, I'll keep shader program eviction explicit on my fork as it suits me better.

On 23 May 2013 05:45, Jonathan Pace notifications@github.com wrote:

This is cool - though I'm going to hold off on merging it. The reason being - I'm currently working on a mini overhaul of the material/texture/shader policy used internally.

Part of this will involves keeping shaders on the GPU longer than is strictly necessary - and only booting them out of memory when they're a) not being used, and b) havn't been used in a while.

This will solve the problem you describe without requiring users to have any extra knowledge about the inner workings of the API.

— Reply to this email directly or view it on GitHubhttps://github.com/unwrong/Starling-Extension-Graphics/pull/45#issuecomment-18302995 .

Jarrod Moldrich - Mobile Apps Developer mob: +61401686802