| 827 | } |
| 828 | |
| 829 | void GPUDeviceDX11::Dispose() |
| 830 | { |
| 831 | GPUDeviceLock lock(this); |
| 832 | |
| 833 | // Check if has been disposed already |
| 834 | if (_state == DeviceState::Disposed) |
| 835 | return; |
| 836 | |
| 837 | // Set current state |
| 838 | _state = DeviceState::Disposing; |
| 839 | |
| 840 | // Wait for rendering end |
| 841 | WaitForGPU(); |
| 842 | |
| 843 | // Pre dispose |
| 844 | preDispose(); |
| 845 | |
| 846 | // Clear device resources |
| 847 | SAFE_RELEASE(_samplerLinearClamp); |
| 848 | SAFE_RELEASE(_samplerPointClamp); |
| 849 | SAFE_RELEASE(_samplerLinearWrap); |
| 850 | SAFE_RELEASE(_samplerPointWrap); |
| 851 | SAFE_RELEASE(_samplerShadow); |
| 852 | SAFE_RELEASE(_samplerShadowLinear); |
| 853 | for (auto i = BlendStates.Begin(); i.IsNotEnd(); ++i) |
| 854 | i->Value->Release(); |
| 855 | for (auto i = DepthStencilStates.Begin(); i.IsNotEnd(); ++i) |
| 856 | i->Value->Release(); |
| 857 | BlendStates.Clear(); |
| 858 | for (uint32 i = 0; i < ARRAY_COUNT(RasterizerStates); i++) |
| 859 | { |
| 860 | SAFE_RELEASE(RasterizerStates[i]); |
| 861 | } |
| 862 | for (auto& query : _queries) |
| 863 | query.Release(); |
| 864 | _queries.Clear(); |
| 865 | for (auto& e : _readyQueries) |
| 866 | e.Clear(); |
| 867 | |
| 868 | // Clear DirectX stuff |
| 869 | SAFE_DELETE(_mainContext); |
| 870 | SAFE_DELETE(_adapter); |
| 871 | SAFE_RELEASE(_imContext); |
| 872 | #if GPU_ENABLE_DIAGNOSTICS && 0 |
| 873 | ID3D11Debug* debugLayer = nullptr; |
| 874 | _device->QueryInterface(IID_PPV_ARGS(&debugLayer)); |
| 875 | if (debugLayer) |
| 876 | { |
| 877 | // Report any DirectX object leaks |
| 878 | debugLayer->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL | D3D11_RLDO_IGNORE_INTERNAL); |
| 879 | debugLayer->Release(); |
| 880 | } |
| 881 | #endif |
| 882 | SAFE_RELEASE(_device); |
| 883 | SAFE_RELEASE(_factoryDXGI); |
| 884 | |
| 885 | // Base |
| 886 | GPUDeviceDX::Dispose(); |