Vulkan: Add debugging of the command buffer.

Add a debugger context and server to vk::Device, along with a getter for acquiring the debugger context.

Generate a synthetic file containing all the Vulkan commands in the command buffer, and allow the debugger to single line step over these.

All of this is no-op unless ENABLE_VK_DEBUGGER is defined at compile time, and the VK_DEBUGGER_PORT env var is set at run time.

Bug: b/145351270
Change-Id: I8bea398a6c08d4cb23d76172dbca2a08ae109a6d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38913
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Vulkan/VkDevice.hpp b/src/Vulkan/VkDevice.hpp
index 94fbba6..d83e8e8 100644
--- a/src/Vulkan/VkDevice.hpp
+++ b/src/Vulkan/VkDevice.hpp
@@ -33,6 +33,11 @@
 class PhysicalDevice;
 class Queue;
 
+namespace dbg {
+class Context;
+class Server;
+}  // namespace dbg
+
 class Device
 {
 public:
@@ -93,6 +98,13 @@
 	rr::Routine *findInConstCache(const SamplingRoutineCache::Key &key) const;
 	void updateSamplingRoutineConstCache();
 
+#ifdef ENABLE_VK_DEBUGGER
+	std::shared_ptr<vk::dbg::Context> getDebuggerContext() const
+	{
+		return debugger.context;
+	}
+#endif  // ENABLE_VK_DEBUGGER
+
 private:
 	PhysicalDevice *const physicalDevice = nullptr;
 	Queue *const queues = nullptr;
@@ -105,6 +117,14 @@
 	ExtensionName *extensions = nullptr;
 	const VkPhysicalDeviceFeatures enabledFeatures = {};
 	std::shared_ptr<marl::Scheduler> scheduler;
+
+#ifdef ENABLE_VK_DEBUGGER
+	struct
+	{
+		std::shared_ptr<vk::dbg::Context> context;
+		std::shared_ptr<vk::dbg::Server> server;
+	} debugger;
+#endif  // ENABLE_VK_DEBUGGER
 };
 
 using DispatchableDevice = DispatchableObject<Device, VkDevice>;