1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-08 10:46:09 +01:00
dxvk/src/d3d11/d3d11_device.h

353 lines
13 KiB
C
Raw Normal View History

2017-10-11 09:51:48 +02:00
#pragma once
#include <mutex>
#include <vector>
#include "../dxbc/dxbc_options.h"
2017-12-12 12:50:52 +01:00
#include "../dxgi/dxgi_object.h"
#include "../util/com/com_private_data.h"
#include "d3d11_interfaces.h"
#include "d3d11_state.h"
#include "d3d11_util.h"
2017-10-11 09:51:48 +02:00
namespace dxvk {
class DxgiAdapter;
class D3D11Buffer;
2017-12-29 22:20:31 +01:00
class D3D11Counter;
2017-10-11 09:51:48 +02:00
class D3D11DeviceContext;
class D3D11ImmediateContext;
2017-12-29 22:20:31 +01:00
class D3D11Predicate;
class D3D11PresentDevice;
2017-12-29 22:20:31 +01:00
class D3D11Query;
class D3D11ShaderModule;
2017-12-19 16:01:50 +01:00
class D3D11Texture1D;
class D3D11Texture2D;
class D3D11Texture3D;
2017-10-11 09:51:48 +02:00
class D3D11Device : public ComObject<ID3D11Device1> {
/// Maximum number of resource init commands per command buffer
constexpr static uint64_t InitCommandThreshold = 50;
2017-10-11 09:51:48 +02:00
public:
D3D11Device(
2017-11-27 15:51:53 +01:00
IDXGIDevicePrivate* dxgiDevice,
D3D_FEATURE_LEVEL featureLevel,
UINT featureFlags);
2017-10-11 09:51:48 +02:00
~D3D11Device();
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateBuffer(
2017-10-11 09:51:48 +02:00
const D3D11_BUFFER_DESC* pDesc,
const D3D11_SUBRESOURCE_DATA* pInitialData,
ID3D11Buffer** ppBuffer) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateTexture1D(
2017-10-11 09:51:48 +02:00
const D3D11_TEXTURE1D_DESC* pDesc,
const D3D11_SUBRESOURCE_DATA* pInitialData,
ID3D11Texture1D** ppTexture1D) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateTexture2D(
2017-10-11 09:51:48 +02:00
const D3D11_TEXTURE2D_DESC* pDesc,
const D3D11_SUBRESOURCE_DATA* pInitialData,
ID3D11Texture2D** ppTexture2D) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateTexture3D(
2017-10-11 09:51:48 +02:00
const D3D11_TEXTURE3D_DESC* pDesc,
const D3D11_SUBRESOURCE_DATA* pInitialData,
ID3D11Texture3D** ppTexture3D) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateShaderResourceView(
2017-10-11 09:51:48 +02:00
ID3D11Resource* pResource,
const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc,
ID3D11ShaderResourceView** ppSRView) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateUnorderedAccessView(
2017-10-11 09:51:48 +02:00
ID3D11Resource* pResource,
const D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc,
ID3D11UnorderedAccessView** ppUAView) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateRenderTargetView(
2017-10-11 09:51:48 +02:00
ID3D11Resource* pResource,
const D3D11_RENDER_TARGET_VIEW_DESC* pDesc,
ID3D11RenderTargetView** ppRTView) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateDepthStencilView(
2017-10-11 09:51:48 +02:00
ID3D11Resource* pResource,
const D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc,
ID3D11DepthStencilView** ppDepthStencilView) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE 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) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateVertexShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11VertexShader** ppVertexShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateGeometryShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11GeometryShader** ppGeometryShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE 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) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreatePixelShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11PixelShader** ppPixelShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateHullShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11HullShader** ppHullShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateDomainShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11DomainShader** ppDomainShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateComputeShader(
2017-10-11 09:51:48 +02:00
const void* pShaderBytecode,
SIZE_T BytecodeLength,
ID3D11ClassLinkage* pClassLinkage,
ID3D11ComputeShader** ppComputeShader) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateClassLinkage(
2017-10-11 09:51:48 +02:00
ID3D11ClassLinkage** ppLinkage) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateBlendState(
2017-10-11 09:51:48 +02:00
const D3D11_BLEND_DESC* pBlendStateDesc,
ID3D11BlendState** ppBlendState) final;
HRESULT STDMETHODCALLTYPE CreateBlendState1(
const D3D11_BLEND_DESC1* pBlendStateDesc,
ID3D11BlendState1** ppBlendState) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateDepthStencilState(
2017-10-11 09:51:48 +02:00
const D3D11_DEPTH_STENCIL_DESC* pDepthStencilDesc,
ID3D11DepthStencilState** ppDepthStencilState) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateRasterizerState(
2017-10-11 09:51:48 +02:00
const D3D11_RASTERIZER_DESC* pRasterizerDesc,
ID3D11RasterizerState** ppRasterizerState) final;
HRESULT STDMETHODCALLTYPE CreateRasterizerState1(
const D3D11_RASTERIZER_DESC1* pRasterizerDesc,
ID3D11RasterizerState1** ppRasterizerState) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateSamplerState(
2017-10-11 09:51:48 +02:00
const D3D11_SAMPLER_DESC* pSamplerDesc,
ID3D11SamplerState** ppSamplerState) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateQuery(
2017-10-11 09:51:48 +02:00
const D3D11_QUERY_DESC* pQueryDesc,
ID3D11Query** ppQuery) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreatePredicate(
2017-10-11 09:51:48 +02:00
const D3D11_QUERY_DESC* pPredicateDesc,
ID3D11Predicate** ppPredicate) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateCounter(
2017-10-11 09:51:48 +02:00
const D3D11_COUNTER_DESC* pCounterDesc,
ID3D11Counter** ppCounter) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CreateDeferredContext(
2017-10-11 09:51:48 +02:00
UINT ContextFlags,
ID3D11DeviceContext** ppDeferredContext) final;
HRESULT STDMETHODCALLTYPE CreateDeferredContext1(
UINT ContextFlags,
ID3D11DeviceContext1** ppDeferredContext) final;
HRESULT STDMETHODCALLTYPE CreateDeviceContextState(
UINT Flags,
const D3D_FEATURE_LEVEL* pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
REFIID EmulatedInterface,
D3D_FEATURE_LEVEL* pChosenFeatureLevel,
ID3DDeviceContextState** ppContextState) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE OpenSharedResource(
2017-10-11 09:51:48 +02:00
HANDLE hResource,
REFIID ReturnedInterface,
void** ppResource) final;
HRESULT STDMETHODCALLTYPE OpenSharedResource1(
HANDLE hResource,
REFIID returnedInterface,
void** ppResource) final;
HRESULT STDMETHODCALLTYPE OpenSharedResourceByName(
LPCWSTR lpName,
DWORD dwDesiredAccess,
REFIID returnedInterface,
void** ppResource) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CheckFormatSupport(
2017-10-11 09:51:48 +02:00
DXGI_FORMAT Format,
UINT* pFormatSupport) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels(
2017-10-11 09:51:48 +02:00
DXGI_FORMAT Format,
UINT SampleCount,
UINT* pNumQualityLevels) final;
2017-12-12 12:50:52 +01:00
void STDMETHODCALLTYPE CheckCounterInfo(
2017-10-11 09:51:48 +02:00
D3D11_COUNTER_INFO* pCounterInfo) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE 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) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE CheckFeatureSupport(
2017-10-11 09:51:48 +02:00
D3D11_FEATURE Feature,
void* pFeatureSupportData,
UINT FeatureSupportDataSize) final;
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE GetPrivateData(
REFGUID Name,
UINT *pDataSize,
void *pData) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE SetPrivateData(
REFGUID Name,
UINT DataSize,
const void *pData) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
REFGUID Name,
const IUnknown *pUnknown) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
D3D_FEATURE_LEVEL STDMETHODCALLTYPE GetFeatureLevel() final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
UINT STDMETHODCALLTYPE GetCreationFlags() final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason() final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
void STDMETHODCALLTYPE GetImmediateContext(
2017-10-11 09:51:48 +02:00
ID3D11DeviceContext** ppImmediateContext) final;
void STDMETHODCALLTYPE GetImmediateContext1(
ID3D11DeviceContext1** ppImmediateContext) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE SetExceptionMode(UINT RaiseFlags) final;
2017-10-11 09:51:48 +02:00
2017-12-12 12:50:52 +01:00
UINT STDMETHODCALLTYPE GetExceptionMode() final;
2017-10-11 09:51:48 +02:00
Rc<DxvkDevice> GetDXVKDevice() {
return m_dxvkDevice;
}
2017-10-15 21:38:09 +02:00
DxvkBufferSlice AllocateCounterSlice();
void FreeCounterSlice(const DxvkBufferSlice& Slice);
2018-01-13 05:00:27 +01:00
void FlushInitContext();
VkPipelineStageFlags GetEnabledShaderStages() const;
2017-12-20 14:54:24 +01:00
DxgiFormatInfo STDMETHODCALLTYPE LookupFormat(
2017-12-19 16:01:50 +01:00
DXGI_FORMAT format,
DxgiFormatMode mode) const;
static bool CheckFeatureLevelSupport(
const Rc<DxvkAdapter>& adapter,
D3D_FEATURE_LEVEL featureLevel);
static VkPhysicalDeviceFeatures GetDeviceFeatures(
const Rc<DxvkAdapter>& adapter,
D3D_FEATURE_LEVEL featureLevel);
2017-10-11 09:51:48 +02:00
private:
const Com<IDXGIDevicePrivate> m_dxgiDevice;
Com<IDXGIAdapterPrivate> m_dxgiAdapter;
const Com<D3D11PresentDevice> m_presentDevice;
const D3D_FEATURE_LEVEL m_featureLevel;
const UINT m_featureFlags;
const Rc<DxvkDevice> m_dxvkDevice;
const Rc<DxvkAdapter> m_dxvkAdapter;
2017-10-11 09:51:48 +02:00
const DxbcOptions m_dxbcOptions;
D3D11ImmediateContext* m_context = nullptr;
2017-10-11 09:51:48 +02:00
std::mutex m_counterMutex;
std::vector<uint32_t> m_counterSlices;
Rc<DxvkBuffer> m_counterBuffer;
std::mutex m_resourceInitMutex;
Rc<DxvkContext> m_resourceInitContext;
uint64_t m_resourceInitCommands = 0;
D3D11StateObjectSet<D3D11BlendState> m_bsStateObjects;
D3D11StateObjectSet<D3D11DepthStencilState> m_dsStateObjects;
D3D11StateObjectSet<D3D11RasterizerState> m_rsStateObjects;
D3D11StateObjectSet<D3D11SamplerState> m_samplerObjects;
HRESULT CreateShaderModule(
D3D11ShaderModule* pShaderModule,
const void* pShaderBytecode,
size_t BytecodeLength,
ID3D11ClassLinkage* pClassLinkage);
void InitBuffer(
D3D11Buffer* pBuffer,
const D3D11_SUBRESOURCE_DATA* pInitialData);
2017-12-08 23:13:15 +01:00
void InitTexture(
const Rc<DxvkImage>& image,
2017-12-08 23:13:15 +01:00
const D3D11_SUBRESOURCE_DATA* pInitialData);
HRESULT GetFormatSupportFlags(
DXGI_FORMAT Format,
UINT* pFlags1,
UINT* pFlags2) const;
void CreateCounterBuffer();
void LockResourceInitContext();
void UnlockResourceInitContext(uint64_t CommandCount);
void SubmitResourceInitCommands();
2018-01-13 05:00:27 +01:00
static D3D_FEATURE_LEVEL GetMaxFeatureLevel();
2017-10-11 09:51:48 +02:00
};
}