Sign in to follow this  
dmtuan

[SharpDX] Load precompiled shaders into Windows Store App

Recommended Posts

Hi, could someone please help me with this little problem..

 

I used fxc.exe to precompile my vertex shader and pixel shader. I now have VS.fxo and PS.fxo files, that I need to load into my Windows Store Application. 

 

Normaly, if we were in Desktop App, we would use

ShaderBytecode s = ShaderBytecode.FromFile("VS.fxo");

But since we are in Windows Store App, we do not have ShaderBytecode.FromFile() method available. We can only use Shaderbytecode.FromStream(System.IO.Stream stream). But that's a problem, because we cannot use FileStream object in Windows Store App. How do I load the precompiled shaders into my app then? :/

Share this post


Link to post
Share on other sites

Do you have any sort of file system?  I am still using the effect framework, and it has a nice constructor for Effect (Device, byteCode[]) that works if you can manually load it from storage somehow.  I'm not familiar with windows store restrictions.

 

In my stuff on PC I compile from file, then take the compilation result and save it out to a file myself.  Then later load that up and pass it into effect.

Share this post


Link to post
Share on other sites


Hi, could someone please help me with this little problem..

 

I used fxc.exe to precompile my vertex shader and pixel shader. I now have VS.fxo and PS.fxo files, that I need to load into my Windows Store Application. 

 

Normaly, if we were in Desktop App, we would use

ShaderBytecode s = ShaderBytecode.FromFile("VS.fxo");

But since we are in Windows Store App, we do not have ShaderBytecode.FromFile() method available. We can only use Shaderbytecode.FromStream(System.IO.Stream stream). But that's a problem, because we cannot use FileStream object in Windows Store App. How do I load the precompiled shaders into my app then? :/

Surely there must be some way to get a file read from the disk into a stream of bytes, right?

 

If you can get the URI of the file, this might work:

Uri uri = new Uri("IDon'tKnowWhatever");
var stream = System.Windows.Application.GetResourceStream(uri).Stream;
var shaderByteCode = ShaderBytecode.FromStream(stream);
Utilities.Dispose(ref stream);

Share this post


Link to post
Share on other sites


If you can get the URI of the file, this might work:
Uri uri = new Uri("IDon'tKnowWhatever");
var stream = System.Windows.Application.GetResourceStream(uri).Stream;
var shaderByteCode = ShaderBytecode.FromStream(stream);
Utilities.Dispose(ref stream);

 

Thank you, I will try this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this