Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProgramState and Program performance issues #20188

Closed
Mee-gu opened this issue Oct 10, 2019 · 3 comments
Closed

ProgramState and Program performance issues #20188

Mee-gu opened this issue Oct 10, 2019 · 3 comments
Milestone

Comments

@Mee-gu
Copy link
Contributor

Mee-gu commented Oct 10, 2019

You can find discussion of related issues here.
After discussion with @minggo , we want to simplify the work of ProgramState and Program in following ways:

  1. for Program usage, it was create in following two ways:
    • for engine built-in Program, we can use static way static Program* Program::getBuiltinProgram(ProgramType type); to get a Program instance. An internal ProgramCache will caching those built-in Program.
    • for user-define Program, we can use Program* Device::newProgram(const std::string& vertexShader, const std::string& fragmentShader); to new a Program instance. The developers can do caching for those user-define Program themselves.
  2. for ProgramState usage, there is only one way to create a instance of the ProgramState by its constructor: ProgramState(Program* program);, the parameter program either comes from step 1 or step 2.
  • scenario 1, use built-in Program to create the ProgramState
auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR);
auto programState = new (std::nothrow) backend::ProgramState(program);
...
CC_SAFE_RELEASE(programState);
...
  • scenario 2, use user-define 'Program' to create the ProgramState
auto program = backend::Device::getInstance()->newProgram(positionTextureColor_vert, positionTextureColor_frag);
auto programState = new (std::nothrow) backend::ProgramState(program);
...
CC_SAFE_RELEASE(program);
CC_SAFE_RELEASE(programState);
...

Any feedback would appreciate.

@Mee-gu Mee-gu added this to the 4.0 milestone Oct 10, 2019
@minggo
Copy link
Contributor

minggo commented Oct 10, 2019

@Mee-gu add some codes is better to describe it.

@Mee-gu
Copy link
Contributor Author

Mee-gu commented Oct 10, 2019

@Mee-gu add some codes is better to describe it.

Got it, complete it soon.

@rh101
Copy link
Contributor

rh101 commented Oct 10, 2019

Personally, I don't mind adding my own caching layer to handle the caching of Program instances (user-defined or built-in, it won't matter).

I can imagine that a significant number of developers would end up having to create their own caching layer, and this fact alone is usually an indicator that it would have been better served to make it part of the Cocos2d-x framework.

Regardless, if you feel strongly about not adding caching in the framework for user-defined scripts in a way that allows for custom identifiers, or returning of the hash keys, then that's fine.

The only thing that we really need, and which doesn't exist in v4rc0, is this public constructor:

ProgramState(Program* program);

Once that function is added, then it will allow developers to create ProgramState from previously created Program instances, and we can implement our own caching layer to handle these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants