Skip to main content
gamedev.net
🔒 Locked

ID3DXInclude Issue

Started by Mindowindow 1 reply 2.5k views
Original Post
Mindowindow
Mindowindow
I'm setting up an resource loading system and have run into some bizarre issues with the ID3DXEffect and ID3DXInclude interfaces. Essentially, my setup is that an App says LoadEffect(string filename) and the engine does the following: 1. It checks the App's local effect folder and searches for filename. If it finds it, it will load the effect with D3DXCreateEffectFromFile. 2. If not it will search for the file in a custom resource file provided by the App, and will load the effect from system memory using D3DXCreateEffect. 3. If the engine still can't find the file then a default effect, embedded in the engine dll as a resource, will be loaded with D3DXCreateEffectFromResource. Now for this process I pass a ID3DXInclude interface into all the CreateEffect*** functions, which essentially impliments the same type of search for effect include files (except that it looks at the D3DXINCLUDE_TYPE specification, and no default include is made available). Now the include interface works great for the fallback D3DXCreateEffectFromResource method. I pass in a non-existant filename and the default effect loads fine (with its include dependencies). However, the D3DXCreateEffectFromFile method is doing some strange things (if I pass in a valid filename and it attempts to load the effect from disk two things happen that do not seem like they should): 1. First, D3DXCreateEffectFromFile seems to be trying to use the ID3DXInclude interface to load the actual effect file into memory...which would work fine...but... 2. It tries to load it twice...(I set a debugger break point at the beginning of my ID3DXInclude::Open definition and it breaks twice with the filename I passed in originally...not any include file)...and there is a compile error before I can see if it is going to load the "real" include dependencies: assets\metamaterials\sim.fx(1): error X3000: syntax error: unexpected end of file There is nothing wrong with the file since it is the same as the embedded default resource that compiles fine. If I pass a NULL ID3DXInclude interface to the D3DXCreateEffectFromFile function (and place the include files in the folder with the effect) everything works, but this is not desired to be a requirement. This seems like some bizarre behavior to me, I've scoured the DX docs for some info on the compile error and more details on ID3DXInclude but I found nothing. Any ideas?
Namethatnobodyelsetook
Namethatnobodyelsetook
I've seen this too, but it caused no problems. I end up finding, allocating memory for, and loading the effect twice. Because it calls your include call to load the FX file, you could call the CreateEffectFromFile for FX that are in packed data file, embedded in your app, etc, rather than having loose FX files on disk.

I'm not sure why I loads twice, but as long as you properly return the shader source it should be fine.
Mindowindow
Mindowindow
It's good to know that this is at least "somewhat" normal. So is it a bug, or is there a reason DX would load the file into memory twice, wasting time and resources?

Quote:

I'm not sure why I loads twice, but as long as you properly return the shader source it should be fine.


Yeah, that was the problem, I finally found a bug in the code that was loading the file into memory (something quite stupid...i'd set the read pointer to the eof to find out how much memory to allocate...and hadn't put it back to the begining...so of course the file didn't get loaded into the memory buffer, and of course there was an end of file error...there was no file!).

Still, it bugs me that DX loads the file twice, why would it need to do that?

Topic Locked

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

Sign in to reply to this topic.