1

我正在尝试 DX10 的共享资源功能,因为我的一个项目需要这个功能。但我找不到太多示例或代码,尤其是使用 SlimDX。根据 DX10 文档,我只需要将资源指定为共享,然后我可以使用来自另一个应用程序的 OpenSharedResource() 打开它。在 SlimDX 中使用一个简单的测试应用程序,我做了以下

        Texture2D tex = new Texture2D(device, new Texture2DDescription()
        {
            ArraySize = 1,
            BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
            CpuAccessFlags = CpuAccessFlags.None,
            Format = Format.B8G8R8A8_UNorm,
            Height = 128,
            Width = 128,
            MipLevels = 1,
            OptionFlags = ResourceOptionFlags.Shared,
            SampleDescription = new SampleDescription(1, 0),
            Usage = ResourceUsage.Default,
        });

        Texture2D tex2 = device.OpenSharedResource<Texture2D>(tex.ComPointer);

但我不断收到此错误

 E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

我似乎无法弄清楚出了什么问题,因为 tex.ComPointer 可能不是 OpenSharedResource 的正确指针或 Texture2D 不受支持(没有明确提到它不在文档中)

通过指定 pHandle 传递给 CreateTexture 函数的另一种替代方法在 SlimDX 中不可用,或者我不知道。

有没有人成功尝试过这个?一些帮助将不胜感激。

谢谢

4

1 回答 1

3

我发现我的代码有问题。我需要使用 DXGI 来检索共享句柄(不是指针)。以下代码完美运行

SlimDX.DXGI.Resource r = new Resource(tex);

Texture2D tex2 = device.OpenSharedResource<Texture2D>(r.SharedHandle);
于 2010-07-07T18:25:57.860 回答