Lot of small fixes/improvements

This commit is contained in:
Jérôme Leclercq
2021-05-14 01:48:47 +02:00
parent 9376cfefd2
commit 61dbd91346
22 changed files with 84 additions and 82 deletions

View File

@@ -906,6 +906,8 @@ namespace Nz
std::size_t passIndex = *itRead;
if (seen.find(passIndex) == seen.end())
{
seen.insert(passIndex);
if (itRead != itWrite)
*itWrite++ = passIndex;
else

View File

@@ -112,6 +112,7 @@ namespace Nz
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
//FIXME: Don't clear when not needed
for (std::size_t i = 0; i < colorBufferCount; ++i)
{
Nz::Color color = command.clearValues[i].color;
@@ -127,6 +128,7 @@ namespace Nz
GLenum buffer = GL_BACK;
context->glDrawBuffers(1, &buffer);
//FIXME: Don't clear when not needed
Nz::Color color = command.clearValues[0].color;
context->glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f);
context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@@ -112,7 +112,7 @@ namespace Nz
m_commandBuffer.SetViewport(viewportRegion);
}
void OpenGLCommandBufferBuilder::TextureBarrier(PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout, const Texture& texture)
void OpenGLCommandBufferBuilder::TextureBarrier(PipelineStageFlags /*srcStageMask*/, PipelineStageFlags /*dstStageMask*/, MemoryAccessFlags /*srcAccessMask*/, MemoryAccessFlags /*dstAccessMask*/, TextureLayout /*oldLayout*/, TextureLayout /*newLayout*/, const Texture& /*texture*/)
{
/* nothing to do */
}

View File

@@ -31,14 +31,15 @@ namespace Nz
return m_uploadPool;
}
void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
void OpenGLRenderImage::Present()
{
m_owner.Present();
m_uploadPool.Reset();
}
void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags /*queueTypeFlags*/)
{
OpenGLCommandBuffer* oglCommandBuffer = static_cast<OpenGLCommandBuffer*>(commandBuffer);
oglCommandBuffer->Execute();
}
void OpenGLRenderImage::Present()
{
m_owner.Present();
}
}

View File

@@ -377,7 +377,7 @@ namespace Nz::GL
return false;
}
if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0)
if (m_loader.DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0)
{
m_params.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits;
m_params.depthBits = descriptor.cDepthBits;

View File

@@ -25,14 +25,6 @@ namespace Nz
return m_image->GetUploadPool();
}
void RenderFrame::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{
if (!m_image)
throw std::runtime_error("frame is either invalid or has already been presented");
m_image->SubmitCommandBuffer(commandBuffer, queueTypeFlags);
}
void RenderFrame::Present()
{
if (!m_image)
@@ -41,4 +33,12 @@ namespace Nz
m_image->Present();
m_image = nullptr;
}
void RenderFrame::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{
if (!m_image)
throw std::runtime_error("frame is either invalid or has already been presented");
m_image->SubmitCommandBuffer(commandBuffer, queueTypeFlags);
}
}

View File

@@ -68,7 +68,7 @@ namespace Nz
const ShaderAst::ExpressionType& rightType = GetExpressionType(*node.right);
ShaderAst::PrimitiveType leftTypeBase = RetrieveBaseType(leftType);
ShaderAst::PrimitiveType rightTypeBase = RetrieveBaseType(rightType);
//ShaderAst::PrimitiveType rightTypeBase = RetrieveBaseType(rightType);
UInt32 leftOperand = EvaluateExpression(node.left);

View File

@@ -79,7 +79,7 @@ namespace Nz
beginInfo.renderArea.offset.y = renderRect.y;
beginInfo.renderArea.extent.width = renderRect.width;
beginInfo.renderArea.extent.height = renderRect.height;
beginInfo.clearValueCount = vkClearValues.size();
beginInfo.clearValueCount = UInt32(vkClearValues.size());
beginInfo.pClearValues = vkClearValues.data();
m_commandBuffer.BeginRenderPass(beginInfo);

View File

@@ -63,6 +63,15 @@ namespace Nz
return m_uploadPool;
}
void VulkanRenderImage::Present()
{
Vk::QueueHandle& graphicsQueue = m_owner.GetGraphicsQueue();
if (!graphicsQueue.Submit(UInt32(m_graphicalCommandsBuffers.size()), m_graphicalCommandsBuffers.data(), m_imageAvailableSemaphore, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, m_renderFinishedSemaphore, m_inFlightFence))
throw std::runtime_error("Failed to submit command buffers: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
m_owner.Present(m_imageIndex, m_renderFinishedSemaphore);
}
void VulkanRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{
VulkanCommandBuffer& vkCommandBuffer = *static_cast<VulkanCommandBuffer*>(commandBuffer);
@@ -81,13 +90,4 @@ namespace Nz
throw std::runtime_error("Failed to submit command buffer: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
}
}
void VulkanRenderImage::Present()
{
Vk::QueueHandle& graphicsQueue = m_owner.GetGraphicsQueue();
if (!graphicsQueue.Submit(UInt32(m_graphicalCommandsBuffers.size()), m_graphicalCommandsBuffers.data(), m_imageAvailableSemaphore, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, m_renderFinishedSemaphore, m_inFlightFence))
throw std::runtime_error("Failed to submit command buffers: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
m_owner.Present(m_imageIndex, m_renderFinishedSemaphore);
}
}

View File

@@ -76,7 +76,7 @@ namespace Nz
return colorBlendStates;
}
VkPipelineColorBlendStateCreateInfo VulkanRenderPipeline::BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState)
VkPipelineColorBlendStateCreateInfo VulkanRenderPipeline::BuildColorBlendInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState)
{
VkPipelineColorBlendStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
@@ -100,7 +100,7 @@ namespace Nz
return createInfo;
}
VkPipelineDynamicStateCreateInfo VulkanRenderPipeline::BuildDynamicStateInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkDynamicState>& dynamicStates)
VkPipelineDynamicStateCreateInfo VulkanRenderPipeline::BuildDynamicStateInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkDynamicState>& dynamicStates)
{
VkPipelineDynamicStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
@@ -110,7 +110,7 @@ namespace Nz
return createInfo;
}
std::vector<VkDynamicState> VulkanRenderPipeline::BuildDynamicStateList(const RenderPipelineInfo& pipelineInfo)
std::vector<VkDynamicState> VulkanRenderPipeline::BuildDynamicStateList(const RenderPipelineInfo& /*pipelineInfo*/)
{
return { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
}
@@ -124,7 +124,7 @@ namespace Nz
return createInfo;
}
VkPipelineMultisampleStateCreateInfo VulkanRenderPipeline::BuildMultisampleInfo(const RenderPipelineInfo& pipelineInfo)
VkPipelineMultisampleStateCreateInfo VulkanRenderPipeline::BuildMultisampleInfo(const RenderPipelineInfo& /*pipelineInfo*/)
{
VkPipelineMultisampleStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
@@ -146,7 +146,7 @@ namespace Nz
return createInfo;
}
VkPipelineViewportStateCreateInfo VulkanRenderPipeline::BuildViewportInfo(const RenderPipelineInfo& pipelineInfo)
VkPipelineViewportStateCreateInfo VulkanRenderPipeline::BuildViewportInfo(const RenderPipelineInfo& /*pipelineInfo*/)
{
VkPipelineViewportStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
@@ -229,7 +229,7 @@ namespace Nz
return vertexBindings;
}
VkPipelineVertexInputStateCreateInfo VulkanRenderPipeline::BuildVertexInputInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkVertexInputAttributeDescription>& vertexAttributes, const std::vector<VkVertexInputBindingDescription>& bindingDescriptions)
VkPipelineVertexInputStateCreateInfo VulkanRenderPipeline::BuildVertexInputInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkVertexInputAttributeDescription>& vertexAttributes, const std::vector<VkVertexInputBindingDescription>& bindingDescriptions)
{
VkPipelineVertexInputStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;

View File

@@ -24,7 +24,7 @@ namespace Nz
std::vector<EntryPoint> entryPoints;
bool HandleOpcode(const SpirvInstruction& instruction, UInt32 wordCount) override
bool HandleOpcode(const SpirvInstruction& instruction, UInt32 /*wordCount*/) override
{
switch (instruction.op)
{

View File

@@ -56,14 +56,15 @@ namespace
}
ShaderGraph::ShaderGraph() :
m_flowScene(BuildRegistry()),
m_type(ShaderType::NotSet)
{
m_flowScene.emplace(BuildRegistry());
m_previewModel = std::make_unique<QuadPreview>();
QObject::connect(&m_flowScene, &QGraphicsScene::selectionChanged, [&]
QObject::connect(&m_flowScene.value(), &QGraphicsScene::selectionChanged, [&]
{
auto selectedNodes = m_flowScene.selectedNodes();
auto selectedNodes = m_flowScene->selectedNodes();
if (selectedNodes.size() == 1)
OnSelectedNodeUpdate(this, static_cast<ShaderNode*>(selectedNodes.front()->nodeDataModel()));
else
@@ -78,31 +79,31 @@ m_type(ShaderType::NotSet)
UpdateTexturePreview(0, QImage(R"(C:\Users\Lynix\Pictures\potatavril.png)"));
auto& node1 = m_flowScene.createNode(std::make_unique<TextureValue>(*this));
auto& node1 = m_flowScene->createNode(std::make_unique<TextureValue>(*this));
node1.nodeGraphicsObject().setPos(0, 200);
auto& node2 = m_flowScene.createNode(std::make_unique<InputValue>(*this));
auto& node2 = m_flowScene->createNode(std::make_unique<InputValue>(*this));
node2.nodeGraphicsObject().setPos(50, 350);
auto& node3 = m_flowScene.createNode(std::make_unique<SampleTexture>(*this));
auto& node3 = m_flowScene->createNode(std::make_unique<SampleTexture>(*this));
node3.nodeGraphicsObject().setPos(200, 200);
auto& node4 = m_flowScene.createNode(std::make_unique<VecMul>(*this));
auto& node4 = m_flowScene->createNode(std::make_unique<VecMul>(*this));
node4.nodeGraphicsObject().setPos(400, 200);
auto& node5 = m_flowScene.createNode(std::make_unique<OutputValue>(*this));
auto& node5 = m_flowScene->createNode(std::make_unique<OutputValue>(*this));
node5.nodeGraphicsObject().setPos(600, 300);
m_flowScene.createConnection(node3, 0, node1, 0);
m_flowScene.createConnection(node3, 1, node2, 0);
m_flowScene.createConnection(node4, 0, node3, 0);
m_flowScene.createConnection(node4, 1, node3, 0);
m_flowScene.createConnection(node5, 0, node4, 0);
m_flowScene->createConnection(node3, 0, node1, 0);
m_flowScene->createConnection(node3, 1, node2, 0);
m_flowScene->createConnection(node4, 0, node3, 0);
m_flowScene->createConnection(node4, 1, node3, 0);
m_flowScene->createConnection(node5, 0, node4, 0);
}
ShaderGraph::~ShaderGraph()
{
m_flowScene.clearScene();
m_flowScene.reset();
}
std::size_t ShaderGraph::AddBuffer(std::string name, BufferType bufferType, std::size_t structIndex, std::size_t bindingIndex)
@@ -187,8 +188,8 @@ void ShaderGraph::Clear()
{
m_type = ShaderType::NotSet;
m_flowScene.clearScene();
m_flowScene.clear();
m_flowScene->clearScene();
m_flowScene->clear();
m_buffers.clear();
m_conditions.clear();
@@ -313,10 +314,10 @@ void ShaderGraph::Load(const QJsonObject& data)
OnTextureListUpdate(this);
for (QJsonValueRef node : data["nodes"].toArray())
m_flowScene.restoreNode(node.toObject());
m_flowScene->restoreNode(node.toObject());
for (QJsonValueRef connection : data["connections"].toArray())
m_flowScene.restoreConnection(connection.toObject());
m_flowScene->restoreConnection(connection.toObject());
}
QJsonObject ShaderGraph::Save()
@@ -430,14 +431,14 @@ QJsonObject ShaderGraph::Save()
QJsonArray nodesJsonArray;
{
for (auto&& [uuid, node] : m_flowScene.nodes())
for (auto&& [uuid, node] : m_flowScene->nodes())
nodesJsonArray.append(node->save());
}
sceneJson["nodes"] = nodesJsonArray;
QJsonArray connectionJsonArray;
{
for (auto&& [uuid, connection] : m_flowScene.connections())
for (auto&& [uuid, connection] : m_flowScene->connections())
{
QJsonObject connectionJson = connection->save();
@@ -638,8 +639,12 @@ void ShaderGraph::UpdateTexturePreview(std::size_t textureIndex, QImage preview)
{
assert(textureIndex < m_textures.size());
auto& textureEntry = m_textures[textureIndex];
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
textureEntry.preview = std::move(preview);
textureEntry.preview.convertTo(QImage::Format_RGBA8888);
#else
textureEntry.preview = preview.convertToFormat(QImage::Format_RGBA8888);
#endif
OnTexturePreviewUpdate(this, textureIndex);
}
@@ -844,7 +849,7 @@ std::unique_ptr<Nz::ShaderAst::DeclareFunctionStatement> ShaderGraph::ToFunction
std::vector<QtNodes::Node*> outputNodes;
m_flowScene.iterateOverNodes([&](QtNodes::Node* node)
m_flowScene->iterateOverNodes([&](QtNodes::Node* node)
{
if (node->nodeDataModel()->nPorts(QtNodes::PortType::Out) == 0)
{

View File

@@ -9,6 +9,7 @@
#include <nodes/FlowScene>
#include <ShaderNode/Enums.hpp>
#include <ShaderNode/Previews/PreviewModel.hpp>
#include <optional>
#include <string>
#include <vector>
@@ -153,7 +154,7 @@ class ShaderGraph
std::shared_ptr<QtNodes::DataModelRegistry> BuildRegistry();
std::unique_ptr<Nz::ShaderAst::DeclareFunctionStatement> ToFunction() const;
mutable QtNodes::FlowScene m_flowScene;
mutable std::optional<QtNodes::FlowScene> m_flowScene;
std::vector<BufferEntry> m_buffers;
std::vector<ConditionEntry> m_conditions;
std::vector<InputEntry> m_inputs;

View File

@@ -87,7 +87,7 @@ inline const PreviewModel& ShaderGraph::GetPreviewModel() const
inline QtNodes::FlowScene& ShaderGraph::GetScene()
{
return m_flowScene;
return *m_flowScene;
}
inline auto ShaderGraph::GetTexture(std::size_t textureIndex) const -> const TextureEntry&