-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add support of Texture.CopyTexture() #215
Comments
I'm not sure I understand the proposal (also the actual API proposal isn't really an API either). using UploadTexture2D<float> upload = GraphicsDevice.Default.AllocateUploadTexture2D<float>(64, 64);
using ReadOnlyTexture2D<float> texture = GraphicsDevice.Default.AllocateReadOnlyTexture2D<float>(64, 64);
upload.CopyTo(texture);
// Run the shader...
using ReadBackTexture2D<float> readback = GraphicsDevice.Default.AllocateReadBackTexture2D<float>(64, 64);
texture.CopyTo(readback); Am I missing something? Could you clarify what you're trying to do that's not working for you? 🤔 |
The idea is CopyTexture will automatically convert the pixel format from source to target, it will be a large cost to convert it in CPU. |
Another target is I can upload a RGBA image data to GPU, then CopyTexture to a BGRA32 Texture for later processing |
I've had to do something similar when working with Direct2D so I can render on the GPU at RGBA Float32 precision (128-bits per pixel), and then pull data back to the CPU-side at BGRA U8 precision (32-bits per pixel). I render to a RGBA F32 target, then I copy to a second GPU-side bitmap that is BGRA U8, which means the conversion happens on the GPU. Very useful because otherwise, as you state, the cost to do it on the CPU is much higher. This also lets me do un-premultiplication on the GPU at full Float32, which avoids smashing low-alpha color values. |
@JohnMasen I'm still not sure I understand the proposal, could you clarify exactly what API you're asking for?
But... That doesn't seem to be true? That API is this: ComputeSharp/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs Lines 326 to 338 in 1da016a
But that ComputeSharp/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs Lines 357 to 366 in 1da016a
So I'm not sure what API you're referring to exactly as not being public here? 🤔
If the ask is for a new API to copy to a texture with a different pixel format, then I can understand that, I'm just not sure how the two things are related. Like, this just seems like a request for a new API, but not to make an existing one public? |
The native api allows user copy texture with a pixel format mapping, this enables user copy and transfer pixelformat with single operation. |
Description (optional)
I found the library is using texture copy inside AllocateReadOnlyTexture2D<T,TPixel>(), however the texture copy method is not exposed to public.
The idea is able to create a texture processing pipleline like this:
Upload ->CopyTo Texture -> Process Texture ->Readback result
Rationale
I'm trying to use ComputeSharp to build a fast image resize/resample pipeline for AI Model(ONNX) inference, the stream from video source is RGBA32 format, I wish I could use UploadTexutre2D to upload the stream then copy it to ReadOnlyTexture2D .
Proposed API
Add CopyTexture<TSource,TTarget>(Texture texture) to UploadTexture.
Drawbacks
TBD
Alternatives
Other thoughts
It is also suggested add a customer type mapper to allow map user data structure to DXPixelFormat just like DXGIFormatHelper. User can create UploadTexture/ReadOnlyTexture with the custom mapper to
example:
device.AllocateUploadTexture2D(ReadonlySpan buffer, int w, int h, DXGITypeMapper mapper );
Thanks
The text was updated successfully, but these errors were encountered: