From df9ea5eee1f3c11519df263b8206793f33c2bc48 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 13 Oct 2026 14:09:07 +1000 Subject: [PATCH] D3D11Device: Fix input layout cache keys and feature level 10 limits --- src/util/d3d11_device.cpp | 10 +++++----- src/util/d3d11_device.h | 7 ++++++- src/util/d3d11_pipeline.cpp | 12 +++++++++--- src/util/d3d11_stream_buffer.cpp | 2 +- src/util/d3d11_texture.cpp | 4 ++++ 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/util/d3d11_device.cpp b/src/util/d3d11_device.cpp index b41167155..b5a0f48ee 100644 --- a/src/util/d3d11_device.cpp +++ b/src/util/d3d11_device.cpp @@ -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); } diff --git a/src/util/d3d11_device.h b/src/util/d3d11_device.h index 146305a07..77fef87cd 100644 --- a/src/util/d3d11_device.h +++ b/src/util/d3d11_device.h @@ -139,8 +139,13 @@ private: using RasterizationStateMap = std::unordered_map>; using DepthStateMap = std::unordered_map>; using BlendStateMap = std::unordered_map, BlendStateMapHash>; + struct InputLayoutEntry + { + std::vector attributes; // referenced by the map key + ComPtr layout; + }; using InputLayoutMap = - std::unordered_map, GPUPipeline::InputLayoutHash>; + std::unordered_map; static constexpr u32 MIN_UNIFORM_BUFFER_SIZE = 16; static constexpr u32 UNIFORM_BUFFER_ALIGNMENT = 256; diff --git a/src/util/d3d11_pipeline.cpp b/src/util/d3d11_pipeline.cpp index af3b6d6a3..e19ddb952 100644 --- a/src/util/d3d11_pipeline.cpp +++ b/src/util/d3d11_pipeline.cpp @@ -176,7 +176,7 @@ D3D11Device::ComPtr D3D11Device::GetRasterizationState(co desc.FillMode = D3D11_FILL_SOLID; desc.CullMode = cull_mapping[static_cast(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 D3D11Device::GetBlendState(const GPUPipeli { ComPtr dbs; - const std::pair key(bs.key, num_rts); + // The blend constant is set separately, so keep it out of the key. + const std::pair 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 D3D11Device::GetInputLayout(const GPUPipe HRESULT hr = m_device->CreateInputLayout(elems, static_cast(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; diff --git a/src/util/d3d11_stream_buffer.cpp b/src/util/d3d11_stream_buffer.cpp index 4b49bbdd1..5cb98026b 100644 --- a/src/util/d3d11_stream_buffer.cpp +++ b/src/util/d3d11_stream_buffer.cpp @@ -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."); diff --git a/src/util/d3d11_texture.cpp b/src/util/d3d11_texture.cpp index 607e78bd1..dfc6b58ee 100644 --- a/src/util/d3d11_texture.cpp +++ b/src/util/d3d11_texture.cpp @@ -280,6 +280,10 @@ std::unique_ptr 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(D3D11_BIND_SHADER_RESOURCE); + if ((flags & Flags::AllowBindAsImage) != Flags::None) { DebugAssert(levels == 1);