VideoBackends/D3D: Eliminate CHECK in favor of ASSERT_MSG

This commit is contained in:
Pokechu22
2021-11-10 15:55:33 -08:00
parent 161c627466
commit 82acfa6a46
17 changed files with 74 additions and 64 deletions

View File

@ -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<BBoxType> 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;

View File

@ -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<void**>(&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;

View File

@ -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<void**>(&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;

View File

@ -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<ID3D12Resource> 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;

View File

@ -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<ID3D12CommandList*, 1> execute_lists{res.command_list.Get()};
m_command_queue->ExecuteCommandLists(static_cast<UINT>(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();
}

View File

@ -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());

View File

@ -39,7 +39,7 @@ static ComPtr<ID3D12Resource> 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> 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<void**>(&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> 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;

View File

@ -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<UINT>(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;

View File

@ -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;