• Advertisement
Sign in to follow this  

.cso in .lib

This topic is 396 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

Advertisement

I wrote a small Visual Studio plugin that compiles HLSL and GLSL files into their binary form, and then writes that out to a COFF file which is linked into the executable.  I love the result, but it took some time as the MSBuild system is a little strange and its documentation terrible.

Share this post


Link to post
Share on other sites

I wrote a small Visual Studio plugin that compiles HLSL and GLSL files into their binary form, and then writes that out to a COFF file which is linked into the executable.  I love the result, but it took some time as the MSBuild system is a little strange and its documentation terrible.

And you can then read the blobs from the .lib in the .exe?

Share this post


Link to post
Share on other sites

You don't need special plugins.

I'm using `objcopy` in linux, and `objcopy` from mingw-w64 package on windows.

It reads your binary data, generates object file to be included in the build or in the static lib (many supported formats and platforms), and defines two symbols, designating binary blob beginning address and its length. Accessing that data is no different than constant string.

Share this post


Link to post
Share on other sites

 

I wrote a small Visual Studio plugin that compiles HLSL and GLSL files into their binary form, and then writes that out to a COFF file which is linked into the executable.  I love the result, but it took some time as the MSBuild system is a little strange and its documentation terrible.

And you can then read the blobs from the .lib in the .exe?

 

Alternatively, HLSL compiler can output .h file (see picture) which contains array with compiled shader. It's just .cso file in inlined into array, so you load it exactly same way and if you need to access it outside .lib you'll have to write some function to return array + size.

[attachment=35208:Capture.PNG]

Share this post


Link to post
Share on other sites

 

I wrote a small Visual Studio plugin that compiles HLSL and GLSL files into their binary form, and then writes that out to a COFF file which is linked into the executable.  I love the result, but it took some time as the MSBuild system is a little strange and its documentation terrible.

And you can then read the blobs from the .lib in the .exe?

 

Yup.  They become just a global variable, so I define them at file scope, something like:
namespace SomeNamespace { extern const ShaderByteCode vertex_shader; }
As Zaoshi Kaba pointer out, you can output to a header file which you can then link in, its probably alot easier than rolling your own.

Share this post


Link to post
Share on other sites

Alternatively, HLSL compiler can output .h file (see picture) which contains array with compiled shader. It's just .cso file in inlined into array, so you load it exactly same way and if you need to access it outside .lib you'll have to write some function to return array + size.

This works like a charm!

I still have 2 minor issues with the basic approach:

  • Is it possible to let the header begin automatically with "pragma once"?
  • Is it possible to have no textual references to my directory structure (i.e. #line 48 "C:\Users\Matthias\Documents\Visual Studio 2015\Projects\...\....fx")?

Share this post


Link to post
Share on other sites
  • HLSL compiler doesn't seem to provide any way to add extra code so not really. Since it's const and global you could include all shaders in a single .cpp file and create GetShader(...) method to retrieve data.
  • It appears only in debug build for debugging reasons, so if you aren't interested in debugging shaders you might as well turn off debug stuff for shaders:
    [attachment=35337:Capture.PNG]

Share this post


Link to post
Share on other sites
How about the resource compiler instead? I use that to embed binary data that I don't want as separate files. Simple and flexible without extra plugins or build tools.

Share this post


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

  • Advertisement