summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2023-03-09 15:18:39 +0100
committerGitHub <noreply@github.com>2023-03-09 15:18:39 +0100
commitb5c0c1e16360ad7c3b82d70d46c2193b6e32fe63 (patch)
treeab2ac964d3ed958f42e0dd362f746cc702bd0ebf /src
parentMerge pull request #9906 from german77/metroid2 (diff)
parentbuffer_cache: Add logic for non-NVN storage buffer tracking (diff)
downloadyuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar.gz
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar.bz2
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar.lz
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar.xz
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.tar.zst
yuzu-b5c0c1e16360ad7c3b82d70d46c2193b6e32fe63.zip
Diffstat (limited to 'src')
-rw-r--r--src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp8
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h24
2 files changed, 27 insertions, 5 deletions
diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
index 336338e62..d1e59f22e 100644
--- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
+++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
@@ -35,6 +35,7 @@ struct Bias {
u32 index;
u32 offset_begin;
u32 offset_end;
+ u32 alignment;
};
using boost::container::flat_set;
@@ -349,7 +350,8 @@ std::optional<StorageBufferAddr> Track(const IR::Value& value, const Bias* bias)
.index = index.U32(),
.offset = offset.U32(),
};
- if (!Common::IsAligned(storage_buffer.offset, 16)) {
+ const u32 alignment{bias ? bias->alignment : 8U};
+ if (!Common::IsAligned(storage_buffer.offset, alignment)) {
// The SSBO pointer has to be aligned
return std::nullopt;
}
@@ -371,6 +373,7 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info)
.index = 0,
.offset_begin = 0x110,
.offset_end = 0x610,
+ .alignment = 16,
};
// Track the low address of the instruction
const std::optional<LowAddrInfo> low_addr_info{TrackLowAddress(&inst)};
@@ -386,8 +389,11 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info)
storage_buffer = Track(low_addr, nullptr);
if (!storage_buffer) {
// If that also fails, use NVN fallbacks
+ LOG_WARNING(Shader, "Storage buffer failed to track, using global memory fallbacks");
return;
}
+ LOG_WARNING(Shader, "Storage buffer tracked without bias, index {} offset {}",
+ storage_buffer->index, storage_buffer->offset);
}
// Collect storage buffer and the instruction
if (IsGlobalMemoryWrite(inst)) {
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 2a150ccdc..1f656ffa8 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -383,7 +383,8 @@ private:
void NotifyBufferDeletion();
- [[nodiscard]] Binding StorageBufferBinding(GPUVAddr ssbo_addr, bool is_written = false) const;
+ [[nodiscard]] Binding StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index,
+ bool is_written = false) const;
[[nodiscard]] TextureBufferBinding GetTextureBufferBinding(GPUVAddr gpu_addr, u32 size,
PixelFormat format);
@@ -802,7 +803,7 @@ void BufferCache<P>::BindGraphicsStorageBuffer(size_t stage, size_t ssbo_index,
const auto& cbufs = maxwell3d->state.shader_stages[stage];
const GPUVAddr ssbo_addr = cbufs.const_buffers[cbuf_index].address + cbuf_offset;
- storage_buffers[stage][ssbo_index] = StorageBufferBinding(ssbo_addr, is_written);
+ storage_buffers[stage][ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written);
}
template <class P>
@@ -842,7 +843,7 @@ void BufferCache<P>::BindComputeStorageBuffer(size_t ssbo_index, u32 cbuf_index,
const auto& cbufs = launch_desc.const_buffer_config;
const GPUVAddr ssbo_addr = cbufs[cbuf_index].Address() + cbuf_offset;
- compute_storage_buffers[ssbo_index] = StorageBufferBinding(ssbo_addr, is_written);
+ compute_storage_buffers[ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written);
}
template <class P>
@@ -1988,11 +1989,26 @@ void BufferCache<P>::NotifyBufferDeletion() {
template <class P>
typename BufferCache<P>::Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr,
+ u32 cbuf_index,
bool is_written) const {
const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr);
- const u32 size = gpu_memory->Read<u32>(ssbo_addr + 8);
+ const auto size = [&]() {
+ const bool is_nvn_cbuf = cbuf_index == 0;
+ // The NVN driver buffer (index 0) is known to pack the SSBO address followed by its size.
+ if (is_nvn_cbuf) {
+ return gpu_memory->Read<u32>(ssbo_addr + 8);
+ }
+ // Other titles (notably Doom Eternal) may use STG/LDG on buffer addresses in custom defined
+ // cbufs, which do not store the sizes adjacent to the addresses, so use the fully
+ // mapped buffer size for now.
+ const u32 memory_layout_size = static_cast<u32>(gpu_memory->GetMemoryLayoutSize(gpu_addr));
+ LOG_INFO(HW_GPU, "Binding storage buffer for cbuf index {}, MemoryLayoutSize 0x{:X}",
+ cbuf_index, memory_layout_size);
+ return memory_layout_size;
+ }();
const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr);
if (!cpu_addr || size == 0) {
+ LOG_WARNING(HW_GPU, "Failed to find storage buffer for cbuf index {}", cbuf_index);
return NULL_BINDING;
}
const VAddr cpu_end = Common::AlignUp(*cpu_addr + size, Core::Memory::YUZU_PAGESIZE);