// 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 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(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(cbuf + descriptor.cbuf_offset)}; return base != 0 ? gpu_memory.Read(base + offset) : 0U; }) .value_or(0U); } } // namespace VideoCommon