Merge branch 'master' into nzsl-modules

This commit is contained in:
Jérôme Leclercq
2022-02-27 18:44:44 +01:00
20 changed files with 133 additions and 75 deletions

View File

@@ -67,6 +67,12 @@ namespace Nz
if (!passData.name.empty())
builder.BeginDebugRegion(passData.name, Color::Green);
FramePassEnvironment env{
*this,
passData.renderRect,
renderFrame
};
bool first = true;
for (auto& subpass : passData.subpasses)
{
@@ -75,7 +81,7 @@ namespace Nz
first = false;
subpass.commandCallback(builder, passData.renderRect);
subpass.commandCallback(builder, env);
}
if (!passData.name.empty())

View File

@@ -137,7 +137,7 @@ namespace Nz
return (m_rebuildCommandBuffer) ? FramePassExecution::UpdateAndExecute : FramePassExecution::Execute;
});
depthPrepass.SetCommandCallback([this](CommandBufferBuilder& builder, const Recti& /*renderRect*/)
depthPrepass.SetCommandCallback([this](CommandBufferBuilder& builder, const FramePassEnvironment& /*env*/)
{
Recti viewport = m_viewer->GetViewport();

View File

@@ -532,10 +532,10 @@ namespace Nz
mergePass.AddOutput(renderTargetData.finalAttachment);
mergePass.SetClearColor(0, Color::Black);
mergePass.SetCommandCallback([&targetViewers](CommandBufferBuilder& builder, const Recti& renderRect)
mergePass.SetCommandCallback([&targetViewers](CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderRect);
builder.SetViewport(renderRect);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
Graphics* graphics = Graphics::Instance();
builder.BindPipeline(*graphics->GetBlitPipeline(false));

View File

@@ -282,7 +282,7 @@ namespace Nz
return (m_rebuildCommandBuffer) ? FramePassExecution::UpdateAndExecute : FramePassExecution::Execute;
});
forwardPass.SetCommandCallback([this](CommandBufferBuilder& builder, const Recti& /*renderRect*/)
forwardPass.SetCommandCallback([this](CommandBufferBuilder& builder, const FramePassEnvironment& /*env*/)
{
Recti viewport = m_viewer->GetViewport();

View File

@@ -17,9 +17,9 @@ namespace Nz::ShaderAst
DependencyCheckerVisitor usageChecker;
};
StatementPtr EliminateUnusedPassVisitor::Process(Statement& statement)
StatementPtr EliminateUnusedPassVisitor::Process(Statement& statement, const Config& config)
{
Context context;
Context context(config);
statement.Visit(context.usageChecker);
context.usageChecker.Resolve();

View File

@@ -2271,23 +2271,35 @@ namespace Nz::ShaderAst
TypeMustMatch(resolvedType, GetExpressionType(*node.initialExpression));
}
if (m_context->options.makeVariableNameUnique && FindIdentifier(node.varName) != nullptr)
{
// Try to make variable name unique by appending _X to its name (incrementing X until it's unique) to the variable name until by incrementing X
unsigned int cloneIndex = 2;
std::string candidateName;
do
{
candidateName = node.varName + "_" + std::to_string(cloneIndex++);
}
while (FindIdentifier(candidateName) != nullptr);
node.varName = std::move(candidateName);
}
node.varIndex = RegisterVariable(node.varName, resolvedType);
node.varType = std::move(resolvedType);
if (m_context->options.makeVariableNameUnique)
{
// Since we are registered, FindIdentifier will find us
auto IgnoreOurself = [varIndex = *node.varIndex](const Identifier& identifier)
{
if (identifier.type == Identifier::Type::Variable && identifier.index == varIndex)
return false;
return true;
};
if (FindIdentifier(node.varName, IgnoreOurself) != nullptr)
{
// Try to make variable name unique by appending _X to its name (incrementing X until it's unique) to the variable name until by incrementing X
unsigned int cloneIndex = 2;
std::string candidateName;
do
{
candidateName = node.varName + "_" + std::to_string(cloneIndex++);
}
while (FindIdentifier(candidateName, IgnoreOurself) != nullptr);
node.varName = std::move(candidateName);
}
}
SanitizeIdentifier(node.varName);
}

View File

@@ -180,8 +180,12 @@ namespace Nz
{
ShaderAst::StatementPtr tempAst;
ShaderAst::EliminateUnusedPassVisitor::Config eliminateUnunsedConfig;
if (shaderStage)
eliminateUnunsedConfig.usedShaderStages = *shaderStage;
tempAst = ShaderAst::PropagateConstants(*targetAst);
optimizedAst = ShaderAst::EliminateUnusedPass(*tempAst);
optimizedAst = ShaderAst::EliminateUnusedPass(*tempAst, eliminateUnunsedConfig);
targetAst = optimizedAst.get();
}

View File

@@ -91,6 +91,10 @@ namespace Nz
bool VulkanDevice::IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const
{
VkFormat vulkanFormat = ToVulkan(format);
if (vulkanFormat == VK_FORMAT_UNDEFINED)
return false;
VkFormatFeatureFlags flags = 0;
switch (usage)
{
@@ -116,7 +120,7 @@ namespace Nz
break;
}
VkFormatProperties formatProperties = GetInstance().GetPhysicalDeviceFormatProperties(GetPhysicalDevice(), ToVulkan(format));
VkFormatProperties formatProperties = GetInstance().GetPhysicalDeviceFormatProperties(GetPhysicalDevice(), vulkanFormat);
return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling
}
}