Shared parameter sets
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Shared parameter sets
I pulled off one of the 1.8 TODO items today, shared parameter sets.
You can now define a named, shared parameter set by using GpuProgramManager::createSharedParameters. You define the structure of the parameter set through that, and set values on it in much the same way as you do for GpuProgramParameters. You can then reference that shared parameter set using GpuProgramParameters::addSharedParameters, and any values that match that you set in the shared parameter set will become available to that material. From then on when you need to update the parameters for all materials referencing this set, you only have to do so in one place, ie on the shared parameters.
Note that only manual parameters are supported in the shared parameter sets for now (no auto parameters). Since this is primarily designed to reduce the effort involved in updating manual parameters across many materials, auto parameters are not needed.
Also note that you can use the shared parameter set even if you don't use all of the parameters contained within it. It will simply match up the relevant ones and use those. Obviously, only named parameters are supported.
Shared parameter sets are named so that you can reference them easily in scripts and from elsewhere in code. I'm still working on the scripting interface to this though, only the code-level version is in SVN right now.
The base implementation involves the values in the shared parameter set being copied across to the individual parameter sets when being bound. However, it is up to the rendersystem whether this copying actually happens, and there are Ogre::Any variables on GpuProgramParameters, GpuSharedParameters and GpuSharedParametersUsage designed to hold RenderSystem-specific data should it wish to take another approach. For example, in Dx10 you could detect matches with a separate constant buffer defined in the code, and instead of copying / merging values, store the shared parameter set in its own constant buffer and only update it once per frame (there's a frame number counter on it to help with this). I haven't implemented this yet but the facility is there. This could also be done in GLSL with GL_EXT_bindable_uniform, although from the searching I've done it doesn't seem to be very well supported.
I'll be sorting out the script interface for my next update anyway. Hope this is useful to people.
You can now define a named, shared parameter set by using GpuProgramManager::createSharedParameters. You define the structure of the parameter set through that, and set values on it in much the same way as you do for GpuProgramParameters. You can then reference that shared parameter set using GpuProgramParameters::addSharedParameters, and any values that match that you set in the shared parameter set will become available to that material. From then on when you need to update the parameters for all materials referencing this set, you only have to do so in one place, ie on the shared parameters.
Note that only manual parameters are supported in the shared parameter sets for now (no auto parameters). Since this is primarily designed to reduce the effort involved in updating manual parameters across many materials, auto parameters are not needed.
Also note that you can use the shared parameter set even if you don't use all of the parameters contained within it. It will simply match up the relevant ones and use those. Obviously, only named parameters are supported.
Shared parameter sets are named so that you can reference them easily in scripts and from elsewhere in code. I'm still working on the scripting interface to this though, only the code-level version is in SVN right now.
The base implementation involves the values in the shared parameter set being copied across to the individual parameter sets when being bound. However, it is up to the rendersystem whether this copying actually happens, and there are Ogre::Any variables on GpuProgramParameters, GpuSharedParameters and GpuSharedParametersUsage designed to hold RenderSystem-specific data should it wish to take another approach. For example, in Dx10 you could detect matches with a separate constant buffer defined in the code, and instead of copying / merging values, store the shared parameter set in its own constant buffer and only update it once per frame (there's a frame number counter on it to help with this). I haven't implemented this yet but the facility is there. This could also be done in GLSL with GL_EXT_bindable_uniform, although from the searching I've done it doesn't seem to be very well supported.
I'll be sorting out the script interface for my next update anyway. Hope this is useful to people.
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Code example:
Code: Select all
testSharedParams = GpuProgramManager::getSingleton().createSharedParameters("SinbadsParams");
// define the shared param structure
testSharedParams->addConstantDefinition("colourInput", GCT_FLOAT4);
testSharedParams->addConstantDefinition("someFloatParam", GCT_FLOAT1);
// set some initial values
Vector4 col(0.7, 0.0, 0.0, 1.0);
testSharedParams->setNamedConstant("colourInput", col);
testSharedParams->setNamedConstant("someFloatParam", 0.1f);
// reference shared params, and set autos
GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
params ->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
params ->addSharedParameters("SinbadsParams");
params = pass2->getVertexProgramParameters();
params ->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
params ->addSharedParameters("SinbadsParams");
// now I can update testSharedParams and it will affect both param sets in both materials / passes
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Re: Shared parameter sets
Nice work, I can see many uses for this.
Watch out for my OGRE related tweets here.
- Wolfmanfx
- OGRE Team Member
- Posts: 1525
- Joined: Fri Feb 03, 2006 10:37 pm
- Location: Austria - Leoben
- x 99
- Contact:
Re: Shared parameter sets
A nice addtion would to automate the registration of the shared parameter set so that GpuProgramManager adds the shared parameter to every gpu programs (or just Global Shared parameters).
- Kencho
- OGRE Retired Moderator
- Posts: 4011
- Joined: Fri Sep 19, 2003 6:28 pm
- Location: Burgos, Spain
- x 2
- Contact:
- iloseall
- Gremlin
- Posts: 156
- Joined: Sun Sep 14, 2003 3:54 am
- Location: Beijing China
- Contact:
Re: Shared parameter sets
Thanks!
I think I can provide Parameters of Wind(Dynamic) into all of Material easily Now.
I think I can provide Parameters of Wind(Dynamic) into all of Material easily Now.
-
- Hobgoblin
- Posts: 554
- Joined: Tue Nov 14, 2006 3:26 pm
- x 7
Re: Shared parameter sets
Hey, that's really cool.
I was doing this externally, via something called 'ParamManager'. Now I can use this
Many thanks!
I was doing this externally, via something called 'ParamManager'. Now I can use this
Many thanks!
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Hmm, interesting idea. I went with 'shared' rather than 'global' just because I thought it was more flexible to be able to have more than one set. But maybe an option to make the set be merged into all parameter sets created since then is doable (slight timing issues with having loaded the program so that names can be matched up, but probably not impossible).Wolfmanfx wrote:A nice addtion would to automate the registration of the shared parameter set so that GpuProgramManager adds the shared parameter to every gpu programs (or just Global Shared parameters).
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Ok, scripting support has now been added.
Initial values are supported, although if you never change these values then it's not worth using a shared parameter set at all. But, I figured people might want to set them up with defaults in the script and alter them in code later. Arrays and matrix types are supported too. The manual is updated with the details.
Further enhancements for Dx10 constant buffers and automatically included shared param sets may be considered later.
Code: Select all
shared_params SomeSharedParams
{
// A parameter with values initialised
shared_param_named colourParam float4 0.3 0.2 0.1 1
// An array parameter
shared_param_named someArrayParam float4 [3]
// A matrix parameter
shared_param_named aMatrixParam matrix4x4
}
material TestShared1
{
technique
{
pass
{
vertex_program_ref YayForShadersvp
{
shared_params_ref SomeSharedParams
// other parameters (autos and pass-specific manual settings)
}
// and so on
}
}
}
Further enhancements for Dx10 constant buffers and automatically included shared param sets may be considered later.
- haffax
- OGRE Retired Moderator
- Posts: 4823
- Joined: Fri Jun 18, 2004 1:40 pm
- Location: Berlin, Germany
- x 7
- Contact:
Re: Shared parameter sets
Very good. This makes consistent forward shading much easier to implement. Thanks.
- iloseall
- Gremlin
- Posts: 156
- Joined: Sun Sep 14, 2003 3:54 am
- Location: Beijing China
- Contact:
Re: Shared parameter sets
I try to use Shared Parameter in my Editor project.
I can not modify the ConstantDefinition in GpuSharedParameters.
I add "removeAllConstantDefinition" method for this.
https://sourceforge.net/tracker2/?func= ... tid=302997
I can not modify the ConstantDefinition in GpuSharedParameters.
I add "removeAllConstantDefinition" method for this.
https://sourceforge.net/tracker2/?func= ... tid=302997
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Ok thanks, but it's important to note that for performance, the mapping between the shared parameter set and the GpuProgramParameters is set up when the shared set is first referenced by the parameters. Therefore, changing the shared set at runtime when parameters are referencing it is dangerous - it's safe to add new entries (existing param sets referring to the shared set will just never see them), but removing them can cause a crash if you don't also detach and reattach the shared sets to the parameter sets. This was the reason for omitting a 'remove' method.
We can add remove methods, but a strong health warning needs to be put on it.
We can add remove methods, but a strong health warning needs to be put on it.
- iloseall
- Gremlin
- Posts: 156
- Joined: Sun Sep 14, 2003 3:54 am
- Location: Beijing China
- Contact:
Re: Shared parameter sets
In my editor , shared parameter set, material,compositor can be modified dynamic for.
remove method only used for Developer in Editor.So he can try difference shared parameters and type match the shader's modify.
I think in release client , it is stable.
I has use shared parameter set for dynamic wind direction and force for all tree\grass. And it work fine.
Set the shared parameter ref in my tree ,grass ,etc material .then update the wind parameters in FrameListener::update with wind function.
I like shared parameter.
Can I set a sampler(Cube) parameter in shared parameter set?So I can change env cube dynamic with Charactor position and attach it for all object easily.
remove method only used for Developer in Editor.So he can try difference shared parameters and type match the shader's modify.
I think in release client , it is stable.
I has use shared parameter set for dynamic wind direction and force for all tree\grass. And it work fine.
Set the shared parameter ref in my tree ,grass ,etc material .then update the wind parameters in FrameListener::update with wind function.
I like shared parameter.
Can I set a sampler(Cube) parameter in shared parameter set?So I can change env cube dynamic with Charactor position and attach it for all object easily.
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Not with this feature, since it only controls parameters rather than other material properties like texture bindings. You can do this kind of thing with script templates, but of course that doesn't help at runtime.iloseall wrote:Can I set a sampler(Cube) parameter in shared parameter set?So I can change env cube dynamic with Charactor position and attach it for all object easily.
What you could do though is use a single named Texture instance, and use a manual loader to populate the content. When you want to change it, reload it and repopulate the data from another file in your manual loader (the texture can still be called the same thing). Any materials using that texture will then get the new content. The standard loader assumes name == filename, but that doesn't have to be the case.
- lf3thn4d
- Orc
- Posts: 478
- Joined: Mon Apr 10, 2006 9:12 pm
- x 12
Re: Shared parameter sets
Hey, this sounds like just THE thing for PSSM split points! I like!
-
- Greenskin
- Posts: 116
- Joined: Tue Feb 06, 2007 8:54 pm
- Location: Berlin, Germany
- x 25
Re: Shared parameter sets
Or global shadow softness. A really useful feature!
Generated with vBaum - voxel based procedural geometry generator with python interface.
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
For info, I put in a more robust mechanism for picking up changes to the shared parameter definitions when params are already using them. You can remove individual or all definitions now and add new ones, and the changes will be picked up.
-
- Halfling
- Posts: 63
- Joined: Sun Jan 23, 2005 1:04 pm
- Location: Poland
Re: Shared parameter sets
Actually, both NVIDIA and AMD supports GL_EXT_bindable_uniform. AMD has implemented this extension in new Catalyst 9.2 driver.This could also be done in GLSL with GL_EXT_bindable_uniform, although from the searching I've done it doesn't seem to be very well supported.
-
- Gremlin
- Posts: 196
- Joined: Tue Aug 08, 2006 6:45 pm
- x 14
Re: Shared parameter sets
I've a question, if I create shaders in code with HighLevelGpuProgramManager::createProgram then set the program in a pass I'll already have named params for e.g. getVertexProgramParameters(). I tried just doing pass->getVertexProgramParameters()->addSharedParameters, which didn't seem to work. So are some of the named params then in two places, once in the normal params and once in the shared set? And is there an easier way to get what i want than sort of comparing the two and creating a third that doesn't include any of the shared sets params in the base and then doing addSharedParameters, I think that might get tricky.
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
The shared parameters don't change what's already present in the actual per-pass parameters. What it does is create a mapping from the named parameter in the shared set to the named parameter in the pass-specific set, and automatically updates them. The mapping is very efficient since its based on buffer offsets, not the name, after the association has been set.
I don't see what's 'tricky'. Create a shared parameter set to contain your shared parameters, with the same names as the parameters you want to match up with. Then add the shared parameters to as many pass-specific params as you like. OGRE then updates all the pass instances from that one shared set which you update.
I don't see what's 'tricky'. Create a shared parameter set to contain your shared parameters, with the same names as the parameters you want to match up with. Then add the shared parameters to as many pass-specific params as you like. OGRE then updates all the pass instances from that one shared set which you update.
-
- Gremlin
- Posts: 196
- Joined: Tue Aug 08, 2006 6:45 pm
- x 14
Re: Shared parameter sets
Think I've realised what I was doing wrong, I was cloning a material that used shared parameters, but clone didn't seem to actually clone the link
- sinbad
- OGRE Retired Team Member
- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 66
- Contact:
Re: Shared parameter sets
Ok, this is a bug; GpuSharedParametersUsage needs re-pointing after being copied to point at the clone.cloud wrote:Think I've realised what I was doing wrong, I was cloning a material that used shared parameters, but clone didn't seem to actually clone the link