zoukankan      html  css  js  c++  java
  • XNA 4.0 beta: EffectPass not a simple wrapper!

      So, the beta is out!

          XNA 4.0进行了大幅更新,大部分改动都不错,不过一直有2点让我非常不爽:1. render target必须和某个depth buffer绑定到一起;2. 没有了SetxxShader和SetShaderConstant等底层函数。前者对deffered shading非常不友好,后者让我写的整个材质系统都不能用了。相比之下,后者更让我担心,因为CTP中的Effect和EffectPass仅仅是DX Effect系统之上的一个简单wrapper众所周知,DirectX中Effect的性能一直是被人诟病的地方。好在Shawn告诉我:

    “The Windows EffectPass.Apply implementation in the CTP is not complete, and many optimizations not yet implemented. The CTP implementation is functionally correct, but not from a performance standpoint, so you should not worry too much about Windows performance in the CTP.”

         似乎Beta版已经解决了这个问题,4.0中的EffectPass不再是DX Effect上的一个简单wrapper,xna team做了很大的努力减少状态改变,以至于PIX分析xna 4.0的程序时有可能出错,Shawn在blog中说:

    "The problem occurs because PIX does not support some crazy tricks that GS4 uses to optimize state management" 。

          下面是同一段代码在CTP和beta版下的对比:

    //test code//
    .....set parameter for first object
    effectPass.Apply();
    graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 
    00,vertices.Count, 0, primitiveCount);
    //only change world matrix and draw the same object again
    effect.World = Matrix.CreateTranslation(100);
    effectPass.Apply();
    graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 
    00,vertices.Count, 0, primitiveCount);



    //Pix data for ctp:
    ID3DXEffect::BeginPass(0)                          
    ID3DXEffect::EndPass()                         
    ID3DXEffect::End()                         
    IDirect3DDevice9::BeginScene()                         
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)//draw the 1 primitive                  
    ID3DXEffect::SetMatrix(0xFF6B4D6B0x0039E6F0)                     
    ID3DXEffect::SetMatrix(
    0xFF6B4E130x0039E684)                     
    ID3DXEffect::SetMatrix(
    0xFF6B4DBF0x0039E684)                     
    ID3DXEffect::Begin(
    0x0039E7EC0x00000001)                 
    ID3DXEffect::BeginPass(
    0)                          
     IDirect3DDevice9::SetVertexShader(
    0x06487820)                     //redundance!!!!!!
     IDirect3DDevice9::SetVertexShaderConstantF(00x015851C81)      //redundance!!!!!!!!      
     IDirect3DDevice9::SetVertexShaderConstantF(140x015852A81)     //redundance !!!!!!    
     IDirect3DDevice9::SetVertexShaderConstantF(150x015852B84)             
     IDirect3DDevice9::SetVertexShaderConstantF(
    190x015852F83)             
     IDirect3DDevice9::SetVertexShaderConstantF(
    230x015853383)             
     IDirect3DDevice9::SetPixelShader(
    0x06486AE8)   3914655838         //redundance!!!!!
     IDirect3DDevice9::SetPixelShaderConstantF(00x01586D4015)      //redundance!!!!!!    
    ID3DXEffect::EndPass()                         
    ID3DXEffect::End()                     
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)// draw the 2 primitive      


    //Pix data for beta with d3dx function call
    ID3DXEffect::BeginPass(0)                
    IDirect3DDevice9::BeginScene()
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)        
    ID3DXEffect::SetMatrix(
    0xFF84502B0x0023E444)                    
    ID3DXEffect::SetMatrix(
    0xFF8450D30x0023E3D8)                    
    ID3DXEffect::SetMatrix(
    0xFF84507F0x0023E3D8)                    
    ID3DXEffect::CommitChanges()                    
      IDirect3DDevice9::SetVertexShaderConstantF(
    150x00FB56684)
      IDirect3DDevice9::SetVertexShaderConstantF(
    190x00FB56A83)
      IDirect3DDevice9::SetVertexShaderConstantF(
    230x00FB56E83)
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)

    //Pix data for beta without d3dx function:
    IDirect3DDevice9::BeginScene()                
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)
    IDirect3DDevice9::SetVertexShaderConstantF(
    150x007D56604)
    IDirect3DDevice9::SetVertexShaderConstantF(
    190x007D56A03)
    IDirect3DDevice9::SetVertexShaderConstantF(
    230x007D56E03)
    IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
    0024012)                    

         可以看到beta版中,完全过滤了冗余的状态设置,测试代码中的effect.World会更新world marix,worldViewProjMatrix以及WorldInverseTranspose,因此渲染第二个对象前出现3个参数更新是正确的。测试程序里只渲染了2个图形,因此,BeginScene在第一次DP之前出现也是正确的。

     

       

  • 相关阅读:
    Oracle 创建索引分区
    Shiro SessionManager会话管理器设计概念
    管理表分区
    Oracle 表分区策略
    Oracle 表分区
    参考Shiro的Session定期验证会话失效的线程池
    HDU 3555 Bomb (数位dp)
    POJ 3666 Making the Grade (动态规划)
    Gym
    POJ
  • 原文地址:https://www.cnblogs.com/clayman/p/1776611.html
Copyright © 2011-2022 走看看