mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-03-27 03:49:41 -04:00
feat(vulkan): add VK_KHR_buffer_device_address support infrastructure
- Add vkGetBufferDeviceAddress function pointer loading - Add GetBufferAddress method to Device wrapper with null checks - Add buffer device address feature detection and AMD GPU disable - Add VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT to buffer creation - Store and expose device address in Buffer class - Update VMA allocator with BUFFER_DEVICE_ADDRESS_BIT flag - Add IsRectangularLinesSupported/IsSmoothLinesSupported checks - Disable buffer_device_address on AMD GPUs for stability
This commit is contained in:
@@ -69,6 +69,11 @@ vk::Buffer CreateBuffer(const Device& device, const MemoryAllocator& memory_allo
|
||||
if (device.IsExtConditionalRendering()) {
|
||||
flags |= VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT;
|
||||
}
|
||||
// Enable buffer device address for NVN-style global memory emulation (NVNbufferAddress)
|
||||
// This allows shaders to use 64-bit buffer addresses directly, matching Nintendo's NVN API
|
||||
if (device.IsKhrBufferDeviceAddressSupported()) {
|
||||
flags |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
|
||||
}
|
||||
|
||||
// Optimize buffer size based on VRAM usage mode
|
||||
u64 optimized_size = size;
|
||||
@@ -158,6 +163,20 @@ Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
|
||||
if (runtime.device.HasDebuggingToolAttached()) {
|
||||
buffer.SetObjectNameEXT(fmt::format("Buffer 0x{:x}", CpuAddr()).c_str());
|
||||
}
|
||||
// Obtain 64-bit GPU address for NVN-style global memory emulation
|
||||
// This is the equivalent of nvnBufferGetAddress() from Nintendo's NVN API
|
||||
if (device->IsKhrBufferDeviceAddressSupported()) {
|
||||
// Safety check: ensure buffer handle is valid before querying address
|
||||
const VkBuffer buffer_handle = *buffer;
|
||||
if (buffer_handle != VK_NULL_HANDLE) {
|
||||
const VkBufferDeviceAddressInfo address_info{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
||||
.pNext = nullptr,
|
||||
.buffer = buffer_handle,
|
||||
};
|
||||
device_address = device->GetLogical().GetBufferAddress(address_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VkBufferView Buffer::View(u32 offset, u32 size, VideoCore::Surface::PixelFormat format) {
|
||||
|
||||
@@ -34,6 +34,13 @@ public:
|
||||
return *buffer;
|
||||
}
|
||||
|
||||
/// Returns the 64-bit GPU address of this buffer (NVNbufferAddress equivalent)
|
||||
/// This is the Vulkan equivalent of nvnBufferGetAddress() from the Nintendo NVN API
|
||||
/// Used for global memory emulation where shaders need direct 64-bit buffer addresses
|
||||
[[nodiscard]] VkDeviceAddress GetDeviceAddress() const noexcept {
|
||||
return device_address;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsRegionUsed(u64 offset, u64 size) const noexcept {
|
||||
return tracker.IsUsed(offset, size);
|
||||
}
|
||||
@@ -60,6 +67,7 @@ private:
|
||||
|
||||
const Device* device{};
|
||||
vk::Buffer buffer;
|
||||
VkDeviceAddress device_address{}; // NVNbufferAddress - 64-bit GPU address for global memory
|
||||
std::vector<BufferView> views;
|
||||
VideoCommon::UsageTracker tracker;
|
||||
bool is_null{};
|
||||
|
||||
@@ -350,6 +350,7 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
.support_int64_atomics = device.IsExtShaderAtomicInt64Supported(),
|
||||
.support_derivative_control = true,
|
||||
.support_geometry_shader_passthrough = device.IsNvGeometryShaderPassthroughSupported(),
|
||||
.support_buffer_device_address = device.IsKhrBufferDeviceAddressSupported(),
|
||||
.support_native_ndc = device.IsExtDepthClipControlSupported(),
|
||||
.support_scaled_attributes = !device.MustEmulateScaledFormats(),
|
||||
.support_multi_viewport = device.SupportsMultiViewport(),
|
||||
|
||||
Reference in New Issue
Block a user