【XBOX360 Porting Tricks】二

Posted on 2008-10-25 13:33  活着就是幸福  阅读(671)  评论(0)    收藏  举报
1. Xbox 360 does not support the creation of lockable render-targets. Using the IDirect3DDevice9::Resolve method, render-targets can be copied to a texture that, in turn, can be

locked.
When using EDRAM, be sure that your game does not use multiple surfaces simultaneously that conflict by pointing to the same EDRAM memory

2. D3DFVF_XYZRHW 修改
    (1) 添加顶点声明( 无需SetFVF函数,推荐 ) 或 使用SetFVF( D3DFVF_XYZW | ... ) ( 无需顶点声明,性能警告,因为SetFVF内部转换成顶点声明,但是由于no cache, 所以每次重新生成 )
    (2) 添加vs shader,位置使用Out.ProjPos = In.ObjPos;之类的简单赋值( 位置赋值强制存在,xbox shader要求严格 )
    (3) 设置SetRenderState( D3DRS_VIEWPORTENABLE, FALSE );
    -------------------------------------------------------
    (1) 添加顶点声明( 无需SetFVF函数,推荐 ) 或 使用SetFVF( D3DFVF_XYZW | ... ) ( 无需顶点声明,性能警告,因为SetFVF内部转换成顶点声明,但是由于no cache, 所以每次重新生成 )
    (2) 添加vs shader,位置使用Out.ProjPos = ScreenTransform( In.ObjPos ); ( 位置赋值强制存在,xbox shader要求严格 )
        其中
        static float SCREEN_WIDTH = 1280.0;//
        static float SCREEN_HEIGHT = 720.0;//屏幕宽高(注意static)
        float4 ScreenTransform( float4 pos )
        {
            float4 Out;
            Out.x = (pos.x / (SCREEN_WIDTH/2.0)) -1;
            Out.y = -(pos.y / (SCREEN_HEIGHT/2.0)) +1;
            Out.z = pos.z;
            Out.w = 1;
            return Out;
        }
    (3) 无需设置SetRenderState( D3DRS_VIEWPORTENABLE, FALSE ) (2)已经手动变换

3. Xbox360上不能使用D3DXSaveSurfaceToFile() 。因为所有的rendertarget都在EDRAM里,必须生成一张tex, resolve这个rendertarget到tex上,用D3DXSaveTextureToFile()保存到文件。

4. Xbox360上可以使用    PIXBeginNamedEvent( 0xffff0000, "CreateDepthTexture" );
            PIXEndNamedEvent();把要做的事包起来在pix里调试。
   PC上则使用D3DPERF_BeginEvent()和D3DPERF_EndEvent(); 注意,D3DPERF_BeginEvent只有unicode版本。

可以这样做
#ifdef _WIN32
    #define ML_BeginEvent( color, str )        D3DPERF_BeginEvent( color, L##str )
    #define ML_EndEvent()                    D3DPERF_EndEvent()
#else
    #define ML_BeginEvent( color, str )        PIXBeginNamedEvent( color, str )
    #define ML_EndEvent()                    PIXEndNamedEvent()
#endif
///////////////////////////////////////////////////////
// 补充: 摘自XDK
///////////////////////////////////////////////////////
class PIXNamedEventHelperClass
{
public:
    PIXNamedEventHelperClass( const CHAR* strTitle, DWORD dwColor = 0xFFFFFFFF )
    {
        ML_BeginEvent( dwColor, strTitle );
    }
    ~PIXNamedEventHelperClass()
    {
        ML_EndEvent();
    }
};
#define PIXNamedEvent(Title) PIXNamedEventHelperClass PIXNamedEvent##__LINE__(Title)

5. xbox上在磁盘根目录上放置一个空文件[DumpShaderPDBs]即可自动产生UPDB文件。如果用 D3DXCreateEffectFromFile()可直接产生,而三段式的ReadTextData[头拼 接]+D3DXCreateCompiler+CompileEffect+D3DXCreateEffect()则只有进行到最后一步才会产生UPDB 文件。FXLCompileEffectEx 似乎可以正确的产生UPDB,但是产生的Effect不能被D3DXCreateEffect使用。