From 5786aa8aa0d3004c4ada3ac3d80e93026cb32fef Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 28 Apr 2026 21:54:31 +0200 Subject: [PATCH] Try to utilize the default destructor Might need to stall the destruction due to resources being in use by the GPU --- OptiScaler/nvapi/fakenvapi/nvapi_calls.cpp | 2 - OptiScaler/shaders/Shader_Dx12.cpp | 26 +------------ OptiScaler/shaders/Shader_Dx12.h | 8 ++-- OptiScaler/shaders/bias/Bias_Dx12.cpp | 25 ++----------- OptiScaler/shaders/bias/Bias_Dx12.h | 6 +-- OptiScaler/shaders/depth_invert/DI_Dx12.cpp | 23 ++---------- OptiScaler/shaders/depth_invert/DI_Dx12.h | 6 +-- OptiScaler/shaders/depth_scale/DS_Dx12.cpp | 25 ++----------- OptiScaler/shaders/depth_scale/DS_Dx12.h | 6 +-- .../shaders/format_transfer/FT_Dx12.cpp | 23 ++---------- OptiScaler/shaders/format_transfer/FT_Dx12.h | 6 +-- OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp | 35 +++++------------- OptiScaler/shaders/hud_copy/HudCopy_Dx12.h | 4 +- .../shaders/hudless_compare/HC_Dx12.cpp | 31 ++-------------- OptiScaler/shaders/hudless_compare/HC_Dx12.h | 2 - .../hudless_compare_compute/HCC_Dx12.cpp | 35 +++++------------- .../hudless_compare_compute/HCC_Dx12.h | 4 +- OptiScaler/shaders/output_scaling/OS_Dx12.cpp | 33 +++++------------ OptiScaler/shaders/output_scaling/OS_Dx12.h | 6 +-- OptiScaler/shaders/rcas/RCAS_Dx12.cpp | 37 ++++--------------- OptiScaler/shaders/rcas/RCAS_Dx12.h | 8 ++-- OptiScaler/shaders/render_ui/RUI_Dx12.cpp | 35 +++--------------- OptiScaler/shaders/render_ui/RUI_Dx12.h | 4 +- OptiScaler/shaders/resource_flip/RF_Dx12.cpp | 17 ++------- OptiScaler/shaders/resource_flip/RF_Dx12.h | 2 - 25 files changed, 81 insertions(+), 328 deletions(-) diff --git a/OptiScaler/nvapi/fakenvapi/nvapi_calls.cpp b/OptiScaler/nvapi/fakenvapi/nvapi_calls.cpp index a1ff11f3..9ce6da36 100644 --- a/OptiScaler/nvapi/fakenvapi/nvapi_calls.cpp +++ b/OptiScaler/nvapi/fakenvapi/nvapi_calls.cpp @@ -4,8 +4,6 @@ #include #include -using Microsoft::WRL::ComPtr; - LowLatency* LowLatencyCtx::lowlatency_ctx = nullptr; static auto init_mutex = std::mutex {}; diff --git a/OptiScaler/shaders/Shader_Dx12.cpp b/OptiScaler/shaders/Shader_Dx12.cpp index 6631a34b..37f64330 100644 --- a/OptiScaler/shaders/Shader_Dx12.cpp +++ b/OptiScaler/shaders/Shader_Dx12.cpp @@ -6,30 +6,6 @@ using Microsoft::WRL::ComPtr; Shader_Dx12::Shader_Dx12(std::string InName, ID3D12Device* InDevice) : _name(InName), _device(InDevice) {} -Shader_Dx12::~Shader_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - if (_pipelineState != nullptr) - { - _pipelineState->Release(); - _pipelineState = nullptr; - } - - if (_rootSignature != nullptr) - { - _rootSignature->Release(); - _rootSignature = nullptr; - } - - if (_constantBuffer != nullptr) - { - _constantBuffer->Release(); - _constantBuffer = nullptr; - } -} - DXGI_FORMAT Shader_Dx12::TranslateTypelessFormats(DXGI_FORMAT format) { switch (format) @@ -112,7 +88,7 @@ bool Shader_Dx12::CreateComputePipeline(ID3D12Device* device, ID3D12PipelineStat if (!Config::Instance()->UsePrecompiledShaders.value_or_default() && source) shaderBlob = CompileShader(source, "CSMain", "cs_5_0"); - return CreateComputeShader(device, _rootSignature, pipelineState, shaderBlob.Get(), + return CreateComputeShader(device, _rootSignature.Get(), pipelineState, shaderBlob.Get(), CD3DX12_SHADER_BYTECODE(bytecode, bytecodeSize)); } diff --git a/OptiScaler/shaders/Shader_Dx12.h b/OptiScaler/shaders/Shader_Dx12.h index 14d60a11..d55336d7 100644 --- a/OptiScaler/shaders/Shader_Dx12.h +++ b/OptiScaler/shaders/Shader_Dx12.h @@ -16,11 +16,11 @@ class Shader_Dx12 bool _init = false; int _counter = 0; - ID3D12RootSignature* _rootSignature = nullptr; - ID3D12PipelineState* _pipelineState = nullptr; + Microsoft::WRL::ComPtr _rootSignature; + Microsoft::WRL::ComPtr _pipelineState; ID3D12Device* _device = nullptr; - ID3D12Resource* _constantBuffer = nullptr; + Microsoft::WRL::ComPtr _constantBuffer; std::vector _descriptorRanges; @@ -56,6 +56,4 @@ class Shader_Dx12 bool IsInit() const { return _init; } Shader_Dx12(std::string InName, ID3D12Device* InDevice); - - ~Shader_Dx12(); }; diff --git a/OptiScaler/shaders/bias/Bias_Dx12.cpp b/OptiScaler/shaders/bias/Bias_Dx12.cpp index 161c1b4b..23eed5c0 100644 --- a/OptiScaler/shaders/bias/Bias_Dx12.cpp +++ b/OptiScaler/shaders/bias/Bias_Dx12.cpp @@ -24,7 +24,7 @@ bool Bias_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InS void Bias_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool Bias_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, float InBias, @@ -45,7 +45,7 @@ bool Bias_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* I InternalConstants constants {}; constants.Bias = std::clamp(InBias, 0.0f, 0.9f); - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -54,8 +54,8 @@ bool Bias_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* I ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -108,20 +108,3 @@ Bias_Dx12::Bias_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(I _init = InitHeaps(InDevice, _frameHeaps, BIAS_NUM_OF_HEAPS); } - -Bias_Dx12::~Bias_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < BIAS_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/bias/Bias_Dx12.h b/OptiScaler/shaders/bias/Bias_Dx12.h index 159200b0..14f367db 100644 --- a/OptiScaler/shaders/bias/Bias_Dx12.h +++ b/OptiScaler/shaders/bias/Bias_Dx12.h @@ -16,7 +16,7 @@ class Bias_Dx12 : public Shader_Dx12 FrameDescriptorHeap _frameHeaps[BIAS_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; UINT InNumThreadsX = 16; @@ -28,10 +28,8 @@ class Bias_Dx12 : public Shader_Dx12 bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, float InBias, ID3D12Resource* OutResource); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool CanRender() const { return _init && _buffer != nullptr; } Bias_Dx12(std::string InName, ID3D12Device* InDevice); - - ~Bias_Dx12(); }; diff --git a/OptiScaler/shaders/depth_invert/DI_Dx12.cpp b/OptiScaler/shaders/depth_invert/DI_Dx12.cpp index 3f18fe07..9c39e21e 100644 --- a/OptiScaler/shaders/depth_invert/DI_Dx12.cpp +++ b/OptiScaler/shaders/depth_invert/DI_Dx12.cpp @@ -29,7 +29,7 @@ bool DI_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSou void DI_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool DI_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource) @@ -49,8 +49,8 @@ bool DI_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -90,20 +90,3 @@ DI_Dx12::DI_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(InNam _init = InitHeaps(InDevice, _frameHeaps, DI_NUM_OF_HEAPS); } - -DI_Dx12::~DI_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < DI_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/depth_invert/DI_Dx12.h b/OptiScaler/shaders/depth_invert/DI_Dx12.h index 60f851ec..3609fc87 100644 --- a/OptiScaler/shaders/depth_invert/DI_Dx12.h +++ b/OptiScaler/shaders/depth_invert/DI_Dx12.h @@ -14,7 +14,7 @@ class DI_Dx12 : public Shader_Dx12 private: FrameDescriptorHeap _frameHeaps[DI_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; uint32_t InNumThreadsX = 16; @@ -26,10 +26,8 @@ class DI_Dx12 : public Shader_Dx12 void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState); bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool CanRender() const { return _init && _buffer != nullptr; } DI_Dx12(std::string InName, ID3D12Device* InDevice); - - ~DI_Dx12(); }; diff --git a/OptiScaler/shaders/depth_scale/DS_Dx12.cpp b/OptiScaler/shaders/depth_scale/DS_Dx12.cpp index 93872ec3..206af27e 100644 --- a/OptiScaler/shaders/depth_scale/DS_Dx12.cpp +++ b/OptiScaler/shaders/depth_scale/DS_Dx12.cpp @@ -32,7 +32,7 @@ bool DS_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSou void DS_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool DS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource) @@ -52,7 +52,7 @@ bool DS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR DSConstants constants {}; constants.DepthScale = Config::Instance()->FGDepthScaleMax.value_or_default(); - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -61,8 +61,8 @@ bool DS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -124,20 +124,3 @@ DS_Dx12::DS_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(InNam _init = InitHeaps(InDevice, _frameHeaps, DS_NUM_OF_HEAPS); } - -DS_Dx12::~DS_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < DS_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/depth_scale/DS_Dx12.h b/OptiScaler/shaders/depth_scale/DS_Dx12.h index 30f474db..bb0ffbcc 100644 --- a/OptiScaler/shaders/depth_scale/DS_Dx12.h +++ b/OptiScaler/shaders/depth_scale/DS_Dx12.h @@ -14,7 +14,7 @@ class DS_Dx12 : public Shader_Dx12 private: FrameDescriptorHeap _frameHeaps[DS_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; uint32_t InNumThreadsX = 16; @@ -26,10 +26,8 @@ class DS_Dx12 : public Shader_Dx12 void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState); bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool CanRender() const { return _init && _buffer != nullptr; } DS_Dx12(std::string InName, ID3D12Device* InDevice); - - ~DS_Dx12(); }; diff --git a/OptiScaler/shaders/format_transfer/FT_Dx12.cpp b/OptiScaler/shaders/format_transfer/FT_Dx12.cpp index fa1c3002..85677c15 100644 --- a/OptiScaler/shaders/format_transfer/FT_Dx12.cpp +++ b/OptiScaler/shaders/format_transfer/FT_Dx12.cpp @@ -60,7 +60,7 @@ bool FT_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSou void FT_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool FT_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource) @@ -80,8 +80,8 @@ bool FT_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -128,20 +128,3 @@ bool FT_Dx12::IsFormatCompatible(DXGI_FORMAT InFormat) // Bold move: accept all formats return true; } - -FT_Dx12::~FT_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < FT_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/format_transfer/FT_Dx12.h b/OptiScaler/shaders/format_transfer/FT_Dx12.h index eda5ebe8..19d5cb34 100644 --- a/OptiScaler/shaders/format_transfer/FT_Dx12.h +++ b/OptiScaler/shaders/format_transfer/FT_Dx12.h @@ -14,7 +14,7 @@ class FT_Dx12 : public Shader_Dx12 private: FrameDescriptorHeap _frameHeaps[FT_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; DXGI_FORMAT format; @@ -29,13 +29,11 @@ class FT_Dx12 : public Shader_Dx12 void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState); bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool CanRender() const { return _init && _buffer != nullptr; } DXGI_FORMAT Format() const { return format; } FT_Dx12(std::string InName, ID3D12Device* InDevice, DXGI_FORMAT InFormat); bool IsFormatCompatible(DXGI_FORMAT InFormat); - - ~FT_Dx12(); }; diff --git a/OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp b/OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp index e5b406c6..77b3a152 100644 --- a/OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp +++ b/OptiScaler/shaders/hud_copy/HudCopy_Dx12.cpp @@ -50,23 +50,23 @@ bool HudCopy_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* ResourceBarrier(cmdList, present, presentState, D3D12_RESOURCE_STATE_COPY_SOURCE); - cmdList->CopyResource(_buffer, present); + cmdList->CopyResource(_buffer.Get(), present); // Make sure present is in D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); ResourceBarrier(cmdList, hudless, hudlessState, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); // Create views CreateShaderResourceView(_device, hudless, currentHeap.GetSrvCPU(0)); CreateShaderResourceView(_device, present, currentHeap.GetSrvCPU(1)); - CreateUnorderedAccessView(_device, _buffer, currentHeap.GetUavCPU(0), 0); + CreateUnorderedAccessView(_device, _buffer.Get(), currentHeap.GetUavCPU(0), 0); InternalCompareParams constants {}; constants.DiffThreshold = hudDetectionThreshold; - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -75,8 +75,8 @@ bool HudCopy_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; cmdList->SetDescriptorHeaps(_countof(heaps), heaps); - cmdList->SetComputeRootSignature(_rootSignature); - cmdList->SetPipelineState(_pipelineState); + cmdList->SetComputeRootSignature(_rootSignature.Get()); + cmdList->SetPipelineState(_pipelineState.Get()); cmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -86,15 +86,15 @@ bool HudCopy_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* cmdList->Dispatch(dispatchWidth, dispatchHeight, 1); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_DEST); - cmdList->CopyResource(present, _buffer); + cmdList->CopyResource(present, _buffer.Get()); // Restore resource states ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_COPY_DEST, presentState); ResourceBarrier(cmdList, hudless, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, hudlessState); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); return true; } @@ -136,20 +136,3 @@ HudCopy_Dx12::HudCopy_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_ _init = InitHeaps(InDevice, _frameHeaps, HudCopy_NUM_OF_HEAPS); } - -HudCopy_Dx12::~HudCopy_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < HudCopy_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/hud_copy/HudCopy_Dx12.h b/OptiScaler/shaders/hud_copy/HudCopy_Dx12.h index a647a871..1cfd1aaf 100644 --- a/OptiScaler/shaders/hud_copy/HudCopy_Dx12.h +++ b/OptiScaler/shaders/hud_copy/HudCopy_Dx12.h @@ -20,7 +20,7 @@ class HudCopy_Dx12 : public Shader_Dx12 FrameDescriptorHeap _frameHeaps[HudCopy_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; uint32_t InNumThreadsX = 16; uint32_t InNumThreadsY = 16; @@ -33,6 +33,4 @@ class HudCopy_Dx12 : public Shader_Dx12 D3D12_RESOURCE_STATES hudlessState, D3D12_RESOURCE_STATES presentState, float hudDetectionThreshold); HudCopy_Dx12(std::string InName, ID3D12Device* InDevice); - - ~HudCopy_Dx12(); }; diff --git a/OptiScaler/shaders/hudless_compare/HC_Dx12.cpp b/OptiScaler/shaders/hudless_compare/HC_Dx12.cpp index a06074b3..0005e1b6 100644 --- a/OptiScaler/shaders/hudless_compare/HC_Dx12.cpp +++ b/OptiScaler/shaders/hudless_compare/HC_Dx12.cpp @@ -76,7 +76,7 @@ HC_Dx12::HC_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(InNam ID3DBlob *vs, *ps; D3D12_GRAPHICS_PIPELINE_STATE_DESC graphicsPsoDesc {}; - graphicsPsoDesc.pRootSignature = _rootSignature; + graphicsPsoDesc.pRootSignature = _rootSignature.Get(); if (Config::Instance()->UsePrecompiledShaders.value_or_default()) { @@ -209,7 +209,7 @@ bool HC_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, constants.DiffThreshold = 0.003f; constants.PinkAmount = 0.6f; - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -218,8 +218,8 @@ bool HC_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; cmdList->SetDescriptorHeaps(_countof(heaps), heaps); - cmdList->SetGraphicsRootSignature(_rootSignature); - cmdList->SetPipelineState(_pipelineState); + cmdList->SetGraphicsRootSignature(_rootSignature.Get()); + cmdList->SetPipelineState(_pipelineState.Get()); cmdList->SetGraphicsRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -250,26 +250,3 @@ bool HC_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, return true; } - -HC_Dx12::~HC_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - if (_rootSignature != nullptr) - { - _rootSignature->Release(); - _rootSignature = nullptr; - } - - for (int i = 0; i < HC_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_constantBuffer != nullptr) - { - _constantBuffer->Release(); - _constantBuffer = nullptr; - } -} diff --git a/OptiScaler/shaders/hudless_compare/HC_Dx12.h b/OptiScaler/shaders/hudless_compare/HC_Dx12.h index 392cbbe5..a8f4114d 100644 --- a/OptiScaler/shaders/hudless_compare/HC_Dx12.h +++ b/OptiScaler/shaders/hudless_compare/HC_Dx12.h @@ -36,6 +36,4 @@ class HC_Dx12 : public Shader_Dx12 D3D12_RESOURCE_STATES state); HC_Dx12(std::string InName, ID3D12Device* InDevice); - - ~HC_Dx12(); }; diff --git a/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.cpp b/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.cpp index d4966430..0b5e8707 100644 --- a/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.cpp +++ b/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.cpp @@ -49,24 +49,24 @@ bool HCC_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* hudl ResourceBarrier(cmdList, present, presentState, D3D12_RESOURCE_STATE_COPY_SOURCE); - cmdList->CopyResource(_buffer, present); + cmdList->CopyResource(_buffer.Get(), present); // Make sure present is in D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); ResourceBarrier(cmdList, hudless, hudlessState, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); // Create views CreateShaderResourceView(_device, hudless, currentHeap.GetSrvCPU(0)); CreateShaderResourceView(_device, present, currentHeap.GetSrvCPU(1)); - CreateUnorderedAccessView(_device, _buffer, currentHeap.GetUavCPU(0), 0); + CreateUnorderedAccessView(_device, _buffer.Get(), currentHeap.GetUavCPU(0), 0); InternalCompareParams constants {}; constants.DiffThreshold = 0.003f; constants.PinkAmount = 0.6f; - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -75,8 +75,8 @@ bool HCC_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* hudl ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; cmdList->SetDescriptorHeaps(_countof(heaps), heaps); - cmdList->SetComputeRootSignature(_rootSignature); - cmdList->SetPipelineState(_pipelineState); + cmdList->SetComputeRootSignature(_rootSignature.Get()); + cmdList->SetPipelineState(_pipelineState.Get()); cmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -86,15 +86,15 @@ bool HCC_Dx12::Dispatch(ID3D12GraphicsCommandList* cmdList, ID3D12Resource* hudl cmdList->Dispatch(dispatchWidth, dispatchHeight, 1); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_DEST); - cmdList->CopyResource(present, _buffer); + cmdList->CopyResource(present, _buffer.Get()); // Restore resource states ResourceBarrier(cmdList, present, D3D12_RESOURCE_STATE_COPY_DEST, presentState); ResourceBarrier(cmdList, hudless, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, hudlessState); - ResourceBarrier(cmdList, _buffer, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); + ResourceBarrier(cmdList, _buffer.Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); return true; } @@ -136,20 +136,3 @@ HCC_Dx12::HCC_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(InN _init = InitHeaps(InDevice, _frameHeaps, HCC_NUM_OF_HEAPS); } - -HCC_Dx12::~HCC_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < HCC_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.h b/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.h index 182747bb..eaaad007 100644 --- a/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.h +++ b/OptiScaler/shaders/hudless_compare_compute/HCC_Dx12.h @@ -21,7 +21,7 @@ class HCC_Dx12 : public Shader_Dx12 FrameDescriptorHeap _frameHeaps[HCC_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; uint32_t InNumThreadsX = 16; uint32_t InNumThreadsY = 16; @@ -34,6 +34,4 @@ class HCC_Dx12 : public Shader_Dx12 D3D12_RESOURCE_STATES hudlessState, D3D12_RESOURCE_STATES presentState); HCC_Dx12(std::string InName, ID3D12Device* InDevice); - - ~HCC_Dx12(); }; diff --git a/OptiScaler/shaders/output_scaling/OS_Dx12.cpp b/OptiScaler/shaders/output_scaling/OS_Dx12.cpp index c5ff6a47..8c493fa5 100644 --- a/OptiScaler/shaders/output_scaling/OS_Dx12.cpp +++ b/OptiScaler/shaders/output_scaling/OS_Dx12.cpp @@ -46,7 +46,7 @@ bool OS_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSou void OS_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool OS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource) @@ -78,11 +78,12 @@ bool OS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR if (Config::Instance()->OutputScalingDownscaler.value_or_default() == Scaler::FSR1) { createdConstantsBuffer = - CreateConstantsBuffer(_device, _constantBuffer, fsr1Constants, currentHeap.GetCbvCPU(0)); + CreateConstantsBuffer(_device, _constantBuffer.Get(), fsr1Constants, currentHeap.GetCbvCPU(0)); } else { - createdConstantsBuffer = CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0)); + createdConstantsBuffer = + CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0)); } if (!createdConstantsBuffer) @@ -94,8 +95,8 @@ bool OS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -142,7 +143,7 @@ OS_Dx12::OS_Dx12(std::string InName, ID3D12Device* InDevice, bool InUpsample) Config::Instance()->OutputScalingDownscaler.value_or_default() == Scaler::FSR1) { D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {}; - computePsoDesc.pRootSignature = _rootSignature; + computePsoDesc.pRootSignature = _rootSignature.Get(); computePsoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; // fsr upscaling @@ -295,7 +296,8 @@ OS_Dx12::OS_Dx12(std::string InName, ID3D12Device* InDevice, bool InUpsample) LOG_ERROR("[{0}] CompileShader error!", _name); // create pso objects - if (!Shader_Dx12::CreateComputeShader(InDevice, _rootSignature, &_pipelineState, _recEncodeShader, byteCode)) + if (!Shader_Dx12::CreateComputeShader(InDevice, _rootSignature.Get(), &_pipelineState, _recEncodeShader, + byteCode)) { LOG_ERROR("[{0}] CreateComputeShader error!", _name); return; @@ -310,20 +312,3 @@ OS_Dx12::OS_Dx12(std::string InName, ID3D12Device* InDevice, bool InUpsample) _init = InitHeaps(InDevice, _frameHeaps, OS_NUM_OF_HEAPS); } - -OS_Dx12::~OS_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < OS_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/output_scaling/OS_Dx12.h b/OptiScaler/shaders/output_scaling/OS_Dx12.h index b85da32f..2b881e90 100644 --- a/OptiScaler/shaders/output_scaling/OS_Dx12.h +++ b/OptiScaler/shaders/output_scaling/OS_Dx12.h @@ -14,7 +14,7 @@ class OS_Dx12 : public Shader_Dx12 FrameDescriptorHeap _frameHeaps[OS_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; uint32_t InNumThreadsX = 16; @@ -26,11 +26,9 @@ class OS_Dx12 : public Shader_Dx12 void SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState); bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* OutResource); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool IsUpsampling() { return _upsample; } bool CanRender() const { return _init && _buffer != nullptr; } OS_Dx12(std::string InName, ID3D12Device* InDevice, bool InUpsample); - - ~OS_Dx12(); }; diff --git a/OptiScaler/shaders/rcas/RCAS_Dx12.cpp b/OptiScaler/shaders/rcas/RCAS_Dx12.cpp index 818eb1ed..255d0213 100644 --- a/OptiScaler/shaders/rcas/RCAS_Dx12.cpp +++ b/OptiScaler/shaders/rcas/RCAS_Dx12.cpp @@ -30,7 +30,7 @@ bool RCAS_Dx12::DispatchRCAS(ID3D12GraphicsCommandList* InCmdList, ID3D12Resourc FillMotionConstants(constants, InConstants); - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -38,8 +38,8 @@ bool RCAS_Dx12::DispatchRCAS(ID3D12GraphicsCommandList* InCmdList, ID3D12Resourc ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); auto inDesc = InResource->GetDesc(); @@ -78,7 +78,7 @@ bool RCAS_Dx12::DispatchDepthAdaptive(ID3D12GraphicsCommandList* InCmdList, ID3D FillMotionConstants(constants, InConstants); - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -86,8 +86,8 @@ bool RCAS_Dx12::DispatchDepthAdaptive(ID3D12GraphicsCommandList* InCmdList, ID3D ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineStateDA); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineStateDA.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); UINT dispatchWidth = static_cast((constants.OutputWidth + InNumThreadsX - 1) / InNumThreadsX); @@ -115,7 +115,7 @@ bool RCAS_Dx12::CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InS void RCAS_Dx12::SetBufferState(ID3D12GraphicsCommandList* InCommandList, D3D12_RESOURCE_STATES InState) { - return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer, &_bufferState); + return Shader_Dx12::SetBufferState(InCommandList, InState, _buffer.Get(), &_bufferState); } bool RCAS_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, @@ -185,26 +185,3 @@ RCAS_Dx12::RCAS_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(I _init = InitHeaps(InDevice, _frameHeaps, RCAS_NUM_OF_HEAPS); } - -RCAS_Dx12::~RCAS_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - if (_pipelineStateDA != nullptr) - { - _pipelineStateDA->Release(); - _pipelineStateDA = nullptr; - } - - for (int i = 0; i < RCAS_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_buffer != nullptr) - { - _buffer->Release(); - _buffer = nullptr; - } -} diff --git a/OptiScaler/shaders/rcas/RCAS_Dx12.h b/OptiScaler/shaders/rcas/RCAS_Dx12.h index e5df2e8d..23fb02e8 100644 --- a/OptiScaler/shaders/rcas/RCAS_Dx12.h +++ b/OptiScaler/shaders/rcas/RCAS_Dx12.h @@ -19,10 +19,10 @@ class RCAS_Dx12 : public Shader_Dx12, public RCAS_Common FrameDescriptorHeap _frameHeaps[RCAS_NUM_OF_HEAPS]; - ID3D12Resource* _buffer = nullptr; + Microsoft::WRL::ComPtr _buffer = nullptr; D3D12_RESOURCE_STATES _bufferState = D3D12_RESOURCE_STATE_COMMON; - ID3D12PipelineState* _pipelineStateDA = nullptr; + Microsoft::WRL::ComPtr _pipelineStateDA = nullptr; uint32_t InNumThreadsX = 16; uint32_t InNumThreadsY = 16; @@ -39,10 +39,8 @@ class RCAS_Dx12 : public Shader_Dx12, public RCAS_Common bool Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InResource, ID3D12Resource* InMotionVectors, RcasConstants InConstants, ID3D12Resource* OutResource, ID3D12Resource* InDepth = nullptr); - ID3D12Resource* Buffer() { return _buffer; } + ID3D12Resource* Buffer() { return _buffer.Get(); } bool CanRender() const { return _init && _buffer != nullptr; } RCAS_Dx12(std::string InName, ID3D12Device* InDevice); - - ~RCAS_Dx12(); }; diff --git a/OptiScaler/shaders/render_ui/RUI_Dx12.cpp b/OptiScaler/shaders/render_ui/RUI_Dx12.cpp index d255cdb9..7cecd4bf 100644 --- a/OptiScaler/shaders/render_ui/RUI_Dx12.cpp +++ b/OptiScaler/shaders/render_ui/RUI_Dx12.cpp @@ -47,7 +47,7 @@ void RUI_Dx12::SetBufferState(UINT index, ID3D12GraphicsCommandList* InCommandLi if (_bufferState[index] == InState) return; - ResourceBarrier(InCommandList, _buffer[index], _bufferState[index], InState); + ResourceBarrier(InCommandList, _buffer[index].Get(), _bufferState[index], InState); _bufferState[index] = InState; } @@ -79,7 +79,7 @@ RUI_Dx12::RUI_Dx12(std::string InName, ID3D12Device* InDevice, bool preMultiplie ID3DBlob *vs, *ps; D3D12_GRAPHICS_PIPELINE_STATE_DESC graphicsPsoDesc {}; - graphicsPsoDesc.pRootSignature = _rootSignature; + graphicsPsoDesc.pRootSignature = _rootSignature.Get(); if (Config::Instance()->UsePrecompiledShaders.value_or_default()) { @@ -204,7 +204,7 @@ bool RUI_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, ResourceBarrier(cmdList, scBuffer, D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_SOURCE); if (_buffer[_counter] != nullptr) - cmdList->CopyResource(_buffer[_counter], scBuffer); + cmdList->CopyResource(_buffer[_counter].Get(), scBuffer); ResourceBarrier(cmdList, scBuffer, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); SetBufferState(_counter, cmdList, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); @@ -220,14 +220,14 @@ bool RUI_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, // Create views CreateShaderResourceView(_device, hudless, currentHeap.GetSrvCPU(0)); - CreateShaderResourceView(_device, _buffer[_counter], currentHeap.GetSrvCPU(1)); + CreateShaderResourceView(_device, _buffer[_counter].Get(), currentHeap.GetSrvCPU(1)); CreateRenderTargetView(_device, scBuffer, currentHeap.GetRtvCPU(0), 0); ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; cmdList->SetDescriptorHeaps(_countof(heaps), heaps); - cmdList->SetGraphicsRootSignature(_rootSignature); - cmdList->SetPipelineState(_pipelineState); + cmdList->SetGraphicsRootSignature(_rootSignature.Get()); + cmdList->SetPipelineState(_pipelineState.Get()); cmdList->SetGraphicsRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -258,26 +258,3 @@ bool RUI_Dx12::Dispatch(IDXGISwapChain3* sc, ID3D12GraphicsCommandList* cmdList, return true; } - -RUI_Dx12::~RUI_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - if (_rootSignature != nullptr) - { - _rootSignature->Release(); - _rootSignature = nullptr; - } - - for (int i = 0; i < HC_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } - - if (_constantBuffer != nullptr) - { - _constantBuffer->Release(); - _constantBuffer = nullptr; - } -} diff --git a/OptiScaler/shaders/render_ui/RUI_Dx12.h b/OptiScaler/shaders/render_ui/RUI_Dx12.h index 91d36655..7386f594 100644 --- a/OptiScaler/shaders/render_ui/RUI_Dx12.h +++ b/OptiScaler/shaders/render_ui/RUI_Dx12.h @@ -16,7 +16,7 @@ class RUI_Dx12 : public Shader_Dx12 bool _pm = false; FrameDescriptorHeap _frameHeaps[HC_NUM_OF_HEAPS]; - ID3D12Resource* _buffer[HC_NUM_OF_HEAPS] = {}; + Microsoft::WRL::ComPtr _buffer[HC_NUM_OF_HEAPS] = {}; D3D12_RESOURCE_STATES _bufferState[HC_NUM_OF_HEAPS] = { D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COMMON }; static void ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource, @@ -32,6 +32,4 @@ class RUI_Dx12 : public Shader_Dx12 bool IsPreMultipliedAlpha() const { return _pm; } RUI_Dx12(std::string InName, ID3D12Device* InDevice, bool preMultipliedAlpha); - - ~RUI_Dx12(); }; diff --git a/OptiScaler/shaders/resource_flip/RF_Dx12.cpp b/OptiScaler/shaders/resource_flip/RF_Dx12.cpp index 04f7bd37..546933da 100644 --- a/OptiScaler/shaders/resource_flip/RF_Dx12.cpp +++ b/OptiScaler/shaders/resource_flip/RF_Dx12.cpp @@ -33,7 +33,7 @@ bool RF_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR LOG_DEBUG("Width: {}, Height: {}, Offset", constants.width, constants.height, constants.offset); - if (!CreateConstantsBuffer(_device, _constantBuffer, constants, currentHeap.GetCbvCPU(0))) + if (!CreateConstantsBuffer(_device, _constantBuffer.Get(), constants, currentHeap.GetCbvCPU(0))) { LOG_ERROR("[{0}] Failed to create a constants buffer", _name); return false; @@ -42,8 +42,8 @@ bool RF_Dx12::Dispatch(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InR ID3D12DescriptorHeap* heaps[] = { currentHeap.GetHeapCSU() }; InCmdList->SetDescriptorHeaps(_countof(heaps), heaps); - InCmdList->SetComputeRootSignature(_rootSignature); - InCmdList->SetPipelineState(_pipelineState); + InCmdList->SetComputeRootSignature(_rootSignature.Get()); + InCmdList->SetPipelineState(_pipelineState.Get()); InCmdList->SetComputeRootDescriptorTable(0, currentHeap.GetTableGPUStart()); @@ -105,14 +105,3 @@ RF_Dx12::RF_Dx12(std::string InName, ID3D12Device* InDevice) : Shader_Dx12(InNam _init = InitHeaps(InDevice, _frameHeaps, RF_NUM_OF_HEAPS); } - -RF_Dx12::~RF_Dx12() -{ - if (!_init || State::Instance().isShuttingDown) - return; - - for (int i = 0; i < RF_NUM_OF_HEAPS; i++) - { - _frameHeaps[i].ReleaseHeaps(); - } -} diff --git a/OptiScaler/shaders/resource_flip/RF_Dx12.h b/OptiScaler/shaders/resource_flip/RF_Dx12.h index 72f608e6..b9a535ca 100644 --- a/OptiScaler/shaders/resource_flip/RF_Dx12.h +++ b/OptiScaler/shaders/resource_flip/RF_Dx12.h @@ -22,6 +22,4 @@ class RF_Dx12 : public Shader_Dx12 UINT64 width, UINT height, bool velocity); RF_Dx12(std::string InName, ID3D12Device* InDevice); - - ~RF_Dx12(); };