[英]Error creating effect from memory (c++, directx 11)
I'm trying to create an effect variable from my compiled shader so I can reference variables and set their values but something is going wrong. 我正在尝试从编译的着色器创建一个效果变量,以便我可以引用变量并设置其值,但是出了点问题。 I pulled a snippet from the Introduction to 3D Game Programming by Frank Luna and made tweaks where necessary
我从Frank Luna的3D游戏编程简介中摘录了一段代码,并在必要时进行了调整
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;
}
And it throws the error 并引发错误
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.
I've tried to debug a little and rebuild the effect libraries but still nothing. 我尝试调试一些并重建效果库,但仍然一无所获。 Could someone spot the issue or tell me how to go about finding the cause?
有人可以发现问题或告诉我如何去寻找原因吗?
Edit: I believe the issue is with the debug layer. 编辑:我相信问题出在调试层。 I have tried enabling the debug layer using (both D3D10 and D3D11)
我尝试使用(D3D10和D3D11两者)启用调试层
#if defined(_DEBUG) || defined (DEBUG)
shaderFlags |= D3D10_CREATE_DEVICE_DEBUG;
shaderFlags |= D3D10_SHADER_DEBUG;
shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif
My device flags also enable debug mode 我的设备标志也启用调试模式
UINT createDeviceFlags = 0;
#if defined (_DEBUG) || defined(DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
I'm using Windows 8.1 and Visual Studio is using the Windows 8.1 SDK by default, but I am also referencing the old June 2010 SDK and this is where the problem is happening. 我使用的是Windows 8.1,默认情况下,Visual Studio使用的是Windows 8.1 SDK,但我也引用的是2010年6月的旧版SDK,这就是问题所在。 The methods I am trying to use above are from the old SDK.
我上面尝试使用的方法来自旧的SDK。
I believe all the requires dlls are installed for the debug layer. 我相信为调试层安装了所有必需的dll。
I also have the dlls for the old sdk (the one I'm using to reference the old methods) 我也有旧sdk的dll(我用来引用旧方法的那个)
Solved 解决了
I downloaded the latest version of Effects11 and compiled the shader with a compatible fx version (fx_5_0) 我下载了最新版本的Effects11,并使用兼容的fx版本(fx_5_0)编译了着色器
拉动最新版本的Effects 11似乎可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.