aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/shader_handle_program.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/shader_handle_program.h')
-rw-r--r--src/video_core/shader_handle_program.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/video_core/shader_handle_program.h b/src/video_core/shader_handle_program.h
new file mode 100644
index 0000000000..3d35524cc8
--- /dev/null
+++ b/src/video_core/shader_handle_program.h
@@ -0,0 +1,39 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include "common/common_types.h"
+#include "shader_recompiler/shader_info.h"
+#include "video_core/memory_manager.h"
+
+namespace VideoCommon {
+
+/// The texture handle a shader reads from a storage buffer, computed from the current constant
+/// buffer and storage buffer words (Shader::Info::handle_programs). cbuf_address(index) is the
+/// bound constant buffer's address, 0 when none is bound.
+template <typename CbufAddress>
+u32 EvaluateTextureHandle(const Shader::Info& info, u32 program, Tegra::MemoryManager& gpu_memory,
+ CbufAddress&& cbuf_address) {
+ return Shader::EvaluateHandleProgram(
+ info.handle_programs[program],
+ [&](u32 index, u32 offset) -> u32 {
+ const GPUVAddr base{cbuf_address(index)};
+ return base != 0 ? gpu_memory.Read<u32>(base + offset) : 0U;
+ },
+ [&](u32 binding, u32 offset) -> u32 {
+ if (binding >= info.storage_buffers_descriptors.size()) {
+ return 0U;
+ }
+ const auto& descriptor{info.storage_buffers_descriptors[binding]};
+ const GPUVAddr cbuf{cbuf_address(descriptor.cbuf_index)};
+ if (cbuf == 0) {
+ return 0U;
+ }
+ const GPUVAddr base{gpu_memory.Read<u64>(cbuf + descriptor.cbuf_offset)};
+ return base != 0 ? gpu_memory.Read<u32>(base + offset) : 0U;
+ })
+ .value_or(0U);
+}
+
+} // namespace VideoCommon