D3D12: Get rid of safe deletion macros

Anything these macros provided can be obsoleted by using
the correct standard library types.
This commit is contained in:
Lioncash 2016-02-16 01:21:22 -05:00
parent 626fcf4c15
commit 6b08194728
9 changed files with 63 additions and 58 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <algorithm>
#include <memory>
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
@ -46,7 +47,7 @@ namespace D3D
ID3D12Device* device12 = nullptr;
ID3D12CommandQueue* command_queue = nullptr;
D3DCommandListManager* command_list_mgr = nullptr;
std::unique_ptr<D3DCommandListManager> command_list_mgr;
ID3D12GraphicsCommandList* current_command_list = nullptr;
ID3D12RootSignature* default_root_signature = nullptr;
@ -55,10 +56,10 @@ D3D12_CPU_DESCRIPTOR_HANDLE null_srv_cpu_shadow = {};
unsigned int resource_descriptor_size = 0;
unsigned int sampler_descriptor_size = 0;
D3DDescriptorHeapManager* gpu_descriptor_heap_mgr = nullptr;
D3DDescriptorHeapManager* sampler_descriptor_heap_mgr = nullptr;
D3DDescriptorHeapManager* dsv_descriptor_heap_mgr = nullptr;
D3DDescriptorHeapManager* rtv_descriptor_heap_mgr = nullptr;
std::unique_ptr<D3DDescriptorHeapManager> gpu_descriptor_heap_mgr;
std::unique_ptr<D3DDescriptorHeapManager> sampler_descriptor_heap_mgr;
std::unique_ptr<D3DDescriptorHeapManager> dsv_descriptor_heap_mgr;
std::unique_ptr<D3DDescriptorHeapManager> rtv_descriptor_heap_mgr;
std::array<ID3D12DescriptorHeap*, 2> gpu_descriptor_heaps;
HWND hWnd;
@ -558,7 +559,7 @@ HRESULT Create(HWND wnd)
CreateDescriptorHeaps();
CreateRootSignatures();
command_list_mgr = new D3DCommandListManager(
command_list_mgr = std::make_unique<D3DCommandListManager>(
D3D12_COMMAND_LIST_TYPE_DIRECT,
device12,
command_queue
@ -605,7 +606,7 @@ void CreateDescriptorHeaps()
gpu_descriptor_heap_desc.NumDescriptors = 500000;
gpu_descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
gpu_descriptor_heap_mgr = new D3DDescriptorHeapManager(&gpu_descriptor_heap_desc, device12, 50000);
gpu_descriptor_heap_mgr = std::make_unique<D3DDescriptorHeapManager>(&gpu_descriptor_heap_desc, device12, 50000);
gpu_descriptor_heaps[0] = gpu_descriptor_heap_mgr->GetDescriptorHeap();
@ -641,7 +642,7 @@ void CreateDescriptorHeaps()
sampler_descriptor_heap_desc.NumDescriptors = 2000;
sampler_descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
sampler_descriptor_heap_mgr = new D3DDescriptorHeapManager(&sampler_descriptor_heap_desc, device12);
sampler_descriptor_heap_mgr = std::make_unique<D3DDescriptorHeapManager>(&sampler_descriptor_heap_desc, device12);
gpu_descriptor_heaps[1] = sampler_descriptor_heap_mgr->GetDescriptorHeap();
}
@ -652,7 +653,7 @@ void CreateDescriptorHeaps()
dsv_descriptor_heap_desc.NumDescriptors = 2000;
dsv_descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsv_descriptor_heap_mgr = new D3DDescriptorHeapManager(&dsv_descriptor_heap_desc, device12);
dsv_descriptor_heap_mgr = std::make_unique<D3DDescriptorHeapManager>(&dsv_descriptor_heap_desc, device12);
}
{
@ -662,7 +663,7 @@ void CreateDescriptorHeaps()
rtv_descriptor_heap_desc.NumDescriptors = 1000000;
rtv_descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtv_descriptor_heap_mgr = new D3DDescriptorHeapManager(&rtv_descriptor_heap_desc, device12);
rtv_descriptor_heap_mgr = std::make_unique<D3DDescriptorHeapManager>(&rtv_descriptor_heap_desc, device12);
}
}
@ -757,15 +758,15 @@ void Close()
SAFE_RELEASE(s_swap_chain);
SAFE_DELETE(command_list_mgr);
command_list_mgr.reset();
command_queue->Release();
default_root_signature->Release();
SAFE_DELETE(gpu_descriptor_heap_mgr);
SAFE_DELETE(sampler_descriptor_heap_mgr);
SAFE_DELETE(rtv_descriptor_heap_mgr);
SAFE_DELETE(dsv_descriptor_heap_mgr);
gpu_descriptor_heap_mgr.reset();
sampler_descriptor_heap_mgr.reset();
rtv_descriptor_heap_mgr.reset();
dsv_descriptor_heap_mgr.reset();
ULONG remaining_references = device12->Release();
if ((!s_debug_device12 && remaining_references) || (s_debug_device12 && remaining_references > 1))

View File

@ -13,6 +13,7 @@
#include <d3d12.h>
#include <d3dcompiler.h>
#include <dxgi1_4.h>
#include <memory>
#include <vector>
#include "../../Externals/d3dx12/d3dx12.h"
@ -25,8 +26,6 @@ namespace DX12
{
#define SAFE_RELEASE(x) { if (x) (x)->Release(); (x) = nullptr; }
#define SAFE_DELETE(x) { delete (x); (x) = nullptr; }
#define SAFE_DELETE_ARRAY(x) { delete[] (x); (x) = nullptr; }
#define CHECK(cond, Message, ...) if (!(cond)) { __debugbreak(); PanicAlert(__FUNCTION__ " failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
// DEBUGCHECK is for high-frequency functions that we only want to check on debug builds.
@ -80,17 +79,17 @@ extern ID3D12Device* device12;
extern unsigned int resource_descriptor_size;
extern unsigned int sampler_descriptor_size;
extern D3DDescriptorHeapManager* gpu_descriptor_heap_mgr;
extern D3DDescriptorHeapManager* sampler_descriptor_heap_mgr;
extern D3DDescriptorHeapManager* dsv_descriptor_heap_mgr;
extern D3DDescriptorHeapManager* rtv_descriptor_heap_mgr;
extern std::unique_ptr<D3DDescriptorHeapManager> gpu_descriptor_heap_mgr;
extern std::unique_ptr<D3DDescriptorHeapManager> sampler_descriptor_heap_mgr;
extern std::unique_ptr<D3DDescriptorHeapManager> dsv_descriptor_heap_mgr;
extern std::unique_ptr<D3DDescriptorHeapManager> rtv_descriptor_heap_mgr;
extern std::array<ID3D12DescriptorHeap*, 2> gpu_descriptor_heaps;
extern D3D12_CPU_DESCRIPTOR_HANDLE null_srv_cpu;
extern D3D12_CPU_DESCRIPTOR_HANDLE null_srv_cpu_shadow;
extern D3DCommandListManager* command_list_mgr;
extern std::unique_ptr<D3DCommandListManager> command_list_mgr;
extern ID3D12GraphicsCommandList* current_command_list;
extern ID3D12RootSignature* default_root_signature;

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <memory>
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "VideoBackends/D3D12/D3DBase.h"
@ -19,11 +21,11 @@ namespace DX12
namespace D3D
{
static D3DStreamBuffer* s_texture_upload_stream_buffer = nullptr;
static std::unique_ptr<D3DStreamBuffer> s_texture_upload_stream_buffer;
void CleanupPersistentD3DTextureResources()
{
SAFE_DELETE(s_texture_upload_stream_buffer);
s_texture_upload_stream_buffer.reset();
}
void ReplaceRGBATexture2D(ID3D12Resource* texture12, const u8* buffer, unsigned int width, unsigned int height, unsigned int src_pitch, unsigned int level, D3D12_RESOURCE_STATES current_resource_state)
@ -32,7 +34,7 @@ void ReplaceRGBATexture2D(ID3D12Resource* texture12, const u8* buffer, unsigned
if (!s_texture_upload_stream_buffer)
{
s_texture_upload_stream_buffer = new D3DStreamBuffer(4 * 1024 * 1024, 64 * 1024 * 1024, nullptr);
s_texture_upload_stream_buffer = std::make_unique<D3DStreamBuffer>(4 * 1024 * 1024, 64 * 1024 * 1024, nullptr);
}
bool current_command_list_executed = s_texture_upload_stream_buffer->AllocateSpaceInBuffer(upload_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);

View File

@ -4,6 +4,7 @@
#include <cctype>
#include <list>
#include <memory>
#include <string>
#include "VideoBackends/D3D12/D3DBase.h"
@ -58,11 +59,11 @@ class UtilVertexBuffer
public:
explicit UtilVertexBuffer(size_t size)
{
m_stream_buffer = new D3DStreamBuffer(size, size * 4, nullptr);
m_stream_buffer = std::make_unique<D3DStreamBuffer>(size, size * 4, nullptr);
}
~UtilVertexBuffer()
{
SAFE_DELETE(m_stream_buffer);
}
size_t GetSize() const { return m_stream_buffer->GetSize(); }
@ -97,14 +98,14 @@ public:
}
private:
D3DStreamBuffer* m_stream_buffer = nullptr;
std::unique_ptr<D3DStreamBuffer> m_stream_buffer;
};
CD3DFont font;
UtilVertexBuffer* util_vbuf_stq = nullptr;
UtilVertexBuffer* util_vbuf_cq = nullptr;
UtilVertexBuffer* util_vbuf_clearq = nullptr;
UtilVertexBuffer* util_vbuf_efbpokequads = nullptr;
static std::unique_ptr<UtilVertexBuffer> util_vbuf_stq;
static std::unique_ptr<UtilVertexBuffer> util_vbuf_cq;
static std::unique_ptr<UtilVertexBuffer> util_vbuf_clearq;
static std::unique_ptr<UtilVertexBuffer> util_vbuf_efbpokequads;
static const unsigned int s_max_num_vertices = 8000 * 6;
@ -541,10 +542,10 @@ static size_t clearq_offset;
void InitUtils()
{
util_vbuf_stq = new UtilVertexBuffer(0x10000);
util_vbuf_cq = new UtilVertexBuffer(0x10000);
util_vbuf_clearq = new UtilVertexBuffer(0x10000);
util_vbuf_efbpokequads = new UtilVertexBuffer(0x100000);
util_vbuf_stq = std::make_unique<UtilVertexBuffer>(0x10000);
util_vbuf_cq = std::make_unique<UtilVertexBuffer>(0x10000);
util_vbuf_clearq = std::make_unique<UtilVertexBuffer>(0x10000);
util_vbuf_efbpokequads = std::make_unique<UtilVertexBuffer>(0x100000);
D3D12_SAMPLER_DESC point_sampler_desc = {
D3D12_FILTER_MIN_MAG_MIP_POINT,
@ -590,10 +591,10 @@ void ShutdownUtils()
{
font.Shutdown();
SAFE_DELETE(util_vbuf_stq);
SAFE_DELETE(util_vbuf_cq);
SAFE_DELETE(util_vbuf_clearq);
SAFE_DELETE(util_vbuf_efbpokequads);
util_vbuf_stq.reset();
util_vbuf_cq.reset();
util_vbuf_clearq.reset();
util_vbuf_efbpokequads.reset();
}
void SetPointCopySampler()

View File

@ -2,11 +2,12 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "D3DBase.h"
#include "D3DCommandListManager.h"
#include "D3DStreamBuffer.h"
#include <memory>
#include "ShaderConstantsManager.h"
#include "VideoBackends/D3D12/D3DBase.h"
#include "VideoBackends/D3D12/D3DCommandListManager.h"
#include "VideoBackends/D3D12/D3DStreamBuffer.h"
#include "VideoBackends/D3D12/ShaderConstantsManager.h"
#include "VideoCommon/GeometryShaderManager.h"
#include "VideoCommon/PixelShaderManager.h"
@ -25,7 +26,7 @@ enum SHADER_STAGE
SHADER_STAGE_COUNT = 3
};
static std::array<D3DStreamBuffer*, SHADER_STAGE_COUNT> s_shader_constant_stream_buffers = {};
static std::array<std::unique_ptr<D3DStreamBuffer>, SHADER_STAGE_COUNT> s_shader_constant_stream_buffers;
static const unsigned int s_shader_constant_buffer_padded_sizes[SHADER_STAGE_COUNT] = {
(sizeof(GeometryShaderConstants) + 0xff) & ~0xff,
@ -37,14 +38,14 @@ void ShaderConstantsManager::Init()
{
// Allow a large maximum size, as we want to minimize stalls here
std::generate(std::begin(s_shader_constant_stream_buffers), std::end(s_shader_constant_stream_buffers), []() {
return new D3DStreamBuffer(2 * 1024 * 1024, 64 * 1024 * 1024, nullptr);
return std::make_unique<D3DStreamBuffer>(2 * 1024 * 1024, 64 * 1024 * 1024, nullptr);
});
}
void ShaderConstantsManager::Shutdown()
{
for (auto& it : s_shader_constant_stream_buffers)
SAFE_DELETE(it);
for (auto& buffer : s_shader_constant_stream_buffers)
buffer.reset();
}
bool ShaderConstantsManager::LoadAndSetGeometryShaderConstants()

View File

@ -563,7 +563,7 @@ TextureCache::TextureCache()
m_palette_pixel_shaders[GX_TL_RGB565] = GetConvertShader12(std::string("RGB565"));
m_palette_pixel_shaders[GX_TL_RGB5A3] = GetConvertShader12(std::string("RGB5A3"));
m_palette_stream_buffer = new D3DStreamBuffer(sizeof(u16) * 256 * 1024, sizeof(u16) * 256 * 1024 * 16, nullptr);
m_palette_stream_buffer = std::make_unique<D3DStreamBuffer>(sizeof(u16) * 256 * 1024, sizeof(u16) * 256 * 1024 * 16, nullptr);
// Right now, there are only two variants of palette_uniform data. So, we'll just create an upload heap to permanently store both of these.
CheckHR(
@ -604,8 +604,6 @@ TextureCache::~TextureCache()
s_efb_copy_stream_buffer.reset();
SAFE_DELETE(m_palette_stream_buffer);
if (s_texture_cache_entry_readback_buffer)
{
D3D::command_list_mgr->DestroyResourceAfterCurrentCommandListExecuted(s_texture_cache_entry_readback_buffer);

View File

@ -4,6 +4,8 @@
#pragma once
#include <memory>
#include "VideoBackends/D3D12/D3DTexture.h"
#include "VideoCommon/TextureCacheBase.h"
@ -59,7 +61,7 @@ private:
void CompileShaders() override { }
void DeleteShaders() override { }
D3DStreamBuffer* m_palette_stream_buffer = nullptr;
std::unique_ptr<D3DStreamBuffer> m_palette_stream_buffer;
ID3D12Resource* m_palette_uniform_buffer = nullptr;
D3D12_SHADER_BYTECODE m_palette_pixel_shaders[3] = {};

View File

@ -44,8 +44,8 @@ void VertexManager::CreateDeviceObjects()
m_vertex_draw_offset = 0;
m_index_draw_offset = 0;
m_vertex_stream_buffer = new D3DStreamBuffer(VertexManager::MAXVBUFFERSIZE * 2, MAX_VBUFFER_SIZE, &m_vertex_stream_buffer_reallocated);
m_index_stream_buffer = new D3DStreamBuffer(VertexManager::MAXIBUFFERSIZE * sizeof(u16) * 2, VertexManager::MAXIBUFFERSIZE * sizeof(u16) * 16, &m_index_stream_buffer_reallocated);
m_vertex_stream_buffer = std::make_unique<D3DStreamBuffer>(MAXVBUFFERSIZE * 2, MAX_VBUFFER_SIZE, &m_vertex_stream_buffer_reallocated);
m_index_stream_buffer = std::make_unique<D3DStreamBuffer>(MAXIBUFFERSIZE * sizeof(u16) * 2, MAXIBUFFERSIZE * sizeof(u16) * 16, &m_index_stream_buffer_reallocated);
SetIndexBuffer();
@ -57,8 +57,8 @@ void VertexManager::CreateDeviceObjects()
void VertexManager::DestroyDeviceObjects()
{
SAFE_DELETE(m_vertex_stream_buffer);
SAFE_DELETE(m_index_stream_buffer);
m_vertex_stream_buffer.reset();
m_index_stream_buffer.reset();
m_vertex_cpu_buffer.clear();
m_index_cpu_buffer.clear();

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include "VideoCommon/VertexManagerBase.h"
namespace DX12
@ -34,8 +35,8 @@ private:
u32 m_vertex_draw_offset;
u32 m_index_draw_offset;
D3DStreamBuffer* m_vertex_stream_buffer = nullptr;
D3DStreamBuffer* m_index_stream_buffer = nullptr;
std::unique_ptr<D3DStreamBuffer> m_vertex_stream_buffer;
std::unique_ptr<D3DStreamBuffer> m_index_stream_buffer;
bool m_vertex_stream_buffer_reallocated = false;
bool m_index_stream_buffer_reallocated = false;