D3D11: Use D3DCommon where appropriate

This commit is contained in:
Stenzek
2019-03-29 19:52:38 +10:00
parent ea15080d8f
commit 3d8014beb5
19 changed files with 433 additions and 1055 deletions
@@ -6,6 +6,7 @@
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3DCommon/Common.h"
#include "VideoCommon/VideoConfig.h"
namespace DX11
@@ -35,7 +36,7 @@ void BBox::Init()
HRESULT hr;
hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer);
CHECK(SUCCEEDED(hr), "Create BoundingBox Buffer.");
D3D::SetDebugObjectName(s_bbox_buffer, "BoundingBox Buffer");
D3DCommon::SetDebugObjectName(s_bbox_buffer, "BoundingBox Buffer");
// Second to use as a staging buffer.
desc.Usage = D3D11_USAGE_STAGING;
@@ -43,7 +44,7 @@ void BBox::Init()
desc.BindFlags = 0;
hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_staging_buffer);
CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer.");
D3D::SetDebugObjectName(s_bbox_staging_buffer, "BoundingBox Staging Buffer");
D3DCommon::SetDebugObjectName(s_bbox_staging_buffer, "BoundingBox Staging Buffer");
// UAV is required to allow concurrent access.
D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc = {};
@@ -54,7 +55,7 @@ void BBox::Init()
UAVdesc.Buffer.NumElements = 4;
hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav);
CHECK(SUCCEEDED(hr), "Create BoundingBox UAV.");
D3D::SetDebugObjectName(s_bbox_uav, "BoundingBox UAV");
D3DCommon::SetDebugObjectName(s_bbox_uav, "BoundingBox UAV");
D3D::stateman->SetOMUAV(s_bbox_uav);
}
}
@@ -26,4 +26,5 @@ target_link_libraries(videod3d
PUBLIC
common
videocommon
videod3dcommon
)
@@ -46,6 +46,7 @@
<ClCompile Include="NativeVertexFormat.cpp" />
<ClCompile Include="PerfQuery.cpp" />
<ClCompile Include="Render.cpp" />
<ClCompile Include="SwapChain.cpp" />
<ClCompile Include="VertexManager.cpp" />
</ItemGroup>
<ItemGroup>
@@ -57,6 +58,7 @@
<ClInclude Include="DXTexture.h" />
<ClInclude Include="PerfQuery.h" />
<ClInclude Include="Render.h" />
<ClInclude Include="SwapChain.h" />
<ClInclude Include="VertexManager.h" />
<ClInclude Include="VideoBackend.h" />
</ItemGroup>
@@ -64,6 +66,9 @@
<ProjectReference Include="$(CoreDir)VideoCommon\VideoCommon.vcxproj">
<Project>{3de9ee35-3e91-4f27-a014-2866ad8c3fe3}</Project>
</ProjectReference>
<ProjectReference Include="..\D3DCommon\D3DCommon.vcxproj">
<Project>{dea96cf2-f237-4a1a-b32f-c916769efb50}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -40,6 +40,9 @@
<ClCompile Include="DXPipeline.cpp">
<Filter>Render</Filter>
</ClCompile>
<ClCompile Include="SwapChain.cpp">
<Filter>Render</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="D3DBase.h">
@@ -70,5 +73,8 @@
<ClInclude Include="DXPipeline.h">
<Filter>Render</Filter>
</ClInclude>
<ClInclude Include="SwapChain.h">
<Filter>Render</Filter>
</ClInclude>
</ItemGroup>
</Project>
File diff suppressed because it is too large Load Diff
+14 -51
View File
@@ -9,13 +9,12 @@
#include <d3dcompiler.h>
#include <dxgi1_5.h>
#include <vector>
#include <wrl/client.h>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
namespace DX11
{
#define SAFE_RELEASE(x) \
{ \
if (x) \
@@ -38,61 +37,25 @@ namespace DX11
PanicAlert("%s failed in %s at line %d: " Message, __func__, __FILE__, __LINE__, __VA_ARGS__); \
}
class DXTexture;
class DXFramebuffer;
namespace DX11
{
using Microsoft::WRL::ComPtr;
class SwapChain;
namespace D3D
{
HRESULT LoadDXGI();
HRESULT LoadD3D();
HRESULT LoadD3DCompiler();
void UnloadDXGI();
void UnloadD3D();
void UnloadD3DCompiler();
extern ComPtr<IDXGIFactory2> dxgi_factory;
extern ComPtr<ID3D11Device> device;
extern ComPtr<ID3D11Device1> device1;
extern ComPtr<ID3D11DeviceContext> context;
extern D3D_FEATURE_LEVEL feature_level;
D3D_FEATURE_LEVEL GetFeatureLevel(IDXGIAdapter* adapter);
std::vector<DXGI_SAMPLE_DESC> EnumAAModes(IDXGIAdapter* adapter);
bool Create(u32 adapter_index, bool enable_debug_layer);
void Destroy();
HRESULT Create(HWND wnd);
void Close();
extern ID3D11Device* device;
extern ID3D11Device1* device1;
extern ID3D11DeviceContext* context;
extern IDXGISwapChain1* swapchain;
void Reset(HWND new_wnd);
void ResizeSwapChain();
void Present();
DXTexture* GetSwapChainTexture();
DXFramebuffer* GetSwapChainFramebuffer();
const char* PixelShaderVersionString();
const char* GeometryShaderVersionString();
const char* VertexShaderVersionString();
const char* ComputeShaderVersionString();
bool BGRATexturesSupported();
bool AllowTearingSupported();
u32 GetMaxTextureSize(D3D_FEATURE_LEVEL feature_level);
HRESULT SetFullscreenState(bool enable_fullscreen);
bool GetFullscreenState();
// This function will assign a name to the given resource.
// The DirectX debug layer will make it easier to identify resources that way,
// e.g. when listing up all resources who have unreleased references.
void SetDebugObjectName(ID3D11DeviceChild* resource, const char* name);
std::string GetDebugObjectName(ID3D11DeviceChild* resource);
// Returns a list of supported AA modes for the current device.
std::vector<u32> GetAAModes(u32 adapter_index);
} // namespace D3D
typedef HRESULT(WINAPI* CREATEDXGIFACTORY)(REFIID, void**);
extern CREATEDXGIFACTORY PCreateDXGIFactory;
typedef HRESULT(WINAPI* D3D11CREATEDEVICE)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT,
CONST D3D_FEATURE_LEVEL*, UINT, UINT, ID3D11Device**,
D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
extern pD3DCompile PD3DCompile;
} // namespace DX11
+5 -19
View File
@@ -13,6 +13,7 @@
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3D/DXTexture.h"
#include "VideoBackends/D3DCommon/Common.h"
#include "VideoCommon/VideoConfig.h"
namespace DX11
@@ -360,10 +361,7 @@ ID3D11SamplerState* StateCache::Get(SamplerState state)
ID3D11SamplerState* res = nullptr;
HRESULT hr = D3D::device->CreateSamplerState(&sampdc, &res);
if (FAILED(hr))
PanicAlert("Fail %s %d\n", __FILE__, __LINE__);
D3D::SetDebugObjectName(res, "sampler state used to emulate the GX pipeline");
CHECK(SUCCEEDED(hr), "Creating D3D sampler state failed");
m_sampler.emplace(state.hex, res);
return res;
}
@@ -400,7 +398,6 @@ ID3D11BlendState* StateCache::Get(BlendingState state)
HRESULT hr = D3D::device1->CreateBlendState1(&desc, &res);
if (SUCCEEDED(hr))
{
D3D::SetDebugObjectName(res, "blend state used to emulate the GX pipeline");
m_blend.emplace(state.hex, res);
return res;
}
@@ -443,10 +440,7 @@ ID3D11BlendState* StateCache::Get(BlendingState state)
ID3D11BlendState* res = nullptr;
HRESULT hr = D3D::device->CreateBlendState(&desc, &res);
if (FAILED(hr))
PanicAlert("Failed to create blend state at %s %d\n", __FILE__, __LINE__);
D3D::SetDebugObjectName(res, "blend state used to emulate the GX pipeline");
CHECK(SUCCEEDED(hr), "Creating D3D blend state failed");
m_blend.emplace(state.hex, res);
return res;
}
@@ -468,10 +462,7 @@ ID3D11RasterizerState* StateCache::Get(RasterizationState state)
ID3D11RasterizerState* res = nullptr;
HRESULT hr = D3D::device->CreateRasterizerState(&desc, &res);
if (FAILED(hr))
PanicAlert("Failed to create rasterizer state at %s %d\n", __FILE__, __LINE__);
D3D::SetDebugObjectName(res, "rasterizer state used to emulate the GX pipeline");
CHECK(SUCCEEDED(hr), "Creating D3D rasterizer state failed");
m_raster.emplace(state.hex, res);
return res;
}
@@ -515,13 +506,8 @@ ID3D11DepthStencilState* StateCache::Get(DepthState state)
ID3D11DepthStencilState* res = nullptr;
HRESULT hr = D3D::device->CreateDepthStencilState(&depthdc, &res);
if (SUCCEEDED(hr))
D3D::SetDebugObjectName(res, "depth-stencil state used to emulate the GX pipeline");
else
PanicAlert("Failed to create depth state at %s %d\n", __FILE__, __LINE__);
CHECK(SUCCEEDED(hr), "Creating D3D depth stencil state failed");
m_depth.emplace(state.hex, res);
return res;
}
+3 -103
View File
@@ -2,22 +2,14 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <fstream>
#include "Common/Assert.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/DXShader.h"
#include "VideoCommon/VideoConfig.h"
#include "Common/Assert.h"
#include "VideoBackends/D3D/D3DBase.h"
namespace DX11
{
DXShader::DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader)
: AbstractShader(stage), m_bytecode(bytecode), m_shader(shader)
: D3DCommon::Shader(stage, std::move(bytecode)), m_shader(shader)
{
}
@@ -50,16 +42,6 @@ ID3D11ComputeShader* DXShader::GetD3DComputeShader() const
return static_cast<ID3D11ComputeShader*>(m_shader);
}
bool DXShader::HasBinary() const
{
return true;
}
AbstractShader::BinaryData DXShader::GetBinary() const
{
return m_bytecode;
}
std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, BinaryData bytecode)
{
switch (stage)
@@ -117,86 +99,4 @@ std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, Binary
return nullptr;
}
static const char* GetCompileTarget(ShaderStage stage)
{
switch (stage)
{
case ShaderStage::Vertex:
return D3D::VertexShaderVersionString();
case ShaderStage::Geometry:
return D3D::GeometryShaderVersionString();
case ShaderStage::Pixel:
return D3D::PixelShaderVersionString();
case ShaderStage::Compute:
return D3D::ComputeShaderVersionString();
default:
return "";
}
}
bool DXShader::CompileShader(BinaryData* out_bytecode, ShaderStage stage, const char* source,
size_t length)
{
static constexpr D3D_SHADER_MACRO macros[] = {{"API_D3D", "1"}, {nullptr, nullptr}};
const UINT flags = g_ActiveConfig.bEnableValidationLayer ?
(D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION) :
(D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE_SKIP_VALIDATION);
const char* target = GetCompileTarget(stage);
ID3DBlob* code = nullptr;
ID3DBlob* errors = nullptr;
HRESULT hr = PD3DCompile(source, length, nullptr, macros, nullptr, "main", target, flags, 0,
&code, &errors);
if (FAILED(hr))
{
static int num_failures = 0;
std::string filename = StringFromFormat(
"%sbad_%s_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), target, num_failures++);
std::ofstream file;
File::OpenFStream(file, filename, std::ios_base::out);
file.write(source, length);
file << "\n";
file.write(static_cast<const char*>(errors->GetBufferPointer()), errors->GetBufferSize());
file.close();
PanicAlert("Failed to compile %s:\nDebug info (%s):\n%s", filename.c_str(), target,
static_cast<const char*>(errors->GetBufferPointer()));
errors->Release();
return false;
}
if (errors && errors->GetBufferSize() > 0)
{
WARN_LOG(VIDEO, "%s compilation succeeded with warnings:\n%s", target,
static_cast<const char*>(errors->GetBufferPointer()));
}
SAFE_RELEASE(errors);
out_bytecode->resize(code->GetBufferSize());
std::memcpy(out_bytecode->data(), code->GetBufferPointer(), code->GetBufferSize());
code->Release();
return true;
}
std::unique_ptr<DXShader> DXShader::CreateFromSource(ShaderStage stage, const char* source,
size_t length)
{
BinaryData bytecode;
if (!CompileShader(&bytecode, stage, source, length))
return nullptr;
return CreateFromBytecode(stage, std::move(bytecode));
}
std::unique_ptr<DXShader> DXShader::CreateFromBinary(ShaderStage stage, const void* data,
size_t length)
{
if (length == 0)
return nullptr;
BinaryData bytecode(length);
std::memcpy(bytecode.data(), data, length);
return CreateFromBytecode(stage, std::move(bytecode));
}
} // namespace DX11
+2 -14
View File
@@ -6,11 +6,11 @@
#include <d3d11.h>
#include <memory>
#include "VideoCommon/AbstractShader.h"
#include "VideoBackends/D3DCommon/Shader.h"
namespace DX11
{
class DXShader final : public AbstractShader
class DXShader final : public D3DCommon::Shader
{
public:
DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader);
@@ -23,22 +23,10 @@ public:
ID3D11PixelShader* GetD3DPixelShader() const;
ID3D11ComputeShader* GetD3DComputeShader() const;
bool HasBinary() const override;
BinaryData GetBinary() const override;
// Creates a new shader object.
static std::unique_ptr<DXShader> CreateFromBytecode(ShaderStage stage, BinaryData bytecode);
static bool CompileShader(BinaryData* out_bytecode, ShaderStage stage, const char* source,
size_t length);
static std::unique_ptr<DXShader> CreateFromBinary(ShaderStage stage, const void* data,
size_t length);
static std::unique_ptr<DXShader> CreateFromSource(ShaderStage stage, const char* source,
size_t length);
private:
ID3D11DeviceChild* m_shader;
BinaryData m_bytecode;
};
} // namespace DX11
+76 -156
View File
@@ -11,141 +11,27 @@
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3D/DXTexture.h"
#include "VideoBackends/D3DCommon/Common.h"
namespace DX11
{
namespace
{
DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format, bool typeless)
{
switch (format)
{
case AbstractTextureFormat::DXT1:
return DXGI_FORMAT_BC1_UNORM;
case AbstractTextureFormat::DXT3:
return DXGI_FORMAT_BC2_UNORM;
case AbstractTextureFormat::DXT5:
return DXGI_FORMAT_BC3_UNORM;
case AbstractTextureFormat::BPTC:
return DXGI_FORMAT_BC7_UNORM;
case AbstractTextureFormat::RGBA8:
return typeless ? DXGI_FORMAT_R8G8B8A8_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
return typeless ? DXGI_FORMAT_B8G8R8A8_TYPELESS : DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::R16:
return typeless ? DXGI_FORMAT_R16_TYPELESS : DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F:
return typeless ? DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_R32_FLOAT;
case AbstractTextureFormat::D16:
return DXGI_FORMAT_R16_TYPELESS;
case AbstractTextureFormat::D24_S8:
return DXGI_FORMAT_R24G8_TYPELESS;
case AbstractTextureFormat::D32F:
return DXGI_FORMAT_R32_TYPELESS;
case AbstractTextureFormat::D32F_S8:
return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
default:
PanicAlert("Unhandled texture format.");
return DXGI_FORMAT_R8G8B8A8_UNORM;
}
}
DXGI_FORMAT GetSRVFormatForHostFormat(AbstractTextureFormat format)
{
switch (format)
{
case AbstractTextureFormat::DXT1:
return DXGI_FORMAT_BC1_UNORM;
case AbstractTextureFormat::DXT3:
return DXGI_FORMAT_BC2_UNORM;
case AbstractTextureFormat::DXT5:
return DXGI_FORMAT_BC3_UNORM;
case AbstractTextureFormat::BPTC:
return DXGI_FORMAT_BC7_UNORM;
case AbstractTextureFormat::RGBA8:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
return DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::R16:
return DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F:
return DXGI_FORMAT_R32_FLOAT;
case AbstractTextureFormat::D16:
return DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::D24_S8:
return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
case AbstractTextureFormat::D32F:
return DXGI_FORMAT_R32_FLOAT;
case AbstractTextureFormat::D32F_S8:
return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
default:
PanicAlert("Unhandled SRV format");
return DXGI_FORMAT_UNKNOWN;
}
}
DXGI_FORMAT GetRTVFormatForHostFormat(AbstractTextureFormat format, bool integer)
{
switch (format)
{
case AbstractTextureFormat::RGBA8:
return integer ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
return DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::R16:
return integer ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F:
return DXGI_FORMAT_R32_FLOAT;
default:
PanicAlert("Unhandled RTV format");
return DXGI_FORMAT_UNKNOWN;
}
}
DXGI_FORMAT GetDSVFormatForHostFormat(AbstractTextureFormat format)
{
switch (format)
{
case AbstractTextureFormat::D16:
return DXGI_FORMAT_D16_UNORM;
case AbstractTextureFormat::D24_S8:
return DXGI_FORMAT_D24_UNORM_S8_UINT;
case AbstractTextureFormat::D32F:
return DXGI_FORMAT_D32_FLOAT;
case AbstractTextureFormat::D32F_S8:
return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
default:
PanicAlert("Unhandled DSV format");
return DXGI_FORMAT_UNKNOWN;
}
}
} // Anonymous namespace
DXTexture::DXTexture(const TextureConfig& tex_config, ID3D11Texture2D* d3d_texture,
ID3D11ShaderResourceView* d3d_srv, ID3D11UnorderedAccessView* d3d_uav)
: AbstractTexture(tex_config), m_d3d_texture(d3d_texture), m_d3d_srv(d3d_srv),
m_d3d_uav(d3d_uav)
DXTexture::DXTexture(const TextureConfig& config, ID3D11Texture2D* texture)
: AbstractTexture(config), m_texture(texture)
{
}
DXTexture::~DXTexture()
{
if (m_d3d_uav)
m_d3d_uav->Release();
if (m_d3d_srv)
{
if (D3D::stateman->UnsetTexture(m_d3d_srv) != 0)
D3D::stateman->ApplyTextures();
m_d3d_srv->Release();
}
m_d3d_texture->Release();
if (m_srv && D3D::stateman->UnsetTexture(m_srv.Get()) != 0)
D3D::stateman->ApplyTextures();
}
std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
{
// Use typeless to create the texture when it's a render target, so we can alias it with an
// integer format (for EFB).
const DXGI_FORMAT tex_format = GetDXGIFormatForHostFormat(config.format, config.IsRenderTarget());
const DXGI_FORMAT srv_format = GetSRVFormatForHostFormat(config.format);
const DXGI_FORMAT tex_format =
D3DCommon::GetDXGIFormatForAbstractFormat(config.format, config.IsRenderTarget());
UINT bindflags = D3D11_BIND_SHADER_RESOURCE;
if (config.IsRenderTarget())
bindflags |= IsDepthFormat(config.format) ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_RENDER_TARGET;
@@ -154,7 +40,7 @@ std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
CD3D11_TEXTURE2D_DESC desc(tex_format, config.width, config.height, config.layers, config.levels,
bindflags, D3D11_USAGE_DEFAULT, 0, config.samples, 0, 0);
ID3D11Texture2D* d3d_texture;
ComPtr<ID3D11Texture2D> d3d_texture;
HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &d3d_texture);
if (FAILED(hr))
{
@@ -163,36 +49,69 @@ std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
return nullptr;
}
ID3D11ShaderResourceView* d3d_srv;
const CD3D11_SHADER_RESOURCE_VIEW_DESC srv_desc(d3d_texture,
config.IsMultisampled() ?
D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_SRV_DIMENSION_TEXTURE2DARRAY,
srv_format, 0, config.levels, 0, config.layers);
hr = D3D::device->CreateShaderResourceView(d3d_texture, &srv_desc, &d3d_srv);
std::unique_ptr<DXTexture> tex(new DXTexture(config, d3d_texture.Get()));
if (!tex->CreateSRV() || (config.IsComputeImage() && !tex->CreateUAV()))
return nullptr;
return tex;
}
std::unique_ptr<DXTexture> DXTexture::CreateAdopted(ID3D11Texture2D* texture)
{
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
// Convert to our texture config format.
TextureConfig config(desc.Width, desc.Height, desc.MipLevels, desc.ArraySize,
desc.SampleDesc.Count,
D3DCommon::GetAbstractFormatForDXGIFormat(desc.Format), 0);
if (desc.BindFlags & D3D11_BIND_RENDER_TARGET)
config.flags |= AbstractTextureFlag_RenderTarget;
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)
config.flags |= AbstractTextureFlag_ComputeImage;
std::unique_ptr<DXTexture> tex(new DXTexture(config, texture));
if (desc.BindFlags & D3D11_BIND_SHADER_RESOURCE && !tex->CreateSRV())
return nullptr;
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS && !tex->CreateUAV())
return nullptr;
return tex;
}
bool DXTexture::CreateSRV()
{
const CD3D11_SHADER_RESOURCE_VIEW_DESC desc(
m_texture.Get(),
m_config.IsMultisampled() ? D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_SRV_DIMENSION_TEXTURE2DARRAY,
D3DCommon::GetSRVFormatForAbstractFormat(m_config.format), 0, m_config.levels, 0,
m_config.layers);
HRESULT hr = D3D::device->CreateShaderResourceView(m_texture.Get(), &desc, &m_srv);
if (FAILED(hr))
{
PanicAlert("Failed to create %ux%ux%u D3D SRV", config.width, config.height, config.layers);
d3d_texture->Release();
return nullptr;
PanicAlert("Failed to create %ux%ux%u D3D SRV", m_config.width, m_config.height,
m_config.layers);
return false;
}
ID3D11UnorderedAccessView* d3d_uav = nullptr;
if (config.IsComputeImage())
return true;
}
bool DXTexture::CreateUAV()
{
const CD3D11_UNORDERED_ACCESS_VIEW_DESC desc(
m_texture.Get(), D3D11_UAV_DIMENSION_TEXTURE2DARRAY,
D3DCommon::GetSRVFormatForAbstractFormat(m_config.format), 0, 0, m_config.layers);
HRESULT hr = D3D::device->CreateUnorderedAccessView(m_texture.Get(), &desc, &m_uav);
if (FAILED(hr))
{
const CD3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc(
d3d_texture, D3D11_UAV_DIMENSION_TEXTURE2DARRAY, srv_format, 0, 0, config.layers);
hr = D3D::device->CreateUnorderedAccessView(d3d_texture, &uav_desc, &d3d_uav);
if (FAILED(hr))
{
PanicAlert("Failed to create %ux%ux%u D3D UAV", config.width, config.height, config.layers);
d3d_uav->Release();
d3d_texture->Release();
return nullptr;
}
PanicAlert("Failed to create %ux%ux%u D3D UAV", m_config.width, m_config.height,
m_config.layers);
return false;
}
return std::make_unique<DXTexture>(config, d3d_texture, d3d_srv, d3d_uav);
return true;
}
void DXTexture::CopyRectangleFromTexture(const AbstractTexture* src,
@@ -213,8 +132,8 @@ void DXTexture::CopyRectangleFromTexture(const AbstractTexture* src,
src_box.back = 1;
D3D::context->CopySubresourceRegion(
m_d3d_texture, D3D11CalcSubresource(dst_level, dst_layer, m_config.levels), dst_rect.left,
dst_rect.top, 0, srcentry->m_d3d_texture,
m_texture.Get(), D3D11CalcSubresource(dst_level, dst_layer, m_config.levels), dst_rect.left,
dst_rect.top, 0, srcentry->m_texture.Get(),
D3D11CalcSubresource(src_level, src_layer, srcentry->m_config.levels), &src_box);
}
@@ -228,16 +147,16 @@ void DXTexture::ResolveFromTexture(const AbstractTexture* src, const MathUtil::R
rect.top + rect.GetHeight() <= static_cast<int>(srcentry->m_config.height));
D3D::context->ResolveSubresource(
m_d3d_texture, D3D11CalcSubresource(level, layer, m_config.levels), srcentry->m_d3d_texture,
D3D11CalcSubresource(level, layer, srcentry->m_config.levels),
GetDXGIFormatForHostFormat(m_config.format, false));
m_texture.Get(), D3D11CalcSubresource(level, layer, m_config.levels),
srcentry->m_texture.Get(), D3D11CalcSubresource(level, layer, srcentry->m_config.levels),
D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false));
}
void DXTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
size_t buffer_size)
{
size_t src_pitch = CalculateStrideForFormat(m_config.format, row_length);
D3D::context->UpdateSubresource(m_d3d_texture, level, nullptr, buffer,
D3D::context->UpdateSubresource(m_texture.Get(), level, nullptr, buffer,
static_cast<UINT>(src_pitch), 0);
}
@@ -275,8 +194,8 @@ std::unique_ptr<DXStagingTexture> DXStagingTexture::Create(StagingTextureType ty
cpu_flags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
}
CD3D11_TEXTURE2D_DESC desc(GetDXGIFormatForHostFormat(config.format, false), config.width,
config.height, 1, 1, 0, usage, cpu_flags);
CD3D11_TEXTURE2D_DESC desc(D3DCommon::GetDXGIFormatForAbstractFormat(config.format, false),
config.width, config.height, 1, 1, 0, usage, cpu_flags);
ID3D11Texture2D* texture;
HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &texture);
@@ -437,14 +356,15 @@ std::unique_ptr<DXFramebuffer> DXFramebuffer::Create(DXTexture* color_attachment
CD3D11_RENDER_TARGET_VIEW_DESC desc(
color_attachment->IsMultisampled() ? D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_RTV_DIMENSION_TEXTURE2DARRAY,
GetRTVFormatForHostFormat(color_attachment->GetFormat(), false), 0, 0,
D3DCommon::GetRTVFormatForAbstractFormat(color_attachment->GetFormat(), false), 0, 0,
color_attachment->GetLayers());
HRESULT hr =
D3D::device->CreateRenderTargetView(color_attachment->GetD3DTexture(), &desc, &rtv);
CHECK(SUCCEEDED(hr), "Create render target view for framebuffer");
// Only create the integer RTV on Win8+.
DXGI_FORMAT integer_format = GetRTVFormatForHostFormat(color_attachment->GetFormat(), true);
DXGI_FORMAT integer_format =
D3DCommon::GetRTVFormatForAbstractFormat(color_attachment->GetFormat(), true);
if (D3D::device1 && integer_format != desc.Format)
{
desc.Format = integer_format;
@@ -460,7 +380,7 @@ std::unique_ptr<DXFramebuffer> DXFramebuffer::Create(DXTexture* color_attachment
const CD3D11_DEPTH_STENCIL_VIEW_DESC desc(
depth_attachment->GetConfig().IsMultisampled() ? D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_DSV_DIMENSION_TEXTURE2DARRAY,
GetDSVFormatForHostFormat(depth_attachment->GetFormat()), 0, 0,
D3DCommon::GetDSVFormatForAbstractFormat(depth_attachment->GetFormat()), 0, 0,
depth_attachment->GetLayers(), 0);
HRESULT hr =
D3D::device->CreateDepthStencilView(depth_attachment->GetD3DTexture(), &desc, &dsv);
+12 -8
View File
@@ -17,11 +17,10 @@ namespace DX11
class DXTexture final : public AbstractTexture
{
public:
explicit DXTexture(const TextureConfig& tex_config, ID3D11Texture2D* d3d_texture,
ID3D11ShaderResourceView* d3d_srv, ID3D11UnorderedAccessView* d3d_uav);
~DXTexture();
static std::unique_ptr<DXTexture> Create(const TextureConfig& config);
static std::unique_ptr<DXTexture> CreateAdopted(ID3D11Texture2D* texture);
void CopyRectangleFromTexture(const AbstractTexture* src,
const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
@@ -32,14 +31,19 @@ public:
void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
size_t buffer_size) override;
ID3D11Texture2D* GetD3DTexture() const { return m_d3d_texture; }
ID3D11ShaderResourceView* GetD3DSRV() const { return m_d3d_srv; }
ID3D11UnorderedAccessView* GetD3DUAV() const { return m_d3d_uav; }
ID3D11Texture2D* GetD3DTexture() const { return m_texture.Get(); }
ID3D11ShaderResourceView* GetD3DSRV() const { return m_srv.Get(); }
ID3D11UnorderedAccessView* GetD3DUAV() const { return m_uav.Get(); }
private:
ID3D11Texture2D* m_d3d_texture;
ID3D11ShaderResourceView* m_d3d_srv;
ID3D11UnorderedAccessView* m_d3d_uav;
DXTexture(const TextureConfig& config, ID3D11Texture2D* texture);
bool CreateSRV();
bool CreateUAV();
ComPtr<ID3D11Texture2D> m_texture;
ComPtr<ID3D11ShaderResourceView> m_srv;
ComPtr<ID3D11UnorderedAccessView> m_uav;
};
class DXStagingTexture final : public AbstractStagingTexture
@@ -160,9 +160,7 @@ ID3D11InputLayout* D3DVertexFormat::GetInputLayout(const void* vs_bytecode, size
HRESULT hr = D3D::device->CreateInputLayout(m_elems.data(), m_num_elems, vs_bytecode,
vs_bytecode_size, &layout);
if (FAILED(hr))
PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);
DX11::D3D::SetDebugObjectName(m_layout, "input layout used to emulate the GX pipeline");
CHECK(SUCCEEDED(hr), "Failed to create input layout");
// This method can be called from multiple threads, so ensure that only one thread sets the
// cached input layout pointer. If another thread beats this thread, use the existing layout.
+41 -58
View File
@@ -26,6 +26,7 @@
#include "VideoBackends/D3D/DXPipeline.h"
#include "VideoBackends/D3D/DXShader.h"
#include "VideoBackends/D3D/DXTexture.h"
#include "VideoBackends/D3D/SwapChain.h"
#include "VideoCommon/BPFunctions.h"
#include "VideoCommon/FramebufferManager.h"
@@ -48,11 +49,12 @@ typedef struct _Nv_Stereo_Image_Header
#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e
Renderer::Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale)
: ::Renderer(backbuffer_width, backbuffer_height, backbuffer_scale,
AbstractTextureFormat::RGBA8)
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale)
: ::Renderer(swap_chain ? swap_chain->GetWidth() : 0, swap_chain ? swap_chain->GetHeight() : 0,
backbuffer_scale,
swap_chain ? swap_chain->GetFormat() : AbstractTextureFormat::Undefined),
m_swap_chain(std::move(swap_chain))
{
m_last_fullscreen_state = D3D::GetFullscreenState();
}
Renderer::~Renderer() = default;
@@ -82,17 +84,13 @@ void Renderer::Create3DVisionTexture(int width, int height)
ID3D11Texture2D* texture;
HRESULT hr = D3D::device->CreateTexture2D(&texture_desc, &sys_data, &texture);
CHECK(SUCCEEDED(hr), "Create 3D Vision Texture");
m_3d_vision_texture = std::make_unique<DXTexture>(TextureConfig(width * 2, height + 1, 1, 1, 1,
AbstractTextureFormat::RGBA8,
AbstractTextureFlag_RenderTarget),
texture, nullptr, nullptr);
m_3d_vision_framebuffer =
DXFramebuffer::Create(static_cast<DXTexture*>(m_3d_vision_texture.get()), nullptr);
m_3d_vision_texture = DXTexture::CreateAdopted(texture);
m_3d_vision_framebuffer = DXFramebuffer::Create(m_3d_vision_texture.get(), nullptr);
}
bool Renderer::IsHeadless() const
{
return D3D::swapchain == nullptr;
return !m_swap_chain;
}
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
@@ -116,13 +114,17 @@ std::unique_ptr<AbstractFramebuffer> Renderer::CreateFramebuffer(AbstractTexture
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
const char* source, size_t length)
{
return DXShader::CreateFromSource(stage, source, length);
DXShader::BinaryData bytecode;
if (!DXShader::CompileShader(D3D::feature_level, &bytecode, stage, source, length))
return nullptr;
return DXShader::CreateFromBytecode(stage, std::move(bytecode));
}
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length)
{
return DXShader::CreateFromBinary(stage, data, length);
return DXShader::CreateFromBytecode(stage, DXShader::CreateByteCode(data, length));
}
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
@@ -196,64 +198,44 @@ void Renderer::DispatchComputeShader(const AbstractShader* shader, u32 groups_x,
void Renderer::BindBackbuffer(const ClearColor& clear_color)
{
CheckForSurfaceChange();
CheckForSurfaceResize();
SetAndClearFramebuffer(D3D::GetSwapChainFramebuffer(), clear_color);
CheckForSwapChainChanges();
SetAndClearFramebuffer(m_swap_chain->GetFramebuffer(), clear_color);
}
void Renderer::PresentBackbuffer()
{
D3D::Present();
m_swap_chain->Present();
}
void Renderer::OnConfigChanged(u32 bits)
{
// Quad-buffer changes require swap chain recreation.
if (bits & CONFIG_CHANGE_BIT_STEREO_MODE && m_swap_chain)
m_swap_chain->SetStereo(SwapChain::WantsStereo());
}
void Renderer::CheckForSurfaceChange()
void Renderer::CheckForSwapChainChanges()
{
if (!m_surface_changed.TestAndClear())
const bool surface_changed = m_surface_changed.TestAndClear();
const bool surface_resized =
m_surface_resized.TestAndClear() || m_swap_chain->CheckForFullscreenChange();
if (!surface_changed && !surface_resized)
return;
m_3d_vision_framebuffer.reset();
m_3d_vision_texture.reset();
D3D::Reset(reinterpret_cast<HWND>(m_new_surface_handle));
m_new_surface_handle = nullptr;
UpdateBackbufferSize();
}
void Renderer::CheckForSurfaceResize()
{
const bool fullscreen_state = D3D::GetFullscreenState();
const bool exclusive_fullscreen_changed = fullscreen_state != m_last_fullscreen_state;
if (!m_surface_resized.TestAndClear() && !exclusive_fullscreen_changed)
return;
m_3d_vision_framebuffer.reset();
m_3d_vision_texture.reset();
m_last_fullscreen_state = fullscreen_state;
if (D3D::swapchain)
D3D::ResizeSwapChain();
UpdateBackbufferSize();
}
void Renderer::UpdateBackbufferSize()
{
if (D3D::swapchain)
if (surface_changed)
{
DXGI_SWAP_CHAIN_DESC1 desc = {};
D3D::swapchain->GetDesc1(&desc);
m_backbuffer_width = std::max(desc.Width, 1u);
m_backbuffer_height = std::max(desc.Height, 1u);
m_swap_chain->ChangeSurface(m_new_surface_handle);
m_new_surface_handle = nullptr;
}
else
{
m_backbuffer_width = 1;
m_backbuffer_height = 1;
m_swap_chain->ResizeSwapChain();
}
m_backbuffer_width = m_swap_chain->GetWidth();
m_backbuffer_height = m_swap_chain->GetHeight();
m_3d_vision_framebuffer.reset();
m_3d_vision_texture.reset();
}
void Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)
@@ -392,22 +374,23 @@ void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const EFBRectan
// Copy the left eye to the backbuffer, if Nvidia 3D Vision is enabled it should
// recognize the signature and automatically include the right eye frame.
const CD3D11_BOX box(0, 0, 0, m_backbuffer_width, m_backbuffer_height, 1);
D3D::context->CopySubresourceRegion(D3D::GetSwapChainTexture()->GetD3DTexture(), 0, 0, 0, 0,
const CD3D11_BOX box(0, 0, 0, m_swap_chain->GetWidth(), m_swap_chain->GetHeight(), 1);
D3D::context->CopySubresourceRegion(m_swap_chain->GetTexture()->GetD3DTexture(), 0, 0, 0, 0,
m_3d_vision_texture->GetD3DTexture(), 0, &box);
// Restore render target to backbuffer
SetFramebuffer(D3D::GetSwapChainFramebuffer());
SetFramebuffer(m_swap_chain->GetFramebuffer());
}
void Renderer::SetFullscreen(bool enable_fullscreen)
{
D3D::SetFullscreenState(enable_fullscreen);
if (m_swap_chain)
m_swap_chain->SetFullscreen(enable_fullscreen);
}
bool Renderer::IsFullscreen() const
{
return D3D::GetFullscreenState();
return m_swap_chain && m_swap_chain->GetFullscreen();
}
} // namespace DX11
+4 -6
View File
@@ -11,13 +11,14 @@
namespace DX11
{
class SwapChain;
class DXTexture;
class DXFramebuffer;
class Renderer : public ::Renderer
{
public:
Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale);
Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Renderer() override;
StateCache& GetStateCache() { return m_state_cache; }
@@ -69,15 +70,12 @@ public:
private:
void Create3DVisionTexture(int width, int height);
void CheckForSurfaceChange();
void CheckForSurfaceResize();
void UpdateBackbufferSize();
void CheckForSwapChainChanges();
StateCache m_state_cache;
std::unique_ptr<SwapChain> m_swap_chain;
std::unique_ptr<DXTexture> m_3d_vision_texture;
std::unique_ptr<DXFramebuffer> m_3d_vision_framebuffer;
bool m_last_fullscreen_state = false;
};
} // namespace DX11
@@ -0,0 +1,52 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "VideoBackends/D3D/SwapChain.h"
#include "VideoBackends/D3D/DXTexture.h"
namespace DX11
{
SwapChain::SwapChain(const WindowSystemInfo& wsi, IDXGIFactory2* dxgi_factory,
ID3D11Device* d3d_device)
: D3DCommon::SwapChain(wsi, dxgi_factory, d3d_device)
{
}
SwapChain::~SwapChain() = default;
std::unique_ptr<SwapChain> SwapChain::Create(const WindowSystemInfo& wsi)
{
std::unique_ptr<SwapChain> swap_chain =
std::make_unique<SwapChain>(wsi, D3D::dxgi_factory.Get(), D3D::device.Get());
if (!swap_chain->CreateSwapChain(WantsStereo()))
return nullptr;
return swap_chain;
}
bool SwapChain::CreateSwapChainBuffers()
{
ComPtr<ID3D11Texture2D> texture;
HRESULT hr = m_swap_chain->GetBuffer(0, IID_PPV_ARGS(&texture));
CHECK(SUCCEEDED(hr), "Get swap chain buffer");
if (FAILED(hr))
return false;
m_texture = DXTexture::CreateAdopted(texture.Get());
if (!m_texture)
return false;
m_framebuffer = DXFramebuffer::Create(m_texture.get(), nullptr);
if (!m_framebuffer)
return false;
return true;
}
void SwapChain::DestroySwapChainBuffers()
{
m_framebuffer.reset();
m_texture.reset();
}
} // namespace DX11
+44
View File
@@ -0,0 +1,44 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <d3d11.h>
#include <dxgi.h>
#include <memory>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/WindowSystemInfo.h"
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3DCommon/SwapChain.h"
#include "VideoCommon/TextureConfig.h"
namespace DX11
{
class DXTexture;
class DXFramebuffer;
class SwapChain : public D3DCommon::SwapChain
{
public:
SwapChain(const WindowSystemInfo& wsi, IDXGIFactory2* dxgi_factory, ID3D11Device* d3d_device);
~SwapChain();
static std::unique_ptr<SwapChain> Create(const WindowSystemInfo& wsi);
DXTexture* GetTexture() const { return m_texture.get(); }
DXFramebuffer* GetFramebuffer() const { return m_framebuffer.get(); }
protected:
bool CreateSwapChainBuffers() override;
void DestroySwapChainBuffers() override;
private:
// The runtime takes care of renaming the buffers.
std::unique_ptr<DXTexture> m_texture;
std::unique_ptr<DXFramebuffer> m_framebuffer;
};
} // namespace DX11
@@ -14,6 +14,7 @@
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3D/Render.h"
#include "VideoBackends/D3DCommon/Common.h"
#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/GeometryShaderManager.h"
@@ -34,8 +35,11 @@ static ID3D11Buffer* AllocateConstantBuffer(u32 size)
D3D11_CPU_ACCESS_WRITE);
ID3D11Buffer* cbuf;
const HRESULT hr = D3D::device->CreateBuffer(&cbdesc, nullptr, &cbuf);
CHECK(hr == S_OK, "shader constant buffer (size=%u)", cbsize);
D3D::SetDebugObjectName(cbuf, "constant buffer used to emulate the GX pipeline");
CHECK(SUCCEEDED(hr), "shader constant buffer (size=%u)", cbsize);
if (FAILED(hr))
return nullptr;
D3DCommon::SetDebugObjectName(cbuf, "constant buffer");
return cbuf;
}
@@ -88,7 +92,8 @@ bool VertexManager::Initialize()
{
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, nullptr, &m_buffers[i])),
"Failed to create buffer.");
D3D::SetDebugObjectName(m_buffers[i], "Buffer of VertexManager");
if (m_buffers[i])
D3DCommon::SetDebugObjectName(m_buffers[i], "Buffer of VertexManager");
}
m_vertex_constant_buffer = AllocateConstantBuffer(sizeof(VertexShaderConstants));
@@ -11,6 +11,7 @@ namespace DX11
{
class VideoBackend : public VideoBackendBase
{
public:
bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
@@ -18,5 +19,8 @@ class VideoBackend : public VideoBackendBase
std::string GetDisplayName() const override;
void InitBackendInfo() override;
private:
void FillBackendInfo();
};
} // namespace DX11
+30 -74
View File
@@ -14,8 +14,10 @@
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/PerfQuery.h"
#include "VideoBackends/D3D/Render.h"
#include "VideoBackends/D3D/SwapChain.h"
#include "VideoBackends/D3D/VertexManager.h"
#include "VideoBackends/D3D/VideoBackend.h"
#include "VideoBackends/D3DCommon/Common.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/ShaderCache.h"
@@ -37,15 +39,15 @@ std::string VideoBackend::GetDisplayName() const
void VideoBackend::InitBackendInfo()
{
HRESULT hr = DX11::D3D::LoadDXGI();
if (SUCCEEDED(hr))
hr = DX11::D3D::LoadD3D();
if (FAILED(hr))
{
DX11::D3D::UnloadDXGI();
if (!D3DCommon::LoadLibraries())
return;
}
FillBackendInfo();
D3DCommon::UnloadLibraries();
}
void VideoBackend::FillBackendInfo()
{
g_Config.backend_info.api_type = APIType::D3D;
g_Config.backend_info.MaxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
g_Config.backend_info.bUsesLowerLeftOrigin = false;
@@ -73,82 +75,36 @@ void VideoBackend::InitBackendInfo()
g_Config.backend_info.bSupportsBPTCTextures = false;
g_Config.backend_info.bSupportsFramebufferFetch = false;
g_Config.backend_info.bSupportsBackgroundCompiling = true;
g_Config.backend_info.bSupportsST3CTextures = true;
g_Config.backend_info.bSupportsBPTCTextures = true;
g_Config.backend_info.bSupportsEarlyZ = true;
g_Config.backend_info.bSupportsBBox = true;
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = true;
g_Config.backend_info.bSupportsGSInstancing = true;
g_Config.backend_info.bSupportsSSAA = true;
IDXGIFactory2* factory;
IDXGIAdapter* ad;
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)&factory);
if (FAILED(hr))
PanicAlert("Failed to create IDXGIFactory object");
// adapters
g_Config.backend_info.Adapters.clear();
g_Config.backend_info.AAModes.clear();
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) !=
DXGI_ERROR_NOT_FOUND)
{
const size_t adapter_index = g_Config.backend_info.Adapters.size();
DXGI_ADAPTER_DESC desc;
ad->GetDesc(&desc);
// TODO: These don't get updated on adapter change, yet
if (adapter_index == g_Config.iAdapter)
{
std::vector<DXGI_SAMPLE_DESC> modes = DX11::D3D::EnumAAModes(ad);
// First iteration will be 1. This equals no AA.
for (unsigned int i = 0; i < modes.size(); ++i)
{
g_Config.backend_info.AAModes.push_back(modes[i].Count);
}
D3D_FEATURE_LEVEL feature_level = D3D::GetFeatureLevel(ad);
bool shader_model_5_supported = feature_level >= D3D_FEATURE_LEVEL_11_0;
g_Config.backend_info.MaxTextureSize = D3D::GetMaxTextureSize(feature_level);
// Requires the earlydepthstencil attribute (only available in shader model 5)
g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
// Requires full UAV functionality (only available in shader model 5)
g_Config.backend_info.bSupportsBBox =
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported;
// Requires the instance attribute (only available in shader model 5)
g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
// Sample shading requires shader model 5
g_Config.backend_info.bSupportsSSAA = shader_model_5_supported;
}
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
ad->Release();
}
factory->Release();
DX11::D3D::UnloadDXGI();
DX11::D3D::UnloadD3D();
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
}
bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
if (!D3D::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
return false;
FillBackendInfo();
InitializeShared();
if (FAILED(D3D::Create(reinterpret_cast<HWND>(wsi.render_surface))))
std::unique_ptr<SwapChain> swap_chain;
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
{
PanicAlert("Failed to create D3D device.");
PanicAlertT("Failed to create D3D swap chain");
ShutdownShared();
D3D::Destroy();
return false;
}
int backbuffer_width = 1, backbuffer_height = 1;
if (D3D::swapchain)
{
DXGI_SWAP_CHAIN_DESC1 desc = {};
D3D::swapchain->GetDesc1(&desc);
backbuffer_width = std::max(desc.Width, 1u);
backbuffer_height = std::max(desc.Height, 1u);
}
// internal interfaces
g_renderer =
std::make_unique<Renderer>(backbuffer_width, backbuffer_height, wsi.render_surface_scale);
g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
@@ -158,6 +114,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
!g_shader_cache->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize())
{
Shutdown();
return false;
}
@@ -181,7 +138,6 @@ void VideoBackend::Shutdown()
g_renderer.reset();
ShutdownShared();
D3D::Close();
D3D::Destroy();
}
} // namespace DX11