C# E_INVALIDARG:传递给返回函数的参数无效

C# E_INVALIDARG:传递给返回函数的参数无效,c#,directx,slimdx,directx-10,C#,Directx,Slimdx,Directx 10,我试图制作一个简单的SlimDX示例来测试与GDI的一些性能,不幸的是,我一开始就被卡住了。我在VS2010中创建了简单控制台应用程序,并将此代码添加到程序主方法中: // 0. STEP SlimDX.Direct3D10.Device device = new SlimDX.Direct3D10.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport); SlimDX.Direct

我试图制作一个简单的SlimDX示例来测试与GDI的一些性能,不幸的是,我一开始就被卡住了。我在VS2010中创建了简单控制台应用程序,并将此代码添加到程序主方法中:

        // 0. STEP
        SlimDX.Direct3D10.Device device = new SlimDX.Direct3D10.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
        SlimDX.Direct2D.Factory factory = new SlimDX.Direct2D.Factory();

        // 1. STEP
        Texture2DDescription textureDesc = new Texture2DDescription();
        textureDesc.Width = 512;
        textureDesc.Height = 512;
        textureDesc.MipLevels = 1;
        textureDesc.ArraySize = 1;
        textureDesc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
        textureDesc.SampleDescription = new SampleDescription(1, 0);
        textureDesc.Usage = ResourceUsage.Default;
        textureDesc.BindFlags = BindFlags.RenderTarget;
        textureDesc.CpuAccessFlags = CpuAccessFlags.None;
        textureDesc.OptionFlags = ResourceOptionFlags.None;
        Texture2D maskTexture = new Texture2D(device, textureDesc);

        // 2. STEP
        SlimDX.DXGI.Surface surface = maskTexture.AsSurface();

        // 3. STEPpro
        RenderTargetProperties props = new RenderTargetProperties
        {
            HorizontalDpi = 96,
            VerticalDpi = 96,
            MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
            PixelFormat = new PixelFormat(SlimDX.DXGI.Format.Unknown, AlphaMode.Premultiplied),
            Type = RenderTargetType.Default,
            Usage = RenderTargetUsage.None
        };
        RenderTarget target = RenderTarget.FromDXGI(factory, surface, props);
这会导致RenderTarget.FromDXGI调用崩溃,并显示以下消息:

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)
不幸的是,我无法启用此问题中所述的DirectX调试输出:

。。。所以,这就是我的全部

但是,我在家里(win8.1,vs2013)和工作中(win7,vs2010sp1)都试过,在家里,当我从2013年开始使用图形诊断调试应用程序时,它可以工作。当我开始常规调试或尝试手动启动exe时,它不起作用。在工作中,它根本不起作用


从代码中有什么想法吗?我在这里有点绝望(

我刚刚注意到你对我的另一个答案的评论。以下是我使用的创建函数:

    public static Texture2D CreateRenderTexture(this RenderHelper helper, int width, int height)
    {
        Texture2DDescription description = new Texture2DDescription
        {
            ArraySize = 1,
            BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
            CpuAccessFlags = CpuAccessFlags.None,
            Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
            Width = width,
            Height = height,
            MipLevels = 1,
            OptionFlags = ResourceOptionFlags.None,
            SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
            Usage = ResourceUsage.Default,
        };

        return new Texture2D(helper.Device, description);
    }

您需要将
DeviceCreationFlags.Debug
传递给
Device
构造函数才能获得调试输出。我不确定渲染目标是否可以使用未知的像素格式创建。这对我来说没有多大意义。尤其是如果底层纹理具有已知格式。顺便说一句,使用
设备会更舒适。CreateWithSwapChain
方法创建设备并呈现目标。1)当我尝试使用调试标志创建设备时,我得到以下错误:E_失败:发生了一个未确定的错误;2) 我已将渲染目标的格式设置为与您建议的纹理相同;3) 我不需要渲染到视觉控制,所以我没有使用swapchain。我只需要将一些线条渲染为纹理,然后将其导出为位图。您安装Windows SDK中包含的DirectX SDK有一段时间了吗?在我的家用计算机(win8.1)上安装了Windows SDK,在我的工作计算机(win7)上安装了DirectX SDK。我还将DebugLevel.Information设置为D2D factory,这样我可以获得更多日志信息,但即使我从以下链接额外安装了D2D调试层,我仍然会得到“无法加载D2D调试层”: