{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/70","labels_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/70/comments","events_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/70/events","html_url":"https://github.com/Microsoft/DirectX-Graphics-Samples/issues/70","id":120870995,"number":70,"title":"Device removal has been triggered","user":{"login":"jpvanoosten","id":1395769,"avatar_url":"https://avatars.githubusercontent.com/u/1395769?v=3","gravatar_id":"","url":"https://api.github.com/users/jpvanoosten","html_url":"https://github.com/jpvanoosten","followers_url":"https://api.github.com/users/jpvanoosten/followers","following_url":"https://api.github.com/users/jpvanoosten/following{/other_user}","gists_url":"https://api.github.com/users/jpvanoosten/gists{/gist_id}","starred_url":"https://api.github.com/users/jpvanoosten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpvanoosten/subscriptions","organizations_url":"https://api.github.com/users/jpvanoosten/orgs","repos_url":"https://api.github.com/users/jpvanoosten/repos","events_url":"https://api.github.com/users/jpvanoosten/events{/privacy}","received_events_url":"https://api.github.com/users/jpvanoosten/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-07T21:23:38Z","updated_at":"2015-12-08T18:30:20Z","closed_at":"2015-12-08T10:40:42Z","body":"I'm using MiniEngine core library to create a DX12 experiment for my master thesis.\r\n\r\nIn my experiment, I am creating a StructuredBuffer for the dynamic lights in the scene. I want to be able to resize the StructuredBuffer if I add lights (or reduce the StructuredBuffer if I remove lights). In my implementation of the IGameApp class, I override the Update function and in that function the light buffer will be resized if the user presses a key on the keyboard. To resize the buffer, the `GpuBuffer::Create` method is used on the StructuredBuffer object. The StructuredBuffer object is not destroyed, only the Create method is used to recreate the buffer resource.\r\n\r\nThe problem is that (seemingly randomly but is more easily reproducible with larger buffers) a device removal is triggered:\r\n```\r\nD3D12: Removing Device.\r\nD3D12 ERROR: ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). [ EXECUTION ERROR #232: DEVICE_REMOVAL_PROCESS_AT_FAULT]\r\nD3D12: **BREAK** enabled for the previous message, which was: [ ERROR EXECUTION #232: DEVICE_REMOVAL_PROCESS_AT_FAULT ]\r\n```\r\nThe error occurs 100% in the `CommandListManager::ExecuteCommandList` method when the `m_CommandQueue->ExecuteCommandLists` gets invoked.\r\n\r\nThe size of the StructuredBuffer doesn't seem to matter. It happens if I only have 10 lights (1 KB) or 32 lights (3.5 KB) but the more lights, the more likely the timeout will occur. I suspect it's a threading issue as device removal should not occur when uploading only a few KB to a structured buffer.\r\n\r\nAny ideas?\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/comments/162971413","html_url":"https://github.com/Microsoft/DirectX-Graphics-Samples/issues/70#issuecomment-162971413","issue_url":"https://api.github.com/repos/Microsoft/DirectX-Graphics-Samples/issues/70","id":162971413,"user":{"login":"stanard","id":7883299,"avatar_url":"https://avatars.githubusercontent.com/u/7883299?v=3","gravatar_id":"","url":"https://api.github.com/users/stanard","html_url":"https://github.com/stanard","followers_url":"https://api.github.com/users/stanard/followers","following_url":"https://api.github.com/users/stanard/following{/other_user}","gists_url":"https://api.github.com/users/stanard/gists{/gist_id}","starred_url":"https://api.github.com/users/stanard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stanard/subscriptions","organizations_url":"https://api.github.com/users/stanard/orgs","repos_url":"https://api.github.com/users/stanard/repos","events_url":"https://api.github.com/users/stanard/events{/privacy}","received_events_url":"https://api.github.com/users/stanard/received_events","type":"User","site_admin":false},"created_at":"2015-12-08T18:30:20Z","updated_at":"2015-12-08T18:30:20Z","body":"Idling the GPU is a non-optimal solution.  You don't want to do it every frame, and if you are creating multiple resources, you wouldn't need to keep idling the GPU.  It's really only in the Destroy() method that you need the idle, as new resources won't have been referenced by the GPU yet.\r\n\r\nI think a better solution for you is to use the LinearAllocator class.  If the size of your buffer varies each frame, you can allocate just what you need each time.  You could have a variable number of buffers of different sizes each frame, and the memory gets recycled automatically.  But they are associated with a command context so that they can query whether its fence has transpired and it's safe to reclaim.  (Note that all you need is a GPU virtual pointer to read and write a StructuredBuffer so long as you use root entries to bind it to your shader.)\r\n\r\nIf you are only changing the size once per frame, a double or triple buffer scheme would possibly be the simplest approach to guarantee safety."}}