Skip to main content
GameDev.net gamedev.net
🔒 Locked

[D3D12] Barriers are really necessary?

Started by Shigeo.K Mar 15, 2017 at 12:53 AM 7 replies 7.1k views
Original Post
Shigeo.K
Shigeo.K

Hi.

I am learning the barrier stuff now.

I got a simple question.

I understood the theory of the barrier.

But my D3D12 program(and MS sample program too) run fine WITHOUT barrier commands.

It seems like D3D12 driver doesn't care about barriers.

why D3D12 works fine without barriers?

Following code ,of course, works fine.


g_pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(g_pRenderTargets[g_FrameIndex], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

(Draw operations)

g_pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(g_pRenderTargets[g_FrameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

And bellow works fine TOO (barrier commands are commented out).


//g_pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(g_pRenderTargets[g_FrameIndex], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

(Draw operations)

//g_pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(g_pRenderTargets[g_FrameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

why?

galop1n
galop1n

You are in the world of undefined behaviors if you do not use proper barriers. The result may vary per GPU/driver/captain age !

For example, transition from render target to texture and vice versa are super important as they usually involve cache flush and possible surface decompression or fast clear elimination.

If you do not want to deal with barrier, use DX11, it is probable that DX12 is not for you anyway. It targets AAA games that are pushing the limit of what the driver/api can achieve, or it targets application that need a specific feature not accessible in DX11, like bindless resources or conservative rendering !

Shigeo.K
Shigeo.K

I did not mean I do not want to deal with barriers. Actually, opposite(That's why I post this thread).



You are in the world of undefined behaviors if you do not use proper barriers.

Yes this is what I thought.



, transition from render target to texture and vice versa are super important

Following your advice, I will test some texture transition, and see what happen if I don't put barrier commands.

Thanks.

AAA games, I agree in some ways.

But there is a developer like me who want to get maximum performance for his game. not only enormous budget games.

You might need to know that.

MJP
MJP

Any particular piece of hardware is almost certainly going to have barriers that it doesn't care about. The barrier API is meant to be a superset of possible barrier operations for all hardware, and is probably meant to be forward-looking as well. So even if the hardware you're testing on doesn't care about a particular barrier, it doesn't mean that you can get away with omitting it on all hardware.

I would recommend that you turn on the validation layer, and fix all of the errors and warnings that it brings up. Otherwise you're heading down the path of rare synchronization artifacts that only show up on a particular GPU or driver revision.

galop1n
galop1n

But there is a developer like me who want to get maximum performance for his game. not only enormous budget games.

You might need to know that.

This is a miss-conception, yes, in some case you can get better performance than DX11, but unless you have a crazy load on your cpu and gpu, the chance you will see a marginal difference are quite low plus you put in balance months of complex development and intense hardcore low level debugging. That has a price !

I do not know your game, but many smaller production can run easily at >100fps if properly done even on moderate hardware with dx11 and DX12 is mostly a CPU improvement API to start with, while modest production usually hit the GPU bottleneck faster. On the GPU, you are looking for the quarter or half millisecond of implicit barriers in dx11 that could be avoid on dx12 on your GPU, or at best 1 or 2ms ( as observe on console renderer ) is you do a great use of async compute. Let me tell you, async compute is not the miraculous things AMD try to sell you,

Infinisearch
Infinisearch

Shigeo.K out of curiosity what video card are you doing this on?

Also is it possible the driver is putting the barrier in for him? I know its not supposed to for the sake of thinness but I was wondering.

-potential energy is easily made kinetic-
Shigeo.K
Shigeo.K



what video card are you doing this on?

I am using a very common hardware, GeForce GTX 1070(driver version 21.21.13.7653 2016.12.29) and Core i7 6700K.

I have examined texture transition without putting barriers.

Still D3D12 works fine.

Maybe we will need barriers in the near future. Not now.

Of course, we can't disrespect for the barrier. Barrier is exist because D3D12 want us to use it, obviously.

I just a little surprised that I can do almost everything WITHOUT barriers for now(on my hardware).



is it possible the driver is putting the barrier in for him?

Sorry I can't understand what this means.



This is a miss-conception, yes, in some case

I think I am some kind of peculiar developer.

I am 1 man developer, and I have passed steam greenlight, my game is in the steam store.



a crazy load on your cpu and gpu

My game is the game which has a crazy load on the cpu and the gpu.



rare synchronization artifacts that only show up on a particular GPU or driver revision.

Yes, it seems so. That what I was thinking.

Anyway, thanks to you guys, I could get a great confidence.

Thank you.

galop1n
galop1n

What is that game ?

Example of transition that are really necessary :

RTV to SRV : Fast clear elimination and Color ROP cache flush because texture will use L2 cache. Same things if it is to PRESENT state

DSV to SRV : Depth decompression ( too bad, we do not have access to the ZTile data on PC :( )

UAV to SRV : Some cache need to be flushed or you may read outdated incorrect value

UAV to UAV : Not a transition barrier but it is needed to serialize two draw?dispatch or they may overlap. If there is no dependency, it is great and not needed, if there was and the barrier missing, well, it is hazard factory. Some cache flush will happen two for the same reason as uav to srv

To Indirect buffer argument : This one need even more flush than normal or your indirect draws won't see the proper value.

From copy dest to something : Obviously to wait for the copy to be complete.

Aliasing transition : Probably no work, but the barrier has a requirement to issue a clear that imply work.

That are the major chances of real work on transitions. Anyway, because you care, you run with the debug layer and gpu based validation, so even if the barriers where not useful, you do not want thousands of warning a frame to still see the real errors :)

Shigeo.K
Shigeo.K
What is that game ?

http://store.steampowered.com/app/418050/?snr=1_7_7_151_150_1

I don't come here to advertise my game. So do not buy from the above link :P

Example of transition that are really necessary :

Of course they are.

Needless to say, we need transitions.

But I don't need barriers (on my hardware, for now, on my simple examinations).

I just want to make it clear that I do not say I do not need a transition itself.

On my PC, program works fine without barriers, but I know I need barriers for many reasons.

Topic Locked

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

Sign in to reply to this topic.