Commit 9bc7a814 by Alexis Hetu Committed by Alexis Hétu

RenderPass begin and end

Implemented vkCmdBeginRenderPass and vkCmdEndRenderPass. The RenderPass object begin and end are noop for now, but the framebuffer gets cleared within vkCmdBeginRenderPass. Bug b/119620965 b/118619338 Change-Id: I8e1f2932d9d52b3dcb5c10d4e60cba83b28bb95d Reviewed-on: https://swiftshader-review.googlesource.com/c/23108Reviewed-by: 's avatarCorentin Wallez <cwallez@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com>
parent e6e76c61
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
// limitations under the License. // limitations under the License.
#include "VkCommandBuffer.hpp" #include "VkCommandBuffer.hpp"
#include "VkFramebuffer.hpp"
#include "VkImage.hpp" #include "VkImage.hpp"
#include "VkRenderpass.hpp"
#include <cstring> #include <cstring>
...@@ -24,7 +26,7 @@ class CommandBuffer::Command ...@@ -24,7 +26,7 @@ class CommandBuffer::Command
{ {
public: public:
// FIXME (b/119421344): change the commandBuffer argument to a CommandBuffer state // FIXME (b/119421344): change the commandBuffer argument to a CommandBuffer state
virtual void play(CommandBuffer* commandBuffer) = 0; virtual void play(CommandBuffer::ExecutionState& executionState) = 0;
virtual ~Command() {} virtual ~Command() {}
}; };
...@@ -47,9 +49,10 @@ public: ...@@ -47,9 +49,10 @@ public:
} }
protected: protected:
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
UNIMPLEMENTED(); Cast(renderPass)->begin();
Cast(framebuffer)->clear(clearValueCount, clearValues, renderArea);
} }
private: private:
...@@ -68,9 +71,9 @@ public: ...@@ -68,9 +71,9 @@ public:
} }
protected: protected:
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
UNIMPLEMENTED(); Cast(executionState.renderpass)->end();
} }
private: private:
...@@ -85,9 +88,9 @@ public: ...@@ -85,9 +88,9 @@ public:
} }
protected: protected:
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
UNIMPLEMENTED(); executionState.pipelines[pipelineBindPoint] = pipeline;
} }
private: private:
...@@ -102,9 +105,9 @@ struct VertexBufferBind : public CommandBuffer::Command ...@@ -102,9 +105,9 @@ struct VertexBufferBind : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
UNIMPLEMENTED(); executionState.vertexInputBindings[binding] = { buffer, offset };
} }
uint32_t binding; uint32_t binding;
...@@ -118,7 +121,7 @@ struct Draw : public CommandBuffer::Command ...@@ -118,7 +121,7 @@ struct Draw : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
...@@ -133,7 +136,7 @@ struct ImageToImageCopy : public CommandBuffer::Command ...@@ -133,7 +136,7 @@ struct ImageToImageCopy : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
Cast(srcImage)->copyTo(dstImage, region); Cast(srcImage)->copyTo(dstImage, region);
} }
...@@ -151,7 +154,7 @@ struct ImageToBufferCopy : public CommandBuffer::Command ...@@ -151,7 +154,7 @@ struct ImageToBufferCopy : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
Cast(srcImage)->copyTo(dstBuffer, region); Cast(srcImage)->copyTo(dstBuffer, region);
} }
...@@ -169,7 +172,7 @@ struct BufferToImageCopy : public CommandBuffer::Command ...@@ -169,7 +172,7 @@ struct BufferToImageCopy : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
Cast(dstImage)->copyFrom(srcBuffer, region); Cast(dstImage)->copyFrom(srcBuffer, region);
} }
...@@ -186,7 +189,7 @@ struct PipelineBarrier : public CommandBuffer::Command ...@@ -186,7 +189,7 @@ struct PipelineBarrier : public CommandBuffer::Command
{ {
} }
void play(CommandBuffer* commandBuffer) void play(CommandBuffer::ExecutionState& executionState)
{ {
// This can currently be a noop. The sw::Surface locking/unlocking mechanism used by the renderer already takes care of // This can currently be a noop. The sw::Surface locking/unlocking mechanism used by the renderer already takes care of
// making sure the read/writes always happen in order. Eventually, if we remove this synchronization mechanism, we can // making sure the read/writes always happen in order. Eventually, if we remove this synchronization mechanism, we can
...@@ -205,9 +208,6 @@ CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel) ...@@ -205,9 +208,6 @@ CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel)
{ {
// FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations
commands = new std::vector<std::unique_ptr<Command> >(); commands = new std::vector<std::unique_ptr<Command> >();
pipelines[VK_PIPELINE_BIND_POINT_GRAPHICS] = VK_NULL_HANDLE;
pipelines[VK_PIPELINE_BIND_POINT_COMPUTE] = VK_NULL_HANDLE;
} }
void CommandBuffer::destroy(const VkAllocationCallbacks* pAllocator) void CommandBuffer::destroy(const VkAllocationCallbacks* pAllocator)
...@@ -591,14 +591,14 @@ void CommandBuffer::drawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, ui ...@@ -591,14 +591,14 @@ void CommandBuffer::drawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, ui
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
void CommandBuffer::submit() void CommandBuffer::submit(CommandBuffer::ExecutionState& executionState)
{ {
// Perform recorded work // Perform recorded work
state = PENDING; state = PENDING;
for(auto& command : *commands) for(auto& command : *commands)
{ {
command->play(this); command->play(executionState);
} }
// After work is completed // After work is completed
......
...@@ -109,7 +109,21 @@ public: ...@@ -109,7 +109,21 @@ public:
void drawIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); void drawIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride);
void drawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); void drawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride);
void submit(); // TODO(sugoi): Move ExecutionState out of CommandBuffer (possibly into Device)
struct ExecutionState
{
VkRenderPass renderpass = VK_NULL_HANDLE;
VkPipeline pipelines[VK_PIPELINE_BIND_POINT_RANGE_SIZE] = {};
struct VertexInputBinding
{
VkBuffer buffer;
VkDeviceSize offset;
};
VertexInputBinding vertexInputBindings[MAX_VERTEX_INPUT_BINDINGS] = {};
};
void submit(CommandBuffer::ExecutionState& executionState);
class Command; class Command;
private: private:
...@@ -118,14 +132,6 @@ private: ...@@ -118,14 +132,6 @@ private:
enum State { INITIAL, RECORDING, EXECUTABLE, PENDING, INVALID }; enum State { INITIAL, RECORDING, EXECUTABLE, PENDING, INVALID };
State state = INITIAL; State state = INITIAL;
VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
VkPipeline pipelines[VK_PIPELINE_BIND_POINT_RANGE_SIZE];
struct VertexInputBindings
{
VkBuffer buffer;
VkDeviceSize offset;
};
VertexInputBindings vertexInputBindings[MAX_VERTEX_INPUT_BINDINGS];
// FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations
std::vector<std::unique_ptr<Command>>* commands; std::vector<std::unique_ptr<Command>>* commands;
......
...@@ -34,9 +34,12 @@ void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence f ...@@ -34,9 +34,12 @@ void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence f
vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]); vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]);
} }
{
CommandBuffer::ExecutionState executionState;
for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++) for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++)
{ {
vk::Cast(submitInfo.pCommandBuffers[j])->submit(); vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);
}
} }
for(uint32_t j = 0; j < submitInfo.signalSemaphoreCount; j++) for(uint32_t j = 0; j < submitInfo.signalSemaphoreCount; j++)
......
...@@ -30,4 +30,14 @@ size_t RenderPass::ComputeRequiredAllocationSize(const VkRenderPassCreateInfo* p ...@@ -30,4 +30,14 @@ size_t RenderPass::ComputeRequiredAllocationSize(const VkRenderPassCreateInfo* p
return 0; return 0;
} }
void RenderPass::begin()
{
// FIXME (b/119620965): noop
}
void RenderPass::end()
{
// FIXME (b/119620965): noop
}
} // namespace vk } // namespace vk
\ No newline at end of file
...@@ -29,6 +29,9 @@ public: ...@@ -29,6 +29,9 @@ public:
static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkRenderPassCreateInfo* pCreateInfo);
void begin();
void end();
private: private:
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment