Files
LookingGlass/idd/LGIdd/CFrameBufferResource.cpp
Geoffrey McRae 69f44a003d
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled
[all] refresh copyright
2026-05-31 15:13:57 +10:00

134 lines
3.7 KiB
C++

/**
* 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 "CFrameBufferResource.h"
#include "CSwapChainProcessor.h"
#include "CDebug.h"
bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, unsigned frameIndex, uint8_t * base, size_t size)
{
m_frameIndex = frameIndex;
if (size > swapChain->GetDevice()->GetMaxFrameSize())
{
DEBUG_ERROR("Frame size of %lu is too large to fit in available shared ram");
return false;
}
// nothing to do if the resource already exists and is large enough
if (m_base == base && m_size >= size)
{
m_frameSize = size;
return true;
}
Reset();
D3D12_RESOURCE_DESC desc = {};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = size;
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_UNKNOWN;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
HRESULT hr;
const WCHAR * resName;
if (swapChain->GetD3D12Device()->IsIndirectCopy())
{
DEBUG_TRACE("Creating standard resource for %p", base);
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_READBACK;
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
heapProps.CreationNodeMask = 1;
heapProps.VisibleNodeMask = 1;
hr = swapChain->GetD3D12Device()->GetDevice()->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&desc,
D3D12_RESOURCE_STATE_COPY_DEST,
NULL,
IID_PPV_ARGS(&m_res)
);
resName = L"STAGING";
if (SUCCEEDED(hr))
{
D3D12_RANGE range = {0, 0};
hr = m_res->Map(0, &range, &m_map);
if (FAILED(hr))
{
DEBUG_ERROR_HR(hr, "Failed to map the resource");
return false;
}
}
}
else
{
DEBUG_TRACE("Creating ivshmem resource for %p", base);
desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER;
hr = swapChain->GetD3D12Device()->GetDevice()->CreatePlacedResource(
swapChain->GetD3D12Device()->GetHeap().Get(),
(uintptr_t)base - (uintptr_t)swapChain->GetDevice()->GetIVSHMEM().GetMem(),
&desc,
D3D12_RESOURCE_STATE_COPY_DEST,
NULL,
IID_PPV_ARGS(&m_res)
);
resName = L"IVSHMEM";
}
if (FAILED(hr))
{
DEBUG_ERROR_HR(hr, "Failed to create the FrameBuffer ID3D12Resource");
return false;
}
m_res->SetName(resName);
m_base = base;
m_size = size;
m_frameSize = size;
m_valid = true;
return true;
}
void CFrameBufferResource::Reset()
{
if (m_map)
{
m_res->Unmap(0, NULL);
m_map = NULL;
}
m_base = nullptr;
m_size = 0;
m_res.Reset();
m_valid = false;
}