Effect API changes in XNA Game Studio 4.0

Effect API changes in XNA Game Studio 4.0

  • Comments 37

Where in previous XNA versions you used to write:

    effect.Begin();
    effect.CurrentTechnique.Passes[0].Begin();

    DrawStuff();

    effect.CurrentTechnique.Passes[0].End();
    effect.End();

With Game Studio 4.0 this becomes just:

    effect.CurrentTechnique.Passes[0].Apply();

    DrawStuff();

What in previous versions would be:

    effect.Begin();
    effect.CurrentTechnique.Passes[0].Begin();

    DrawStuff();

    effect.Parameters["lives"].SetValue(9);
    effect.CommitChanges();

    DrawOtherStuff();

    effect.CurrentTechnique.Passes[0].End();
    effect.End();

Is now:

    effect.CurrentTechnique.Passes[0].Apply();

    DrawStuff();

    effect.Parameters["lives"].SetValue(9);
    effect.CurrentTechnique.Passes[0].Apply();

    DrawOtherStuff();

Editors note: if you profile the new Apply method with the 4.0 CTP, you may notice it is slower than the old CommitChanges. Don't worry: this is just a temporary state of affairs due to some missing optimizations that didn't make it in time for the CTP release.

We also took out a bunch of stuff:

  • Removed the low level shader APIs (VertexShader, PixelShader, SetVertexShaderConstant, SetPixelShaderConstant, GetVertexShaderConstant, GetPixelShaderConstant, ShaderConstantTable, ShaderProfile, ShaderRegisterSet, and ShaderSemantic). These duplicated the same functionality that is also available using Effect and EffectParameter, but in a form that was closely tied to DirectX 9, and which could not be efficiently implemented with DirectX 10 or 11. Effects provide an abstraction that sits naturally on top of multiple native layers, and the vast majority of our customers preferred the Effect API in any case.

  • Removed EffectPool. This was confusing, and turned out to be nowhere near as useful as it seemed on the surface like it ought to be.

  • Removed EffectParameterBlock. This looked like it could be a useful optimization technique, but in fact always made things slower anytime anyone tried to use it :-) 

  • Removed assorted other boring and rarely used doodads (EffectFunction, Effect.Creator, EffectParameter.SetArrayRange, and EffectTechnique.IsParameterUsed).

Finally, we upgraded to a more recent version of the Windows HLSL compiler, which means that:

  • You can use newer HLSL features such as loop control attributes.

  • Shader model 1.x is no longer supported. Game Studio 4.0 requires at least shader model 2.0.
  • Yes! Updated HLSL compiler, 4 years coming, but we got there in the end :)

  • Those are great changes but I am sad to see the Effect.Creator go i have used that in the past.

    Now what we really need is syntax highlighting and intellisense for effect files!

  • Ah great to see it's getting more and more DX10 and 11 'compatible'. DX10/11 support in xna 5.0?

  • YAY! A newer HLSL compiler! *tears of joy* :D

    Shawn, if you don't stop mentioning DX10 you're going to get nerds spreading baseless techulation on their blogs, hehe. ;)

  • Just a note on something I found yesterday.

    The new HLSL compiler doesnt like using "PixelShader" as name for the errr pixel shader routine.

  • > The new HLSL compiler doesnt like using "PixelShader" as name for the errr pixel shader routine.

    Yeah, apparently that counts as a reserved keyword now.

    You wouldn't believe how many of our unit tests this particular restriction broke! Seems like a lot of people chose that as the name for their shader function :-)

  • Will there be any new options for the effects processor and/or allow overriding the effects processor and the routines to choose compiler options?

    I find it rather painful that I have to basically re-impliment the effects processor/error handling/line numbering etc. Just so I can do things like disable specific optimizations.

    Which is very important to work around bugs in the effects compiler, admitedly most of the current bugs I run into have probably been fixed in the newer version, but still...

  • Shawn, is it still possible to compile with the old fxc and load in an effect with a byte[]?  For SM1.1 compatibility?

  • > is it still possible to compile with the old fxc and load in an effect with a byte[]?  For SM1.1 compatibility?

    This is not possible. There is no way to use 1.x shaders with XNA 4.0, and thus no way to run 4.0 games on 1.x shader hardware.

  • In fact, is a custom effects processor possible with 4.0.

    eg this could be a problem if I cant create an effect from a byte array and the effect compilation function are not present(although this could be worked around using interop). Also, not sure if it is just my system, but using the function to compile an effect from a file instead of memory has never worked.

  • > Shader model 1.x is no longer supported. Game

    > Studio 4.0 requires at least shader model 2.0.

    Yess!!!

    Will all effects live in the same pool now? Or can I no longer use "shared" variables?

  • > Will there be any new options for the effects processor and/or allow overriding the effects processor and the routines to choose compiler options?

    That's currently my next-but-six blog topic (I have a giant list of stuff I want to write about, slowly working my way through it all :-)

  • >>>That's currently my next-but-six blog topic (I have a giant list of stuff I want to write about, slowly working my way through it all :-)<<<

    Cool, I thought we must be getting to the end of the 4.0 blog topics by now:-)

    Hmmm, looking at the CTP docs, it does seem possible to disable optimizations. Which is a little blunt, just disabling all optimizations.

    However I guess it is a whole other topic if fxc optimizations are a benefit at all since the drivers are rumoured to do a bunch of optimization themselves....

  • > Cool, I thought we must be getting to the end of the 4.0 blog topics by now:-)

    No end in sight yet I'm afraid :-)

  • nice ,,

    shawn is there support for a ealy out to save the compute

    if(somthing)

    return

    and can you post more about the xbox360 special feutures of shaders

Page 1 of 3 (37 items) 123
Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post