Jump to content

  • Log In with Google      Sign In   
  • Create Account

can't load precompiled shaders


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 vpalmer   Members   -  Reputation: 107

Like
1Likes
Like

Posted 04 May 2013 - 11:48 AM

SOLVED! 

//my shader files were wrong compiled (without /E parametr for Entry point), and need to remember to allocate memory for variable to read file content into it with ifstream

I'm trying to learn DX11 programming - by books and tutorials on net. Few days ago I stucked at loading precompiled shaders files and creating shaders with them.With tutorial I wrote program to draw simple triangle and it works fine while i load and compile shaders from 2 .hlsl files with

D3DX11CompileFromFile function. But after i compiled .hlsl files with fxc.exe utility and trying to read them with ifstream, my program crash during runtime (still compiled without warnings).

 

shaderbuf struct for file reading and global vars:

struct shaderbuf
{
	char* pbuf;
	int size;
};

extern shaderbuf vsh;
extern shaderbuf psh;

 

compiled shader files reading function and shader creation:

shaderbuf ReadShader(char* filename)
{
	shaderbuf sb;
	int size;
	std::ifstream ifs;
	
	ifs.open(filename, ifs.in | ifs.binary);
	ifs.seekg(0, ifs.end);
	size = int(ifs.tellg());

	sb.size = size;

	ifs.seekg(0, ifs.beg);
	ifs.read(sb.pbuf, size);
	ifs.close();
	return sb;
}

void InitPipeline()
{
	shaderbuf vsh =	ReadShader("vshader.cso");
	shaderbuf psh = ReadShader("pshader.cso");

	dev->CreateVertexShader(&vsh.pbuf, vsh.size,
							NULL, &pVS);
	dev->CreatePixelShader(&psh.pbuf, psh.size,
							NULL, &pPS);

	
	//set shader objects
	devcon->VSSetShader(pVS, 0, 0);
	devcon->PSSetShader(pPS, 0, 0);

	BufferCreatingAndMapping();
}

 

InputLayout creation (i guess there can be some errors with pointers to Bytecode too):

dev->CreateInputLayout(ied, sizeof(ied)/sizeof(ied[0]),
		       vsh.pbuf, vsh.size,
		       &pLayout);

 

 

Help me pls to find my errors. Need to resolve shader files loading with ifstream.


Edited by vpalmer, 05 May 2013 - 05:44 AM.


Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2716

Like
0Likes
Like

Posted 04 May 2013 - 12:02 PM

You need to allocate some space for data that pbuf will point at.

shaderbuf ReadShader(char* filename)
{
    shaderbuf sb;
    int size;
    std::ifstream ifs;
    
    ifs.open(filename, ifs.in | ifs.binary);
    ifs.seekg(0, ifs.end);
    size = int(ifs.tellg());

    sb.size = size;
 
    // =============================
   sb.pbuf = new char[size];
   // ============================= 

    ifs.seekg(0, ifs.beg);
    ifs.read(sb.pbuf, size);
    ifs.close();
    return sb;
}

Edited by belfegor, 04 May 2013 - 12:04 PM.


#3 vpalmer   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 May 2013 - 12:13 PM

You need to allocate some space for data that pbuf will point at.

shaderbuf ReadShader(char* filename)
{
    shaderbuf sb;
    int size;
    std::ifstream ifs;
    
    ifs.open(filename, ifs.in | ifs.binary);
    ifs.seekg(0, ifs.end);
    size = int(ifs.tellg());

    sb.size = size;
 
    // =============================
   sb.pbuf = new char[size];
   // ============================= 

    ifs.seekg(0, ifs.beg);
    ifs.read(sb.pbuf, size);
    ifs.close();
    return sb;
}

 

i tried this already (and tried now again), but unfortunatly this does not help - program still crashes on runtime.


Edited by vpalmer, 04 May 2013 - 12:13 PM.


#4 belfegor   Crossbones+   -  Reputation: 2716

Like
0Likes
Like

Posted 04 May 2013 - 12:16 PM

Put some breakpoints and run your project with debugger to find out where it crashes.

Also enable d3d debug runtimes to see additional warning/error messages that you might have.

Check all d3d functions that return HRESULT for errors.


Edited by belfegor, 04 May 2013 - 12:18 PM.


#5 vpalmer   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 May 2013 - 05:36 PM

via debugger i found some errors (compiled shader files were in wrong directory). but now i have next problem:

 

dev->CreateVertexShader(vsh.pbuf, vsh.size,NULL, &pVS);

 

returns E_INVALIDARG - what wrong with parameters?


Edited by vpalmer, 04 May 2013 - 05:37 PM.


#6 vpalmer   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 May 2013 - 05:45 AM

solved (read first post of that topic).






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS