Skip to main content
gamedev.net
🔒 Locked

HLSL Assembly

Started by yoelshoshan May 17, 2009 at 11:16 AM 9 replies 4.8k views
Original Post
yoelshoshan
yoelshoshan
Hi, Is there anywhere a definition of the hlsl assembly BINARY structure? I need to read a hlsl binary and understand the opcodes that i'm reading. (I'm aware it's quite reverse of common usage) Appereciate any help :) Cheers!
MJP
MJP
I don't believe the binary format is documented anywhere.

However you should be able to load up the shader in an app, and then use PIX to view the assembly.

EDIT: I was totally wrong, ignore me. [smile]

[Edited by - MJP on May 17, 2009 1:21:53 PM]
yoelshoshan
yoelshoshan
MJP:
Thanks but i was aiming to do it in real time anyway (my app needs to really understand the binary on the fly - not manually using pix) :)

J-Fox:
Wow! Thanks a lot for that great link, i searched quite a lot and didn't find it - you just saved me a whole lot of work! =]



yoelshoshan
yoelshoshan
Great Failure...

It seems that the documentation is only relevant to SM1,2,3
and NOT to SM4 :/


[Edited by - yoelshoshan on May 19, 2009 8:17:38 AM]
J-Fox
J-Fox
Thats highly possible.
You could check if the headers define other constants which sound like tokens for shaders and try to look them up on the msdn or just contact ms directly.
DieterVW
DieterVW
Hey guys,

I was wondering what you're interested in doing since for sm 4.0+ we do not make the assembler available publicly. In addition, the header blob(s) format is also not published since it could change at any time.

Dieter
yoelshoshan
yoelshoshan
DieterVW:

Mostly educational purposes:
1. Looking in games Shaders, and learning a thing or two =]
2. Changing a game behaviour from outside

Reversing it is of course an option, But i prefer to see if there's available info on this anywhere before i start.
Sik_the_hedgehog
Sik_the_hedgehog
Quote:
Original post by DieterVW
Hey guys,

I was wondering what you're interested in doing since for sm 4.0+ we do not make the assembler available publicly. In addition, the header blob(s) format is also not published since it could change at any time.

Dieter

Actually, moreover, if I recall correctly, Direct3D 10 doesn't allow assembly for shaders at all =/ Though I guess that makes sense because it allows GPUs to use whatever internal language the manufacturer wants.

EDIT: um, that sounds like I tried to mean that the GPUs use the same assembly as Direct3D pre-10 did =P My point was that not all assembly instructions may be easily translatable (at least in the future), or that it may end up missing on a lot of instructions the manufacturer may want to add (something the compiler wouldn't miss because that would be part of the device-specific driver), etc.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
yoelshoshan
yoelshoshan
I didn't mention the exact info i'm trying to extract from the binary.
What i'm looking for is the Resource Binding information,

"... with an assembly language-like instruction set, input and output registers for inter-stage communication, general purpose registers ..., and a set of RESOURCE BINDING points for attaching memory resources such as texture images."

(i can extract the input and output registers from the DDI layer)

Quoting from here:

Direct3d10_web.pdf
DieterVW
DieterVW
Right, there is no way for you to compile a shader from assembly. The hardware vendors do a JIT when you call CreateShader and compile the IL to their own instruction set. Plus, the HLSL compiler provides great feedback and does its best to make sure that the shaders you write will work. Writing in assembly is full of gotchyas now since there are many limitations with regards to how instructions can be used in order to ensure good performance.

The good news is that we provide an API for looking at a compiled shader and getting the resource binding information. This means that you shouldn't have to go through the effort of trying to figure out how the blob works. Besides, the blob could change at any time with any SDK release (and it does) so, the effort you'd go through reverse engineering it wouldn't be worth much.

The reflection API gives lots of other information too, such as instruction counts, variable names, binding slots, data types, and much much more.

Here are some links to get you started:
http://msdn.microsoft.com/en-us/library/dd607334(VS.85).aspx

D3DCompiler.h -> D3DReflect
For a compiled 4.0 target shader, request type __uuidof(ID3D10ShaderReflection)
For a compiled 4.1 target shader, request type __uuidof(ID3D10ShaderReflection1)
For a compiled 5.0 target shader, request type __uuidof(ID3D11ShaderReflection)

The reflection API can be found in the following headers:
d3d10shader.h
d3d10_1shader.h
d3d11shader.h

Top level interface (DX10):
http://msdn.microsoft.com/en-us/library/bb173835(VS.85).aspx

Hopefully this will fill the gap for you.

Dieter

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.