2017-11-29 16:23:33 +01:00
|
|
|
#include "d3d11_device.h"
|
2018-01-21 18:04:22 +01:00
|
|
|
#include "d3d11_context_imm.h"
|
2017-11-29 16:23:33 +01:00
|
|
|
#include "d3d11_present.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-08-05 16:40:03 +02:00
|
|
|
D3D11VkBackBuffer::D3D11VkBackBuffer(D3D11Texture2D* pTexture)
|
|
|
|
: m_texture(pTexture) {
|
|
|
|
m_texture->AddRefPrivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11VkBackBuffer::~D3D11VkBackBuffer() {
|
|
|
|
m_texture->ReleasePrivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 19:06:00 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11VkBackBuffer::QueryInterface(REFIID riid, void** ppvObject) {
|
2017-12-19 16:01:50 +01:00
|
|
|
return m_texture->QueryInterface(riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 19:06:00 +02:00
|
|
|
Rc<DxvkImage> D3D11VkBackBuffer::GetDXVKImage() {
|
2018-03-14 00:45:07 +01:00
|
|
|
return m_texture->GetCommonTexture()->GetImage();
|
2017-12-19 16:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
D3D11Presenter:: D3D11Presenter(
|
|
|
|
IDXGIObject* pContainer,
|
|
|
|
ID3D11Device* pDevice)
|
|
|
|
: m_container(pContainer), m_device(pDevice) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11Presenter::~D3D11Presenter() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11Presenter::AddRef() {
|
|
|
|
return m_container->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11Presenter::Release() {
|
|
|
|
return m_container->Release();
|
|
|
|
}
|
2017-11-29 16:23:33 +01:00
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Presenter::QueryInterface(REFIID riid, void** ppvObject) {
|
|
|
|
return m_container->QueryInterface(riid, ppvObject);
|
2017-11-29 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Presenter::CreateSwapChainBackBuffer(
|
2018-05-23 01:06:34 +02:00
|
|
|
const DXGI_SWAP_CHAIN_DESC1* pSwapChainDesc,
|
2018-03-28 21:24:52 +02:00
|
|
|
IDXGIVkBackBuffer** ppInterface) {
|
2018-03-13 23:51:30 +01:00
|
|
|
D3D11_COMMON_TEXTURE_DESC desc;
|
2018-06-21 10:12:38 +02:00
|
|
|
desc.Width = std::max(pSwapChainDesc->Width, 1u);
|
|
|
|
desc.Height = std::max(pSwapChainDesc->Height, 1u);
|
2018-03-13 23:51:30 +01:00
|
|
|
desc.Depth = 1;
|
2017-11-29 16:23:33 +01:00
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
2018-05-23 01:06:34 +02:00
|
|
|
desc.Format = pSwapChainDesc->Format;
|
2017-11-29 16:23:33 +01:00
|
|
|
desc.SampleDesc = pSwapChainDesc->SampleDesc;
|
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.BindFlags = D3D11_BIND_RENDER_TARGET
|
2018-03-12 13:03:33 +01:00
|
|
|
| D3D11_BIND_SHADER_RESOURCE;
|
2017-11-29 16:23:33 +01:00
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.MiscFlags = 0;
|
2018-06-21 10:12:38 +02:00
|
|
|
|
2018-03-12 13:03:33 +01:00
|
|
|
if (pSwapChainDesc->BufferUsage & DXGI_USAGE_UNORDERED_ACCESS)
|
|
|
|
desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
|
|
|
|
|
2017-12-19 16:01:50 +01:00
|
|
|
try {
|
2018-03-28 19:06:00 +02:00
|
|
|
*ppInterface = ref(new D3D11VkBackBuffer(
|
2018-03-28 21:24:52 +02:00
|
|
|
new D3D11Texture2D(static_cast<D3D11Device*>(m_device), &desc)));
|
2017-12-19 16:01:50 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-11-29 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Presenter::FlushRenderingCommands() {
|
2018-01-21 02:57:36 +01:00
|
|
|
Com<ID3D11DeviceContext> deviceContext = nullptr;
|
|
|
|
m_device->GetImmediateContext(&deviceContext);
|
2017-11-29 16:23:33 +01:00
|
|
|
|
2018-01-21 18:04:22 +01:00
|
|
|
// The presentation code is run from the main rendering thread
|
|
|
|
// rather than the command stream thread, so we synchronize.
|
|
|
|
auto immediateContext = static_cast<D3D11ImmediateContext*>(deviceContext.ptr());
|
|
|
|
immediateContext->Flush();
|
|
|
|
immediateContext->SynchronizeCsThread();
|
2017-11-29 16:23:33 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Presenter::GetDevice(REFGUID riid, void** ppvDevice) {
|
2017-11-29 16:23:33 +01:00
|
|
|
return m_device->QueryInterface(riid, ppvDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|