From 82acfa6a46120ea28d139fa5fe9db336d766c651 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 10 Nov 2021 15:55:33 -0800 Subject: [PATCH] VideoBackends/D3D: Eliminate CHECK in favor of ASSERT_MSG --- .../Core/VideoBackends/D3D/D3DBoundingBox.cpp | 8 ++++--- .../D3D/D3DNativeVertexFormat.cpp | 3 ++- Source/Core/VideoBackends/D3D/D3DState.cpp | 9 +++---- .../Core/VideoBackends/D3D/D3DSwapChain.cpp | 4 +++- .../VideoBackends/D3D/D3DVertexManager.cpp | 18 +++++++------- Source/Core/VideoBackends/D3D/DXShader.cpp | 8 +++---- Source/Core/VideoBackends/D3D/DXTexture.cpp | 11 +++++---- .../VideoBackends/D3D12/D3D12BoundingBox.cpp | 7 +++--- .../VideoBackends/D3D12/D3D12PerfQuery.cpp | 7 +++--- .../VideoBackends/D3D12/D3D12StreamBuffer.cpp | 4 ++-- .../VideoBackends/D3D12/D3D12SwapChain.cpp | 9 ++++--- .../Core/VideoBackends/D3D12/DX12Context.cpp | 24 ++++++++++--------- .../Core/VideoBackends/D3D12/DX12Shader.cpp | 3 ++- .../Core/VideoBackends/D3D12/DX12Texture.cpp | 8 +++---- .../D3D12/DescriptorAllocator.cpp | 4 +++- .../D3D12/DescriptorHeapManager.cpp | 4 ++-- .../Core/VideoBackends/D3DCommon/D3DCommon.h | 7 ------ 17 files changed, 74 insertions(+), 64 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DBoundingBox.cpp b/Source/Core/VideoBackends/D3D/D3DBoundingBox.cpp index 830ae1f9a4..56ff1ad5b2 100644 --- a/Source/Core/VideoBackends/D3D/D3DBoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D/D3DBoundingBox.cpp @@ -6,8 +6,10 @@ #include #include +#include "Common/Assert.h" #include "Common/CommonTypes.h" #include "Common/MsgHandler.h" + #include "VideoBackends/D3D/D3DState.h" #include "VideoBackends/D3DCommon/D3DCommon.h" @@ -33,7 +35,7 @@ bool D3DBoundingBox::Initialize() data.SysMemSlicePitch = 0; HRESULT hr; hr = D3D::device->CreateBuffer(&desc, &data, &m_buffer); - CHECK(SUCCEEDED(hr), "Create BoundingBox Buffer."); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create BoundingBox Buffer"); if (FAILED(hr)) return false; D3DCommon::SetDebugObjectName(m_buffer.Get(), "BoundingBox Buffer"); @@ -43,7 +45,7 @@ bool D3DBoundingBox::Initialize() desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.BindFlags = 0; hr = D3D::device->CreateBuffer(&desc, nullptr, &m_staging_buffer); - CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer."); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create BoundingBox Staging Buffer"); if (FAILED(hr)) return false; D3DCommon::SetDebugObjectName(m_staging_buffer.Get(), "BoundingBox Staging Buffer"); @@ -56,7 +58,7 @@ bool D3DBoundingBox::Initialize() UAVdesc.Buffer.Flags = 0; UAVdesc.Buffer.NumElements = NUM_BBOX_VALUES; hr = D3D::device->CreateUnorderedAccessView(m_buffer.Get(), &UAVdesc, &m_uav); - CHECK(SUCCEEDED(hr), "Create BoundingBox UAV."); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create BoundingBox UAV"); if (FAILED(hr)) return false; D3DCommon::SetDebugObjectName(m_uav.Get(), "BoundingBox UAV"); diff --git a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp index 8f7d9cad12..76eeef6ec3 100644 --- a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp @@ -3,6 +3,7 @@ #include +#include "Common/Assert.h" #include "Common/EnumMap.h" #include "VideoBackends/D3D/D3DBase.h" @@ -182,7 +183,7 @@ ID3D11InputLayout* D3DVertexFormat::GetInputLayout(const void* vs_bytecode, size HRESULT hr = D3D::device->CreateInputLayout(m_elems.data(), m_num_elems, vs_bytecode, vs_bytecode_size, &layout); - CHECK(SUCCEEDED(hr), "Failed to create input layout"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create input layout"); // This method can be called from multiple threads, so ensure that only one thread sets the // cached input layout pointer. If another thread beats this thread, use the existing layout. diff --git a/Source/Core/VideoBackends/D3D/D3DState.cpp b/Source/Core/VideoBackends/D3D/D3DState.cpp index 7fd103d0bd..a5aa2f863e 100644 --- a/Source/Core/VideoBackends/D3D/D3DState.cpp +++ b/Source/Core/VideoBackends/D3D/D3DState.cpp @@ -6,6 +6,7 @@ #include #include +#include "Common/Assert.h" #include "Common/BitSet.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" @@ -348,7 +349,7 @@ ID3D11SamplerState* StateCache::Get(SamplerState state) ComPtr res; HRESULT hr = D3D::device->CreateSamplerState(&sampdc, res.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Creating D3D sampler state failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating D3D sampler state failed"); return m_sampler.emplace(state, std::move(res)).first->second.Get(); } @@ -425,7 +426,7 @@ ID3D11BlendState* StateCache::Get(BlendingState state) ComPtr res; HRESULT hr = D3D::device->CreateBlendState(&desc, res.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Creating D3D blend state failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating D3D blend state failed"); return m_blend.emplace(state.hex, std::move(res)).first->second.Get(); } @@ -446,7 +447,7 @@ ID3D11RasterizerState* StateCache::Get(RasterizationState state) ComPtr res; HRESULT hr = D3D::device->CreateRasterizerState(&desc, res.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Creating D3D rasterizer state failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating D3D rasterizer state failed"); return m_raster.emplace(state.hex, std::move(res)).first->second.Get(); } @@ -488,7 +489,7 @@ ID3D11DepthStencilState* StateCache::Get(DepthState state) ComPtr res; HRESULT hr = D3D::device->CreateDepthStencilState(&depthdc, res.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Creating D3D depth stencil state failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating D3D depth stencil state failed"); return m_depth.emplace(state.hex, std::move(res)).first->second.Get(); } diff --git a/Source/Core/VideoBackends/D3D/D3DSwapChain.cpp b/Source/Core/VideoBackends/D3D/D3DSwapChain.cpp index 95ed7fdb2a..a79e0e3829 100644 --- a/Source/Core/VideoBackends/D3D/D3DSwapChain.cpp +++ b/Source/Core/VideoBackends/D3D/D3DSwapChain.cpp @@ -3,6 +3,8 @@ #include "VideoBackends/D3D/D3DSwapChain.h" +#include "Common/Assert.h" + #include "VideoBackends/D3D/DXTexture.h" namespace DX11 @@ -29,7 +31,7 @@ bool SwapChain::CreateSwapChainBuffers() { ComPtr texture; HRESULT hr = m_swap_chain->GetBuffer(0, IID_PPV_ARGS(&texture)); - CHECK(SUCCEEDED(hr), "Get swap chain buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to get swap chain buffer"); if (FAILED(hr)) return false; diff --git a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp index c9ef178f73..05d76805c0 100644 --- a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp @@ -34,7 +34,7 @@ static ComPtr AllocateConstantBuffer(u32 size) D3D11_CPU_ACCESS_WRITE); ComPtr cbuf; const HRESULT hr = D3D::device->CreateBuffer(&cbdesc, nullptr, &cbuf); - CHECK(SUCCEEDED(hr), "shader constant buffer (size=%u)", cbsize); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create shader constant buffer (size={})", cbsize); if (FAILED(hr)) return nullptr; @@ -59,8 +59,8 @@ CreateTexelBufferView(ID3D11Buffer* buffer, TexelBufferFormat format, DXGI_FORMA CD3D11_SHADER_RESOURCE_VIEW_DESC srv_desc(buffer, srv_format, 0, VertexManager::TEXEL_STREAM_BUFFER_SIZE / VertexManager::GetTexelBufferElementSize(format)); - CHECK(SUCCEEDED(D3D::device->CreateShaderResourceView(buffer, &srv_desc, &srv)), - "Create SRV for texel buffer"); + HRESULT hr = D3D::device->CreateShaderResourceView(buffer, &srv_desc, &srv); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create SRV for texel buffer"); return srv; } @@ -79,8 +79,8 @@ bool VertexManager::Initialize() for (int i = 0; i < BUFFER_COUNT; i++) { - CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, nullptr, &m_buffers[i])), - "Failed to create buffer."); + HRESULT hr = D3D::device->CreateBuffer(&bufdesc, nullptr, &m_buffers[i]); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create buffer"); if (m_buffers[i]) D3DCommon::SetDebugObjectName(m_buffers[i].Get(), "Buffer of VertexManager"); } @@ -93,8 +93,8 @@ bool VertexManager::Initialize() CD3D11_BUFFER_DESC texel_buf_desc(TEXEL_STREAM_BUFFER_SIZE, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); - CHECK(SUCCEEDED(D3D::device->CreateBuffer(&texel_buf_desc, nullptr, &m_texel_buffer)), - "Creating texel buffer failed"); + HRESULT hr = D3D::device->CreateBuffer(&texel_buf_desc, nullptr, &m_texel_buffer); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating texel buffer failed"); if (!m_texel_buffer) return false; @@ -132,7 +132,7 @@ bool VertexManager::MapTexelBuffer(u32 required_size, D3D11_MAPPED_SUBRESOURCE& { // Restart buffer. HRESULT hr = D3D::context->Map(m_texel_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &sr); - CHECK(SUCCEEDED(hr), "Map texel buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to map texel buffer"); if (FAILED(hr)) return false; @@ -142,7 +142,7 @@ bool VertexManager::MapTexelBuffer(u32 required_size, D3D11_MAPPED_SUBRESOURCE& { // Don't overwrite the earlier-used space. HRESULT hr = D3D::context->Map(m_texel_buffer.Get(), 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &sr); - CHECK(SUCCEEDED(hr), "Map texel buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to map texel buffer"); if (FAILED(hr)) return false; } diff --git a/Source/Core/VideoBackends/D3D/DXShader.cpp b/Source/Core/VideoBackends/D3D/DXShader.cpp index 9f7619ce76..533bb3a2a7 100644 --- a/Source/Core/VideoBackends/D3D/DXShader.cpp +++ b/Source/Core/VideoBackends/D3D/DXShader.cpp @@ -55,7 +55,7 @@ std::unique_ptr DXShader::CreateFromBytecode(ShaderStage stage, Binary { ComPtr vs; HRESULT hr = D3D::device->CreateVertexShader(bytecode.data(), bytecode.size(), nullptr, &vs); - CHECK(SUCCEEDED(hr), "Create vertex shader"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create vertex shader"); if (FAILED(hr)) return nullptr; @@ -66,7 +66,7 @@ std::unique_ptr DXShader::CreateFromBytecode(ShaderStage stage, Binary { ComPtr gs; HRESULT hr = D3D::device->CreateGeometryShader(bytecode.data(), bytecode.size(), nullptr, &gs); - CHECK(SUCCEEDED(hr), "Create geometry shader"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create geometry shader"); if (FAILED(hr)) return nullptr; @@ -78,7 +78,7 @@ std::unique_ptr DXShader::CreateFromBytecode(ShaderStage stage, Binary { ComPtr ps; HRESULT hr = D3D::device->CreatePixelShader(bytecode.data(), bytecode.size(), nullptr, &ps); - CHECK(SUCCEEDED(hr), "Create pixel shader"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create pixel shader"); if (FAILED(hr)) return nullptr; @@ -90,7 +90,7 @@ std::unique_ptr DXShader::CreateFromBytecode(ShaderStage stage, Binary { ComPtr cs; HRESULT hr = D3D::device->CreateComputeShader(bytecode.data(), bytecode.size(), nullptr, &cs); - CHECK(SUCCEEDED(hr), "Create compute shader"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create compute shader"); if (FAILED(hr)) return nullptr; diff --git a/Source/Core/VideoBackends/D3D/DXTexture.cpp b/Source/Core/VideoBackends/D3D/DXTexture.cpp index 097c4c28de..0f72ec9c98 100644 --- a/Source/Core/VideoBackends/D3D/DXTexture.cpp +++ b/Source/Core/VideoBackends/D3D/DXTexture.cpp @@ -207,7 +207,7 @@ std::unique_ptr DXStagingTexture::Create(StagingTextureType ty ComPtr texture; HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, texture.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Create staging texture"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create staging texture"); if (FAILED(hr)) return nullptr; @@ -298,7 +298,7 @@ bool DXStagingTexture::Map() D3D11_MAPPED_SUBRESOURCE sr; HRESULT hr = D3D::context->Map(m_tex.Get(), 0, map_type, 0, &sr); - CHECK(SUCCEEDED(hr), "Map readback texture"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to map readback texture"); if (FAILED(hr)) return false; @@ -363,7 +363,7 @@ std::unique_ptr DXFramebuffer::Create(DXTexture* color_attachment color_attachment->GetLayers()); HRESULT hr = D3D::device->CreateRenderTargetView(color_attachment->GetD3DTexture(), &desc, rtv.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Create render target view for framebuffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create render target view for framebuffer"); if (FAILED(hr)) return nullptr; @@ -375,7 +375,8 @@ std::unique_ptr DXFramebuffer::Create(DXTexture* color_attachment desc.Format = integer_format; hr = D3D::device->CreateRenderTargetView(color_attachment->GetD3DTexture(), &desc, integer_rtv.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Create integer render target view for framebuffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), + "Failed to create integer render target view for framebuffer"); } } @@ -389,7 +390,7 @@ std::unique_ptr DXFramebuffer::Create(DXTexture* color_attachment depth_attachment->GetLayers(), 0); HRESULT hr = D3D::device->CreateDepthStencilView(depth_attachment->GetD3DTexture(), &desc, dsv.GetAddressOf()); - CHECK(SUCCEEDED(hr), "Create depth stencil view for framebuffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create depth stencil view for framebuffer"); if (FAILED(hr)) return nullptr; } diff --git a/Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp b/Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp index 3c326455dd..0713edb80b 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp @@ -3,6 +3,7 @@ #include "VideoBackends/D3D12/D3D12BoundingBox.h" +#include "Common/Assert.h" #include "Common/Logging/Log.h" #include "VideoBackends/D3D12/D3D12Renderer.h" @@ -41,7 +42,7 @@ std::vector D3D12BoundingBox::Read(u32 index, u32 length) static constexpr D3D12_RANGE read_range = {0, BUFFER_SIZE}; void* mapped_pointer; HRESULT hr = m_readback_buffer->Map(0, &read_range, &mapped_pointer); - CHECK(SUCCEEDED(hr), "Map bounding box CPU buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Map bounding box CPU buffer failed"); if (FAILED(hr)) return values; @@ -102,7 +103,7 @@ bool D3D12BoundingBox::CreateBuffers() HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource( &gpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&m_gpu_buffer)); - CHECK(SUCCEEDED(hr), "Creating bounding box GPU buffer failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating bounding box GPU buffer failed"); if (FAILED(hr) || !g_dx_context->GetDescriptorHeapManager().Allocate(&m_gpu_descriptor)) return false; @@ -115,7 +116,7 @@ bool D3D12BoundingBox::CreateBuffers() hr = g_dx_context->GetDevice()->CreateCommittedResource( &cpu_heap_properties, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_readback_buffer)); - CHECK(SUCCEEDED(hr), "Creating bounding box CPU buffer failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating bounding box CPU buffer failed"); if (FAILED(hr)) return false; diff --git a/Source/Core/VideoBackends/D3D12/D3D12PerfQuery.cpp b/Source/Core/VideoBackends/D3D12/D3D12PerfQuery.cpp index dcda278e66..c7e5acac7f 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12PerfQuery.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12PerfQuery.cpp @@ -7,6 +7,7 @@ #include "Common/Assert.h" #include "Common/Logging/Log.h" + #include "VideoBackends/D3D12/Common.h" #include "VideoBackends/D3D12/D3D12Renderer.h" #include "VideoBackends/D3D12/DX12Context.h" @@ -22,7 +23,7 @@ bool PerfQuery::Initialize() { constexpr D3D12_QUERY_HEAP_DESC desc = {D3D12_QUERY_HEAP_TYPE_OCCLUSION, PERF_QUERY_BUFFER_SIZE}; HRESULT hr = g_dx_context->GetDevice()->CreateQueryHeap(&desc, IID_PPV_ARGS(&m_query_heap)); - CHECK(SUCCEEDED(hr), "Failed to create query heap"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create query heap"); if (FAILED(hr)) return false; @@ -40,7 +41,7 @@ bool PerfQuery::Initialize() hr = g_dx_context->GetDevice()->CreateCommittedResource( &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_query_readback_buffer)); - CHECK(SUCCEEDED(hr), "Failed to create query buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create query buffer"); if (FAILED(hr)) return false; @@ -220,7 +221,7 @@ void PerfQuery::AccumulateQueriesFromBuffer(u32 query_count) (m_query_readback_pos + query_count) * sizeof(PerfQueryDataType)}; u8* mapped_ptr; HRESULT hr = m_query_readback_buffer->Map(0, &read_range, reinterpret_cast(&mapped_ptr)); - CHECK(SUCCEEDED(hr), "Failed to map query readback buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to map query readback buffer"); if (FAILED(hr)) return; diff --git a/Source/Core/VideoBackends/D3D12/D3D12StreamBuffer.cpp b/Source/Core/VideoBackends/D3D12/D3D12StreamBuffer.cpp index df7a83bf2b..a5d28d62e9 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12StreamBuffer.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12StreamBuffer.cpp @@ -46,13 +46,13 @@ bool StreamBuffer::AllocateBuffer(u32 size) HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource( &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&m_buffer)); - CHECK(SUCCEEDED(hr), "Allocate buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to allocate buffer of size {}", size); if (FAILED(hr)) return false; static const D3D12_RANGE read_range = {}; hr = m_buffer->Map(0, &read_range, reinterpret_cast(&m_host_pointer)); - CHECK(SUCCEEDED(hr), "Map buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to map buffer of size {}", size); if (FAILED(hr)) return false; diff --git a/Source/Core/VideoBackends/D3D12/D3D12SwapChain.cpp b/Source/Core/VideoBackends/D3D12/D3D12SwapChain.cpp index f7607fb437..45ba0be22e 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12SwapChain.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12SwapChain.cpp @@ -3,6 +3,8 @@ #include "VideoBackends/D3D12/D3D12SwapChain.h" +#include "Common/Assert.h" + #include "VideoBackends/D3D12/DX12Context.h" #include "VideoBackends/D3D12/DX12Texture.h" @@ -32,16 +34,17 @@ bool SwapChain::CreateSwapChainBuffers() { ComPtr resource; HRESULT hr = m_swap_chain->GetBuffer(i, IID_PPV_ARGS(&resource)); - CHECK(SUCCEEDED(hr), "Get swap chain buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to get swap chain buffer {}", i); BufferResources buffer; buffer.texture = DXTexture::CreateAdopted(resource.Get()); - CHECK(buffer.texture, "Create swap chain buffer texture"); + ASSERT_MSG(VIDEO, buffer.texture != nullptr, "Failed to create swap chain buffer texture"); if (!buffer.texture) return false; buffer.framebuffer = DXFramebuffer::Create(buffer.texture.get(), nullptr); - CHECK(buffer.texture, "Create swap chain buffer framebuffer"); + ASSERT_MSG(VIDEO, buffer.framebuffer != nullptr, + "Failed to create swap chain buffer framebuffer"); if (!buffer.framebuffer) return false; diff --git a/Source/Core/VideoBackends/D3D12/DX12Context.cpp b/Source/Core/VideoBackends/D3D12/DX12Context.cpp index 8582575b70..b74785a059 100644 --- a/Source/Core/VideoBackends/D3D12/DX12Context.cpp +++ b/Source/Core/VideoBackends/D3D12/DX12Context.cpp @@ -12,6 +12,7 @@ #include "Common/Assert.h" #include "Common/DynamicLibrary.h" #include "Common/StringUtil.h" + #include "VideoBackends/D3D12/Common.h" #include "VideoBackends/D3D12/D3D12StreamBuffer.h" #include "VideoBackends/D3D12/DescriptorHeapManager.h" @@ -172,7 +173,7 @@ bool DXContext::CreateDevice(u32 adapter_index, bool enable_debug_layer) // Create the actual device. hr = s_d3d12_create_device(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_device)); - CHECK(SUCCEEDED(hr), "Create D3D12 device"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create D3D12 device"); if (FAILED(hr)) return false; @@ -207,7 +208,7 @@ bool DXContext::CreateCommandQueue() D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, D3D12_COMMAND_QUEUE_FLAG_NONE}; HRESULT hr = m_device->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&m_command_queue)); - CHECK(SUCCEEDED(hr), "Create command queue"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create command queue"); return SUCCEEDED(hr); } @@ -215,12 +216,12 @@ bool DXContext::CreateFence() { HRESULT hr = m_device->CreateFence(m_completed_fence_value, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence)); - CHECK(SUCCEEDED(hr), "Create fence"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create fence"); if (FAILED(hr)) return false; m_fence_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); - CHECK(m_fence_event != NULL, "Create fence event"); + ASSERT_MSG(VIDEO, m_fence_event != NULL, "Failed to create fence event"); if (!m_fence_event) return false; @@ -309,7 +310,7 @@ static bool BuildRootSignature(ID3D12Device* device, ID3D12RootSignature** sig_p hr = device->CreateRootSignature(0, root_signature_blob->GetBufferPointer(), root_signature_blob->GetBufferSize(), IID_PPV_ARGS(sig_ptr)); - CHECK(SUCCEEDED(hr), "Create root signature"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create root signature"); return true; } @@ -416,21 +417,21 @@ bool DXContext::CreateCommandLists() CommandListResources& res = m_command_lists[i]; HRESULT hr = m_device->CreateCommandAllocator( D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(res.command_allocator.GetAddressOf())); - CHECK(SUCCEEDED(hr), "Create command allocator"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create command allocator"); if (FAILED(hr)) return false; hr = m_device->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, res.command_allocator.Get(), nullptr, IID_PPV_ARGS(res.command_list.GetAddressOf())); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create command list"); if (FAILED(hr)) { - PanicAlertFmt("Failed to create command list."); return false; } // Close the command list, since the first thing we do is reset them. hr = res.command_list->Close(); - CHECK(SUCCEEDED(hr), "Closing new command list failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Closing new command list failed"); if (FAILED(hr)) return false; @@ -472,14 +473,15 @@ void DXContext::ExecuteCommandList(bool wait_for_completion) // Close and queue command list. HRESULT hr = res.command_list->Close(); - CHECK(SUCCEEDED(hr), "Close command list"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to close command list"); const std::array execute_lists{res.command_list.Get()}; m_command_queue->ExecuteCommandLists(static_cast(execute_lists.size()), execute_lists.data()); // Update fence when GPU has completed. hr = m_command_queue->Signal(m_fence.Get(), m_current_fence_value); - CHECK(SUCCEEDED(hr), "Signal fence"); + + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to signal fence"); MoveToNextCommandList(); if (wait_for_completion) @@ -532,7 +534,7 @@ void DXContext::WaitForFence(u64 fence) { // Fall back to event. HRESULT hr = m_fence->SetEventOnCompletion(fence, m_fence_event); - CHECK(SUCCEEDED(hr), "Set fence event on completion"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to set fence event on completion"); WaitForSingleObject(m_fence_event, INFINITE); m_completed_fence_value = m_fence->GetCompletedValue(); } diff --git a/Source/Core/VideoBackends/D3D12/DX12Shader.cpp b/Source/Core/VideoBackends/D3D12/DX12Shader.cpp index eb0c3dd1f9..724059a621 100644 --- a/Source/Core/VideoBackends/D3D12/DX12Shader.cpp +++ b/Source/Core/VideoBackends/D3D12/DX12Shader.cpp @@ -3,6 +3,7 @@ #include "VideoBackends/D3D12/DX12Shader.h" +#include "Common/Assert.h" #include "Common/StringUtil.h" #include "VideoBackends/D3D12/Common.h" @@ -51,7 +52,7 @@ bool DXShader::CreateComputePipeline() HRESULT hr = g_dx_context->GetDevice()->CreateComputePipelineState( &desc, IID_PPV_ARGS(&m_compute_pipeline)); - CHECK(SUCCEEDED(hr), "Creating compute pipeline failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating compute pipeline failed"); if (m_compute_pipeline && !m_name.empty()) m_compute_pipeline->SetName(m_name.c_str()); diff --git a/Source/Core/VideoBackends/D3D12/DX12Texture.cpp b/Source/Core/VideoBackends/D3D12/DX12Texture.cpp index 69b9b754d1..d0a0f0d79c 100644 --- a/Source/Core/VideoBackends/D3D12/DX12Texture.cpp +++ b/Source/Core/VideoBackends/D3D12/DX12Texture.cpp @@ -39,7 +39,7 @@ static ComPtr CreateTextureUploadBuffer(u32 buffer_size) HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource( &heap_properties, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&resource)); - CHECK(SUCCEEDED(hr), "Create texture upload buffer"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create texture upload buffer"); return resource; } @@ -116,7 +116,7 @@ std::unique_ptr DXTexture::Create(const TextureConfig& config, std::s HRESULT hr = g_dx_context->GetDevice()->CreateCommittedResource( &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, resource_state, config.IsRenderTarget() ? &optimized_clear_value : nullptr, IID_PPV_ARGS(&resource)); - CHECK(SUCCEEDED(hr), "Create D3D12 texture resource"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create D3D12 texture resource"); if (FAILED(hr)) return nullptr; @@ -598,7 +598,7 @@ bool DXStagingTexture::Map() const D3D12_RANGE read_range = {0u, m_type == StagingTextureType::Upload ? 0u : m_buffer_size}; HRESULT hr = m_resource->Map(0, &read_range, reinterpret_cast(&m_map_pointer)); - CHECK(SUCCEEDED(hr), "Map resource failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Map resource failed"); if (FAILED(hr)) return false; @@ -663,7 +663,7 @@ std::unique_ptr DXStagingTexture::Create(StagingTextureType ty &heap_properties, D3D12_HEAP_FLAG_NONE, &desc, is_upload ? D3D12_RESOURCE_STATE_GENERIC_READ : D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&resource)); - CHECK(SUCCEEDED(hr), "Create staging texture resource"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create staging texture resource"); if (FAILED(hr)) return nullptr; diff --git a/Source/Core/VideoBackends/D3D12/DescriptorAllocator.cpp b/Source/Core/VideoBackends/D3D12/DescriptorAllocator.cpp index bfc1c43d8c..989dec905c 100644 --- a/Source/Core/VideoBackends/D3D12/DescriptorAllocator.cpp +++ b/Source/Core/VideoBackends/D3D12/DescriptorAllocator.cpp @@ -3,6 +3,8 @@ #include "VideoBackends/D3D12/DescriptorAllocator.h" +#include "Common/Assert.h" + #include "VideoBackends/D3D12/DX12Context.h" namespace DX12 @@ -16,7 +18,7 @@ bool DescriptorAllocator::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYP const D3D12_DESCRIPTOR_HEAP_DESC desc = {type, static_cast(num_descriptors), D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}; HRESULT hr = device->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&m_descriptor_heap)); - CHECK(SUCCEEDED(hr), "Creating descriptor heap for linear allocator failed"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Creating descriptor heap for linear allocator failed"); if (FAILED(hr)) return false; diff --git a/Source/Core/VideoBackends/D3D12/DescriptorHeapManager.cpp b/Source/Core/VideoBackends/D3D12/DescriptorHeapManager.cpp index e175d6ef63..265aedaa87 100644 --- a/Source/Core/VideoBackends/D3D12/DescriptorHeapManager.cpp +++ b/Source/Core/VideoBackends/D3D12/DescriptorHeapManager.cpp @@ -20,7 +20,7 @@ bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_T D3D12_DESCRIPTOR_HEAP_FLAG_NONE}; HRESULT hr = device->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&m_descriptor_heap)); - CHECK(SUCCEEDED(hr), "Create descriptor heap"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create descriptor heap"); if (FAILED(hr)) return false; @@ -176,7 +176,7 @@ bool SamplerHeapManager::Create(ID3D12Device* device, u32 num_descriptors) { const D3D12_DESCRIPTOR_HEAP_DESC desc = {D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, num_descriptors}; HRESULT hr = device->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&m_descriptor_heap)); - CHECK(SUCCEEDED(hr), "Failed to create sampler descriptor heap"); + ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create sampler descriptor heap"); if (FAILED(hr)) return false; diff --git a/Source/Core/VideoBackends/D3DCommon/D3DCommon.h b/Source/Core/VideoBackends/D3DCommon/D3DCommon.h index 668708c090..f4bcc97930 100644 --- a/Source/Core/VideoBackends/D3DCommon/D3DCommon.h +++ b/Source/Core/VideoBackends/D3DCommon/D3DCommon.h @@ -11,13 +11,6 @@ #include "Common/CommonTypes.h" -#define CHECK(cond, Message, ...) \ - if (!(cond)) \ - { \ - PanicAlert("%s failed in %s at line %d: " Message, __func__, __FILE__, __LINE__, \ - ##__VA_ARGS__); \ - } - struct IDXGIFactory; enum class AbstractTextureFormat : u32;