diff --git a/src/video_core/buffer_cache/buffer_cache.cpp b/src/video_core/buffer_cache/buffer_cache.cpp index d5ebd85fc2..0a92691641 100644 --- a/src/video_core/buffer_cache/buffer_cache.cpp +++ b/src/video_core/buffer_cache/buffer_cache.cpp @@ -34,21 +34,10 @@ BufferCache::BufferCache(const Vulkan::Instance& instance_, Vulkan::Scheduler& s // Ensure the first slot is used for the null buffer const auto null_id = - slot_buffers.insert(instance, scheduler, MemoryUsage::DeviceLocal, 0, ReadFlags, 1); + slot_buffers.insert(instance, scheduler, MemoryUsage::DeviceLocal, 0, ReadFlags, 4); ASSERT(null_id.index == 0); const vk::Buffer& null_buffer = slot_buffers[null_id].buffer; Vulkan::SetObjectName(instance.GetDevice(), null_buffer, "Null Buffer"); - - const vk::BufferViewCreateInfo null_view_ci = { - .buffer = null_buffer, - .format = vk::Format::eR8Unorm, - .offset = 0, - .range = VK_WHOLE_SIZE, - }; - const auto [null_view_result, null_view] = instance.GetDevice().createBufferView(null_view_ci); - ASSERT_MSG(null_view_result == vk::Result::eSuccess, "Failed to create null buffer view."); - null_buffer_view = null_view; - Vulkan::SetObjectName(instance.GetDevice(), null_buffer_view, "Null Buffer View"); } BufferCache::~BufferCache() = default; diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index c367795f19..f29a37b63e 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -71,10 +71,6 @@ class BufferCache { return slot_buffers[id]; } - [[nodiscard]] vk::BufferView& NullBufferView() { - return null_buffer_view; - } - /// Invalidates any buffer in the logical page range. void InvalidateMemory(VAddr device_addr, u64 size); @@ -160,7 +156,6 @@ class BufferCache { std::shared_mutex mutex; Common::SlotVector slot_buffers; RangeSet gpu_modified_ranges; - vk::BufferView null_buffer_view; MemoryTracker memory_tracker; PageTable page_table; }; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 6e628239be..addada490b 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -537,6 +537,7 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding } // Second pass to re-bind buffers that were updated after binding + auto& null_buffer = buffer_cache.GetBuffer(VideoCore::NULL_BUFFER_ID); for (u32 i = 0; i < buffer_bindings.size(); i++) { const auto& [buffer_id, vsharp] = buffer_bindings[i]; const auto& desc = stage.buffers[i]; @@ -548,7 +549,6 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding } else if (instance.IsNullDescriptorSupported()) { buffer_infos.emplace_back(VK_NULL_HANDLE, 0, VK_WHOLE_SIZE); } else { - auto& null_buffer = buffer_cache.GetBuffer(VideoCore::NULL_BUFFER_ID); buffer_infos.emplace_back(null_buffer.Handle(), 0, VK_WHOLE_SIZE); } } else { @@ -582,12 +582,10 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding ++binding.buffer; } - const auto null_buffer_view = - instance.IsNullDescriptorSupported() ? VK_NULL_HANDLE : buffer_cache.NullBufferView(); for (u32 i = 0; i < texbuffer_bindings.size(); i++) { const auto& [buffer_id, vsharp] = texbuffer_bindings[i]; const auto& desc = stage.texture_buffers[i]; - vk::BufferView& buffer_view = buffer_views.emplace_back(null_buffer_view); + vk::BufferView buffer_view; if (buffer_id) { const u32 alignment = instance.TexelBufferMinAlignment(); const auto [vk_buffer, offset] = buffer_cache.ObtainBuffer( @@ -612,6 +610,11 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding if (desc.is_written) { texture_cache.InvalidateMemoryFromGPU(vsharp.base_address, vsharp.GetSize()); } + } else if (instance.IsNullDescriptorSupported()) { + buffer_view = VK_NULL_HANDLE; + } else { + buffer_view = null_buffer.View(0, null_buffer.SizeBytes(), desc.is_written, + vsharp.GetDataFmt(), vsharp.GetNumberFmt()); } set_writes.push_back({ @@ -621,7 +624,7 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding .descriptorCount = 1, .descriptorType = desc.is_written ? vk::DescriptorType::eStorageTexelBuffer : vk::DescriptorType::eUniformTexelBuffer, - .pTexelBufferView = &buffer_view, + .pTexelBufferView = &buffer_views.emplace_back(buffer_view), }); ++binding.buffer; }