mirror of
https://github.com/stenzek/duckstation.git
synced 2026-11-17 19:44:24 +01:00
D3D11Device: Fix input layout cache keys and feature level 10 limits
This commit is contained in:
5 files changed
+25
-10
No files matched your search
@@ -161,9 +161,10 @@ void D3D11Device::SetFeatures(CreateFlags create_flags)
|
||||
const D3D_FEATURE_LEVEL feature_level = m_device->GetFeatureLevel();
|
||||
|
||||
m_render_api_version = D3DCommon::GetRenderAPIVersionForFeatureLevel(feature_level);
|
||||
m_max_texture_size = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
||||
m_max_texture_size =
|
||||
(feature_level >= D3D_FEATURE_LEVEL_11_0) ? D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION : 8192; // D3D10_REQ_*
|
||||
m_max_multisamples = 1;
|
||||
for (u32 multisamples = 2; multisamples < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; multisamples++)
|
||||
for (u32 multisamples = 2; multisamples <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; multisamples *= 2)
|
||||
{
|
||||
UINT num_quality_levels;
|
||||
if (SUCCEEDED(
|
||||
@@ -1286,9 +1287,8 @@ void D3D11Device::Dispatch(u32 threads_x, u32 threads_y, u32 threads_z, u32 grou
|
||||
DebugAssert(m_current_compute_shader);
|
||||
s_stats.num_draws++;
|
||||
|
||||
const u32 groups_x = threads_x / group_size_x;
|
||||
const u32 groups_y = threads_y / group_size_y;
|
||||
const u32 groups_z = threads_z / group_size_z;
|
||||
const auto [groups_x, groups_y, groups_z] =
|
||||
GetDispatchCount(threads_x, threads_y, threads_z, group_size_x, group_size_y, group_size_z);
|
||||
m_context->Dispatch(groups_x, groups_y, groups_z);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,8 +139,13 @@ private:
|
||||
using RasterizationStateMap = std::unordered_map<u16, ComPtr<ID3D11RasterizerState>>;
|
||||
using DepthStateMap = std::unordered_map<u8, ComPtr<ID3D11DepthStencilState>>;
|
||||
using BlendStateMap = std::unordered_map<BlendStateMapKey, ComPtr<ID3D11BlendState>, BlendStateMapHash>;
|
||||
struct InputLayoutEntry
|
||||
{
|
||||
std::vector<GPUPipeline::VertexAttribute> attributes; // referenced by the map key
|
||||
ComPtr<ID3D11InputLayout> layout;
|
||||
};
|
||||
using InputLayoutMap =
|
||||
std::unordered_map<GPUPipeline::InputLayout, ComPtr<ID3D11InputLayout>, GPUPipeline::InputLayoutHash>;
|
||||
std::unordered_map<GPUPipeline::InputLayout, InputLayoutEntry, GPUPipeline::InputLayoutHash>;
|
||||
|
||||
static constexpr u32 MIN_UNIFORM_BUFFER_SIZE = 16;
|
||||
static constexpr u32 UNIFORM_BUFFER_ALIGNMENT = 256;
|
||||
|
||||
@@ -176,7 +176,7 @@ D3D11Device::ComPtr<ID3D11RasterizerState> D3D11Device::GetRasterizationState(co
|
||||
desc.FillMode = D3D11_FILL_SOLID;
|
||||
desc.CullMode = cull_mapping[static_cast<u8>(rs.cull_mode.GetValue())];
|
||||
desc.ScissorEnable = TRUE;
|
||||
// desc.MultisampleEnable ???
|
||||
desc.MultisampleEnable = (rs.multisamples > 1); // needed for MSAA at feature level 10.0
|
||||
|
||||
HRESULT hr = m_device->CreateRasterizerState(&desc, drs.GetAddressOf());
|
||||
if (FAILED(hr)) [[unlikely]]
|
||||
@@ -247,7 +247,8 @@ D3D11Device::ComPtr<ID3D11BlendState> D3D11Device::GetBlendState(const GPUPipeli
|
||||
{
|
||||
ComPtr<ID3D11BlendState> dbs;
|
||||
|
||||
const std::pair<u64, u32> key(bs.key, num_rts);
|
||||
// The blend constant is set separately, so keep it out of the key.
|
||||
const std::pair<u64, u32> key(bs.key & 0xFFFFFFFFu, num_rts);
|
||||
{
|
||||
const Threading::SharedLockGuard lock(m_state_map_mutex);
|
||||
const auto it = m_blend_states.find(key);
|
||||
@@ -362,11 +363,16 @@ D3D11Device::ComPtr<ID3D11InputLayout> D3D11Device::GetInputLayout(const GPUPipe
|
||||
HRESULT hr = m_device->CreateInputLayout(elems, static_cast<UINT>(il.vertex_attributes.size()),
|
||||
vs->GetBytecode().data(), vs->GetBytecode().size(), dil.GetAddressOf());
|
||||
if (FAILED(hr)) [[unlikely]]
|
||||
{
|
||||
Error::SetHResult(error, "CreateInputLayout() failed: ", hr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The key has to reference our own copy of the attributes, the caller's may not outlive the cache.
|
||||
InputLayoutEntry entry = {{il.vertex_attributes.begin(), il.vertex_attributes.end()}, dil};
|
||||
const GPUPipeline::InputLayout key = {entry.attributes, il.vertex_stride};
|
||||
const std::lock_guard lock(m_state_map_mutex);
|
||||
m_input_layouts.emplace(il, dil);
|
||||
m_input_layouts.emplace(key, std::move(entry));
|
||||
}
|
||||
|
||||
return dil;
|
||||
|
||||
@@ -38,7 +38,7 @@ bool D3D11StreamBuffer::Create(D3D11_BIND_FLAG bind_flags, u32 min_size, u32 max
|
||||
{
|
||||
// Older Intel drivers go absolutely bananas with CPU usage when using offset constant buffers.
|
||||
// NVIDIA seems to be okay, I don't know about AMD. So let's be safe and limit it to feature level 12+.
|
||||
m_use_map_no_overwrite = options.MapNoOverwriteOnDynamicConstantBuffer;
|
||||
m_use_map_no_overwrite = (options.MapNoOverwriteOnDynamicConstantBuffer && options.ConstantBufferOffsetting);
|
||||
if (m_use_map_no_overwrite && D3D11Device::GetMaxFeatureLevel() < D3D_FEATURE_LEVEL_12_0)
|
||||
{
|
||||
WARNING_LOG("Ignoring MapNoOverwriteOnDynamicConstantBuffer on driver due to feature level.");
|
||||
|
||||
@@ -280,6 +280,10 @@ std::unique_ptr<D3D11Texture> D3D11Texture::Create(ID3D11Device* device, u32 wid
|
||||
DefaultCaseIsUnreachable();
|
||||
}
|
||||
|
||||
// Multisampled depth buffers cannot be sampled at feature level 10.0.
|
||||
if (type == Type::DepthStencil && samples > 1 && device->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_1)
|
||||
bind_flags &= ~static_cast<u32>(D3D11_BIND_SHADER_RESOURCE);
|
||||
|
||||
if ((flags & Flags::AllowBindAsImage) != Flags::None)
|
||||
{
|
||||
DebugAssert(levels == 1);
|
||||
|
||||
Reference in new issue
Block a user