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

Speed up shader compilation (HLSL)

34 posts in this topic

Hmm, it was said earlier in this thread that inline assembly is not possible in HLSL shader files.

So, how would I use those precompiled asm code (since the engine I'm using doesn't understand asm files)?
0

Share this post


Link to post
Share on other sites
I'm only talking from 3DS Max experience here, but it works fine with Max' DXSAS compiler. So it's not exactly true that this isn't possible in general.
Have you looked at the example? I can't tell you for sure if it will work in the Xray engine, I don't know what you have tried exactly so far, but it might be worth the try to create a very simple shader and then compile an ASM version to see if the engine will take it.

BTW, I'm curious what you are doing exactly in your shader that is so heavy and improves the quality so drastically?
0

Share this post


Link to post
Share on other sites
[quote name='Xoliul' timestamp='1337705111' post='4942252']
Have you looked at the example? I can't tell you for sure if it will work in the Xray engine, I don't know what you have tried exactly so far, but it might be worth the try to create a very simple shader and then compile an ASM version to see if the engine will take it.[/quote]

Yeah, I have, and it doesn't work. The compiler / engine doesn't seem to recognize the asm { } command that he is using in his example. The compiler seems to think that I wanted to define my own function called "asm", thus exiting with error

error X3064: object literals are not allowed inside functions

I don't know what D3D or compiler version is required to allow such inline asm blocks, or if some special compiler switch / option would need to be activated in order to use it. However I think it's just not possible with the xRay engine I'm running.

[quote name='Xoliul' timestamp='1337705111' post='4942252']
BTW, I'm curious what you are doing exactly in your shader that is so heavy and improves the quality so drastically?
[/quote]

Several different things which are not supported by xRay itself, and which require both lots of texture lookups and complex functions, such as dynamic depth of field (focus blur), adaptive night vision, and dynamic wet surfaces including object reflections - everything done purely in one single pixel shader (with several includes, of course).

For a "causual" windows or web application my code wouldn't be very complex, but for the HLSL compiler it seems to max out the limits... Edited by Meltac
0

Share this post


Link to post
Share on other sites
[quote name='Meltac' timestamp='1337372080' post='4941268']
I tried replacing the used D3DCompiler_43.dll with the Win 8 SDK's d3dcompiler_44.dll (renamed it of course), but it didn't speed up anything at all.

Are there maybe any other files that I need to copy over in order to get the new compiler running without fxc.exe? And does the new compiler even speed up DX9 shaders?
[/quote]

Could anybody give some additional information that might help sorting out why the new compiler doesn't increase compilation speed in my case?

EDIT:
After further investigation, I've found that compilation time depends heavily on the code order. Consider the following example (simplified):
[CODE]
// 1. Do some basic color calculations and store them into the local variable "Color"

// 2. Create fake reflections
#ifdef WET_OBJREFLECT
Color = objreflect(Color, viewspace_P, uv, dist_factor, wind, WET_OBJMAXCOL, WET_OBJMAXREF);
#endif

// 3. Add blur to everything
#ifdef WET_REFBLUR
float contrib=1.h;
float total_blur = amount * WET_REFBLUR; // e_barrier.y * 1000; //1000 * (e_kernel.x-0.4); // --> 0.401
float f=0.f;
float inc=total_blur/WET_REFBLURQUALITY;
float3 sum = 0;
for (int i=0;i<WET_REFBLURQUALITY;i++){sum+=gaussblur(uv,f);contrib++;f+=inc;}
Color.rgb += (sum/contrib) - tex2D(s_image,uv);
#endif
[/CODE]

This version takes nearly 6 seconds to compile, whereas the compilation time is only around 3 seconds if I swap code block 2 and 3 (applying blur BEFORE reflections).

As you can see these two code blocks do not depend directly on each other, both of them just modify the previously calculated Color, like simple process stack. So why compiles that code twice as fast when order is swapped? Edited by Meltac
0

Share this post


Link to post
Share on other sites
[quote name='Meltac' timestamp='1337940590' post='4943190']
As you can see these two code blocks do not depend directly on each other, both of them just modify the previously calculated Color, like simple process stack. So why compiles that code twice as fast when order is swapped?
[/quote]
Assuming that you didn't change color assignment, Part 3 [font=courier new,courier,monospace]"Color.rgb += (sum/contrib) - tex2D(s_image,uv);"[/font] will be override by Part 2 [font=courier new,courier,monospace]"Color = objreflect(Color, viewspace_P, uv, dist_factor, wind, WET_OBJMAXCOL, WET_OBJMAXREF);"[/font], so the compiler won't bother to compile part 3. Check the output of fxc and you will see that part3 was gone.

Again, the only way to have a faster compilation is to simplify your shader by replacing plain texture sampling with their respective grad/ ddx/ddy or calculate the mipmap levels yourself. Edited by xoofx
0

Share this post


Link to post
Share on other sites
Sorry, I don't get you. In Part 2, the previously processed "Color" is passed in as a function parameter "Color", so this shouldn't override anything, but just takes the Color as input and returns a modified Color as output. So why should the compiler omit the previous statements? They are significant to get the final result, and it would be misbehavior of the compiler to exclude them.

Of course, I still have to figure out how to use the grad/ ddx/ddy texture functions to produce the correct result.

However, another discovery I made that the described compilation time differences are only so huge when using fxc. When triggering compilation instead through the d3dx9 library the difference is only about one seconds (instead of 3), but compilation seems to take more time overall in that case (up to ten seconds).

What brings me to another question: Might it be that the default behavior of the compiler is different when using fxc.exe or d3dx9.dll or d3dcompiler.dll directly? Or, in other words, do I need to specify some special compiler options such as shader profiles or switches (in the case of fxc) or function arguments (in the case of triggering compilation through one of the dll's) in order to get the exact same result?

Otherwise I see no reason for these obvious compilation differences...
0

Share this post


Link to post
Share on other sites
oops, my apologize, I missed the Color passed by argument! Better look at the asm why it is optimizing faster. But anyway, I would quickly try to replace all tex2D by tex2Dlod and check how much It will reduce the compilation time. Also, if you are sampling a previous render target/backbuffer to apply some posteffects and that there is no mipmap, it is safe to use tex2Dlod on the mipmap 0 (t.w = 0).

fxc is using both d3dx9_43.dll and D3DCOMPILER_43.dll internally. Do you know the settings STALKER is using to compile your shaders? What profile are you using to compile your shaders? If you are using the same, you shouldn't have any differences.
0

Share this post


Link to post
Share on other sites
Wow, I love tex2Dlod! Now THAT gave the thing a real boost! Thanks for the hint! Btw, does it speed up runtime as well or only compilation?

Now the next step would be find a way to make compilation of loops faster. Here making the [loop] attribute working would be best, don't know why it's not.

I don't know what settings STALKER is using to compile its shaders, nor do I have a clue how to figure that out (there's not much dev-internal information public available). All I know is that the game includes d3dx9_34.dll (not d3dx9_43.dll) which in turn triggers d3dcompiler.dll (don't remember the version) to compile the shaders. I can see the use of the method D3DXCompileShader in the dissambly but don't see what parameters actually are passed. All I know is they are compiling against vs_3_0 and ps_3_0.

Using the latest DX9 binaries (d3dx9_43.dll and the respective d3dcompiler.dll) doesn't seem to change a thing - although I can see the replaced new dll's are being used by the game engine, that doesn't speed up anything nor provide access to newer features such as attributes, strangely. Would enabling attributes require to call some other compiler method instead, or some special settings or something? Edited by Meltac
0

Share this post


Link to post
Share on other sites
tex2Dlod doesn't need to compute the lod (mip-map) level, you pass it in manually, which means that no screen partial derivatives are needed. Things are then easier for both the compiler and run-time. While reading your questions, I gained the impression you needed to sample correct (automatic) mip-map levels, you wouldn't be able to use this instruction otherwise. If you can, use it pretty much "everywhere" :-) Edited by pcmaster
0

Share this post


Link to post
Share on other sites
I didn't have an idea like that before, but since xoofx noted that sampling from a backbuffer wouldn't require tex2D with mipmaps anyway I guess this is what saved my day.

Thanks again everbody! Edited by Meltac
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