I'm using Media Foundation to decode video frames (D3D9 GPU decoding, BGRA32 format) and ComputeSharp for pixel processing. Currently, I'm forced to stage the data through the CPU when copying from the decoded D3D9 buffer to ReadOnlyTexture2D, which introduces significant overhead. The workflow looks like this:
IMF2DBuffer (GPU) → UploadTexture2D (CPU) → ReadOnlyTexture2D (GPU)
Here's the current code snippet:
using var buffer = result.ConvertToContiguousBuffer();
using var buffer2d = buffer.QueryInterface<IMF2DBuffer>();
buffer2d.Lock2D(out var scanline0, out var strideInBytes);
int length = height * strideInBytes;
unsafe
{
// Staging through CPU-visible texture
using var stagingTexture = GraphicsDevice.GetDefault().AllocateUploadTexture2D<Bgra32>(width, height);
var pointer = stagingTexture.View.DangerousGetAddressAndByteStride(out _);
Buffer.MemoryCopy(scanline0.ToPointer(), pointer, length, length);
// GPU texture creation and copy
var originTexture = GraphicsDevice.GetDefault().AllocateReadOnlyTexture2D<Bgra32, float4>(width, height);
originTexture.CopyFrom(stagingTexture);
// ... processing ...
originTexture.Dispose();
}
buffer2d.Unlock2D();
Key Questions:
- Is there a way to directly copy from the D3D9-decoded surface to ComputeSharp's
ReadOnlyTexture2D without CPU staging?
- Alternatively, can ComputeSharp/Direct3D interop allow direct access to the D3D9 buffer in compute shaders (e.g., via resource sharing or shared handles)?
- The D3D9 surface comes from Media Foundation's
IMF2DBuffer (docs)
- Current CPU staging (
UploadTexture2D) is a bottleneck for real-time processing
I'm using Media Foundation to decode video frames (D3D9 GPU decoding,
BGRA32format) and ComputeSharp for pixel processing. Currently, I'm forced to stage the data through the CPU when copying from the decoded D3D9 buffer toReadOnlyTexture2D, which introduces significant overhead. The workflow looks like this:IMF2DBuffer (GPU) → UploadTexture2D (CPU) → ReadOnlyTexture2D (GPU)Here's the current code snippet:
Key Questions:
ReadOnlyTexture2Dwithout CPU staging?IMF2DBuffer(docs)UploadTexture2D) is a bottleneck for real-time processing