SDL中文论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 6358|回复: 0
打印 上一主题 下一主题

[Discuss] SDL_UpdateTexture、SDL_RenderCopy、SDL_RenderReadPixels的花费时间

[复制链接]

149

主题

331

帖子

2445

积分

版主

Rank: 7Rank: 7Rank: 7

积分
2445
跳转到指定楼层
楼主
发表于 2016-7-8 14:06:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 ancientcc 于 2016-7-8 14:08 编辑
  1. surface render_scale_surface(const surface &surf, int w, int h)
  2. {
  3.         tblend_none_lock lock(surf);

  4.         uint32_t t1, t2, t3, t4, t5;
  5.         t1 = SDL_GetTicks();

  6.         SDL_Texture* src = SDL_CreateTextureFromSurface(renderer, surf);
  7.         SDL_Texture* target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
  8.         SDL_SetRenderTarget(renderer, target);

  9.         t2 = SDL_GetTicks();
  10.         SDL_RenderCopy(renderer, src, NULL, NULL);
  11.         t3 = SDL_GetTicks();

  12.         surface dst(create_neutral_surface(w, h));
  13.         {
  14.                 surface_lock dst_lock(dst);
  15.                 t4 = SDL_GetTicks();
  16.                 SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, dst->pixels, 4 * w);
  17.         }
  18.         t5 = SDL_GetTicks();
  19.         posix_print("create: %i, RenderCopy: %i, create2: %i, ReadPixels: %i\n", t2 - t1, t3 - t2, t4 - t3, t5 - t4);

  20.         SDL_SetRenderTarget(renderer, NULL);
  21.         SDL_DestroyTexture(target);
  22.         SDL_DestroyTexture(src);
  23.         return dst;
  24. }
复制代码

上面是一个执行缩功能的函数,它同时用到了这三个函数,并打印它们花费的时间。打印部分见后面。
  1. create: 31, RenderCopy: 4, create2: 6, ReadPixels: 16
  2. (750x1334)==>(640x1136), soft: 65, gpu: 61
复制代码

以以上这条记录为例说明各字段。它们时间单位都是毫秒
字段
create会调用SDL_CreateTexture,该函数要执行SDL_UpdateTexture,它花费的时间基本花费在SDL_UpdateTexture
RenderCopy花费在SDL_RenderCopy的时间
create2创建目标图面,和opengl无关
ReadPixels花费在SDL_RenderReadPixels上时间
(750x1334)==>(640x1136) 指示这次缩放的(源图像尺寸)==>(目标图像尺寸)
soft缩放这个图像,scale_surface花费了的时间。相比opengl使用GPU,把它称为软缩放
gpu缩放这个图像,render_scale_surface花费了的时间,就是以上那几个时间之和


根据察看打印得出的几个结论。
  • 执行SDL_UpdateTexture,Android要比iOS快。不过iOS慢也不算离谱,还能接受。
  • 执行SDL_RenderCopy,不论Android还是iOS,都快。
  • 执行SDL_RenderReadPixels,都不算快,尤其Android,只能用慢到离谱来形容。
  • 对缩放小图像,像<100x100的,因为GPU有固定消耗在那里,相比软缩放没优势,但图像越大,它的优势越明显。
  • 程序应该尽量避免SDL_RenderReadPixels!



iOS
create: 31, RenderCopy: 4, create2: 6, ReadPixels: 16
(750x1334)==>(640x1136), soft: 65, gup: 61
create: 35, RenderCopy: 0, create2: 6, ReadPixels: 17
(750x1334)==>(640x1136), soft: 394, gup: 62
create: 4, RenderCopy: 0, create2: 1, ReadPixels: 2
(224x224)==>(220x220), soft: 6, gup: 8
create: 5, RenderCopy: 0, create2: 6, ReadPixels: 17
(750x133)==>(640x1136), soft: 45, gup: 30
2create: 2, RenderCopy: 0, create2: 5, ReadPixels: 15
(100x100)==>(640x1008), soft: 38, gup: 23
create: 2, RenderCopy: 0, create2: 1, ReadPixels: 2
(224x224)==>(220x220), soft: 6, gup: 6
create: 5, RenderCopy: 0, create2: 6, ReadPixels: 17
(750x133)==>(640x1136), soft: 43, gup: 30
create: 31, RenderCopy: 0, create2: 4, ReadPixels: 16
(750x1131)==>(640x780), soft: 234, gup: 54
create: 5, RenderCopy: 0, create2: 1, ReadPixels: 4
(266x600)==>(266x346), soft: 13, gup: 11
create: 1, RenderCopy: 1, create2: 1, ReadPixels: 5
(100x100)==>(640x244), soft: 9, gup: 9
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 1
(24x24)==>(48x48), soft: 1, gup: 3
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 2
(80x80)==>(76x76), soft: 1, gup: 4
create: 37, RenderCopy: 1, create2: 6, ReadPixels: 29
(750x1334)==>(640x1136), soft: 143, gup: 77
create: 1, RenderCopy: 1, create2: 0, ReadPixels: 1
(126x1)==>(368x1), soft: 0, gup: 3
create: 0, RenderCopy: 0, create2: 0, ReadPixels: 2
(24x24)==>(48x48), soft: 1, gup: 2
create: 0, RenderCopy: 0, create2: 1, ReadPixels: 1
(126x1)==>(368x1), soft: 0, gup: 2
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 1
(24x24)==>(48x48), soft: 0, gup: 3
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 2
(126x1)==>(368x1), soft: 0, gup: 3
create: 0, RenderCopy: 1, create2: 0, ReadPixels: 1
(24x24)==>(48x48), soft: 1, gup: 2
create: 20, RenderCopy: 0, create2: 4, ReadPixels: 14
(640x1136)==>(531x944), soft: 217, gup: 41
create: 33, RenderCopy: 0, create2: 6, ReadPixels: 38
(750x1334)==>(640x1136), soft: 143, gup: 82
create: 28, RenderCopy: 0, create2: 6, ReadPixels: 17
(750x1334)==>(640x1136), soft: 144, gup: 55


Android
create: 15, RenderCopy: 3, create2: 14, ReadPixels: 189
(750x1334)==>(1080x1860), soft: 73, gup: 224
create: 19, RenderCopy: 0, create2: 22, ReadPixels: 212
(750x1334)==>(1080x1860), soft: 286, gup: 257
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 3
(88x88)==>(132x132), soft: 1, gup: 4
create: 0, RenderCopy: 1, create2: 0, ReadPixels: 12
(224x224)==>(336x336), soft: 7, gup: 13
create: 1, RenderCopy: 0, create2: 1, ReadPixels: 10
(224x224)==>(336x336), soft: 6, gup: 13
create: 1, RenderCopy: 0, create2: 1, ReadPixels: 7
(88x88)==>(126x126), soft: 2, gup: 9
create: 0, RenderCopy: 0, create2: 1, ReadPixels: 2
(88x88)==>(132x132), soft: 2, gup: 3
create: 17, RenderCopy: 0, create2: 29, ReadPixels: 169
(750x1334)==>(1080x1860), soft: 133, gup: 218
create: 0, RenderCopy: 0, create2: 0, ReadPixels: 2
(126x1)==>(648x1), soft: 0, gup: 2
create: 0, RenderCopy: 0, create2: 0, ReadPixels: 1
(24x24)==>(72x72), soft: 1, gup: 1
create: 0, RenderCopy: 0, create2: 0, ReadPixels: 0
(126x1)==>(648x1), soft: 0, gup: 0
create: 0, RenderCopy: 0, create2: 0, ReadPixels: 9
(24x24)==>(72x72), soft: 0, gup: 9
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 1
(126x1)==>(648x1), soft: 1, gup: 2
create: 1, RenderCopy: 0, create2: 0, ReadPixels: 1
(24x24)==>(72x72), soft: 0, gup: 2
create: 32, RenderCopy: 0, create2: 8, ReadPixels: 200
(1080x1860)==>(912x1572), soft: 199, gup: 243
create: 16, RenderCopy: 0, create2: 14, ReadPixels: 160
(750x1334)==>(1080x1860), soft: 140, gup: 194
create: 0, RenderCopy: 0, create2: 1, ReadPixels: 2
(88x88)==>(132x132), soft: 2, gup: 3
create: 1, RenderCopy: 1, create2: 0, ReadPixels: 21
(224x224)==>(336x336), soft: 7, gup: 23
create: 1, RenderCopy: 0, create2: 1, ReadPixels: 24
(224x224)==>(336x336), soft: 14, gup: 26
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|丽谷软件|libsdl.cn

GMT+8, 2025-5-2 01:07 , Processed in 0.052009 second(s), 19 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表