From 859ba21f6db184f7ada03314ed02b42e49eb8149 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Tue, 1 Jun 2021 13:26:43 -0400 Subject: [PATCH] buffer_cache: Simplify uniform disabling logic --- src/video_core/buffer_cache/buffer_cache.h | 11 +++++++---- src/video_core/engines/maxwell_3d.cpp | 8 ++++++-- src/video_core/memory_manager.cpp | 3 +++ src/video_core/rasterizer_interface.h | 3 +++ src/video_core/renderer_opengl/gl_rasterizer.cpp | 4 ++++ src/video_core/renderer_opengl/gl_rasterizer.h | 1 + src/video_core/renderer_vulkan/vk_rasterizer.cpp | 4 ++++ src/video_core/renderer_vulkan/vk_rasterizer.h | 1 + 8 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 9e6b87960c..d371b842f0 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -110,6 +110,8 @@ public: void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size); + void DisableGraphicsUniformBuffer(size_t stage, u32 index); + void UpdateGraphicsBuffers(bool is_indexed); void UpdateComputeBuffers(); @@ -419,10 +421,6 @@ template void BufferCache

::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) { const std::optional cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); - if (!cpu_addr) { - uniform_buffers[stage][index] = NULL_BINDING; - return; - } const Binding binding{ .cpu_addr = *cpu_addr, .size = size, @@ -431,6 +429,11 @@ void BufferCache

::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr uniform_buffers[stage][index] = binding; } +template +void BufferCache

::DisableGraphicsUniformBuffer(size_t stage, u32 index) { + uniform_buffers[stage][index] = NULL_BINDING; +} + template void BufferCache

::UpdateGraphicsBuffers(bool is_indexed) { MICROPROFILE_SCOPE(GPU_PrepareBuffers); diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 75517a4f7e..aab6b8f7a3 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -578,8 +578,12 @@ void Maxwell3D::ProcessCBBind(size_t stage_index) { buffer.size = regs.const_buffer.cb_size; const bool is_enabled = bind_data.valid.Value() != 0; - const GPUVAddr gpu_addr = is_enabled ? regs.const_buffer.BufferAddress() : 0; - const u32 size = is_enabled ? regs.const_buffer.cb_size : 0; + if (!is_enabled) { + rasterizer->DisableGraphicsUniformBuffer(stage_index, bind_data.index); + return; + } + const GPUVAddr gpu_addr = regs.const_buffer.BufferAddress(); + const u32 size = regs.const_buffer.cb_size; rasterizer->BindGraphicsUniformBuffer(stage_index, bind_data.index, gpu_addr, size); } diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index eb58ac6b6c..7124c755c7 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -163,6 +163,9 @@ std::optional MemoryManager::FindFreeRange(std::size_t size, std::size } std::optional MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const { + if (gpu_addr == 0) { + return std::nullopt; + } const auto page_entry{GetPageEntry(gpu_addr)}; if (!page_entry.IsValid()) { return std::nullopt; diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.h index 50491b7586..f968b5b164 100644 --- a/src/video_core/rasterizer_interface.h +++ b/src/video_core/rasterizer_interface.h @@ -54,6 +54,9 @@ public: virtual void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) = 0; + /// Signal disabling of a uniform buffer + virtual void DisableGraphicsUniformBuffer(size_t stage, u32 index) = 0; + /// Signal a GPU based semaphore as a fence virtual void SignalSemaphore(GPUVAddr addr, u32 value) = 0; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index a5dbb9adfd..f87bb269b6 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -526,6 +526,10 @@ void RasterizerOpenGL::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAd buffer_cache.BindGraphicsUniformBuffer(stage, index, gpu_addr, size); } +void RasterizerOpenGL::DisableGraphicsUniformBuffer(size_t stage, u32 index) { + buffer_cache.DisableGraphicsUniformBuffer(stage, index); +} + void RasterizerOpenGL::FlushAll() {} void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) { diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 3745cf6379..76298517f5 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -72,6 +72,7 @@ public: void ResetCounter(VideoCore::QueryType type) override; void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional timestamp) override; void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override; + void DisableGraphicsUniformBuffer(size_t stage, u32 index) override; void FlushAll() override; void FlushRegion(VAddr addr, u64 size) override; bool MustFlushRegion(VAddr addr, u64 size) override; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index e9a0e78118..1c91201709 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -476,6 +476,10 @@ void RasterizerVulkan::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAd buffer_cache.BindGraphicsUniformBuffer(stage, index, gpu_addr, size); } +void Vulkan::RasterizerVulkan::DisableGraphicsUniformBuffer(size_t stage, u32 index) { + buffer_cache.DisableGraphicsUniformBuffer(stage, index); +} + void RasterizerVulkan::FlushAll() {} void RasterizerVulkan::FlushRegion(VAddr addr, u64 size) { diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 235afc6f3b..cb8c5c279a 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h @@ -64,6 +64,7 @@ public: void ResetCounter(VideoCore::QueryType type) override; void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional timestamp) override; void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override; + void DisableGraphicsUniformBuffer(size_t stage, u32 index) override; void FlushAll() override; void FlushRegion(VAddr addr, u64 size) override; bool MustFlushRegion(VAddr addr, u64 size) override;