2017-10-15 21:38:09 +02:00
|
|
|
#include "d3d11_buffer.h"
|
2017-12-13 17:49:08 +01:00
|
|
|
#include "d3d11_context.h"
|
2017-10-15 21:38:09 +02:00
|
|
|
#include "d3d11_device.h"
|
|
|
|
|
2017-12-13 17:49:08 +01:00
|
|
|
#include "../dxvk/dxvk_data.h"
|
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D11Buffer::D3D11Buffer(
|
2017-11-29 16:23:33 +01:00
|
|
|
D3D11Device* device,
|
2017-12-07 13:17:16 +01:00
|
|
|
IDXGIBufferResourcePrivate* resource,
|
2017-11-29 16:23:33 +01:00
|
|
|
const D3D11_BUFFER_DESC& desc)
|
|
|
|
: m_device (device),
|
|
|
|
m_resource(resource),
|
|
|
|
m_desc (desc) {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11Buffer::~D3D11Buffer() {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Buffer::QueryInterface(REFIID riid, void** ppvObject) {
|
2017-10-15 21:50:34 +02:00
|
|
|
COM_QUERY_IFACE(riid, ppvObject, IUnknown);
|
|
|
|
COM_QUERY_IFACE(riid, ppvObject, ID3D11DeviceChild);
|
|
|
|
COM_QUERY_IFACE(riid, ppvObject, ID3D11Resource);
|
2017-10-15 21:38:09 +02:00
|
|
|
COM_QUERY_IFACE(riid, ppvObject, ID3D11Buffer);
|
|
|
|
|
2017-11-29 16:23:33 +01:00
|
|
|
if (riid == __uuidof(IDXGIResource)
|
|
|
|
|| riid == __uuidof(IDXGIBufferResourcePrivate))
|
|
|
|
return m_resource->QueryInterface(riid, ppvObject);
|
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
Logger::warn("D3D11Buffer::QueryInterface: Unknown interface query");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Buffer::GetDevice(ID3D11Device** ppDevice) {
|
2017-12-09 15:57:05 +01:00
|
|
|
*ppDevice = m_device.ref();
|
2017-10-15 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
UINT STDMETHODCALLTYPE D3D11Buffer::GetEvictionPriority() {
|
2017-12-07 13:31:32 +01:00
|
|
|
UINT EvictionPriority = DXGI_RESOURCE_PRIORITY_NORMAL;
|
|
|
|
m_resource->GetEvictionPriority(&EvictionPriority);
|
|
|
|
return EvictionPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Buffer::SetEvictionPriority(UINT EvictionPriority) {
|
2017-12-07 13:31:32 +01:00
|
|
|
m_resource->SetEvictionPriority(EvictionPriority);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Buffer::GetType(D3D11_RESOURCE_DIMENSION* pResourceDimension) {
|
2017-10-15 21:38:09 +02:00
|
|
|
*pResourceDimension = D3D11_RESOURCE_DIMENSION_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Buffer::GetDesc(D3D11_BUFFER_DESC* pDesc) {
|
2017-10-15 21:38:09 +02:00
|
|
|
*pDesc = m_desc;
|
|
|
|
}
|
|
|
|
|
2017-12-07 14:03:15 +01:00
|
|
|
|
2017-12-13 17:49:08 +01:00
|
|
|
HRESULT D3D11Buffer::Map(
|
|
|
|
D3D11DeviceContext* pContext,
|
|
|
|
D3D11_MAP MapType,
|
|
|
|
UINT MapFlags,
|
|
|
|
D3D11_MAPPED_SUBRESOURCE* pMappedSubresource) {
|
|
|
|
const Rc<DxvkBuffer> buffer = GetDXVKBuffer();
|
|
|
|
|
|
|
|
if (buffer->mapPtr(0) == nullptr) {
|
|
|
|
Logger::err("D3D11: Cannot map a device-local buffer");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pMappedSubresource == nullptr)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (!buffer->isInUse()) {
|
|
|
|
// Simple case: The buffer is currently not being
|
|
|
|
// used by the device, we can return the pointer.
|
|
|
|
pMappedSubresource->pData = buffer->mapPtr(0);
|
|
|
|
pMappedSubresource->RowPitch = buffer->info().size;
|
|
|
|
pMappedSubresource->DepthPitch = buffer->info().size;
|
|
|
|
return S_OK;
|
|
|
|
} else {
|
|
|
|
// Don't wait if the application tells us not to
|
|
|
|
if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT)
|
|
|
|
return DXGI_ERROR_WAS_STILL_DRAWING;
|
|
|
|
|
|
|
|
if (MapType == D3D11_MAP_WRITE_DISCARD) {
|
|
|
|
// Instead of synchronizing with the device, which is
|
|
|
|
// highly inefficient, return a host-local buffer to
|
|
|
|
// the application and upload its contents on unmap()
|
|
|
|
// TODO evaluate whether this improves performance
|
|
|
|
m_mapData = new DxvkDataBuffer(buffer->info().size);
|
|
|
|
|
|
|
|
pMappedSubresource->pData = m_mapData->data();
|
|
|
|
pMappedSubresource->RowPitch = buffer->info().size;
|
|
|
|
pMappedSubresource->DepthPitch = buffer->info().size;
|
|
|
|
return S_OK;
|
|
|
|
} else {
|
|
|
|
// We have to wait for the device to complete
|
|
|
|
pContext->Flush();
|
|
|
|
pContext->Synchronize();
|
|
|
|
|
|
|
|
pMappedSubresource->pData = buffer->mapPtr(0);
|
|
|
|
pMappedSubresource->RowPitch = buffer->info().size;
|
|
|
|
pMappedSubresource->DepthPitch = buffer->info().size;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11Buffer::Unmap(
|
|
|
|
D3D11DeviceContext* pContext) {
|
|
|
|
if (m_mapData != nullptr) {
|
|
|
|
const Rc<DxvkContext> context
|
|
|
|
= pContext->GetDXVKContext();
|
|
|
|
|
|
|
|
context->updateBuffer(
|
|
|
|
m_resource->GetDXVKBuffer(),
|
|
|
|
0, m_mapData->size(),
|
|
|
|
m_mapData->data());
|
|
|
|
|
|
|
|
m_mapData = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-07 14:03:15 +01:00
|
|
|
Rc<DxvkBuffer> D3D11Buffer::GetDXVKBuffer() {
|
|
|
|
return m_resource->GetDXVKBuffer();
|
|
|
|
}
|
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
}
|