• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
VanillaSnake21

D3DCreateEffectFromMemory Fails, everything is correct, why?

7 posts in this topic

Hi, I'm trying to use a simple hlsl file in the rendering, so I compile my .fx with the fxc.exe as directed on msdn, it produces a clean object with no errors. I read it into memory using msdn's method, but for some reason this function still comes back with E_FAIL. Here's some of my code:

 

[source]ifstream is(TEXT("DX10RendererEffect.fxo"), ios::binary);
is.seekg(0, ios_base::end);
streampos pos = is.tellg();
is.seekg(0, ios_base::beg);
char * effectBuffer = new char[pos];
is.read(effectBuffer, pos);
HRESULT hr;
if (FAILED(hr = D3D10CreateEffectFromMemory((void*)effectBuffer, pos, 0, softObjPtr->pD3D10Device, NULL, &softObjPtr->pD3D10Effect))){
return;

}[/source]

 

Also, I've created my device using the D3D10DEBUG_DEVICE flag (something like that), but the function doesn't say anything besides E_FAIL, that on msdn says that means the debug layer is not installed.

 

I don't know if this matters but I'm on a fresh in stall of Windows 7 and I just installed Windows 8.1 SDK. It's a hassle because all the D3DX helper functions are removed, so I can't compile from file, and must use a build rule on visual studio to compile my fx files manually. And the D3D sdk is completely merged with Windows SDK, so I can't tell if the debug layer was installed or not, it should have been right? Any suggestions?

0

Share this post


Link to post
Share on other sites

You don’t release effectBuffer on failure, which is a memory leak.

Did you compile the effect with the correct version?
Did you verify that it compiled correctly?
Did you verify that the file exists?
Did you add your program to the debug-layer list of executables and enable debugging of it?


L. Spiro

 

I'm trying to get it to work, so memory leaks are second priority right now. 

Here is my compilation string in the build tool:

 

"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\fxc.exe" /Od /Zi /T fx_4_0 /Fo "C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fxo" "C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fx"

 

this is the end of my .fx file

[source]

technique10 Render
{
pass P0
{
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS()));
}
}
[/source]
So the versions seem to match.
 
When I compile it in VS I get this: 
 
CUSTOMBUILD : warning X4717: Effects deprecated for D3DCompiler_47
1>  
1>  compilation object save succeeded; see C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fxo
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
 
The file does exist and I do check it, I just wrote that little file reading snippet on the fly, my actual function is
 
[source]
int LoadFileToMemory(const wchar_t* szFileName, char** buffer)
{
ifstream inFile(szFileName, ios::binary);
 
if (!inFile.good()) //file not found
return -1;
 
streampos beginPos = inFile.tellg();
inFile.seekg(0, ios::end);
streampos endPos = inFile.tellg();
int size = endPos - beginPos;
 
(*buffer) = new char[size];
inFile.read((*buffer), size);
inFile.close();
 
return size;
}

[/source]

 

I'm not sure how to add the program to the dubug layer though, that might be helpful if it gives me a more elaborate fail string. How exactly do I do that?

0

Share this post


Link to post
Share on other sites

Can you try to retrieve the HRESULT error string?

 

Something like this:
 

void PrintDebugOutput(const LPCWSTR pText, const HRESULT pHr)
{
	OutputDebugString(pText);
	OutputDebugString(DXGetErrorString(pHr));
	OutputDebugString(L", ");
	OutputDebugString(DXGetErrorDescription(pHr));
	OutputDebugString(L"\n");
}
1

Share this post


Link to post
Share on other sites

Can you try to retrieve the HRESULT error string?
 
Something like this:
 

void PrintDebugOutput(const LPCWSTR pText, const HRESULT pHr)
{
	OutputDebugString(pText);
	OutputDebugString(DXGetErrorString(pHr));
	OutputDebugString(L", ");
	OutputDebugString(DXGetErrorDescription(pHr));
	OutputDebugString(L"\n");
}

 
So I get "E_FAIL" out geterrorstring
and "An undetermined error occurred" at the errordescription
 
Another thing is that I installed the wrong SDK originally. I got the windows 8.1 sdk, even though I'm on windows 7. I'm not sure if it's a big deal but just to be safe I uninstalled the windows 8.1 sdk and installed windows 7.1 instead, along with June 2010 DirectX SDK. Otherwise the above function you suggested doesn't even exist as windows 8 merged dx with the os, so you have to use the regular os error reporting function. Anyways with that taken care of, it's the same issue and I STILL can't get DX to spit out debug information. What am I doing wrong??? This is how I create my device:

 

[source]if (FAILED(D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &softObjPtr->D3D10SwapChainDesc, &softObjPtr->pD3D10SwapChain, &softObjPtr->pD3D10Device)))
{
ZeroMemory(&softObjPtr->D3D10SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
return;
}[/source]

 

I also selected the program "SoftwareRasterizer" in my debug folder as the target in the DX Control Panel, should I instead select the VS 2012 executable? 

 

I'm trying to move my direct draw rasterizer to DX10 and this is proving to be quite a hassle, lol.

 

I'm going to try using the old DX functions to compile my effect instead of the FXC and I'll update on how it goes, but I would still appreciate the help in trying to get my debug output to work ))

0

Share this post


Link to post
Share on other sites

OK so rewrote the code with D3DX10CreateEffectFromFile and it seems to work, so I'm thinking something was off about the object created by fxc compiler, judging from another forum where someone had a similar issue it pads the size of the file, but not sure, it was a post from 2008. Thanks for the help.

0

Share this post


Link to post
Share on other sites

If you want to precompile your effects, you first need to use D3DX10CompileFromFile and copy the compiled data using the ID3D10Blob::GetBufferPointer into your output file. You can then use D3D10CreateBlob in your code to create an empty blob the size of your file, and load the compiled data into it. Then simply use D3D10CreateEffectFromMemory and give it the blob pointer and size to load it.

 

Works like a charm even for precompiled shaders that get compiled as resources in dlls or exes.

Edited by Naruto-kun
0

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  
Followers 0