

All subresources must be individually checkedĬonst uint32 numSubresourceStates = _subresourceState.Count() įor (uint32 i = 0 i < numSubresourceStates i++)ĭ3D12_RESOURCE_STATES GetSubresourceState(uint32 subresourceIndex) constĪSSERT(subresourceIndex < static_cast (_subresourceState.Count()))

_resourceState = D3D12_RESOURCE_STATE_CORRUPT īool CheckResourceState(D3D12_RESOURCE_STATES state) const Return _resourceState != D3D12_RESOURCE_STATE_CORRUPT || _subresourceState.HasElements() _subresourceState.Resize(subresourceCount, false) Void Initialize(uint32 subresourceCount, D3D12_RESOURCE_STATES initialState)ĪSSERT(_subresourceState.IsEmpty() & subresourceCount > 0) & ((currentState | targeState) != currentState || targeState = D3D12_RESOURCE_STATE_COMMON) Static bool IsTransitionNeeded(D3D12_RESOURCE_STATES currentState, D3D12_RESOURCE_STATES targeState) : _resourceState(D3D12_RESOURCE_STATE_CORRUPT) The per subresource state (used only if _allSubresourcesSame is 0). In this case, each subresources may have a different state Set to 0 if _subresourceState is valid. In this case, all subresources have the same state The whole resource state (used only if _allSubresourcesSame is 1).ĭ3D12_RESOURCE_STATES _resourceState : 31 #define D3D12_RESOURCE_STATE_CORRUPT (D3D12_RESOURCE_STATES)-1 Custom resource state used to indicate invalid state (usefull for debuging resource tracking issues).
#Control directx 11 or 12 code#
Those help GPU to synchronize work but are a little pain on DirectX 12 because we have to do it manually (DirectX 11 does it on it’s own).īasically here is a sample code which provides resource state tracking with per subresource changes so it helps with barriers errors and strange problems. So in order to prevent data mismatches and race conditions we have to specify resource barriers. Why it’s problematic? Because GPU is all about being asynchronous and multi-threaded. blur/bloom effect or luminance map) you have to sample higher texture mip map and render it to the lower mip map (kind of copy).ĭuring this operation one subresource is in reading state while the other one is in writing state. Looks the same, huh?įor those who also try to implement DirectX 12 I’ve got sample code to help you out with resource barriers and resources state tracking.įor example if you have a texture used for downscaling (eg. Here is sample image comparison on DirectX 11 vs DirectX 12. Probably in a future we will investigate it even more and improve the current implementation because I think DX12 can run faster than DX11. Which is not always resolved in a proper way.
#Control directx 11 or 12 driver#
Why driver code? Because DirectX 12 is very low-level API and many obvious operations from DX11 have to be done manually. This gives a way more power and control over the GPU but does it?įirst of all we’ve successfully implemented both DirectX 11 and DirectX 12 as our graphics backends.īoth are running pretty well but we couldn’t write such a good driver code for DX12 and it’s slower than DX11. Did you hear about DirectX 12? It’s a next graphics API from Microsoft after DirectX 11 which is not a successor but kind of new low-level API.
