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

Present() without actually presenting..

11 posts in this topic

In my understanding, the only way to be sure that the GPU has finished all his jobs, is to call Present().
Present will stall until everything gets done.

Anyway, when you call Present(), the current backbuffer is flipped to frontbuffer showing whatever you've draw onto it.
What if I don't want to show anything?
Or better, what if I want to let the current fontbuffer unchanged (ie: don't want the flip to occur) ?

For example, let's say I need to fill a texture. I can do it by using a rendertarget and doing some gpu works on it.
Now I want to wait (or to be notified when..) until the job on the rendertarget has finished so that I can use it for something else.

Is there any way to do this?
0

Share this post


Link to post
Share on other sites
You shouldn't have to worry about it - the driver will internally block when you try to use the rendertarget (E.g. if you LockRect() it or something), and wait for previous rendering to complete.
0

Share this post


Link to post
Share on other sites
If you [i]need[/i] to explicitly flush the command buffer to the GPU and then wait for it to idle, you can submit a query and retrieve it's result using [font=courier new,courier,monospace]IDirect3DQuery9::GetData(D3DGETDATA_FLUSH)[/font] ([i]in the docs, see "Accurately Profiling Direct3D API Calls (Direct3D 9)" and "Queries (Direct3D 9)"[/i]).

[b]However[/b], if "use it for something else" is more GPU work, you don't have to do anything at all - it will work as expected.
Also, if you just want to read the texture back to the CPU, then simply lock the texture - the driver won't let the lock complete until the previously issued commands affecting the texture have been completed.
1

Share this post


Link to post
Share on other sites
Thank you for answers.
LockRect() could be an option to be sure that GPU has finished his works, but what I'm trying to do is a bit more complex.

I've a thread that will BeginScene() -> Do GPU Jobs -> EndScene() -> Present as soon as there are some GPU jobs scheduled.
(BTW: this is hypotetical, I'm just trying to figure it out).

Suppose I want to render the main game scene only every 16ms (60fps).
The idea is that at time=0 I submit a GPU job that will render the scene and present it to frontbuffer.
Then, the GPU will do nothing for the next 16ms until, at time=16ms, I will submit another GPU job.
This will go on forever.

Now, if during the "idle" time I need to submit another GPU job (ie: render to a texture), the problem I'm facing is that the main thread will BeginScene() -> do job -> EndScene() and, finaly, Present().
The last Present() will actually present a "not rendered" backbuffer, while I'd like to let the current frontbuffer untouched.
0

Share this post


Link to post
Share on other sites
The fact that you've mentioned using a D3D9 device from two different threads is a huge red flag ([i]D3D9 is not designed to be used by any thread other than the one that created your window[/i]) -- why do you need two different threads to be able to control the device?

Why can't you do your RTT in the same begin/end/present bundle?
[left]i.e [font=courier new,courier,monospace]BeginScene -> RTT -> Main GPU Jobs -> EndScene -> Present[/font][/left]


As a side note, the GPU is allowed to lag behind the CPU by an arbitrary amount of time. When you issue some D3D commands, the GPU might not start working on them until, say 30ms later. If you're trying to keep the CPU and GPU tightly in sync, then you'll end up causing a lot of stalls as you continually wait for these latencies.
Usually the GPU is one frame behind, so when you're submitting the commands for frame #2, the GPU is just starting to execute the commands from frame #1. So, Present doesn't really guarantee that the GPU has finished all of it's commands at all, all it does is submit a command to the GPU ([i]which will be executed in the future, e.g. with a 1-frame delay[/i]) telling it to display the results of it's most recently-completed frame. If the CPU is running faster than the GPU and is getting too far ahead, then Present will stall, to avoid getting into a situation where you've buffered up 100 frames worth of commands, etc...
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1328883602' post='4911669']
Why can't you do your RTT in the same begin/end/present bundle?
i.e BeginScene -> RTT -> Main GPU Jobs -> EndScene -> Present
[/quote]
Main GPU Jobs is unkwnown at the moment. It has been drawn 16 ms ago, so when Present() will end, what will it present? It will present the current backbuffer which should be "dirty" because during this BeginScene() / EndScene() I didn't write anything on it, while I'd like to keep the current frontbuffer untouched (ie: still show the result from the previous BeginScene() / EndScene() / Present())


[quote name='Hodgman' timestamp='1328883602' post='4911669']
Also, the fact that you've mentioned using a D3D9 device from two different threads is a dangerous sign -- why do you need two different threads to be able to control the device?
[/quote]


I've simplified a bit the whole thing, but I'm not accessing D3D from multiple threads. Only main thread directly access D3D.
Other threads sends commands to a queue and then the main thread will execute them.
You should figure it this way: there is a PC somewhere in the world that can render things using DX9.
There's another PC in the world that communicate with the first one and ask for jobs to be done and then read back the results.
Don't think about threads, this is not the point.
0

Share this post


Link to post
Share on other sites
Ok, the logic I was using was that you've got this:
[font=courier new,courier,monospace]BeginScene -> Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT -> EndScene -> Present[/font]
But you don't want the last present to occur:
[font=courier new,courier,monospace]BeginScene -> Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT -> EndScene[/font]
Which lets you simplify it to this:
[font=courier new,courier,monospace]Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT[/font]
Which is the same as this:
[font=courier new,courier,monospace]BeginScene -> RTT -> Main GPU Jobs -> EndScene -> Present[/font]
[quote name='Giallanon' timestamp='1328884077' post='4911673']You should figure it this way: there is a PC somewhere in the world that can render things using DX9.
There's another PC in the world that communicate with the first one and ask for jobs to be done and then read back the results.[/quote]Do you need to download the results of the jobs before you can begin the next "Main render job"? Or are the "main render job" and the "during idle" jobs independent of each other?
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1328884614' post='4911675']
Do you need to download the results of the jobs before you can begin the next "Main render job"? Or are the "main render job" and the "during idle" jobs independent of each other?
[/quote]
The idea is to have "Main job" and "Idle jobs" totally indipendent from each other.
Also there should not be a real difference between "main job" and "idle job" (from the GPU point of view) apart from the fact that "main job" wants to Present() the result to the frontbuffer while "idle job" doesn't

[quote name='Hodgman' timestamp='1328884614' post='4911675']
Ok, the logic I was using was that you've got this:
BeginScene -> Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT -> EndScene -> Present
But you don't want the last present to occur:
BeginScene -> Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT -> EndScene
Which lets you simplify it to this:
Main GPU Jobs -> EndScene -> Present -> BeginScene -> RTT
Which is the same as this:
BeginScene -> RTT -> Main GPU Jobs -> EndScene -> Present
[/quote]
Yes, this could be true if "main job" and "idle job" were always both queued for scheduling, but this is not always the case.
I'm not sending the "main gpu job" every frame, I'm sending it every now and then.
Using big numbers just to be clear, let's say I send a "main gpu job" every 10 seconds; GPU receive it and display it using Present().
For the next 10 seconds, the front buffer should never change, it must display the result from the last "main job" BUT, I could send "idle jobs" to be executed and I don't want to wait the next "main job" before they get exectued.
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1328888420' post='4911692']
So just don't call Present unless a main job has been submitted?
[/quote]
I remember I read something about DX9 doesn't like multiple BeginScene() / EndScene() without a Present in the middle.
Also (but this is a minor issue that can be solved with a LockRect as stated in the 2nd post) without calling Present() you can't be sure that after EndScene() the GPU will flush the pipeline and actually do its job
0

Share this post


Link to post
Share on other sites
[quote name='Giallanon' timestamp='1328886699' post='4911684']Yes, this could be true if "main job" and "idle job" were always both queued for scheduling, but this is not always the case.
I'm not sending the "main gpu job" every frame, I'm sending it every now and then.
Using big numbers just to be clear, let's say I send a "main gpu job" every 10 seconds; GPU receive it and display it using Present().[/quote]I still don't see why you can't put both jobs into the same begin/end scene pair, like:[code]void main()
{
beginScene();
while(!quit)
{
if( maybe1 )
doIdleJob();
if( maybe2 )
{
doMainJob();
endScene();
present();
beginScene();
}
}
endScene();
}[/code]
[quote name='Giallanon' timestamp='1328888672' post='4911694']
Also (but this is a minor issue that can be solved with a LockRect as stated in the 2nd post) without calling Present() you can't be sure that after EndScene() the GPU will flush the pipeline and actually do its job[/quote]Why do you need to manually flush the pipeline and ensure that the GPU has completed it's job? That detail is automatically managed -- the job will be completed before you use it's results. If you don't use it's results, you can't be sure it's completed yet, but you don't need to be sure because you're not using the results...
0

Share this post


Link to post
Share on other sites
Yes, I think you're right. I just have to beginscene() and let it open until someone want to present something to the screen. When this happen just endscene() and present(). Thank you for helping
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