rasterizer_cache: Improve debugging

* Give surfaces an object label viewable in renderdoc with useful information

* Break up the Cache Mgmt microprofile scope and commonize it
This commit is contained in:
GPUCode
2023-02-27 23:09:59 +02:00
parent 07f85cf639
commit 8396ce0b47
8 changed files with 62 additions and 40 deletions

View File

@@ -6,13 +6,14 @@
namespace VideoCore {
MICROPROFILE_DEFINE(RasterizerCache_BlitSurface, "RasterizerCache", "BlitSurface",
MP_RGB(128, 192, 64));
MICROPROFILE_DEFINE(RasterizerCache_CopySurface, "RasterizerCache", "CopySurface",
MICROPROFILE_DEFINE(RasterizerCache_SurfaceCopy, "RasterizerCache", "Surface Copy",
MP_RGB(128, 192, 64));
MICROPROFILE_DEFINE(RasterizerCache_SurfaceLoad, "RasterizerCache", "Surface Load",
MP_RGB(128, 192, 64));
MICROPROFILE_DEFINE(RasterizerCache_SurfaceFlush, "RasterizerCache", "Surface Flush",
MP_RGB(128, 192, 64));
MICROPROFILE_DEFINE(RasterizerCache_Invalidation, "RasterizerCache", "Invalidation",
MP_RGB(128, 64, 192));
MICROPROFILE_DEFINE(RasterizerCache_Flush, "RasterizerCache", "Flush", MP_RGB(128, 64, 192));
} // namespace VideoCore

View File

@@ -17,10 +17,11 @@
namespace VideoCore {
MICROPROFILE_DECLARE(RasterizerCache_BlitSurface);
MICROPROFILE_DECLARE(RasterizerCache_CopySurface);
MICROPROFILE_DECLARE(RasterizerCache_SurfaceCopy);
MICROPROFILE_DECLARE(RasterizerCache_SurfaceLoad);
MICROPROFILE_DECLARE(RasterizerCache_SurfaceFlush);
MICROPROFILE_DECLARE(RasterizerCache_Invalidation);
MICROPROFILE_DECLARE(RasterizerCache_Flush);
inline auto RangeFromInterval(auto& map, const auto& interval) {
return boost::make_iterator_range(map.equal_range(interval));
@@ -64,6 +65,8 @@ RasterizerCache<T>::~RasterizerCache() {
template <class T>
bool RasterizerCache<T>::AccelerateTextureCopy(const GPU::Regs::DisplayTransferConfig& config) {
MICROPROFILE_SCOPE(RasterizerCache_SurfaceCopy);
u32 copy_size = Common::AlignDown(config.texture_copy.size, 16);
if (copy_size == 0) {
return false;
@@ -159,6 +162,8 @@ bool RasterizerCache<T>::AccelerateTextureCopy(const GPU::Regs::DisplayTransferC
template <class T>
bool RasterizerCache<T>::AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) {
MICROPROFILE_SCOPE(RasterizerCache_SurfaceCopy);
SurfaceParams src_params;
src_params.addr = config.GetPhysicalInputAddress();
src_params.width = config.output_width;
@@ -405,7 +410,7 @@ SurfaceId RasterizerCache<T>::FindMatch(const SurfaceParams& params, ScaleMatch
template <class T>
void RasterizerCache<T>::CopySurface(Surface& src_surface, Surface& dst_surface,
SurfaceInterval copy_interval) {
MICROPROFILE_SCOPE(RasterizerCache_CopySurface);
MICROPROFILE_SCOPE(RasterizerCache_SurfaceCopy);
const auto subrect_params = dst_surface.FromInterval(copy_interval);
const Rect2D dst_rect = dst_surface.GetScaledSubRect(subrect_params);
@@ -1173,6 +1178,8 @@ void RasterizerCache<T>::FlushRegion(PAddr addr, u32 size, SurfaceId flush_surfa
return;
}
MICROPROFILE_SCOPE(RasterizerCache_Flush);
const SurfaceInterval flush_interval(addr, addr + size);
SurfaceRegions flushed_intervals{};
@@ -1183,7 +1190,7 @@ void RasterizerCache<T>::FlushRegion(PAddr addr, u32 size, SurfaceId flush_surfa
// access that region, anything higher than 8 you're guaranteed it comes from a service
const SurfaceInterval interval =
size <= 8 ? dirty_interval : dirty_interval & flush_interval;
if (surface_id && surface_id != flush_surface_id) {
if (flush_surface_id && surface_id != flush_surface_id) {
continue;
}
@@ -1215,6 +1222,8 @@ void RasterizerCache<T>::InvalidateRegion(PAddr addr, u32 size, SurfaceId region
return;
}
MICROPROFILE_SCOPE(RasterizerCache_Invalidation);
const SurfaceInterval invalid_interval{addr, addr + size};
if (region_owner_id) {
Surface& region_owner = slot_surfaces[region_owner_id];

View File

@@ -24,8 +24,6 @@ MICROPROFILE_DEFINE(OpenGL_VAO, "OpenGL", "Vertex Array Setup", MP_RGB(255, 128,
MICROPROFILE_DEFINE(OpenGL_VS, "OpenGL", "Vertex Shader Setup", MP_RGB(192, 128, 128));
MICROPROFILE_DEFINE(OpenGL_GS, "OpenGL", "Geometry Shader Setup", MP_RGB(128, 192, 128));
MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
using VideoCore::SurfaceType;
@@ -644,22 +642,18 @@ void RasterizerOpenGL::NotifyFixedFunctionPicaRegisterChanged(u32 id) {
}
void RasterizerOpenGL::FlushAll() {
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
res_cache.FlushAll();
}
void RasterizerOpenGL::FlushRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
res_cache.FlushRegion(addr, size);
}
void RasterizerOpenGL::InvalidateRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
res_cache.InvalidateRegion(addr, size);
}
void RasterizerOpenGL::FlushAndInvalidateRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
res_cache.FlushRegion(addr, size);
res_cache.InvalidateRegion(addr, size);
}
@@ -669,7 +663,6 @@ void RasterizerOpenGL::ClearAll(bool flush) {
}
bool RasterizerOpenGL::AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) {
MICROPROFILE_SCOPE(OpenGL_Blits);
return res_cache.AccelerateDisplayTransfer(config);
}
@@ -687,7 +680,6 @@ bool RasterizerOpenGL::AccelerateDisplay(const GPU::Regs::FramebufferConfig& con
if (framebuffer_addr == 0) {
return false;
}
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
VideoCore::SurfaceParams src_params;
src_params.addr = framebuffer_addr;

View File

@@ -334,10 +334,19 @@ void TextureRuntime::BindFramebuffer(GLenum target, GLint level, GLenum textarge
Surface::Surface(TextureRuntime& runtime_, const VideoCore::SurfaceParams& params)
: VideoCore::SurfaceBase{params}, runtime{&runtime_}, driver{&runtime_.GetDriver()} {
if (pixel_format != VideoCore::PixelFormat::Invalid) {
const auto& tuple = runtime->GetFormatTuple(pixel_format);
alloc = runtime->Allocate(GetScaledWidth(), GetScaledHeight(), levels, tuple, texture_type);
if (pixel_format == VideoCore::PixelFormat::Invalid) {
return;
}
const u32 scaled_width = GetScaledWidth();
const u32 scaled_height = GetScaledHeight();
const auto& tuple = runtime->GetFormatTuple(pixel_format);
alloc = runtime->Allocate(scaled_width, scaled_height, levels, tuple, texture_type);
const std::string name =
fmt::format("Surface: {}x{} {} {} levels from {:#x} to {:#x}", scaled_width, scaled_height,
VideoCore::PixelFormatAsString(pixel_format), levels, addr, end);
glObjectLabel(GL_TEXTURE, alloc.texture.handle, -1, name.c_str());
}
Surface::~Surface() {

View File

@@ -326,14 +326,10 @@ Instance::Instance(Frontend::EmuWindow& window, u32 physical_device_index)
return it != extensions.end();
};
bool debug_messenger_supported{};
bool debug_report_supported{};
if (enable_validation) {
debug_messenger_supported = IsSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
debug_report_supported = IsSupported(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
if (!debug_messenger_supported) {
instance_chain.unlink<vk::DebugUtilsMessengerCreateInfoEXT>();
}
debug_messenger_supported = IsSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
debug_report_supported = IsSupported(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
if (!debug_messenger_supported || !enable_validation) {
instance_chain.unlink<vk::DebugUtilsMessengerCreateInfoEXT>();
}
try {

View File

@@ -193,6 +193,11 @@ public:
return shader_stencil_export;
}
/// Returns true if VK_EXT_debug_utils is supported
bool IsExtDebugUtilsSupported() const {
return debug_messenger_supported;
}
/// Returns the vendor ID of the physical device
u32 GetVendorID() const {
return properties.vendorID;
@@ -333,6 +338,8 @@ private:
bool shader_stencil_export{};
bool enable_validation{};
bool dump_command_buffers{};
bool debug_messenger_supported{};
bool debug_report_supported{};
};
} // namespace Vulkan

View File

@@ -22,8 +22,6 @@ namespace {
MICROPROFILE_DEFINE(Vulkan_VS, "Vulkan", "Vertex Shader Setup", MP_RGB(192, 128, 128));
MICROPROFILE_DEFINE(Vulkan_GS, "Vulkan", "Geometry Shader Setup", MP_RGB(128, 192, 128));
MICROPROFILE_DEFINE(Vulkan_Drawing, "Vulkan", "Drawing", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(Vulkan_CacheManagement, "Vulkan", "Cache Mgmt", MP_RGB(100, 255, 100));
MICROPROFILE_DEFINE(Vulkan_Blits, "Vulkan", "Blits", MP_RGB(100, 100, 255));
using TriangleTopology = Pica::PipelineRegs::TriangleTopology;
using VideoCore::SurfaceType;
@@ -720,22 +718,18 @@ void RasterizerVulkan::NotifyFixedFunctionPicaRegisterChanged(u32 id) {
}
void RasterizerVulkan::FlushAll() {
MICROPROFILE_SCOPE(Vulkan_CacheManagement);
res_cache.FlushAll();
}
void RasterizerVulkan::FlushRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(Vulkan_CacheManagement);
res_cache.FlushRegion(addr, size);
}
void RasterizerVulkan::InvalidateRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(Vulkan_CacheManagement);
res_cache.InvalidateRegion(addr, size);
}
void RasterizerVulkan::FlushAndInvalidateRegion(PAddr addr, u32 size) {
MICROPROFILE_SCOPE(Vulkan_CacheManagement);
res_cache.FlushRegion(addr, size);
res_cache.InvalidateRegion(addr, size);
}
@@ -745,7 +739,6 @@ void RasterizerVulkan::ClearAll(bool flush) {
}
bool RasterizerVulkan::AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) {
MICROPROFILE_SCOPE(Vulkan_Blits);
return res_cache.AccelerateDisplayTransfer(config);
}
@@ -760,10 +753,9 @@ bool RasterizerVulkan::AccelerateFill(const GPU::Regs::MemoryFillConfig& config)
bool RasterizerVulkan::AccelerateDisplay(const GPU::Regs::FramebufferConfig& config,
PAddr framebuffer_addr, u32 pixel_stride,
ScreenInfo& screen_info) {
if (framebuffer_addr == 0) {
if (framebuffer_addr == 0) [[unlikely]] {
return false;
}
MICROPROFILE_SCOPE(Vulkan_CacheManagement);
VideoCore::SurfaceParams src_params;
src_params.addr = framebuffer_addr;

View File

@@ -491,7 +491,7 @@ bool TextureRuntime::CopyTextures(Surface& source, Surface& dest,
.srcSubresource{
.aspectMask = params.aspect,
.mipLevel = copy.src_level,
.baseArrayLayer = 0,
.baseArrayLayer = copy.src_layer,
.layerCount = 1,
},
.srcOffset = {static_cast<s32>(copy.src_offset.x), static_cast<s32>(copy.src_offset.y),
@@ -499,7 +499,7 @@ bool TextureRuntime::CopyTextures(Surface& source, Surface& dest,
.dstSubresource{
.aspectMask = params.aspect,
.mipLevel = copy.dst_level,
.baseArrayLayer = 0,
.baseArrayLayer = copy.dst_layer,
.layerCount = 1,
},
.dstOffset = {static_cast<s32>(copy.dst_offset.x), static_cast<s32>(copy.dst_offset.y),
@@ -774,9 +774,25 @@ Surface::Surface(TextureRuntime& runtime_, const VideoCore::SurfaceParams& param
: VideoCore::SurfaceBase{params}, runtime{&runtime_}, instance{&runtime_.GetInstance()},
scheduler{&runtime_.GetScheduler()} {
if (pixel_format != VideoCore::PixelFormat::Invalid) {
alloc = runtime->Allocate(GetScaledWidth(), GetScaledHeight(), levels, params.pixel_format,
texture_type);
if (pixel_format == VideoCore::PixelFormat::Invalid) {
return;
}
const u32 scaled_width = GetScaledWidth();
const u32 scaled_height = GetScaledHeight();
alloc =
runtime->Allocate(scaled_width, scaled_height, levels, params.pixel_format, texture_type);
if (instance->IsExtDebugUtilsSupported()) {
const std::string name = fmt::format(
"Surface: {}x{} {} {} levels from {:#x} to {:#x}", scaled_width, scaled_height,
VideoCore::PixelFormatAsString(pixel_format), levels, addr, end);
const vk::DebugUtilsObjectNameInfoEXT name_info = {
.objectType = vk::ObjectType::eImage,
.objectHandle = (u64) static_cast<VkImage>(alloc.image),
.pObjectName = name.c_str(),
};
instance->GetDevice().setDebugUtilsObjectNameEXT(name_info);
}
}