mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 15:11:31 +00:00
[idd] capture: execute texture frame graphs
This commit is contained in:
@@ -165,6 +165,20 @@ bool CColorTransformEffect::Init(const ComPtr<ID3D12Device3>& device)
|
||||
PostProcessStatus CColorTransformEffect::SetFormat(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, true);
|
||||
}
|
||||
|
||||
PostProcessStatus CColorTransformEffect::Cfg(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, false);
|
||||
}
|
||||
|
||||
PostProcessStatus CColorTransformEffect::Set(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own)
|
||||
{
|
||||
const auto transform = D12::Transform(src.colorTransform);
|
||||
if (!transform)
|
||||
@@ -205,10 +219,15 @@ PostProcessStatus CColorTransformEffect::SetFormat(
|
||||
|
||||
D3D12_RESOURCE_DESC desc = src.desc;
|
||||
desc.Format = dstFormat;
|
||||
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||
if (!m_dst || m_dst->GetDesc().Width != desc.Width ||
|
||||
m_dst->GetDesc().Height != desc.Height ||
|
||||
m_dst->GetDesc().Format != desc.Format)
|
||||
desc.Flags = own ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS :
|
||||
dst.desc.Flags;
|
||||
if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
|
||||
return PostProcessStatus::FAILED;
|
||||
if (own &&
|
||||
(!m_dst ||
|
||||
m_dst->GetDesc().Width != desc.Width ||
|
||||
m_dst->GetDesc().Height != desc.Height ||
|
||||
m_dst->GetDesc().Format != desc.Format))
|
||||
{
|
||||
if (!CreateDefaultTexture(device, desc, m_dst))
|
||||
return PostProcessStatus::FAILED;
|
||||
@@ -216,9 +235,9 @@ PostProcessStatus CColorTransformEffect::SetFormat(
|
||||
|
||||
std::memcpy(m_consts.matrix, transform->matrix,
|
||||
sizeof(m_consts.matrix));
|
||||
m_consts.scalar = transform->scalar;
|
||||
m_consts.matrixEnabled = matrixEnabled;
|
||||
m_consts.lutEnabled = lutEnabled;
|
||||
m_consts.scalar = transform->scalar;
|
||||
m_consts.matrixEnabled = matrixEnabled;
|
||||
m_consts.lutEnabled = lutEnabled;
|
||||
const UINT inputTransfer = src.hdrPQ ? TRANSFER_PQ :
|
||||
(src.hdr ? TRANSFER_LINEAR : TRANSFER_SRGB);
|
||||
m_consts.inputTransfer = inputTransfer;
|
||||
@@ -230,6 +249,7 @@ PostProcessStatus CColorTransformEffect::SetFormat(
|
||||
|
||||
m_srcFormat = src.desc.Format;
|
||||
m_dstFormat = dstFormat;
|
||||
m_outDesc = desc;
|
||||
m_threadsX = Groups((unsigned)desc.Width);
|
||||
m_threadsY = Groups(desc.Height);
|
||||
|
||||
@@ -245,6 +265,30 @@ ComPtr<ID3D12Resource> CColorTransformEffect::Run(
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!m_dst || !Draw(device, commandList, src, m_dst.Get(),
|
||||
dirtyRects, nbDirtyRects))
|
||||
return nullptr;
|
||||
return m_dst;
|
||||
}
|
||||
|
||||
bool CColorTransformEffect::Run(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!device || !commandList || !src || src.Get() == dst || !IsDst(dst))
|
||||
return false;
|
||||
return Draw(device, commandList, src, dst,
|
||||
dirtyRects, nbDirtyRects);
|
||||
}
|
||||
|
||||
bool CColorTransformEffect::Draw(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dirtyRects);
|
||||
UNREFERENCED_PARAMETER(nbDirtyRects);
|
||||
@@ -261,7 +305,7 @@ ComPtr<ID3D12Resource> CColorTransformEffect::Run(
|
||||
m_uploadPending = false;
|
||||
}
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_COMMON,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
CBV(device, 0, m_constBuffer.Get(), sizeof(m_consts));
|
||||
@@ -275,10 +319,10 @@ ComPtr<ID3D12Resource> CColorTransformEffect::Run(
|
||||
device->CreateShaderResourceView(
|
||||
m_lutBuffer.Get(), &lutDesc, Handle(device, 2));
|
||||
|
||||
UAV(device, 3, m_dst.Get(), m_dstFormat);
|
||||
UAV(device, 3, dst, m_dstFormat);
|
||||
Dispatch(commandList);
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_COMMON);
|
||||
return m_dst;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,13 @@ private:
|
||||
CalPart m_part;
|
||||
bool m_keepSignal;
|
||||
|
||||
PostProcessStatus Set(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own);
|
||||
bool Draw(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
|
||||
public:
|
||||
explicit CColorTransformEffect(CalPart part = CalPart::ALL,
|
||||
bool keepSignal = false) :
|
||||
@@ -62,9 +69,17 @@ public:
|
||||
|
||||
PostProcessStatus SetFormat(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst) override;
|
||||
// Configures shader state without allocating the legacy-owned output.
|
||||
PostProcessStatus Cfg(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst);
|
||||
|
||||
ComPtr<ID3D12Resource> Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects) override;
|
||||
// dst must match Cfg's output and be in COMMON; Run restores COMMON.
|
||||
bool Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
};
|
||||
|
||||
@@ -280,11 +280,27 @@ void CComputeEffect::UAV(const ComPtr<ID3D12Device3>& device, UINT index,
|
||||
void CComputeEffect::TransitionDst(
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after)
|
||||
{
|
||||
TransitionDst(commandList, m_dst.Get(), before, after);
|
||||
}
|
||||
|
||||
bool CComputeEffect::IsDst(ID3D12Resource * dst) const
|
||||
{
|
||||
if (!dst)
|
||||
return false;
|
||||
|
||||
return D12::Same(dst->GetDesc(), m_outDesc);
|
||||
}
|
||||
|
||||
void CComputeEffect::TransitionDst(
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
ID3D12Resource * dst, D3D12_RESOURCE_STATES before,
|
||||
D3D12_RESOURCE_STATES after)
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER barrier = {};
|
||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||
barrier.Transition.pResource = m_dst.Get();
|
||||
barrier.Transition.pResource = dst;
|
||||
barrier.Transition.StateBefore = before;
|
||||
barrier.Transition.StateAfter = after;
|
||||
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
|
||||
@@ -61,6 +61,7 @@ protected:
|
||||
ComPtr<ID3D12PipelineState> m_pso;
|
||||
ComPtr<ID3D12DescriptorHeap> m_descHeap;
|
||||
ComPtr<ID3D12Resource> m_dst;
|
||||
D3D12_RESOURCE_DESC m_outDesc = {};
|
||||
unsigned m_threadsX = 0;
|
||||
unsigned m_threadsY = 0;
|
||||
|
||||
@@ -81,6 +82,11 @@ protected:
|
||||
void UAV(const ComPtr<ID3D12Device3>& device, UINT index,
|
||||
ID3D12Resource * resource, DXGI_FORMAT format) const;
|
||||
|
||||
bool IsDst(ID3D12Resource * dst) const;
|
||||
|
||||
void TransitionDst(const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after);
|
||||
void TransitionDst(const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
ID3D12Resource * dst, D3D12_RESOURCE_STATES before,
|
||||
D3D12_RESOURCE_STATES after);
|
||||
};
|
||||
|
||||
@@ -156,6 +156,20 @@ bool CDownsampleEffect::Init(const ComPtr<ID3D12Device3>& device, bool report)
|
||||
PostProcessStatus CDownsampleEffect::SetFormat(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, true);
|
||||
}
|
||||
|
||||
PostProcessStatus CDownsampleEffect::Cfg(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, false);
|
||||
}
|
||||
|
||||
PostProcessStatus CDownsampleEffect::Set(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own)
|
||||
{
|
||||
unsigned targetX = m_targetX;
|
||||
unsigned targetY = m_targetY;
|
||||
@@ -174,9 +188,12 @@ PostProcessStatus CDownsampleEffect::SetFormat(
|
||||
D3D12_RESOURCE_DESC desc = src.desc;
|
||||
desc.Width = targetX;
|
||||
desc.Height = targetY;
|
||||
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||
desc.Flags = own ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS :
|
||||
dst.desc.Flags;
|
||||
if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
|
||||
return PostProcessStatus::FAILED;
|
||||
|
||||
if (!CreateDefaultTexture(device, desc, m_dst))
|
||||
if (own && !CreateDefaultTexture(device, desc, m_dst))
|
||||
return PostProcessStatus::FAILED;
|
||||
|
||||
m_consts.width = (float)targetX;
|
||||
@@ -190,6 +207,7 @@ PostProcessStatus CDownsampleEffect::SetFormat(
|
||||
}
|
||||
m_threadsX = Groups((unsigned)desc.Width);
|
||||
m_threadsY = Groups(desc.Height);
|
||||
m_outDesc = desc;
|
||||
m_format = src.desc.Format;
|
||||
m_scaleX = (double)desc.Width / src.desc.Width;
|
||||
m_scaleY = (double)desc.Height / src.desc.Height;
|
||||
@@ -225,19 +243,43 @@ ComPtr<ID3D12Resource> CDownsampleEffect::Run(
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!m_dst || !Draw(device, commandList, src, m_dst.Get(),
|
||||
dirtyRects, nbDirtyRects))
|
||||
return nullptr;
|
||||
return m_dst;
|
||||
}
|
||||
|
||||
bool CDownsampleEffect::Run(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!device || !commandList || !src || src.Get() == dst || !IsDst(dst))
|
||||
return false;
|
||||
return Draw(device, commandList, src, dst,
|
||||
dirtyRects, nbDirtyRects);
|
||||
}
|
||||
|
||||
bool CDownsampleEffect::Draw(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dirtyRects);
|
||||
UNREFERENCED_PARAMETER(nbDirtyRects);
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_COMMON,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
CBV(device, 0, m_constBuffer.Get(), sizeof(m_consts));
|
||||
SRV(device, 1, src.Get(), m_format);
|
||||
UAV(device, 2, m_dst.Get(), m_format);
|
||||
UAV(device, 2, dst, m_format);
|
||||
Dispatch(commandList);
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_COMMON);
|
||||
return m_dst;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,12 @@ private:
|
||||
|
||||
bool ParseRules(const std::wstring& value, bool report);
|
||||
const Rule * MatchRule(unsigned width, unsigned height) const;
|
||||
PostProcessStatus Set(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own);
|
||||
bool Draw(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
|
||||
public:
|
||||
CDownsampleEffect() = default;
|
||||
@@ -67,6 +73,9 @@ public:
|
||||
|
||||
PostProcessStatus SetFormat(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst) override;
|
||||
// Configures shader state without allocating the legacy-owned output.
|
||||
PostProcessStatus Cfg(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst);
|
||||
|
||||
void AdjustDamage(RECT dirtyRects[], unsigned * nbDirtyRects) override;
|
||||
|
||||
@@ -74,4 +83,9 @@ public:
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects) override;
|
||||
// dst must match Cfg's output and be in COMMON; Run restores COMMON.
|
||||
bool Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
};
|
||||
|
||||
164
idd/LGIdd/postprocess/effect/CFormatEffect.cpp
Normal file
164
idd/LGIdd/postprocess/effect/CFormatEffect.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "CFormatEffect.h"
|
||||
|
||||
#include "CDebug.h"
|
||||
|
||||
using namespace PostProcessUtil;
|
||||
|
||||
namespace
|
||||
{
|
||||
bool IsSDR8(const D12FrameFormat& format)
|
||||
{
|
||||
if (format.hdr || format.hdrPQ)
|
||||
return false;
|
||||
|
||||
switch (format.format)
|
||||
{
|
||||
case FRAME_TYPE_BGRA:
|
||||
return format.desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
case FRAME_TYPE_RGBA:
|
||||
return format.desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CFormatEffect::Init(const ComPtr<ID3D12Device3>& device)
|
||||
{
|
||||
D3D12_DESCRIPTOR_RANGE ranges[] =
|
||||
{
|
||||
Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0),
|
||||
Range(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 0),
|
||||
};
|
||||
|
||||
const char * shader =
|
||||
"Texture2D<float4> src : register(t0);\n"
|
||||
"RWTexture2D<float4> dst : register(u0);\n"
|
||||
"[numthreads(" POST_PROCESS_THREADS_STR ", "
|
||||
POST_PROCESS_THREADS_STR ", 1)]\n"
|
||||
"void main(uint3 dt : SV_DispatchThreadID)\n"
|
||||
"{\n"
|
||||
" dst[dt.xy] = src[dt.xy];\n"
|
||||
"}\n";
|
||||
|
||||
return InitCompute(device, ranges, ARRAYSIZE(ranges), nullptr, 0, shader);
|
||||
}
|
||||
|
||||
PostProcessStatus CFormatEffect::SetFormat(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Cfg(device, src, dst);
|
||||
}
|
||||
|
||||
PostProcessStatus CFormatEffect::Cfg(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, const D12FrameFormat& dst)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(device);
|
||||
|
||||
if (src.desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D ||
|
||||
dst.desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D ||
|
||||
!src.desc.Width ||
|
||||
!src.desc.Height ||
|
||||
src.desc.Width != dst.desc.Width ||
|
||||
src.desc.Height != dst.desc.Height ||
|
||||
!IsSDR8(src) ||
|
||||
!IsSDR8(dst))
|
||||
{
|
||||
DEBUG_ERROR("Unsupported texture format conversion");
|
||||
return PostProcessStatus::FAILED;
|
||||
}
|
||||
|
||||
if (src.desc.Format == dst.desc.Format)
|
||||
return PostProcessStatus::BYPASS_EFFECT;
|
||||
|
||||
if (!(dst.desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
|
||||
{
|
||||
DEBUG_ERROR("Format conversion destination does not allow UAV access");
|
||||
return PostProcessStatus::FAILED;
|
||||
}
|
||||
|
||||
m_srcDesc = src.desc;
|
||||
m_outDesc = dst.desc;
|
||||
m_srcFormat = src.desc.Format;
|
||||
m_dstFormat = dst.desc.Format;
|
||||
m_threadsX = Groups((unsigned)dst.desc.Width);
|
||||
m_threadsY = Groups(dst.desc.Height);
|
||||
return PostProcessStatus::SUCCESS;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12Resource> CFormatEffect::Run(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(device);
|
||||
UNREFERENCED_PARAMETER(commandList);
|
||||
UNREFERENCED_PARAMETER(src);
|
||||
UNREFERENCED_PARAMETER(dirtyRects);
|
||||
UNREFERENCED_PARAMETER(nbDirtyRects);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CFormatEffect::IsSrc(ID3D12Resource * src) const
|
||||
{
|
||||
if (!src)
|
||||
return false;
|
||||
|
||||
return D12::Same(src->GetDesc(), m_srcDesc, D12::DescCmp::VIEW);
|
||||
}
|
||||
|
||||
bool CFormatEffect::Run(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!device || !commandList || !IsSrc(src.Get()) ||
|
||||
src.Get() == dst || !IsDst(dst))
|
||||
return false;
|
||||
return Draw(device, commandList, src, dst, dirtyRects, nbDirtyRects);
|
||||
}
|
||||
|
||||
bool CFormatEffect::Draw(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dirtyRects);
|
||||
UNREFERENCED_PARAMETER(nbDirtyRects);
|
||||
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
SRV(device, 0, src.Get(), m_srcFormat);
|
||||
UAV(device, 1, dst, m_dstFormat);
|
||||
Dispatch(commandList);
|
||||
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_COMMON);
|
||||
return true;
|
||||
}
|
||||
57
idd/LGIdd/postprocess/effect/CFormatEffect.h
Normal file
57
idd/LGIdd/postprocess/effect/CFormatEffect.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CComputeEffect.h"
|
||||
|
||||
class CFormatEffect : public CComputeEffect
|
||||
{
|
||||
private:
|
||||
D3D12_RESOURCE_DESC m_srcDesc = {};
|
||||
DXGI_FORMAT m_srcFormat = DXGI_FORMAT_UNKNOWN;
|
||||
DXGI_FORMAT m_dstFormat = DXGI_FORMAT_UNKNOWN;
|
||||
|
||||
bool IsSrc(ID3D12Resource * src) const;
|
||||
bool Draw(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
|
||||
public:
|
||||
const char * GetName() const override { return "Format"; }
|
||||
|
||||
bool Init(const ComPtr<ID3D12Device3>& device);
|
||||
|
||||
PostProcessStatus SetFormat(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst) override;
|
||||
PostProcessStatus Cfg(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, const D12FrameFormat& dst);
|
||||
|
||||
ComPtr<ID3D12Resource> Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects) override;
|
||||
// dst must match Cfg's output and be in COMMON; Run restores COMMON.
|
||||
bool Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
};
|
||||
@@ -87,17 +87,35 @@ bool CHDR16to10Effect::Init(const ComPtr<ID3D12Device3>& device)
|
||||
PostProcessStatus CHDR16to10Effect::SetFormat(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, true);
|
||||
}
|
||||
|
||||
PostProcessStatus CHDR16to10Effect::Cfg(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||
{
|
||||
return Set(device, src, dst, false);
|
||||
}
|
||||
|
||||
PostProcessStatus CHDR16to10Effect::Set(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own)
|
||||
{
|
||||
if (src.desc.Format != DXGI_FORMAT_R16G16B16A16_FLOAT || !src.hdr)
|
||||
return PostProcessStatus::BYPASS_EFFECT;
|
||||
|
||||
D3D12_RESOURCE_DESC desc = src.desc;
|
||||
desc.Format = DXGI_FORMAT_R10G10B10A2_UNORM;
|
||||
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||
|
||||
if (!CreateDefaultTexture(device, desc, m_dst))
|
||||
desc.Flags = own ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS :
|
||||
dst.desc.Flags;
|
||||
if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
|
||||
return PostProcessStatus::FAILED;
|
||||
|
||||
if (own && !CreateDefaultTexture(device, desc, m_dst))
|
||||
return PostProcessStatus::FAILED;
|
||||
|
||||
m_outDesc = desc;
|
||||
m_threadsX = Groups((unsigned)desc.Width);
|
||||
m_threadsY = Groups(desc.Height);
|
||||
|
||||
@@ -118,19 +136,43 @@ ComPtr<ID3D12Resource> CHDR16to10Effect::Run(
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!m_dst || !Draw(device, commandList, src, m_dst.Get(),
|
||||
dirtyRects, nbDirtyRects))
|
||||
return nullptr;
|
||||
return m_dst;
|
||||
}
|
||||
|
||||
bool CHDR16to10Effect::Run(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
if (!device || !commandList || !src || src.Get() == dst || !IsDst(dst))
|
||||
return false;
|
||||
return Draw(device, commandList, src, dst,
|
||||
dirtyRects, nbDirtyRects);
|
||||
}
|
||||
|
||||
bool CHDR16to10Effect::Draw(
|
||||
const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dirtyRects);
|
||||
UNREFERENCED_PARAMETER(nbDirtyRects);
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_COMMON,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
CBV(device, 0, m_constBuffer.Get(), sizeof(m_consts));
|
||||
SRV(device, 1, src.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT);
|
||||
UAV(device, 2, m_dst.Get(), DXGI_FORMAT_R10G10B10A2_UNORM);
|
||||
UAV(device, 2, dst, DXGI_FORMAT_R10G10B10A2_UNORM);
|
||||
Dispatch(commandList);
|
||||
|
||||
TransitionDst(commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
TransitionDst(commandList, dst, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_COMMON);
|
||||
return m_dst;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,13 @@ private:
|
||||
} m_consts = { 80.0f };
|
||||
ComPtr<ID3D12Resource> m_constBuffer;
|
||||
|
||||
PostProcessStatus Set(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst, bool own);
|
||||
bool Draw(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
|
||||
public:
|
||||
const char * GetName() const override { return "HDR16to10"; }
|
||||
|
||||
@@ -38,9 +45,17 @@ public:
|
||||
|
||||
PostProcessStatus SetFormat(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst) override;
|
||||
// Configures shader state without allocating the legacy-owned output.
|
||||
PostProcessStatus Cfg(const ComPtr<ID3D12Device3>& device,
|
||||
const D12FrameFormat& src, D12FrameFormat& dst);
|
||||
|
||||
ComPtr<ID3D12Resource> Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, RECT dirtyRects[],
|
||||
unsigned * nbDirtyRects) override;
|
||||
// dst must match Cfg's output and be in COMMON; Run restores COMMON.
|
||||
bool Run(const ComPtr<ID3D12Device3>& device,
|
||||
const ComPtr<ID3D12GraphicsCommandList>& commandList,
|
||||
const ComPtr<ID3D12Resource>& src, ID3D12Resource * dst,
|
||||
RECT dirtyRects[], unsigned * nbDirtyRects);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user