diff options
| author | 2023-10-30 19:34:02 -0400 | |
|---|---|---|
| committer | 2023-10-31 20:10:54 -0400 | |
| commit | 735612c9b3b17d79c9259ba6415a481d6c776a5e (patch) | |
| tree | 9bca06e8f92a855f0d6a8eff6605fa4ab372e2d1 /src | |
| parent | shader_recompiler: Align SSBO offsets to meet host requirements (diff) | |
| download | yuzu-735612c9b3b17d79c9259ba6415a481d6c776a5e.tar.gz yuzu-735612c9b3b17d79c9259ba6415a481d6c776a5e.tar.xz yuzu-735612c9b3b17d79c9259ba6415a481d6c776a5e.zip | |
buffer_cache: Apply storage buffer alignment only to the offset
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/buffer_cache/buffer_cache.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 9202e53c7..5574c6130 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -1770,7 +1770,6 @@ template <class P> | |||
| 1770 | Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index, | 1770 | Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index, |
| 1771 | bool is_written) const { | 1771 | bool is_written) const { |
| 1772 | const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr); | 1772 | const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr); |
| 1773 | const u32 alignment = runtime.GetStorageBufferAlignment(); | ||
| 1774 | const auto size = [&]() { | 1773 | const auto size = [&]() { |
| 1775 | const bool is_nvn_cbuf = cbuf_index == 0; | 1774 | const bool is_nvn_cbuf = cbuf_index == 0; |
| 1776 | // The NVN driver buffer (index 0) is known to pack the SSBO address followed by its size. | 1775 | // The NVN driver buffer (index 0) is known to pack the SSBO address followed by its size. |
| @@ -1786,19 +1785,24 @@ Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index, | |||
| 1786 | const u32 memory_layout_size = static_cast<u32>(gpu_memory->GetMemoryLayoutSize(gpu_addr)); | 1785 | const u32 memory_layout_size = static_cast<u32>(gpu_memory->GetMemoryLayoutSize(gpu_addr)); |
| 1787 | return std::min(memory_layout_size, static_cast<u32>(8_MiB)); | 1786 | return std::min(memory_layout_size, static_cast<u32>(8_MiB)); |
| 1788 | }(); | 1787 | }(); |
| 1788 | // Alignment only applies to the offset of the buffer | ||
| 1789 | const u32 alignment = runtime.GetStorageBufferAlignment(); | ||
| 1789 | const GPUVAddr aligned_gpu_addr = Common::AlignDown(gpu_addr, alignment); | 1790 | const GPUVAddr aligned_gpu_addr = Common::AlignDown(gpu_addr, alignment); |
| 1790 | const u32 aligned_size = | 1791 | const u32 aligned_size = static_cast<u32>(gpu_addr - aligned_gpu_addr) + size; |
| 1791 | Common::AlignUp(static_cast<u32>(gpu_addr - aligned_gpu_addr) + size, alignment); | ||
| 1792 | 1792 | ||
| 1793 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(aligned_gpu_addr); | 1793 | const std::optional<VAddr> aligned_cpu_addr = gpu_memory->GpuToCpuAddress(aligned_gpu_addr); |
| 1794 | if (!cpu_addr || size == 0) { | 1794 | if (!aligned_cpu_addr || size == 0) { |
| 1795 | LOG_WARNING(HW_GPU, "Failed to find storage buffer for cbuf index {}", cbuf_index); | 1795 | LOG_WARNING(HW_GPU, "Failed to find storage buffer for cbuf index {}", cbuf_index); |
| 1796 | return NULL_BINDING; | 1796 | return NULL_BINDING; |
| 1797 | } | 1797 | } |
| 1798 | const VAddr cpu_end = Common::AlignUp(*cpu_addr + aligned_size, Core::Memory::YUZU_PAGESIZE); | 1798 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1799 | ASSERT_MSG(cpu_addr, "Unaligned storage buffer address not found for cbuf index {}", cbuf_index); | ||
| 1800 | // The end address used for size calculation does not need to be aligned | ||
| 1801 | const VAddr cpu_end = Common::AlignUp(*cpu_addr + size, Core::Memory::YUZU_PAGESIZE); | ||
| 1802 | |||
| 1799 | const Binding binding{ | 1803 | const Binding binding{ |
| 1800 | .cpu_addr = *cpu_addr, | 1804 | .cpu_addr = *aligned_cpu_addr, |
| 1801 | .size = is_written ? aligned_size : static_cast<u32>(cpu_end - *cpu_addr), | 1805 | .size = is_written ? aligned_size : static_cast<u32>(cpu_end - *aligned_cpu_addr), |
| 1802 | .buffer_id = BufferId{}, | 1806 | .buffer_id = BufferId{}, |
| 1803 | }; | 1807 | }; |
| 1804 | return binding; | 1808 | return binding; |