简体   繁体   中英

Compiling DirectX11 Shader Files

I am currently following the DirectX 11 tutorial from www.rastertek.com in the 2nd series of tutorials. I'm currently using VS2015 on a Windows7 x64. Following this tutorial has me using the Windows 10 kit.

I've successfully completed the first 3 tutorials and was able to render a colored window using DirectX 11. I've just completed tutorial 4 to render a colored triangle using the HLSL with a vertex & pixel shaders. I'm following this tutorial where both the vertex and pixel shaders are in separate files the only difference in my code is the file extension that I'm using. His website uses *.vs and *.ps respectively where I'm using *.vsh and *.psh since this gives me code highlighting. All of my class files compile correctly but when I begin to build out my solution I am getting this error.

1>------ Build started: Project: DirectX 11 Engine, Configuration: Debug x64 ------
1>FXC : error X3501: 'main': entrypoint not found
1>
1>  compilation failed; no code produced
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The creator of this website does not have any contact information or community based forums. I do not know if this is an error within the website's tutorial or not. Now I know that this code has worked before using older versions of VS such as 2010, 2012 and 2013 on both Windows Vista and Windows 7 using both Windows 7 & Windows 8 kits from his first series of DirectX 10 & DirectX 11 tutorials. I wasn't able to find any help from www.msdn.com since some of their tutorials are written with the requirement of Windows 8 for DirectX 11 using VS2013. Their documentation is quite poor too.

One of the things that I have noticed that is different within DirectX 11 from the Windows Kit versus the deprecated June 2010 Direct X SDK release when Compiling a Shader file is as follows:

June 2010 Direct X SDK - Uses:

HRESULT result;

result = D3DX11CompileFromFile( "shaderFilename", NULL, NULL, "ShaderName", "*s_5_0" or "*s_5_1", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pShaderBuffer, &pErrorMessage, NULL );

Versus...

This tutorial (Windows 10 kit from VS2015) - Uses:

HRESULT result;
result = D3DCompileFromFile( "shaderFilename", NULL, NULL, "ShaderName", "*s_5_0" or "*s_5_1", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pShaderBuffer, &pErrorMessage );

Where the shader filename, shader name, feature level, and the shader buffer is either a Vertex or Pixel Shader Type. And the feature level being used in both these cases is "5_0" and not "5_1" even though I have specified both feature levels.

I'm not sure what has changed between the different compilers for DirectX's HLSL, and I don't understand where or why this error is being generated from. I do not know if the Shader Source code from the website's tutorial is missing something, or if there is some kind of property or setting in VS2015 not set right that I'm unaware of. I am open for any and all suggestions to help resolve this issue.

Visual Studio automatically compiles the shaders for you using FXC . Here, FXC reports that it cannot find the main entry point, ie the function main . This is the default, you have 2 solutions:

  • Assuming the VertexShader entry point is ColorVertexShader (it is in the tutorial you linked), change it to main
  • Change the entry point in the properties: Right click on file -> Properties -> HLSL Compiler -> General -> Entrypoint name

Because Visual Studio compiles the shaders for you, you don't have to compile them yourself via D3DCompileFromFile , consider using D3DReadFileToBlob to read the data, then passing them in CreateVertexShader from the ID3D11Device .


If you don't want to FXC to compile the shaders, you can Right click on file -> Properties -> General -> Item type - Change it to Does not participate in build

The error message is quite explicit, the compiler is not able to find the entry point, by default it is main . My guess is that your shaders use something like vsmain or psmain ...

If you look at the documentation of D3DCompileFromFile , then you will see that one parameter is the name of the entry point : https://msdn.microsoft.com/en-us/library/windows/desktop/hh446872(v=vs.85).aspx

Also, imagine that "*s_5_0" or "*s_5_1" is a pseudo code of you, or is a deprecated feature in recent C++ and here would just or two pointer and give true, and the compile function does not recognize wildcards.

After I have submitted this question; I happened to stumble onto this question FXC : error X3501: 'main': entrypoint not found and from some of the comments and answers there. I simply ended up right clicking on the "color.psh" and "color.vsh" files and under their properties:

  • Configuration Properties -> General -> Excluded From Build section I set the flag to "Yes"
    • HLSL Compiler -> General -> Shader Type section I set the Shader Type respectively for Pixel & Vertex Shader For Each File.
    • HLSL Compiler -> General -> Shader Model section I set to Shader Model 5.0(/5_0) for both files.

Now every thing builds successfully and I am rendering a Green Triangle on a Black Windowed Background as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM