Add ComputeParticlesTest
Renderer: Add a way to execute commands on the device
This commit is contained in:
committed by
Jérôme Leclercq
parent
9e7b98a017
commit
e34ba8c05d
@@ -160,7 +160,7 @@ namespace Nz
|
||||
|
||||
void OpenGLCommandBufferBuilder::PostTransferBarrier()
|
||||
{
|
||||
/* nothing to do */
|
||||
m_commandBuffer.InsertMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
|
||||
}
|
||||
|
||||
void OpenGLCommandBufferBuilder::SetScissor(const Recti& scissorRegion)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLBuffer.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLComputePipeline.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
|
||||
@@ -155,6 +156,22 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenGLDevice::Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueType /*queueType*/)
|
||||
{
|
||||
const GL::Context* activeContext = GL::Context::GetCurrentContext();
|
||||
if (!activeContext || activeContext->GetDevice() != this)
|
||||
{
|
||||
if (!GL::Context::SetCurrentContext(m_referenceContext.get()))
|
||||
throw std::runtime_error("failed to activate context");
|
||||
}
|
||||
|
||||
OpenGLCommandBuffer commandBuffer; //< TODO: Use a pool and remove default constructor
|
||||
OpenGLCommandBufferBuilder builder(commandBuffer);
|
||||
callback(builder);
|
||||
|
||||
commandBuffer.Execute();
|
||||
}
|
||||
|
||||
const RenderDeviceInfo& OpenGLDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_deviceInfo;
|
||||
@@ -318,4 +335,16 @@ namespace Nz
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenGLDevice::WaitForIdle()
|
||||
{
|
||||
const GL::Context* activeContext = GL::Context::GetCurrentContext();
|
||||
if (!activeContext || activeContext->GetDevice() != this)
|
||||
{
|
||||
if (!GL::Context::SetCurrentContext(m_referenceContext.get()))
|
||||
throw std::runtime_error("failed to activate context");
|
||||
}
|
||||
|
||||
m_referenceContext->glFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ namespace Nz
|
||||
|
||||
void VulkanCommandBufferBuilder::PostTransferBarrier()
|
||||
{
|
||||
m_commandBuffer.MemoryBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_UNIFORM_READ_BIT);
|
||||
m_commandBuffer.MemoryBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_UNIFORM_READ_BIT);
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::SetScissor(const Recti& scissorRegion)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanComputePipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderPass.hpp>
|
||||
@@ -13,12 +14,29 @@
|
||||
#include <Nazara/VulkanRenderer/VulkanTexture.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanTextureFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanTextureSampler.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/QueueHandle.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
VulkanDevice::~VulkanDevice() = default;
|
||||
|
||||
void VulkanDevice::Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueType queueType)
|
||||
{
|
||||
Vk::AutoCommandBuffer commandBuffer = AllocateCommandBuffer(queueType);
|
||||
if (!commandBuffer->Begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT))
|
||||
throw std::runtime_error("failed to begin command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
VulkanCommandBufferBuilder builder(commandBuffer);
|
||||
callback(builder);
|
||||
|
||||
if (!commandBuffer->End())
|
||||
throw std::runtime_error("failed to build command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
GetQueue(GetDefaultFamilyIndex(queueType), 0).Submit(commandBuffer);
|
||||
GetQueue(GetDefaultFamilyIndex(queueType), 0).WaitIdle();
|
||||
}
|
||||
|
||||
const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_renderDeviceInfo;
|
||||
@@ -144,4 +162,9 @@ namespace Nz
|
||||
VkFormatProperties formatProperties = GetInstance().GetPhysicalDeviceFormatProperties(GetPhysicalDevice(), vulkanFormat);
|
||||
return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling
|
||||
}
|
||||
|
||||
void VulkanDevice::WaitForIdle()
|
||||
{
|
||||
Device::WaitForIdle();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user