Advertisement

Compiling HLSL to ASM? And inserting ASM into HLSL?

Started by August 16, 2017 07:24 PM
4 comments, last by bandages 7 years, 5 months ago

Hi, I'm just a self-taught amateur exploring HLSL (among other things).  I'm using MikuMikuDance to render my models and effects.  It's closed source but free, based on DX9 (so shader model 3.0).

One of my problems with this renderer is that effects are always compiled at run time.  This is handy for debugging, of course.  But when I get something finished, load times can be irritating.  I very much appreciate the intelligence of the compiler in terms of optimization, but loading times are the price to be paid for that.  Since I usually attach shaders to models that I make for public use (public domain to the extent made possible by any other sources I might use), shader load times can limit my audience.

I believe that if I could insert assembly into my .fx files, that I could bypass most of the compiler's thought processes.  In order to do that, I'd need to know how to output my HLSL to ASM (I can't write ASM and have a lot of other priorities) and how to replace my HLSL with the outputted ASM.

Maybe that's bad thinking?  Like I said, I'm just a beginner, trying to work within the limits of my knowledge and my environment.  Always happy to hear if I'm pursuing something unwise.

But otherwise, this strikes me as something that is probably possible, and that would probably help load times quite a bit.  Any help or advice?  Wasn't able to refine my Googling enough to get anything useful.

 

This should give a start :D

https://stackoverflow.com/questions/5020204/loading-a-precompiled-hlsl-shader-into-memory-for-use-with-createpixelshader

.:vinterberg:.

Advertisement

Thanks, that might be a start.  I'll try to figure out what I can get out of fxc.

 

Just to be clear about my limits, my "development environment" is Notepad++ and I don't have any access to C code from the renderer.  I believe that the renderer will only load uncompiled HLSL files (typically with the .fx extension) rather than compiled shaders.

You can't insert inline assembly into HLSL. The only way to avoid compiling at runtime is to pre-compile offline (or cache compiler outputs at runtime), and create your shaders from the pre-compiled binary data. If you can't modify the code that loads the shaders, then your only options are to somehow patch the executable or DLL, or create a shim DLL that intercepts the call to compile the shader and does something else.

Thanks MJP, that's good to know.  DLL workaround sounds beyond my current ability.

This topic is closed to new replies.

Advertisement