{"id":1413,"date":"2011-08-22T18:39:54","date_gmt":"2011-08-22T17:39:54","guid":{"rendered":"http:\/\/positech.co.uk\/cliffsblog\/?p=1413"},"modified":"2011-08-24T14:13:24","modified_gmt":"2011-08-24T13:13:24","slug":"400-speedup-in-a-pesky-transform-thing","status":"publish","type":"post","link":"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/08\/22\/400-speedup-in-a-pesky-transform-thing\/","title":{"rendered":"400% speedup in a pesky transform thing"},"content":{"rendered":"<p>This code was slow*:<\/p>\n<pre>\u00a0\u00a0\u00a0 D3DTLVERTEX* pvert = LocalMem;\r\n\u00a0\u00a0 \u00a0for(int c = 0; c &lt; CopiedIn; c++)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSX -= TransformX;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSY -= TransformY;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSX *= TransformZoom;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSY *= TransformZoom;\r\n\u00a0\u00a0 \u00a0}<\/pre>\n<p>This code runs in one quarter of the time:<\/p>\n<pre>\u00a0\u00a0\u00a0 D3DTLVERTEX* pvert = LocalMem;\r\n\u00a0\u00a0 \u00a0for(int c = 0; c &lt; CopiedIn; c++)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert-&gt;dvSX -= TransformX;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert-&gt;dvSY -= TransformY;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert-&gt;dvSX *= TransformZoom;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert-&gt;dvSY *= TransformZoom;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert++;\r\n\u00a0\u00a0 \u00a0}<\/pre>\n<p>Pointers FTW!<\/p>\n<p>I&#8217;m doing this sort of stuff now, which isn&#8217;t as fast as actually using hardware T&amp;L, but is better than my older, hacky software transforms which happened on individual sprites, rather than at the VB level. Yeah I know&#8230; everyone uses world matrices and hardware T&amp;L, I won&#8217;t bore you with the reasons I&#8217;m not, but there ya go. It works! (GSB uses a per-object world -&gt; screen software transform for each object).<\/p>\n<p><strong>EDIT: These measurements may be a glitch. I&#8217;ve run and re-run, and re-run the profiler on both versions and now cannot get as big a discrepancy (although there is still a speed difference). Getting accurate measurements on a multi-core PC that has a live internet connection and various background services running is hell. Now I know why people like console dev :D<\/strong><\/p>\n<p>*relatively speaking.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This code was slow*: \u00a0\u00a0\u00a0 D3DTLVERTEX* pvert = LocalMem; \u00a0\u00a0 \u00a0for(int c = 0; c &lt; CopiedIn; c++) \u00a0\u00a0 \u00a0{ \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSX -= TransformX; \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSY -= TransformY; \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSX *= TransformZoom; \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pvert[c].dvSY *= TransformZoom; \u00a0\u00a0 \u00a0} This code runs in one quarter of the time: \u00a0\u00a0\u00a0 D3DTLVERTEX* pvert =<\/p>\n<p class=\"text-right\"><span class=\"screen-reader-text\">Continue Reading&#8230; 400% speedup in a pesky transform thing<\/span><a class=\"btn btn-secondary continue-reading\" href=\"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/08\/22\/400-speedup-in-a-pesky-transform-thing\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1413","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/comments?post=1413"}],"version-history":[{"count":3,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1413\/revisions"}],"predecessor-version":[{"id":1416,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1413\/revisions\/1416"}],"wp:attachment":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/media?parent=1413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/categories?post=1413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/tags?post=1413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}