vkCmdSetEvent/vkCmdResetEvent implementation

This implementation of vkCmdSetEvent and vkCmdResetEvent assumes:
- There's only one queue (which currently is the case)
- Everything in the queue is executed linearly (which is currently the case)
- VkPipelineStageFlags can be ignored for now

Taking VkPipelineStageFlags into account could be used to avoid unnecessary
stalls or cache flushing. This will come at the optimization phase after
full conformance is achieved.

Bug b/117835459

Change-Id: Icb08a8b8e3fe63e827c9ba994a5e4353603e4ac9
Reviewed-on: https://swiftshader-review.googlesource.com/c/24371
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 432edf9..52bde46 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -14,6 +14,7 @@
 
 #include "VkCommandBuffer.hpp"
 #include "VkBuffer.hpp"
+#include "VkEvent.hpp"
 #include "VkFramebuffer.hpp"
 #include "VkImage.hpp"
 #include "VkPipeline.hpp"
@@ -343,6 +344,38 @@
 private:
 };
 
+struct SignalEvent : public CommandBuffer::Command
+{
+	SignalEvent(VkEvent ev, VkPipelineStageFlags stageMask) : ev(ev), stageMask(stageMask)
+	{
+	}
+
+	void play(CommandBuffer::ExecutionState& executionState)
+	{
+		Cast(ev)->signal();
+	}
+
+private:
+	VkEvent ev;
+	VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and signal the event at the last stage
+};
+
+struct ResetEvent : public CommandBuffer::Command
+{
+	ResetEvent(VkEvent ev, VkPipelineStageFlags stageMask) : ev(ev), stageMask(stageMask)
+	{
+	}
+
+	void play(CommandBuffer::ExecutionState& executionState)
+	{
+		Cast(ev)->reset();
+	}
+
+private:
+	VkEvent ev;
+	VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and reset the event at the last stage
+};
+
 CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel)
 {
 	// FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations
@@ -729,12 +762,16 @@
 
 void CommandBuffer::setEvent(VkEvent event, VkPipelineStageFlags stageMask)
 {
-	UNIMPLEMENTED();
+	ASSERT(state == RECORDING);
+
+	addCommand<SignalEvent>(event, stageMask);
 }
 
 void CommandBuffer::resetEvent(VkEvent event, VkPipelineStageFlags stageMask)
 {
-	UNIMPLEMENTED();
+	ASSERT(state == RECORDING);
+
+	addCommand<ResetEvent>(event, stageMask);
 }
 
 void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask,