XNa 4.0 Beta: effectpass not a simple wrapper!

Source: Internet
Author: User

So, the Beta is out!

XNa 4.0 has been significantly updated, most of the changes are good, but there have been two points that make me very uncomfortable: 1. the render target must be bound to a depth buffer; 2. there are no underlying functions such as setxxshader and setshaderconstant. The former is very unfriendly to deffered shading, and the latter makes the entire material system I wrote unusable. In contrast, the latter makes me more worried, because the effect and effectpass In the CTP are just a simple wrapper on the DX effect system. As we all know, the effect performance in DirectX has been criticized. Fortunately, Shawn told me:

"The Windows Firewall tpass. apply implementation in the CTP is not complete, and has optimizations not yet implemented. the CTP implementation is functionally correct, but not from a performance standpoint, So you shoshould not worry too much about Windows performance in the CTP."

 

It seems that the beta version has solved this problem. In analyticdb 4.0, javastpass is no longer a simple wrapper on DX effect. xNa team has made great efforts to reduce the status change, so that the PIX analyzes the xNa 4.0ProgramErrors may occur. Shawn says in the blog:

"The problem occurs because pix does not support some crazy tricks that gs4 uses to Optimize State management ".

 

Below is the same paragraphCodeComparison in the CTP and beta versions:

// Test code //
..... Set Parameter For First Object
Required tpass. Apply ();
Graphicsdevice. drawindexedprimitives (primitivetype. trianglelist, 0 , 0 , Vertices. Count, 0 , Primitivecount );
// Only change world matrix and draw the same object again
Effect. World = Matrix. createtranslation ( 1 , 0 , 0 );
Required tpass. Apply ();
Graphicsdevice. drawindexedprimitives (primitivetype. trianglelist, 0 , 0 , Vertices. Count, 0 , Primitivecount );

// PIX data for CTP:
Id3dxeffect: beginpass ( 0 )
Id3dxeffect: endpass ()
Id3dxeffect: end ()
Idirect3ddevice9: beginscene ()
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 ) // Draw the 1 primitive
Id3dxeffect: setmatrix ( 0xff6b4d6b , 0x0039e6f0 )
Id3dxeffect: setmatrix ( 0xff6b4e13 , 0x0039e684 )
Id3dxeffect: setmatrix ( 0xff6b4dbf , 0x0039e684 )
Id3dxeffect: Begin ( 0x0039e7ec , Zero X 00000001 )
Id3dxeffect: beginpass ( 0 )
Idirect3ddevice9: setvertexshader ( Zero X 06487820 ) // Redundance !!!!!!
Idirect3ddevice9: setvertexshaderconstantf ( 0 , 0x015851c8 , 1 ) // Redundance !!!!!!!!
Idirect3ddevice9: setvertexshaderconstantf ( 14 , 0x015852a8 , 1 ) // Redundance !!!!!!
Idirect3ddevice9: setvertexshaderconstantf ( 15 , 0x015852b8 , 4 )
Idirect3ddevice9: setvertexshaderconstantf ( 19 , 0x015852f8 , 3 )
Idirect3ddevice9: setvertexshaderconstantf ( 23 , Zero X 01585338 , 3 )
Idirect3ddevice9: setpixelshader ( 0x06486ae8 ) 3914655838 // Redundance !!!!!
Idirect3ddevice9: setpixelshaderconstantf ( 0 , 0x01586d40 , 15 ) // Redundance !!!!!!
Id3dxeffect: endpass ()
Id3dxeffect: end ()
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 ) // Draw the 2 primitive

// PIX data for Beta With d3dx function call
Id3dxeffect: beginpass ( 0 )
Idirect3ddevice9: beginscene ()
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 )
Id3dxeffect: setmatrix ( 0xff84502b , 0x0023e444 )
Id3dxeffect: setmatrix ( 0xff8450d3 , 0x0023e3d8 )
Id3dxeffect: setmatrix ( 0xff84507f , 0x0023e3d8 )
Id3dxeffect: commitchanges ()
Idirect3ddevice9: setvertexshaderconstantf ( 15 , 0x00fb5668 , 4 )
Idirect3ddevice9: setvertexshaderconstantf ( 19 , 0x00fb56a8 , 3 )
Idirect3ddevice9: setvertexshaderconstantf ( 23 , 0x00fb56e8 , 3 )
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 )

// PIX data for Beta without d3dx function:
Idirect3ddevice9: beginscene ()
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 )
Idirect3ddevice9: setvertexshaderconstantf ( 15 , 0x007d5660 , 4 )
Idirect3ddevice9: setvertexshaderconstantf ( 19 , 0x007d56a0 , 3 )
Idirect3ddevice9: setvertexshaderconstantf ( 23 , 0x007d56e0 , 3 )
Idirect3ddevice9: drawindexedprimitive (d3dpt_trianglelist, 0 , 0 , 24 , 0 , 12 )

 

 

We can see that in Beta, the redundant state settings are completely filtered out, andEffect. World updates World marix, worldviewprojmatrix, and worldinversetranspose. Therefore, it is correct to update three parameters before rendering the second object. Only two graphs are rendered in the test program. Therefore, beginscene appears correctly before the first DP.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.