D3D12: Fix swapchains after 921fb5e1cef

The Swapchain::Configure was changed to not require an initial usage
anymore. Previously the code was doing a transition to this usage
causing the code to now transition to <uninitialized data> usage.
Fix this by deleting code. Also make TextureD3D12 responsible for the
transition to PRESENT.
This commit is contained in:
Corentin Wallez 2018-02-06 09:53:08 -05:00 committed by Corentin Wallez
parent eba7c027f9
commit 099656dc7a
3 changed files with 3 additions and 34 deletions

View File

@ -62,22 +62,11 @@ namespace backend { namespace d3d12 {
backendDevice->NextSerial(); backendDevice->NextSerial();
} }
void ExecuteCommandLists(nxtDevice device,
std::initializer_list<ID3D12CommandList*> commandLists) {
Device* backendDevice = reinterpret_cast<Device*>(device);
backendDevice->ExecuteCommandLists(commandLists);
}
void WaitForSerial(nxtDevice device, uint64_t serial) { void WaitForSerial(nxtDevice device, uint64_t serial) {
Device* backendDevice = reinterpret_cast<Device*>(device); Device* backendDevice = reinterpret_cast<Device*>(device);
backendDevice->WaitForSerial(serial); backendDevice->WaitForSerial(serial);
} }
void OpenCommandList(nxtDevice device, ComPtr<ID3D12GraphicsCommandList>* commandList) {
Device* backendDevice = reinterpret_cast<Device*>(device);
return backendDevice->OpenCommandList(commandList);
}
void ASSERT_SUCCESS(HRESULT hr) { void ASSERT_SUCCESS(HRESULT hr) {
ASSERT(SUCCEEDED(hr)); ASSERT(SUCCEEDED(hr));
} }

View File

@ -44,6 +44,9 @@ namespace backend { namespace d3d12 {
resourceState |= D3D12_RESOURCE_STATE_RENDER_TARGET; resourceState |= D3D12_RESOURCE_STATE_RENDER_TARGET;
} }
} }
if (usage & nxt::TextureUsageBit::Present) {
resourceState |= D3D12_RESOURCE_STATE_PRESENT;
}
return resourceState; return resourceState;
} }

View File

@ -37,10 +37,7 @@ namespace backend { namespace d3d12 {
ComPtr<ID3D12CommandQueue> GetCommandQueue(nxtDevice device); ComPtr<ID3D12CommandQueue> GetCommandQueue(nxtDevice device);
uint64_t GetSerial(const nxtDevice device); uint64_t GetSerial(const nxtDevice device);
void NextSerial(nxtDevice device); void NextSerial(nxtDevice device);
void ExecuteCommandLists(nxtDevice device,
std::initializer_list<ID3D12CommandList*> commandLists);
void WaitForSerial(nxtDevice device, uint64_t serial); void WaitForSerial(nxtDevice device, uint64_t serial);
void OpenCommandList(nxtDevice device, ComPtr<ID3D12GraphicsCommandList>* commandList);
}} // namespace backend::d3d12 }} // namespace backend::d3d12
namespace utils { namespace utils {
@ -188,24 +185,6 @@ namespace utils {
ASSERT_SUCCESS(mSwapChain->Present(1, 0)); ASSERT_SUCCESS(mSwapChain->Present(1, 0));
// Transition last frame's render target back to being a render target
if (mRenderTargetResourceState != D3D12_RESOURCE_STATE_PRESENT) {
ComPtr<ID3D12GraphicsCommandList> commandList = {};
backend::d3d12::OpenCommandList(mBackendDevice, &commandList);
D3D12_RESOURCE_BARRIER resourceBarrier;
resourceBarrier.Transition.pResource =
mRenderTargetResources[mPreviousRenderTargetIndex].Get();
resourceBarrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
resourceBarrier.Transition.StateAfter = mRenderTargetResourceState;
resourceBarrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
resourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
commandList->ResourceBarrier(1, &resourceBarrier);
ASSERT_SUCCESS(commandList->Close());
backend::d3d12::ExecuteCommandLists(mBackendDevice, {commandList.Get()});
}
backend::d3d12::NextSerial(mBackendDevice); backend::d3d12::NextSerial(mBackendDevice);
mPreviousRenderTargetIndex = mRenderTargetIndex; mPreviousRenderTargetIndex = mRenderTargetIndex;
@ -240,8 +219,6 @@ namespace utils {
uint32_t mRenderTargetIndex = 0; uint32_t mRenderTargetIndex = 0;
uint32_t mPreviousRenderTargetIndex = 0; uint32_t mPreviousRenderTargetIndex = 0;
uint64_t mLastSerialRenderTargetWasUsed[kFrameCount] = {}; uint64_t mLastSerialRenderTargetWasUsed[kFrameCount] = {};
D3D12_RESOURCE_STATES mRenderTargetResourceState;
}; };
class D3D12Binding : public BackendBinding { class D3D12Binding : public BackendBinding {