D3DXAssembleShader for D3D11 ?

Started by
11 comments, last by yoelshoshan 12 years, 3 months ago
Is it possible to assemble a shader in D3D11 ? (as opposed to compiling it) ?
It was possible in D3D9, i've used it.

If not, can you offer alternative methods to do it ?
Perhaps there is a way the hlsl assembly to the D3DX11 compile function somehow?

Edit: i DO NOT have access to the shaders hlsl code.

Thanks,
Yoel.
Advertisement
There is no hlsl assembly language assembler in D3D11. You must write hlsl or upload already compiled shader binary.
Thanks Marins, for your answer.

Before i fire up IDA Pro, and work on extracting such functionality from their DLLs, Is there any alternative method that someone here knows?

Regards,
Yoel..
Why do you need to compile shaders from Asm instead of from HLSL?

Note that in DX11/SM5, dynamic linking capabilities were added, which allows the driver itself to perform splicing of different chunks of Asm code together.
The reason i need to compile shaders from Asm, is that i have some project in which I hook d3d functions, and patch hlsl shaders.
It perfectly works in DX9, and now i'm searching for a DX11 solution.
The project is related to Intel Article about "Dynamic Resolution": http://software.intel.com/en-us/articles/dynamic-resolution-rendering-article/

I don't know how will i handle dynamic linking, i want to support base level first.
PS - i'm checking the DDI level now (the level in which D3D talks with the driver, it's similar to D3D but lower level), perhaps there are hints there
Ok found something nice:
d3d11TokenizedProgramFormat.hpp
It's in the WDK.
It's supposed to contain all the info i need.
This is explicit in the D3D11 documentation and was originally removed by D3D10 - check out the "Direct3D 9 to Direct3D 10 Considerations" topic in your SDK.

If you do decide to proceed with this in a production program you will be releasing something that will land you in support difficulties. If anything goes wrong you'll be on your own, and the first thing you will be told is "use HLSL instead".

Speaking of which - any particular reason to not use HLSL?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Hi mhagain, thanks for your reply.
I'm aware that it's officially not supported and i do not expect any official support for this.

The reason that i can't use hlsl, is that i need to patch shaders to change their behaviour in a certain way.
It's significantly easier to do it for assembly code, than for hlsl code due to many reasons. One of the reasons is how easy it is to write an hlsl assembly parser in comparison with writing a parser for hlsl.

Generally there are obvious reasons to why people use assembly, optimizations are some, full control of exactly what shaders they create is another.
Are you patching shaders that you've made yourself, or patching the shaders of other games?

The ability to create 'variations' of a particular HLSL shader is something that almost every game engine needs to implement -- this isn't a unique feature. And AFAIK, not many people would resort to unofficial binary hacking to get this core feature working...
full control of exactly what shaders they create is another[/quote]This isn't really true -- D3D's shader assembly language is only an intermediate language (like MSIL compared to x86 asm). Every different GPU model has its own asm language, which you don't have access to, and the graphics driver will compile your D3D assmebly into real GPU assembly at some point (and in the process, may perform it's own optimisation/rescheduling pass over your code).
Even on the xbox360, where developers do have access to the real GPU microcode format, Microsoft still recommends using HLSL and then reading the output to check whether the compiler is doing what you want (and then tweaking the HLSL to produce the assembly that you want).

The reason that i can't use hlsl, is that i need to patch shaders to change their behaviour in a certain way.
It's significantly easier to do it for assembly code, than for hlsl code due to many reasons. One of the reasons is how easy it is to write an hlsl assembly parser in comparison with writing a parser for hlsl.

It sounds like a very unreliable and complicated way to post-patch the generated assembler code to change the behavior of a shader. Despite "Dynamic Linking" is working only with SM5.0 profile, you could probably use other techniques to achieve similar goals, like using OOP features introduced with D3D11 which are backward compatible to SM3.0 profile (check for example "Advanced HLSL using closures and function pointers")

This topic is closed to new replies.

Advertisement