2018-01-31 01:57:43 +01:00
|
|
|
#include <algorithm>
|
2017-10-11 09:51:48 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-10-15 21:38:09 +02:00
|
|
|
#include "d3d11_buffer.h"
|
2017-12-12 01:07:07 +01:00
|
|
|
#include "d3d11_class_linkage.h"
|
2018-01-23 09:23:31 +01:00
|
|
|
#include "d3d11_context_def.h"
|
2018-01-20 13:22:44 +01:00
|
|
|
#include "d3d11_context_imm.h"
|
2017-10-11 09:51:48 +02:00
|
|
|
#include "d3d11_device.h"
|
2017-12-07 12:45:02 +01:00
|
|
|
#include "d3d11_input_layout.h"
|
2018-04-20 00:19:03 +02:00
|
|
|
#include "d3d11_interop.h"
|
2017-11-29 16:23:33 +01:00
|
|
|
#include "d3d11_present.h"
|
2017-12-29 22:20:31 +01:00
|
|
|
#include "d3d11_query.h"
|
2017-12-09 20:49:56 +01:00
|
|
|
#include "d3d11_sampler.h"
|
2017-12-06 18:54:01 +01:00
|
|
|
#include "d3d11_shader.h"
|
2017-11-29 07:55:44 +01:00
|
|
|
#include "d3d11_texture.h"
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
D3D11DeviceContainer::D3D11DeviceContainer() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11DeviceContainer::~D3D11DeviceContainer() {
|
2018-04-20 00:19:03 +02:00
|
|
|
delete m_d3d11VkInterop;
|
2018-03-28 21:24:52 +02:00
|
|
|
delete m_d3d11Presenter;
|
|
|
|
delete m_d3d11Device;
|
|
|
|
delete m_dxgiDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContainer::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(IDXGIObject)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == __uuidof(IDXGIDevice)
|
|
|
|
|| riid == __uuidof(IDXGIDevice1)
|
|
|
|
|| riid == __uuidof(IDXGIDevice2)
|
|
|
|
|| riid == __uuidof(IDXGIVkDevice)) {
|
|
|
|
*ppvObject = ref(m_dxgiDevice);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-20 00:19:03 +02:00
|
|
|
if (riid == __uuidof(IDXGIVkInteropDevice)) {
|
|
|
|
*ppvObject = ref(m_d3d11VkInterop);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
if (riid == __uuidof(ID3D11Device)
|
|
|
|
|| riid == __uuidof(ID3D11Device1)) {
|
|
|
|
*ppvObject = ref(m_d3d11Device);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == __uuidof(IDXGIVkPresenter)) {
|
|
|
|
*ppvObject = ref(m_d3d11Presenter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == __uuidof(ID3D11Debug))
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
// Undocumented interfaces that are queried by some games
|
|
|
|
if (riid == GUID{0xd56e2a4c,0x5127,0x8437,{0x65,0x8a,0x98,0xc5,0xbb,0x78,0x94,0x98}})
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
Logger::warn("D3D11DeviceContainer::QueryInterface: Unknown interface query");
|
|
|
|
Logger::warn(str::format(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContainer::GetParent(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppParent) {
|
|
|
|
return m_dxgiDevice->GetParent(riid, ppParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
D3D11Device::D3D11Device(
|
2018-03-28 21:24:52 +02:00
|
|
|
IDXGIObject* pContainer,
|
|
|
|
IDXGIVkDevice* pDxgiDevice,
|
|
|
|
D3D_FEATURE_LEVEL FeatureLevel,
|
|
|
|
UINT FeatureFlags)
|
|
|
|
: m_container (pContainer),
|
|
|
|
m_featureLevel (FeatureLevel),
|
|
|
|
m_featureFlags (FeatureFlags),
|
|
|
|
m_dxvkDevice (pDxgiDevice->GetDXVKDevice()),
|
2018-01-07 20:05:27 +01:00
|
|
|
m_dxvkAdapter (m_dxvkDevice->adapter()),
|
2018-03-24 17:02:24 +01:00
|
|
|
m_d3d11Options (D3D11GetAppOptions(env::getExeName())),
|
2018-04-22 23:49:41 +02:00
|
|
|
m_dxbcOptions (getDxbcAppOptions(env::getExeName()) |
|
|
|
|
getDxbcDeviceOptions(m_dxvkDevice)) {
|
2017-12-04 13:47:18 +01:00
|
|
|
Com<IDXGIAdapter> adapter;
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
if (FAILED(pDxgiDevice->GetAdapter(&adapter))
|
2018-03-28 19:06:00 +02:00
|
|
|
|| FAILED(adapter->QueryInterface(__uuidof(IDXGIVkAdapter),
|
2017-12-04 13:47:18 +01:00
|
|
|
reinterpret_cast<void**>(&m_dxgiAdapter))))
|
|
|
|
throw DxvkError("D3D11Device: Failed to query adapter");
|
|
|
|
|
2018-01-20 13:22:44 +01:00
|
|
|
m_context = new D3D11ImmediateContext(this, m_dxvkDevice);
|
2018-01-13 05:00:27 +01:00
|
|
|
|
2017-12-07 18:51:41 +01:00
|
|
|
m_resourceInitContext = m_dxvkDevice->createContext();
|
2018-01-13 05:00:27 +01:00
|
|
|
m_resourceInitContext->beginRecording(
|
|
|
|
m_dxvkDevice->createCommandList());
|
2018-01-11 12:23:55 +01:00
|
|
|
|
|
|
|
CreateCounterBuffer();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11Device::~D3D11Device() {
|
2017-12-11 17:01:38 +01:00
|
|
|
delete m_context;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 21:24:52 +02:00
|
|
|
ULONG STDMETHODCALLTYPE D3D11Device::AddRef() {
|
|
|
|
return m_container->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11Device::Release() {
|
|
|
|
return m_container->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-03-28 21:24:52 +02:00
|
|
|
return m_container->QueryInterface(riid, ppvObject);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2017-10-11 15:32:24 +02:00
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateBuffer(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_BUFFER_DESC* pDesc,
|
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData,
|
|
|
|
ID3D11Buffer** ppBuffer) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppBuffer);
|
|
|
|
|
2018-02-27 08:54:24 +01:00
|
|
|
if (ppBuffer == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
2017-12-14 15:59:55 +01:00
|
|
|
const Com<D3D11Buffer> buffer
|
|
|
|
= new D3D11Buffer(this, pDesc);
|
2017-12-07 13:31:32 +01:00
|
|
|
|
2017-12-14 15:59:55 +01:00
|
|
|
this->InitBuffer(buffer.ptr(), pInitialData);
|
|
|
|
*ppBuffer = buffer.ref();
|
2018-02-27 08:54:24 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
2017-12-07 13:17:16 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateTexture1D(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_TEXTURE1D_DESC* pDesc,
|
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData,
|
|
|
|
ID3D11Texture1D** ppTexture1D) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppTexture1D);
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
D3D11_COMMON_TEXTURE_DESC desc;
|
|
|
|
desc.Width = pDesc->Width;
|
|
|
|
desc.Height = 1;
|
|
|
|
desc.Depth = 1;
|
|
|
|
desc.MipLevels = pDesc->MipLevels;
|
|
|
|
desc.ArraySize = pDesc->ArraySize;
|
|
|
|
desc.Format = pDesc->Format;
|
|
|
|
desc.SampleDesc = DXGI_SAMPLE_DESC { 1, 0 };
|
|
|
|
desc.Usage = pDesc->Usage;
|
|
|
|
desc.BindFlags = pDesc->BindFlags;
|
|
|
|
desc.CPUAccessFlags = pDesc->CPUAccessFlags;
|
|
|
|
desc.MiscFlags = pDesc->MiscFlags;
|
|
|
|
|
|
|
|
if (FAILED(D3D11CommonTexture::NormalizeTextureProperties(&desc)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-27 08:54:24 +01:00
|
|
|
if (ppTexture1D == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
2018-03-14 00:45:07 +01:00
|
|
|
const Com<D3D11Texture1D> texture = new D3D11Texture1D(this, &desc);
|
2018-05-22 21:06:26 +02:00
|
|
|
this->InitTexture(texture->GetCommonTexture(), pInitialData);
|
2017-12-23 17:05:07 +01:00
|
|
|
*ppTexture1D = texture.ref();
|
2018-02-27 08:54:24 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateTexture2D(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_TEXTURE2D_DESC* pDesc,
|
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData,
|
|
|
|
ID3D11Texture2D** ppTexture2D) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppTexture2D);
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
D3D11_COMMON_TEXTURE_DESC desc;
|
|
|
|
desc.Width = pDesc->Width;
|
|
|
|
desc.Height = pDesc->Height;
|
|
|
|
desc.Depth = 1;
|
|
|
|
desc.MipLevels = pDesc->MipLevels;
|
|
|
|
desc.ArraySize = pDesc->ArraySize;
|
|
|
|
desc.Format = pDesc->Format;
|
|
|
|
desc.SampleDesc = pDesc->SampleDesc;
|
|
|
|
desc.Usage = pDesc->Usage;
|
|
|
|
desc.BindFlags = pDesc->BindFlags;
|
|
|
|
desc.CPUAccessFlags = pDesc->CPUAccessFlags;
|
|
|
|
desc.MiscFlags = pDesc->MiscFlags;
|
|
|
|
|
|
|
|
if (FAILED(D3D11CommonTexture::NormalizeTextureProperties(&desc)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-27 08:54:24 +01:00
|
|
|
if (ppTexture2D == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
2018-03-14 00:45:07 +01:00
|
|
|
const Com<D3D11Texture2D> texture = new D3D11Texture2D(this, &desc);
|
2018-05-22 21:06:26 +02:00
|
|
|
this->InitTexture(texture->GetCommonTexture(), pInitialData);
|
2017-12-19 16:01:50 +01:00
|
|
|
*ppTexture2D = texture.ref();
|
2018-02-27 08:54:24 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
2017-12-08 23:13:15 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateTexture3D(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_TEXTURE3D_DESC* pDesc,
|
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData,
|
|
|
|
ID3D11Texture3D** ppTexture3D) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppTexture3D);
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
D3D11_COMMON_TEXTURE_DESC desc;
|
|
|
|
desc.Width = pDesc->Width;
|
|
|
|
desc.Height = pDesc->Height;
|
|
|
|
desc.Depth = pDesc->Depth;
|
|
|
|
desc.MipLevels = pDesc->MipLevels;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.Format = pDesc->Format;
|
|
|
|
desc.SampleDesc = DXGI_SAMPLE_DESC { 1, 0 };
|
|
|
|
desc.Usage = pDesc->Usage;
|
|
|
|
desc.BindFlags = pDesc->BindFlags;
|
|
|
|
desc.CPUAccessFlags = pDesc->CPUAccessFlags;
|
|
|
|
desc.MiscFlags = pDesc->MiscFlags;
|
|
|
|
|
|
|
|
if (FAILED(D3D11CommonTexture::NormalizeTextureProperties(&desc)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-27 08:54:24 +01:00
|
|
|
if (ppTexture3D == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
2018-03-14 00:45:07 +01:00
|
|
|
const Com<D3D11Texture3D> texture = new D3D11Texture3D(this, &desc);
|
2018-05-22 21:06:26 +02:00
|
|
|
this->InitTexture(texture->GetCommonTexture(), pInitialData);
|
2017-12-23 17:05:07 +01:00
|
|
|
*ppTexture3D = texture.ref();
|
2018-02-27 08:54:24 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateShaderResourceView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc,
|
|
|
|
ID3D11ShaderResourceView** ppSRView) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppSRView);
|
|
|
|
|
2017-12-09 14:46:23 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&resourceDim);
|
2017-12-09 15:57:05 +01:00
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
// The description is optional. If omitted, we'll create
|
|
|
|
// a view that covers all subresources of the image.
|
2017-12-09 19:06:51 +01:00
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
|
2017-12-09 15:57:05 +01:00
|
|
|
|
2017-12-09 19:06:51 +01:00
|
|
|
if (pDesc == nullptr) {
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11ShaderResourceView::GetDescFromResource(pResource, &desc)))
|
2017-12-09 19:06:51 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
} else {
|
|
|
|
desc = *pDesc;
|
2018-01-17 15:19:55 +01:00
|
|
|
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11ShaderResourceView::NormalizeDesc(pResource, &desc)))
|
2018-01-17 15:19:55 +01:00
|
|
|
return E_INVALIDARG;
|
2017-12-09 19:06:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2017-12-27 14:32:07 +01:00
|
|
|
auto resource = static_cast<D3D11Buffer*>(pResource);
|
|
|
|
|
2017-12-28 16:33:42 +01:00
|
|
|
D3D11_BUFFER_DESC resourceDesc;
|
|
|
|
resource->GetDesc(&resourceDesc);
|
2017-12-27 14:32:07 +01:00
|
|
|
|
2018-02-22 21:38:45 +01:00
|
|
|
if ((resourceDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE) == 0) {
|
|
|
|
Logger::warn("D3D11: Trying to create SRV for buffer without D3D11_BIND_SHADER_RESOURCE");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-28 16:33:42 +01:00
|
|
|
DxvkBufferViewCreateInfo viewInfo;
|
2017-12-27 14:32:07 +01:00
|
|
|
|
2017-12-29 12:11:45 +01:00
|
|
|
D3D11_BUFFEREX_SRV bufInfo;
|
|
|
|
|
2017-12-28 16:33:42 +01:00
|
|
|
if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX) {
|
2017-12-29 12:11:45 +01:00
|
|
|
bufInfo.FirstElement = desc.BufferEx.FirstElement;
|
|
|
|
bufInfo.NumElements = desc.BufferEx.NumElements;
|
|
|
|
bufInfo.Flags = desc.BufferEx.Flags;
|
|
|
|
} else if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER) {
|
|
|
|
bufInfo.FirstElement = desc.Buffer.FirstElement;
|
|
|
|
bufInfo.NumElements = desc.Buffer.NumElements;
|
|
|
|
bufInfo.Flags = 0;
|
|
|
|
} else {
|
|
|
|
Logger::err("D3D11Device: Invalid buffer view dimension");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bufInfo.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) {
|
|
|
|
// Raw buffer view. We'll represent this as a
|
|
|
|
// uniform texel buffer with UINT32 elements.
|
2017-12-28 16:33:42 +01:00
|
|
|
viewInfo.format = VK_FORMAT_R32_UINT;
|
2017-12-29 12:11:45 +01:00
|
|
|
viewInfo.rangeOffset = sizeof(uint32_t) * bufInfo.FirstElement;
|
|
|
|
viewInfo.rangeLength = sizeof(uint32_t) * bufInfo.NumElements;
|
|
|
|
} else if (desc.Format == DXGI_FORMAT_UNKNOWN) {
|
|
|
|
// Structured buffer view
|
|
|
|
viewInfo.format = VK_FORMAT_R32_UINT;
|
|
|
|
viewInfo.rangeOffset = resourceDesc.StructureByteStride * bufInfo.FirstElement;
|
|
|
|
viewInfo.rangeLength = resourceDesc.StructureByteStride * bufInfo.NumElements;
|
2017-12-28 16:33:42 +01:00
|
|
|
} else {
|
|
|
|
// Typed buffer view - must use an uncompressed color format
|
|
|
|
viewInfo.format = m_dxgiAdapter->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
desc.Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
2017-12-28 16:33:42 +01:00
|
|
|
|
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(viewInfo.format);
|
2017-12-29 12:11:45 +01:00
|
|
|
viewInfo.rangeOffset = formatInfo->elementSize * bufInfo.FirstElement;
|
|
|
|
viewInfo.rangeLength = formatInfo->elementSize * bufInfo.NumElements;
|
2017-12-28 16:33:42 +01:00
|
|
|
|
|
|
|
if (formatInfo->flags.test(DxvkFormatFlag::BlockCompressed)) {
|
|
|
|
Logger::err("D3D11Device: Compressed formats for buffer views not supported");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2017-12-27 14:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ppSRView == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
*ppSRView = ref(new D3D11ShaderResourceView(
|
|
|
|
this, pResource, desc,
|
|
|
|
m_dxvkDevice->createBufferView(
|
|
|
|
resource->GetBufferSlice().buffer(), viewInfo)));
|
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-12-09 19:06:51 +01:00
|
|
|
} else {
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* textureInfo = GetCommonTexture(pResource);
|
2017-12-19 14:47:35 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
if ((textureInfo->Desc()->BindFlags & D3D11_BIND_SHADER_RESOURCE) == 0) {
|
2018-05-05 15:13:35 +02:00
|
|
|
Logger::err("D3D11: Trying to create SRV for texture without D3D11_BIND_SHADER_RESOURCE");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether we can use the requested format for the view
|
|
|
|
if (!textureInfo->CheckViewFormatCompatibility(desc.Format)) {
|
|
|
|
Logger::err(str::format("D3D11: Incompatible SRV formats",
|
|
|
|
"\n Base format: ", textureInfo->Desc()->Format,
|
|
|
|
"\n View format: ", desc.Format));
|
2018-02-22 21:38:45 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
// Fill in the view info. The view type depends solely
|
|
|
|
// on the view dimension field in the view description,
|
|
|
|
// not on the resource type.
|
2018-04-12 17:49:14 +02:00
|
|
|
const DXGI_VK_FORMAT_INFO formatInfo = m_dxgiAdapter
|
2018-03-14 00:45:07 +01:00
|
|
|
->LookupFormat(desc.Format, textureInfo->GetFormatMode());
|
2017-12-20 14:54:24 +01:00
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
DxvkImageViewCreateInfo viewInfo;
|
2018-04-12 17:49:14 +02:00
|
|
|
viewInfo.format = formatInfo.Format;
|
|
|
|
viewInfo.aspect = formatInfo.Aspect;
|
|
|
|
viewInfo.swizzle = formatInfo.Swizzle;
|
2017-12-09 19:06:51 +01:00
|
|
|
|
2018-05-05 15:15:09 +02:00
|
|
|
// Shaders expect the stencil value in the G component
|
|
|
|
if (viewInfo.aspect == VK_IMAGE_ASPECT_STENCIL_BIT) {
|
|
|
|
viewInfo.swizzle = VkComponentMapping {
|
|
|
|
VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_R,
|
|
|
|
VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO };
|
|
|
|
}
|
|
|
|
|
2017-12-09 19:06:51 +01:00
|
|
|
switch (desc.ViewDimension) {
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE1D:
|
2018-04-23 00:46:27 +02:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.minLevel = desc.Texture1D.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.Texture1D.MipLevels;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture1DArray.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.Texture1DArray.MipLevels;
|
|
|
|
viewInfo.minLayer = desc.Texture1DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture1DArray.ArraySize;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE2D:
|
2018-04-23 00:46:27 +02:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.minLevel = desc.Texture2D.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.Texture2D.MipLevels;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture2DArray.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.Texture2DArray.MipLevels;
|
|
|
|
viewInfo.minLayer = desc.Texture2DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DArray.ArraySize;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE2DMS:
|
2018-04-23 00:46:27 +02:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture2DMSArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DMSArray.ArraySize;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURE3D:
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_3D;
|
|
|
|
viewInfo.minLevel = desc.Texture3D.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.Texture3D.MipLevels;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURECUBE:
|
2018-01-11 12:33:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.minLevel = desc.TextureCube.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.TextureCube.MipLevels;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 6;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY:
|
2017-12-09 19:36:38 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.TextureCubeArray.MostDetailedMip;
|
|
|
|
viewInfo.numLevels = desc.TextureCubeArray.MipLevels;
|
|
|
|
viewInfo.minLayer = desc.TextureCubeArray.First2DArrayFace;
|
|
|
|
viewInfo.numLayers = desc.TextureCubeArray.NumCubes * 6;
|
2017-12-09 19:06:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: View dimension not supported for SRV: ",
|
|
|
|
desc.ViewDimension));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
if (ppSRView == nullptr)
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_FALSE;
|
2017-12-09 19:06:51 +01:00
|
|
|
|
|
|
|
try {
|
2017-12-09 19:36:38 +01:00
|
|
|
*ppSRView = ref(new D3D11ShaderResourceView(
|
2017-12-27 01:36:45 +01:00
|
|
|
this, pResource, desc,
|
2017-12-09 19:36:38 +01:00
|
|
|
m_dxvkDevice->createImageView(
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetImage(),
|
|
|
|
viewInfo)));
|
2017-12-09 19:06:51 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateUnorderedAccessView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
const D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc,
|
|
|
|
ID3D11UnorderedAccessView** ppUAView) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppUAView);
|
|
|
|
|
2017-12-28 19:05:53 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&resourceDim);
|
|
|
|
|
|
|
|
// The description is optional. If omitted, we'll create
|
|
|
|
// a view that covers all subresources of the image.
|
|
|
|
D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
|
|
|
|
|
|
|
|
if (pDesc == nullptr) {
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11UnorderedAccessView::GetDescFromResource(pResource, &desc)))
|
2017-12-28 19:05:53 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
} else {
|
|
|
|
desc = *pDesc;
|
2018-01-28 11:30:15 +01:00
|
|
|
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11UnorderedAccessView::NormalizeDesc(pResource, &desc)))
|
2018-01-28 11:30:15 +01:00
|
|
|
return E_INVALIDARG;
|
2017-12-28 19:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
|
|
|
auto resource = static_cast<D3D11Buffer*>(pResource);
|
|
|
|
|
|
|
|
D3D11_BUFFER_DESC resourceDesc;
|
|
|
|
resource->GetDesc(&resourceDesc);
|
|
|
|
|
2018-02-22 21:38:45 +01:00
|
|
|
if ((resourceDesc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) == 0) {
|
|
|
|
Logger::warn("D3D11: Trying to create UAV for buffer without D3D11_BIND_UNORDERED_ACCESS");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-28 19:05:53 +01:00
|
|
|
DxvkBufferViewCreateInfo viewInfo;
|
|
|
|
|
|
|
|
if (desc.Buffer.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) {
|
|
|
|
viewInfo.format = VK_FORMAT_R32_UINT;
|
|
|
|
viewInfo.rangeOffset = sizeof(uint32_t) * desc.Buffer.FirstElement;
|
|
|
|
viewInfo.rangeLength = sizeof(uint32_t) * desc.Buffer.NumElements;
|
|
|
|
} else if (desc.Format == DXGI_FORMAT_UNKNOWN) {
|
|
|
|
viewInfo.format = VK_FORMAT_R32_UINT;
|
|
|
|
viewInfo.rangeOffset = resourceDesc.StructureByteStride * desc.Buffer.FirstElement;
|
|
|
|
viewInfo.rangeLength = resourceDesc.StructureByteStride * desc.Buffer.NumElements;
|
|
|
|
} else {
|
|
|
|
// Typed buffer view - must use an uncompressed color format
|
|
|
|
viewInfo.format = m_dxgiAdapter->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
desc.Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
2017-12-28 19:05:53 +01:00
|
|
|
|
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(viewInfo.format);
|
|
|
|
viewInfo.rangeOffset = formatInfo->elementSize * desc.Buffer.FirstElement;
|
|
|
|
viewInfo.rangeLength = formatInfo->elementSize * desc.Buffer.NumElements;
|
|
|
|
|
|
|
|
if (formatInfo->flags.test(DxvkFormatFlag::BlockCompressed)) {
|
|
|
|
Logger::err("D3D11Device: Compressed formats for buffer views not supported");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ppUAView == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
2018-01-11 12:23:55 +01:00
|
|
|
// Fetch a buffer slice for atomic
|
|
|
|
// append/consume functionality.
|
|
|
|
DxvkBufferSlice counterSlice;
|
|
|
|
|
|
|
|
if (desc.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
|
|
|
|
counterSlice = AllocateCounterSlice();
|
|
|
|
|
2017-12-28 19:05:53 +01:00
|
|
|
*ppUAView = ref(new D3D11UnorderedAccessView(
|
|
|
|
this, pResource, desc,
|
|
|
|
m_dxvkDevice->createBufferView(
|
2018-01-11 12:23:55 +01:00
|
|
|
resource->GetBufferSlice().buffer(), viewInfo),
|
|
|
|
counterSlice));
|
2017-12-28 19:05:53 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* textureInfo = GetCommonTexture(pResource);
|
2018-01-01 19:46:19 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
if ((textureInfo->Desc()->BindFlags & D3D11_BIND_UNORDERED_ACCESS) == 0) {
|
2018-02-22 21:38:45 +01:00
|
|
|
Logger::warn("D3D11: Trying to create UAV for texture without D3D11_BIND_UNORDERED_ACCESS");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:13:35 +02:00
|
|
|
// Check whether we can use the requested format for the view
|
|
|
|
if (!textureInfo->CheckViewFormatCompatibility(desc.Format)) {
|
|
|
|
Logger::err(str::format("D3D11: Incompatible UAV formats",
|
|
|
|
"\n Base format: ", textureInfo->Desc()->Format,
|
|
|
|
"\n View format: ", desc.Format));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-01-01 19:46:19 +01:00
|
|
|
// Fill in the view info. The view type depends solely
|
|
|
|
// on the view dimension field in the view description,
|
|
|
|
// not on the resource type.
|
2018-04-12 17:49:14 +02:00
|
|
|
const DXGI_VK_FORMAT_INFO formatInfo = m_dxgiAdapter
|
2018-03-14 00:45:07 +01:00
|
|
|
->LookupFormat(desc.Format, textureInfo->GetFormatMode());
|
2018-01-01 19:46:19 +01:00
|
|
|
|
|
|
|
DxvkImageViewCreateInfo viewInfo;
|
2018-04-12 17:49:14 +02:00
|
|
|
viewInfo.format = formatInfo.Format;
|
|
|
|
viewInfo.aspect = formatInfo.Aspect;
|
|
|
|
viewInfo.swizzle = formatInfo.Swizzle;
|
2018-01-01 19:46:19 +01:00
|
|
|
|
|
|
|
switch (desc.ViewDimension) {
|
|
|
|
case D3D11_UAV_DIMENSION_TEXTURE1D:
|
2018-04-23 00:46:27 +02:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
2018-01-01 19:46:19 +01:00
|
|
|
viewInfo.minLevel = desc.Texture1D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_UAV_DIMENSION_TEXTURE1DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture1DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture1DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture1DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_UAV_DIMENSION_TEXTURE2D:
|
2018-04-23 00:46:27 +02:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
2018-01-01 19:46:19 +01:00
|
|
|
viewInfo.minLevel = desc.Texture2D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture2DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture2DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_UAV_DIMENSION_TEXTURE3D:
|
2018-01-28 11:30:15 +01:00
|
|
|
// FIXME we actually have to map this to a
|
|
|
|
// 2D array view in order to support W slices
|
2018-01-01 19:46:19 +01:00
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_3D;
|
|
|
|
viewInfo.minLevel = desc.Texture3D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
2018-01-06 02:09:07 +01:00
|
|
|
"D3D11: View dimension not supported for UAV: ",
|
2018-01-01 19:46:19 +01:00
|
|
|
desc.ViewDimension));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ppUAView == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
*ppUAView = ref(new D3D11UnorderedAccessView(
|
|
|
|
this, pResource, desc,
|
|
|
|
m_dxvkDevice->createImageView(
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetImage(),
|
|
|
|
viewInfo),
|
2018-01-11 12:23:55 +01:00
|
|
|
DxvkBufferSlice()));
|
2018-01-01 19:46:19 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-12-28 19:05:53 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateRenderTargetView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
const D3D11_RENDER_TARGET_VIEW_DESC* pDesc,
|
|
|
|
ID3D11RenderTargetView** ppRTView) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppRTView);
|
|
|
|
|
2018-03-18 21:38:48 +01:00
|
|
|
// DXVK only supports render target views for image resources
|
2017-11-29 15:16:07 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&resourceDim);
|
|
|
|
|
2018-03-18 21:38:48 +01:00
|
|
|
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2018-03-31 21:47:54 +02:00
|
|
|
Logger::warn("D3D11: Cannot create render target view for a buffer");
|
|
|
|
return S_OK; // It is required to run Battlefield 3 and Battlefield 4.
|
2018-03-18 21:38:48 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
// The view description is optional. If not defined, it
|
2017-12-08 23:25:38 +01:00
|
|
|
// will use the resource's format and all array layers.
|
2017-11-29 20:19:40 +01:00
|
|
|
D3D11_RENDER_TARGET_VIEW_DESC desc;
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
if (pDesc == nullptr) {
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11RenderTargetView::GetDescFromResource(pResource, &desc)))
|
2017-12-09 19:36:38 +01:00
|
|
|
return E_INVALIDARG;
|
2017-11-29 20:19:40 +01:00
|
|
|
} else {
|
2017-12-09 19:36:38 +01:00
|
|
|
desc = *pDesc;
|
2018-02-14 01:29:50 +01:00
|
|
|
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11RenderTargetView::NormalizeDesc(pResource, &desc)))
|
2018-02-14 01:29:50 +01:00
|
|
|
return E_INVALIDARG;
|
2017-11-29 20:19:40 +01:00
|
|
|
}
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
// Retrieve the image that we are going to create the view for
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* textureInfo = GetCommonTexture(pResource);
|
2017-12-09 19:36:38 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
if ((textureInfo->Desc()->BindFlags & D3D11_BIND_RENDER_TARGET) == 0) {
|
2018-02-22 21:38:45 +01:00
|
|
|
Logger::warn("D3D11: Trying to create RTV for texture without D3D11_BIND_RENDER_TARGET");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:13:35 +02:00
|
|
|
// Check whether we can use the requested format for the view
|
|
|
|
if (!textureInfo->CheckViewFormatCompatibility(desc.Format)) {
|
|
|
|
Logger::err(str::format("D3D11: Incompatible RTV formats",
|
|
|
|
"\n Base format: ", textureInfo->Desc()->Format,
|
|
|
|
"\n View format: ", desc.Format));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
// Fill in Vulkan image view info
|
|
|
|
DxvkImageViewCreateInfo viewInfo;
|
2018-04-12 17:49:14 +02:00
|
|
|
viewInfo.format = m_dxgiAdapter->LookupFormat(desc.Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
2017-12-09 02:44:59 +01:00
|
|
|
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
|
2017-11-29 15:16:07 +01:00
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
switch (desc.ViewDimension) {
|
2018-02-26 15:21:18 +01:00
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE1D:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
|
|
viewInfo.minLevel = desc.Texture1D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture1DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture1DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture1DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE2D:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
viewInfo.minLevel = desc.Texture2D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture2DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture2DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE2DMS:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
2017-12-19 18:12:18 +01:00
|
|
|
viewInfo.minLayer = desc.Texture2DMSArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DMSArray.ArraySize;
|
2017-11-29 20:19:40 +01:00
|
|
|
break;
|
|
|
|
|
2018-02-14 03:16:53 +01:00
|
|
|
case D3D11_RTV_DIMENSION_TEXTURE3D:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture3D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture3D.FirstWSlice;
|
|
|
|
viewInfo.numLayers = desc.Texture3D.WSize;
|
|
|
|
break;
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
2017-12-08 23:25:38 +01:00
|
|
|
"D3D11: pDesc->ViewDimension not supported for render target views: ",
|
2017-11-29 20:19:40 +01:00
|
|
|
desc.ViewDimension));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:53:00 +02:00
|
|
|
// Normalize view type so that we won't accidentally
|
|
|
|
// bind 2D array views and 2D views at the same time
|
|
|
|
if (viewInfo.numLayers == 1) {
|
|
|
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_1D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
|
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
}
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
// Create the actual image view if requested
|
|
|
|
if (ppRTView == nullptr)
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_FALSE;
|
2017-11-29 15:16:07 +01:00
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
try {
|
2017-12-09 02:09:13 +01:00
|
|
|
*ppRTView = ref(new D3D11RenderTargetView(
|
2017-12-27 01:36:45 +01:00
|
|
|
this, pResource, desc,
|
2017-12-09 19:36:38 +01:00
|
|
|
m_dxvkDevice->createImageView(
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetImage(),
|
|
|
|
viewInfo)));
|
2017-11-29 20:19:40 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
2017-12-27 14:32:07 +01:00
|
|
|
return E_FAIL;
|
2017-11-29 20:19:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDepthStencilView(
|
2017-11-29 20:19:40 +01:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
const D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc,
|
|
|
|
ID3D11DepthStencilView** ppDepthStencilView) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppDepthStencilView);
|
|
|
|
|
2017-12-08 23:25:38 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&resourceDim);
|
|
|
|
|
|
|
|
// The view description is optional. If not defined, it
|
|
|
|
// will use the resource's format and all array layers.
|
|
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC desc;
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
if (pDesc == nullptr) {
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11DepthStencilView::GetDescFromResource(pResource, &desc)))
|
2017-12-09 19:36:38 +01:00
|
|
|
return E_INVALIDARG;
|
2017-12-08 23:25:38 +01:00
|
|
|
} else {
|
2017-12-09 19:36:38 +01:00
|
|
|
desc = *pDesc;
|
2018-02-14 01:29:50 +01:00
|
|
|
|
2018-03-17 13:42:37 +01:00
|
|
|
if (FAILED(D3D11DepthStencilView::NormalizeDesc(pResource, &desc)))
|
2018-02-14 01:29:50 +01:00
|
|
|
return E_INVALIDARG;
|
2017-12-08 23:25:38 +01:00
|
|
|
}
|
|
|
|
|
2017-12-09 19:36:38 +01:00
|
|
|
// Retrieve the image that we are going to create the view for
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* textureInfo = GetCommonTexture(pResource);
|
2017-12-09 19:36:38 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
if ((textureInfo->Desc()->BindFlags & D3D11_BIND_DEPTH_STENCIL) == 0) {
|
2018-02-22 21:38:45 +01:00
|
|
|
Logger::warn("D3D11: Trying to create DSV for texture without D3D11_BIND_DEPTH_STENCIL");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:13:35 +02:00
|
|
|
// Check whether we can use the requested format for the view
|
|
|
|
if (!textureInfo->CheckViewFormatCompatibility(desc.Format)) {
|
|
|
|
Logger::err(str::format("D3D11: Incompatible DSV formats",
|
|
|
|
"\n Base format: ", textureInfo->Desc()->Format,
|
|
|
|
"\n View format: ", desc.Format));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:38 +01:00
|
|
|
// Fill in Vulkan image view info
|
|
|
|
DxvkImageViewCreateInfo viewInfo;
|
2018-04-12 17:49:14 +02:00
|
|
|
viewInfo.format = m_dxgiAdapter->LookupFormat(desc.Format, DXGI_VK_FORMAT_MODE_DEPTH).Format;
|
2017-12-09 02:44:59 +01:00
|
|
|
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
|
2017-12-08 23:25:38 +01:00
|
|
|
|
|
|
|
switch (desc.ViewDimension) {
|
2018-02-26 15:21:18 +01:00
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE1D:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
|
|
viewInfo.minLevel = desc.Texture1D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture1DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture1DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture1DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
2017-12-08 23:25:38 +01:00
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE2D:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
viewInfo.minLevel = desc.Texture2D.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = desc.Texture2DArray.MipSlice;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = desc.Texture2DArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DArray.ArraySize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE2DMS:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
viewInfo.minLayer = 0;
|
|
|
|
viewInfo.numLayers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
|
|
|
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
viewInfo.minLevel = 0;
|
|
|
|
viewInfo.numLevels = 1;
|
2017-12-19 18:12:18 +01:00
|
|
|
viewInfo.minLayer = desc.Texture2DMSArray.FirstArraySlice;
|
|
|
|
viewInfo.numLayers = desc.Texture2DMSArray.ArraySize;
|
2017-12-08 23:25:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: pDesc->ViewDimension not supported for depth-stencil views: ",
|
|
|
|
desc.ViewDimension));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-05-05 15:53:00 +02:00
|
|
|
// Normalize view type so that we won't accidentally
|
|
|
|
// bind 2D array views and 2D views at the same time
|
|
|
|
if (viewInfo.numLayers == 1) {
|
|
|
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_1D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
|
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:38 +01:00
|
|
|
// Create the actual image view if requested
|
|
|
|
if (ppDepthStencilView == nullptr)
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_FALSE;
|
2017-12-08 23:25:38 +01:00
|
|
|
|
|
|
|
try {
|
2017-12-09 02:09:13 +01:00
|
|
|
*ppDepthStencilView = ref(new D3D11DepthStencilView(
|
2017-12-27 01:36:45 +01:00
|
|
|
this, pResource, desc,
|
2017-12-09 19:36:38 +01:00
|
|
|
m_dxvkDevice->createImageView(
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetImage(),
|
|
|
|
viewInfo)));
|
2017-12-08 23:25:38 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
2017-12-27 14:32:07 +01:00
|
|
|
return E_FAIL;
|
2017-12-08 23:25:38 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateInputLayout(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_INPUT_ELEMENT_DESC* pInputElementDescs,
|
|
|
|
UINT NumElements,
|
|
|
|
const void* pShaderBytecodeWithInputSignature,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11InputLayout** ppInputLayout) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppInputLayout);
|
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
try {
|
|
|
|
DxbcReader dxbcReader(reinterpret_cast<const char*>(
|
|
|
|
pShaderBytecodeWithInputSignature), BytecodeLength);
|
|
|
|
DxbcModule dxbcModule(dxbcReader);
|
|
|
|
|
2018-01-08 20:23:21 +01:00
|
|
|
const Rc<DxbcIsgn> inputSignature = dxbcModule.isgn();
|
2018-05-30 13:33:48 +02:00
|
|
|
|
|
|
|
uint32_t attrMask = 0;
|
|
|
|
uint32_t bindMask = 0;
|
2017-12-07 12:45:02 +01:00
|
|
|
|
2018-05-30 13:33:48 +02:00
|
|
|
std::array<DxvkVertexAttribute, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> attrList;
|
|
|
|
std::array<DxvkVertexBinding, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> bindList;
|
2017-12-07 12:45:02 +01:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < NumElements; i++) {
|
|
|
|
const DxbcSgnEntry* entry = inputSignature->find(
|
|
|
|
pInputElementDescs[i].SemanticName,
|
2018-06-23 20:13:00 +02:00
|
|
|
pInputElementDescs[i].SemanticIndex, 0);
|
2017-12-07 12:45:02 +01:00
|
|
|
|
|
|
|
if (entry == nullptr) {
|
2018-01-19 01:25:19 +01:00
|
|
|
Logger::debug(str::format(
|
2018-01-02 12:07:30 +01:00
|
|
|
"D3D11Device: No such vertex shader semantic: ",
|
2017-12-07 12:45:02 +01:00
|
|
|
pInputElementDescs[i].SemanticName,
|
|
|
|
pInputElementDescs[i].SemanticIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create vertex input attribute description
|
2017-12-08 00:44:58 +01:00
|
|
|
DxvkVertexAttribute attrib;
|
2018-05-30 13:33:48 +02:00
|
|
|
attrib.location = entry != nullptr ? entry->registerId : 0;
|
2017-12-07 12:45:02 +01:00
|
|
|
attrib.binding = pInputElementDescs[i].InputSlot;
|
|
|
|
attrib.format = m_dxgiAdapter->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
pInputElementDescs[i].Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
2017-12-07 12:45:02 +01:00
|
|
|
attrib.offset = pInputElementDescs[i].AlignedByteOffset;
|
|
|
|
|
2017-12-18 23:24:10 +01:00
|
|
|
// The application may choose to let the implementation
|
|
|
|
// generate the exact vertex layout. In that case we'll
|
|
|
|
// pack attributes on the same binding in the order they
|
|
|
|
// are declared, aligning each attribute to four bytes.
|
2017-12-07 12:45:02 +01:00
|
|
|
if (attrib.offset == D3D11_APPEND_ALIGNED_ELEMENT) {
|
2017-12-18 23:24:10 +01:00
|
|
|
attrib.offset = 0;
|
|
|
|
|
|
|
|
for (uint32_t j = 1; j <= i; j++) {
|
2018-05-30 13:33:48 +02:00
|
|
|
const DxvkVertexAttribute& prev = attrList.at(i - j);
|
2017-12-18 23:24:10 +01:00
|
|
|
|
|
|
|
if (prev.binding == attrib.binding) {
|
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(prev.format);
|
|
|
|
attrib.offset = align(prev.offset + formatInfo->elementSize, 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-07 12:45:02 +01:00
|
|
|
}
|
2018-05-30 13:33:48 +02:00
|
|
|
|
|
|
|
attrList.at(i) = attrib;
|
2017-12-07 12:45:02 +01:00
|
|
|
|
2017-12-07 19:28:54 +01:00
|
|
|
// Create vertex input binding description. The
|
|
|
|
// stride is dynamic state in D3D11 and will be
|
2018-01-08 20:23:21 +01:00
|
|
|
// set by D3D11DeviceContext::IASetVertexBuffers.
|
2017-12-08 00:44:58 +01:00
|
|
|
DxvkVertexBinding binding;
|
2017-12-07 12:45:02 +01:00
|
|
|
binding.binding = pInputElementDescs[i].InputSlot;
|
2018-02-01 20:15:25 +01:00
|
|
|
binding.fetchRate = pInputElementDescs[i].InstanceDataStepRate;
|
|
|
|
binding.inputRate = pInputElementDescs[i].InputSlotClass == D3D11_INPUT_PER_INSTANCE_DATA
|
2018-05-30 13:33:48 +02:00
|
|
|
? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX;
|
2017-12-07 12:45:02 +01:00
|
|
|
|
|
|
|
// Check if the binding was already defined. If so, the
|
|
|
|
// parameters must be identical (namely, the input rate).
|
|
|
|
bool bindingDefined = false;
|
|
|
|
|
2018-05-30 13:33:48 +02:00
|
|
|
for (uint32_t j = 0; j < i; j++) {
|
|
|
|
uint32_t bindingId = attrList.at(j).binding;
|
|
|
|
|
|
|
|
if (binding.binding == bindingId) {
|
2017-12-07 12:45:02 +01:00
|
|
|
bindingDefined = true;
|
|
|
|
|
2018-05-30 13:33:48 +02:00
|
|
|
if (binding.inputRate != bindList.at(bindingId).inputRate) {
|
2017-12-07 12:45:02 +01:00
|
|
|
Logger::err(str::format(
|
2018-01-08 20:23:21 +01:00
|
|
|
"D3D11Device: Conflicting input rate for binding ",
|
2017-12-07 12:45:02 +01:00
|
|
|
binding.binding));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 13:33:48 +02:00
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
if (!bindingDefined)
|
2018-05-30 13:33:48 +02:00
|
|
|
bindList.at(binding.binding) = binding;
|
|
|
|
|
|
|
|
if (entry != nullptr) {
|
|
|
|
attrMask |= 1u << i;
|
|
|
|
bindMask |= 1u << binding.binding;
|
|
|
|
}
|
2017-12-07 12:45:02 +01:00
|
|
|
}
|
2018-05-30 13:33:48 +02:00
|
|
|
|
|
|
|
// Compact the attribute and binding lists to filter
|
|
|
|
// out attributes and bindings not used by the shader
|
|
|
|
uint32_t attrCount = CompactSparseList(attrList.data(), attrMask);
|
|
|
|
uint32_t bindCount = CompactSparseList(bindList.data(), bindMask);
|
|
|
|
|
2018-01-08 20:23:21 +01:00
|
|
|
// Check if there are any semantics defined in the
|
|
|
|
// shader that are not included in the current input
|
|
|
|
// layout.
|
|
|
|
for (auto i = inputSignature->begin(); i != inputSignature->end(); i++) {
|
|
|
|
bool found = i->systemValue != DxbcSystemValue::None;
|
|
|
|
|
2018-05-30 13:33:48 +02:00
|
|
|
for (uint32_t j = 0; j < attrCount && !found; j++)
|
|
|
|
found = attrList.at(j).location == i->registerId;
|
2018-01-08 20:23:21 +01:00
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
Logger::warn(str::format(
|
|
|
|
"D3D11Device: Vertex input '",
|
|
|
|
i->semanticName, i->semanticIndex,
|
|
|
|
"' not defined by input layout"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
// Create the actual input layout object
|
|
|
|
// if the application requests it.
|
|
|
|
if (ppInputLayout != nullptr) {
|
|
|
|
*ppInputLayout = ref(
|
|
|
|
new D3D11InputLayout(this,
|
2018-05-30 13:33:48 +02:00
|
|
|
attrCount, attrList.data(),
|
|
|
|
bindCount, bindList.data()));
|
2017-12-07 12:45:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
2017-12-27 14:32:07 +01:00
|
|
|
return E_FAIL;
|
2017-12-07 12:45:02 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateVertexShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11VertexShader** ppVertexShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppVertexShader);
|
2017-12-06 18:54:01 +01:00
|
|
|
D3D11ShaderModule module;
|
2018-06-23 17:14:35 +02:00
|
|
|
|
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
2017-12-06 18:54:01 +01:00
|
|
|
|
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::VertexShader)))
|
2017-12-06 18:54:01 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppVertexShader == nullptr)
|
|
|
|
return S_FALSE;
|
2017-12-06 18:54:01 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppVertexShader = ref(new D3D11VertexShader(this, module));
|
2017-12-06 18:54:01 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateGeometryShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11GeometryShader** ppGeometryShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppGeometryShader);
|
2017-12-18 12:53:53 +01:00
|
|
|
D3D11ShaderModule module;
|
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
|
|
|
|
2017-12-18 12:53:53 +01:00
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::GeometryShader)))
|
2017-12-18 12:53:53 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppGeometryShader == nullptr)
|
|
|
|
return S_FALSE;
|
2017-12-18 12:53:53 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppGeometryShader = ref(new D3D11GeometryShader(this, module));
|
2017-12-18 12:53:53 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateGeometryShaderWithStreamOutput(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
const D3D11_SO_DECLARATION_ENTRY* pSODeclaration,
|
|
|
|
UINT NumEntries,
|
|
|
|
const UINT* pBufferStrides,
|
|
|
|
UINT NumStrides,
|
|
|
|
UINT RasterizedStream,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11GeometryShader** ppGeometryShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppGeometryShader);
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11Device::CreateGeometryShaderWithStreamOutput: Not implemented");
|
2018-05-25 23:53:34 +02:00
|
|
|
|
|
|
|
// Returning S_OK instead of an error fixes some issues
|
|
|
|
// with Overwatch until this is properly implemented
|
|
|
|
return m_d3d11Options.test(D3D11Option::FakeStreamOutSupport) ? S_OK : E_NOTIMPL;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreatePixelShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11PixelShader** ppPixelShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppPixelShader);
|
2017-12-06 18:54:01 +01:00
|
|
|
D3D11ShaderModule module;
|
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
|
|
|
|
2017-12-06 18:54:01 +01:00
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::PixelShader)))
|
2017-12-06 18:54:01 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppPixelShader == nullptr)
|
|
|
|
return S_FALSE;
|
2017-12-06 18:54:01 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppPixelShader = ref(new D3D11PixelShader(this, module));
|
2017-12-06 18:54:01 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateHullShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11HullShader** ppHullShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppHullShader);
|
2018-01-29 11:53:57 +01:00
|
|
|
D3D11ShaderModule module;
|
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
|
|
|
|
2018-03-06 17:02:47 +01:00
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::HullShader)))
|
2018-03-06 17:02:47 +01:00
|
|
|
return E_INVALIDARG;
|
2018-01-29 11:53:57 +01:00
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppHullShader == nullptr)
|
|
|
|
return S_FALSE;
|
2018-01-29 11:53:57 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppHullShader = ref(new D3D11HullShader(this, module));
|
2018-01-29 11:53:57 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDomainShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11DomainShader** ppDomainShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppDomainShader);
|
2018-01-29 11:53:57 +01:00
|
|
|
D3D11ShaderModule module;
|
2018-02-26 17:04:45 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
|
|
|
|
2018-03-06 17:02:47 +01:00
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::DomainShader)))
|
2018-03-06 17:02:47 +01:00
|
|
|
return E_INVALIDARG;
|
2018-01-29 11:53:57 +01:00
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppDomainShader == nullptr)
|
|
|
|
return S_FALSE;
|
2018-01-29 11:53:57 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppDomainShader = ref(new D3D11DomainShader(this, module));
|
2018-01-29 11:53:57 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateComputeShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
const void* pShaderBytecode,
|
|
|
|
SIZE_T BytecodeLength,
|
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
|
|
|
ID3D11ComputeShader** ppComputeShader) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppComputeShader);
|
2017-12-21 17:27:40 +01:00
|
|
|
D3D11ShaderModule module;
|
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo moduleInfo;
|
|
|
|
moduleInfo.options = m_dxbcOptions;
|
|
|
|
|
2017-12-21 17:27:40 +01:00
|
|
|
if (FAILED(this->CreateShaderModule(&module,
|
2018-04-06 17:54:02 +02:00
|
|
|
pShaderBytecode, BytecodeLength, pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
&moduleInfo, DxbcProgramType::ComputeShader)))
|
2017-12-21 17:27:40 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-26 17:04:45 +01:00
|
|
|
if (ppComputeShader == nullptr)
|
|
|
|
return S_FALSE;
|
2017-12-21 17:27:40 +01:00
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
*ppComputeShader = ref(new D3D11ComputeShader(this, module));
|
2017-12-21 17:27:40 +01:00
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateClassLinkage(ID3D11ClassLinkage** ppLinkage) {
|
2017-12-12 01:07:07 +01:00
|
|
|
*ppLinkage = ref(new D3D11ClassLinkage(this));
|
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateBlendState(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_BLEND_DESC* pBlendStateDesc,
|
|
|
|
ID3D11BlendState** ppBlendState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppBlendState);
|
|
|
|
|
2018-03-18 23:27:29 +01:00
|
|
|
D3D11_BLEND_DESC1 desc = pBlendStateDesc != nullptr
|
|
|
|
? D3D11BlendState::PromoteDesc(pBlendStateDesc)
|
|
|
|
: D3D11BlendState::DefaultDesc();
|
2017-12-11 13:03:07 +01:00
|
|
|
|
2018-03-18 23:27:29 +01:00
|
|
|
if (FAILED(D3D11BlendState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
2017-12-11 13:03:07 +01:00
|
|
|
|
2017-12-27 14:32:07 +01:00
|
|
|
if (ppBlendState != nullptr) {
|
2017-12-11 13:03:07 +01:00
|
|
|
*ppBlendState = m_bsStateObjects.Create(this, desc);
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_OK;
|
|
|
|
} return S_FALSE;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateBlendState1(
|
|
|
|
const D3D11_BLEND_DESC1* pBlendStateDesc,
|
|
|
|
ID3D11BlendState1** ppBlendState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppBlendState);
|
|
|
|
|
2018-03-18 23:27:29 +01:00
|
|
|
D3D11_BLEND_DESC1 desc = pBlendStateDesc != nullptr
|
|
|
|
? *pBlendStateDesc
|
|
|
|
: D3D11BlendState::DefaultDesc();
|
|
|
|
|
|
|
|
if (FAILED(D3D11BlendState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (ppBlendState != nullptr) {
|
|
|
|
*ppBlendState = m_bsStateObjects.Create(this, desc);
|
|
|
|
return S_OK;
|
|
|
|
} return S_FALSE;
|
2018-03-17 20:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDepthStencilState(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_DEPTH_STENCIL_DESC* pDepthStencilDesc,
|
|
|
|
ID3D11DepthStencilState** ppDepthStencilState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppDepthStencilState);
|
|
|
|
|
2018-03-18 23:32:01 +01:00
|
|
|
D3D11_DEPTH_STENCIL_DESC desc = pDepthStencilDesc != nullptr
|
|
|
|
? *pDepthStencilDesc
|
|
|
|
: D3D11DepthStencilState::DefaultDesc();
|
2017-12-11 01:43:15 +01:00
|
|
|
|
2018-03-18 23:32:01 +01:00
|
|
|
if (FAILED(D3D11DepthStencilState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
2017-12-11 01:43:15 +01:00
|
|
|
|
2017-12-27 14:32:07 +01:00
|
|
|
if (ppDepthStencilState != nullptr) {
|
2017-12-11 01:43:15 +01:00
|
|
|
*ppDepthStencilState = m_dsStateObjects.Create(this, desc);
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_OK;
|
|
|
|
} return S_FALSE;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateRasterizerState(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_RASTERIZER_DESC* pRasterizerDesc,
|
|
|
|
ID3D11RasterizerState** ppRasterizerState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppRasterizerState);
|
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
D3D11_RASTERIZER_DESC1 desc = pRasterizerDesc != nullptr
|
|
|
|
? D3D11RasterizerState::PromoteDesc(pRasterizerDesc)
|
|
|
|
: D3D11RasterizerState::DefaultDesc();
|
2017-12-06 13:16:54 +01:00
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
if (FAILED(D3D11RasterizerState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
2017-12-06 13:16:54 +01:00
|
|
|
|
2017-12-27 14:32:07 +01:00
|
|
|
if (ppRasterizerState != nullptr) {
|
2017-12-06 13:16:54 +01:00
|
|
|
*ppRasterizerState = m_rsStateObjects.Create(this, desc);
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_OK;
|
|
|
|
} return S_FALSE;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
HRESULT D3D11Device::CreateRasterizerState1(
|
|
|
|
const D3D11_RASTERIZER_DESC1* pRasterizerDesc,
|
|
|
|
ID3D11RasterizerState1** ppRasterizerState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppRasterizerState);
|
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
D3D11_RASTERIZER_DESC1 desc = pRasterizerDesc != nullptr
|
|
|
|
? *pRasterizerDesc
|
|
|
|
: D3D11RasterizerState::DefaultDesc();
|
|
|
|
|
|
|
|
if (FAILED(D3D11RasterizerState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (ppRasterizerState != nullptr) {
|
|
|
|
*ppRasterizerState = m_rsStateObjects.Create(this, desc);
|
|
|
|
return S_OK;
|
|
|
|
} return S_FALSE;
|
2018-03-17 20:11:00 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateSamplerState(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_SAMPLER_DESC* pSamplerDesc,
|
|
|
|
ID3D11SamplerState** ppSamplerState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppSamplerState);
|
2018-03-18 23:35:40 +01:00
|
|
|
D3D11_SAMPLER_DESC desc = *pSamplerDesc;
|
2017-12-09 20:49:56 +01:00
|
|
|
|
2018-03-18 23:35:40 +01:00
|
|
|
if (FAILED(D3D11SamplerState::NormalizeDesc(&desc)))
|
|
|
|
return E_INVALIDARG;
|
2017-12-09 20:49:56 +01:00
|
|
|
|
|
|
|
if (ppSamplerState == nullptr)
|
2017-12-27 14:32:07 +01:00
|
|
|
return S_FALSE;
|
2017-12-09 20:49:56 +01:00
|
|
|
|
|
|
|
try {
|
2018-03-18 23:35:40 +01:00
|
|
|
*ppSamplerState = m_samplerObjects.Create(this, desc);
|
2017-12-09 20:49:56 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
2017-12-27 14:32:07 +01:00
|
|
|
return E_FAIL;
|
2017-12-09 20:49:56 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateQuery(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_QUERY_DESC* pQueryDesc,
|
|
|
|
ID3D11Query** ppQuery) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppQuery);
|
|
|
|
|
2018-02-18 22:34:23 +01:00
|
|
|
if (pQueryDesc->Query != D3D11_QUERY_EVENT
|
|
|
|
&& pQueryDesc->Query != D3D11_QUERY_OCCLUSION
|
|
|
|
&& pQueryDesc->Query != D3D11_QUERY_TIMESTAMP
|
|
|
|
&& pQueryDesc->Query != D3D11_QUERY_TIMESTAMP_DISJOINT
|
|
|
|
&& pQueryDesc->Query != D3D11_QUERY_PIPELINE_STATISTICS
|
|
|
|
&& pQueryDesc->Query != D3D11_QUERY_OCCLUSION_PREDICATE) {
|
|
|
|
Logger::warn(str::format("D3D11Query: Unsupported query type ", pQueryDesc->Query));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-29 22:20:31 +01:00
|
|
|
if (ppQuery == nullptr)
|
|
|
|
return S_FALSE;
|
2018-02-18 22:34:23 +01:00
|
|
|
|
2017-12-29 22:20:31 +01:00
|
|
|
try {
|
2018-01-01 20:59:54 +01:00
|
|
|
*ppQuery = ref(new D3D11Query(this, *pQueryDesc));
|
2017-12-29 22:20:31 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreatePredicate(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_QUERY_DESC* pPredicateDesc,
|
|
|
|
ID3D11Predicate** ppPredicate) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppPredicate);
|
|
|
|
|
2018-02-18 22:34:23 +01:00
|
|
|
if (pPredicateDesc->Query != D3D11_QUERY_OCCLUSION_PREDICATE)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (ppPredicate == nullptr)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
*ppPredicate = ref(new D3D11Query(this, *pPredicateDesc));
|
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateCounter(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_COUNTER_DESC* pCounterDesc,
|
|
|
|
ID3D11Counter** ppCounter) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppCounter);
|
|
|
|
|
2018-06-11 14:01:45 +02:00
|
|
|
Logger::err(str::format("D3D11: Unsupported counter: ", pCounterDesc->Counter));
|
|
|
|
return E_INVALIDARG;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDeferredContext(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT ContextFlags,
|
|
|
|
ID3D11DeviceContext** ppDeferredContext) {
|
2018-01-23 09:23:31 +01:00
|
|
|
*ppDeferredContext = ref(new D3D11DeferredContext(this, m_dxvkDevice, ContextFlags));
|
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDeferredContext1(
|
|
|
|
UINT ContextFlags,
|
|
|
|
ID3D11DeviceContext1** ppDeferredContext) {
|
|
|
|
*ppDeferredContext = ref(new D3D11DeferredContext(this, m_dxvkDevice, ContextFlags));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CreateDeviceContextState(
|
|
|
|
UINT Flags,
|
|
|
|
const D3D_FEATURE_LEVEL* pFeatureLevels,
|
|
|
|
UINT FeatureLevels,
|
|
|
|
UINT SDKVersion,
|
|
|
|
REFIID EmulatedInterface,
|
|
|
|
D3D_FEATURE_LEVEL* pChosenFeatureLevel,
|
|
|
|
ID3DDeviceContextState** ppContextState) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppContextState);
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
Logger::err("D3D11Device::CreateDeviceContextState: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::OpenSharedResource(
|
2017-10-11 09:51:48 +02:00
|
|
|
HANDLE hResource,
|
|
|
|
REFIID ReturnedInterface,
|
|
|
|
void** ppResource) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppResource);
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11Device::OpenSharedResource: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::OpenSharedResource1(
|
|
|
|
HANDLE hResource,
|
|
|
|
REFIID ReturnedInterface,
|
|
|
|
void** ppResource) {
|
2018-04-02 12:04:20 +02:00
|
|
|
InitReturnPtr(ppResource);
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
Logger::err("D3D11Device::OpenSharedResource1: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::OpenSharedResourceByName(
|
|
|
|
LPCWSTR lpName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
REFIID returnedInterface,
|
2018-04-02 12:04:20 +02:00
|
|
|
void** ppResource) {
|
|
|
|
InitReturnPtr(ppResource);
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
Logger::err("D3D11Device::OpenSharedResourceByName: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CheckFormatSupport(
|
2017-10-11 09:51:48 +02:00
|
|
|
DXGI_FORMAT Format,
|
|
|
|
UINT* pFormatSupport) {
|
2018-03-21 13:31:22 +01:00
|
|
|
return GetFormatSupportFlags(Format, pFormatSupport, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CheckMultisampleQualityLevels(
|
2017-10-11 09:51:48 +02:00
|
|
|
DXGI_FORMAT Format,
|
|
|
|
UINT SampleCount,
|
|
|
|
UINT* pNumQualityLevels) {
|
2017-12-09 19:44:06 +01:00
|
|
|
// There are many error conditions, so we'll just assume
|
|
|
|
// that we will fail and return a non-zero value in case
|
|
|
|
// the device does actually support the format.
|
2017-12-09 14:46:23 +01:00
|
|
|
*pNumQualityLevels = 0;
|
|
|
|
|
2017-12-09 19:44:06 +01:00
|
|
|
// We need to check whether the format is
|
2017-12-19 14:47:35 +01:00
|
|
|
VkFormat format = m_dxgiAdapter->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
Format, DXGI_VK_FORMAT_MODE_ANY).Format;
|
2017-12-09 14:46:23 +01:00
|
|
|
|
|
|
|
if (format == VK_FORMAT_UNDEFINED) {
|
|
|
|
Logger::err(str::format("D3D11: Unsupported format: ", Format));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2017-12-09 19:44:06 +01:00
|
|
|
// D3D may legally query non-power-of-two sample counts as well
|
2017-12-09 14:46:23 +01:00
|
|
|
VkSampleCountFlagBits sampleCountFlag = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
2018-04-13 13:46:45 +02:00
|
|
|
if (FAILED(DecodeSampleCount(SampleCount, &sampleCountFlag)))
|
2018-03-05 01:08:26 +01:00
|
|
|
return E_INVALIDARG;
|
2017-12-09 14:46:23 +01:00
|
|
|
|
2017-12-09 19:44:06 +01:00
|
|
|
// Check if the device supports the given combination of format
|
|
|
|
// and sample count. D3D exposes the opaque concept of quality
|
|
|
|
// levels to the application, we'll just define one such level.
|
2017-12-09 14:46:23 +01:00
|
|
|
VkImageFormatProperties formatProps;
|
|
|
|
|
|
|
|
VkResult status = m_dxvkAdapter->imageFormatProperties(
|
|
|
|
format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
|
|
|
|
VK_IMAGE_USAGE_SAMPLED_BIT, 0, formatProps);
|
|
|
|
|
|
|
|
if ((status == VK_SUCCESS) && (formatProps.sampleCounts & sampleCountFlag))
|
|
|
|
*pNumQualityLevels = 1;
|
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Device::CheckCounterInfo(D3D11_COUNTER_INFO* pCounterInfo) {
|
2018-06-11 14:01:45 +02:00
|
|
|
// We basically don't support counters
|
|
|
|
pCounterInfo->LastDeviceDependentCounter = D3D11_COUNTER(0);
|
|
|
|
pCounterInfo->NumSimultaneousCounters = 0;
|
|
|
|
pCounterInfo->NumDetectableParallelUnits = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CheckCounter(
|
2017-10-11 09:51:48 +02:00
|
|
|
const D3D11_COUNTER_DESC* pDesc,
|
|
|
|
D3D11_COUNTER_TYPE* pType,
|
|
|
|
UINT* pActiveCounters,
|
|
|
|
LPSTR szName,
|
|
|
|
UINT* pNameLength,
|
|
|
|
LPSTR szUnits,
|
|
|
|
UINT* pUnitsLength,
|
|
|
|
LPSTR szDescription,
|
|
|
|
UINT* pDescriptionLength) {
|
2018-06-11 14:01:45 +02:00
|
|
|
Logger::err("D3D11: Counters not supported");
|
|
|
|
return E_INVALIDARG;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::CheckFeatureSupport(
|
2017-10-11 09:51:48 +02:00
|
|
|
D3D11_FEATURE Feature,
|
|
|
|
void* pFeatureSupportData,
|
|
|
|
UINT FeatureSupportDataSize) {
|
2017-12-19 11:05:41 +01:00
|
|
|
switch (Feature) {
|
|
|
|
case D3D11_FEATURE_THREADING: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_THREADING))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-03-21 04:58:31 +01:00
|
|
|
// We report native support for command lists here so that we do not actually
|
|
|
|
// have to re-implement the UpdateSubresource bug from the D3D11 runtime, see
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476486(v=vs.85).aspx)
|
2017-12-19 11:05:41 +01:00
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_THREADING*>(pFeatureSupportData);
|
|
|
|
info->DriverConcurrentCreates = TRUE;
|
2018-03-19 17:57:20 +01:00
|
|
|
info->DriverCommandLists = TRUE;
|
2017-12-19 11:05:41 +01:00
|
|
|
} return S_OK;
|
|
|
|
|
|
|
|
case D3D11_FEATURE_DOUBLES: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_DOUBLES))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-06-07 15:35:24 +02:00
|
|
|
const VkPhysicalDeviceFeatures& features = m_dxvkDevice->features();
|
|
|
|
|
2017-12-19 11:05:41 +01:00
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_DOUBLES*>(pFeatureSupportData);
|
2018-06-07 15:35:24 +02:00
|
|
|
info->DoublePrecisionFloatShaderOps = features.shaderFloat64 && features.shaderInt64;
|
2017-12-19 11:05:41 +01:00
|
|
|
} return S_OK;
|
|
|
|
|
|
|
|
case D3D11_FEATURE_FORMAT_SUPPORT: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_FORMAT_SUPPORT*>(pFeatureSupportData);
|
2018-03-21 13:31:22 +01:00
|
|
|
return GetFormatSupportFlags(info->InFormat, &info->OutFormatSupport, nullptr);
|
|
|
|
} return S_OK;
|
|
|
|
|
|
|
|
case D3D11_FEATURE_FORMAT_SUPPORT2: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT2))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_FORMAT_SUPPORT2*>(pFeatureSupportData);
|
|
|
|
return GetFormatSupportFlags(info->InFormat, nullptr, &info->OutFormatSupport2);
|
2017-12-19 11:05:41 +01:00
|
|
|
} return S_OK;
|
|
|
|
|
2017-12-29 12:51:54 +01:00
|
|
|
case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS*>(pFeatureSupportData);
|
|
|
|
info->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = TRUE;
|
|
|
|
} return S_OK;
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
case D3D11_FEATURE_D3D11_OPTIONS: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS))
|
|
|
|
return E_INVALIDARG;
|
2018-03-20 23:25:23 +01:00
|
|
|
|
|
|
|
// TODO implement, most of these are required for FL 11.1
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/hh404457(v=vs.85).aspx
|
2018-03-21 15:08:17 +01:00
|
|
|
const VkPhysicalDeviceFeatures& features = m_dxvkDevice->features();
|
|
|
|
|
2018-03-17 20:11:00 +01:00
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_D3D11_OPTIONS*>(pFeatureSupportData);
|
2018-03-21 15:08:17 +01:00
|
|
|
info->OutputMergerLogicOp = features.logicOp;
|
2018-03-20 23:25:23 +01:00
|
|
|
info->UAVOnlyRenderingForcedSampleCount = FALSE;
|
|
|
|
info->DiscardAPIsSeenByDriver = FALSE;
|
|
|
|
info->FlagsForUpdateAndCopySeenByDriver = FALSE;
|
|
|
|
info->ClearView = FALSE;
|
|
|
|
info->CopyWithOverlap = FALSE;
|
|
|
|
info->ConstantBufferPartialUpdate = TRUE;
|
|
|
|
info->ConstantBufferOffsetting = TRUE;
|
|
|
|
info->MapNoOverwriteOnDynamicConstantBuffer = TRUE;
|
|
|
|
info->MapNoOverwriteOnDynamicBufferSRV = TRUE;
|
|
|
|
info->MultisampleRTVWithForcedSampleCountOne = FALSE;
|
|
|
|
info->SAD4ShaderInstructions = FALSE;
|
|
|
|
info->ExtendedDoublesShaderInstructions = FALSE;
|
|
|
|
info->ExtendedResourceSharing = FALSE;
|
2018-03-17 20:11:00 +01:00
|
|
|
} return S_OK;
|
|
|
|
|
|
|
|
case D3D11_FEATURE_ARCHITECTURE_INFO: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_ARCHITECTURE_INFO))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_ARCHITECTURE_INFO*>(pFeatureSupportData);
|
2018-03-21 04:58:31 +01:00
|
|
|
info->TileBasedDeferredRenderer = FALSE;
|
2018-03-17 20:11:00 +01:00
|
|
|
} return S_OK;
|
2018-03-21 04:58:31 +01:00
|
|
|
|
|
|
|
case D3D11_FEATURE_SHADER_MIN_PRECISION_SUPPORT: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_SHADER_MIN_PRECISION_SUPPORT))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
// Report that we only support full 32-bit operations
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_SHADER_MIN_PRECISION_SUPPORT*>(pFeatureSupportData);
|
|
|
|
info->PixelShaderMinPrecision = 0;
|
|
|
|
info->AllOtherShaderStagesMinPrecision = 0;
|
|
|
|
} return S_OK;
|
|
|
|
|
|
|
|
case D3D11_FEATURE_D3D9_SHADOW_SUPPORT: {
|
|
|
|
if (FeatureSupportDataSize != sizeof(D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
auto info = static_cast<D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT*>(pFeatureSupportData);
|
|
|
|
info->SupportsDepthAsTextureWithLessEqualComparisonFilter = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
} break;
|
2018-03-17 20:11:00 +01:00
|
|
|
|
2017-12-19 11:05:41 +01:00
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
2017-12-29 12:51:54 +01:00
|
|
|
"D3D11Device: CheckFeatureSupport: Unknown feature: ",
|
2017-12-19 11:05:41 +01:00
|
|
|
Feature));
|
2018-03-21 15:08:17 +01:00
|
|
|
return E_NOTIMPL;
|
2017-12-19 11:05:41 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::GetPrivateData(
|
2017-10-11 09:51:48 +02:00
|
|
|
REFGUID guid, UINT* pDataSize, void* pData) {
|
2018-03-28 21:24:52 +02:00
|
|
|
return m_container->GetPrivateData(guid, pDataSize, pData);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::SetPrivateData(
|
2017-10-11 09:51:48 +02:00
|
|
|
REFGUID guid, UINT DataSize, const void* pData) {
|
2018-03-28 21:24:52 +02:00
|
|
|
return m_container->SetPrivateData(guid, DataSize, pData);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::SetPrivateDataInterface(
|
2017-10-11 09:51:48 +02:00
|
|
|
REFGUID guid, const IUnknown* pData) {
|
2018-03-28 21:24:52 +02:00
|
|
|
return m_container->SetPrivateDataInterface(guid, pData);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
D3D_FEATURE_LEVEL STDMETHODCALLTYPE D3D11Device::GetFeatureLevel() {
|
2017-10-11 09:51:48 +02:00
|
|
|
return m_featureLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
UINT STDMETHODCALLTYPE D3D11Device::GetCreationFlags() {
|
2017-10-11 09:51:48 +02:00
|
|
|
return m_featureFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::GetDeviceRemovedReason() {
|
2018-01-18 23:59:40 +01:00
|
|
|
static std::atomic<bool> s_errorShown = { false };
|
2018-01-12 11:39:59 +01:00
|
|
|
|
|
|
|
if (!s_errorShown.exchange(true))
|
|
|
|
Logger::warn("D3D11Device::GetDeviceRemovedReason: Stub");
|
|
|
|
|
|
|
|
return S_OK;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Device::GetImmediateContext(ID3D11DeviceContext** ppImmediateContext) {
|
2017-12-11 17:01:38 +01:00
|
|
|
*ppImmediateContext = ref(m_context);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 20:11:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Device::GetImmediateContext1(ID3D11DeviceContext1 ** ppImmediateContext) {
|
|
|
|
*ppImmediateContext = ref(m_context);
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Device::SetExceptionMode(UINT RaiseFlags) {
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11Device::SetExceptionMode: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
UINT STDMETHODCALLTYPE D3D11Device::GetExceptionMode() {
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11Device::GetExceptionMode: Not implemented");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-11 15:32:24 +02:00
|
|
|
|
2018-05-05 12:57:22 +02:00
|
|
|
DXGI_VK_FORMAT_INFO D3D11Device::LookupFormat(
|
|
|
|
DXGI_FORMAT Format,
|
|
|
|
DXGI_VK_FORMAT_MODE Mode) const {
|
|
|
|
return m_dxgiAdapter->LookupFormat(Format, Mode);
|
2017-12-19 16:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-11 12:23:55 +01:00
|
|
|
DxvkBufferSlice D3D11Device::AllocateCounterSlice() {
|
|
|
|
std::lock_guard<std::mutex> lock(m_counterMutex);
|
|
|
|
|
|
|
|
if (m_counterSlices.size() == 0)
|
|
|
|
throw DxvkError("D3D11Device: Failed to allocate counter slice");
|
|
|
|
|
|
|
|
uint32_t sliceId = m_counterSlices.back();
|
|
|
|
m_counterSlices.pop_back();
|
|
|
|
|
|
|
|
return DxvkBufferSlice(m_counterBuffer,
|
|
|
|
sizeof(D3D11UavCounter) * sliceId,
|
|
|
|
sizeof(D3D11UavCounter));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11Device::FreeCounterSlice(const DxvkBufferSlice& Slice) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_counterMutex);
|
|
|
|
m_counterSlices.push_back(Slice.offset() / sizeof(D3D11UavCounter));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-13 05:00:27 +01:00
|
|
|
void D3D11Device::FlushInitContext() {
|
2018-01-13 23:40:17 +01:00
|
|
|
LockResourceInitContext();
|
|
|
|
if (m_resourceInitCommands != 0)
|
|
|
|
SubmitResourceInitCommands();
|
|
|
|
UnlockResourceInitContext(0);
|
2018-01-13 05:00:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-14 15:59:55 +01:00
|
|
|
VkPipelineStageFlags D3D11Device::GetEnabledShaderStages() const {
|
|
|
|
VkPipelineStageFlags enabledShaderPipelineStages
|
|
|
|
= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
|
|
|
| VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
|
|
|
|
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
|
|
|
|
|
|
if (m_dxvkDevice->features().geometryShader)
|
|
|
|
enabledShaderPipelineStages |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
|
|
|
|
|
|
|
|
if (m_dxvkDevice->features().tessellationShader) {
|
|
|
|
enabledShaderPipelineStages |= VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
|
|
|
|
| VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return enabledShaderPipelineStages;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 15:32:24 +02:00
|
|
|
bool D3D11Device::CheckFeatureLevelSupport(
|
2017-12-02 16:47:06 +01:00
|
|
|
const Rc<DxvkAdapter>& adapter,
|
2017-10-11 15:32:24 +02:00
|
|
|
D3D_FEATURE_LEVEL featureLevel) {
|
2017-12-02 16:47:06 +01:00
|
|
|
// We currently only support 11_0 interfaces
|
2018-01-30 12:19:53 +01:00
|
|
|
if (featureLevel > GetMaxFeatureLevel())
|
2017-12-02 16:47:06 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check whether all features are supported
|
|
|
|
const VkPhysicalDeviceFeatures features
|
|
|
|
= GetDeviceFeatures(adapter, featureLevel);
|
|
|
|
|
|
|
|
if (!adapter->checkFeatureSupport(features))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO also check for required limits
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkPhysicalDeviceFeatures D3D11Device::GetDeviceFeatures(
|
|
|
|
const Rc<DxvkAdapter>& adapter,
|
|
|
|
D3D_FEATURE_LEVEL featureLevel) {
|
|
|
|
VkPhysicalDeviceFeatures supported = adapter->features();
|
2018-01-28 19:37:22 +01:00
|
|
|
VkPhysicalDeviceFeatures enabled = {};
|
2017-12-02 16:47:06 +01:00
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_9_1) {
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.depthClamp = VK_TRUE;
|
|
|
|
enabled.depthBiasClamp = VK_TRUE;
|
|
|
|
enabled.fillModeNonSolid = VK_TRUE;
|
|
|
|
enabled.pipelineStatisticsQuery = supported.pipelineStatisticsQuery;
|
2018-02-08 10:06:10 +01:00
|
|
|
enabled.sampleRateShading = VK_TRUE;
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.samplerAnisotropy = VK_TRUE;
|
|
|
|
enabled.shaderClipDistance = VK_TRUE;
|
|
|
|
enabled.shaderCullDistance = VK_TRUE;
|
2018-01-09 00:51:10 +01:00
|
|
|
enabled.robustBufferAccess = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_9_2) {
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.occlusionQueryPrecise = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_9_3) {
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.multiViewport = VK_TRUE;
|
|
|
|
enabled.independentBlend = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_10_0) {
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.fullDrawIndexUint32 = VK_TRUE;
|
|
|
|
enabled.fragmentStoresAndAtomics = VK_TRUE;
|
|
|
|
enabled.geometryShader = VK_TRUE;
|
|
|
|
enabled.logicOp = supported.logicOp;
|
|
|
|
enabled.shaderImageGatherExtended = VK_TRUE;
|
|
|
|
enabled.textureCompressionBC = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_10_1) {
|
2018-01-18 08:42:57 +01:00
|
|
|
enabled.dualSrcBlend = VK_TRUE;
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.imageCubeArray = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_11_0) {
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.shaderFloat64 = supported.shaderFloat64;
|
|
|
|
enabled.shaderInt64 = supported.shaderInt64;
|
|
|
|
enabled.tessellationShader = VK_TRUE;
|
2018-05-26 20:34:40 +02:00
|
|
|
// TODO enable unconditionally once RADV gains support
|
|
|
|
enabled.shaderStorageImageMultisample = supported.shaderStorageImageMultisample;
|
2018-03-21 12:57:29 +01:00
|
|
|
enabled.shaderStorageImageReadWithoutFormat = supported.shaderStorageImageReadWithoutFormat;
|
2018-01-01 17:14:06 +01:00
|
|
|
enabled.shaderStorageImageWriteWithoutFormat = VK_TRUE;
|
2017-12-02 16:47:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 23:39:40 +01:00
|
|
|
if (featureLevel >= D3D_FEATURE_LEVEL_11_1) {
|
|
|
|
enabled.logicOp = VK_TRUE;
|
|
|
|
enabled.vertexPipelineStoresAndAtomics = VK_TRUE;
|
|
|
|
}
|
|
|
|
|
2017-12-02 16:47:06 +01:00
|
|
|
return enabled;
|
2017-10-11 15:32:24 +02:00
|
|
|
}
|
|
|
|
|
2017-12-06 18:54:01 +01:00
|
|
|
|
|
|
|
HRESULT D3D11Device::CreateShaderModule(
|
|
|
|
D3D11ShaderModule* pShaderModule,
|
|
|
|
const void* pShaderBytecode,
|
|
|
|
size_t BytecodeLength,
|
2018-04-06 17:54:02 +02:00
|
|
|
ID3D11ClassLinkage* pClassLinkage,
|
2018-06-23 17:14:35 +02:00
|
|
|
const DxbcModuleInfo* pModuleInfo,
|
2018-04-06 17:54:02 +02:00
|
|
|
DxbcProgramType ProgramType) {
|
2017-12-12 01:07:07 +01:00
|
|
|
if (pClassLinkage != nullptr)
|
|
|
|
Logger::warn("D3D11Device::CreateShaderModule: Class linkage not supported");
|
2017-12-06 18:54:01 +01:00
|
|
|
|
|
|
|
try {
|
2018-04-06 17:54:02 +02:00
|
|
|
*pShaderModule = m_shaderModules.GetShaderModule(
|
2018-06-23 17:14:35 +02:00
|
|
|
pModuleInfo, pShaderBytecode, BytecodeLength, ProgramType);
|
2017-12-06 18:54:01 +01:00
|
|
|
return S_OK;
|
|
|
|
} catch (const DxvkError& e) {
|
|
|
|
Logger::err(e.message());
|
2017-12-27 14:32:07 +01:00
|
|
|
return E_FAIL;
|
2017-12-06 18:54:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 13:17:16 +01:00
|
|
|
|
2017-12-07 18:51:41 +01:00
|
|
|
void D3D11Device::InitBuffer(
|
2017-12-14 15:59:55 +01:00
|
|
|
D3D11Buffer* pBuffer,
|
2017-12-07 18:51:41 +01:00
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
2018-05-22 21:06:26 +02:00
|
|
|
const DxvkBufferSlice bufferSlice = pBuffer->GetBufferSlice();
|
2017-12-07 18:51:41 +01:00
|
|
|
|
2018-05-22 21:10:39 +02:00
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
pBuffer->GetDesc(&desc);
|
|
|
|
|
2018-03-03 23:33:55 +01:00
|
|
|
if (pInitialData != nullptr && pInitialData->pSysMem != nullptr) {
|
2018-01-13 23:40:17 +01:00
|
|
|
LockResourceInitContext();
|
2018-01-13 05:00:27 +01:00
|
|
|
|
2017-12-07 18:51:41 +01:00
|
|
|
m_resourceInitContext->updateBuffer(
|
2017-12-14 19:07:08 +01:00
|
|
|
bufferSlice.buffer(),
|
2017-12-14 19:09:49 +01:00
|
|
|
bufferSlice.offset(),
|
|
|
|
bufferSlice.length(),
|
2017-12-07 18:51:41 +01:00
|
|
|
pInitialData->pSysMem);
|
2018-01-13 23:40:17 +01:00
|
|
|
|
2018-05-22 21:10:39 +02:00
|
|
|
UnlockResourceInitContext(1);
|
|
|
|
} else if (desc.Usage == D3D11_USAGE_DEFAULT) {
|
|
|
|
LockResourceInitContext();
|
|
|
|
|
|
|
|
m_resourceInitContext->clearBuffer(
|
|
|
|
bufferSlice.buffer(),
|
|
|
|
bufferSlice.offset(),
|
|
|
|
bufferSlice.length(),
|
|
|
|
0u);
|
|
|
|
|
2018-01-13 23:40:17 +01:00
|
|
|
UnlockResourceInitContext(1);
|
2017-12-07 18:51:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-08 23:13:15 +01:00
|
|
|
void D3D11Device::InitTexture(
|
2018-05-22 21:06:26 +02:00
|
|
|
D3D11CommonTexture* pTexture,
|
2017-12-08 23:13:15 +01:00
|
|
|
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
2018-05-22 21:06:26 +02:00
|
|
|
const Rc<DxvkImage> image = pTexture->GetImage();
|
2017-12-10 19:10:17 +01:00
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(image->info().format);
|
2017-12-08 23:13:15 +01:00
|
|
|
|
2018-03-03 23:33:55 +01:00
|
|
|
if (pInitialData != nullptr && pInitialData->pSysMem != nullptr) {
|
2018-01-13 23:40:17 +01:00
|
|
|
LockResourceInitContext();
|
|
|
|
|
2017-12-10 19:10:17 +01:00
|
|
|
// pInitialData is an array that stores an entry for
|
|
|
|
// every single subresource. Since we will define all
|
|
|
|
// subresources, this counts as initialization.
|
2017-12-10 15:57:51 +01:00
|
|
|
VkImageSubresourceLayers subresourceLayers;
|
2017-12-10 19:10:17 +01:00
|
|
|
subresourceLayers.aspectMask = formatInfo->aspectMask;
|
2017-12-10 15:57:51 +01:00
|
|
|
subresourceLayers.mipLevel = 0;
|
|
|
|
subresourceLayers.baseArrayLayer = 0;
|
2017-12-10 19:10:17 +01:00
|
|
|
subresourceLayers.layerCount = 1;
|
2017-12-10 15:57:51 +01:00
|
|
|
|
2017-12-10 19:10:17 +01:00
|
|
|
for (uint32_t layer = 0; layer < image->info().numLayers; layer++) {
|
|
|
|
for (uint32_t level = 0; level < image->info().mipLevels; level++) {
|
|
|
|
subresourceLayers.baseArrayLayer = layer;
|
|
|
|
subresourceLayers.mipLevel = level;
|
|
|
|
|
|
|
|
const uint32_t id = D3D11CalcSubresource(
|
|
|
|
level, layer, image->info().mipLevels);
|
|
|
|
|
|
|
|
m_resourceInitContext->updateImage(
|
|
|
|
image, subresourceLayers,
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
image->mipLevelExtent(level),
|
|
|
|
pInitialData[id].pSysMem,
|
|
|
|
pInitialData[id].SysMemPitch,
|
|
|
|
pInitialData[id].SysMemSlicePitch);
|
|
|
|
}
|
|
|
|
}
|
2018-01-13 23:40:17 +01:00
|
|
|
|
|
|
|
const uint32_t subresourceCount =
|
|
|
|
image->info().numLayers * image->info().mipLevels;
|
|
|
|
UnlockResourceInitContext(subresourceCount);
|
2017-12-10 19:10:17 +01:00
|
|
|
} else {
|
2018-01-13 23:40:17 +01:00
|
|
|
LockResourceInitContext();
|
|
|
|
|
2018-01-19 18:11:20 +01:00
|
|
|
// While the Microsoft docs state that resource contents are
|
|
|
|
// undefined if no initial data is provided, some applications
|
|
|
|
// expect a resource to be pre-cleared. We can only do that
|
|
|
|
// for non-compressed images, but that should be fine.
|
2017-12-10 19:10:17 +01:00
|
|
|
VkImageSubresourceRange subresources;
|
|
|
|
subresources.aspectMask = formatInfo->aspectMask;
|
|
|
|
subresources.baseMipLevel = 0;
|
|
|
|
subresources.levelCount = image->info().mipLevels;
|
|
|
|
subresources.baseArrayLayer = 0;
|
|
|
|
subresources.layerCount = image->info().numLayers;
|
2018-01-02 21:32:39 +01:00
|
|
|
|
2018-01-19 18:11:20 +01:00
|
|
|
if (formatInfo->flags.test(DxvkFormatFlag::BlockCompressed)) {
|
|
|
|
m_resourceInitContext->initImage(
|
|
|
|
image, subresources);
|
2018-01-02 21:32:39 +01:00
|
|
|
} else {
|
2018-01-19 18:11:20 +01:00
|
|
|
if (subresources.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) {
|
|
|
|
m_resourceInitContext->clearColorImage(
|
2018-01-28 19:37:22 +01:00
|
|
|
image, VkClearColorValue(), subresources);
|
2018-01-19 18:11:20 +01:00
|
|
|
} else {
|
|
|
|
VkClearDepthStencilValue value;
|
|
|
|
value.depth = 1.0f;
|
|
|
|
value.stencil = 0;
|
|
|
|
|
|
|
|
m_resourceInitContext->clearDepthStencilImage(
|
|
|
|
image, value, subresources);
|
|
|
|
}
|
2018-01-02 21:32:39 +01:00
|
|
|
}
|
2018-01-13 23:40:17 +01:00
|
|
|
|
|
|
|
UnlockResourceInitContext(1);
|
2017-12-10 15:57:51 +01:00
|
|
|
}
|
2017-12-08 23:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-21 13:31:22 +01:00
|
|
|
HRESULT D3D11Device::GetFormatSupportFlags(DXGI_FORMAT Format, UINT* pFlags1, UINT* pFlags2) const {
|
2018-04-14 16:07:01 +02:00
|
|
|
// Query some general information from DXGI, DXVK and Vulkan about the format
|
|
|
|
const DXGI_VK_FORMAT_INFO fmtMapping = m_dxgiAdapter->LookupFormat(Format, DXGI_VK_FORMAT_MODE_ANY);
|
|
|
|
const VkFormatProperties fmtSupport = m_dxvkAdapter->formatProperties(fmtMapping.Format);
|
|
|
|
const DxvkFormatInfo* fmtProperties = imageFormatInfo(fmtMapping.Format);
|
|
|
|
|
|
|
|
// Reset output flags preemptively
|
|
|
|
if (pFlags1 != nullptr) *pFlags1 = 0;
|
|
|
|
if (pFlags2 != nullptr) *pFlags2 = 0;
|
|
|
|
|
|
|
|
// Unsupported or invalid format
|
|
|
|
if (fmtMapping.Format == VK_FORMAT_UNDEFINED)
|
|
|
|
return E_INVALIDARG;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-03-21 13:31:22 +01:00
|
|
|
UINT flags1 = 0;
|
|
|
|
UINT flags2 = 0;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format can be used for shader resource views with buffers
|
|
|
|
if (fmtSupport.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)
|
2018-03-21 13:31:22 +01:00
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_BUFFER;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format can be used for vertex data
|
|
|
|
if (fmtSupport.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT)
|
2018-03-21 13:31:22 +01:00
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format can be used for index data. Only
|
|
|
|
// these two formats are supported by D3D11.
|
|
|
|
if (Format == DXGI_FORMAT_R16_UINT
|
|
|
|
|| Format == DXGI_FORMAT_R32_UINT)
|
2018-03-21 13:31:22 +01:00
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
|
|
|
// TODO implement stream output
|
|
|
|
// D3D11_FORMAT_SUPPORT_SO_BUFFER
|
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
if (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
|
|
|
|| fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
|
|
|
|
const VkFormat depthFormat = m_dxgiAdapter->LookupFormat(Format, DXGI_VK_FORMAT_MODE_DEPTH).Format;
|
|
|
|
|
|
|
|
if (GetImageTypeSupport(fmtMapping.Format, VK_IMAGE_TYPE_1D)) flags1 |= D3D11_FORMAT_SUPPORT_TEXTURE1D;
|
|
|
|
if (GetImageTypeSupport(fmtMapping.Format, VK_IMAGE_TYPE_2D)) flags1 |= D3D11_FORMAT_SUPPORT_TEXTURE2D;
|
|
|
|
if (GetImageTypeSupport(fmtMapping.Format, VK_IMAGE_TYPE_3D)) flags1 |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
|
|
|
|
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_MIP
|
|
|
|
| D3D11_FORMAT_SUPPORT_CPU_LOCKABLE
|
2018-03-21 13:31:22 +01:00
|
|
|
| D3D11_FORMAT_SUPPORT_CAST_WITHIN_BIT_LAYOUT;
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format can be read
|
|
|
|
if (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) {
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_TEXTURECUBE
|
|
|
|
| D3D11_FORMAT_SUPPORT_SHADER_LOAD
|
|
|
|
| D3D11_FORMAT_SUPPORT_SHADER_GATHER
|
|
|
|
| D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
|
|
|
|
|
|
|
|
if (depthFormat != VK_FORMAT_UNDEFINED) {
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON
|
|
|
|
| D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 13:31:22 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format is a color format that can be used for rendering
|
|
|
|
if (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_RENDER_TARGET
|
|
|
|
| D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
|
|
|
|
|
|
|
|
if (m_dxvkDevice->features().logicOp)
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_OUTPUT_MERGER_LOGIC_OP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format supports blending when used for rendering
|
|
|
|
if (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_BLENDABLE;
|
|
|
|
|
|
|
|
// Format is a depth-stencil format that can be used for rendering
|
|
|
|
if (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_DEPTH_STENCIL;
|
|
|
|
|
|
|
|
// FIXME implement properly. This would require a VkSurface.
|
|
|
|
if (Format == DXGI_FORMAT_R8G8B8A8_UNORM
|
|
|
|
|| Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
|
|
|
|| Format == DXGI_FORMAT_B8G8R8A8_UNORM
|
|
|
|
|| Format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
|
|
|
|
|| Format == DXGI_FORMAT_R16G16B16A16_FLOAT
|
|
|
|
|| Format == DXGI_FORMAT_R10G10B10A2_UNORM
|
|
|
|
|| Format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_DISPLAY;
|
|
|
|
|
|
|
|
// Query multisample support for this format
|
|
|
|
VkImageFormatProperties imgFmtProperties;
|
|
|
|
|
|
|
|
VkResult status = m_dxvkAdapter->imageFormatProperties(fmtMapping.Format,
|
|
|
|
VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
|
|
|
|
(fmtProperties->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
|
|
|
|
? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
|
|
|
: VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
|
|
|
0, imgFmtProperties);
|
|
|
|
|
|
|
|
if (status == VK_SUCCESS && imgFmtProperties.sampleCounts > VK_SAMPLE_COUNT_1_BIT) {
|
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
|
|
|
|
| D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
|
|
|
|
| D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
|
|
|
|
}
|
2018-03-21 13:31:22 +01:00
|
|
|
}
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Format can be used for storage images or storage texel buffers
|
|
|
|
if ((fmtSupport.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT)
|
2018-04-14 23:20:35 +02:00
|
|
|
&& (fmtSupport.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
|
2018-03-21 13:31:22 +01:00
|
|
|
flags1 |= D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW;
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE;
|
|
|
|
|
|
|
|
if (m_dxvkDevice->features().shaderStorageImageReadWithoutFormat
|
|
|
|
|| Format == DXGI_FORMAT_R32_UINT
|
|
|
|
|| Format == DXGI_FORMAT_R32_SINT
|
|
|
|
|| Format == DXGI_FORMAT_R32_FLOAT)
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD;
|
2018-04-14 16:07:01 +02:00
|
|
|
|
|
|
|
if (Format == DXGI_FORMAT_R32_UINT
|
|
|
|
|| Format == DXGI_FORMAT_R32_SINT) {
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_ADD
|
|
|
|
| D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_BITWISE_OPS
|
|
|
|
| D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_COMPARE_STORE_OR_COMPARE_EXCHANGE
|
|
|
|
| D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_EXCHANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Format == DXGI_FORMAT_R32_SINT)
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_SIGNED_MIN_OR_MAX;
|
|
|
|
|
|
|
|
if (Format == DXGI_FORMAT_R32_UINT)
|
|
|
|
flags2 |= D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_UNSIGNED_MIN_OR_MAX;
|
2018-03-21 13:31:22 +01:00
|
|
|
}
|
2017-12-19 11:05:41 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
// Write back format support flags
|
2018-03-21 13:31:22 +01:00
|
|
|
if (pFlags1 != nullptr) *pFlags1 = flags1;
|
|
|
|
if (pFlags2 != nullptr) *pFlags2 = flags2;
|
2017-12-19 11:05:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-11 12:23:55 +01:00
|
|
|
|
2018-04-14 16:07:01 +02:00
|
|
|
BOOL D3D11Device::GetImageTypeSupport(VkFormat Format, VkImageType Type) const {
|
|
|
|
VkImageFormatProperties props;
|
|
|
|
|
|
|
|
VkResult status = m_dxvkAdapter->imageFormatProperties(
|
|
|
|
Format, Type, VK_IMAGE_TILING_OPTIMAL,
|
|
|
|
VK_IMAGE_USAGE_SAMPLED_BIT, 0, props);
|
|
|
|
|
|
|
|
return status == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-11 12:23:55 +01:00
|
|
|
void D3D11Device::CreateCounterBuffer() {
|
|
|
|
const uint32_t MaxCounterStructs = 1 << 16;
|
|
|
|
|
|
|
|
// The counter buffer is used as a storage buffer
|
|
|
|
DxvkBufferCreateInfo info;
|
|
|
|
info.size = MaxCounterStructs * sizeof(D3D11UavCounter);
|
|
|
|
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
|
|
|
info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT
|
|
|
|
| GetEnabledShaderStages();
|
|
|
|
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT
|
|
|
|
| VK_ACCESS_SHADER_READ_BIT
|
|
|
|
| VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
m_counterBuffer = m_dxvkDevice->createBuffer(
|
|
|
|
info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
// Init the counter struct allocator as well
|
|
|
|
m_counterSlices.resize(MaxCounterStructs);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < MaxCounterStructs; i++)
|
|
|
|
m_counterSlices[i] = MaxCounterStructs - i - 1;
|
|
|
|
}
|
|
|
|
|
2018-01-13 23:40:17 +01:00
|
|
|
|
|
|
|
void D3D11Device::LockResourceInitContext() {
|
|
|
|
m_resourceInitMutex.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11Device::UnlockResourceInitContext(uint64_t CommandCount) {
|
|
|
|
m_resourceInitCommands += CommandCount;
|
|
|
|
|
|
|
|
if (m_resourceInitCommands >= InitCommandThreshold)
|
|
|
|
SubmitResourceInitCommands();
|
|
|
|
|
|
|
|
m_resourceInitMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11Device::SubmitResourceInitCommands() {
|
|
|
|
m_dxvkDevice->submitCommandList(
|
|
|
|
m_resourceInitContext->endRecording(),
|
|
|
|
nullptr, nullptr);
|
|
|
|
|
|
|
|
m_resourceInitContext->beginRecording(
|
|
|
|
m_dxvkDevice->createCommandList());
|
|
|
|
|
|
|
|
m_resourceInitCommands = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-30 12:19:53 +01:00
|
|
|
|
|
|
|
D3D_FEATURE_LEVEL D3D11Device::GetMaxFeatureLevel() {
|
2018-03-18 23:39:40 +01:00
|
|
|
static const std::array<std::pair<std::string, D3D_FEATURE_LEVEL>, 7> s_featureLevels = {{
|
|
|
|
{ "11_1", D3D_FEATURE_LEVEL_11_1 },
|
2018-01-30 12:19:53 +01:00
|
|
|
{ "11_0", D3D_FEATURE_LEVEL_11_0 },
|
|
|
|
{ "10_1", D3D_FEATURE_LEVEL_10_1 },
|
|
|
|
{ "10_0", D3D_FEATURE_LEVEL_10_0 },
|
|
|
|
{ "9_3", D3D_FEATURE_LEVEL_9_3 },
|
|
|
|
{ "9_2", D3D_FEATURE_LEVEL_9_2 },
|
|
|
|
{ "9_1", D3D_FEATURE_LEVEL_9_1 },
|
|
|
|
}};
|
|
|
|
|
|
|
|
const std::string maxLevel = env::getEnvVar(L"DXVK_FEATURE_LEVEL");
|
|
|
|
|
|
|
|
auto entry = std::find_if(s_featureLevels.begin(), s_featureLevels.end(),
|
|
|
|
[&] (const std::pair<std::string, D3D_FEATURE_LEVEL>& pair) {
|
|
|
|
return pair.first == maxLevel;
|
|
|
|
});
|
|
|
|
|
|
|
|
return entry != s_featureLevels.end()
|
|
|
|
? entry->second
|
|
|
|
: D3D_FEATURE_LEVEL_11_0;
|
|
|
|
}
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|