HRESULT RosCompiler::Compile()
{
    HRESULT hr = E_NOTIMPL;

    assert(m_pCode);
    assert(m_ProgramType == (D3D10_SB_TOKENIZED_PROGRAM_TYPE)((m_pCode[0] & D3D10_SB_TOKENIZED_PROGRAM_TYPE_MASK) >> D3D10_SB_TOKENIZED_PROGRAM_TYPE_SHIFT));
    
#if DBG
    // Disassemble HLSL
    Disassemble_Signatures();
    Disassemble_HLSL();
#endif // DBG

#if VC4
    Vc4Shader Vc4ShaderCompiler(this);

    // Set HLSL bytecode.
    Vc4ShaderCompiler.SetShaderCode(m_pCode);

    switch (m_ProgramType)
    {
    case D3D10_SB_VERTEX_SHADER:
        // Set output hw shader storage.
        // for vertex shader.
        Vc4ShaderCompiler.SetShaderStorage(
            &m_Storage[ROS_VERTEX_SHADER_STORAGE],
            &m_Storage[ROS_VERTEX_SHADER_UNIFORM_STORAGE]);
        // for coordinate shader
        Vc4ShaderCompiler.SetShaderStorageAux(
            &m_Storage[ROS_COORDINATE_SHADER_STORAGE],
            &m_Storage[ROS_COORDINATE_SHADER_UNIFORM_STORAGE]);

        // Compile shader
        hr = Vc4ShaderCompiler.Translate_VS();

#if DBG
        // Disassemble h/w shader.
        Disassemble_HW(m_Storage[ROS_VERTEX_SHADER_STORAGE], TEXT("VC4 Vertex shader"));
        Disassemble_HW(m_Storage[ROS_COORDINATE_SHADER_STORAGE], TEXT("VC4 Coordinate shader"));
#endif   
        break;

    case D3D10_SB_PIXEL_SHADER:
        // Set output hw shader storage.
        Vc4ShaderCompiler.SetShaderStorage(
            &m_Storage[ROS_PIXEL_SHADER_STORAGE],
            &m_Storage[ROS_PIXEL_SHADER_UNIFORM_STORAGE]);;

        // Compile shader
        hr = Vc4ShaderCompiler.Translate_PS();

#if DBG
        // Disassemble h/w shader.
        Disassemble_HW(m_Storage[ROS_PIXEL_SHADER_STORAGE], TEXT("VC4 Pixel shader"));
#endif 
        break;

    default:
        assert(false);
    }
#else
    assert(false);
#endif // VC4

    return hr;
}
HRESULT RosCompiler::Compile()
{
    HRESULT hr = E_NOTIMPL;

    assert(m_pCode);
    assert(m_ProgramType == (D3D10_SB_TOKENIZED_PROGRAM_TYPE)((m_pCode[0] & D3D10_SB_TOKENIZED_PROGRAM_TYPE_MASK) >> D3D10_SB_TOKENIZED_PROGRAM_TYPE_SHIFT));
    
#if DBG
    // Disassemble HLSL
    Disassemble_Signatures();
    Disassemble_HLSL();
#endif // DBG

#if VC4
    Vc4Shader Vc4ShaderCompiler(this);

    // Set HLSL bytecode.
    Vc4ShaderCompiler.SetShaderCode(m_pCode);
    if (m_pDownstreamCode)
    {
        Vc4ShaderCompiler.SetDownstreamShaderCode(m_pDownstreamCode);
    }
    if (m_pUpstreamCode)
    {
        Vc4ShaderCompiler.SetUpstreamShaderCode(m_pUpstreamCode);
    }

    switch (m_ProgramType)
    {
    case D3D10_SB_VERTEX_SHADER:
        // Set output hw shader storage.
        // for vertex shader.
        Vc4ShaderCompiler.SetShaderStorage(
            &m_Storage[ROS_VERTEX_SHADER_STORAGE],
            &m_Storage[ROS_VERTEX_SHADER_UNIFORM_STORAGE]);
        // for coordinate shader
        Vc4ShaderCompiler.SetShaderStorageAux(
            &m_Storage[ROS_COORDINATE_SHADER_STORAGE],
            &m_Storage[ROS_COORDINATE_SHADER_UNIFORM_STORAGE]);

        try
        {
            // Compile shader
            hr = Vc4ShaderCompiler.Translate_VS();
        }
        catch (RosCompilerException & e)
        {
            hr = e.GetError();
        }

        if (SUCCEEDED(hr))
        {
            m_cShaderInput = Vc4ShaderCompiler.GetInputCount();
            m_cShaderOutput = Vc4ShaderCompiler.GetOutputCount();

#if DBG
            // Disassemble h/w shader.
            Disassemble_HW(m_Storage[ROS_VERTEX_SHADER_STORAGE], TEXT("VC4 Vertex shader"));
            Dump_UniformTable(m_Storage[ROS_VERTEX_SHADER_UNIFORM_STORAGE], TEXT("VC4 Vertex shader Uniform"));

            Disassemble_HW(m_Storage[ROS_COORDINATE_SHADER_STORAGE], TEXT("VC4 Coordinate shader"));
            Dump_UniformTable(m_Storage[ROS_COORDINATE_SHADER_UNIFORM_STORAGE], TEXT("VC4 Coordinate shader Uniform"));
#endif // DBG
        }

        break;

    case D3D10_SB_PIXEL_SHADER:
        // Set output hw shader storage.
        Vc4ShaderCompiler.SetShaderStorage(
            &m_Storage[ROS_PIXEL_SHADER_STORAGE],
            &m_Storage[ROS_PIXEL_SHADER_UNIFORM_STORAGE]);;

        try
        {
            // Compile shader
            hr = Vc4ShaderCompiler.Translate_PS();
        }
        catch (RosCompilerException & e)
        {
            hr = e.GetError();
        }

        if (SUCCEEDED(hr))
        {
            m_cShaderInput = Vc4ShaderCompiler.GetInputCount();
            m_cShaderOutput = Vc4ShaderCompiler.GetOutputCount();

#if DBG
            // Disassemble h/w shader.
            Disassemble_HW(m_Storage[ROS_PIXEL_SHADER_STORAGE], TEXT("VC4 Pixel shader"));
            Dump_UniformTable(m_Storage[ROS_PIXEL_SHADER_UNIFORM_STORAGE], TEXT("VC4 Vertex shader Uniform"));
#endif // DBG

        }

        break;

    default:
        assert(false);
    }
#else
    assert(false);
#endif // VC4

    return hr;
}