mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-08-26 08:06:33 +00:00
Reduced swapchain queries
This commit is contained in:
@@ -233,6 +233,7 @@ class State
|
||||
ID3D11Device* currentD3D11Device = nullptr;
|
||||
ID3D12CommandQueue* currentCommandQueue = nullptr;
|
||||
VkDevice currentVkDevice = nullptr;
|
||||
DXGI_SWAP_CHAIN_DESC currentSwapchainDesc {};
|
||||
|
||||
std::vector<ID3D12Device*> d3d12Devices;
|
||||
std::vector<ID3D11Device*> d3d11Devices;
|
||||
|
||||
@@ -228,12 +228,7 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
return true;
|
||||
}
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
if (State::Instance().currentSwapchain->GetDesc(&scDesc) != S_OK)
|
||||
{
|
||||
LOG_WARN("Can't get swapchain desc!");
|
||||
return false;
|
||||
}
|
||||
auto& s = State::Instance();
|
||||
|
||||
// There are all these chacks because looks like ResTracker is still missing some resources
|
||||
// Need check more docs about D3D12 resource/heap usage
|
||||
@@ -246,12 +241,15 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
auto resDesc = resource->buffer->GetDesc();
|
||||
|
||||
// dimensions not match
|
||||
if (resDesc.Height != scDesc.BufferDesc.Height || resDesc.Width != scDesc.BufferDesc.Width)
|
||||
if (resDesc.Height != s.currentSwapchainDesc.BufferDesc.Height ||
|
||||
resDesc.Width != s.currentSwapchainDesc.BufferDesc.Width)
|
||||
{
|
||||
// Extended size check
|
||||
if (!(Config::Instance()->FGRelaxedResolutionCheck.value_or_default() &&
|
||||
resDesc.Height >= scDesc.BufferDesc.Height - 32 && resDesc.Height <= scDesc.BufferDesc.Height + 32 &&
|
||||
resDesc.Width >= scDesc.BufferDesc.Width - 32 && resDesc.Width <= scDesc.BufferDesc.Width + 32))
|
||||
resDesc.Height >= s.currentSwapchainDesc.BufferDesc.Height - 32 &&
|
||||
resDesc.Height <= s.currentSwapchainDesc.BufferDesc.Height + 32 &&
|
||||
resDesc.Width >= s.currentSwapchainDesc.BufferDesc.Width - 32 &&
|
||||
resDesc.Width <= s.currentSwapchainDesc.BufferDesc.Width + 32))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -269,11 +267,12 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
}
|
||||
|
||||
// format match
|
||||
if (resDesc.Format == scDesc.BufferDesc.Format)
|
||||
if (resDesc.Format == s.currentSwapchainDesc.BufferDesc.Format)
|
||||
{
|
||||
LOG_DEBUG("Width: {}/{}, Height: {}/{}, Format: {}/{}, Resource: {:X}, convertFormat: {} -> TRUE",
|
||||
resDesc.Width, scDesc.BufferDesc.Width, resDesc.Height, scDesc.BufferDesc.Height,
|
||||
(UINT) resDesc.Format, (UINT) scDesc.BufferDesc.Format, (size_t) resource->buffer,
|
||||
resDesc.Width, s.currentSwapchainDesc.BufferDesc.Width, resDesc.Height,
|
||||
s.currentSwapchainDesc.BufferDesc.Height, (UINT) resDesc.Format,
|
||||
(UINT) s.currentSwapchainDesc.BufferDesc.Format, (size_t) resource->buffer,
|
||||
Config::Instance()->FGHUDFixExtended.value_or_default());
|
||||
|
||||
return true;
|
||||
@@ -294,25 +293,26 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
resDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM || resDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ||
|
||||
resDesc.Format == DXGI_FORMAT_B8G8R8A8_TYPELESS || resDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM ||
|
||||
resDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB) &&
|
||||
(scDesc.BufferDesc.Format == DXGI_FORMAT_R10G10B10A2_UNORM ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R10G10B10A2_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R16G16B16A16_FLOAT ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R16G16B16A16_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R11G11B10_FLOAT ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32A32_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32_FLOAT ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_TYPELESS ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM ||
|
||||
scDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB))
|
||||
(s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R10G10B10A2_UNORM ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R10G10B10A2_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R16G16B16A16_FLOAT ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R16G16B16A16_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R11G11B10_FLOAT ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32A32_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32_FLOAT ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R32G32B32_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_TYPELESS ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM ||
|
||||
s.currentSwapchainDesc.BufferDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB))
|
||||
{
|
||||
LOG_DEBUG("Width: {}/{}, Height: {}/{}, Format: {}/{}, Resource: {:X}, convertFormat: {} -> TRUE",
|
||||
resDesc.Width, scDesc.BufferDesc.Width, resDesc.Height, scDesc.BufferDesc.Height,
|
||||
(UINT) resDesc.Format, (UINT) scDesc.BufferDesc.Format, (size_t) resource->buffer,
|
||||
resDesc.Width, s.currentSwapchainDesc.BufferDesc.Width, resDesc.Height,
|
||||
s.currentSwapchainDesc.BufferDesc.Height, (UINT) resDesc.Format,
|
||||
(UINT) s.currentSwapchainDesc.BufferDesc.Format, (size_t) resource->buffer,
|
||||
Config::Instance()->FGHUDFixExtended.value_or_default());
|
||||
|
||||
return true;
|
||||
@@ -438,7 +438,9 @@ bool Hudfix_Dx12::SkipHudlessChecks() { return _skipHudlessChecks; }
|
||||
bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandList* cmdList, ResourceInfo* resource,
|
||||
D3D12_RESOURCE_STATES state, bool ignoreBlocked)
|
||||
{
|
||||
if (State::Instance().currentFG == nullptr)
|
||||
auto& s = State::Instance();
|
||||
|
||||
if (s.currentFG == nullptr)
|
||||
return false;
|
||||
|
||||
if (!IsResourceCheckActive())
|
||||
@@ -449,7 +451,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
if (!CheckResource(resource))
|
||||
break;
|
||||
|
||||
CapturedHudlessInfo* capturedHudlessInfo = &State::Instance().CapturedHudlesses[resource->buffer];
|
||||
CapturedHudlessInfo* capturedHudlessInfo = &s.CapturedHudlesses[resource->buffer];
|
||||
if (capturedHudlessInfo != nullptr && !capturedHudlessInfo->enabled)
|
||||
{
|
||||
LOG_DEBUG("Skipping {:X}, disabled from captured hudless list!", (size_t) resource->buffer);
|
||||
@@ -457,7 +459,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
}
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
if (State::Instance().currentSwapchain->GetDesc(&scDesc) != S_OK)
|
||||
if (s.currentSwapchain->GetDesc(&scDesc) != S_OK)
|
||||
{
|
||||
LOG_WARN("Can't get swapchain desc!");
|
||||
break;
|
||||
@@ -577,7 +579,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
// Make a copy of resource to capture current state
|
||||
if (!resource->extended)
|
||||
{
|
||||
if (CreateBufferResource(State::Instance().currentD3D12Device, resource, D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
if (CreateBufferResource(s.currentD3D12Device, resource, D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
&_captureBuffer[fIndex]))
|
||||
{
|
||||
LOG_DEBUG("Create a copy of resource: {:X}", (size_t) resource->buffer);
|
||||
@@ -603,9 +605,9 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CreateBufferResourceWithSize(State::Instance().currentD3D12Device, resource,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST, &_captureBuffer[fIndex],
|
||||
scDesc.BufferDesc.Width, scDesc.BufferDesc.Height))
|
||||
if (CreateBufferResourceWithSize(s.currentD3D12Device, resource, D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
&_captureBuffer[fIndex], scDesc.BufferDesc.Width,
|
||||
scDesc.BufferDesc.Height))
|
||||
{
|
||||
LOG_DEBUG("Create a copy of resource: {:X}", (size_t) resource->buffer);
|
||||
|
||||
@@ -662,7 +664,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
}
|
||||
}
|
||||
|
||||
auto fg = reinterpret_cast<IFGFeature_Dx12*>(State::Instance().currentFG);
|
||||
auto fg = reinterpret_cast<IFGFeature_Dx12*>(s.currentFG);
|
||||
UINT64 interpolationRectWidth = 0;
|
||||
UINT interpolationRectHeight = 0;
|
||||
if (fg != nullptr)
|
||||
@@ -672,25 +674,16 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
uint32_t top = 0;
|
||||
|
||||
// use swapchain buffer info
|
||||
DXGI_SWAP_CHAIN_DESC scDesc1 {};
|
||||
if (State::Instance().currentSwapchain->GetDesc(&scDesc1) == S_OK)
|
||||
{
|
||||
LOG_DEBUG("SwapChain Res: {}x{}, Upscaler Display Res: {}x{}", scDesc1.BufferDesc.Width,
|
||||
scDesc1.BufferDesc.Height, interpolationRectWidth, interpolationRectHeight);
|
||||
LOG_DEBUG("SwapChain Res: {}x{}, Upscaler Display Res: {}x{}", s.currentSwapchainDesc.BufferDesc.Width,
|
||||
s.currentSwapchainDesc.BufferDesc.Height, interpolationRectWidth, interpolationRectHeight);
|
||||
|
||||
auto calculatedLeft = ((int) scDesc1.BufferDesc.Width - (int) interpolationRectWidth) / 2;
|
||||
if (calculatedLeft > 0)
|
||||
left = Config::Instance()->FGRectLeft.value_or(calculatedLeft);
|
||||
auto calculatedLeft = ((int) s.currentSwapchainDesc.BufferDesc.Width - (int) interpolationRectWidth) / 2;
|
||||
if (calculatedLeft > 0)
|
||||
left = Config::Instance()->FGRectLeft.value_or(calculatedLeft);
|
||||
|
||||
auto calculatedTop = ((int) scDesc1.BufferDesc.Height - (int) interpolationRectHeight) / 2;
|
||||
if (calculatedTop > 0)
|
||||
top = Config::Instance()->FGRectTop.value_or(calculatedTop);
|
||||
}
|
||||
else
|
||||
{
|
||||
left = Config::Instance()->FGRectLeft.value_or(0);
|
||||
top = Config::Instance()->FGRectTop.value_or(0);
|
||||
}
|
||||
auto calculatedTop = ((int) s.currentSwapchainDesc.BufferDesc.Height - (int) interpolationRectHeight) / 2;
|
||||
if (calculatedTop > 0)
|
||||
top = Config::Instance()->FGRectTop.value_or(calculatedTop);
|
||||
|
||||
// needs conversion?
|
||||
if (resource->format != scDesc.BufferDesc.Format)
|
||||
@@ -704,14 +697,13 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
delete _formatTransfer[fIndex];
|
||||
|
||||
_formatTransfer[fIndex] = nullptr;
|
||||
State::Instance().skipHeapCapture = true;
|
||||
_formatTransfer[fIndex] =
|
||||
new FT_Dx12("FormatTransfer", State::Instance().currentD3D12Device, scDesc.BufferDesc.Format);
|
||||
State::Instance().skipHeapCapture = false;
|
||||
s.skipHeapCapture = true;
|
||||
_formatTransfer[fIndex] = new FT_Dx12("FormatTransfer", s.currentD3D12Device, scDesc.BufferDesc.Format);
|
||||
s.skipHeapCapture = false;
|
||||
}
|
||||
|
||||
if (_formatTransfer[fIndex] != nullptr &&
|
||||
_formatTransfer[fIndex]->CreateBufferResource(State::Instance().currentD3D12Device, resource->buffer,
|
||||
_formatTransfer[fIndex]->CreateBufferResource(s.currentD3D12Device, resource->buffer,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
// This will prevent resource tracker to check these operations
|
||||
@@ -720,7 +712,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
|
||||
ResourceBarrier(cmdList, _captureBuffer[fIndex], D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
_formatTransfer[fIndex]->Dispatch(State::Instance().currentD3D12Device, cmdList, _captureBuffer[fIndex],
|
||||
_formatTransfer[fIndex]->Dispatch(s.currentD3D12Device, cmdList, _captureBuffer[fIndex],
|
||||
_formatTransfer[fIndex]->Buffer());
|
||||
ResourceBarrier(cmdList, _captureBuffer[fIndex], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST);
|
||||
@@ -774,11 +766,11 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
}
|
||||
}
|
||||
|
||||
if (State::Instance().FGcaptureResources)
|
||||
if (s.FGcaptureResources)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_captureMutex);
|
||||
_captureList.insert(resource->buffer);
|
||||
State::Instance().FGcapturedResourceCount = _captureList.size();
|
||||
s.FGcapturedResourceCount = _captureList.size();
|
||||
}
|
||||
|
||||
LOG_DEBUG("Calling FG with hudless");
|
||||
@@ -791,7 +783,7 @@ bool Hudfix_Dx12::CheckForHudless(std::string callerName, ID3D12GraphicsCommandL
|
||||
if (capturedHudlessInfo != nullptr)
|
||||
capturedHudlessInfo->usageCount++;
|
||||
else
|
||||
State::Instance().CapturedHudlesses[resource->buffer] = {};
|
||||
s.CapturedHudlesses[resource->buffer] = {};
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -417,18 +417,16 @@ static Fsr3::FfxErrorCode hkffxRegisterFrameinterpolationUiResourceDX12(Fsr3::Ff
|
||||
{
|
||||
LOG_DEBUG("UiResource found 1: {:X}", (size_t) uiResource.resource);
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg->FrameGenerationContext() != nullptr && uiResource.resource != nullptr)
|
||||
{
|
||||
UINT width = 0;
|
||||
UINT height = 0;
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
|
||||
Dx12Resource ui {};
|
||||
ui.cmdList = nullptr; // Not sure about this
|
||||
@@ -569,7 +567,8 @@ static Fsr3::FfxErrorCode hkffxFrameInterpolationDispatch(FfxFrameInterpolationC
|
||||
if (context == nullptr || params == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg == nullptr)
|
||||
{
|
||||
@@ -595,11 +594,8 @@ static Fsr3::FfxErrorCode hkffxFrameInterpolationDispatch(FfxFrameInterpolationC
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -627,11 +623,8 @@ static Fsr3::FfxErrorCode hkffxFrameInterpolationDispatch(FfxFrameInterpolationC
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -673,7 +666,8 @@ static Fsr3::FfxErrorCode hkffxFsr3ConfigureFrameGeneration(void* context, Fsr3:
|
||||
if (context == nullptr || config == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg == nullptr)
|
||||
{
|
||||
@@ -685,7 +679,7 @@ static Fsr3::FfxErrorCode hkffxFsr3ConfigureFrameGeneration(void* context, Fsr3:
|
||||
{
|
||||
LOG_DEBUG("frameGenerationEnabled: {} ", config->frameGenerationEnabled);
|
||||
|
||||
State::Instance().FSRFGInputActive = config->frameGenerationEnabled;
|
||||
s.FSRFGInputActive = config->frameGenerationEnabled;
|
||||
|
||||
if (config->frameGenerationEnabled && !fg->IsActive() && Config::Instance()->FGEnabled.value_or_default())
|
||||
{
|
||||
@@ -708,11 +702,8 @@ static Fsr3::FfxErrorCode hkffxFsr3ConfigureFrameGeneration(void* context, Fsr3:
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -756,7 +747,8 @@ static Fsr3::FfxErrorCode hkffxSetFrameGenerationConfigToSwapchainDX12(Fsr3::Ffx
|
||||
if (config == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg == nullptr)
|
||||
{
|
||||
@@ -768,7 +760,7 @@ static Fsr3::FfxErrorCode hkffxSetFrameGenerationConfigToSwapchainDX12(Fsr3::Ffx
|
||||
{
|
||||
LOG_DEBUG("frameGenerationEnabled: {} ", config->frameGenerationEnabled);
|
||||
|
||||
State::Instance().FSRFGInputActive = config->frameGenerationEnabled;
|
||||
s.FSRFGInputActive = config->frameGenerationEnabled;
|
||||
|
||||
if (config->frameGenerationEnabled && !fg->IsActive() && Config::Instance()->FGEnabled.value_or_default())
|
||||
{
|
||||
@@ -791,11 +783,8 @@ static Fsr3::FfxErrorCode hkffxSetFrameGenerationConfigToSwapchainDX12(Fsr3::Ffx
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
@@ -163,6 +163,8 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
|
||||
LOG_DEBUG("");
|
||||
|
||||
auto& s = State::Instance();
|
||||
|
||||
if (desc->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION)
|
||||
{
|
||||
ffxCreateContextDescHeader* next = nullptr;
|
||||
@@ -180,14 +182,14 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
}
|
||||
}
|
||||
|
||||
if (_device != nullptr && State::Instance().currentFG != nullptr)
|
||||
if (_device != nullptr && s.currentFG != nullptr)
|
||||
{
|
||||
if (State::Instance().currentFG->FrameGenerationContext() != nullptr)
|
||||
if (s.currentFG->FrameGenerationContext() != nullptr)
|
||||
{
|
||||
LOG_INFO("There is already an active FG context: {:X}, destroying it.",
|
||||
(size_t) State::Instance().currentFG->FrameGenerationContext());
|
||||
(size_t) s.currentFG->FrameGenerationContext());
|
||||
|
||||
State::Instance().currentFG->DestroyFGContext();
|
||||
s.currentFG->DestroyFGContext();
|
||||
}
|
||||
|
||||
auto ccDesc = (ffxCreateContextDescFrameGeneration*) desc;
|
||||
@@ -223,7 +225,7 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
LOG_DEBUG("XeFG HighResMV: {}", Config::Instance()->FGXeFGHighResMV.value_or_default());
|
||||
Config::Instance()->SaveXeFG();
|
||||
|
||||
State::Instance().currentFG->CreateContext(_device, _fgConst);
|
||||
s.currentFG->CreateContext(_device, _fgConst);
|
||||
|
||||
*context = (ffxContext) fgContext;
|
||||
return FFX_API_RETURN_OK;
|
||||
@@ -233,16 +235,15 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
{
|
||||
auto cDesc = (ffxCreateContextDescFrameGenerationSwapChainWrapDX12*) desc;
|
||||
|
||||
if (State::Instance().currentFG != nullptr && State::Instance().currentFGSwapchain != nullptr)
|
||||
if (s.currentFG != nullptr && s.currentFGSwapchain != nullptr)
|
||||
{
|
||||
*context = (ffxContext) scContext; // State::Instance().currentFG->SwapchainContext();
|
||||
*cDesc->swapchain = (IDXGISwapChain4*) State::Instance().currentFGSwapchain;
|
||||
*context = (ffxContext) scContext; // s.currentFG->SwapchainContext();
|
||||
*cDesc->swapchain = (IDXGISwapChain4*) s.currentFGSwapchain;
|
||||
return FFX_API_RETURN_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("currentFG: {:X}, currentFGSwapchain: {:X}", (size_t) State::Instance().currentFG,
|
||||
(size_t) State::Instance().currentFGSwapchain);
|
||||
LOG_ERROR("currentFG: {:X}, currentFGSwapchain: {:X}", (size_t) s.currentFG, (size_t) s.currentFGSwapchain);
|
||||
return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -256,7 +257,7 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
{
|
||||
LOG_INFO("Swapchain created");
|
||||
|
||||
if (State::Instance().currentFG != nullptr && State::Instance().currentFGSwapchain != nullptr)
|
||||
if (s.currentFG != nullptr && s.currentFGSwapchain != nullptr)
|
||||
{
|
||||
*context = (ffxContext) scContext;
|
||||
return FFX_API_RETURN_OK;
|
||||
@@ -264,7 +265,7 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
else
|
||||
{
|
||||
LOG_ERROR("FG Swapchain creation error, currentFG: {:X}, currentFGSwapchain: {:X}",
|
||||
(size_t) State::Instance().currentFG, (size_t) State::Instance().currentFGSwapchain);
|
||||
(size_t) s.currentFG, (size_t) s.currentFGSwapchain);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -293,7 +294,7 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
{
|
||||
LOG_INFO("Swapchain created");
|
||||
|
||||
if (State::Instance().currentFG != nullptr && State::Instance().currentFGSwapchain != nullptr)
|
||||
if (s.currentFG != nullptr && s.currentFGSwapchain != nullptr)
|
||||
{
|
||||
*context = (ffxContext) scContext;
|
||||
return FFX_API_RETURN_OK;
|
||||
@@ -301,7 +302,7 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
|
||||
else
|
||||
{
|
||||
LOG_ERROR("FG Swapchain creation error, currentFG: {:X}, currentFGSwapchain: {:X}",
|
||||
(size_t) State::Instance().currentFG, (size_t) State::Instance().currentFGSwapchain);
|
||||
(size_t) s.currentFG, (size_t) s.currentFGSwapchain);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -372,7 +373,8 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader*
|
||||
return (ffxReturnCode_t) 0xFFFFFFFF;
|
||||
#endif
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg == nullptr)
|
||||
{
|
||||
@@ -399,7 +401,7 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader*
|
||||
LOG_DEBUG("FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION frameID: {}, enabled: {} ", cDesc->frameID,
|
||||
cDesc->frameGenerationEnabled);
|
||||
|
||||
State::Instance().FSRFGInputActive = cDesc->frameGenerationEnabled;
|
||||
s.FSRFGInputActive = cDesc->frameGenerationEnabled;
|
||||
|
||||
if (cDesc->frameGenerationEnabled && !fg->IsActive() && Config::Instance()->FGEnabled.value_or_default())
|
||||
{
|
||||
@@ -422,11 +424,8 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader*
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -563,11 +562,8 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader*
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -649,11 +645,8 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader*
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -805,7 +798,8 @@ ffxReturnCode_t ffxDispatch_Dx12FG(ffxContext* context, ffxDispatchDescHeader* d
|
||||
return (ffxReturnCode_t) 0xFFFFFFFF;
|
||||
#endif
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
auto& s = State::Instance();
|
||||
auto fg = s.currentFG;
|
||||
|
||||
if (fg == nullptr)
|
||||
{
|
||||
@@ -817,7 +811,6 @@ ffxReturnCode_t ffxDispatch_Dx12FG(ffxContext* context, ffxDispatchDescHeader* d
|
||||
{
|
||||
auto cdDesc = (ffxDispatchDescFrameGeneration*) desc;
|
||||
|
||||
auto fg = State::Instance().currentFG;
|
||||
if (fg != nullptr)
|
||||
{
|
||||
fg->SetInterpolationPos(cdDesc->generationRect.left, cdDesc->generationRect.top);
|
||||
@@ -833,11 +826,8 @@ ffxReturnCode_t ffxDispatch_Dx12FG(ffxContext* context, ffxDispatchDescHeader* d
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
State::Instance().currentFGSwapchain->GetDesc(&scDesc);
|
||||
|
||||
width = scDesc.BufferDesc.Width;
|
||||
height = scDesc.BufferDesc.Height;
|
||||
width = s.currentSwapchainDesc.BufferDesc.Width;
|
||||
height = s.currentSwapchainDesc.BufferDesc.Height;
|
||||
top = 0;
|
||||
left = 0;
|
||||
}
|
||||
@@ -874,7 +864,7 @@ ffxReturnCode_t ffxDispatch_Dx12FG(ffxContext* context, ffxDispatchDescHeader* d
|
||||
}
|
||||
}
|
||||
|
||||
auto device = _device == nullptr ? State::Instance().currentD3D12Device : _device;
|
||||
auto device = _device == nullptr ? s.currentD3D12Device : _device;
|
||||
fg->EvaluateState(device, _fgConst);
|
||||
|
||||
if (!fg->IsActive() || fg->IsPaused())
|
||||
|
||||
@@ -3396,28 +3396,25 @@ bool MenuCommon::RenderMenu()
|
||||
|
||||
if (state.isHdrActive)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
if (state.currentSwapchain->GetDesc(&scDesc) == S_OK)
|
||||
// DXGI_FORMAT_R32G32B32A32_TYPELESS = 1
|
||||
// DXGI_FORMAT_R32G32B32A32_FLOAT
|
||||
// DXGI_FORMAT_R32G32B32A32_UINT
|
||||
// DXGI_FORMAT_R32G32B32A32_SINT
|
||||
// DXGI_FORMAT_R32G32B32_TYPELESS
|
||||
// DXGI_FORMAT_R32G32B32_FLOAT
|
||||
// DXGI_FORMAT_R32G32B32_UINT
|
||||
// DXGI_FORMAT_R32G32B32_SINT
|
||||
// DXGI_FORMAT_R16G16B16A16_TYPELESS
|
||||
// DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||
// DXGI_FORMAT_R16G16B16A16_UNORM
|
||||
// DXGI_FORMAT_R16G16B16A16_UINT
|
||||
// DXGI_FORMAT_R16G16B16A16_SNORM
|
||||
// DXGI_FORMAT_R16G16B16A16_SINT = 14
|
||||
if (state.currentSwapchainDesc.BufferDesc.Format > 0 &&
|
||||
state.currentSwapchainDesc.BufferDesc.Format < 15)
|
||||
{
|
||||
// DXGI_FORMAT_R32G32B32A32_TYPELESS = 1
|
||||
// DXGI_FORMAT_R32G32B32A32_FLOAT
|
||||
// DXGI_FORMAT_R32G32B32A32_UINT
|
||||
// DXGI_FORMAT_R32G32B32A32_SINT
|
||||
// DXGI_FORMAT_R32G32B32_TYPELESS
|
||||
// DXGI_FORMAT_R32G32B32_FLOAT
|
||||
// DXGI_FORMAT_R32G32B32_UINT
|
||||
// DXGI_FORMAT_R32G32B32_SINT
|
||||
// DXGI_FORMAT_R16G16B16A16_TYPELESS
|
||||
// DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||
// DXGI_FORMAT_R16G16B16A16_UNORM
|
||||
// DXGI_FORMAT_R16G16B16A16_UINT
|
||||
// DXGI_FORMAT_R16G16B16A16_SNORM
|
||||
// DXGI_FORMAT_R16G16B16A16_SINT = 14
|
||||
if (scDesc.BufferDesc.Format > 0 && scDesc.BufferDesc.Format < 15)
|
||||
{
|
||||
cantActivate = true;
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.f), "XeFG only supports HDR10");
|
||||
}
|
||||
cantActivate = true;
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.f), "XeFG only supports HDR10");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ static thread_local HeapCacheTLS cacheCR;
|
||||
|
||||
bool ResTrack_Dx12::CheckResource(ID3D12Resource* resource)
|
||||
{
|
||||
if (State::Instance().currentSwapchain == nullptr || State::Instance().isShuttingDown)
|
||||
if (State::Instance().isShuttingDown)
|
||||
return false;
|
||||
|
||||
auto resDesc = resource->GetDesc();
|
||||
@@ -146,19 +146,16 @@ bool ResTrack_Dx12::CheckResource(ID3D12Resource* resource)
|
||||
if (State::Instance().frameCount == 0)
|
||||
return false;
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC scDesc {};
|
||||
if (State::Instance().currentSwapchain->GetDesc(&scDesc) != S_OK)
|
||||
{
|
||||
LOG_WARN("Can't get swapchain desc!");
|
||||
return false;
|
||||
}
|
||||
auto& s = State::Instance();
|
||||
|
||||
if (resDesc.Height != scDesc.BufferDesc.Height || resDesc.Width != scDesc.BufferDesc.Width)
|
||||
if (resDesc.Height != s.currentSwapchainDesc.BufferDesc.Height ||
|
||||
resDesc.Width != s.currentSwapchainDesc.BufferDesc.Width)
|
||||
{
|
||||
auto result = Config::Instance()->FGRelaxedResolutionCheck.value_or_default() &&
|
||||
resDesc.Height >= scDesc.BufferDesc.Height - 32 &&
|
||||
resDesc.Height <= scDesc.BufferDesc.Height + 32 &&
|
||||
resDesc.Width >= scDesc.BufferDesc.Width - 32 && resDesc.Width <= scDesc.BufferDesc.Width + 32;
|
||||
resDesc.Height >= s.currentSwapchainDesc.BufferDesc.Height - 32 &&
|
||||
resDesc.Height <= s.currentSwapchainDesc.BufferDesc.Height + 32 &&
|
||||
resDesc.Width >= s.currentSwapchainDesc.BufferDesc.Width - 32 &&
|
||||
resDesc.Width <= s.currentSwapchainDesc.BufferDesc.Width + 32;
|
||||
|
||||
// LOG_TRACK("Resource: {}x{} ({}), Swapchain: {}x{} ({}), Relaxed Result: {}", resDesc.Width, resDesc.Height,
|
||||
// (UINT) resDesc.Format, scDesc.BufferDesc.Width, scDesc.BufferDesc.Height,
|
||||
|
||||
@@ -59,6 +59,10 @@ static HRESULT LocalPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT
|
||||
State::Instance().lastFGFrameTime = ftDelta;
|
||||
|
||||
LOG_DEBUG("SyncInterval: {}, Flags: {:X}, Frametime: {:0.3f} ms", SyncInterval, Flags, ftDelta);
|
||||
|
||||
// Update swapchain info evey frame
|
||||
if (pSwapChain->GetDesc(&State::Instance().currentSwapchainDesc) != S_OK)
|
||||
LOG_WARN("Can't get swapchain desc!");
|
||||
}
|
||||
|
||||
ID3D11Device* device = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user