如何设置着色器文件的入口点(错误X3501)?

4
我对DirectX不熟悉,在Visual Studio中运行[此教程][1]时遇到编译错误:"error X3501: 'main': entrypoint not found."。通过搜索,我找到了[这个答案][2],其中建议在我的着色器文件属性中设置着色器类型和入口点。尽管提供的解决方案非常好,但是我不知道我的入口点应该是什么。起初,我以为它应该是我实际调用的D3DX11CompileFromFile()函数,即在ColorShaderClass::InitializeShader中,然而我又遇到了X3501错误。请问该怎么办?
我的文件如下:
ColorVS.hlsl
ColorPS.hlsl

使用名称的方法
bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
{
    bool result;


    // Initialize the vertex and pixel shaders.
    result = InitializeShader(device, hwnd, L"ColorVS.hlsl", L"ColorPS.hlsl");
    if (!result)
    {
        return false;
    }

    return true;
}

并且

bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{
    HRESULT result;
    ID3D10Blob* errorMessage;
    ID3D10Blob* vertexShaderBuffer;
    ID3D10Blob* pixelShaderBuffer;
    D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
    unsigned int numElements;
    D3D11_BUFFER_DESC matrixBufferDesc;

// Initialize the pointers this function will use to null.
errorMessage = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;

    // Compile the vertex shader code.
    result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
    &vertexShaderBuffer, &errorMessage, NULL);
if (FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if (errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
    }
    // If there was nothing in the error message then it simply could not find the shader file itself.
    else
    {
        MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}

// Compile the pixel shader code.
result = D3DX11CompileFromFile(psFilename, NULL, NULL, "ColorPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
    &pixelShaderBuffer, &errorMessage, NULL);
if (FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if (errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
    }
    // If there was  nothing in the error message then it simply could not find the file itself.
    else
    {
        MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}
//more code
}

编辑

正如tsandy所回答的那样,入口点是实际执行着色的函数。对于那些遵循本教程并使用与我相同方案的人来说:

ColorPS.hlsl 的入口点为 "ColorPixelShader"

ColorVS.hlsl 的入口点为 "ColorVertexShader"

1个回答

3

每个hlsl文件的入口点应该是执行着色的hlsl文件中函数的名称。例如,在以下像素着色器hlsl文件中:

struct PixelInputType
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

float4 ColorPixelShader(PixelInputType input) : SV_TARGET
{
    return input.color;
}

您需要使用ColorPixelShader作为入口点。

1
非常好!谢谢!有关详细信息,请查看我问题中的编辑。 - OKUZA
如果你同时拥有顶点着色器和像素着色器,会怎样呢? - Vinz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接