- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11740
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
Concepts of frame cache technique.
1. use worker threads (or say, background threads) to generate the frames.
2. the consumer thread (or say, main thread) takes away the frames
3. there is a limit of worker threads (2 is suggested), so maybe a simple threadpool implementation will be required.
4. there is a max number of frames cached (5 is suggested), so maybe a continuous implementation of circular queue will be required.
5. if there is no frames being cached, the consumer thread has to wait
6. if there is no more room for new frames to be cached, the worker threads will wait
7. the consumer thread always takes the first frame in the frame cache queue, if the frame number doesn't match, all the frames cached will be dropped, otherwise, only the first frame will be dropped.
How can frame cache improve the overall performance?
1. background threads can make full use of the CPU (usually previewing a tcas fx will not take up 100% CPU, around 35% is the normal level)
2. the I/O takes up a considerable CPU time, if this can be done simultaneously with the generation of a frame or the overlay of a frame, we can save some time.
3. usually, when we previewing an FX, we will simply follow the frame sequence, jumping is merely seldom.
Process of the new renderer (applying the frame cache technique).
1. Initialize the frame cache struct in the main thread
2. then the worker threads will start to generate frames (start from the first valid frame, which may not be 0), and the generated frames will be stored in the frame cache struct.
3. in the main thread, we use query frame function to ask for the specific frame in the frame cache struct, during which the first frame will be returned, if the frame returned is not the frame specified, all the frames in the frame cache struct will be dropped, if they meet, only the first frame will be dropped. If there is no frames cached, the main thread has to wait for the coming of the very first frame.
4. once there is room for a new frame, the worker threads will start to generate the next frame sequence.
5. if the main thread wants to exit, a signal will be sent to the worker threads to let them exit after their completion of their current work (the generating of frame will not be terminated), after the worker threads exit, the main thread exits.
Implementation tips
1. use a new .h header and a new .c file to contain the code of frame cache facility.
2. frame cache is only a utility to libtcas core (tcas.c, tcas.h), just like hla_mt.c and hla_mt_mm.c
3. so the .c file name can be hla_frame_cache.c
Issues
1. What should be stored in the frame cache struct?
a) a threadpool
b) max cached frames count
c) a queue stored the frames cached, (use continuous circular array based queue implementation other than link implementation)
d) etc.
2. The vital functions
a) libtcas_frame_cache_init, to initialize a frame cache struct
b) libtcas_frame_cache_run, to actually run the worker threads of the frame cache in the background
c) libtcas_frame_cache_fin, finalize the frame cache struct
d) libtcas_frame_cache_get, to get the specified frame in the frame cache, if there is no available frame, the function will wait for the completion of the frame, by taking away the specified frame, the function will ask the worker thread to generate the following frames.
3. to use a threadpool, or just multi-threads?
Additional Notes
1. The main reason that the frame cache feature can speed up the overall rendering is that the background threads make full use of the spare time when the main thread doing the overlaying. (frame generating and overlaying are two separate process, hence multi-threading can improve the performance).
|
|