2018-01-23 09:23:31 +01:00
|
|
|
#include "d3d11_cmdlist.h"
|
|
|
|
#include "d3d11_device.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D11CommandList::D3D11CommandList(
|
2019-10-25 22:08:21 +02:00
|
|
|
D3D11Device* pDevice,
|
|
|
|
D3D11CommandListAllocator* pAllocator)
|
|
|
|
: m_device(pDevice), m_allocator(pAllocator) {
|
|
|
|
|
|
|
|
}
|
2018-01-23 09:23:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
D3D11CommandList::~D3D11CommandList() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-25 21:37:18 +02:00
|
|
|
ULONG STDMETHODCALLTYPE D3D11CommandList::AddRef() {
|
|
|
|
ULONG refCount = m_refCount++;
|
|
|
|
if (!refCount)
|
|
|
|
m_device->AddRef();
|
|
|
|
return refCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11CommandList::Release() {
|
|
|
|
ULONG refCount = --m_refCount;
|
2019-10-25 22:08:21 +02:00
|
|
|
|
|
|
|
if (!refCount) {
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
m_allocator->RecycleCommandList(this);
|
2019-10-25 21:37:18 +02:00
|
|
|
m_device->Release();
|
2019-10-25 22:08:21 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 21:37:18 +02:00
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-23 09:23:31 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11CommandList::QueryInterface(REFIID riid, void** ppvObject) {
|
2019-02-10 08:01:01 +01:00
|
|
|
if (ppvObject == nullptr)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11CommandList)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-01-23 09:23:31 +01:00
|
|
|
|
|
|
|
Logger::warn("D3D11CommandList::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2018-01-23 09:23:31 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11CommandList::GetDevice(ID3D11Device **ppDevice) {
|
|
|
|
*ppDevice = ref(m_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-23 12:16:28 +01:00
|
|
|
UINT STDMETHODCALLTYPE D3D11CommandList::GetContextFlags() {
|
2018-01-23 09:23:31 +01:00
|
|
|
return m_contextFlags;
|
|
|
|
}
|
|
|
|
|
2018-01-23 12:03:26 +01:00
|
|
|
|
2018-08-27 16:07:38 +02:00
|
|
|
void D3D11CommandList::AddChunk(DxvkCsChunkRef&& Chunk) {
|
2018-01-23 12:03:26 +01:00
|
|
|
m_chunks.push_back(std::move(Chunk));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11CommandList::EmitToCommandList(ID3D11CommandList* pCommandList) {
|
|
|
|
auto cmdList = static_cast<D3D11CommandList*>(pCommandList);
|
|
|
|
|
2018-04-28 01:14:57 +02:00
|
|
|
for (const auto& chunk : m_chunks)
|
2018-01-23 12:03:26 +01:00
|
|
|
cmdList->m_chunks.push_back(chunk);
|
2018-06-29 12:44:52 +02:00
|
|
|
|
|
|
|
MarkSubmitted();
|
2018-01-23 12:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-03 20:59:17 +01:00
|
|
|
void D3D11CommandList::EmitToCsThread(DxvkCsThread* CsThread) {
|
2018-04-28 01:14:57 +02:00
|
|
|
for (const auto& chunk : m_chunks)
|
2018-08-27 16:07:38 +02:00
|
|
|
CsThread->dispatchChunk(DxvkCsChunkRef(chunk));
|
2018-06-29 12:44:52 +02:00
|
|
|
|
|
|
|
MarkSubmitted();
|
|
|
|
}
|
2019-10-25 22:08:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11CommandList::Reset() {
|
|
|
|
m_chunks.clear();
|
|
|
|
|
|
|
|
m_contextFlags = 0;
|
|
|
|
m_submitted = false;
|
|
|
|
m_warned = false;
|
|
|
|
}
|
2018-06-29 12:44:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11CommandList::MarkSubmitted() {
|
2018-10-09 16:29:50 +02:00
|
|
|
if (m_submitted.exchange(true) && !m_warned.exchange(true)
|
2018-11-20 10:51:09 +01:00
|
|
|
&& m_device->GetOptions()->dcSingleUseMode) {
|
2018-06-29 12:44:52 +02:00
|
|
|
Logger::warn(
|
2018-10-09 16:29:50 +02:00
|
|
|
"D3D11: Command list submitted multiple times,\n"
|
2018-11-20 10:51:09 +01:00
|
|
|
" but d3d11.dcSingleUseMode is enabled");
|
2018-06-29 12:44:52 +02:00
|
|
|
}
|
2018-01-23 12:03:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 22:08:21 +02:00
|
|
|
|
|
|
|
D3D11CommandListAllocator::D3D11CommandListAllocator(D3D11Device* pDevice)
|
|
|
|
: m_device(pDevice) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11CommandListAllocator::~D3D11CommandListAllocator() {
|
|
|
|
for (uint32_t i = 0; i < m_listCount; i++)
|
|
|
|
delete m_lists[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11CommandList* D3D11CommandListAllocator::AllocCommandList(
|
|
|
|
UINT ContextFlags) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
D3D11CommandList* result = nullptr;
|
|
|
|
|
|
|
|
if (m_listCount)
|
|
|
|
result = m_lists[--m_listCount];
|
|
|
|
else
|
|
|
|
result = new D3D11CommandList(m_device, this);
|
|
|
|
|
|
|
|
result->SetContextFlags(ContextFlags);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11CommandListAllocator::RecycleCommandList(
|
|
|
|
D3D11CommandList* pCommandList) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
|
|
|
if (m_listCount < m_lists.size())
|
|
|
|
m_lists[m_listCount++] = pCommandList;
|
|
|
|
else
|
|
|
|
delete pCommandList;
|
|
|
|
}
|
|
|
|
|
2018-01-23 09:23:31 +01:00
|
|
|
}
|