Skip to main content
GameDev.net gamedev.net
🔒 Locked

using shaders without D3DXAssembleShader() ??

Started by eeeko Jul 5, 2004 at 7:00 AM 5 replies 2.4k views
Original Post
eeeko
eeeko
Hello! I'm currently working on a 64kb intro ( I pressume you know what that is :-) ) and has come to a halt. I'm trying to use shaders but haven't found any info about using shader without using d3dx9 commands. Just by declaring a single d3dxvector3 my exe grows with ~90kb and that is not good while coding for minimal size. Any Ideas how this can be achived? ( I ignore the default libraries and compile for smallest size ) Thanks Y'all!
S1CA
S1CA
You can use the vertex shader assembler and pixel shader assembler supplied with the DirectX SDK to compile the shaders into binaries.

You'll find them in the Bin\DXUtils folder with the names vsa.exe and psa.exe (they're command line utilities - so you could call them as a custom build step or use them from a cmd window).

Those will allow you to compile your shaders into their binary form; then you could simply include the binary in the exe in the same way as you do with other data.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Etnu
Etnu
Wouldn't you have to use assemble shader from resource to do that...which would effectively give him the same size increase?
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
S1CA
S1CA
Quote:
Original post by Etnu
Wouldn't you have to use assemble shader from resource to do that...which would effectively give him the same size increase?


To use vsa & psa ?

They compile from the shader source file (*.vsh & *.psh) into pure & compact binary object code that you can incbin (if you're using an assembler anywhere), compile as a binary resource or link in with.

Although there is some overhead for using a resource, its nowhere near what it'd be for including the full shader source code and D3DX.


Alternatively vsa & psa will also output the compiled binary object code as a header file for you!

For example using vsa.exe with the Ripple.vsh shader from the SDK and the /Fh option produced the following:

//// Generated by Microsoft (R) D3DX9 Shader Assembler////  Source: C:\ripple.vsh//  Flags: //const DWORD g_vs11_main[] ={    0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x00000001, 0x80010000,     0x90000000, 0x00000001, 0x80020000, 0xa0ff0004, 0x00000001, 0x80040000,     0x90550000, 0x00000001, 0x80080000, 0xa0ff0004, 0x00000001, 0x80050004,     0x80e40000, 0x00000001, 0x80020004, 0xa0550004, 0x00000008, 0x80010004,     0x80e40004, 0x80e40004, 0x00000007, 0x80010004, 0x80000004, 0x00000006,     0x80010004, 0x80000004, 0x00000005, 0x80070004, 0x80e40004, 0xa0000004,     0x00000002, 0x80010004, 0x80000004, 0xa0000007, 0x00000005, 0x80010004,     0x80000004, 0xa0550007, 0x00000013, 0x80030004, 0x80000004, 0x00000005,     0x80010004, 0x80000004, 0xa0aa0007, 0x00000002, 0x80010004, 0x80000004,     0xa1000007, 0x00000001, 0x80010005, 0xa0ff0004, 0x00000001, 0x80010004,     0x80000004, 0x00000005, 0x80020005, 0x80000004, 0x80000004, 0x00000005,     0x80020004, 0x80000004, 0x80550005, 0x00000005, 0x80040005, 0x80550005,     0x80550005, 0x00000005, 0x80040004, 0x80000004, 0x80aa0005, 0x00000005,     0x80080005, 0x80550005, 0x80aa0005, 0x00000005, 0x80080004, 0x80000004,     0x80ff0005, 0x00000005, 0x800f0004, 0x80e40004, 0xa0e4000a, 0x00000009,     0x80010004, 0x80e40004, 0xa0ff0004, 0x00000005, 0x800f0005, 0x80e40005,     0xa0e4000b, 0x00000009, 0x80010005, 0x80e40005, 0xa0ff0004, 0x00000002,     0x80010005, 0x81000005, 0xa0ff0004, 0x00000005, 0xd00f0000, 0x80000005,     0xa0aa0004, 0x00000005, 0x80020000, 0x80000004, 0xa0ff0007, 0x00000009,     0xc0010000, 0x80e40000, 0xa0e40000, 0x00000009, 0xc0020000, 0x80e40000,     0xa0e40001, 0x00000009, 0xc0040000, 0x80e40000, 0xa0e40002, 0x00000009,     0xc0080000, 0x80e40000, 0xa0e40003, 0x0000ffff};


So all you really need to do is put the *.vsh and *.psh files into your workspace/solution and set up a custom build step on them in the project settings that calls vsa.exe and psa.exe to generate header files of the same name as the shader file.

Then you just #include all shaders by their header name and refer to their binary data directly as if it were the result of one of the D3DX assemble calls.


The output binary from the shader should also compress pretty well with UPX and the like that the OP will likely be using for the intro. [If there's a lot of shaders you could probably get even higher compression ratios by writing a specialist shader compressor - there are certain rules you know shader object code has to follow that you can rely on - and runtime fragment linking by hand shouldn't be too difficult - shader programs aren't too complex and are always memory relative].
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
eeeko
eeeko
Love ya guys! That's just what I needed!

DrunkenHyena: Well, then I'm just half a man! :-D
Kibble
Kibble
Quote:
Original post by eeeko
Love ya guys! That's just what I needed!

DrunkenHyena: Well, then I'm just half a man! :-D

4/64 = 1/16th of a man ;)

Topic Locked

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

Sign in to reply to this topic.