I’m running a job that’s building a texture using GetPixelData to pass the texture pointer. The job is fast even on main thread but texture.Apply takes 1ms for a 200x200 texture that’s a bit much (on Switch).
So I was wondering if there was a faster way to upload the texture to the GPU that doesn’t hog that much of the main thread, something on another thread maybe?
public void RecalculateBoostJobified(Rect r)
{
// prep native data for the job
_newTextureMapHalfPointer = _tex.GetPixelData<half>(0);
var recalculateBoostJob = new RecalculateBoostJob
{
r_IN = r,
newTextureMapHalfPointer_INOUT = _newTextureMapHalfPointer
};
recalculateBoostJob.Run();
_tex.Apply(true);
}
There is the CommandBuffer.BeginWrite and EndWrite.
But I’ve found issues:
Gets way too slow when recording with OBS (fixed already I assume) when using those
You can’t have more than one active NativeArray per CommandBuffer
The NativeArray seem to be filled with dirt memory, and it will override the CommandBuffer with dirt if you don’t override the whole allocated slice up to the ‘totalwritten’ EndWrite parameter
Can’t EndWrite in a job, needs to do so in the start of the next frame or similar
Because there is no automatic resource versioning for SubUpdates buffers. Otherwise, you’ll get unexpectedly corrupted data. This issue we faced with Begin\End spread across frames, thanks to @JussiKnuuttila from Hybrid Renderer team he has shade light on this tricky part with SubUpdates buffers and Begin\End.
I see commandbuffer, aren’t those made to send arrays? I use texture bilinear to get a smooth gradient and might still use mipmap, how would i get that with buffers?
Oh yeah, I was getting crazy flickering and had to put .Complete() on my jobs, I guess I never actually connected what kind of change made the flickering stop, at least now I know. Although I do override the data every single frame and it just works