Jump to content
  • Advertisement
Sign in to follow this  
fir

optymizations by self modifying code

This topic is 1464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

recently i found interesting remark
 
After the continuous headway of GPU rendering, software rasterization was 
increasingly losing ground. Despite this, some great results have been born, such as 
the Pixomatic 1, 2, 3 renderers [15] by Rad Game Tools and the Swiftshader by 
TrasGaming [2]. Both products are highly optimized utilizing the modern threading 
capabilities of today’s Multicore CPUs and have dynamically self-modifying pixel 
pipelines. In addition, Pixomatic 3 and Swiftshader are 100% DirectX 9 
compatible.
 
it seems that in search for top optymizations possible some use old technique of rewriting code at runtime (if i understand it correctly) 
Does maybe someone suspect wkat kind of routines/hotspots can be optymized this way, what kind of benefit it can bring
 
i dont quite get it 

Share this post


Link to post
Share on other sites
Advertisement

Since those software renderers are trying to emulate DX6 or DX7 (or higher?) level capability, they need to have a very flexible pixel shading pipeline. The naive way to implement this would likely be by using a bunch of switch statements or different functions in the pixel shading code that allowed all the features to be enabled/disabled/configured. That's not optimal, so they need to dynamically compile optimal shading functions at runtime, depending on the render state's configuration.

 

The benefit of this is that the pixel drawing code doesn't need to constantly check the render state and decide what to do. It'll just do exactly what it needs to do, because it will have been compiled that way.

Edited by Samith

Share this post


Link to post
Share on other sites

Pretty sure modern Windows doesn't allow self modifying code, so I think that either the article is talking about techniques that can't be used these days, or more likely the compiled shader code is being interpreted instead of executed natively.

 

I would imagine the self-modifying code is more along the lines of branch prediction or patching the shaders to account for values of uniforms, rather than being like the older style code modifications.

Share this post


Link to post
Share on other sites
I think this is about GPU code. Write Access to code segments is only allowed by the os

Share this post


Link to post
Share on other sites

 

Pretty sure modern Windows doesn't allow self modifying code, so I think that either the article is talking about techniques that can't be used these days, or more likely the compiled shader code is being interpreted instead of executed natively.


Of course it does. You just have to make sure that the pages in question are writable and aren't marked no-execute. Self modification is no different than other other JIT compilation in this respect.

Some console and mobile platforms have restrictions that outright disallow a combination of writeable and executable for either security or DRM purposes, but Windows is fine.

 

i also think that its possible - probably  such simple thing as

buf = VirtualAlloc(NULL,size,MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE_READWRITE);

will sufice

Share this post


Link to post
Share on other sites

Since those software renderers are trying to emulate DX6 or DX7 (or higher?) level capability, they need to have a very flexible pixel shading pipeline. The naive way to implement this would likely be by using a bunch of switch statements or different functions in the pixel shading code that allowed all the features to be enabled/disabled/configured. That's not optimal, so they need to dynamically compile optimal shading functions at runtime, depending on the render state's configuration.

 

The benefit of this is that the pixel drawing code doesn't need to constantly check the render state and decide what to do. It'll just do exactly what it needs to do, because it will have been compiled that way.

 

well, thats sad, i thinked if it is maybe some some general way of optymizing (helping get away some ifs or something though i got no idea

how it would look like) - if so this is not general idea on optymizing but more like script compilation  indeed

Edited by fir

Share this post


Link to post
Share on other sites

Moderation note: a number of off-topic replies have been removed from this discussion, and warnings have been issued to a couple of members.  Please keep all further discussion on topic.

Share this post


Link to post
Share on other sites
You can not change the attribute of a a code segment from read only to read-write. You create a new data area that is executable. So the os makes your code segment always read only at load time.

I dont had these self created data areas in mind.

Share this post


Link to post
Share on other sites

Executable memory is one of those things that Apple have decided is "far too dangerous for developers to have".

 

So any attempt at self modifying code on IOS is doomed to failure.

 

You can trick windows and get some nice executable memory, I used it for years as a way of injecting my own code into third party games.

 

However in the general case if you think you need self modifying code, you have probably got the algorithm wrong smile.png

 

Even with the best designed bits of self modding, you save nanoseconds (they may be important nanoseconds, if such a beast exists) whereas a change in the algorithm often saves milliseconds.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!