locked
FXC : error X3501: 'main': entrypoint not found

    Question

  • simple sample fx file as bellow, but when i add it to project in vs11, it report the error:1>FXC : error X3501: 'main': entrypoint not found,
    how can i config the property of the project? thanks
    //--------------------------------------------------------------------------------------
    // defines
    //--------------------------------------------------------------------------------------
    #define MAX_BONE_MATRICES 255
    //--------------------------------------------------------------------------------------
    // Input/Output structures
    //--------------------------------------------------------------------------------------
    struct VSSkinnedIn
    {
        float3 Pos : POSITION; //Position
        float4 Weights : WEIGHTS; //Bone weights
        uint4  Bones : BONES; //Bone indices
        float3 Norm : NORMAL; //Normal
        float2 Tex : TEXCOORD;    //Texture coordinate
        float3 Tan : TANGENT;    //Normalized Tangent vector
    };
    struct PSSkinnedIn
    {
        float4 Pos : SV_Position; //Position
        float3 vPos : POSWORLD; //world space Pos
        float3 Norm : NORMAL; //Normal
        float2 Tex : TEXCOORD;    //Texture coordinate
        float3 Tangent : TANGENT; //Normalized Tangent vector
    };
    //--------------------------------------------------------------------------------------
    // Constant buffers
    //--------------------------------------------------------------------------------------
    cbuffer cb0
    {
        float4x4 g_mWorldViewProj;
        float4x4 g_mWorld;
    };
    cbuffer cbUserChange
    {
        float3 g_vLightPos;
        float3 g_vEyePt;
    };
    cbuffer cbImmutable
    {
        float4 g_directional = float4(1.0,1.0,1.0,1.0);
        float4 g_ambient = float4(0.1,0.1,0.1,0.0);
        float4 g_objectspeccolor = float4(1.0,1.0,1.0,1.0);
    };
    // Constant buffer for bone matrices
    cbuffer cbAnimMatrices
    {
        matrix g_mConstBoneWorld[MAX_BONE_MATRICES];
    };
    // TBuffer for bone matrices
    tbuffer tbAnimMatrices
    {
        matrix g_mTexBoneWorld[MAX_BONE_MATRICES];
    };
    //--------------------------------------------------------------------------------------
    // Textures
    //--------------------------------------------------------------------------------------
    Texture2D g_txDiffuse;
    Texture2D g_txNormal;
    // Texture for bone matrices
    Texture1D g_txTexBoneWorld;
    //--------------------------------------------------------------------------------------
    // Buffers (this is the buffer object for bone matrices)
    //--------------------------------------------------------------------------------------
    Buffer<float4> g_BufferBoneWorld;
    //--------------------------------------------------------------------------------------
    // Texture samplers
    //--------------------------------------------------------------------------------------
    SamplerState g_samLinear
    {
        Filter = ANISOTROPIC;
        AddressU = Clamp;
        AddressV = Clamp;
    };
    SamplerState g_samPoint
    {
        Filter = MIN_MAG_MIP_POINT;
        AddressU = Clamp;
        AddressV = Clamp;
    };
    //--------------------------------------------------------------------------------------
    // State
    //--------------------------------------------------------------------------------------
    DepthStencilState DisableDepth
    {
        DepthEnable = FALSE;
        DepthWriteMask = 0;
    };
    DepthStencilState EnableDepth
    {
        DepthEnable = TRUE;
        DepthWriteMask = ALL;
    };
    //--------------------------------------------------------------------------------------
    // Helper struct for passing back skinned vertex information
    //--------------------------------------------------------------------------------------
    struct SkinnedInfo
    {
        float4 Pos;
        float3 Norm;
        float3 Tan;
    };
    //--------------------------------------------------------------------------------------
    // FetchBoneTransform fetches a bone transformation using one of several methods
    //
    // FT_CONSTANTBUFFER:
    // With this approach, the bone matrices are stored in a constant buffer.
    // The shader will index into the constant buffer to grab the correct
    // transformation matrices for each vertex.
    // FT_TEXTUREBUFFER:
    // This approach shows the differences between constant buffers and tbuffers.
    // tbuffers are special constant buffers that are accessed like textures.
    // They should give better random access performance.
    // FT_TEXTURE:
    // When FT_TEXTURE is specified, the matrices are loaded into a 1D texture.
    // This is different from a tbuffer in that an actual texture fetch is used
    // instead of a lookup into a constant buffer.
    // FT_BUFFER:
    // This loads the matrices into a buffer that is bound to the shader.  The
    // shader calls Load on the buffer object to load the different matrices from
    // the stream.  This should give better linear access performance.
    //--------------------------------------------------------------------------------------
    matrix FetchBoneTransform( uint iBone)
    {
        matrix mret = g_mConstBoneWorld[ iBone ];
        return mret;
    }
    //--------------------------------------------------------------------------------------
    // SkinVert skins a single vertex
    //--------------------------------------------------------------------------------------
    SkinnedInfo SkinVert( VSSkinnedIn Input)
    {
        SkinnedInfo Output = (SkinnedInfo)0;
        
        float4 Pos = float4(Input.Pos,1);
        float3 Norm = Input.Norm;
        float3 Tan = Input.Tan;
        
        //Bone0
        uint iBone = Input.Bones.x;
        float fWeight = Input.Weights.x;
        matrix m = FetchBoneTransform( iBone);
        Output.Pos += fWeight * mul( Pos, m );
        Output.Norm += fWeight * mul( Norm, (float3x3)m );
        Output.Tan += fWeight * mul( Tan, (float3x3)m );
        
        //Bone1
        iBone = Input.Bones.y;
        fWeight = Input.Weights.y;
        m = FetchBoneTransform( iBone);
        Output.Pos += fWeight * mul( Pos, m );
        Output.Norm += fWeight * mul( Norm, (float3x3)m );
        Output.Tan += fWeight * mul( Tan, (float3x3)m );
        
        //Bone2
        iBone = Input.Bones.z;
        fWeight = Input.Weights.z;
        m = FetchBoneTransform( iBone);
        Output.Pos += fWeight * mul( Pos, m );
        Output.Norm += fWeight * mul( Norm, (float3x3)m );
        Output.Tan += fWeight * mul( Tan, (float3x3)m );
        
        //Bone3
        iBone = Input.Bones.w;
        fWeight = Input.Weights.w;
        m = FetchBoneTransform( iBone);
        Output.Pos += fWeight * mul( Pos, m );
        Output.Norm += fWeight * mul( Norm, (float3x3)m );
        Output.Tan += fWeight * mul( Tan, (float3x3)m );
        
        return Output;
    }
    //--------------------------------------------------------------------------------------
    // Vertex shader used for skinning the mesh for immediate render  VSSkinnedmain
    //--------------------------------------------------------------------------------------
    PSSkinnedIn VSSkinnedmain(VSSkinnedIn input)
    {
        PSSkinnedIn output;
        
        SkinnedInfo vSkinned = SkinVert( input );
        output.Pos = mul( vSkinned.Pos, g_mWorldViewProj );
        output.vPos = mul( vSkinned.Pos, g_mWorld );
        output.Norm = normalize( mul( vSkinned.Norm, (float3x3)g_mWorld ) );
        output.Tangent = normalize( mul( vSkinned.Tan, (float3x3)g_mWorld ) );
        output.Tex = input.Tex;
        
        return output;
    }
    //--------------------------------------------------------------------------------------
    // Pixel shader that performs bump mapping on the final vertex PSSkinnedmain
    //--------------------------------------------------------------------------------------
    float4 PSSkinnedmain(PSSkinnedIn input) : SV_Target
    {
        float4 diffuse = g_txDiffuse.Sample( g_samLinear, input.Tex );
        float3 Norm = g_txNormal.Sample( g_samLinear, input.Tex );
        Norm *= 2.0;
        Norm -= float3(1,1,1);
        
        // Create TBN matrix
        float3 lightDir = normalize( g_vLightPos - input.vPos );
        float3 viewDir = normalize( g_vEyePt - input.vPos );
        float3 BiNorm = normalize( cross( input.Norm, input.Tangent ) );
        float3x3 BTNMatrix = float3x3( BiNorm, input.Tangent, input.Norm );
        Norm = normalize( mul( Norm, BTNMatrix ) ); //world space bump
        
        //diffuse lighting
        float lightAmt = saturate( dot( lightDir, Norm ) );
        float4 lightColor = lightAmt.xxxx*g_directional + g_ambient;
        // Calculate specular power
        float3 halfAngle = normalize( viewDir + lightDir );
        float4 spec = pow( saturate(dot( halfAngle, Norm )), 64 );
            
        // Return combined lighting
        return lightColor*diffuse + spec*g_objectspeccolor*diffuse.a;
    }
    //--------------------------------------------------------------------------------------
    // Render the scene by fetching bone matrices from a constant buffer
    //--------------------------------------------------------------------------------------
    technique11 RenderConstantBuffer
    {
        pass P0
        {       
            SetVertexShader( CompileShader( vs_5_0, VSSkinnedmain( ) ) );
            SetGeometryShader( NULL );
            SetPixelShader( CompileShader( ps_5_0, PSSkinnedmain() ) );
            
            SetDepthStencilState( EnableDepth, 0 );
        }
    }
    Friday, January 13, 2012 8:53 AM

Answers

  • FXC is the command-line HLSL compiler, so it needs to know at a minimum the 'shader profile' and 'entry-point'.

    The following compiles the Vertex Shader using Shader Model 5.0

    fxc simple.fx /Tvs_5_0 /EVSSkinnedmain

    The following compiles the Pixel Shader using Shader Model 5.0 

    fxc simple.fx /Tps_5_0 /EPSSkinnedmain

    Note that if this is a Desktop application that uses the Effects 11 library, you can also use

     

    fxc simple.fx /Tfx_5_0

    If this is for a Metro style app, however, you can't use Effects 11 since it relies on runtime use of D3DCompile_*.DLL reflection APIs which are not supported for Metro style app deployment.

     

    One of the nice new features in VS 11 is that the IDE actually understands .hlsl and .fx extension files and the HLSL complier. Add the file to your VS 11 project, right-click on the properties, and then you can set details. In this case, go to "HLSL Compiler" / "Entrypoint Name" and then type the desired entry-point and set the "Shader Model".

    The IDE is really designed for a single shader file generating a single shader, and the IDE doesn't support the deprecated "FX" profiles. As such, you are probably better off copying "simple.fx" to two new files "simpleVS.hlsl" and "simplePS.hlsl".

    The default VS 11 IDE settings will generate a ".cso" shader binary blob you can load in your application using standard file I/O, but you can also generate a C++ header instead (see "Output Files") that you can include directly into your source code.

     



    Friday, January 13, 2012 7:52 PM

All replies

  • FXC is the command-line HLSL compiler, so it needs to know at a minimum the 'shader profile' and 'entry-point'.

    The following compiles the Vertex Shader using Shader Model 5.0

    fxc simple.fx /Tvs_5_0 /EVSSkinnedmain

    The following compiles the Pixel Shader using Shader Model 5.0 

    fxc simple.fx /Tps_5_0 /EPSSkinnedmain

    Note that if this is a Desktop application that uses the Effects 11 library, you can also use

     

    fxc simple.fx /Tfx_5_0

    If this is for a Metro style app, however, you can't use Effects 11 since it relies on runtime use of D3DCompile_*.DLL reflection APIs which are not supported for Metro style app deployment.

     

    One of the nice new features in VS 11 is that the IDE actually understands .hlsl and .fx extension files and the HLSL complier. Add the file to your VS 11 project, right-click on the properties, and then you can set details. In this case, go to "HLSL Compiler" / "Entrypoint Name" and then type the desired entry-point and set the "Shader Model".

    The IDE is really designed for a single shader file generating a single shader, and the IDE doesn't support the deprecated "FX" profiles. As such, you are probably better off copying "simple.fx" to two new files "simpleVS.hlsl" and "simplePS.hlsl".

    The default VS 11 IDE settings will generate a ".cso" shader binary blob you can load in your application using standard file I/O, but you can also generate a C++ header instead (see "Output Files") that you can include directly into your source code.

     



    Friday, January 13, 2012 7:52 PM
  • In addition to what Chuck Walbourn says you can set the shader type to "Effect (/fx)". By doing this you can then set the entry point to your Technique name - which in your case is "RenderConstantBuffer". That way you don't need to split your file into 2 :)
    • Proposed as answer by The Orm Tuesday, September 18, 2012 8:12 AM
    Tuesday, September 18, 2012 8:10 AM
  • Try this, http://www.zettabyte.ws/viewtopic.php?f=41&t=1015. See Shader Type in settings.
    Tuesday, September 18, 2012 8:01 PM