Shared parameter sets

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.

Shared parameter sets

Postby sinbad » Tue Feb 17, 2009 6:51 pm

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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby sinbad » Tue Feb 17, 2009 6:54 pm

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


User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby Assaf Raman » Tue Feb 17, 2009 9:01 pm

Nice work, I can see many uses for this.
Watch out for my OGRE related tweets here.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
 
Posts: 3089
Kudos: 78
Joined: 11 Apr 2006
Location: TLV, Israel

Re: Shared parameter sets

Postby Wolfmanfx » Tue Feb 17, 2009 10:15 pm

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).
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
 
Posts: 1426
Kudos: 98
Joined: 03 Feb 2006
Location: Austria - Leoben

Re: Shared parameter sets

Postby Kencho » Tue Feb 17, 2009 11:48 pm

Assaf Raman wrote:Nice work, I can see many uses for this.

Me too :)
Image
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 4534
Kudos: 1
Joined: 19 Sep 2003
Location: Burgos, Spain

Re: Shared parameter sets

Postby iloseall » Wed Feb 18, 2009 2:23 am

Thanks!
I think I can provide Parameters of Wind(Dynamic) into all of Material easily Now.
User avatar
iloseall
Gremlin
 
Posts: 160
Kudos: 0
Joined: 14 Sep 2003
Location: Beijing China

Re: Shared parameter sets

Postby psquare » Wed Feb 18, 2009 10:50 am

Hey, that's really cool.

I was doing this externally, via something called 'ParamManager'. Now I can use this :-)

Many thanks!
psquare
Hobgoblin
 
Posts: 554
Kudos: 6
Joined: 14 Nov 2006

Re: Shared parameter sets

Postby sinbad » Wed Feb 18, 2009 1:31 pm

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).


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).
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby sinbad » Wed Feb 18, 2009 7:06 pm

Ok, scripting support has now been added.

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
      }
   }
}


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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby haffax » Wed Feb 18, 2009 9:11 pm

Very good. This makes consistent forward shading much easier to implement. Thanks. :)
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 5084
Kudos: 3
Joined: 18 Jun 2004
Location: Berlin, Germany

Re: Shared parameter sets

Postby iloseall » Thu Feb 19, 2009 5:15 am

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=detail&aid=2615441&group_id=2997&atid=302997
User avatar
iloseall
Gremlin
 
Posts: 160
Kudos: 0
Joined: 14 Sep 2003
Location: Beijing China

Re: Shared parameter sets

Postby sinbad » Thu Feb 19, 2009 6:49 pm

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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby iloseall » Fri Feb 20, 2009 2:33 am

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.
User avatar
iloseall
Gremlin
 
Posts: 160
Kudos: 0
Joined: 14 Sep 2003
Location: Beijing China

Re: Shared parameter sets

Postby sinbad » Fri Feb 20, 2009 10:30 pm

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.


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.

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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby lf3thn4d » Sun Feb 22, 2009 11:52 pm

Hey, this sounds like just THE thing for PSSM split points! :) I like!
User avatar
lf3thn4d
Orc
 
Posts: 478
Kudos: 12
Joined: 10 Apr 2006

Re: Shared parameter sets

Postby Caphalor » Mon Feb 23, 2009 9:26 am

Or global shadow softness. :) A really useful feature!
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
Caphalor
Greenskin
 
Posts: 116
Kudos: 25
Joined: 06 Feb 2007
Location: Berlin, Germany

Re: Shared parameter sets

Postby sinbad » Tue Feb 24, 2009 6:29 pm

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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby randall » Thu Feb 26, 2009 12:21 pm

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.


Actually, both NVIDIA and AMD supports GL_EXT_bindable_uniform. AMD has implemented this extension in new Catalyst 9.2 driver.
randall
Halfling
 
Posts: 66
Kudos: 0
Joined: 23 Jan 2005
Location: Poland

Re: Shared parameter sets

Postby cloud » Sat Apr 04, 2009 11:01 am

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.
cloud
Gremlin
 
Posts: 166
Kudos: 7
Joined: 08 Aug 2006

Re: Shared parameter sets

Postby sinbad » Sat Apr 04, 2009 5:07 pm

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.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Shared parameter sets

Postby cloud » Sun Apr 05, 2009 7:50 am

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 :oops:
cloud
Gremlin
 
Posts: 166
Kudos: 7
Joined: 08 Aug 2006

Re: Shared parameter sets

Postby sinbad » Mon Apr 06, 2009 5:31 pm

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 :oops:


Ok, this is a bug; GpuSharedParametersUsage needs re-pointing after being copied to point at the clone.
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands


Return to Developer talk

Who is online

Users browsing this forum: No registered users and 6 guests