summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2022-10-12 15:36:56 -0700
committerGravatar GitHub2022-10-12 15:36:56 -0700
commitdbacb31f61f3ba0e4f6c37ccfca16cf282a00cc4 (patch)
treebe6c686c9c7c071585dc19d83c1a27c7f9c13acc
parentMerge pull request #9040 from liamwhite/woe-thirty-two (diff)
parentRevert "vulkan: automatically use larger staging buffer sizes when possible" (diff)
downloadyuzu-dbacb31f61f3ba0e4f6c37ccfca16cf282a00cc4.tar.gz
yuzu-dbacb31f61f3ba0e4f6c37ccfca16cf282a00cc4.tar.xz
yuzu-dbacb31f61f3ba0e4f6c37ccfca16cf282a00cc4.zip
Merge pull request #9027 from yuzu-emu/revert-8987-another-name-for-reinforcement-steel
Revert "vulkan: automatically use larger staging buffer sizes when possible"
-rw-r--r--src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp84
-rw-r--r--src/video_core/renderer_vulkan/vk_staging_buffer_pool.h3
2 files changed, 27 insertions, 60 deletions
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
index 7fb256953..06f68d09a 100644
--- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
+++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
@@ -26,39 +26,20 @@ using namespace Common::Literals;
26constexpr VkDeviceSize MAX_ALIGNMENT = 256; 26constexpr VkDeviceSize MAX_ALIGNMENT = 256;
27// Maximum size to put elements in the stream buffer 27// Maximum size to put elements in the stream buffer
28constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB; 28constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB;
29// Stream buffer size in bytes
30constexpr VkDeviceSize STREAM_BUFFER_SIZE = 128_MiB;
31constexpr VkDeviceSize REGION_SIZE = STREAM_BUFFER_SIZE / StagingBufferPool::NUM_SYNCS;
29 32
30constexpr VkMemoryPropertyFlags HOST_FLAGS = 33constexpr VkMemoryPropertyFlags HOST_FLAGS =
31 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; 34 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
32constexpr VkMemoryPropertyFlags STREAM_FLAGS = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | HOST_FLAGS; 35constexpr VkMemoryPropertyFlags STREAM_FLAGS = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | HOST_FLAGS;
33 36
34static bool IsStreamHeap(VkMemoryHeap heap, size_t staging_buffer_size) noexcept { 37bool IsStreamHeap(VkMemoryHeap heap) noexcept {
35 return staging_buffer_size < (heap.size * 2) / 3; 38 return STREAM_BUFFER_SIZE < (heap.size * 2) / 3;
36}
37
38static bool HasLargeDeviceLocalHostVisibleMemory(const VkPhysicalDeviceMemoryProperties& props) {
39 const auto flags{VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT};
40
41 for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) {
42 const auto& memory_type{props.memoryTypes[type_index]};
43
44 if ((memory_type.propertyFlags & flags) != flags) {
45 // Memory must be device local and host visible
46 continue;
47 }
48
49 const auto& heap{props.memoryHeaps[memory_type.heapIndex]};
50 if (heap.size >= 7168_MiB) {
51 // This is the right type of memory
52 return true;
53 }
54 }
55
56 return false;
57} 39}
58 40
59std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, 41std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask,
60 VkMemoryPropertyFlags flags, 42 VkMemoryPropertyFlags flags) noexcept {
61 size_t staging_buffer_size) noexcept {
62 for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) { 43 for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) {
63 if (((type_mask >> type_index) & 1) == 0) { 44 if (((type_mask >> type_index) & 1) == 0) {
64 // Memory type is incompatible 45 // Memory type is incompatible
@@ -69,7 +50,7 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p
69 // Memory type doesn't have the flags we want 50 // Memory type doesn't have the flags we want
70 continue; 51 continue;
71 } 52 }
72 if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex], staging_buffer_size)) { 53 if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex])) {
73 // Memory heap is not suitable for streaming 54 // Memory heap is not suitable for streaming
74 continue; 55 continue;
75 } 56 }
@@ -80,17 +61,17 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p
80} 61}
81 62
82u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, 63u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask,
83 bool try_device_local, size_t staging_buffer_size) { 64 bool try_device_local) {
84 std::optional<u32> type; 65 std::optional<u32> type;
85 if (try_device_local) { 66 if (try_device_local) {
86 // Try to find a DEVICE_LOCAL_BIT type, Nvidia and AMD have a dedicated heap for this 67 // Try to find a DEVICE_LOCAL_BIT type, Nvidia and AMD have a dedicated heap for this
87 type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS, staging_buffer_size); 68 type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS);
88 if (type) { 69 if (type) {
89 return *type; 70 return *type;
90 } 71 }
91 } 72 }
92 // Otherwise try without the DEVICE_LOCAL_BIT 73 // Otherwise try without the DEVICE_LOCAL_BIT
93 type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS, staging_buffer_size); 74 type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS);
94 if (type) { 75 if (type) {
95 return *type; 76 return *type;
96 } 77 }
@@ -98,32 +79,20 @@ u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_
98 throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY); 79 throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY);
99} 80}
100 81
101size_t Region(size_t iterator, size_t region_size) noexcept { 82size_t Region(size_t iterator) noexcept {
102 return iterator / region_size; 83 return iterator / REGION_SIZE;
103} 84}
104} // Anonymous namespace 85} // Anonymous namespace
105 86
106StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& memory_allocator_, 87StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& memory_allocator_,
107 Scheduler& scheduler_) 88 Scheduler& scheduler_)
108 : device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} { 89 : device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} {
109
110 const auto memory_properties{device.GetPhysical().GetMemoryProperties().memoryProperties};
111 if (HasLargeDeviceLocalHostVisibleMemory(memory_properties)) {
112 // Possible on many integrated and newer discrete cards
113 staging_buffer_size = 1_GiB;
114 } else {
115 // Well-supported default size used by most Vulkan PC games
116 staging_buffer_size = 256_MiB;
117 }
118
119 region_size = staging_buffer_size / StagingBufferPool::NUM_SYNCS;
120
121 const vk::Device& dev = device.GetLogical(); 90 const vk::Device& dev = device.GetLogical();
122 stream_buffer = dev.CreateBuffer(VkBufferCreateInfo{ 91 stream_buffer = dev.CreateBuffer(VkBufferCreateInfo{
123 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, 92 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
124 .pNext = nullptr, 93 .pNext = nullptr,
125 .flags = 0, 94 .flags = 0,
126 .size = staging_buffer_size, 95 .size = STREAM_BUFFER_SIZE,
127 .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | 96 .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
128 VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 97 VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
129 .sharingMode = VK_SHARING_MODE_EXCLUSIVE, 98 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
@@ -148,18 +117,19 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem
148 .image = nullptr, 117 .image = nullptr,
149 .buffer = *stream_buffer, 118 .buffer = *stream_buffer,
150 }; 119 };
120 const auto memory_properties = device.GetPhysical().GetMemoryProperties().memoryProperties;
151 VkMemoryAllocateInfo stream_memory_info{ 121 VkMemoryAllocateInfo stream_memory_info{
152 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, 122 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
153 .pNext = make_dedicated ? &dedicated_info : nullptr, 123 .pNext = make_dedicated ? &dedicated_info : nullptr,
154 .allocationSize = requirements.size, 124 .allocationSize = requirements.size,
155 .memoryTypeIndex = FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true, 125 .memoryTypeIndex =
156 staging_buffer_size), 126 FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true),
157 }; 127 };
158 stream_memory = dev.TryAllocateMemory(stream_memory_info); 128 stream_memory = dev.TryAllocateMemory(stream_memory_info);
159 if (!stream_memory) { 129 if (!stream_memory) {
160 LOG_INFO(Render_Vulkan, "Dynamic memory allocation failed, trying with system memory"); 130 LOG_INFO(Render_Vulkan, "Dynamic memory allocation failed, trying with system memory");
161 stream_memory_info.memoryTypeIndex = FindMemoryTypeIndex( 131 stream_memory_info.memoryTypeIndex =
162 memory_properties, requirements.memoryTypeBits, false, staging_buffer_size); 132 FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, false);
163 stream_memory = dev.AllocateMemory(stream_memory_info); 133 stream_memory = dev.AllocateMemory(stream_memory_info);
164 } 134 }
165 135
@@ -167,7 +137,7 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem
167 stream_memory.SetObjectNameEXT("Stream Buffer Memory"); 137 stream_memory.SetObjectNameEXT("Stream Buffer Memory");
168 } 138 }
169 stream_buffer.BindMemory(*stream_memory, 0); 139 stream_buffer.BindMemory(*stream_memory, 0);
170 stream_pointer = stream_memory.Map(0, staging_buffer_size); 140 stream_pointer = stream_memory.Map(0, STREAM_BUFFER_SIZE);
171} 141}
172 142
173StagingBufferPool::~StagingBufferPool() = default; 143StagingBufferPool::~StagingBufferPool() = default;
@@ -188,25 +158,25 @@ void StagingBufferPool::TickFrame() {
188} 158}
189 159
190StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) { 160StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
191 if (AreRegionsActive(Region(free_iterator, region_size) + 1, 161 if (AreRegionsActive(Region(free_iterator) + 1,
192 std::min(Region(iterator + size, region_size) + 1, NUM_SYNCS))) { 162 std::min(Region(iterator + size) + 1, NUM_SYNCS))) {
193 // Avoid waiting for the previous usages to be free 163 // Avoid waiting for the previous usages to be free
194 return GetStagingBuffer(size, MemoryUsage::Upload); 164 return GetStagingBuffer(size, MemoryUsage::Upload);
195 } 165 }
196 const u64 current_tick = scheduler.CurrentTick(); 166 const u64 current_tick = scheduler.CurrentTick();
197 std::fill(sync_ticks.begin() + Region(used_iterator, region_size), 167 std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + Region(iterator),
198 sync_ticks.begin() + Region(iterator, region_size), current_tick); 168 current_tick);
199 used_iterator = iterator; 169 used_iterator = iterator;
200 free_iterator = std::max(free_iterator, iterator + size); 170 free_iterator = std::max(free_iterator, iterator + size);
201 171
202 if (iterator + size >= staging_buffer_size) { 172 if (iterator + size >= STREAM_BUFFER_SIZE) {
203 std::fill(sync_ticks.begin() + Region(used_iterator, region_size), 173 std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS,
204 sync_ticks.begin() + NUM_SYNCS, current_tick); 174 current_tick);
205 used_iterator = 0; 175 used_iterator = 0;
206 iterator = 0; 176 iterator = 0;
207 free_iterator = size; 177 free_iterator = size;
208 178
209 if (AreRegionsActive(0, Region(size, region_size) + 1)) { 179 if (AreRegionsActive(0, Region(size) + 1)) {
210 // Avoid waiting for the previous usages to be free 180 // Avoid waiting for the previous usages to be free
211 return GetStagingBuffer(size, MemoryUsage::Upload); 181 return GetStagingBuffer(size, MemoryUsage::Upload);
212 } 182 }
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
index 90c67177f..91dc84da8 100644
--- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
+++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
@@ -93,9 +93,6 @@ private:
93 size_t free_iterator = 0; 93 size_t free_iterator = 0;
94 std::array<u64, NUM_SYNCS> sync_ticks{}; 94 std::array<u64, NUM_SYNCS> sync_ticks{};
95 95
96 size_t staging_buffer_size = 0;
97 size_t region_size = 0;
98
99 StagingBuffersCache device_local_cache; 96 StagingBuffersCache device_local_cache;
100 StagingBuffersCache upload_cache; 97 StagingBuffersCache upload_cache;
101 StagingBuffersCache download_cache; 98 StagingBuffersCache download_cache;