【问题标题】:error C3861: 'D3DCompileFromFile': identifier not found错误 C3861:“D3DCompileFromFile”:找不到标识符
【发布时间】:2014-11-04 17:09:04
【问题描述】:

我正在尝试使用 D3D 函数 D3DCompilFromFile,它工作得非常好,直到我稍微调整了我的着色器,现在我的程序突然停止识别 D3DCompileFromFile 函数,我检查了哪些头/库/dll我需要包括在内,据我所知,它们都在那里。

我正在使用 VS2013

这是一些示例代码

应用程序.cpp

HRESULT Application::CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut)
{
    HRESULT hr = S_OK;

    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
    // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

    ID3DBlob* pErrorBlob;
    hr = D3DCompileFromFile(szFileName, nullptr, nullptr, szEntryPoint, szShaderModel,
        dwShaderFlags, 0, ppBlobOut, &pErrorBlob);

    if (FAILED(hr))
    {
        if (pErrorBlob != nullptr)
            OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());

        if (pErrorBlob) pErrorBlob->Release();

        return hr;
    }

    if (pErrorBlob) pErrorBlob->Release();

    return S_OK;
}

应用程序.h

#include <windows.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <directxmath.h>
#include <directxcolors.h>
#include "resource.h"
#include <iostream>
#include <vector>
#include <time.h>
#include <stdio.h>
#include <stdlib.h> 

using namespace DirectX;
using namespace std;
.
.
.
.
HRESULT CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut);

Lighting.fx

cbuffer cbData
{
    float4x4 World; 
    float4x4 View; 
    float4x4 Projection;

    float4 gDiffuseMtrl; 
    float4 gDiffuseLight; 
    float3 gLightVecW;
    float4 gAmbientMtrl;
    float4 gAmbientLight;
};

struct VS_IN
{
    float4 posL   : POSITION;
    float3 normalL : NORMAL;
};

struct VS_OUT
{
    float4 Pos    : SV_POSITION;
    float4 Col    : COLOR;
};

VS_OUT VS(VS_IN vIn)
{
    VS_OUT output = (VS_OUT)0;

    output.Pos = mul( vIn.posL, World ); 
    output.Pos = mul( output.Pos, View ); 
    output.Pos = mul( output.Pos, Projection );


    // Convert from local to world normal
    float3 normalW = mul(float4(vIn.normalL, 0.0f), World).xyz;
    normalW = normalize(normalW);

    // Compute Colour
    float s = max(dot(gLightVecW, normalW), 0.0f);
    float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
    float3 ambient = gAmbientMtrl * gAmbientLight;
    output.Col.rgb = diffuse + ambient;
    output.Col.a = gDiffuseMtrl.a;


    return output;
}

float4 PS(VS_OUT pIn) : SV_Target
{
    return pIn.Col;
}

technique11 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}

对不起,如果我只是向人们扔了太多代码,但我真的很难找出原因

【问题讨论】:

    标签: c++ visual-studio-2013 direct3d directx-11


    【解决方案1】:

    您使用的是legacy DirectX SDK 吗? D3DCompileFromFile 不存在于旧的 #43 版本的 D3DCompiler 中,这意味着您可能在 DirectX SDK 中选择较旧的“d3dcompiler.h”标头,而不是较新的 Windows 8.1 SDK 版本的“d3dcompiler.h”与 VS 2013 一起提供。

    理想情况下,您根本不应该使用 DirectX SDK(请参阅Living without D3DX)。

    我从您的着色器中看到您正在使用 Effects 11,因此您应该确保移至不需要任何 DXSDK 标头的最新 CodePlex 版本。请注意,对“fx_5_0”配置文件的支持已被弃用,预计将在 HLSL 编译器的未来更新中删除。 Windows 8.1 SDK #47 版本的编译器会发出警告说明这一点,但仍会编译这些着色器。

    【讨论】:

    • 感谢您的评论,当我转到 D3DCompileFromFile 的定义时,它会将我带到位于“Windows Kits\8.1\Include\um”中的 d3dcompiler.h 文件,该文件还包含 @987654326 @ 这让我相信我使用了正确的编译器文件,在我的 Include 和 Lib 路径中,我还使用了 windows 8.1 "include/um" 和 "Lib\winv6.3\um\x86"
    • 啊,等等,我想我将原始包含路径留在了 VC++ 目录选项卡中,现在我已经删除了它们,我收到一条错误消息,说我没有 D3DCOMPILER_46.dll跨度>
    • #46 是 VS 2012 附带的 Windows 8.0 SDK。您的 VC++ 目录选项卡应该是默认值(如果将它们设置为其他任何值,请将它们全部设置为“从父级继承..”)。如果您还需要来自旧版 DirectX SDK(基本上是 D3DX 或 XACT)的东西,那么您需要将 Executable 设置为 $(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86,将 Include 设置为 $(IncludePath);$(DXSDK_DIR)Include,并将 Library 设置为 $(LibraryPath);$(DXSDK_DIR)Lib\x86$(LibraryPath);$(DXSDK_DIR)Lib\x64 for VS 2012 或 VS 2013。
    • 我尝试将它们全部设置为“从父级继承”但我仍然遇到问题,当我转到 D3DCompileFromFile 的定义时,它说有两个定义/d3dcompiler.h 文件,一个在 8.0 文件夹中,一个在 8.1 文件夹中,现在我只需要弄清楚如何仅包含 8.1 文件夹,我已经尝试告诉它单独包含它,但它似乎没有帮助
    • 解决了!在我将 8.0 文件夹重命名为其他文件夹然后再次运行程序后,它似乎运行得非常好,甚至在我将 8.0 文件夹恢复为原来的名称后它仍然可以工作。非常感谢!
    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多