vulkan: configure staging buffer size
This commit is contained in:
@@ -61,6 +61,8 @@ void LogSettings() {
|
||||
log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
|
||||
log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
|
||||
log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
|
||||
log_setting("Renderer_StagingBufferSize",
|
||||
(1ULL << static_cast<u32>(values.staging_buffer_size.GetValue())) * 128);
|
||||
log_setting("Audio_OutputEngine", values.sink_id.GetValue());
|
||||
log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue());
|
||||
log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue());
|
||||
@@ -196,6 +198,7 @@ void RestoreGlobalState(bool is_powered_on) {
|
||||
values.use_asynchronous_shaders.SetGlobal(true);
|
||||
values.use_fast_gpu_time.SetGlobal(true);
|
||||
values.use_pessimistic_flushes.SetGlobal(true);
|
||||
values.staging_buffer_size.SetGlobal(true);
|
||||
values.bg_red.SetGlobal(true);
|
||||
values.bg_green.SetGlobal(true);
|
||||
values.bg_blue.SetGlobal(true);
|
||||
|
||||
@@ -33,6 +33,14 @@ enum class GPUAccuracy : u32 {
|
||||
Extreme = 2,
|
||||
};
|
||||
|
||||
enum class StagingBufferSize : u32 {
|
||||
Size_128MiB = 0,
|
||||
Size_256MiB = 1,
|
||||
Size_512MiB = 2,
|
||||
Size_1024MiB = 3,
|
||||
Size_2048MiB = 4,
|
||||
};
|
||||
|
||||
enum class CPUAccuracy : u32 {
|
||||
Auto = 0,
|
||||
Accurate = 1,
|
||||
@@ -447,6 +455,9 @@ struct Values {
|
||||
SwitchableSetting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"};
|
||||
SwitchableSetting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"};
|
||||
SwitchableSetting<bool> use_pessimistic_flushes{false, "use_pessimistic_flushes"};
|
||||
SwitchableSetting<StagingBufferSize, true> staging_buffer_size{
|
||||
StagingBufferSize::Size_128MiB, StagingBufferSize::Size_128MiB,
|
||||
StagingBufferSize::Size_2048MiB, "staging_buffer_size"};
|
||||
|
||||
SwitchableSetting<u8> bg_red{0, "bg_red"};
|
||||
SwitchableSetting<u8> bg_green{0, "bg_green"};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "common/bit_util.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/literals.h"
|
||||
#include "common/settings.h"
|
||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
@@ -26,20 +27,18 @@ using namespace Common::Literals;
|
||||
constexpr VkDeviceSize MAX_ALIGNMENT = 256;
|
||||
// Maximum size to put elements in the stream buffer
|
||||
constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB;
|
||||
// Stream buffer size in bytes
|
||||
constexpr VkDeviceSize STREAM_BUFFER_SIZE = 128_MiB;
|
||||
constexpr VkDeviceSize REGION_SIZE = STREAM_BUFFER_SIZE / StagingBufferPool::NUM_SYNCS;
|
||||
|
||||
constexpr VkMemoryPropertyFlags HOST_FLAGS =
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
constexpr VkMemoryPropertyFlags STREAM_FLAGS = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | HOST_FLAGS;
|
||||
|
||||
bool IsStreamHeap(VkMemoryHeap heap) noexcept {
|
||||
return STREAM_BUFFER_SIZE < (heap.size * 2) / 3;
|
||||
static bool IsStreamHeap(VkMemoryHeap heap, size_t staging_buffer_size) noexcept {
|
||||
return staging_buffer_size < (heap.size * 2) / 3;
|
||||
}
|
||||
|
||||
std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask,
|
||||
VkMemoryPropertyFlags flags) noexcept {
|
||||
VkMemoryPropertyFlags flags,
|
||||
size_t staging_buffer_size) noexcept {
|
||||
for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) {
|
||||
if (((type_mask >> type_index) & 1) == 0) {
|
||||
// Memory type is incompatible
|
||||
@@ -50,7 +49,7 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p
|
||||
// Memory type doesn't have the flags we want
|
||||
continue;
|
||||
}
|
||||
if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex])) {
|
||||
if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex], staging_buffer_size)) {
|
||||
// Memory heap is not suitable for streaming
|
||||
continue;
|
||||
}
|
||||
@@ -61,17 +60,17 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p
|
||||
}
|
||||
|
||||
u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask,
|
||||
bool try_device_local) {
|
||||
bool try_device_local, size_t staging_buffer_size) {
|
||||
std::optional<u32> type;
|
||||
if (try_device_local) {
|
||||
// Try to find a DEVICE_LOCAL_BIT type, Nvidia and AMD have a dedicated heap for this
|
||||
type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS);
|
||||
type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS, staging_buffer_size);
|
||||
if (type) {
|
||||
return *type;
|
||||
}
|
||||
}
|
||||
// Otherwise try without the DEVICE_LOCAL_BIT
|
||||
type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS);
|
||||
type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS, staging_buffer_size);
|
||||
if (type) {
|
||||
return *type;
|
||||
}
|
||||
@@ -79,20 +78,25 @@ u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_
|
||||
throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
||||
}
|
||||
|
||||
size_t Region(size_t iterator) noexcept {
|
||||
return iterator / REGION_SIZE;
|
||||
size_t Region(size_t iterator, size_t region_size) noexcept {
|
||||
return iterator / region_size;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& memory_allocator_,
|
||||
Scheduler& scheduler_)
|
||||
: device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} {
|
||||
|
||||
staging_buffer_size =
|
||||
(1ULL << static_cast<u32>(Settings::values.staging_buffer_size.GetValue())) * 128_MiB;
|
||||
region_size = staging_buffer_size / StagingBufferPool::NUM_SYNCS;
|
||||
|
||||
const vk::Device& dev = device.GetLogical();
|
||||
stream_buffer = dev.CreateBuffer(VkBufferCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.size = STREAM_BUFFER_SIZE,
|
||||
.size = staging_buffer_size,
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
@@ -122,14 +126,14 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.pNext = make_dedicated ? &dedicated_info : nullptr,
|
||||
.allocationSize = requirements.size,
|
||||
.memoryTypeIndex =
|
||||
FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true),
|
||||
.memoryTypeIndex = FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true,
|
||||
staging_buffer_size),
|
||||
};
|
||||
stream_memory = dev.TryAllocateMemory(stream_memory_info);
|
||||
if (!stream_memory) {
|
||||
LOG_INFO(Render_Vulkan, "Dynamic memory allocation failed, trying with system memory");
|
||||
stream_memory_info.memoryTypeIndex =
|
||||
FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, false);
|
||||
stream_memory_info.memoryTypeIndex = FindMemoryTypeIndex(
|
||||
memory_properties, requirements.memoryTypeBits, false, staging_buffer_size);
|
||||
stream_memory = dev.AllocateMemory(stream_memory_info);
|
||||
}
|
||||
|
||||
@@ -137,7 +141,7 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem
|
||||
stream_memory.SetObjectNameEXT("Stream Buffer Memory");
|
||||
}
|
||||
stream_buffer.BindMemory(*stream_memory, 0);
|
||||
stream_pointer = stream_memory.Map(0, STREAM_BUFFER_SIZE);
|
||||
stream_pointer = stream_memory.Map(0, staging_buffer_size);
|
||||
}
|
||||
|
||||
StagingBufferPool::~StagingBufferPool() = default;
|
||||
@@ -158,25 +162,25 @@ void StagingBufferPool::TickFrame() {
|
||||
}
|
||||
|
||||
StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
|
||||
if (AreRegionsActive(Region(free_iterator) + 1,
|
||||
std::min(Region(iterator + size) + 1, NUM_SYNCS))) {
|
||||
if (AreRegionsActive(Region(free_iterator, region_size) + 1,
|
||||
std::min(Region(iterator + size, region_size) + 1, NUM_SYNCS))) {
|
||||
// Avoid waiting for the previous usages to be free
|
||||
return GetStagingBuffer(size, MemoryUsage::Upload);
|
||||
}
|
||||
const u64 current_tick = scheduler.CurrentTick();
|
||||
std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + Region(iterator),
|
||||
current_tick);
|
||||
std::fill(sync_ticks.begin() + Region(used_iterator, region_size),
|
||||
sync_ticks.begin() + Region(iterator, region_size), current_tick);
|
||||
used_iterator = iterator;
|
||||
free_iterator = std::max(free_iterator, iterator + size);
|
||||
|
||||
if (iterator + size >= STREAM_BUFFER_SIZE) {
|
||||
std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS,
|
||||
current_tick);
|
||||
if (iterator + size >= staging_buffer_size) {
|
||||
std::fill(sync_ticks.begin() + Region(used_iterator, region_size),
|
||||
sync_ticks.begin() + NUM_SYNCS, current_tick);
|
||||
used_iterator = 0;
|
||||
iterator = 0;
|
||||
free_iterator = size;
|
||||
|
||||
if (AreRegionsActive(0, Region(size) + 1)) {
|
||||
if (AreRegionsActive(0, Region(size, region_size) + 1)) {
|
||||
// Avoid waiting for the previous usages to be free
|
||||
return GetStagingBuffer(size, MemoryUsage::Upload);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,9 @@ private:
|
||||
size_t free_iterator = 0;
|
||||
std::array<u64, NUM_SYNCS> sync_ticks{};
|
||||
|
||||
size_t staging_buffer_size = 0;
|
||||
size_t region_size = 0;
|
||||
|
||||
StagingBuffersCache device_local_cache;
|
||||
StagingBuffersCache upload_cache;
|
||||
StagingBuffersCache download_cache;
|
||||
|
||||
@@ -673,6 +673,7 @@ void Config::ReadRendererValues() {
|
||||
ReadGlobalSetting(Settings::values.scaling_filter);
|
||||
ReadGlobalSetting(Settings::values.anti_aliasing);
|
||||
ReadGlobalSetting(Settings::values.max_anisotropy);
|
||||
ReadGlobalSetting(Settings::values.staging_buffer_size);
|
||||
ReadGlobalSetting(Settings::values.use_speed_limit);
|
||||
ReadGlobalSetting(Settings::values.speed_limit);
|
||||
ReadGlobalSetting(Settings::values.use_disk_shader_cache);
|
||||
@@ -1281,6 +1282,10 @@ void Config::SaveRendererValues() {
|
||||
static_cast<u32>(Settings::values.anti_aliasing.GetDefault()),
|
||||
Settings::values.anti_aliasing.UsingGlobal());
|
||||
WriteGlobalSetting(Settings::values.max_anisotropy);
|
||||
WriteSetting(QString::fromStdString(Settings::values.staging_buffer_size.GetLabel()),
|
||||
static_cast<u32>(Settings::values.staging_buffer_size.GetValue(global)),
|
||||
static_cast<u32>(Settings::values.staging_buffer_size.GetDefault()),
|
||||
Settings::values.staging_buffer_size.UsingGlobal());
|
||||
WriteGlobalSetting(Settings::values.use_speed_limit);
|
||||
WriteGlobalSetting(Settings::values.speed_limit);
|
||||
WriteGlobalSetting(Settings::values.use_disk_shader_cache);
|
||||
|
||||
@@ -208,3 +208,4 @@ Q_DECLARE_METATYPE(Settings::ScalingFilter);
|
||||
Q_DECLARE_METATYPE(Settings::AntiAliasing);
|
||||
Q_DECLARE_METATYPE(Settings::RendererBackend);
|
||||
Q_DECLARE_METATYPE(Settings::ShaderBackend);
|
||||
Q_DECLARE_METATYPE(Settings::StagingBufferSize);
|
||||
|
||||
@@ -35,14 +35,20 @@ void ConfigureGraphicsAdvanced::SetConfiguration() {
|
||||
static_cast<int>(Settings::values.gpu_accuracy.GetValue()));
|
||||
ui->anisotropic_filtering_combobox->setCurrentIndex(
|
||||
Settings::values.max_anisotropy.GetValue());
|
||||
ui->staging_buffer_size->setCurrentIndex(
|
||||
static_cast<u32>(Settings::values.staging_buffer_size.GetValue()));
|
||||
} else {
|
||||
ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy);
|
||||
ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox,
|
||||
&Settings::values.max_anisotropy);
|
||||
ConfigurationShared::SetPerGameSetting(ui->staging_buffer_size,
|
||||
&Settings::values.staging_buffer_size);
|
||||
ConfigurationShared::SetHighlight(ui->label_gpu_accuracy,
|
||||
!Settings::values.gpu_accuracy.UsingGlobal());
|
||||
ConfigurationShared::SetHighlight(ui->af_label,
|
||||
!Settings::values.max_anisotropy.UsingGlobal());
|
||||
ConfigurationShared::SetHighlight(ui->label_staging_buffer_size,
|
||||
!Settings::values.staging_buffer_size.UsingGlobal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +64,8 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() {
|
||||
ui->use_fast_gpu_time, use_fast_gpu_time);
|
||||
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_pessimistic_flushes,
|
||||
ui->use_pessimistic_flushes, use_pessimistic_flushes);
|
||||
ConfigurationShared::ApplyPerGameSetting(&Settings::values.staging_buffer_size,
|
||||
ui->staging_buffer_size);
|
||||
}
|
||||
|
||||
void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) {
|
||||
@@ -84,6 +92,7 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() {
|
||||
Settings::values.use_pessimistic_flushes.UsingGlobal());
|
||||
ui->anisotropic_filtering_combobox->setEnabled(
|
||||
Settings::values.max_anisotropy.UsingGlobal());
|
||||
ui->staging_buffer_size->setEnabled(Settings::values.staging_buffer_size.UsingGlobal());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -103,4 +112,7 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() {
|
||||
ConfigurationShared::SetColoredComboBox(
|
||||
ui->anisotropic_filtering_combobox, ui->af_label,
|
||||
static_cast<int>(Settings::values.max_anisotropy.GetValue(true)));
|
||||
ConfigurationShared::SetColoredComboBox(
|
||||
ui->staging_buffer_size, ui->label_staging_buffer_size,
|
||||
static_cast<u32>(Settings::values.staging_buffer_size.GetValue(true)));
|
||||
}
|
||||
|
||||
@@ -168,6 +168,60 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="staging_buffer_size_layout" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_staging_buffer_size">
|
||||
<property name="text">
|
||||
<string>Vulkan staging buffer size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="staging_buffer_size">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>128 MiB</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>256 MiB</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>512 MiB</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1024 MiB</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2048 MiB</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user