这里我有一个基于SharpDX的应用程序,它应该使用Computer Shader来模拟粒子。我在Intel HD 3000显卡的Win 8.1计算机上运行它。顺便说一句,SharpDX
带有计算机着色器和(或)顶点着色器的样本有fx_4_0
或Profile = 10.0
等要求。
问题是,当通过Content.Load<Effect>()
加载着色器时,它会引发SharpDX.Direct3D11.Device.CreateVertexShader()
例外情况如下:
[SharpDX.SharpDXException] {
SharpDX.SharpDXException: HRESULT: [0x80070057],
Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments],
Message: The parameter is incorrect.
at SharpDX.Result.CheckError()
at SharpDX.Direct3D11.Device.CreateVertexShader(IntPtr shaderBytecodeRef, PointerSize bytecodeLength, ClassLinkage classLinkageRef, VertexShader vertexShaderOut)
at SharpDX.Direct3D11.VertexShader..ctor(Device device, Byte[] shaderBytecode, ClassLinkage linkage)
at SharpDX.Toolkit.Graphics.EffectPool.GetOrCompileShader(EffectShaderType shaderType, Int32 index, Int32 soRasterizedStream, StreamOutputElement[] soElements, String& profileError)
...
at SharpDX.Toolkit.Content.ContentManager.Load[T](String assetName, Object options)
嗯,我已经看了一会儿,但没有找到一个完整的解释 - 这里到底发生了什么? 正如here所述,问题可能在于VertexShader参数,但作为着色器开发中的新手,我无法回避。尽管如此,这是着色器文件:
struct Particle
{
float3 Position;
float3 Velocity;
};
StructuredBuffer<Particle> Particles : register(t0);
cbuffer Params : register(b0)
{
float4x4 View;
float4x4 Projection;
};
struct VertexInput
{
uint VertexID : SV_VertexID;
};
struct PixelInput
{
float4 Position : SV_POSITION;
};
struct PixelOutput
{
float4 Color : SV_TARGET0;
};
PixelInput DefaultVS(VertexInput input)
{
PixelInput output = (PixelInput)0;
Particle particle = Particles[input.VertexID];
float4 worldPosition = float4(particle.Position, 1);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
return output;
}
PixelOutput DefaultPS(PixelInput input)
{
PixelOutput output = (PixelOutput)0;
output.Color = float4((float3)0.1, 1);
return output;
}
technique ParticleRender
{
pass DefaultPass
{
Profile = 10.0;
VertexShader = DefaultVS;
GeometryShader = 0;
PixelShader = DefaultPS;
}
}
我想,问题出在VertexInput
结构和uint VertexID : SV_VertexID;
,因为在sapmles中,我从来没有遇到过这样的事情。通过vay,应用程序来自,所以你知道俄语,欢迎你去看看原点:)。此外,可以从here
效果加载的代码是Content.Load<Effect>("ParticleRender");
和完整堆栈跟踪是
at SharpDX.Result.CheckError()
at SharpDX.Direct3D11.Device.CreateVertexShader(IntPtr shaderBytecodeRef, PointerSize bytecodeLength, ClassLinkage classLinkageRef, VertexShader vertexShaderOut)
at SharpDX.Direct3D11.VertexShader..ctor(Device device, Byte[] shaderBytecode, ClassLinkage linkage)
at SharpDX.Toolkit.Graphics.EffectPool.GetOrCompileShader(EffectShaderType shaderType, Int32 index, Int32 soRasterizedStream, StreamOutputElement[] soElements, String& profileError)
at SharpDX.Toolkit.Graphics.EffectPass.InitStageBlock(StageBlock stageBlock, Logger logger)
at SharpDX.Toolkit.Graphics.EffectPass.Initialize(Logger logger)
at SharpDX.Toolkit.Graphics.Effect.InitializeFrom(Effect effectDataArg, Effect cloneFromEffect)
at SharpDX.Toolkit.Graphics.Effect.CreateInstanceFrom(GraphicsDevice device, EffectData effectData, EffectPool effectPool)
at SharpDX.Toolkit.Graphics.Effect..ctor(GraphicsDevice device, EffectData effectData, EffectPool effectPool)
at SharpDX.Toolkit.Graphics.EffectContentReader.ReadContent(IContentManager readerManager, GraphicsDevice device, ContentReaderParameters& parameters)
at SharpDX.Toolkit.Graphics.GraphicsResourceContentReaderBase`1.SharpDX.Toolkit.Content.IContentReader.ReadContent(IContentManager readerManager, ContentReaderParameters& parameters)
at SharpDX.Toolkit.Content.ContentManager.LoadAssetWithDynamicContentReader(Type assetType, String assetName, Stream stream, Object options)
at SharpDX.Toolkit.Content.ContentManager.Load(Type assetType, String assetName, Object options)
at SharpDX.Toolkit.Content.ContentManager.Load[T](String assetName, Object options)
at GPUParticles.Logic.LoadContent() in f:\Users\Maxim\UserData\Programming\GPUParticlesSources\GPUParticles\Logic.cs:line 63
at SharpDX.Toolkit.Game.InitializeBeforeRun()
at SharpDX.Toolkit.GameWindowDesktop.RunRenderLoop()
at SharpDX.Toolkit.GameWindowDesktop.Run()
at SharpDX.Toolkit.GamePlatform.Run(GameContext gameContext)
at SharpDX.Toolkit.Game.Run(GameContext gameContext)
at GPUParticles.Program.Main() in f:\Users\Maxim\UserData\Programming\GPUParticlesSources\GPUParticles\Program.cs:line 22} SharpDX.SharpDXException
答案 0 :(得分:0)
每当您遇到SharpDXException时,请按照"How to debug sharpDX exception"
进行操作
事实证明,尽管得到了DirectX 10.0的支持,但实际上英特尔3000还没有得到ComputeShader的支持
答案 1 :(得分:0)
因为我遇到了与monogame类似的错误并尝试加载着色器而偶然发现了这一点。
在我的情况下,此错误与未设置为
的graphicsDevice配置文件有关HiDef
graphics = new GraphicsDeviceManager(this);
graphics.GraphicsProfile = GraphicsProfile.HiDef;
干杯,
斯蒂芬