Jump to content
  • Advertisement
Sign in to follow this  
StanIAm

Save shader as ID3D10Blob Pointer

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

Hey ya , I have a question about shaders in Direct3D.
I made some programms for reandering with shaders ( its basic but...) and now I think about the performance of that.
I say in some Engine like CryEngine that the Shaders are saved binary and had the following idea.

When you want to compile a shader , this is saved in a ID3D10Blob Pointer, so we compile that file and have the shader as a Blob Pointer.Can I save the shader binary (The compiled shader as a blob poiinter ) and read that easy to a ID3D10Blob pointer in my application ??
This would be faster, because 1. the shader is loaded binary and 2. you have not to compile that stuff.

Can I do this ??

Share this post


Link to post
Share on other sites
Advertisement
Yes you can. Blob is simply wrapper that stores void* pointer and takes care of destroying it.

You can use fxc.exe to generate compiled shader, or compile it through own tool and save ID3D10Blob to a file (GetBufferPointer() to get data and GetBufferSize() to get size). When you need to load it, just load file into memory and create Blob using D3D10CreateBlob() (but last time I checked creating shader required void* pointer to data, not blob, possibly you don't even need to create blob).

Share this post


Link to post
Share on other sites
Hey I made a programm to compile my shaders and write the blob in a file, but my output file is only 4 bytes in size.
So the question is why.

When I display the blob bufferpointer I become a 1 Byte output.

Here is thecode I hope somebody can help me:


#include <iostream>
#include <fstream>
#include <string>

#include <d3dx11.h>
#include <D3D10.h>
#pragma comment(lib,"d3d10.lib")
#pragma comment(lib,"d3dx11.lib")
using namespace std;
/////////////////////////////////////////////////////////////
// Vertexshader in Blob Datei ( Binärer Shader ) umwandeln
// Shader muss die Hauptfunktion VertexMain enthalten
/////////////////////////////////////////////////////////////
std::string ExtractDirectory( const std::string& path )
{
return path.substr( 0, path.find_last_of( '\\' ) +1 );
}
std::string ExtractFilename( const std::string& path )
{
return path.substr( path.find_last_of( '\\' ) +1 );
}
std::string ChangeExtension( const std::string& path, const std::string& ext )
{
std::string filename = ExtractFilename( path );
return ExtractDirectory( path ) +filename.substr( 0, filename.find_last_of( '.' ) ) +ext;
}

int main(int argc, char* args[])
{
string Filepath;
ID3D10Blob* error;
ID3D10Blob* buffer;
HRESULT hr;
if(argc >= 2 )
{
Filepath = args[1];

cout << "Execute Path:" << args[0] << endl;
cout << "Inputfile:" << args[1] << endl;
hr = D3DX11CompileFromFileA(Filepath.c_str(), NULL, NULL, "VertexMain" , "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, NULL, NULL, &buffer, &error, NULL);
if(FAILED(hr))
{
char* compileError;
unsigned long bufferSize;
unsigned long i;

cout << "FAILED TO COMPILE SHADER" << endl;
cout << "FOLLOWING ERRORS" << endl;
compileError = (char*)error->GetBufferPointer();
bufferSize = error->GetBufferSize();
for(i = 0; i < bufferSize; i++)
{
cout << compileError;
}
error->Release();
error = 0;
getchar();
return 1;

}
else
{
ofstream outfile;
string outpath = ChangeExtension(Filepath,".gvs");
outfile.open(outpath, ios::out | ios::binary );
cout << buffer << endl;
// outfile.write((char*)buffer->GetBufferPointer(),sizeof(buffer->GetBufferPointer()));
outfile.close();
cout << "Ouputpath:" << outpath << endl;
}
}
else
{
cout << "No Inputfile" << endl;
}
getchar();
return 0;
}



Thanks

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!