Fix some Vulkan errors

Depth buffers were not tagged as output on passes writing on it
Handle holes in clear values
This commit is contained in:
SirLynix
2023-10-08 13:47:15 +02:00
parent 078542e44b
commit 98fe974fc8
6 changed files with 42 additions and 24 deletions

View File

@@ -301,8 +301,8 @@ namespace Nz
forwardPass.AddOutput(colorBufferIndex);
if (hasDepthPrepass)
forwardPass.SetDepthStencilInput(depthBufferIndex);
else
forwardPass.SetDepthStencilOutput(depthBufferIndex);
forwardPass.SetDepthStencilOutput(depthBufferIndex);
forwardPass.SetClearColor(0, m_viewer->GetClearColor());
forwardPass.SetDepthStencilClear(1.f, 0);

View File

@@ -85,19 +85,26 @@ namespace Nz
auto& bakedSubpass = bakedPass.subpasses.emplace_back();
bakedSubpass.commandCallback = framePass.GetCommandCallback();
for (const auto& output : framePass.GetOutputs())
const auto& colorOutputs = framePass.GetOutputs();
for (std::size_t i = 0; i < colorOutputs.size(); ++i)
{
const auto& output = colorOutputs[i];
bakedPass.outputTextureIndices.push_back(Retrieve(m_pending.attachmentToTextures, output.attachmentId));
auto& clearValues = bakedPass.outputClearValues.emplace_back();
if (output.clearColor)
clearValues.color = *output.clearColor;
{
bakedPass.outputClearValues.resize(i + 1);
bakedPass.outputClearValues[i].color = *output.clearColor;
}
}
// Add depth-stencil clear values
auto& dsClearValues = bakedPass.outputClearValues.emplace_back();
if (const auto& depthStencilClear = framePass.GetDepthStencilClear())
{
std::size_t depthClearIndex = colorOutputs.size();
bakedPass.outputClearValues.resize(depthClearIndex + 1);
auto& dsClearValues = bakedPass.outputClearValues[depthClearIndex];
dsClearValues.depth = depthStencilClear->depth;
dsClearValues.stencil = depthStencilClear->stencil;
}

View File

@@ -285,7 +285,7 @@ namespace Nz
std::array enabledFeatures = {
//VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT,
//VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT,
VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,
//VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,
VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT
};

View File

@@ -36,23 +36,28 @@ namespace Nz
std::size_t attachmentCount = vkRenderPass.GetAttachmentCount();
StackArray<VkClearValue> vkClearValues = NazaraStackArray(VkClearValue, attachmentCount);
for (std::size_t i = 0; i < attachmentCount; ++i)
{
const auto& values = (i < clearValueCount) ? clearValues[i] : CommandBufferBuilder::ClearValues{};
auto& vkValues = vkClearValues[i];
StackArray<VkClearValue> vkClearValues;
if (PixelFormatInfo::GetContent(vkRenderPass.GetAttachment(i).format) == PixelFormatContent::ColorRGBA)
if (clearValueCount > 0)
{
vkClearValues = NazaraStackArray(VkClearValue, attachmentCount);
for (std::size_t i = 0; i < attachmentCount; ++i)
{
vkValues.color.float32[0] = values.color.r;
vkValues.color.float32[1] = values.color.g;
vkValues.color.float32[2] = values.color.b;
vkValues.color.float32[3] = values.color.a;
}
else
{
vkValues.depthStencil.depth = values.depth;
vkValues.depthStencil.stencil = values.stencil;
const auto& values = (i < clearValueCount) ? clearValues[i] : CommandBufferBuilder::ClearValues{};
auto& vkValues = vkClearValues[i];
if (PixelFormatInfo::GetContent(vkRenderPass.GetAttachment(i).format) == PixelFormatContent::ColorRGBA)
{
vkValues.color.float32[0] = values.color.r;
vkValues.color.float32[1] = values.color.g;
vkValues.color.float32[2] = values.color.b;
vkValues.color.float32[3] = values.color.a;
}
else
{
vkValues.depthStencil.depth = values.depth;
vkValues.depthStencil.stencil = values.stencil;
}
}
}