• 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
Endemoniada

Compile HLSL at Runtime ?

9 posts in this topic

Hi guys,

 

Today I switched from D3D9 to D3D10. I'm having a problem compiling my HLSL effects. I don't want to use any D3DX functions since they are deprecated. I thought I would use D3DCompile() but it can't find ID3D10BLOB.

 

Since I'm using Win8 all I do is #include <d3d10.h> and <d3dcompiler.h>, I don't set any library files and let it use the Windows SDK.

 

I tried adding #include <D3DCommon.h> but it still can't find ID3D10BLOB.

 

Maybe I shouldn't even be using D3DCompile() ? What do you think ?

 

0

Share this post


Link to post
Share on other sites

Win 8 + C# here. From what I know W8 store apps can't use the Effect framework. There could be the same limitation if you are building a W8 app. If you plan to ultimately submit the app to the store then there's no other way, effects have to be compiled offline. You just load the bytecode and set the constants buffer without using any kind of reflection.

0

Share this post


Link to post
Share on other sites

I was able to get D3DCompile() and ID3D10Blob to be recognized. I build a new project from scratch and it magically worked.

 

The thing I don't get is that I have to specify d3d10.lib or else it won't resolve D3D10CreateDeviceAndSwapChain() and also d3dcompiler.lib, I can understand having to manually add d3dcompiler.lib but shouldn't D3D10CreateDeviceAndSwapChain() be in the Windows 8 SDK along with all the other D3D10 stuff ?

 

Thanks.

Edited by Endemoniada
0

Share this post


Link to post
Share on other sites

http://msdn.microsoft.com/en-us/library/windows/desktop/bb173551(v=vs.85).aspx

 

Is probably what you're looking for.  Just give it the raw compiled pixel shader code.  fxc.exe usually compiles to .cso files so you can just load them into ram and feed it directly into the function.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509703(v=vs.85).aspx

 

That goes into more detail.

Edited by Ryan_001
2

Share this post


Link to post
Share on other sites

I almost got it to work. Under D3D10CompileShader() it says "Use D3DX10CompileFromMemory instead of this function." and since I'm not using the deprecated D3DX functions I'm using D3DCompile().

char* source=
"float4 vshader(float4 Pos : POSITION) : SV_POSITION"
"{"
"return Pos;"
"}";
 
ID3D10Blob* blob=NULL;
 
hResult=D3DCompile(source,strlen(source),NULL,NULL,NULL,"vshader","vs_3_0",0,0,&blob,NULL);
 
// so far so good
 
ID3D10VertexShader* vertex_shader=NULL;
 
hResult=d3d_device->CreateVertexShader((DWORD*)blob->GetBufferPointer(),blob->GetBufferSize(),&vertex_shader);
 
// fail: E_INVALIDARG

Here is the funny part (regarding the call to CreateVertexShader): "Since you had to successfully compile the shader first, this call will almost certainly pass, unless you have a memory problem on your machine."

 

What am I doing wrong ? Thanks.

 

*EDIT* Yay, I got it to work, vs_3_0 was causing the error, I changed it to vs_4_0 and it's fine now.

Edited by Endemoniada
0

Share this post


Link to post
Share on other sites

It was from SV_POSITION. It used to be VPOS in D3D9.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#VPOS

 

Also I recommend using visual studio 2012 and compiling offline. My solution used to take 15 seconds to load because it compiled the shaders at run-time. I didn't have that many shaders. I switched to offline compiling and the screen comes up in under a second. It's huge for productivity. And according to some guy I'm not going to cite there's no real advantage to compiling at run-time since it increases loading by so much.

2

Share this post


Link to post
Share on other sites

menohack, I just realized that offline is better. How are you getting your compiled shaders into your program ? I found D3D10CreateEffectFromMemory() but I can't get a triangle on the screen with it and I don't want to use the Effects framework anyway. I'm having a little problem understanding how to pass my shader into CreateVertexShader() as well.

 

Thanks.

0

Share this post


Link to post
Share on other sites

D3DReadFileToBlob loads from a file to a ID3DBlob, but it looks like it is only available for D3D11. I don't know if you can just fopen and fread the .cso file, but you can definitely compile at run-time the first time and just write the blob to a file. Then the next time your program runs you can just fopen the compiled file.

 

If you have to go with the second way then you can still have visual studio compile your shaders to make sure they are correct at build-time. You just won't actually use the object files that it produces.

0

Share this post


Link to post
Share on other sites

I set Visual Studio to compile each shader into a header in my home project. I suppose it's better to have files if you are going to unload / swap them, but I'm not working on something where that is a concern. With a shader in a header, you just pass the array directly into the CreateVertexShader function.

0

Share this post


Link to post
Share on other sites

D3DReadFileToBlob loads from a file to a ID3DBlob, but it looks like it is only available for D3D11. I don't know if you can just fopen and fread the .cso file, but you can definitely compile at run-time the first time and just write the blob to a file. Then the next time your program runs you can just fopen the compiled file.

 

If you have to go with the second way then you can still have visual studio compile your shaders to make sure they are correct at build-time. You just won't actually use the object files that it produces.

 

I just pass the raw file data to it and skip the ID3DBlob.  I load the .cso file into a std::vector<char>, and then pass that via data() and size() to the create shader function.  The blob way is a bit more direct, I'd just thought I'd mention my approach to show that it can be done.

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