【发布时间】:2016-04-06 01:36:47
【问题描述】:
我正在尝试从我编译的着色器中创建一个效果变量,以便我可以引用变量并设置它们的值,但出现了问题。我从 Frank Luna 的 Introduction to 3D Game Programming 中提取了一个 sn-p,并在必要时进行了调整
HRESULT hr;
DWORD shaderFlags = 0;
ID3D10Blob * compiledShader = 0;
ID3D10Blob * compilationMessages = 0;
hr = D3DX11CompileFromFile(L"cubemap.fx", 0, 0, 0, "fx_4_0", shaderFlags, 0, 0, &compiledShader, &compilationMessages, 0);
if (FAILED(hr))
{
MessageBox(nullptr,
L"Failed to compile cubemap shader D3DX11", L"Error", MB_OK);
return hr;
}
ID3DX11Effect * shader;
hr = D3DX11CreateEffectFromMemory(
compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, device, &shader);
if (FAILED(hr))
{
MessageBox(nullptr,
L"Could not create effect from memory", L"Error", MB_OK);
return hr;
}
它会抛出错误
Could not create effect from memory
HR = E_FAIL
Attempted to create a device with the debug layer enabled and the layer is not installed.
我尝试调试了一下并重建效果库,但仍然没有。有人能发现问题或告诉我如何寻找原因吗?
编辑:我认为问题出在调试层。我尝试使用(D3D10 和 D3D11)启用调试层
#if defined(_DEBUG) || defined (DEBUG)
shaderFlags |= D3D10_CREATE_DEVICE_DEBUG;
shaderFlags |= D3D10_SHADER_DEBUG;
shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif
我的设备标志也启用调试模式
UINT createDeviceFlags = 0;
#if defined (_DEBUG) || defined(DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
我使用的是 Windows 8.1,而 Visual Studio 默认使用的是 Windows 8.1 SDK,但我还引用了 2010 年 6 月的旧 SDK,这就是问题所在。我上面尝试使用的方法来自旧的 SDK。
已解决
我下载了最新版本的 Effects11,并使用兼容的 fx 版本 (fx_5_0) 编译了着色器
【问题讨论】:
-
你没有告诉我们
hr的确切值是什么。 -
您的编辑仍然没有告诉我们
hr是什么:msdn.microsoft.com/en-us/library/windows/desktop/…FAILED宏只告诉我们hr < 0。 -
Attempted to create a device with the debug layer enabled and the layer is not installed.那么实际错误的文本是否比FAILED(hr)提供了更多细节? -
@PaulMcKenzie 我对它进行了一些阅读并进行了一些修改,但它仍在发生。设备标志也启用调试模式。有什么我需要安装的吗?