您可以在 AMP Texture<> 和 ID3D11Texture2D 缓冲区之间进行互操作。可以在此处的第 11 章示例中找到完整的代码和其他互操作示例。
// Get a D3D texture resource from an AMP texture.
texture<int, 2> text(100, 100);
CComPtr<ID3D11Texture2D> texture;
IUnknown* unkRes = get_texture(text);
hr = unkRes->QueryInterface(__uuidof(ID3D11Texture2D),
reinterpret_cast<LPVOID*>(&texture));
assert(SUCCEEDED(hr));
// Create a texture from a D3D texture resource
const int height = 100;
const int width = 100;
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Height = height;
desc.Width = width;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
CComPtr<ID3D11Texture2D> dxTexture = nullptr;
hr = device->CreateTexture2D(&desc, nullptr, &dxTexture);
assert(SUCCEEDED(hr));
texture<uint4, 2> ampTexture = make_texture<uint4, 2>(dxView, dxTexture);