Mich
Mich

Reputation: 3594

X3501 'main': entrypoint not found when compiling DirectX11 .hlsl shaders in VS2015

I am trying to follow this tutorial: https://learn.microsoft.com/en-us/windows/uwp/gaming/creating-shaders-and-drawing-primitives

I added two files, named SimplePixelShader.hlsl and `SimpleVertexShader.hlsl to my project with the contents below:

On each file, I went into (Right click file->Properties), Set it to proper configuration (Debug X64) and changed the fields:

General->Excluded From build = blank
General->Content = blank
General->Item Type = HLSL Compiler
HLSL Compiler->Entrypoint Name = blank (deleted main)
HLSL Compiler->Shader Type = Pixel Shader (/ps)
HLSL Compiler->Shader Model = Shader Model 4 Level 9_1 (/4_0_level_9_1)
All Options->Shader Type = Pixel Shader (/ps)
All Options->Entrypoint Name = blank (deleted main)
All Options->Shader Model = Shader Model 4 Level 9_1 (/4_0_level_9_1)

And then made the sam echanges with corresponding Vertex Shader entries for the SimpleVertexShader.hlsl

But no matter what I try, I still get the same error when compiling:

X3501 'main':entrypoint not found

How is this possible if I deleted the entrypoints from all fields? What am I missing?

Thanks,

SimpleVertexShader.hlsl:

struct VertexShaderInput
{
    DirectX::XMFLOAT2 pos : POSITION;
};

struct PixelShaderInput
{
    float4 pos : SV_POSITION;
};

PixelShaderInput SimpleVertexShader(VertexShaderInput input)
{
    PixelShaderInput vertexShaderOutput;

    // For this lesson, set the vertex depth value to 0.5, so it is guaranteed to be drawn.
    vertexShaderOutput.pos = float4(input.pos, 0.5f, 1.0f);

    return vertexShaderOutput;
}

Here is the code in SimplePixelShader.hlsl:

struct PixelShaderInput
{
    float4 pos : SV_POSITION;
};

float4 SimplePixelShader(PixelShaderInput input) : SV_TARGET
{
    // Draw the entire triangle yellow.
    return float4(1.0f, 1.0f, 0.0f, 1.0f);
}

Upvotes: 0

Views: 2234

Answers (2)

Goodies
Goodies

Reputation: 2069

I can add this for DX-12: when you use more than 1 shader file, I found consistent hurdles with the VS-2019 HLSL Compiler. This "main" error message always appears when 2 files both use "HLSL Compiler" . You can set the entry points to avoid it, but then, the program won't be able to compile your shader at runtime, for some reason.

Consider to skip things alltogether: just replace the type "HLSL Compiler" into an unassigned (default) "Custom Build tool". That will (by default) just copy your HLSL next to your exe-application. In DX-12 you'll compile the shader yourself with D3DCompileFromFile(), so there will be no issue in the end.

Upvotes: 0

Mich
Mich

Reputation: 3594

Ok I did some testing, it seems that when you leave the Entrypoint Name field blank, it tries to use main. Instead I just typed in SimpleVertexShader and SimplePixelShader accordingly, and they both compiled. Thanks

Upvotes: 2

Related Questions